1 package org.kuali.ole.batch.helper;
2
3 import org.kuali.ole.batch.bo.*;
4 import org.kuali.ole.batch.util.BatchBibImportUtil;
5 import org.kuali.ole.docstore.common.document.DocstoreDocument;
6 import org.kuali.ole.docstore.common.document.Holdings;
7 import org.kuali.ole.docstore.common.document.HoldingsTree;
8 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
9 import org.kuali.ole.docstore.common.document.content.bib.marc.DataField;
10 import org.kuali.ole.docstore.common.search.SearchParams;
11 import org.kuali.ole.docstore.model.enums.DocType;
12
13 import java.util.*;
14
15
16
17
18 public class BatchGOKbHelperService extends BatchBibImportHelper {
19
20
21 protected void applyBibDataMappingOverlay(BibMarcRecord bibRecord, OLEBatchProcessProfileBo profile) {
22
23 List<OLEBatchProcessBibDataMappingOverlay> oleBatchProcessBibDataMappingOverlays = profile.getOleBatchProcessBibDataMappingOverlayList();
24
25 Iterator<DataField> iterator = bibRecord.getDataFields().iterator();
26 while (iterator.hasNext()) {
27
28 DataField dataField = iterator.next();
29
30 OLEBatchProcessBibDataMappingOverlay matchedBibDataMappingOverlayField = getMatchedBibDataMappingOverlayField(dataField.getTag(), oleBatchProcessBibDataMappingOverlays);
31 if (matchedBibDataMappingOverlayField == null) {
32 iterator.remove();
33 }
34 }
35
36
37 List<String> addFieldsInOverlay = getAddDataFieldTags(profile.getOleBatchProcessBibDataMappingOverlayList());
38
39 for (String tag : addFieldsInOverlay) {
40 OLEBatchGloballyProtectedField oleBatchGloballyProtectedField = new OLEBatchGloballyProtectedField();
41 oleBatchGloballyProtectedField.setTag(tag);
42 profile.getOleBatchGloballyProtectedFieldList().add(oleBatchGloballyProtectedField);
43 }
44
45 }
46
47 private List<String> getAddDataFieldTags(List<OLEBatchProcessBibDataMappingOverlay> oleBatchProcessBibDataMappingOverlays) {
48 List<String> addFieldsInOverlay = new ArrayList<>();
49
50 for(OLEBatchProcessBibDataMappingOverlay oleBatchProcessBibDataMappingOverlay : oleBatchProcessBibDataMappingOverlays) {
51 if(oleBatchProcessBibDataMappingOverlay.getAddOrReplace().equalsIgnoreCase("add")) {
52 addFieldsInOverlay.add(oleBatchProcessBibDataMappingOverlay.getTag().substring(0,3));
53 }
54 }
55 return addFieldsInOverlay;
56 }
57
58 protected void applyBibDataMapping(BibMarcRecord bibRecord, OLEBatchProcessProfileBo profile) {
59
60 Iterator<DataField> iterator = bibRecord.getDataFields().iterator();
61
62 List<String> tags = new ArrayList<>();
63
64 for(OLEBatchProcessBibDataMappingNew oleBatchProcessBibDataMappingNew : profile.getOleBatchProcessBibDataMappingNewList()) {
65 tags.add(oleBatchProcessBibDataMappingNew.getTag().substring(0,3));
66 }
67
68 while(iterator.hasNext()) {
69
70 DataField dataField = iterator.next();
71 if(!dataField.getTag().equals(profile.getOleBatchProcessProfileMappingOptionsList().get(0).getOleBatchProcessProfileDataMappingOptionsBoList().get(0).getSourceField().substring(0, 3)) && !tags.contains(dataField.getTag())) {
72 iterator.remove();
73 }
74 }
75
76 }
77
78 protected void addSearchCondition(String fieldValue, SearchParams searchParams, OLEBatchProcessProfileMatchPoint matchPoint) {
79 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(DocType.BIB.getCode(), BatchBibImportUtil.getDataFieldWithout$(matchPoint.getMatchPoint()), fieldValue), "AND"));
80 }
81
82 private OLEBatchProcessBibDataMappingOverlay getMatchedBibDataMappingOverlayField(String tag, List<OLEBatchProcessBibDataMappingOverlay> oleBatchProcessBibDataMappingOverlayList) {
83
84 for (OLEBatchProcessBibDataMappingOverlay batchProcessBibDataMappingOverlay : oleBatchProcessBibDataMappingOverlayList) {
85 if(batchProcessBibDataMappingOverlay.getTag().substring(0,3).equals(tag)) {
86 return batchProcessBibDataMappingOverlay;
87 }
88 }
89
90 return null;
91
92 }
93
94 protected List<HoldingsTree> processMatchedEHoldings(BibMarcRecord bibRecord, OLEBatchProcessProfileBo profile, OLEBatchBibImportDataObjects oleBatchBibImportDataObjects, List<HoldingsTree> holdingsTrees, MatchingProfile matchingProfile, Holdings matchedHoldings, DataField eHoldingsDataField) {
95
96 holdingsTrees.addAll(buildEHoldingsTreesForBib(bibRecord, profile, false));
97
98 setHoldingsTreeOperations(holdingsTrees, DocstoreDocument.OperationType.CREATE, DocstoreDocument.OperationType.CREATE);
99
100
101 return holdingsTrees;
102 }
103
104
105 }