1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole;
17
18 import org.apache.commons.io.FileUtils;
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Ignore;
22 import org.junit.Test;
23 import org.kuali.ole.docstore.model.enums.DocCategory;
24 import org.kuali.ole.docstore.model.enums.DocFormat;
25 import org.kuali.ole.docstore.model.enums.DocType;
26 import org.kuali.ole.docstore.model.repopojo.FolderNode;
27 import org.kuali.ole.docstore.model.repopojo.RepositoryData;
28 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
29 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
30 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
31 import org.kuali.ole.docstore.service.BeanLocator;
32 import org.kuali.ole.docstore.service.IngestNIndexHandlerService;
33 import org.kuali.ole.pojo.OleException;
34 import org.mockito.MockitoAnnotations;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 import javax.jcr.Node;
39 import javax.jcr.RepositoryException;
40 import javax.jcr.Session;
41 import java.io.File;
42 import java.net.URL;
43 import java.util.Iterator;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.Set;
47
48 import static junit.framework.Assert.assertNotNull;
49 import static org.junit.Assert.assertTrue;
50
51
52
53
54
55
56
57
58 @Ignore
59 @Deprecated
60 public class RepositoryBrowser_UT extends BaseTestCase {
61
62 private static final Logger LOG = LoggerFactory
63 .getLogger(RepositoryBrowser_UT.class);
64 private IngestNIndexHandlerService ingestNIndexHandlerService = BeanLocator
65 .getIngestNIndexHandlerService();
66
67 @Before
68 public void setUp() throws Exception {
69
70
71 }
72
73 @Test
74 public void testBrowseRepository() throws Exception {
75 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
76 List<OleDocStoreData> oleDocStoreDatas = repositoryBrowser.browseDataSetup();
77 for (Iterator<OleDocStoreData> iterator = oleDocStoreDatas.iterator(); iterator.hasNext(); ) {
78 OleDocStoreData oleDocStoreData = iterator.next();
79 LOG.info(oleDocStoreData.getCategory());
80 Map<String, List<String>> typeFormatMap = oleDocStoreData.getTypeFormatMap();
81 Set<String> keys = typeFormatMap.keySet();
82 for (Iterator<String> stringIterator = keys.iterator(); stringIterator.hasNext(); ) {
83 String docType = stringIterator.next();
84 LOG.info(docType + ": " + typeFormatMap.get(docType));
85 }
86 }
87 }
88
89 @Test
90 public void testGetRandomUUIDs() throws Exception {
91 URL url = this.getClass().getResource("repository/request.xml");
92 File file = new File(url.toURI());
93
94 String docStoreDocuments = ingestNIndexHandlerService.ingestNIndexRequestDocuments(readFile(file));
95
96 assertTrue(!docStoreDocuments.isEmpty());
97 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
98 List<String> uuiDs = repositoryBrowser
99 .getUUIDs(DocCategory.WORK.getCode(), DocType.BIB.getDescription(), DocFormat.MARC.getCode(),
100 1);
101 System.out.println("testGetRandomUUIDs uuiDs length " + uuiDs.size());
102 if (uuiDs.size() > 0) {
103 Assert.assertNotNull(uuiDs);
104 }
105 uuiDs = repositoryBrowser.getUUIDs(DocCategory.WORK.getCode(), DocType.LICENSE.getDescription(),
106 DocFormat.ONIXPL.getCode(), 1);
107 System.out.println("uuiDs LICENSE" + uuiDs);
108 if (uuiDs.size() > 0) {
109 Assert.assertNotNull(uuiDs);
110 }
111 uuiDs = repositoryBrowser
112 .getUUIDs(DocCategory.WORK.getCode(), DocType.ITEM.getDescription(), DocFormat.OLEML.getCode(),
113 1);
114 System.out.println("uuiDs ITEM" + uuiDs.size());
115 Assert.assertNotNull(uuiDs);
116 uuiDs = repositoryBrowser.getUUIDs(DocCategory.WORK.getCode(), DocType.HOLDINGS.getDescription(),
117 DocFormat.OLEML.getCode(), 1);
118 Assert.assertNotNull(uuiDs);
119 System.out.println("uuiDs HOLDING" + uuiDs.size());
120 for (Iterator<String> iterator = uuiDs.iterator(); iterator.hasNext(); ) {
121 String uuid = iterator.next();
122 LOG.info(uuid);
123 }
124 }
125
126 public void testGetUUIDs() {
127 try {
128 URL url = this.getClass().getResource("repository/request.xml");
129 File file = new File(url.toURI());
130
131 String docStoreDocuments = ingestNIndexHandlerService.ingestNIndexRequestDocuments(readFile(file));
132
133 assertTrue(!docStoreDocuments.isEmpty());
134 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
135 List<String> uuiDs = repositoryBrowser
136 .getUUIDs(DocCategory.WORK.getCode(), DocType.BIB.getDescription(),
137 DocFormat.MARC.getCode(), 1, 2);
138
139 System.out.println("testGetRandomUUIDs uuiDs length " + uuiDs.size());
140 assertTrue(!uuiDs.isEmpty());
141 uuiDs = repositoryBrowser.getUUIDs(DocCategory.WORK.getCode(), DocType.LICENSE.getDescription(),
142 DocFormat.ONIXPL.getCode(), 1, 1);
143
144 System.out.println("uuiDs LICENSE" + uuiDs);
145
146 uuiDs = repositoryBrowser.getUUIDs(DocCategory.WORK.getCode(), DocType.ITEM.getDescription(),
147 DocFormat.OLEML.getCode(), 1, 1);
148 System.out.println("uuiDs ITEM" + uuiDs);
149
150 uuiDs = repositoryBrowser.getUUIDs(DocCategory.WORK.getCode(), DocType.HOLDINGS.getDescription(),
151 DocFormat.OLEML.getCode(), 1, 1);
152 System.out.println("uuiDs ITEM" + uuiDs);
153 for (Iterator<String> iterator = uuiDs.iterator(); iterator.hasNext(); ) {
154 String uuid = iterator.next();
155 LOG.info(uuid);
156 }
157 } catch (Exception e) {
158 LOG.info("Exception : " + e);
159 }
160 }
161
162 @Test
163 public void testRepositoryNodeCount() throws Exception {
164
165
166
167
168
169
170
171 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
172 List<OleDocStoreData> oleDocStoreDataList = repositoryBrowser.getFilesCount();
173 assertNotNull(oleDocStoreDataList);
174 for (Iterator<OleDocStoreData> iterator = oleDocStoreDataList.iterator(); iterator.hasNext(); ) {
175 OleDocStoreData oleDocStoreData = iterator.next();
176 Map<String, Map<String, Long>> typeFormatMapWithNodeCount = oleDocStoreData.getTypeFormatMapWithNodeCount();
177 for (Iterator<String> oleDocStoreDataIterator = typeFormatMapWithNodeCount.keySet()
178 .iterator(); oleDocStoreDataIterator
179 .hasNext(); ) {
180 String key = oleDocStoreDataIterator.next();
181 LOG.info(key + ": " + typeFormatMapWithNodeCount.get(key));
182 }
183 }
184 }
185
186 @Test
187 public void repoDump() throws RepositoryException, OleException {
188 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
189 String dump = repositoryBrowser.getRepositoryDump();
190 LOG.info("dump" + dump);
191 }
192
193 @Test
194 public void getDetails() throws Exception {
195 RepositoryManager repositoryManager = RepositoryManager.getRepositoryManager();
196 Session session = repositoryManager.getSession("mockUser", "test");
197 System.out.println("getName " + session.getWorkspace().getName());
198 }
199
200 @Ignore
201 @Test
202 public void getRepositoryDumpRange() throws Exception {
203 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
204 String category = DocCategory.WORK.getCode();
205 String type = DocType.BIB.getDescription();
206 String format = DocFormat.MARC.getCode();
207 int fromIndex = 1;
208 int Count = 1;
209 cleanRepository(category, type);
210 String beforedump = repositoryBrowser.getRepositoryDump();
211 LOG.info("beforedump" + beforedump);
212 loadBulkMarcRecords(DocCategory.WORK.getCode(), DocType.BIB.getDescription(), DocFormat.MARC.getCode(),
213 "/org/kuali/ole/bulkhandler/OLE-Bib-bulkIngest-IU-Set1-split.xml");
214 String dump = repositoryBrowser.getRepositoryDump();
215 LOG.info("dump" + dump);
216 String dumpRange = repositoryBrowser.getRepositoryRangeDump(category, type, format, fromIndex, Count);
217 LOG.info("dumpRange" + dumpRange);
218 }
219
220 public void cleanRepository(String category, String type) throws OleException, RepositoryException {
221 RepositoryManager repositoryManager = RepositoryManager.getRepositoryManager();
222 Session session = repositoryManager.getSession("mockUser", "test");
223 Node rootNode = session.getRootNode();
224 Node catNode = rootNode.getNode(category);
225 Node typeNode = catNode.getNode(type);
226 for (Iterator<Node> typeiterator = typeNode.getNodes(); typeiterator.hasNext(); ) {
227 Node formatNode = typeiterator.next();
228 if (!formatNode.getName().equals("jcr:system")) {
229 formatNode.remove();
230 }
231 }
232 session.save();
233 repositoryManager.logout(session);
234 }
235
236 private void loadBulkMarcRecords(String category, String type, String format, String inputXml) throws Exception {
237 File file = new File(getClass().getResource("/org/kuali/ole/repository/request.xml").toURI());
238 String input = FileUtils.readFileToString(file);
239 RequestHandler rh = new RequestHandler();
240 Request request = rh.toObject(input);
241 Response response = ingestNIndexHandlerService.ingestNIndexRequestDocuments(request);
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256 }
257
258 @Test
259 public void loadRepository() throws OleException, RepositoryException {
260 RepositoryManager oleRepositoryManager = RepositoryManager.getRepositoryManager();
261 RepositoryData repositoryData = new RepositoryData();
262 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
263 FolderNode folderNode = repositoryBrowser
264 .computeNodeCount(oleRepositoryManager.getSession().getRootNode(), repositoryData);
265 String repoDump = repositoryData.getRepositoryDump(repositoryData);
266 LOG.info("repoDump" + repoDump);
267 repositoryBrowser.browseRepositoryContent();
268 repositoryBrowser.generateNodeCount();
269 }
270
271 }