View Javadoc
1   package org.kuali.ole.docstore.document.jcr;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.apache.solr.common.SolrInputDocument;
5   import org.junit.Ignore;
6   import org.junit.Test;
7   import org.kuali.ole.BaseTestCase;
8   import org.kuali.ole.RepositoryManager;
9   import org.kuali.ole.docstore.OleDocStoreException;
10  import org.kuali.ole.docstore.model.enums.DocFormat;
11  import org.kuali.ole.docstore.model.xmlpojo.ingest.*;
12  import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
13  import org.kuali.ole.docstore.process.ProcessParameters;
14  import org.kuali.ole.docstore.process.batch.BulkProcessRequest;
15  import org.kuali.ole.docstore.service.BeanLocator;
16  import org.kuali.ole.docstore.service.DocumentServiceImpl;
17  import org.kuali.ole.pojo.OleException;
18  import org.kuali.ole.solr.DummyIndexerServiceImpl;
19  
20  import javax.jcr.Node;
21  import javax.jcr.RepositoryException;
22  import javax.jcr.Session;
23  import java.io.File;
24  import java.io.IOException;
25  import java.net.URISyntaxException;
26  import java.util.ArrayList;
27  import java.util.Calendar;
28  import java.util.List;
29  
30  
31  /**
32   * Created with IntelliJ IDEA.
33   * User: ?
34   * Date: 1/4/13
35   * Time: 12:14 PM
36   * To change this template use File | Settings | File Templates.
37   */
38  @Ignore
39  @Deprecated
40  public class JcrDocumentManagerFactory_UT extends BaseTestCase {
41  
42  
43      @Test
44      public void testWorkLicenseDocumentManager() throws OleDocStoreException, RepositoryException, IOException, URISyntaxException, OleException {
45          ResponseDocument responseDocument = new ResponseDocument();
46  
47          JcrWorkLicenseDocumentManager jcrWorkLicenseDocumentManager = JcrWorkLicenseDocumentManager.getInstance();
48          RepositoryManager repositoryManager = RepositoryManager.getRepositoryManager();
49          Session session = repositoryManager.getSession();
50          File file = new File(getClass().getResource("/org/kuali/ole/repository/request.xml").toURI());
51          String input = FileUtils.readFileToString(file);
52          RequestHandler rh = new RequestHandler();
53          Request request = rh.toObject(input);
54          List<RequestDocument> requestDocuments = request.getRequestDocuments();
55          RequestDocument requestDocument = requestDocuments.get(0);
56          jcrWorkLicenseDocumentManager.convertContentToBytes(requestDocument);
57          jcrWorkLicenseDocumentManager.isVersioningEnabled();
58          AdditionalAttributes additionalAttributes = new AdditionalAttributes();
59          requestDocument.setAdditionalAttributes(additionalAttributes);
60          additionalAttributes = requestDocument.getAdditionalAttributes();
61          additionalAttributes.setAttribute("dateEntered", Calendar.getInstance().toString());
62          requestDocument.setDocumentName("documentName");
63          Node nodeByUUID = session.getNodeByIdentifier(requestDocument.getUuid());
64          jcrWorkLicenseDocumentManager.modifyAdditionalAttributes(requestDocument, nodeByUUID);
65          JcrAbstractDocumentManager abstractDocumentManager = JcrWorkLicenseDocumentManager.getInstance();
66          Node node = abstractDocumentManager.storeDocument(requestDocument, session, responseDocument);
67          jcrWorkLicenseDocumentManager.checkOutContent(node, "all", "checkOut");
68          jcrWorkLicenseDocumentManager.checkOutContent(node, DocFormat.PDF.getCode(), "checkOut");
69      }
70  
71      @Test
72      public void testAbstractDocumentManager() throws OleException, RepositoryException, OleDocStoreException, URISyntaxException, IOException {
73          JcrAbstractDocumentManager abstractDocumentManager = JcrWorkLicenseDocumentManager.getInstance();
74          ResponseDocument responseDocument = new ResponseDocument();
75          Session session = RepositoryManager.getRepositoryManager().getSession("CheckinManager", "checkIn");
76          File file = new File(getClass().getResource("/org/kuali/ole/repository/request-new.xml").toURI());
77          String input = FileUtils.readFileToString(file);
78          RequestHandler rh = new RequestHandler();
79          Request request = rh.toObject(input);
80          request.setOperation("ingest");
81          DocumentServiceImpl d = BeanLocator.getDocumentServiceImpl();
82          Response response1 = d.process(request);
83          String existingUUIDToCheckIn = response1.getDocuments().get(0).getUuid();
84          List<RequestDocument> requestDocuments = request.getRequestDocuments();
85          RequestDocument requestDocument = requestDocuments.get(0);
86          requestDocument.setId(existingUUIDToCheckIn);
87          BulkProcessRequest bulkProcessRequest = new BulkProcessRequest();
88          AdditionalAttributes additionalAttributes = new AdditionalAttributes();
89          requestDocument.setAdditionalAttributes(additionalAttributes);
90          bulkProcessRequest.setUser(ProcessParameters.BULK_DEFAULT_USER);
91          bulkProcessRequest.setOperation(BulkProcessRequest.BulkProcessOperation.INGEST);
92          abstractDocumentManager.bulkIngest(bulkProcessRequest, requestDocuments);
93          abstractDocumentManager.getVersionManager(session);
94          abstractDocumentManager.updateIndex(requestDocument);
95          List<String> valuesList = new ArrayList<String>();
96          abstractDocumentManager.validateInput(requestDocument, session, valuesList);
97          abstractDocumentManager.convertContentToBytes(requestDocument);
98          abstractDocumentManager.buildResponseDocument(requestDocument);
99          requestDocument.setDocumentName(file.getName());
100         requestDocument.setUser(ProcessParameters.BULK_DEFAULT_USER);
101         requestDocument.setUuid(existingUUIDToCheckIn);
102         requestDocument.setOperation(Request.Operation.deleteWithLinkedDocs.name());
103         requestDocument.setUuid(requestDocument.getId());
104         ResponseDocument respDoc = new ResponseDocument();
105         abstractDocumentManager.ingest(requestDocument, session, respDoc);
106         List list = new ArrayList<RequestDocument>();
107         list.add(requestDocument);
108         abstractDocumentManager.ingest(list, session);
109         abstractDocumentManager.checkout(requestDocument, session);
110         abstractDocumentManager.batchIngest(bulkProcessRequest, list, session);
111         abstractDocumentManager.delete(list, session);
112         abstractDocumentManager.index(list, true);
113         Node node = abstractDocumentManager.storeDocument(requestDocument, session, responseDocument);
114         System.out.println("  ");
115         abstractDocumentManager.checkOutContent(node, DocFormat.DOC.getCode(), "checkOut");
116         abstractDocumentManager.updateVersion(session, node);
117         abstractDocumentManager.buildResponseDocument(requestDocument, session, responseDocument);
118     }
119 
120     @Test
121     public void testDummyIndexerServiceImpl() {
122         DummyIndexerServiceImpl dummyIndexerService = DummyIndexerServiceImpl.getInstance();
123         dummyIndexerService.deleteDocument(new String("12"), new String("123"));
124         dummyIndexerService.indexDocumentsFromDirBySolrDoc("1", "2", "3", "4");
125         List list = new ArrayList<File>();
126         dummyIndexerService.indexDocumentsFromFiles("1", "2", "3", list);
127         list = new ArrayList<String>();
128         dummyIndexerService.deleteDocuments("1", list);
129         dummyIndexerService.indexDocumentsFromFileBySolrDoc("1", "2", "3", "4");
130         dummyIndexerService.getSolrDocumentBySolrId("1");
131         dummyIndexerService.getSolrDocument("1", "2");
132         list = new ArrayList<SolrInputDocument>();
133         dummyIndexerService.indexSolrDocuments(list);
134     }
135 
136     @Test
137     public void testDocumentManagerFactory() {
138         JcrDocumentManagerFactory jcrDocumentManagerFactory = JcrDocumentManagerFactory.getInstance();
139         jcrDocumentManagerFactory.getDocumentManager("docCategory", "docType", "docFormat");
140     }
141 }