View Javadoc
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   * Created by IntelliJ IDEA.
12   * User: pvsubrah
13   * Date: 1/10/12
14   * Time: 11:02 AM
15   * To change this template use File | Settings | File Templates.
16   */
17  public class DocumentStoreModelInitiallizer {
18  
19          /*public void init() throws Exception {
20              RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
21              List<OleDocStoreData> oleDocStoreDatas = repositoryBrowser.browseDataSetup();
22              RepositoryManager repositoryManager = RepositoryManager.getRepositoryManager();
23              Session session = repositoryManager.getSession("documentStoreModelInitiallizer","init");
24              Node rootNode = session.getRootNode();
25  
26              for (Iterator<OleDocStoreData> iterator = oleDocStoreDatas.iterator(); iterator.hasNext(); ) {
27                  OleDocStoreData oleDocStoreData = iterator.next();
28                  String category = oleDocStoreData.getCategory();
29                  Node categoryNode;
30                  if (!rootNode.hasNode(category)) {
31                      categoryNode = rootNode.addNode(category, "nt:unstructured");
32                      categoryNode.setProperty("nodeType", "folder");
33                      categoryNode.addMixin("mix:referenceable");
34                  } else {
35                      categoryNode = rootNode.getNode(category);
36                  }
37                  List<String> doctypes = oleDocStoreData.getDoctypes();
38                  for (Iterator<String> stringIterator = doctypes.iterator(); stringIterator.hasNext(); ) {
39                      String docType = stringIterator.next();
40                      Node typeNode;
41                      if (!categoryNode.hasNode(docType)) {
42                          typeNode = categoryNode.addNode(docType, "nt:unstructured");
43                          typeNode.setProperty("nodeType", "folder");
44                          typeNode.addMixin("mix:referenceable");
45                      } else {
46                          typeNode = categoryNode.getNode(docType);
47                      }
48                  }
49              }
50              session.save();
51              repositoryManager.logout(session);
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  }