1   package org.kuali.ole.service.impl;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.BibliographicRecordHandler;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.OleItemRecordHandler;
7   import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
8   import org.kuali.ole.docstore.common.document.content.instance.*;
9   import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
10  import org.kuali.ole.docstore.model.xmlpojo.ingest.Content;
11  import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
12  import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
13  import org.kuali.ole.docstore.common.document.content.bib.marc.DataField;
14  import org.kuali.ole.docstore.common.document.content.bib.marc.SubField;
15  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
16  import org.kuali.ole.docstore.common.document.content.instance.xstream.InstanceOlemlRecordProcessor;
17  
18  import org.kuali.ole.ingest.pojo.OleDataField;
19  import org.kuali.ole.ingest.pojo.OverlayOption;
20  import org.kuali.ole.service.OverlayDataFieldService;
21  import org.kuali.ole.service.OverlayHelperService;
22  import org.kuali.ole.service.OverlayLookupTableService;
23  import org.kuali.ole.service.OverlayRetrivalService;
24  import org.kuali.ole.util.StringUtil;
25  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26  
27  import java.util.*;
28  
29  
30  
31  
32  
33  
34  
35  
36  public class OverlayHelperServiceImpl implements OverlayHelperService {
37  
38      private static final Logger LOG = Logger.getLogger(OverlayHelperServiceImpl.class);
39      private BibliographicRecordHandler bibliographicRecordHandler;
40      private OleItemRecordHandler oleItemRecordHandler;
41      private InstanceOlemlRecordProcessor instanceOlemlRecordProcessor;
42      private HoldingOlemlRecordProcessor holdingOlemlRecordProcessor;
43      private ItemOlemlRecordProcessor itemOlemlRecordProcessor;
44      private OverlayRetrivalService overlayRetrivalService;
45      private OverlayDataFieldService overlayDataFieldService;
46      private OverlayLookupTableService overlayLookupTableService;
47      private List<String> gPFList;
48      private boolean isIgnoreGPF;
49  
50  
51      private String getResponseContent(Response response){
52          String responseString = null;
53          List<ResponseDocument> responseDocumentList = response.getDocuments();
54          for(ResponseDocument responseDocument : responseDocumentList){
55              Content contentObj = responseDocument.getContent();
56              responseString = contentObj.getContent();
57          }
58          return responseString;
59      }
60  
61      private InstanceCollection updateInstance(InstanceCollection oldInstanceCollection,InstanceCollection newInstanceCollection)throws Exception{
62          List<Instance> oldInstanceList = oldInstanceCollection.getInstance();
63          List<Instance> newInstanceList = newInstanceCollection.getInstance();
64          OleHoldings oldOleHoldings = null;
65          List<Item> oldItemList = null;
66          OleHoldings newOleHoldings = null;
67          List<Item> newItemList = null;
68          for(Instance oldInstance : oldInstanceList){
69              oldOleHoldings = oldInstance.getOleHoldings();
70              Items oldItems = oldInstance.getItems();
71              oldItemList = oldItems.getItem();
72          }
73          for(Instance newInstance : newInstanceList){
74              newOleHoldings = newInstance.getOleHoldings();
75              Items newItems = newInstance.getItems();
76              newItemList = newItems.getItem();
77          }
78          updateInstanceHolding(oldOleHoldings,newOleHoldings);
79          updateMatchedItem(oldItemList,newItemList);
80          return oldInstanceCollection;
81      }
82  
83      private void updateInstanceHolding(OleHoldings oldOleHoldings,OleHoldings newOleHoldings)throws Exception{
84  
85  
86  
87          if(newOleHoldings.getCallNumber()!=null){
88              oldOleHoldings.setCallNumber(newOleHoldings.getCallNumber());
89          }
90          if(newOleHoldings.getExtension()!=null){
91              oldOleHoldings.setExtension(newOleHoldings.getExtension());
92          }
93      }
94  
95      private void updateMatchedItem(List<Item> oldItemList,List<Item> newItemList)throws Exception{
96          List<Item> matchedItemList = new ArrayList<Item>();
97          List<Item> umMatchedItemList = new ArrayList<Item>();
98          for(Item oldItem : oldItemList){
99              for(Item newItem : newItemList){
100                 updateInstanceItem(oldItem,newItem);
101             }
102         }
103     }
104 
105     private void updateInstanceItem(Item oldItem,Item newItem)throws Exception{
106         if(newItem.getAccessInformation()!=null){
107             oldItem.getAccessInformation().setUri(newItem.getAccessInformation().getUri());
108         }
109         if(newItem.getBarcodeARSL()!=null){
110             oldItem.setBarcodeARSL(newItem.getBarcodeARSL());
111         }
112         if(newItem.getStatisticalSearchingCode()!=null){
113             oldItem.setStatisticalSearchingCode(newItem.getStatisticalSearchingCode());
114         }
115         if(newItem.getItemType()!=null){
116             oldItem.setItemType(newItem.getItemType());
117         }
118         if(newItem.getLocation()!=null){
119             oldItem.getLocation().setStatus(newItem.getLocation().getStatus());
120         }
121         if(newItem.getCallNumber()!=null){
122             oldItem.setCallNumber(newItem.getCallNumber());
123         }
124         if(newItem.getExtension()!=null){
125             oldItem.setExtension(newItem.getExtension());
126         }
127     }
128 
129 
130     @Override
131     public String updateInstanceToDocstore(String instanceUUID, InstanceCollection oldInstanceCollection, InstanceCollection newInstanceCollection) throws Exception {
132         return null;  
133     }
134 
135     public String getUUID(Response response, String docType) throws Exception{
136         List<ResponseDocument> documents = response.getDocuments();
137         return getUUID(documents, docType);
138     }
139 
140     private String getUUID(List<ResponseDocument> documents, String docType)throws Exception{
141         String uuid = null;
142         for (Iterator<ResponseDocument> iterator = documents.iterator(); iterator.hasNext(); ) {
143             ResponseDocument responseDocument = iterator.next();
144             if (responseDocument.getType().equals(docType)) {
145                 uuid = responseDocument.getUuid();
146             } else {
147                 uuid = getUUID(responseDocument.getLinkedDocuments(), docType);
148             }
149         }
150         return uuid;
151     }
152 
153 
154     public BibMarcRecord updateBibMarcRecordIncludingGPF(BibMarcRecord oldBibMarcRecord, BibMarcRecord newBibMarcRecord,List<String> gpfFieldList,List<OverlayOption> overlayOptionList)throws Exception{
155         List<DataField> oldDatafields = oldBibMarcRecord.getDataFields();
156         List<DataField> newDatafields = newBibMarcRecord.getDataFields();
157         BibMarcRecord updatedBibMarcRecord = oldBibMarcRecord;
158         OverlayOption deleteOverlayOption = getOverlayRetrivalService().getDeleteOverlayOptionWithWildCardSearch(newDatafields, overlayOptionList);
159         List<DataField> updatedDatafieldList = null;
160         updatedDatafieldList = addAllDataFieldsAndSubFields(oldDatafields, newDatafields);
161         oldDatafields = updatedDatafieldList != null?updatedDatafieldList:oldDatafields;
162         isIgnoreGPF = true;
163         updatedDatafieldList = deleteOverlayOptionDataField(oldDatafields,deleteOverlayOption);
164         updatedBibMarcRecord.setDataFields(updatedDatafieldList);
165         return updatedBibMarcRecord;
166     }
167 
168 
169     public BibMarcRecord updateBibMarcRecordExcludingGPF(BibMarcRecord oldBibMarcRecord, BibMarcRecord newBibMarcRecord,List<String> gpfFieldList,List<OverlayOption> overlayOptionList)throws Exception{
170         List<DataField> oldDatafields = oldBibMarcRecord.getDataFields();
171         List<DataField> newDatafields = newBibMarcRecord.getDataFields();
172         BibMarcRecord updatedBibMarcRecord = oldBibMarcRecord;
173         OverlayOption deleteOverlayOption = getOverlayRetrivalService().getDeleteOverlayOptionWithWildCardSearch(newDatafields, overlayOptionList);
174         LinkedHashMap<String,String> updationDataFieldMap = new LinkedHashMap<String,String>();
175         LinkedHashMap<String,String> gpfMap = getGPFMap(oldDatafields, gpfFieldList);
176         List<DataField> updatedDatafieldList = null;
177         isIgnoreGPF = false;
178         gPFList = gpfFieldList;
179         oldDatafields = excludeGPF(oldDatafields,gpfMap,true,updationDataFieldMap);
180         newDatafields = excludeGPF(newDatafields,gpfMap,false,updationDataFieldMap);
181         updatedDatafieldList = addAllDataFieldsAndSubFields(oldDatafields, newDatafields);
182         updatedDatafieldList = deleteOverlayOptionDataField(oldDatafields,deleteOverlayOption);
183         updatedBibMarcRecord.setDataFields(updatedDatafieldList);
184         
185         return updatedBibMarcRecord;
186     }
187 
188     private List<DataField> addAllDataFields(List<DataField> oldDatafields,List<DataField> newDatafields)throws Exception{
189         LinkedHashMap<String,DataField> oldDataFieldValueMap = getOverlayDataFieldService().getDataFieldValueMap(oldDatafields);
190         LinkedHashMap<String,DataField> newDataFieldValueMap = getOverlayDataFieldService().getDataFieldValueMap(newDatafields);
191         String updationField = null;
192         for(Map.Entry<String,DataField> newDataFieldEntry : newDataFieldValueMap.entrySet()){
193             updationField = newDataFieldEntry.getKey();
194             if(LOG.isDebugEnabled()){
195                 LOG.debug("updationField------------->"+updationField);
196             }
197             if(oldDataFieldValueMap.containsKey(updationField)==false){
198                 oldDatafields.add(newDataFieldValueMap.get(updationField));
199             }
200         }
201         return oldDatafields;
202     }
203 
204     private List<DataField> addAllDataFieldsAndSubFields(List<DataField> oldDatafields,List<DataField> newDatafields)throws Exception{
205         LinkedHashMap<String,DataField> oldDataFieldMap = getOverlayDataFieldService().getDataFieldValueMap(oldDatafields);
206         LinkedHashMap<String,DataField> newDataFieldMap = getOverlayDataFieldService().getDataFieldValueMap(newDatafields);
207         LinkedHashMap<String,SubField> oleSubFieldMap = getOverlayDataFieldService().getSubFieldValueMap(oldDatafields);
208         LinkedHashMap<String,SubField> newSubFieldMap = getOverlayDataFieldService().getSubFieldValueMap(newDatafields);
209         LinkedHashMap<String,SubField> newUpdateSubFieldMap = new LinkedHashMap<String,SubField>();
210         String fieldKey = null;
211         String tempFieldKey = null;
212         int fieldKeyLength;
213         
214         for(Map.Entry<String,DataField> newDataFieldEntry : newDataFieldMap.entrySet()){
215             fieldKey = newDataFieldEntry.getKey();
216             if(!oldDataFieldMap.containsKey(fieldKey)){
217                 oldDatafields.add(newDataFieldEntry.getValue());
218             }
219         }
220         
221         for(Map.Entry<String,SubField> newSubFieldEntry : newSubFieldMap.entrySet()){
222             fieldKey = newSubFieldEntry.getKey();
223             if(oleSubFieldMap.containsKey(fieldKey)){
224                 SubField oldSubField = oleSubFieldMap.get(fieldKey);
225                 SubField newSubField = newSubFieldEntry.getValue();
226                 oldSubField.setValue(newSubField.getValue());
227             }else{
228 
229 
230                 newUpdateSubFieldMap.put(fieldKey,newSubFieldEntry.getValue());
231             }
232 
233         }
234         for(Map.Entry<String,SubField> newUpdateSubField : newUpdateSubFieldMap.entrySet()){
235             fieldKey = newUpdateSubField.getKey();
236             fieldKeyLength = fieldKey.length();
237             tempFieldKey = fieldKey.substring(0,fieldKeyLength-2);
238             if(oldDataFieldMap.containsKey(tempFieldKey)){
239                 DataField dataField = oldDataFieldMap.get(tempFieldKey);
240                 List<SubField> subFieldList = dataField.getSubFields();
241                 subFieldList.add(newUpdateSubFieldMap.get(fieldKey));
242 
243             }
244         }
245         return oldDatafields;
246 
247     }
248 
249     private void updateSubfieldValues(List<DataField> oldDatafields,List<DataField> newDatafields)throws Exception{
250         LinkedHashMap<String,SubField> oldSubFieldValueMap = getOverlayDataFieldService().getSubFieldValueMap(oldDatafields);
251         LinkedHashMap<String,SubField> newSubFieldValueMap = getOverlayDataFieldService().getSubFieldValueMap(newDatafields);
252         String updationField = null;
253         for(Map.Entry<String,SubField> oleDataFieldEntry : oldSubFieldValueMap.entrySet()){
254             updationField = oleDataFieldEntry.getKey();
255             if(LOG.isDebugEnabled()){
256                 LOG.debug("updationField------------->"+updationField);
257             }
258             if(newSubFieldValueMap.containsKey(updationField)){
259                 SubField oldSubField = oleDataFieldEntry.getValue();
260                 SubField newSubField = newSubFieldValueMap.get(updationField);
261                 oldSubField.setValue(newSubField.getValue());
262             }
263         }
264     }
265 
266     private List<DataField> excludeGPF(List<DataField> datafieldList,List<String> gpfFieldList,boolean isOldRecord)throws Exception{
267         String tagFieldValue = null;
268         String firstIndicatorValue = null;
269         String secondIndicatorValue = null;
270         String subFieldValue = null;
271         String[] gpfFieldArr = null;
272         List<DataField> updatedDatafieldList = new ArrayList<DataField>();
273         List<SubField> updatedSubfieldList = null;
274         SubField previousSubField = null;
275         if(gpfFieldList.size()>0){
276             for(DataField dataField : datafieldList){
277                 updatedSubfieldList = new ArrayList<SubField>();
278                 for(SubField subField : dataField.getSubFields()){
279                     for(String gpfField :gpfFieldList){
280                         gpfFieldArr = gpfField.split(OLEConstants.DELIMITER_DASH);
281                         tagFieldValue = gpfFieldArr[0];
282                         firstIndicatorValue = gpfFieldArr[1];
283                         secondIndicatorValue = gpfFieldArr[2];
284                         subFieldValue = gpfFieldArr[3];
285                         
286                         if(!((dataField.getTag()+subField.getCode()).equals(tagFieldValue+subFieldValue))){
287                             if(previousSubField != subField){
288                                 updatedSubfieldList.add(subField);
289                             }
290                         }else if(((dataField.getTag()+subField.getCode()).equals(tagFieldValue+subFieldValue)) && isOldRecord){
291                             updatedSubfieldList.add(subField);
292                         }
293                         previousSubField = subField;
294                     }
295                 }
296                 dataField.setSubFields(updatedSubfieldList);
297                 updatedDatafieldList.add(dataField);
298             }
299         }else{
300             updatedDatafieldList = datafieldList;
301         }
302         return updatedDatafieldList;
303     }
304 
305 
306 
307 
308 
309 
310 
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     private List<DataField> excludeGPF(List<DataField> datafieldList,LinkedHashMap<String,String> gpfMap,boolean isOldRecord,LinkedHashMap<String,String> overlayOptionFieldMap)throws Exception{
347         String tagFieldValue = null;
348         String firstIndicator = null;
349         String secondIndicator = null;
350         String subFieldCode = null;
351         String[] gpfFieldArr = null;
352         String field = null;
353         boolean isGPF = false;
354         List<DataField> updatedDatafieldList = new ArrayList<DataField>();
355         List<SubField> updatedSubfieldList = null;
356         SubField previousSubField = null;
357         if(gpfMap!=null && gpfMap.size()>0 && !gpfMap.isEmpty()){
358             for(DataField dataField : datafieldList){
359                 updatedSubfieldList = new ArrayList<SubField>();
360                 for(SubField subField : dataField.getSubFields()){
361                     tagFieldValue = dataField.getTag();
362                     firstIndicator = dataField.getInd1()!=null? StringUtil.trimHashNullValues(dataField.getInd1()):OLEConstants.DELIMITER_HASH;
363                     secondIndicator = dataField.getInd2()!=null?StringUtil.trimHashNullValues(dataField.getInd2()):OLEConstants.DELIMITER_HASH;
364                     subFieldCode = subField.getCode().trim();
365                     field = tagFieldValue+firstIndicator+secondIndicator+OLEConstants.DELIMITER_DOLLAR+subFieldCode;
366                     if(LOG.isDebugEnabled()){
367                         LOG.debug("field------------>"+field);
368                         LOG.debug("gpfMap field------------>"+gpfMap.get(field));
369                     }
370                     if(!gpfMap.containsKey(field)){
371                         updatedSubfieldList.add(subField);
372                     }else if(gpfMap.containsKey(field) && isOldRecord && !overlayOptionFieldMap.containsKey(field)){
373                         
374                         
375                         updatedSubfieldList.add(subField);
376                     }
377                 }
378                 dataField.setSubFields(updatedSubfieldList);
379                 updatedDatafieldList.add(dataField);
380             }
381         }else{
382             updatedDatafieldList = datafieldList;
383         }
384         return updatedDatafieldList;
385     }
386 
387 
388 
389 
390 
391 
392 
393 
394 
395 
396 
397 
398 
399     private LinkedHashMap<String,String> getGPFMap(List<DataField> oldDatafields, List<String> gpfFieldList)throws Exception{
400         LinkedHashMap<String,String> gpfMap = new LinkedHashMap<String,String>();
401         gpfFieldList = checkWildCardSearchForGPF(oldDatafields, gpfFieldList);
402         for(String gpfField :gpfFieldList){
403             if(LOG.isDebugEnabled()){
404                 LOG.debug("gpfField in getGPFMap------------>" + gpfField);
405             }
406             gpfMap.put(gpfField,gpfField);
407         }
408         return gpfMap;
409     }
410 
411     List<String> checkWildCardSearchForGPF(List<DataField> oldDatafields, List<String> gpfFieldList) {
412         List<String> gpfUpdatedList = new ArrayList<String>();
413         for(String gpfFields : gpfFieldList){
414             if(gpfFields.contains("*")){
415                 char[] gpfFieldSplit = gpfFields.toCharArray();
416                 for(DataField oldDataField : oldDatafields) {
417                     boolean oldDataFieldStartsWith = oldDataField.getTag().startsWith(String.valueOf(gpfFieldSplit[0]));
418                     if(oldDataFieldStartsWith){
419                         gpfUpdatedList.add(oldDataField.getTag());
420                     }
421                 }
422             }
423             else {
424                 gpfUpdatedList.add(gpfFields);
425             }
426         }
427         return gpfUpdatedList;
428     }
429 
430     private List<DataField> addOverlayOptionDataField(List<DataField> datafieldList,OverlayOption overlayOption,HashMap<String,String> updationDataFieldMap)throws Exception{
431         List<DataField> updatedDatafieldList = datafieldList;
432         String tagFieldValue = null;
433         String firstIndicatorValue = null;
434         String secondIndicatorValue = null;
435         String subFieldCode = null;
436         Boolean isUpdationField = false;
437         List<OleDataField> addOleDataFieldList = overlayOption.getOleDataFields();
438         DataField addDataField = null;
439         List<SubField> subFieldList = null;
440         if(addOleDataFieldList!=null && addOleDataFieldList.size()>0){
441             for(OleDataField oleDataField : addOleDataFieldList){
442                 tagFieldValue =  oleDataField.getDataFieldTag();
443                 firstIndicatorValue = oleDataField.getDataFieldInd1();
444                 secondIndicatorValue = oleDataField.getDataFieldInd2();
445                 subFieldCode = oleDataField.getSubFieldCode();
446                 if(!(addDataField!=null && addDataField.getTag().equals(tagFieldValue))){
447                     addDataField = new DataField();
448                     addDataField.setTag(tagFieldValue);
449                     addDataField.setInd1(firstIndicatorValue);
450                     addDataField.setInd2(secondIndicatorValue);
451                     subFieldList = new ArrayList<SubField>();
452                     SubField addSubField = new SubField();
453                     addSubField.setCode(subFieldCode);
454                     subFieldList.add(addSubField);
455                     addDataField.setSubFields(subFieldList);
456                     updationDataFieldMap.put(tagFieldValue+OLEConstants.DELIMITER_DASH+firstIndicatorValue+OLEConstants.DELIMITER_DASH+secondIndicatorValue+OLEConstants.DELIMITER_DASH+subFieldCode,
457                             OLEConstants.OVERLAY_OPTION_ADD);
458                 }else{
459                     SubField addSubField = new SubField();
460                     addSubField.setCode(subFieldCode);
461                     subFieldList.add(addSubField);
462                     addDataField.setSubFields(subFieldList);
463                     updationDataFieldMap.put(tagFieldValue+OLEConstants.DELIMITER_DASH+firstIndicatorValue+OLEConstants.DELIMITER_DASH+secondIndicatorValue+OLEConstants.DELIMITER_DASH+subFieldCode,
464                             OLEConstants.OVERLAY_OPTION_ADD);
465                 }
466                 updatedDatafieldList.add(addDataField);
467             }
468         }
469         return updatedDatafieldList;
470     }
471 
472 
473 
474     private List<DataField> deleteOverlayOptionDataField(List<DataField> datafieldList,OverlayOption overlayOption)throws Exception{
475         LinkedHashMap<String,SubField> oldSubFieldValueMap = getOverlayDataFieldService().getSubFieldValueMap(datafieldList);
476         LinkedHashMap<String,SubField> updatedSubFieldValueMap = new LinkedHashMap<String, SubField>();
477         List<DataField> updatedDatafieldList = new ArrayList<DataField>();
478         List<SubField> updatedSubfieldList = null;
479         SubField previousSubField = null;
480         String tagFieldValue = null;
481         String firstIndicator = null;
482         String secondIndicator = null;
483         String subFieldCode = null;
484         if(overlayOption != null && overlayOption.getOleDataFields()!=null){
485             List<OleDataField> deleteOleDataFieldList = overlayOption.getOleDataFields();
486             DataField addDataField = null;
487             List<String> keySBList = new ArrayList<String>();
488             for(OleDataField oleDataField : deleteOleDataFieldList){
489                 tagFieldValue =  oleDataField.getDataFieldTag();
490                 firstIndicator = StringUtil.trimHashNullValues(oleDataField.getDataFieldInd1());
491                 secondIndicator = StringUtil.trimHashNullValues(oleDataField.getDataFieldInd2());
492                 subFieldCode = oleDataField.getSubFieldCode();
493                 StringBuffer keySB = new StringBuffer();
494                 keySB.append(tagFieldValue).append(firstIndicator)
495                        .append(secondIndicator).append(OLEConstants.DELIMITER_DOLLAR).append(subFieldCode);
496                 if(isIgnoreGPF){
497                     keySBList.add(keySB.toString());
498                 }
499                 else if(!gPFList.contains(keySB.toString())) {
500                     keySBList.add(keySB.toString());
501                 }
502             }
503             for(Map.Entry<String,SubField> oldSubFieldValueMapEntry : oldSubFieldValueMap.entrySet()){
504                 if(!keySBList.contains(oldSubFieldValueMapEntry.getKey())){
505                     updatedSubFieldValueMap.put(oldSubFieldValueMapEntry.getKey(),oldSubFieldValueMapEntry.getValue());
506                 }
507             }
508 
509             for(Map.Entry<String,SubField> updatedSubFieldValueMapEntry : updatedSubFieldValueMap.entrySet()){
510                 String dataFieldTags = updatedSubFieldValueMapEntry.getKey();
511                 String tag=dataFieldTags.substring(0,3);
512                 String ind1 = dataFieldTags.substring(3,4);
513                 String ind2 = dataFieldTags.substring(4,5);
514                 boolean flag=false;
515                 for(DataField dataField1:updatedDatafieldList){
516                     if (dataField1.getInd1().equals(ind1)&&dataField1.getInd2().equals(ind2)&&dataField1.getTag().equals(tag)){
517                         SubField newsubField=new SubField();
518                         newsubField.setCode(dataFieldTags.substring(6,7));
519                         newsubField.setValue(updatedSubFieldValueMapEntry.getValue().getValue());
520                         dataField1.getSubFields().add(newsubField);
521                         flag=true;
522                     }
523                 }
524                 if(flag==false){
525                     DataField newDataField = new DataField();
526                     newDataField.setTag(tag);
527                     newDataField.setInd1(ind1);
528                     newDataField.setInd2(ind2);
529 
530                     SubField newsubField=new SubField();
531                     newsubField.setCode(dataFieldTags.substring(6,7));
532                     newsubField.setValue(updatedSubFieldValueMapEntry.getValue().getValue());
533                     List<SubField> subFieldList=new ArrayList<SubField>();
534                     subFieldList.add(newsubField);
535 
536                     newDataField.setSubFields(subFieldList);
537                     updatedDatafieldList.add(newDataField);
538                 }
539             }
540             return updatedDatafieldList;
541         }else{
542             return null;
543         }
544     }
545 
546 
547     public OverlayRetrivalService getOverlayRetrivalService() {
548         if(overlayRetrivalService == null){
549             overlayRetrivalService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_RETRIVAL_SERVICE);
550         }
551         return overlayRetrivalService;
552     }
553 
554     public void setOverlayRetrivalService(OverlayRetrivalService overlayRetrivalService) {
555         this.overlayRetrivalService = overlayRetrivalService;
556     }
557 
558     public OverlayDataFieldService getOverlayDataFieldService() {
559         if(overlayDataFieldService == null){
560             overlayDataFieldService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_DATAFIELD_SERVICE);
561         }
562         return overlayDataFieldService;
563     }
564 
565     public void setOverlayDataFieldService(OverlayDataFieldService overlayDataFieldService) {
566         this.overlayDataFieldService = overlayDataFieldService;
567     }
568 
569     public OverlayLookupTableService getOverlayLookupTableService() {
570         if(overlayLookupTableService == null){
571             overlayLookupTableService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_LOOKUPTABLE_SERVICE);
572         }
573         return overlayLookupTableService;
574     }
575 
576     public void setOverlayLookupTableService(OverlayLookupTableService overlayLookupTableService) {
577         this.overlayLookupTableService = overlayLookupTableService;
578     }
579 
580     private BibliographicRecordHandler getBibliographicRecordHandler(){
581         if(bibliographicRecordHandler == null){
582             bibliographicRecordHandler = new BibliographicRecordHandler();
583         }
584         return bibliographicRecordHandler;
585     }
586 
587     private InstanceOlemlRecordProcessor getInstanceOlemlRecordProcessor() {
588         if(instanceOlemlRecordProcessor == null){
589             instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
590         }
591         return instanceOlemlRecordProcessor;
592     }
593 
594     private OleItemRecordHandler getOleItemRecordHandler() {
595         if(oleItemRecordHandler == null){
596             oleItemRecordHandler = new OleItemRecordHandler();
597         }
598         return oleItemRecordHandler;
599     }
600 
601     public HoldingOlemlRecordProcessor getHoldingOlemlRecordProcessor() {
602         if(holdingOlemlRecordProcessor == null){
603             holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
604         }
605         return holdingOlemlRecordProcessor;
606     }
607 
608     public ItemOlemlRecordProcessor getItemOlemlRecordProcessor() {
609         if(itemOlemlRecordProcessor == null){
610             itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
611         }
612         return itemOlemlRecordProcessor;
613     }
614 
615 }