View Javadoc
1   package org.kuali.ole.service.impl;
2   
3   import org.kuali.ole.DataCarrierService;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.docstore.common.document.content.bib.marc.DataField;
6   import org.kuali.ole.docstore.common.document.content.bib.marc.SubField;
7   import org.kuali.ole.ingest.pojo.OleDataField;
8   import org.kuali.ole.ingest.pojo.OverlayOption;
9   import org.kuali.ole.select.bo.*;
10  import org.kuali.ole.service.OverlayRetrivalService;
11  import org.kuali.ole.util.StringUtil;
12  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
13  import org.kuali.rice.krad.service.BusinessObjectService;
14  import org.kuali.rice.krad.service.KRADServiceLocator;
15  
16  import java.util.ArrayList;
17  import java.util.HashMap;
18  import java.util.List;
19  import java.util.Map;
20  
21  /**
22   * Created with IntelliJ IDEA.
23   * User: ?
24   * Date: 12/10/12
25   * Time: 6:24 PM
26   * To change this template use File | Settings | File Templates.
27   */
28  
29  public class OverlayRetrivalServiceImpl implements OverlayRetrivalService {
30  
31      private DataCarrierService dataCarrierService;
32  
33      @Override
34      public List<OleGloballyProtectedField> getGloballyProtectedFields() throws Exception {
35          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
36          List<OleGloballyProtectedField> oleGloballyProtectedFieldList = (List<OleGloballyProtectedField>) businessObjectService.findAll(OleGloballyProtectedField.class);
37          return oleGloballyProtectedFieldList;
38      }
39  
40      @Override
41      public List<String> getGloballyProtectedFieldsList()throws Exception{
42          List fieldList = new ArrayList<String>();
43          StringBuffer fields = null;
44          String tagField = null;
45          String firstIndicator = null;
46          String secondIndicator = null;
47          String subField = null;
48          List<OleGloballyProtectedField> protectedFieldList = getGloballyProtectedFields();
49          for(OleGloballyProtectedField oleGloballyProtectedField : protectedFieldList){
50              tagField = oleGloballyProtectedField.getTag();
51              firstIndicator = oleGloballyProtectedField.getFirstIndicator()!=null? StringUtil.trimHashNullValues(oleGloballyProtectedField.getFirstIndicator()):OLEConstants.DELIMITER_HASH;
52              secondIndicator = oleGloballyProtectedField.getSecondIndicator()!=null? StringUtil.trimHashNullValues(oleGloballyProtectedField.getSecondIndicator()):OLEConstants.DELIMITER_HASH;
53              subField = oleGloballyProtectedField.getSubField()!=null?OLEConstants.DELIMITER_DOLLAR+oleGloballyProtectedField.getSubField():OLEConstants.DELIMITER_DOLLAR+"*";
54              fields = new StringBuffer();
55              fields = fields.append(tagField).append(firstIndicator).append(secondIndicator).append(subField);
56              fieldList.add(fields.toString());
57          }
58  
59          return fieldList;
60      }
61  
62      @Override
63      public List getGloballyProtectedFieldsModificationList() throws Exception {
64          List fieldList = new ArrayList<String>();
65          StringBuffer fields = null;
66          String tagField = null;
67          String firstIndicator = null;
68          String secondIndicator = null;
69          String subField = null;
70          Map<String, String> criteria = new HashMap<String, String>();
71          criteria.put("modifyFlag","false");
72          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
73          List<OleGloballyProtectedField> protectedFieldList = (List<OleGloballyProtectedField>)businessObjectService.findMatching(OleGloballyProtectedField.class,criteria);
74          for(OleGloballyProtectedField oleGloballyProtectedField : protectedFieldList){
75              //if(!oleGloballyProtectedField.isModifyFlag()){
76                  tagField = oleGloballyProtectedField.getTag();
77                  firstIndicator = oleGloballyProtectedField.getFirstIndicator()!=null?"-"+ oleGloballyProtectedField.getFirstIndicator():"-";
78                  secondIndicator = oleGloballyProtectedField.getSecondIndicator()!=null?"-"+ oleGloballyProtectedField.getSecondIndicator():"-";
79                  subField = oleGloballyProtectedField.getSubField()!=null?"-"+ oleGloballyProtectedField.getSubField():"-";
80                  fields = new StringBuffer();
81                  fields = fields.append(tagField).append(firstIndicator).append(secondIndicator).append(subField);
82                  fieldList.add(fields.toString());
83              //}
84          }
85  
86          return fieldList;
87      }
88  
89      @Override
90      public OverlayOption getAddOverlayOptionWithWildCardSearch(List<DataField> newDatafields, List<OverlayOption> overlayOptionList) throws Exception {
91          OverlayOption addOverlayOption = null;
92          for(OverlayOption overlayOption : overlayOptionList){
93              if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_ADD)){
94                  overlayOption = checkWildCard(newDatafields, overlayOption);
95                  addOverlayOption = overlayOption;
96              }
97          }
98          return addOverlayOption;
99      }
100 
101     @Override
102     public OverlayOption getAddOverlayOption(List<OverlayOption> overlayOptionList)throws Exception{
103         OverlayOption addOverlayOption = null;
104         for(OverlayOption overlayOption : overlayOptionList){
105             if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_ADD)){
106                 addOverlayOption = overlayOption;
107             }
108         }
109         return addOverlayOption;
110     }
111 
112     @Override
113     public OverlayOption getDeleteOverlayOption(List<OverlayOption> overlayOptionList)throws Exception{
114         OverlayOption deleteOverlayOption = null;
115         for(OverlayOption overlayOption : overlayOptionList){
116             if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_DELETE)){
117                 deleteOverlayOption = overlayOption;
118             }
119         }
120         return deleteOverlayOption;
121     }
122 
123     @Override
124     public OverlayOption getDeleteOverlayOptionWithWildCardSearch(List<DataField> newDatafields, List<OverlayOption> overlayOptionList) {
125         OverlayOption deleteOverlayOption = null;
126         for(OverlayOption overlayOption : overlayOptionList){
127             if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_DELETE)){
128                 overlayOption = checkWildCard(newDatafields, overlayOption);
129                 deleteOverlayOption = overlayOption;
130             }
131         }
132         return deleteOverlayOption;
133     }
134 
135     @Override
136     public OverlayOption getUpdateOverlayOption(List<OverlayOption> overlayOptionList)throws Exception{
137         OverlayOption updateOverlayOption = null;
138         for(OverlayOption overlayOption : overlayOptionList){
139             if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_UPDATE)){
140                 updateOverlayOption = overlayOption;
141             }
142         }
143         return updateOverlayOption;
144     }
145 
146     @Override
147     public OverlayOption getUpdateOverlayOptionWithWildCardSearch(List<DataField> newDatafields, List<OverlayOption> overlayOptionList) throws Exception {
148         OverlayOption updateOverlayOption = null;
149         for(OverlayOption overlayOption : overlayOptionList){
150             if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_UPDATE)){
151                 overlayOption = checkWildCard(newDatafields, overlayOption);
152                 updateOverlayOption = overlayOption;
153             }
154         }
155         return updateOverlayOption;
156     }
157 
158     /*@Override
159     public OverlayOption getDontAddOverlayOption(List<OverlayOption> overlayOptionList)throws Exception{
160         OverlayOption dontAddOverlayOption = null;
161         for(OverlayOption overlayOption : overlayOptionList){
162             if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_DONTADD)){
163                 dontAddOverlayOption = overlayOption;
164             }
165         }
166         return dontAddOverlayOption;
167     }
168 
169     @Override
170     public OverlayOption getDontAddOverlayOptionWithWildCardSearch(List<DataField> newDatafields, List<OverlayOption> overlayOptionList) {
171         OverlayOption dontAddOverlayOption = null;
172         for(OverlayOption overlayOption : overlayOptionList){
173             if(overlayOption.getName().equals(OLEConstants.OVERLAY_OPTION_DONTADD)){
174                 overlayOption = checkWildCard(newDatafields, overlayOption);
175                 dontAddOverlayOption = overlayOption;
176             }
177         }
178         return dontAddOverlayOption;
179     }*/
180 
181     /*@Override
182     public String getReceiptStatus() {
183         List<ProfileAttributeBo> profileAttributesList = (List<ProfileAttributeBo>) getDataCarrierService().getData(OLEConstants.PROFILE_ATTRIBUTE_LIST);
184         String receiptStatus = new String();
185         String receiptStatusName = new String();
186         for(ProfileAttributeBo profileAttributeBo : profileAttributesList){
187             if(profileAttributeBo.getAttributeName().equals(OLEConstants.RECEIPT_STATUS)){
188                 receiptStatus = profileAttributeBo.getAttributeValue();
189             }
190         }
191         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
192         Map<String, String> attributeMap = new HashMap<String, String>();
193         attributeMap.put("receiptStatusCode",receiptStatus);
194         List<OleReceiptStatus> oleReceiptStatusList = (List<OleReceiptStatus>) businessObjectService.findMatching(OleReceiptStatus.class,attributeMap);
195         for(OleReceiptStatus oleReceiptStatus : oleReceiptStatusList){
196             receiptStatusName = oleReceiptStatus.getReceiptStatusName();
197         }
198         return receiptStatusName;
199     }*/
200 
201 
202     public OverlayOption checkWildCard(List<DataField> newDatafieldList, OverlayOption overlayOption){
203         List<OleDataField> overlayOptionOleDataFields = overlayOption.getOleDataFields();
204         OverlayOption newOverlayOption = new OverlayOption();
205         newOverlayOption.setId(overlayOption.getId());
206         newOverlayOption.setAgendaName(overlayOption.getAgendaName());
207         newOverlayOption.setName(overlayOption.getName());
208         List<OleDataField> oleDataFields = new ArrayList<OleDataField>();
209         for(OleDataField oleDataField : overlayOptionOleDataFields){
210             String tag = oleDataField.getDataFieldTag();
211             boolean isSubFieldCodeStar = "*".equalsIgnoreCase(oleDataField.getSubFieldCode());
212             if(tag.contains("*")){
213                 char[] dataFieldSplit = oleDataField.getDataFieldTag().toCharArray();
214                 for(DataField dataFields : newDatafieldList){
215                     boolean isStartsWithDataField = dataFields.getTag().startsWith(String.valueOf(dataFieldSplit[0]));
216                     if(isStartsWithDataField){
217                         for(SubField subField : dataFields.getSubFields()){
218                             if(isSubFieldCodeStar){
219                                 OleDataField newOleDataFieldSubFieldCodeStar = new OleDataField();
220                                 newOleDataFieldSubFieldCodeStar.setId(oleDataField.getId());
221                                 newOleDataFieldSubFieldCodeStar.setOverlayOptionId(oleDataField.getOverlayOptionId());
222                                 newOleDataFieldSubFieldCodeStar.setAgendaName(oleDataField.getAgendaName());
223                                 newOleDataFieldSubFieldCodeStar.setDataFieldTag(dataFields.getTag());
224                                 newOleDataFieldSubFieldCodeStar.setDataFieldInd1(oleDataField.getDataFieldInd1());
225                                 newOleDataFieldSubFieldCodeStar.setDataFieldInd2(oleDataField.getDataFieldInd2());
226                                 newOleDataFieldSubFieldCodeStar.setSubFieldCode(subField.getCode());
227                                 oleDataFields.add(newOleDataFieldSubFieldCodeStar);
228                             }
229                             else if(oleDataField.getSubFieldCode().equalsIgnoreCase(subField.getCode())){
230                                 OleDataField newOleDataField = new OleDataField();
231                                 newOleDataField.setId(oleDataField.getId());
232                                 newOleDataField.setOverlayOptionId(oleDataField.getOverlayOptionId());
233                                 newOleDataField.setAgendaName(oleDataField.getAgendaName());
234                                 newOleDataField.setDataFieldTag(dataFields.getTag());
235                                 newOleDataField.setDataFieldInd1(oleDataField.getDataFieldInd1());
236                                 newOleDataField.setDataFieldInd2(oleDataField.getDataFieldInd2());
237                                 newOleDataField.setSubFieldCode(subField.getCode());
238                                 oleDataFields.add(newOleDataField);
239                             }
240                         }
241                     }
242                 }
243             }
244             else if(!tag.contains("*") && oleDataField.getSubFieldCode().equalsIgnoreCase("*")){
245                 for(DataField dataFields : newDatafieldList){
246                     if(tag.equalsIgnoreCase(dataFields.getTag())){
247                         for(SubField subField : dataFields.getSubFields()){
248                             OleDataField newOleDataFieldSubFieldCodeStar = new OleDataField();
249                             newOleDataFieldSubFieldCodeStar.setId(oleDataField.getId());
250                             newOleDataFieldSubFieldCodeStar.setOverlayOptionId(oleDataField.getOverlayOptionId());
251                             newOleDataFieldSubFieldCodeStar.setAgendaName(oleDataField.getAgendaName());
252                             newOleDataFieldSubFieldCodeStar.setDataFieldTag(dataFields.getTag());
253                             newOleDataFieldSubFieldCodeStar.setDataFieldInd1(oleDataField.getDataFieldInd1());
254                             newOleDataFieldSubFieldCodeStar.setDataFieldInd2(oleDataField.getDataFieldInd2());
255                             newOleDataFieldSubFieldCodeStar.setSubFieldCode(subField.getCode());
256                             oleDataFields.add(newOleDataFieldSubFieldCodeStar);
257                         }
258                     }
259                 }
260             }
261             else {
262                 oleDataFields.add(oleDataField);
263             }
264         }
265         newOverlayOption.setOleDataFields(oleDataFields);
266         return newOverlayOption;
267     }
268     @Override
269     public OleCallNumber getCallNumberRecord(String inputValue)throws Exception{
270         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
271         Map<String,String> criteriaMap = new HashMap<String,String>();
272         criteriaMap.put(OLEConstants.OVERLAY_INPUTVALUE,inputValue);
273         List<OleCallNumber> oleCallNumberList = (List<OleCallNumber>) businessObjectService.findMatching(OleCallNumber.class,criteriaMap);
274         if(oleCallNumberList!=null && oleCallNumberList.size()>0){
275             return oleCallNumberList.iterator().next();
276         }else{
277             return null;
278         }
279     }
280 
281     public OleCallNumber getCallNumberRecord(HashMap<String,String> criteriaMap)throws Exception{
282         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
283         List<OleCallNumber> oleCallNumberList = (List<OleCallNumber>) businessObjectService.findMatching(OleCallNumber.class,criteriaMap);
284         if(oleCallNumberList!=null && oleCallNumberList.size()>0){
285             return oleCallNumberList.iterator().next();
286         }else{
287             return null;
288         }
289     }
290     @Override
291     public OleCode getOleCodeRecord(String inputValue)throws Exception{
292         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
293         Map<String,String> criteriaMap = new HashMap<String,String>();
294         criteriaMap.put(OLEConstants.OVERLAY_INPUTVALUE,inputValue);
295         List<OleCode> oleCodeList = (List<OleCode>) businessObjectService.findMatching(OleCode.class,criteriaMap);
296         if(oleCodeList!=null && oleCodeList.size()>0){
297             return oleCodeList.iterator().next();
298         }else{
299             return null;
300         }
301     }
302     @Override
303     public OleCode getOleCodeRecord(HashMap<String,String> criteriaMap)throws Exception{
304         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
305         List<OleCode> oleCodeList = (List<OleCode>) businessObjectService.findMatching(OleCode.class,criteriaMap);
306         if(oleCodeList!=null && oleCodeList.size()>0){
307             return oleCodeList.iterator().next();
308         }else{
309             return null;
310         }
311     }
312     @Override
313     public OleBudgetCode getOleBudgetCode(String inputValue)throws Exception{
314         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
315         Map<String,String> criteriaMap = new HashMap<String,String>();
316         criteriaMap.put(OLEConstants.OVERLAY_INPUTVALUE,inputValue);
317         List<OleBudgetCode> oleBudgetCodeList = (List<OleBudgetCode>) businessObjectService.findMatching(OleBudgetCode.class,criteriaMap);
318         if(oleBudgetCodeList!=null && oleBudgetCodeList.size()>0){
319             return oleBudgetCodeList.iterator().next();
320         }else{
321             return null;
322         }
323     }
324     @Override
325     public OleBudgetCode getOleBudgetCode(HashMap<String,String> criteriaMap)throws Exception{
326         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
327         List<OleBudgetCode> oleBudgetCodeList = (List<OleBudgetCode>) businessObjectService.findMatching(OleBudgetCode.class,criteriaMap);
328         if(oleBudgetCodeList!=null && oleBudgetCodeList.size()>0){
329             return oleBudgetCodeList.iterator().next();
330         }else{
331             return null;
332         }
333     }
334 
335     @Override
336     public OleVendorAccountInfo getAccountObjectForVendorRefNo(HashMap<String,String> criteriaMap)throws Exception{
337         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
338         List<OleVendorAccountInfo> oleVendorAccountInfoList = (List<OleVendorAccountInfo>) businessObjectService.findMatching(OleVendorAccountInfo.class,criteriaMap);
339         if(oleVendorAccountInfoList!=null && oleVendorAccountInfoList.size()>0){
340             return oleVendorAccountInfoList.iterator().next();
341         }else{
342             return null;
343         }
344 /*        OleVendorAccountInfo vendor=new OleVendorAccountInfo();
345         vendor=businessObjectService.findBySinglePrimaryKey(OleVendorAccountInfo.class,vendorReferenceNo);*/
346 
347     }
348 
349     /**
350      *  Gets the dataCarrierService attribute.
351      * @return  Returns dataCarrierService.
352      */
353     protected DataCarrierService getDataCarrierService() {
354         if(dataCarrierService == null){
355             return GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
356         }
357         return dataCarrierService;
358     }
359 
360 }