View Javadoc
1   package org.kuali.ole.ncip.service.impl;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.apache.log4j.Logger;
5   import org.extensiblecatalog.ncip.v2.service.*;
6   import org.kuali.ole.OLEConstants;
7   import org.kuali.ole.deliver.service.ParameterValueResolver;
8   import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
9   import org.kuali.ole.bo.OLECheckInItem;
10  import org.kuali.ole.ncip.bo.OLENCIPConstants;
11  import org.kuali.ole.converter.OLECheckInItemConverter;
12  import org.kuali.ole.ncip.service.NCIPCheckInItemResponseBuilder;
13  import org.kuali.ole.ncip.service.OLECheckInItemService;
14  import org.kuali.ole.ncip.util.OLENCIPUtil;
15  import org.kuali.ole.sys.context.SpringContext;
16  import org.kuali.ole.utility.OleStopWatch;
17  import org.kuali.rice.core.api.config.property.ConfigContext;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  /**
23   * Created by chenchulakshmig on 8/21/15.
24   */
25  public class OLENCIPCheckInItemServiceImpl extends NonSip2CheckinItemServiceImplImpl implements OLECheckInItemService {
26  
27      private static final Logger LOG = Logger.getLogger(OLENCIPCheckInItemServiceImpl.class);
28  
29      private DocstoreClientLocator docstoreClientLocator;
30  
31      public DocstoreClientLocator getDocstoreClientLocator() {
32          if (docstoreClientLocator == null) {
33              docstoreClientLocator = (DocstoreClientLocator) SpringContext.getService("docstoreClientLocator");
34          }
35          return docstoreClientLocator;
36      }
37  
38      public void setDocstoreClientLocator(DocstoreClientLocator docstoreClientLocator) {
39          this.docstoreClientLocator = docstoreClientLocator;
40      }
41  
42      @Override
43      public CheckInItemResponseData performService(CheckInItemInitiationData checkInItemInitiationData, ServiceContext serviceContext, RemoteServiceManager remoteServiceManager) throws ServiceException {
44          OleStopWatch oleStopWatch = new OleStopWatch();
45          oleStopWatch.start();
46  
47          OLENCIPUtil olencipUtil = new OLENCIPUtil();
48          NCIPCheckInItemResponseBuilder ncipCheckInItemResponseBuilder = new NCIPCheckInItemResponseBuilder();
49          CheckInItemResponseData checkInItemResponseData = new CheckInItemResponseData();
50  
51          AgencyId agencyId = olencipUtil.validateAgency(checkInItemInitiationData.getInitiationHeader(), checkInItemResponseData);
52          if (null == agencyId) return checkInItemResponseData;
53  
54          String itemBarcode = checkInItemInitiationData.getItemId().getItemIdentifierValue();
55          String operatorId = olencipUtil.agencyPropertyMap.get(OLENCIPConstants.OPERATOR_ID);
56          String itemDeleteIndicator = ParameterValueResolver.getInstance().getParameter(OLEConstants
57                  .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLENCIPConstants.TEMP_ITEM_DELETE_INDICATOR);
58  
59          Map checkinParameters = new HashMap();
60          checkinParameters.put("operatorId", operatorId);
61          checkinParameters.put("itemBarcode", itemBarcode);
62          checkinParameters.put("responseFormatType", "XML");
63          checkinParameters.put("deleteIndicator", itemDeleteIndicator);
64  
65          String responseString = checkinItem(checkinParameters);
66          OLECheckInItem oleCheckInItem = (OLECheckInItem) new OLECheckInItemConverter().generateCheckInItemObject(responseString);
67  
68          if (oleCheckInItem != null && StringUtils.isNotBlank(oleCheckInItem.getMessage())) {
69              if (oleCheckInItem.getMessage().equals(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_CHECKED_IN))) {
70                  ncipCheckInItemResponseBuilder.setItemId(checkInItemResponseData, itemBarcode, agencyId, oleCheckInItem.getItemType());
71                  ncipCheckInItemResponseBuilder.setUserId(checkInItemResponseData, agencyId, oleCheckInItem);
72                  ncipCheckInItemResponseBuilder.setItemOptionalFields(checkInItemResponseData, oleCheckInItem);
73              } else {
74                  String problemElement = OLENCIPConstants.ITEM;
75                  String problemValue = itemBarcode;
76  
77                  if (oleCheckInItem.getCode().equals("026")) {
78                      problemValue = operatorId;
79                  }
80                  olencipUtil.processProblems(checkInItemResponseData, problemValue, oleCheckInItem.getMessage(), problemElement);
81              }
82          } else {
83              olencipUtil.processProblems(checkInItemResponseData, itemBarcode, ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED), OLENCIPConstants.ITEM);
84          }
85  
86          oleStopWatch.end();
87          LOG.info("Time taken to perform Checkin item service : " + oleStopWatch.getTotalTime());
88          return checkInItemResponseData;
89      }
90  
91  }