1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.select.service.impl;
17  
18  import org.kuali.ole.module.purap.document.service.OlePurapService;
19  import org.kuali.ole.select.OleSelectConstant;
20  import org.kuali.ole.select.batch.service.OleRequisitionCreateDocumentService;
21  import org.kuali.ole.select.batch.service.impl.OleRequisitionCreateDocumentServiceImpl;
22  import org.kuali.ole.select.businessobject.BibInfoBean;
23  import org.kuali.ole.select.service.PopulateBibInfoService;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.core.api.config.property.ConfigurationService;
26  import org.kuali.rice.krad.UserSession;
27  import org.kuali.rice.krad.util.ErrorMessage;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import org.springframework.util.AutoPopulatingList;
30  
31  import java.util.Collections;
32  import java.util.List;
33  import java.util.Map;
34  
35  public class PopulateBibInfoServiceImpl implements PopulateBibInfoService {
36      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PopulateBibInfoServiceImpl.class);
37      protected ConfigurationService kualiConfigurationService;
38      protected OlePurapService olePurapService;
39  
40      public OlePurapService getOlePurapService() {
41          if (olePurapService == null) {
42              olePurapService = SpringContext.getBean(OlePurapService.class);
43          }
44          return olePurapService;
45      }
46  
47      @Override
48      public String processBibInfoForCitation(String citationString, BibInfoBean bibInfoBean) throws Exception {
49          try {
50              String user;
51              if (GlobalVariables.getUserSession() != null) {
52                  user = GlobalVariables.getUserSession().getPrincipalName();
53              } else {
54                  kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
55                  user = kualiConfigurationService.getPropertyValueAsString("userName");
56              }
57              GlobalVariables.setUserSession(new UserSession(user));
58              BuildCitationBibInfoBean buildCitationBibInfoBean = SpringContext.getBean(BuildCitationBibInfoBean.class);
59              bibInfoBean = buildCitationBibInfoBean.getBean(citationString, bibInfoBean);
60              if (bibInfoBean.getTitle() == null || "".equalsIgnoreCase(bibInfoBean.getTitle())) {
61                  return OleSelectConstant.SOAP_CITATION_PARSER_UNREACHABLE;
62              }
63              bibInfoBean.setRequestSourceUrl(citationString);
64              
65              bibInfoBean.setRequisitionSource(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM);
66              bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_WEBFORM);
67              bibInfoBean = setBibInfoDefaultValues(bibInfoBean);
68              OleRequisitionCreateDocumentService createDocument = SpringContext.getBean(OleRequisitionCreateDocumentServiceImpl.class);
69              List<BibInfoBean> bibInfoBeanList = getBibInfoBeanList(bibInfoBean);
70              String docNumber = createDocument.saveRequisitionDocument(bibInfoBeanList, true);
71              return docNumber;
72          } catch (Exception e) {
73              LOG.error("Exception processing for SOAP citation document creation----" + e.getMessage(), e);
74              String errorMessage = null;
75              if (GlobalVariables.getMessageMap().hasErrors()) {
76                  Map<String, AutoPopulatingList<ErrorMessage>> map = GlobalVariables.getMessageMap().getErrorMessages();
77                  for (Map.Entry<String, AutoPopulatingList<ErrorMessage>> entry : map.entrySet()) {
78                      AutoPopulatingList<ErrorMessage> errors = entry.getValue();
79                      ErrorMessage error = errors.get(0);
80                      String[] params = error.getMessageParameters();
81                      errorMessage = params[0];
82                  }
83              }
84              return OleSelectConstant.SOAP_EXCEPTION + " - " + errorMessage;
85          }
86      }
87  
88      
89  
90  
91  
92  
93  
94      private BibInfoBean setBibInfoDefaultValues(BibInfoBean bibInfoBean) throws Exception {
95  
96          
97          bibInfoBean.setFinancialYear(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.FIN_YEAR));
98          bibInfoBean.setChartOfAccountsCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.CHART_OF_ACC_CD));
99          bibInfoBean.setOrganizationCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.ORG_CODE));
100         bibInfoBean.setDocumentFundingSourceCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.FUND_SRC_CD));
101         bibInfoBean.setUseTaxIndicator(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.USE_TAX_IND) == "true" ? true : false);
102         bibInfoBean.setDeliveryCampusCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_CMPS_CD));
103         bibInfoBean.setDeliveryBuildingOtherIndicator(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_BLDNG_OTHR_IND) == "true" ? true : false);
104         bibInfoBean.setDeliveryBuildingCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_BLDNG_CD));
105         bibInfoBean.setDeliveryBuildingLine1Address(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_BLDNG_LN_ADDR));
106         bibInfoBean.setDeliveryBuildingRoomNumber(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_BLDNG_ROOM_NBR));
107         bibInfoBean.setDeliveryCityName(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_CITY_NM));
108         bibInfoBean.setDeliveryStateCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_STATE_CD));
109         bibInfoBean.setDeliveryPostalCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_POSTAL_CD));
110         bibInfoBean.setDeliveryCountryCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DLVR_CNTRY_CD));
111         bibInfoBean.setDeliveryToName(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.DELIVERY_TO_NAME));
112 
113 
114         bibInfoBean.setUom(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.UOM));
115         bibInfoBean.setItemTypeCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.ITEM_TYPE_CD));
116         bibInfoBean.setListprice(new Double(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.LIST_PRICE)));
117         bibInfoBean.setQuantity(new Long(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.QTY)));
118         bibInfoBean.setPurchaseOrderTransmissionMethodCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.PO_TRNS_MTH_CD));
119         bibInfoBean.setPurchaseOrderCostSourceCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.PO_CST_SRC_CD));
120         bibInfoBean.setRequestorPersonName(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_NAME));
121         bibInfoBean.setRequestorPersonPhoneNumber(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_PHONE_NUMBER));
122         bibInfoBean.setRequestorPersonEmailAddress(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_EMAIL_ADDRESS));
123         bibInfoBean.setLocation(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.LOCATION));
124         bibInfoBean.setOrganizationAutomaticPurchaseOrderLimit(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.ORG_PO_LMT));
125         bibInfoBean.setPurchaseOrderAutomaticIndicator(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.PURCHASE_ORDER_AUTOMATIC_INDICATIOR) == "true" ? true : false);
126         bibInfoBean.setReceivingDocumentRequiredIndicator(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.RCV_REQ_INT) == "true" ? true : false);
127         bibInfoBean.setPaymentRequestPositiveApprovalIndicator(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.PREQ_APPRL_INT) == "true" ? true : false);
128         
129 
130 
131 
132         if (LOG.isDebugEnabled()) {
133             LOG.debug("---------------Billing Name from property--------->" + getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_NM));
134         }
135         bibInfoBean.setBillingName(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_NM));
136         bibInfoBean.setBillingCityName(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_CITY_NM));
137         bibInfoBean.setBillingCountryCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_CNTRY_CD));
138         bibInfoBean.setBillingLine1Address(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_LIN_ADDR));
139         bibInfoBean.setBillingPhoneNumber(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_PHN_NBR));
140         bibInfoBean.setBillingPostalCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_POSTAL_CD));
141         bibInfoBean.setBillingStateCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_STATE_CD));
142        
143         
144         return bibInfoBean;
145     }
146 
147 
148     @Override
149     public String processBibInfoForOperURL(String openUrlString, BibInfoBean bibInfoBean) throws Exception {
150         try {
151             String user;
152             if (GlobalVariables.getUserSession() != null) {
153                 user = GlobalVariables.getUserSession().getPrincipalName();
154             } else {
155                 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
156                 user = kualiConfigurationService.getPropertyValueAsString("userName");
157             }
158             GlobalVariables.setUserSession(new UserSession(user));
159             BuildOpenUrlBibInfoBean buildOpenUrlBibInfoBean = SpringContext.getBean(BuildOpenUrlBibInfoBean.class);
160             bibInfoBean = buildOpenUrlBibInfoBean.getBean(bibInfoBean, openUrlString);
161             if (bibInfoBean.getTitle() == null || "".equalsIgnoreCase(bibInfoBean.getTitle())) {
162                 return OleSelectConstant.SOAP_INVALID_OPENURL;
163             }
164             bibInfoBean.setRequestSourceUrl(openUrlString);
165             
166             bibInfoBean.setRequisitionSource(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM);
167             bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_WEBFORM);
168             bibInfoBean = setBibInfoDefaultValues(bibInfoBean);
169             OleRequisitionCreateDocumentService createDocument = SpringContext.getBean(OleRequisitionCreateDocumentServiceImpl.class);
170             List<BibInfoBean> bibInfoBeanList = getBibInfoBeanList(bibInfoBean);
171             String docNumber = createDocument.saveRequisitionDocument(bibInfoBeanList, true);
172             return docNumber;
173         } catch (Exception e) {
174             LOG.error("Exception processing for SOAP citation document creation----" + e.getMessage(), e);
175             String errorMessage = null;
176             if (GlobalVariables.getMessageMap().hasErrors()) {
177                 Map<String, AutoPopulatingList<ErrorMessage>> map = GlobalVariables.getMessageMap().getErrorMessages();
178                 for (Map.Entry<String, AutoPopulatingList<ErrorMessage>> entry : map.entrySet()) {
179                     AutoPopulatingList<ErrorMessage> errors = entry.getValue();
180                     ErrorMessage error = errors.get(0);
181                     String[] params = error.getMessageParameters();
182                     errorMessage = params[0];
183                 }
184             }
185             return OleSelectConstant.SOAP_EXCEPTION + " - " + errorMessage;
186         }
187     }
188 
189 
190     @Override
191     public String processBibInfoForForm(BibInfoBean bibInfoBean, String title, String author, String edition, String series, String publisher, String placeOfPublication, String yearOfPublication, String standardNumber, String typeOfStandardNumber,
192                                         String routeRequesterReceipt) throws Exception {
193         try {
194             String user;
195 
196 
197 
198             kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
199             user = kualiConfigurationService.getPropertyValueAsString("userName");
200             
201             if (LOG.isDebugEnabled()){
202                 LOG.debug("userName in processBibInfoForForm>>>>>>>>>>>>>>" + user);
203             }
204             GlobalVariables.setUserSession(new UserSession(user));
205             BuildFormBibInfoBean buildFormBibInfoBean = SpringContext.getBean(BuildFormBibInfoBean.class);
206             bibInfoBean = buildFormBibInfoBean.getBean(bibInfoBean, title, author, edition, series, publisher, placeOfPublication, yearOfPublication, standardNumber, typeOfStandardNumber, routeRequesterReceipt);
207             bibInfoBean = setBibInfoDefaultValues(bibInfoBean);
208             
209             bibInfoBean.setRequisitionSource(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM);
210             bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_WEBFORM);
211             OleRequisitionCreateDocumentService createDocument = SpringContext.getBean(OleRequisitionCreateDocumentServiceImpl.class);
212             List<BibInfoBean> bibInfoBeanList = getBibInfoBeanList(bibInfoBean);
213             String docNumber = createDocument.saveRequisitionDocument(bibInfoBeanList, true);
214             return docNumber;
215         } catch (Exception e) {
216             LOG.error("Exception processing for SOAP form document creation----" + e.getMessage(), e);
217             String errorMessage = null;
218             if (GlobalVariables.getMessageMap().hasErrors()) {
219                 Map<String, AutoPopulatingList<ErrorMessage>> map = GlobalVariables.getMessageMap().getErrorMessages();
220                 for (Map.Entry<String, AutoPopulatingList<ErrorMessage>> entry : map.entrySet()) {
221                     AutoPopulatingList<ErrorMessage> errors = entry.getValue();
222                     ErrorMessage error = errors.get(0);
223                     String[] params = error.getMessageParameters();
224                     errorMessage = params[0];
225                 }
226             }
227             return OleSelectConstant.SOAP_EXCEPTION + " - " + errorMessage;
228         }
229     }
230 
231     private List<BibInfoBean> getBibInfoBeanList(BibInfoBean bibInfoBean) throws Exception {
232         return Collections.singletonList(bibInfoBean);
233 
234     }
235 
236     public ConfigurationService getConfigurationService() {
237         return kualiConfigurationService;
238     }
239 
240     public void setConfigurationService(ConfigurationService kualiConfigurationService) {
241         this.kualiConfigurationService = kualiConfigurationService;
242     }
243 
244 
245 }