1 package org.kuali.ole;
2
3 import org.kuali.ole.docstore.model.xmlpojo.config.DocumentCategory;
4 import org.kuali.ole.docstore.model.xmlpojo.config.DocumentConfig;
5 import org.kuali.ole.docstore.model.xmlpojo.config.DocumentType;
6
7 import javax.jcr.Node;
8 import javax.jcr.Session;
9
10
11
12
13
14
15
16
17 public class DocumentStoreModelInitiallizer {
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public void init() throws Exception {
55 RepositoryManager repositoryManager = RepositoryManager.getRepositoryManager();
56 Session session = repositoryManager.getSession("documentStoreModelInitiallizer", "init");
57 Node rootNode = session.getRootNode();
58 DocumentConfig documentConfig = DocumentConfig.getInstance();
59 for (DocumentCategory documentCategory : documentConfig.getDocumentCategories()) {
60 String category = documentCategory.getId();
61 Node categoryNode;
62 if (!rootNode.hasNode(category)) {
63 categoryNode = rootNode.addNode(category, "nt:unstructured");
64 categoryNode.setProperty("nodeType", "folder");
65 categoryNode.addMixin("mix:referenceable");
66 } else {
67 categoryNode = rootNode.getNode(category);
68 }
69 for (DocumentType documentType : documentCategory.getDocumentTypes()) {
70 String docType = documentType.getId();
71 if (!((docType.equals("item") || docType.equals("holdings")))) {
72 Node typeNode;
73 if (!categoryNode.hasNode(docType)) {
74 typeNode = categoryNode.addNode(docType, "nt:unstructured");
75 typeNode.setProperty("nodeType", "folder");
76 typeNode.addMixin("mix:referenceable");
77 } else {
78 typeNode = categoryNode.getNode(docType);
79 }
80 }
81 }
82 }
83 session.save();
84 repositoryManager.logout(session);
85 }
86 }