1 package org.kuali.ole.docstore.process;
2
3 import org.apache.commons.lang.time.StopWatch;
4 import org.apache.solr.client.solrj.SolrServer;
5 import org.apache.solr.client.solrj.SolrServerException;
6 import org.apache.solr.common.SolrDocument;
7 import org.apache.solr.common.SolrInputDocument;
8 import org.kuali.ole.DocumentUniqueIDPrefix;
9 import org.kuali.ole.RepositoryBrowser;
10 import org.kuali.ole.RepositoryManager;
11 import org.kuali.ole.docstore.common.document.*;
12 import org.kuali.ole.docstore.common.document.content.instance.FormerIdentifier;
13 import org.kuali.ole.docstore.common.document.content.instance.Instance;
14 import org.kuali.ole.docstore.common.document.content.instance.xstream.InstanceOlemlRecordProcessor;
15 import org.kuali.ole.docstore.common.util.BatchBibTreeDBUtil;
16 import org.kuali.ole.docstore.discovery.service.SolrServerManager;
17
18
19
20
21 import org.kuali.ole.docstore.engine.service.index.solr.BibMarcIndexer;
22 import org.kuali.ole.docstore.engine.service.index.solr.DocumentIndexer;
23
24 import org.kuali.ole.docstore.metrics.reindex.ReIndexingBatchStatus;
25 import org.kuali.ole.docstore.metrics.reindex.ReIndexingStatus;
26 import org.kuali.ole.docstore.model.enums.DocCategory;
27 import org.kuali.ole.docstore.model.enums.DocFormat;
28 import org.kuali.ole.docstore.model.enums.DocType;
29 import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.BibRecord;
30 import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.EInstanceRecord;
31 import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.InstanceRecord;
32
33
34
35
36 import org.kuali.ole.docstore.common.document.content.instance.InstanceCollection;
37 import org.kuali.ole.docstore.model.xstream.work.oleml.WorkEInstanceOlemlRecordProcessor;
38 import org.kuali.ole.docstore.service.BeanLocator;
39
40 import org.kuali.ole.docstore.service.ServiceLocator;
41 import org.kuali.ole.pojo.OleException;
42
43
44 import org.kuali.rice.core.api.criteria.QueryByCriteria;
45 import org.kuali.rice.krad.data.DataObjectService;
46 import org.kuali.rice.krad.service.BusinessObjectService;
47 import org.kuali.rice.kns.service.KNSServiceLocator;
48 import org.kuali.rice.krad.service.KRADServiceLocator;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.kuali.rice.core.api.config.property.ConfigContext;
52
53 import javax.jcr.Binary;
54 import javax.jcr.Node;
55 import javax.jcr.NodeIterator;
56 import javax.jcr.Session;
57 import java.io.ByteArrayInputStream;
58 import java.io.IOException;
59 import java.sql.*;
60 import java.text.DateFormat;
61 import java.text.SimpleDateFormat;
62 import java.util.*;
63 import java.util.Date;
64
65
66
67
68
69
70
71 public class RebuildIndexesHandler
72 implements Runnable {
73
74 private static final Logger LOG = LoggerFactory.getLogger(RebuildIndexesHandler.class);
75 private static RebuildIndexesHandler reBuilder = null;
76 private boolean isRunning = false;
77 private boolean isStop = false;
78 private static final Logger logger = LoggerFactory.getLogger(RebuildIndexesHandler.class);
79 private String docCategory;
80 private String docType;
81 private String docFormat;
82
83
84 private int batchSize;
85
86 public static String EXCEPION_FILE_NAME = "";
87 public static String STATUS_FILE_NAME = "";
88 private String filePath = System.getProperty("solr.solr.home");
89 public synchronized void setRunning(boolean running) {
90 isRunning = running;
91 }
92
93 public synchronized void setStop(boolean stop) {
94 isStop = stop;
95 }
96
97 private RebuildIndexesHandler() {
98
99 }
100
101 public static RebuildIndexesHandler getInstance() {
102 if (reBuilder == null) {
103 reBuilder = new RebuildIndexesHandler();
104 }
105 return reBuilder;
106 }
107
108
109
110
111
112
113 public synchronized boolean isRunning() {
114 return isRunning;
115 }
116
117 public synchronized boolean isStop() {
118 return isStop;
119 }
120
121
122
123
124 public String startProcess(String docCategory, String docType, String docFormat) throws InterruptedException {
125 String status = null;
126 if (isRunning()) {
127 status = "ReIndexing process is already running. Click 'Show Status' button to know the status. ";
128 } else {
129 setRunning(true);
130 setStop(false);
131 status = "ReIndexing process has started. Click 'Show Status' button to know the status. ";
132 ReIndexingStatus reIndexingStatus = ReIndexingStatus.getInstance();
133 reIndexingStatus.reset();
134 if (docCategory == null || docCategory.equals("")) {
135 docCategory = "all";
136 }
137 if (docType == null || docType.equals("")) {
138 docType = "all";
139 }
140 if (docFormat == null || docType.equals("")) {
141 docFormat = "all";
142 }
143 this.docCategory = docCategory;
144 this.docType = docType;
145 this.docFormat = docFormat;
146 Thread reBuilderThread = new Thread(this);
147 reBuilderThread.start();
148
149 setRunning(false);
150 }
151 return status;
152 }
153 public String startProcess(String docCategory, String docType, String docFormat, int batchSize) throws InterruptedException {
154 String status = null;
155 if (isRunning()) {
156 status = "ReIndexing process is already running. Click 'Show Status' button to know the status. ";
157 } else {
158 setRunning(true);
159 setStop(false);
160 status = "ReIndexing process has started. Click 'Show Status' button to know the status. ";
161 ReIndexingStatus reIndexingStatus = ReIndexingStatus.getInstance();
162 reIndexingStatus.reset();
163 if (docCategory == null || docCategory.equals("")) {
164 docCategory = "all";
165 }
166 if (docType == null || docType.equals("")) {
167 docType = "all";
168 }
169 if (docFormat == null || docType.equals("")) {
170 docFormat = "all";
171 }
172 this.docCategory = docCategory;
173 this.docType = docType;
174 this.docFormat = docFormat;
175 this.batchSize = batchSize;
176 Thread reBuilderThread = new Thread(this);
177 reBuilderThread.start();
178
179 setRunning(false);
180 }
181 return status;
182 }
183
184 public String stopProcess() throws Exception {
185 String status = null;
186 if (isRunning()) {
187 status = "ReIndexing process is running. ReIndexing will stop after current batch. ";
188 setStop(true);
189 setRunning(false);
190 } else {
191 status = "ReIndexing process is not running.";
192 }
193 return status;
194
195 }
196
197 public void run() {
198 DocCategoryTypeFormat docCategoryTypeFormat = new DocCategoryTypeFormat();
199 List<String> categoryList = docCategoryTypeFormat.getCategories();
200 List<String> typeList = null;
201 List<String> formatList = null;
202 for (String docCategoryCurr : categoryList) {
203 if (docCategory.equals("all") || docCategory.equals(docCategoryCurr)) {
204 typeList = docCategoryTypeFormat.getDocTypes(docCategoryCurr);
205 for (String docTypeCurr : typeList) {
206 if (docType.equals("all") || docType.equals(docTypeCurr)) {
207 formatList = docCategoryTypeFormat.getDocFormats(docCategoryCurr, docTypeCurr);
208 for (String docFormatCurr : formatList) {
209 if (docFormat.equals("all") || docFormat.equals(docFormatCurr)) {
210 if (!isStop()) {
211 ReIndexingStatus.getInstance()
212 .startDocType(docCategoryCurr, docTypeCurr, docFormatCurr);
213 reIndex(docCategoryCurr, docTypeCurr, docFormatCurr);
214 } else {
215 return;
216 }
217 }
218 }
219 }
220 }
221 }
222 }
223 setRunning(false);
224 }
225
226 private void reIndex(String docCategory, String docType, String docFormat) {
227 Session session = null;
228 setRunning(true);
229 logger.info("Rebuild Indexes Run(" + docCategory + " : " + docType + " : " + docFormat + "): ");
230 try {
231 if (docCategory.equals(DocCategory.WORK.getCode())) {
232 if (docType.equals(DocType.BIB.getDescription())) {
233 if (docFormat.equals(DocFormat.MARC.getCode()) || docFormat.equals(DocFormat.DUBLIN_CORE.getCode())
234 || docFormat.equals(DocFormat.DUBLIN_UNQUALIFIED.getCode())) {
235 org.springframework.util.StopWatch stopWatch = new org.springframework.util.StopWatch();
236 stopWatch.start("total time taken");
237 Date date = new Date();
238 EXCEPION_FILE_NAME = "ReindexErrors-" + date.toString() + ".txt";
239 STATUS_FILE_NAME = "ReindexBatchStatus-" + date.toString() + ".txt";
240 BatchBibTreeDBUtil.writeStatusToFile(filePath, RebuildIndexesHandler.EXCEPION_FILE_NAME, "Reindex started at:" + date);
241 BibHoldingItemReindexer bibHoldingItemReindexer = BibHoldingItemReindexer.getInstance();
242 bibHoldingItemReindexer.index(batchSize);
243 date = new Date();
244 BatchBibTreeDBUtil.writeStatusToFile(filePath, RebuildIndexesHandler.EXCEPION_FILE_NAME, "Reindex ended at:" + date);
245 stopWatch.stop();
246 logger.info(stopWatch.prettyPrint());
247
248 } else {
249 logger.info(
250 "Rebuild Indexes Run(" + docCategory + " : " + docType + " : " + docFormat + "): FAIL");
251 }
252 } else if (docType.equals(DocType.INSTANCE.getDescription())) {
253 if (docFormat.equals(DocFormat.OLEML.getCode())) {
254 workInstanceOLEML(docCategory, docType, docFormat);
255 } else {
256 logger.info(
257 "Rebuild Indexes Run(" + docCategory + " : " + docType + " : " + docFormat + "): FAIL");
258 }
259 } else if (docType.equals(DocType.LICENSE.getDescription())) {
260 if (docFormat.equals(DocFormat.ONIXPL.getCode()) || docFormat.equals(DocFormat.PDF.getCode())
261 || docFormat.equals(DocFormat.DOC.getCode())) {
262 workLicense(docCategory, docType, docFormat);
263 } else {
264 logger.info(
265 "Rebuild Indexes Run(" + docCategory + " : " + docType + " : " + docFormat + "): FAIL");
266 }
267 } else if (docType.equals(DocType.EINSTANCE.getCode())) {
268 if (docFormat.equals(DocFormat.OLEML.getCode())) {
269 workEInstanceOLEML(docCategory, docType, docFormat);
270 } else {
271 logger.info(
272 "Rebuild Indexes Run(" + docCategory + " : " + docType + " : " + docFormat + "): FAIL");
273 }
274 }
275 }
276 } catch (Exception e) {
277 logger.info(e.getMessage(), e);
278 } finally {
279 try {
280 if (isStop) {
281 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Stopped");
282 } else {
283 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Done");
284 }
285 RepositoryManager.getRepositoryManager().logout(session);
286 } catch (OleException e) {
287 logger.error(e.getMessage(), e);
288 }
289 }
290
291 }
292
293 private void workEInstanceOLEML(String docCategory, String docType, String docFormat) {
294 long totalCount = 0;
295 long nodeCount = 0;
296
297 WorkEInstanceOlemlRecordProcessor workEInstanceOlemlRecordProcessor = new WorkEInstanceOlemlRecordProcessor();
298 try {
299
300
301
302
303 List<ReIndexingBatchStatus> batchStatusList = new ArrayList<ReIndexingBatchStatus>();
304 DataObjectService dataObjectService = KRADServiceLocator.getDataObjectService();
305 List<EInstanceRecord> instanceRecords = (List<EInstanceRecord>) dataObjectService.findMatching(EInstanceRecord.class, QueryByCriteria.Builder.create().build()).getResults();
306 StopWatch loadTimer = new StopWatch();
307 StopWatch batchTimer = new StopWatch();
308 loadTimer.start();
309 batchTimer.start();
310 for (int i = 0; i < instanceRecords.size(); i++) {
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341 }
342
343
344
345
346
347 } catch (Exception e) {
348
349
350
351 } finally {
352 if (isStop) {
353 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Stopped");
354 } else {
355 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Done");
356 }
357 }
358
359 }
360
361
362 private void indexBibDocs(List<BibTree> bibTreeList, long records, long recCount,
363 List<ReIndexingBatchStatus> batchStatusList, ReIndexingBatchStatus reIndexingBatchStatus) {
364 StopWatch indexTimer = new StopWatch();
365 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
366 try {
367 Date startDate = new Date();
368 reIndexingBatchStatus.setBatchStartTime(dateFormat.format(startDate));
369 indexTimer.start();
370 reIndexingBatchStatus.setStatus("Indexing");
371 reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
372 reIndexingBatchStatus.setRecordsProcessed(records);
373 reIndexingBatchStatus.setBatchEndTime(" ");
374 batchStatusList.add(reIndexingBatchStatus);
375 ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
376 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
377 BibTrees bibTrees = new BibTrees();
378 bibTrees.getBibTrees().addAll(bibTreeList);
379 documentIndexer.createTrees(bibTrees);
380
381 indexTimer.stop();
382 Date endDate = new Date();
383 reIndexingBatchStatus.setBatchEndTime(dateFormat.format(endDate));
384 reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
385 reIndexingBatchStatus.setRecordsProcessed(records);
386 reIndexingBatchStatus.setStatus("Done");
387 reIndexingBatchStatus.setRecordsRemaining(recCount - records);
388 ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
389 bibTreeList.clear();
390 } catch (Exception e) {
391 String firstBibId = bibTreeList.get(0).getBib().getId();
392 String lastBibId = bibTreeList.get(bibTreeList.size()-1).getBib().getId();
393 logger.error(
394 "Rebuild Indexes Process(" + docCategory + " : " + docType + " : " + docFormat + ") Processed(" + (
395 records - bibTreeList.size()) + "), Failed @ bibId( First BibId: " + firstBibId + " : Last BibId : "+ lastBibId +"): Cause: " + e, e);
396 indexTimer.stop();
397 Date endDate = new Date();
398 reIndexingBatchStatus.setBatchEndTime(dateFormat.format(endDate));
399 reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
400 reIndexingBatchStatus.setRecordsProcessed(0L);
401 reIndexingBatchStatus.setStatus("Done");
402 reIndexingBatchStatus.setRecordsRemaining(recCount - records);
403 ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
404 bibTreeList.clear();
405 }
406 }
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441 private void workBibMarcAndDublinAll(String docCategory, String docType, String docFormat) throws SolrServerException, IOException {
442 long totalCount = 0;
443 long nodeCount = 0;
444 int start = 0;
445 String sqlQuery = null;
446 long startTime = 0;
447 long commitEndTime = 0;
448 long commitStartTime = 0;
449 int batchSize = 50000;
450 int commitSize = 50000;
451 long endIndexBatch = 0;
452 String dbVendor = ConfigContext.getCurrentContextConfig().getProperty("db.vendor");
453 List<BibTree> bibTrees = new ArrayList<BibTree>();
454
455 try {
456 String prefix = DocumentUniqueIDPrefix.getPrefix(docCategory, docType, docFormat);
457 Map prefixMap = new HashMap(0);
458 prefixMap.put("uniqueIdPrefix", prefix);
459 startTime = System.currentTimeMillis();
460
461 BusinessObjectService dataObjectService = KNSServiceLocator.getBusinessObjectService();
462 int bibCount = dataObjectService.countMatching(BibRecord.class, prefixMap);
463 Connection connection = null;
464 PreparedStatement preparedStatement = null;
465 if (bibCount > 0) {
466 connection = getConnection();
467 if (dbVendor.equalsIgnoreCase("mysql")) {
468 sqlQuery = "select * from ole_ds_bib_t b ORDER BY b.bib_id LIMIT ?,?";
469 } else {
470 sqlQuery = "select * from (select b.*,ROWNUM r from OLE_DS_BIB_T b) where r between ? and ?";
471 }
472 preparedStatement = connection.prepareStatement(sqlQuery);
473 }
474 List<ReIndexingBatchStatus> batchStatusList = new ArrayList<ReIndexingBatchStatus>();
475 StopWatch loadTimer = new StopWatch();
476 StopWatch batchTimer = new StopWatch();
477 loadTimer.start();
478 batchTimer.start();
479
480 for (int i = 0; i < bibCount; i++) {
481 if (bibTrees.size() == batchSize) {
482 if (!isStop()) {
483
484 ReIndexingBatchStatus reIndexingBatchStatus = indexBeforeParams(loadTimer);
485 indexBibDocs(bibTrees, totalCount, nodeCount, batchStatusList, reIndexingBatchStatus);
486 indexAfterParams(batchTimer, reIndexingBatchStatus, batchStatusList);
487 resetTimers(batchTimer, loadTimer);
488 totalCount = 0;
489 logger.info("Rebuild");
490 i = start;
491 if (start % commitSize == 0) {
492 commitStartTime = System.currentTimeMillis();
493 logger.info("Time elapsed since start ====>>>>>> " + (commitStartTime - startTime));
494 logger.info("Time elapsed since last commit ====>>>>>> " + (commitStartTime - commitEndTime));
495 logger.info("commit started ====>>>>>> " + commitStartTime);
496 SolrServer solr = SolrServerManager.getInstance().getSolrServer();
497 solr.commit();
498 logger.info("No..of records committed ====>>>>>> " + start);
499 commitEndTime = System.currentTimeMillis();
500 logger.info("Time Taken for commit ====>>>>>> " + (commitEndTime - commitStartTime));
501
502 }
503 } else {
504 return;
505 }
506 } else {
507 if (start < bibCount) {
508 long b2time = System.currentTimeMillis();
509 if (dbVendor.equalsIgnoreCase("mysql")) {
510 preparedStatement.setInt(1, start);
511 preparedStatement.setInt(2, batchSize);
512 } else {
513 preparedStatement.setInt(1, start + 1);
514 preparedStatement.setInt(2, start + batchSize);
515 }
516 ResultSet resultSet = preparedStatement.executeQuery();
517 logger.info("time taking for getting records from DB end======>>>>>" + (System.currentTimeMillis() - b2time));
518 while (resultSet.next()) {
519
520 BibTree bibTree = new BibTree();
521 bibTree.setCategory(docCategory);
522 bibTree.setType(docType);
523 bibTree.setFormat(docFormat);
524 Bib bib = new BibMarc();
525 bib.setCategory(docCategory);
526 bib.setType(docType);
527 bib.setFormat(docFormat);
528 bib.setCreatedBy(resultSet.getString("CREATED_BY"));
529 bib.setCreatedOn(resultSet.getString("DATE_CREATED"));
530 bib.setStaffOnly((resultSet.getString("STAFF_ONLY").equalsIgnoreCase("Y") ? Boolean.TRUE : Boolean.FALSE));
531 bib.setContent(resultSet.getString("CONTENT"));
532 bib.setUpdatedBy(resultSet.getString("UPDATED_BY"));
533 bib.setUpdatedOn(resultSet.getString("DATE_UPDATED"));
534 bib.setLastUpdated(resultSet.getString("DATE_UPDATED"));
535 bib.setStatus(resultSet.getString("STATUS"));
536 bib.setStatusUpdatedBy(resultSet.getString("STATUS_UPDATED_BY"));
537 bib.setStatusUpdatedOn(resultSet.getString("STATUS_UPDATED_DATE"));
538 String uuid = DocumentUniqueIDPrefix.getPrefixedId(resultSet.getString("UNIQUE_ID_PREFIX"), resultSet.getString(1));
539 bib.setId(uuid);
540 bib.setLocalId(uuid);
541 bibTree.setBib(bib);
542
543 start++;
544 totalCount++;
545 bibTrees.add(bibTree);
546 }
547 resultSet.close();
548 }
549 }
550
551 }
552 if (bibTrees.size() > 0 && !isStop()) {
553 ReIndexingBatchStatus reIndexingBatchStatus = indexBeforeParams(loadTimer);
554 indexBibDocs(bibTrees, totalCount, nodeCount, batchStatusList, reIndexingBatchStatus);
555 indexAfterParams(batchTimer, reIndexingBatchStatus, batchStatusList);
556 commitStartTime = System.currentTimeMillis();
557 logger.info("commit started : ----> " + commitStartTime);
558 SolrServer solr = SolrServerManager.getInstance().getSolrServer();
559 solr.commit();
560 logger.info("No..of records committed : ----> " + start);
561 commitEndTime = System.currentTimeMillis();
562 logger.info("Time Taken for commit ======>>> " + (commitEndTime - commitStartTime));
563
564 }
565 endIndexBatch = System.currentTimeMillis();
566 logger.info("Time elapsed since end ====>>>>>> " + endIndexBatch);
567 } catch (Exception e) {
568 logger.error(
569 "Rebuild Indexes Process(" + docCategory + " : " + docType + " : " + docFormat + ") Processed(" + (
570 totalCount - bibTrees.size()) + "), Failed @ batch(" + bibTrees.size() + "): Cause: " + e, e);
571 } finally {
572 if (isStop) {
573 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Stopped");
574 } else {
575 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Done");
576 }
577 }
578 }
579
580 private void workInstanceOLEML(String docCategory, String docType, String docFormat) {
581 long totalCount = 0;
582 long nodeCount = 0;
583
584 InstanceOlemlRecordProcessor instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
585 try {
586
587
588
589
590 List<ReIndexingBatchStatus> batchStatusList = new ArrayList<ReIndexingBatchStatus>();
591 DataObjectService dataObjectService = KRADServiceLocator.getDataObjectService();
592 List<InstanceRecord> instanceRecords = (List<InstanceRecord>) dataObjectService.findMatching(InstanceRecord.class,QueryByCriteria.Builder.create().build()).getResults();
593 StopWatch loadTimer = new StopWatch();
594 StopWatch batchTimer = new StopWatch();
595 loadTimer.start();
596 batchTimer.start();
597 for (int i = 0; i < instanceRecords.size(); i++) {
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632 }
633
634
635
636
637
638 } catch (Exception e) {
639
640
641
642 } finally {
643 if (isStop) {
644 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Stopped");
645 } else {
646 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Done");
647 }
648 }
649 }
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752 private boolean checkApplicability(Object value, Object fieldValue) {
753 if (fieldValue instanceof Collection) {
754 for (Object object : (Collection) fieldValue) {
755 if (object.equals(value)) {
756 return true;
757 }
758 }
759 return false;
760 } else {
761 return value.equals(fieldValue);
762 }
763 }
764
765
766 private String compareListRString(Object id) {
767 if (id != null) {
768 if (id instanceof List) {
769 List<String> idList = (List<String>) id;
770 return idList.get(0);
771 } else if (id instanceof String) {
772 String strId = (String) id;
773 return strId;
774 }
775 }
776 return null;
777 }
778
779 private void compareObjNAddValue(String id, Object idObj, SolrDocument solrDoc, String identifier) {
780 if (idObj != null) {
781 if (idObj instanceof List) {
782 List<String> instBibIdList = (List<String>) idObj;
783 if (!instBibIdList.contains(id)) {
784 solrDoc.addField(identifier, id);
785 }
786 } else if (idObj instanceof String) {
787 String instBibId = (String) idObj;
788 if (!instBibId.equalsIgnoreCase(id)) {
789 solrDoc.addField(identifier, id);
790 }
791 }
792 } else {
793 solrDoc.addField(identifier, id);
794 }
795 }
796
797 private void workLicense(String docCategory, String docType, String docFormat) {
798 Session session = null;
799 long totalCount = 0;
800 long nodeCount = 0;
801
802 try {
803 session = RepositoryManager.getRepositoryManager().getSession(ProcessParameters.BULK_DEFAULT_USER,
804 ProcessParameters.BULK_DEFUALT_ACTION);
805
806
807
808
809
810 Node nodeFormat = null;
811 NodeIterator nodesL1 = nodeFormat.getNodes();
812 List<ReIndexingBatchStatus> batchStatusList = new ArrayList<ReIndexingBatchStatus>();
813 StopWatch loadTimer = new StopWatch();
814 StopWatch batchTimer = new StopWatch();
815 loadTimer.start();
816 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
817 while (nodesL1.hasNext()) {
818 Node nodeL1 = nodesL1.nextNode();
819 NodeIterator nodesFile = nodeL1.getNodes();
820 nodeCount = nodesFile.getSize();
821 batchTimer.start();
822 while (nodesFile.hasNext()) {
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855 }
856 }
857
858
859
860
861
862 } catch (Exception e) {
863
864
865
866 } finally {
867 try {
868 if (isStop) {
869 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Stopped");
870 } else {
871 ReIndexingStatus.getInstance().getDocTypeList().setStatus("Done");
872 }
873 RepositoryManager.getRepositoryManager().logout(session);
874 } catch (OleException e) {
875 logger.error(e.getMessage(), e);
876 }
877 }
878 }
879
880 private void resetTimers(StopWatch batchTimer, StopWatch loadTimer) {
881 batchTimer.reset();
882 batchTimer.start();
883 loadTimer.reset();
884 loadTimer.start();
885 }
886
887 private void indexAfterParams(StopWatch batchTimer, ReIndexingBatchStatus reIndexingBatchStatus,
888 List<ReIndexingBatchStatus> batchStatusList) {
889 batchTimer.stop();
890 reIndexingBatchStatus.setBatchTotalTime(batchTimer.toString());
891 ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
892 }
893
894 private ReIndexingBatchStatus indexBeforeParams(StopWatch loadTimer) {
895 loadTimer.stop();
896 ReIndexingBatchStatus reIndexingBatchStatus = new ReIndexingBatchStatus();
897 reIndexingBatchStatus.setBatchTotalTime(" ");
898 reIndexingBatchStatus.setBatchLoadTime(loadTimer.toString());
899 return reIndexingBatchStatus;
900 }
901
902
903
904
905
906 public Connection getConnection() {
907 Connection connection = null;
908 try {
909
910
911
912 String connectionUrl = ConfigContext.getCurrentContextConfig().getProperty("datasource.url");
913 String userName = ConfigContext.getCurrentContextConfig().getProperty("datasource.username");
914 String passWord = ConfigContext.getCurrentContextConfig().getProperty("datasource.password");
915 String driverName = ConfigContext.getCurrentContextConfig().getProperty("jdbc.driver");
916 Class.forName(driverName);
917 connection = DriverManager.getConnection(connectionUrl, userName, passWord);
918 } catch (Exception e) {
919 LOG.error("Exception : ", e);
920 }
921 return connection;
922 }
923
924 public String showStatus() {
925 BibHoldingItemReindexer bibHoldingItemReindexer = BibHoldingItemReindexer.getInstance();
926 return bibHoldingItemReindexer.showStats();
927 }
928 }