View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole;
17  
18  import org.kuali.ole.docstore.model.enums.DocFormat;
19  import org.kuali.ole.docstore.model.enums.DocType;
20  import org.kuali.ole.docstore.model.repopojo.FolderNode;
21  import org.kuali.ole.docstore.model.repopojo.RepositoryData;
22  import org.kuali.ole.docstore.process.ProcessParameters;
23  import org.kuali.ole.logger.DocStoreLogger;
24  import org.kuali.ole.logger.MetricsLogger;
25  import org.kuali.ole.pojo.OleException;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import javax.jcr.*;
30  import java.io.IOException;
31  import java.io.InputStream;
32  import java.util.*;
33  
34  /**
35   * Created by IntelliJ IDEA.
36   * User: peris
37   * Date: 5/3/11
38   * Time: 10:59 AM
39   * To change this template use File | Settings | File Templates.
40   */
41  public class RepositoryBrowser {
42      private DocStoreLogger docStoreLogger = new DocStoreLogger(this.getClass().getName());
43      private MetricsLogger metricsLogger;
44      protected final Logger LOG = LoggerFactory.getLogger(this.getClass());
45  
46  
47      public void browseRepositoryContent() throws OleException {
48          Session session = RepositoryManager.getRepositoryManager()
49                  .getSession("repositoryBrowser", "browseRepositoryContent");
50          try {
51              Node root = session.getRootNode();
52              List<OleDocStoreData> oleDocStoreDatas = browseDataSetup();
53              for (Iterator<OleDocStoreData> iterator = oleDocStoreDatas.iterator(); iterator.hasNext(); ) {
54                  OleDocStoreData oleDocStoreData = iterator.next();
55                  if (root.hasNode(oleDocStoreData.getCategory())) {
56                      Node categoryNode = root.getNode(oleDocStoreData.getCategory());
57                      NodeIterator nodes = categoryNode.getNodes();
58                      while (nodes.hasNext()) {
59                          Node node = nodes.nextNode();
60                          NodeIterator childNodes = node.getNodes();
61                          while (childNodes.hasNext()) {
62                              Node childOfChildNode = childNodes.nextNode();
63                              NodeIterator fileNodes = childOfChildNode.getNodes();
64                              while (fileNodes.hasNext()) {
65                                  Node nextNode = fileNodes.nextNode();
66                                  if (nextNode.hasNode("jcr:content")) {
67                                  }
68                              }
69  
70                          }
71                      }
72                  }
73  
74              }
75          } catch (RepositoryException e) {
76              throw new OleException(e.getMessage());
77          } finally {
78              RepositoryManager.getRepositoryManager().logout(session);
79          }
80  
81      }
82  
83      public List<OleDocStoreData> getFilesCount() throws OleException {
84          List<OleDocStoreData> oleDocStoreDatas;
85          getMetricsLogger().startRecording();
86          Session session = RepositoryManager.getRepositoryManager().getSession("repositoryBrowser", "fileCount");
87          Map<String, List<String>> formatLevelMap = new HashMap<String, List<String>>();
88          try {
89              Node root = session.getRootNode();
90              oleDocStoreDatas = browseDataSetup();
91              for (Iterator<OleDocStoreData> iterator = oleDocStoreDatas.iterator(); iterator.hasNext(); ) {
92                  OleDocStoreData oleDocStoreData = iterator.next();
93                  if (root.hasNode(oleDocStoreData.getCategory())) {
94                      Node categoryNode = root.getNode(oleDocStoreData.getCategory());
95                      Map<String, List<String>> typeFormatMap = oleDocStoreData.getTypeFormatMap();
96                      Set<String> types = typeFormatMap.keySet();
97                      for (Iterator<String> catIterator = types.iterator(); catIterator.hasNext(); ) {
98                          String type = catIterator.next();
99                          if (categoryNode.hasNode(type)) {
100                             Node typeNode = categoryNode.getNode(type);
101                             List<String> formats = typeFormatMap.get(type);
102                             Map<String, Long> countMap = new HashMap<String, Long>();
103                             if (formats != null && formats.size() > 0) {
104                                 for (Iterator<String> typIterator = formats.iterator(); typIterator.hasNext(); ) {
105                                     String format = typIterator.next();
106                                     if (format.equalsIgnoreCase(DocFormat.MARC.getCode())) {
107                                         List<String> levelNodes = new ArrayList<String>();
108                                         levelNodes.add(ProcessParameters.NODE_LEVEL1);
109                                         formatLevelMap.put(DocFormat.MARC.getCode(), levelNodes);
110                                     } else if (format.equalsIgnoreCase(DocFormat.DUBLIN_CORE.getCode())) {
111                                         List<String> levelNodes = new ArrayList<String>();
112                                         levelNodes.add(ProcessParameters.NODE_LEVEL1);
113                                         formatLevelMap.put(DocFormat.DUBLIN_CORE.getCode(), levelNodes);
114                                     } else if (format.equalsIgnoreCase(DocFormat.DUBLIN_UNQUALIFIED.getCode())) {
115                                         List<String> levelNodes = new ArrayList<String>();
116                                         levelNodes.add(ProcessParameters.NODE_LEVEL1);
117                                         formatLevelMap.put(DocFormat.DUBLIN_UNQUALIFIED.getCode(), levelNodes);
118                                     } else if (format.equalsIgnoreCase("oleml") && type.equalsIgnoreCase("instance")) {
119                                         List<String> levelNodes = new ArrayList<String>();
120                                         levelNodes.add(ProcessParameters.NODE_LEVEL1);
121                                         formatLevelMap.put("oleml", levelNodes);
122                                     }
123                                     if (typeNode.hasNode(format)) {
124                                         Node formatNode = typeNode.getNode(format);
125                                         List<String> folderL1list = formatLevelMap.get(format);
126                                         if (folderL1list != null && folderL1list.size() > 0) {
127                                             for (Iterator<String> forIterator = folderL1list.iterator(); forIterator
128                                                     .hasNext(); ) {
129                                                 String levelL1 = forIterator.next();
130                                                 if (format.equalsIgnoreCase(DocFormat.MARC.getCode())) {
131                                                     List<String> levelNodes = new ArrayList<String>();
132                                                     levelNodes.add(ProcessParameters.NODE_LEVEL2);
133                                                     formatLevelMap.put(ProcessParameters.NODE_LEVEL1, levelNodes);
134                                                 } else if (format.equalsIgnoreCase(DocFormat.DUBLIN_CORE.getCode())) {
135                                                     List<String> levelNodes = new ArrayList<String>();
136                                                     levelNodes.add(ProcessParameters.NODE_LEVEL2);
137                                                     formatLevelMap.put(ProcessParameters.NODE_LEVEL1, levelNodes);
138                                                 } else if (format
139                                                         .equalsIgnoreCase(DocFormat.DUBLIN_UNQUALIFIED.getCode())) {
140                                                     List<String> levelNodes = new ArrayList<String>();
141                                                     levelNodes.add(ProcessParameters.NODE_LEVEL2);
142                                                     formatLevelMap.put(ProcessParameters.NODE_LEVEL1, levelNodes);
143                                                 } else if (format.equalsIgnoreCase("oleml") && type
144                                                         .equalsIgnoreCase("instance")) {
145                                                     List<String> levelNodes = new ArrayList<String>();
146                                                     levelNodes.add(ProcessParameters.NODE_LEVEL2);
147                                                     formatLevelMap.put(ProcessParameters.NODE_LEVEL1, levelNodes);
148                                                 }
149                                                 //                                        addFormatCount(folder12Node, file, format, countMap, type,oleDocStoreData);
150                                                 if (formatNode.hasNode(levelL1)) {
151                                                     Node levelL1Node = formatNode.getNode(levelL1);
152                                                     List<String> folder12List = formatLevelMap.get(levelL1);
153                                                     if (folder12List != null && folder12List.size() > 0) {
154                                                         for (Iterator<String> levelL1Iterator = folder12List
155                                                                 .iterator(); levelL1Iterator.hasNext(); ) {
156                                                             String levelL2 = levelL1Iterator.next();
157 
158                                                             if (format.equalsIgnoreCase(DocFormat.MARC.getCode())) {
159                                                                 List<String> levelNodes = new ArrayList<String>();
160                                                                 levelNodes.add(ProcessParameters.NODE_LEVEL3);
161                                                                 formatLevelMap
162                                                                         .put(ProcessParameters.NODE_LEVEL2, levelNodes);
163                                                             } else if (format.equalsIgnoreCase(
164                                                                     DocFormat.DUBLIN_CORE.getCode())) {
165                                                                 List<String> levelNodes = new ArrayList<String>();
166                                                                 levelNodes.add(ProcessParameters.NODE_LEVEL3);
167                                                                 formatLevelMap
168                                                                         .put(ProcessParameters.NODE_LEVEL2, levelNodes);
169                                                             } else if (format.equalsIgnoreCase(
170                                                                     DocFormat.DUBLIN_UNQUALIFIED.getCode())) {
171                                                                 List<String> levelNodes = new ArrayList<String>();
172                                                                 levelNodes.add(ProcessParameters.NODE_LEVEL3);
173                                                                 formatLevelMap
174                                                                         .put(ProcessParameters.NODE_LEVEL2, levelNodes);
175                                                             } else {
176                                                                 addFormatCount(levelL1Node, levelL2, format, countMap,
177                                                                         type, oleDocStoreData);
178                                                             }
179                                                             if (levelL1Node.hasNode(levelL2)) {
180                                                                 Node folder12Node = levelL1Node.getNode(levelL2);
181                                                                 List<String> folderL3List = formatLevelMap.get(levelL2);
182                                                                 if (folderL3List != null && folderL3List.size() > 0) {
183                                                                     for (Iterator<String> levelL2Iterator = folderL3List
184                                                                             .iterator(); levelL2Iterator.hasNext(); ) {
185                                                                         String file = levelL2Iterator.next();
186                                                                         addFormatCount(folder12Node, file, format,
187                                                                                 countMap, type, oleDocStoreData);
188                                                                     }
189                                                                 }
190                                                             }
191                                                         }
192                                                     }
193                                                 }
194                                             }
195                                         }
196                                     }
197                                     if (!type.equalsIgnoreCase(DocType.INSTANCE.getCode())
198                                             && !format.equalsIgnoreCase(DocFormat.MARC.getCode()) && !format
199                                             .contains("dublin")) {
200                                         addFormatCount(typeNode, format, format, countMap, type, oleDocStoreData);
201                                     }
202                                 }
203                             }
204                         }
205                     }
206                 }
207             }
208             getMetricsLogger().endRecording();
209             getMetricsLogger().printTimes("Getting Files count took:: ");
210         } catch (RepositoryException e) {
211             throw new OleException(e.getMessage());
212         } finally {
213             RepositoryManager.getRepositoryManager().logout(session);
214         }
215         return oleDocStoreDatas;
216     }
217 
218     private void addFormatCount(Node levelL1Node, String levelL2, String format, Map<String, Long> countMap,
219                                 String type, OleDocStoreData oleDocStoreData) throws RepositoryException {
220         Long count = 0L;
221         NodeIterator L2Nodes = levelL1Node.getNodes(levelL2);
222         Map<String, Map<String, Long>> typeFormatMapWithNodeCount = oleDocStoreData.getTypeFormatMapWithNodeCount();
223         while (L2Nodes.hasNext()) {
224             Node fileNode = (Node) L2Nodes.next();
225             NodeIterator filesNodes = fileNode.getNodes();
226             if (countMap.get(format) != null) {
227                 count = countMap.get(format);
228             }
229             count = count + filesNodes.getSize();
230             countMap.put(format, count);
231         }
232         typeFormatMapWithNodeCount.put(type, countMap);
233     }
234 
235 
236     /* public Map<String, Integer> getDocumentCount() throws OleException, RepositoryException {
237         Map<String, Integer> documentCountMap = new HashMap<String, Integer>();
238         RepositoryManager oleRepositoryManager = RepositoryManager.getRepositoryManager();
239         Node node = oleRepositoryManager.getSession().getRootNode();
240         getDocumentCount(node, documentCountMap);
241         return documentCountMap;
242     }
243 
244     private void getDocumentCount(Node node, Map<String, Integer> documentCountMap) throws RepositoryException {
245         if (node.getName().equals("jcr:system")) {
246             return;
247         }
248         PropertyIterator properties = node.getProperties();
249         while (properties.hasNext()) {
250             Property property = properties.nextProperty();
251             if (property.getName().equals("jcr:primaryType") && property.getString().equalsIgnoreCase("olefile")) {
252                 String formatKey = property.getPath().substring(1, property.getPath().lastIndexOf("/"));
253                 formatKey = formatKey.substring(0, formatKey.lastIndexOf("/"));
254                 if (formatKey.contains("[")) {
255                     formatKey = formatKey.substring(0, formatKey.lastIndexOf("["));
256                 }
257                 if (formatKey != null) {
258                     if (documentCountMap.containsKey(formatKey)) {
259                         int count = documentCountMap.get(formatKey);
260                         documentCountMap.put(formatKey, ++count);
261                     }
262                     else {
263                         documentCountMap.put(formatKey, 1);
264                     }
265                 }
266             }
267         }
268         NodeIterator nodes = node.getNodes();
269         while (nodes.hasNext()) {
270             getDocumentCount(nodes.nextNode(), documentCountMap);
271         }                                                                    `
272     }*/
273 
274     public String getRepositoryDump() throws OleException, RepositoryException {
275         StringBuffer repositoryDump = new StringBuffer();
276         RepositoryManager oleRepositoryManager = RepositoryManager.getRepositoryManager();
277         Session session = oleRepositoryManager.getSession("repositoryBrowser", "getRepositoryDump");
278         repositoryDump(session.getRootNode(), repositoryDump);
279         oleRepositoryManager.logout(session);
280         return repositoryDump.toString();
281     }
282 
283     private void repositoryDump(Node node, StringBuffer repositoryDump) throws RepositoryException {
284         repositoryDump.append(node.getPath() + "\n");
285         if (node.getName().equals("jcr:system")) {
286             return;
287         }
288         PropertyIterator properties = node.getProperties();
289         while (properties.hasNext()) {
290             Property property = properties.nextProperty();
291             if (property.getDefinition().isMultiple()) {
292                 Value[] values = property.getValues();
293                 for (int i = 0; i < values.length; i++) {
294                     repositoryDump.append(property.getPath() + " = " + values[i].getString() + "\n");
295                 }
296             } else {
297                 repositoryDump.append(property.getPath() + " = " + property.getString() + "\n");
298             }
299         }
300         NodeIterator nodes = node.getNodes();
301         while (nodes.hasNext()) {
302             repositoryDump(nodes.nextNode(), repositoryDump);
303         }
304     }
305 
306     public String getRepositoryRangeDump(String category, String type, String format, int fromIndex, int count)
307             throws OleException, RepositoryException {
308         StringBuffer repositoryDump = new StringBuffer();
309         RepositoryManager oleRepositoryManager = RepositoryManager.getRepositoryManager();
310         Node rootnode = oleRepositoryManager.getSession("repositoryBrowser", "getRepositoryRangeDump").getRootNode();
311         repositoryRangeDump(rootnode, repositoryDump, category, type, format, fromIndex, count);
312         return repositoryDump.toString();
313     }
314 
315     private void repositoryRangeDump(Node rootnode, StringBuffer repositoryDump, String category, String type,
316                                      String format, int fromIndex, int count) throws RepositoryException {
317         int tempCount = 0;
318         Node categoryNode = rootnode.getNode(category);
319         Node typeNode = categoryNode.getNode(type);
320         Node formatNode = typeNode.getNode(format);
321         repositoryDump.append(categoryNode.toString().replace("node ", "") + "\n");
322         getNodeDump(categoryNode, repositoryDump);
323         repositoryDump.append(typeNode.toString().replace("node ", "") + "\n");
324         getNodeDump(typeNode, repositoryDump);
325         repositoryDump.append(formatNode.toString().replace("node ", "") + "\n");
326         getNodeDump(formatNode, repositoryDump);
327         for (Iterator<Node> formatiterator = formatNode.getNodes(); formatiterator.hasNext(); ) {
328             Node fileNode = formatiterator.next();
329             PropertyIterator properties = fileNode.getProperties();
330             while (properties.hasNext()) {
331                 Property property = properties.nextProperty();
332                 if (property.getName().equals("jcr:primaryType") && property.getString().equalsIgnoreCase(
333                         ProcessParameters.FILE_OLE)) {
334                     tempCount++;
335                     if (tempCount >= fromIndex && tempCount < fromIndex + count) {
336                         repositoryDump.append(fileNode.toString().replace("node ", "") + "\n");
337                         getNodeDump(fileNode, repositoryDump);
338                         NodeIterator nodes = fileNode.getNodes();
339                         while (nodes.hasNext()) {
340                             getNodeDump(nodes.nextNode(), repositoryDump);
341                         }
342                     }
343                 }
344             }
345         }
346     }
347 
348     public void getNodeDump(Node node, StringBuffer repositoryDump) throws RepositoryException {
349         PropertyIterator properties = node.getProperties();
350         while (properties.hasNext()) {
351             Property property = properties.nextProperty();
352             if (property.getDefinition().isMultiple()) {
353                 Value[] values = property.getValues();
354                 for (int i = 0; i < values.length; i++) {
355                     repositoryDump.append(property.getPath() + " = " + values[i].getString() + "\n");
356                 }
357             } else {
358                 repositoryDump.append(property.getPath() + " = " + property.getString() + "\n");
359             }
360         }
361     }
362 
363     public List<OleDocStoreData> browseDataSetup() {
364         List<OleDocStoreData> oleDocStoreDatas = new ArrayList<OleDocStoreData>();
365         InputStream in = RepositoryBrowser.class.getResourceAsStream("docstore-category.properties");
366         Properties categories = getPropertyValues(in);
367         Set<Map.Entry<Object, Object>> entries = categories.entrySet();
368         Map.Entry<Object, Object> next = entries.iterator().next();
369         String value = (String) next.getValue();
370         StringTokenizer tokenizer = new StringTokenizer(value, ",");
371         while (tokenizer.hasMoreTokens()) {
372             OleDocStoreData oleDocStoreData = new OleDocStoreData();
373             oleDocStoreData.setCategory(tokenizer.nextToken());
374             setDocTypes(oleDocStoreData);
375             setFormats(oleDocStoreData);
376             oleDocStoreDatas.add(oleDocStoreData);
377         }
378         return oleDocStoreDatas;
379     }
380 
381     private void setFormats(OleDocStoreData oleDocStoreData) {
382         InputStream in = RepositoryBrowser.class.getResourceAsStream("docstore-format.properties");
383         Properties categories = getPropertyValues(in);
384         Set<Map.Entry<Object, Object>> entries = categories.entrySet();
385         for (Iterator<Map.Entry<Object, Object>> iterator = entries.iterator(); iterator.hasNext(); ) {
386             Map.Entry<Object, Object> entry = iterator.next();
387             String value = (String) entry.getValue();
388             StringTokenizer tokenizer = new StringTokenizer(value, ",");
389             if ((!oleDocStoreData.getDoctypes().isEmpty() && oleDocStoreData.getDoctypes().contains(entry.getKey()))) {
390                 while (tokenizer.hasMoreTokens()) {
391                     oleDocStoreData.addFormat((String) entry.getKey(), tokenizer.nextToken());
392                 }
393             }
394         }
395 
396     }
397 
398     private void setDocTypes(OleDocStoreData oleDocStoreData) {
399         InputStream in = RepositoryBrowser.class.getResourceAsStream("docstore-type.properties");
400         Properties categories = getPropertyValues(in);
401         Set<Map.Entry<Object, Object>> entries = categories.entrySet();
402         for (Iterator<Map.Entry<Object, Object>> iterator = entries.iterator(); iterator.hasNext(); ) {
403             Map.Entry<Object, Object> entry = iterator.next();
404             String value = (String) entry.getValue();
405             StringTokenizer tokenizer = new StringTokenizer(value, ",");
406             if (entry.getKey().equals(oleDocStoreData.getCategory())) {
407                 while (tokenizer.hasMoreTokens()) {
408                     oleDocStoreData.addDocType(tokenizer.nextToken());
409                 }
410             }
411         }
412     }
413 
414     private Properties getPropertyValues(InputStream inputStream) {
415         Properties properties = new Properties();
416         try {
417             properties.load(inputStream);
418         } catch (IOException e) {
419             docStoreLogger.log("Unable to load properties", e);
420         }
421         return properties;
422     }
423 
424     public List<String> getUUIDs(String category, String type, String format, Integer numUUIDs) throws OleException {
425         Node rootNode = null;
426         ArrayList<String> uuids = new ArrayList<String>();
427         Session session = null;
428         try {
429             session = RepositoryManager.getRepositoryManager().getSession("repositoryBrowser", "getUUIDs");
430             String docType = new String(type);
431             LOG.info("doc type in repository browser-->" + docType);
432             rootNode = session.getRootNode();
433             Node categoryNode = rootNode.getNode(category);
434             if (type.equalsIgnoreCase(DocType.HOLDINGS.getCode()) || type.equalsIgnoreCase(DocType.ITEM.getCode())) {
435                 type = "instance";
436             }
437             Node typeNode = categoryNode.getNode(type);
438             Node formatNode = typeNode.getNode(format);
439             if (DocType.BIB.getDescription().equalsIgnoreCase(type)) {
440                 formatNode = formatNode.getNode(ProcessParameters.NODE_LEVEL1).getNode(ProcessParameters.NODE_LEVEL2)
441                         .getNode(ProcessParameters.NODE_LEVEL3);
442             } else if (DocType.LICENSE.getDescription().equals(type)) {
443                 formatNode = formatNode.getNode(ProcessParameters.NODE_LEVEL1);
444             } else {
445                 formatNode = formatNode.getNode(ProcessParameters.NODE_LEVEL1).getNode(ProcessParameters.NODE_LEVEL2);
446 
447             }
448             NodeIterator nodes = formatNode.getNodes();
449             int count = 0;
450             while (nodes.hasNext()) {
451                 Node node = nodes.nextNode();
452                 if (docType.equalsIgnoreCase(DocType.HOLDINGS.getCode())) {
453                     node = node.getNode(ProcessParameters.NODE_HOLDINGS).getNode(ProcessParameters.FILE_HOLDINGS);
454                     if (count < numUUIDs) {
455                         uuids.add(node.getIdentifier());
456                         count++;
457 
458                     }
459                 } else if (docType.equalsIgnoreCase(DocType.ITEM.getCode())) {
460                     NodeIterator itemIterator = node.getNode(ProcessParameters.NODE_HOLDINGS)
461                             .getNodes(ProcessParameters.FILE_ITEM);
462                     while (itemIterator.hasNext()) {
463                         Node itemNode = itemIterator.nextNode();
464                         if (count < numUUIDs) {
465                             uuids.add(itemNode.getIdentifier());
466                             count++;
467                         }
468                     }
469 
470                 } else if (count < numUUIDs) {
471                     uuids.add(node.getIdentifier());
472                     count++;
473                 }
474             }
475         } catch (PathNotFoundException e) {
476             LOG.info(e.getMessage());
477         } catch (RepositoryException e) {
478             LOG.info(e.getMessage());
479         } finally {
480             RepositoryManager.getRepositoryManager().logout(session);
481         }
482         return uuids;
483     }
484 
485     public List<String> getUUIDs(String category, String type, String format, Integer startIndex, Integer endIndex)
486             throws OleException {
487         Node rootNode = null;
488         ArrayList<String> uuids = new ArrayList<String>();
489         Session session = null;
490         endIndex = startIndex + endIndex;
491         try {
492             session = RepositoryManager.getRepositoryManager().getSession("repositoryBrowser", "getUUIDs");
493             String docType = new String(type);
494             LOG.debug("doc type in repository browser-->" + docType);
495             rootNode = session.getRootNode();
496             Node categoryNode = rootNode.getNode(category);
497             if (type.equalsIgnoreCase(DocType.HOLDINGS.getCode()) || type.equalsIgnoreCase(DocType.ITEM.getCode())) {
498                 type = "instance";
499             }
500             Node typeNode = categoryNode.getNode(type);
501             Node formatNode = typeNode.getNode(format);
502             if (DocType.BIB.getDescription().equalsIgnoreCase(type)) {
503                 formatNode = formatNode.getNode(ProcessParameters.NODE_LEVEL1).getNode(ProcessParameters.NODE_LEVEL2)
504                         .getNode(ProcessParameters.NODE_LEVEL3);
505             } else if (DocType.LICENSE.getDescription().equals(type)) {
506                 formatNode = formatNode.getNode(ProcessParameters.NODE_LEVEL1);
507             } else {
508                 formatNode = formatNode.getNode(ProcessParameters.NODE_LEVEL1).getNode(ProcessParameters.NODE_LEVEL2);
509 
510             }
511             NodeIterator nodes = formatNode.getNodes();
512             int count = 1;
513             while (nodes.hasNext()) {
514                 Node node = nodes.nextNode();
515                 if (docType.equalsIgnoreCase(DocType.HOLDINGS.getCode())) {
516                     node = node.getNode(ProcessParameters.NODE_HOLDINGS).getNode(ProcessParameters.FILE_HOLDINGS);
517                     if (count >= startIndex && count < endIndex) {
518                         uuids.add(node.getIdentifier());
519 
520                     }
521                 } else if (docType.equalsIgnoreCase(DocType.ITEM.getCode())) {
522                     NodeIterator itemIterator = node.getNode(ProcessParameters.NODE_HOLDINGS)
523                             .getNodes(ProcessParameters.FILE_ITEM);
524                     while (itemIterator.hasNext()) {
525                         Node itemNode = itemIterator.nextNode();
526                         if (count >= startIndex && count < endIndex) {
527                             uuids.add(itemNode.getIdentifier());
528                         }
529                     }
530 
531                 } else if (count >= startIndex && count < endIndex) {
532                     uuids.add(node.getIdentifier());
533                 }
534                 count++;
535             }
536         } catch (PathNotFoundException e) {
537             LOG.info(e.getMessage());
538         } catch (RepositoryException e) {
539             LOG.info(e.getMessage());
540         } finally {
541             RepositoryManager.getRepositoryManager().logout(session);
542         }
543         return uuids;
544     }
545 
546 
547     private MetricsLogger getMetricsLogger() {
548         if (null == metricsLogger) {
549             metricsLogger = new MetricsLogger(this.getClass().getName());
550         }
551         return metricsLogger;
552     }
553 
554 
555     public String generateNodeCount() throws OleException, RepositoryException {
556         RepositoryManager oleRepositoryManager = RepositoryManager.getRepositoryManager();
557         RepositoryData repositoryData = new RepositoryData();
558         Session session = oleRepositoryManager.getSession("repositoryBrowser", "generateNodeCount");
559         FolderNode folderNode = computeNodeCount(session.getRootNode(), repositoryData);
560         String repoNodeCountDump = repositoryData.getRepositoryDump(repositoryData);
561         oleRepositoryManager.logout(session);
562         return repoNodeCountDump;
563     }
564 
565     public FolderNode computeNodeCount(Node node, RepositoryData repositoryData) throws RepositoryException {
566         Long size = null;
567         FolderNode parentNode = null;
568         if (node != null) {
569             if (!node.hasProperty("nodeType") && !node.getName().equalsIgnoreCase("") && node.getName()
570                     .equalsIgnoreCase(
571                             "jcr:system")) {
572                 return null;
573             } else {
574                 parentNode = repositoryData.loadLine(repositoryData, node.getPath());
575                 if (isLastFolderNode(node)) {
576                     size = new Long(node.getNodes().getSize());
577                     parentNode.setProperty(parentNode.FILE_NODE_COUNT, size);
578                 } else {
579                     long count = 0;
580                     long longValue = 0;
581                     for (Iterator<NodeIterator> it = node.getNodes(); it.hasNext(); ) {
582                         Node childNode = (Node) it.next();
583                         FolderNode folderNode = computeNodeCount(childNode, repositoryData);
584                         if (folderNode != null && folderNode.getPropertyMap() != null) {
585                             Object value = folderNode.getPropertyMap().get(folderNode.FILE_NODE_COUNT);
586                             if (value instanceof Long) {
587                                 longValue = ((Long) value).longValue();
588                             }
589                             if (value != null) {
590                                 count = count + longValue;
591                             }
592                         }
593                     }
594                     if (parentNode != null) {
595                         size = new Long(count);
596                         parentNode.setProperty(parentNode.FILE_NODE_COUNT, size);
597                     }
598                 }
599             }
600         }
601         return parentNode;
602     }
603 
604     private boolean isLastFolderNode(Node node) throws RepositoryException {
605         boolean status = false;
606         if (node.getPath().contains(DocType.BIB.getDescription()) && node.getName()
607                 .startsWith(ProcessParameters.NODE_LEVEL1)) {
608             status = true;
609         } else if (node.getPath().contains(DocType.INSTANCE.getDescription()) && node.getName().startsWith(
610                 ProcessParameters.NODE_LEVEL2)) {
611             status = true;
612         } else if (node.getPath().contains(DocType.PATRON.getDescription())) {
613             status = true;
614         } else if (node.getPath().contains(DocType.LICENSE.getDescription()) && node.getName().startsWith(
615                 ProcessParameters.NODE_LEVEL1)) {
616             status = true;
617         }
618         return status;
619     }
620 }