View Javadoc
1   package org.kuali.ole.service.impl;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.service.OverlayDataFieldService;
6   import org.kuali.ole.util.StringUtil;
7   
8   import java.util.HashMap;
9   import java.util.LinkedHashMap;
10  import java.util.List;
11  import java.util.TreeMap;
12  
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  
16  /**
17   * Created by IntelliJ IDEA.
18   * User: premkb
19   * Date: 2/3/13
20   * Time: 6:17 AM
21   * To change this template use File | Settings | File Templates.
22   */
23  public class OverlayDataFieldServiceImpl implements OverlayDataFieldService{
24  
25      private static final Logger LOG = Logger.getLogger(OverlayDataFieldServiceImpl.class);
26  
27      public LinkedHashMap<String,DataField> getDataFieldValueMap(List<DataField> dataFieldList)throws Exception{
28          LinkedHashMap<String,DataField> dataFieldValueMap = new LinkedHashMap<String,DataField>();
29          if(dataFieldList != null){
30              for(DataField dataField : dataFieldList){
31                  dataFieldValueMap.put(getTagKey(dataField),dataField);
32              }
33          }
34          return dataFieldValueMap;
35      }
36  
37      public LinkedHashMap<String,SubField> getSubFieldValueMap(List<DataField> dataFieldList)throws Exception{
38          LinkedHashMap<String,SubField> subFieldValueMap = new LinkedHashMap<String,SubField>();
39          String ind1 = null;
40          String ind2 = null;
41          StringBuffer key = new StringBuffer();
42          if(dataFieldList != null){
43              for(DataField dataField : dataFieldList){
44                  List<SubField> subFieldList = dataField.getSubFields();
45                  for(SubField subField : subFieldList){
46                      key.append(getTagKey(dataField));
47                      key.append(OLEConstants.DELIMITER_DOLLAR).append(subField.getCode());
48                      subFieldValueMap.put(key.toString(),subField);
49                      if(LOG.isDebugEnabled()){
50                          LOG.debug("field key---------->"+key.toString());
51                          LOG.debug("value-------------->"+subField.getValue());
52                      }
53                      key = new StringBuffer();
54                  }
55              }
56          }
57          return subFieldValueMap;
58      }
59  
60      public HashMap<String,HashMap<SubField,DataField>> getDataFieldValueSubFieldMap(List<DataField> dataFieldList){
61          HashMap<String,HashMap<SubField,DataField>> dataFieldSubFieldValueMap = new HashMap<String,HashMap<SubField,DataField>>();
62          String tagKey = null;
63          if(dataFieldList != null){
64              for(DataField dataField : dataFieldList){
65                  tagKey =getTagKey(dataField);
66                  for(SubField subField : dataField.getSubFields()){
67                      tagKey = tagKey+StringUtil.trimEmptyNullValues(subField.getCode());
68                      HashMap dataFieldSubFieldMap = new HashMap<SubField,DataField>();
69                      dataFieldSubFieldMap.put(subField,dataField);
70                      dataFieldSubFieldValueMap.put(tagKey,dataFieldSubFieldMap);
71                  }
72              }
73          }
74          return dataFieldSubFieldValueMap;
75      }
76  
77      public String getTagKey(DataField dataField){
78          StringBuffer keySB = new StringBuffer();
79          String ind1 = dataField.getInd1()!=null? StringUtil.trimHashNullValues(dataField.getInd1()):OLEConstants.DELIMITER_HASH;
80          String ind2 = dataField.getInd2()!=null? StringUtil.trimHashNullValues(dataField.getInd2()):OLEConstants.DELIMITER_HASH;
81          keySB.append(dataField.getTag()).append(ind1).append(ind2);
82          return keySB.toString();
83      }
84  }