View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.service.impl;
17  
18  import org.kuali.ole.select.OleSelectConstant;
19  import org.kuali.ole.select.batch.service.OleRequisitionCreateDocumentService;
20  import org.kuali.ole.select.batch.service.impl.OleRequisitionCreateDocumentServiceImpl;
21  import org.kuali.ole.select.businessobject.BibInfoBean;
22  import org.kuali.ole.select.service.PopulateBibInfoService;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.core.api.config.property.ConfigurationService;
25  import org.kuali.rice.krad.UserSession;
26  import org.kuali.rice.krad.util.ErrorMessage;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  import org.springframework.util.AutoPopulatingList;
29  
30  import java.util.Collections;
31  import java.util.List;
32  import java.util.Map;
33  
34  public class PopulateBibInfoServiceImpl implements PopulateBibInfoService {
35      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PopulateBibInfoServiceImpl.class);
36      protected ConfigurationService kualiConfigurationService;
37  
38      @Override
39      public String processBibInfoForCitation(String citationString, BibInfoBean bibInfoBean) throws Exception {
40          try {
41              String user;
42              if (GlobalVariables.getUserSession() != null) {
43                  user = GlobalVariables.getUserSession().getPrincipalName();
44              } else {
45                  kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
46                  user = kualiConfigurationService.getPropertyValueAsString("userName");
47              }
48              GlobalVariables.setUserSession(new UserSession(user));
49              BuildCitationBibInfoBean buildCitationBibInfoBean = SpringContext.getBean(BuildCitationBibInfoBean.class);
50              bibInfoBean = buildCitationBibInfoBean.getBean(citationString, bibInfoBean);
51              if (bibInfoBean.getTitle() == null || "".equalsIgnoreCase(bibInfoBean.getTitle())) {
52                  return OleSelectConstant.SOAP_CITATION_PARSER_UNREACHABLE;
53              }
54              bibInfoBean.setRequestSourceUrl(citationString);
55              //bibInfoBean.setRequestSource(OleSelectConstant.REQUEST_SRC_TYPE_WEBFORM);
56              bibInfoBean.setRequisitionSource(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM);
57              bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_WEBFORM);
58              bibInfoBean = setBibInfoDefaultValues(bibInfoBean);
59              OleRequisitionCreateDocumentService createDocument = SpringContext.getBean(OleRequisitionCreateDocumentServiceImpl.class);
60              List<BibInfoBean> bibInfoBeanList = getBibInfoBeanList(bibInfoBean);
61              String docNumber = createDocument.saveRequisitionDocument(bibInfoBeanList, true);
62              return docNumber;
63          } catch (Exception e) {
64              LOG.error("Error processing for SOAP citation document creation----" + e.getMessage(), e);
65              String errorMessage = null;
66              if (GlobalVariables.getMessageMap().hasErrors()) {
67                  Map<String, AutoPopulatingList<ErrorMessage>> map = GlobalVariables.getMessageMap().getErrorMessages();
68                  for (Map.Entry<String, AutoPopulatingList<ErrorMessage>> entry : map.entrySet()) {
69                      AutoPopulatingList<ErrorMessage> errors = entry.getValue();
70                      ErrorMessage error = errors.get(0);
71                      String[] params = error.getMessageParameters();
72                      errorMessage = params[0];
73                  }
74              }
75              return OleSelectConstant.SOAP_EXCEPTION + " - " + errorMessage;
76          }
77      }
78  
79      /**
80       * This method sets the default values to the bibInfoBean
81       *
82       * @param bibInfoBean
83       * @return BibInfoBean
84       */
85      private BibInfoBean setBibInfoDefaultValues(BibInfoBean bibInfoBean) throws Exception {
86  
87          kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
88          // bibInfoBean.setIsbn(kualiConfigurationService.getPropertyValueAsString("isbn"));
89          bibInfoBean.setFinancialYear(kualiConfigurationService.getPropertyValueAsString("financialYear"));
90          bibInfoBean.setChartOfAccountsCode(kualiConfigurationService.getPropertyValueAsString("chartOfAccountsCode"));
91          bibInfoBean.setOrganizationCode(kualiConfigurationService.getPropertyValueAsString("organizationCode"));
92          bibInfoBean.setDocumentFundingSourceCode(kualiConfigurationService.getPropertyValueAsString("documentFundingSourceCode"));
93          bibInfoBean.setUseTaxIndicator(kualiConfigurationService.getPropertyValueAsString("useTaxIndicator") == "true" ? true : false);
94          bibInfoBean.setDeliveryCampusCode(kualiConfigurationService.getPropertyValueAsString("deliveryCampusCode"));
95          bibInfoBean.setDeliveryBuildingOtherIndicator(kualiConfigurationService.getPropertyValueAsString("deliveryBuildingOtherIndicator") == "true" ? true : false);
96          bibInfoBean.setDeliveryBuildingCode(kualiConfigurationService.getPropertyValueAsString("deliveryBuildingCode"));
97          bibInfoBean.setDeliveryBuildingLine1Address(kualiConfigurationService.getPropertyValueAsString("deliveryBuildingLine1Address"));
98          bibInfoBean.setDeliveryBuildingRoomNumber(kualiConfigurationService.getPropertyValueAsString("deliveryBuildingRoomNumber"));
99          bibInfoBean.setDeliveryCityName(kualiConfigurationService.getPropertyValueAsString("deliveryCityName"));
100         bibInfoBean.setDeliveryStateCode(kualiConfigurationService.getPropertyValueAsString("deliveryStateCode"));
101         bibInfoBean.setDeliveryPostalCode(kualiConfigurationService.getPropertyValueAsString("deliveryPostalCode"));
102         bibInfoBean.setDeliveryCountryCode(kualiConfigurationService.getPropertyValueAsString("deliveryCountryCode"));
103         bibInfoBean.setDeliveryToName(kualiConfigurationService.getPropertyValueAsString("deliveryToName"));
104 /*        bibInfoBean.setVendorCode(properties.getProperty("userName"));
105         bibInfoBean.setVendorCustomerNumber(properties.getProperty("userName"));*/
106         bibInfoBean.setUom(kualiConfigurationService.getPropertyValueAsString("uom"));
107         bibInfoBean.setItemTypeCode(kualiConfigurationService.getPropertyValueAsString("itemTypeCode"));
108         bibInfoBean.setListprice(new Double(kualiConfigurationService.getPropertyValueAsString("listprice")));
109         bibInfoBean.setQuantity(new Long(kualiConfigurationService.getPropertyValueAsString("quantity")));
110         bibInfoBean.setPurchaseOrderTransmissionMethodCode(kualiConfigurationService.getPropertyValueAsString("purchaseOrderTransmissionMethodCode"));
111         bibInfoBean.setPurchaseOrderCostSourceCode(kualiConfigurationService.getPropertyValueAsString("purchaseOrderCostSourceCode"));
112         bibInfoBean.setRequestorPersonName(kualiConfigurationService.getPropertyValueAsString("requestorPersonName"));
113         bibInfoBean.setRequestorPersonPhoneNumber(kualiConfigurationService.getPropertyValueAsString("requestorPersonPhoneNumber"));
114         bibInfoBean.setRequestorPersonEmailAddress(kualiConfigurationService.getPropertyValueAsString("requestorPersonEmailAddress"));
115         bibInfoBean.setLocation(kualiConfigurationService.getPropertyValueAsString("location"));
116         bibInfoBean.setOrganizationAutomaticPurchaseOrderLimit(kualiConfigurationService.getPropertyValueAsString("organizationAutomaticPurchaseOrderLimit"));
117         bibInfoBean.setPurchaseOrderAutomaticIndicator(kualiConfigurationService.getPropertyValueAsString("purchaseOrderAutomaticIndicator") == "true" ? true : false);
118         bibInfoBean.setReceivingDocumentRequiredIndicator(kualiConfigurationService.getPropertyValueAsString("receivingDocumentRequiredIndicator") == "true" ? true : false);
119         bibInfoBean.setPaymentRequestPositiveApprovalIndicator(kualiConfigurationService.getPropertyValueAsString("paymentRequestPositiveApprovalIndicator") == "true" ? true : false);
120         /*bibInfoBean.setChart(properties.getProperty("chart"));
121         bibInfoBean.setAccountNumber(properties.getProperty("accountNumber"));
122         bibInfoBean.setObjectCode(properties.getProperty("objectCode"));
123         bibInfoBean.setPercent(new Long(properties.getProperty("percent")));*/
124         if (LOG.isDebugEnabled()) {
125             LOG.debug("---------------Billing Name from property--------->" + kualiConfigurationService.getPropertyValueAsString("billingName"));
126         }
127         bibInfoBean.setBillingName(kualiConfigurationService.getPropertyValueAsString("billingName"));
128         bibInfoBean.setBillingCityName(kualiConfigurationService.getPropertyValueAsString("billingCityName"));
129         bibInfoBean.setBillingCountryCode(kualiConfigurationService.getPropertyValueAsString("billingCountryCode"));
130         bibInfoBean.setBillingLine1Address(kualiConfigurationService.getPropertyValueAsString("billingLine1Address"));
131         bibInfoBean.setBillingPhoneNumber(kualiConfigurationService.getPropertyValueAsString("billingPhoneNumber"));
132         bibInfoBean.setBillingPostalCode(kualiConfigurationService.getPropertyValueAsString("billingPostalCode"));
133         bibInfoBean.setBillingStateCode(kualiConfigurationService.getPropertyValueAsString("billingStateCode"));
134        /* bibInfoBean.setLicensingRequirementIndicator(kualiConfigurationService.getPropertyValueAsBoolean("licensingRequirementIndicator"));*/
135         /*bibInfoBean.setLicensingRequirementCode(kualiConfigurationService.getPropertyValueAsString("licensingRequirementCode"));*/
136         return bibInfoBean;
137     }
138 
139 
140     @Override
141     public String processBibInfoForOperURL(String openUrlString, BibInfoBean bibInfoBean) throws Exception {
142         try {
143             String user;
144             if (GlobalVariables.getUserSession() != null) {
145                 user = GlobalVariables.getUserSession().getPrincipalName();
146             } else {
147                 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
148                 user = kualiConfigurationService.getPropertyValueAsString("userName");
149             }
150             GlobalVariables.setUserSession(new UserSession(user));
151             BuildOpenUrlBibInfoBean buildOpenUrlBibInfoBean = SpringContext.getBean(BuildOpenUrlBibInfoBean.class);
152             bibInfoBean = buildOpenUrlBibInfoBean.getBean(bibInfoBean, openUrlString);
153             if (bibInfoBean.getTitle() == null || "".equalsIgnoreCase(bibInfoBean.getTitle())) {
154                 return OleSelectConstant.SOAP_INVALID_OPENURL;
155             }
156             bibInfoBean.setRequestSourceUrl(openUrlString);
157             //bibInfoBean.setRequestSource(OleSelectConstant.REQUEST_SRC_TYPE_WEBFORM);
158             bibInfoBean.setRequisitionSource(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM);
159             bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_WEBFORM);
160             bibInfoBean = setBibInfoDefaultValues(bibInfoBean);
161             OleRequisitionCreateDocumentService createDocument = SpringContext.getBean(OleRequisitionCreateDocumentServiceImpl.class);
162             List<BibInfoBean> bibInfoBeanList = getBibInfoBeanList(bibInfoBean);
163             String docNumber = createDocument.saveRequisitionDocument(bibInfoBeanList, true);
164             return docNumber;
165         } catch (Exception e) {
166             LOG.error("Error processing for SOAP citation document creation----" + e.getMessage(), e);
167             String errorMessage = null;
168             if (GlobalVariables.getMessageMap().hasErrors()) {
169                 Map<String, AutoPopulatingList<ErrorMessage>> map = GlobalVariables.getMessageMap().getErrorMessages();
170                 for (Map.Entry<String, AutoPopulatingList<ErrorMessage>> entry : map.entrySet()) {
171                     AutoPopulatingList<ErrorMessage> errors = entry.getValue();
172                     ErrorMessage error = errors.get(0);
173                     String[] params = error.getMessageParameters();
174                     errorMessage = params[0];
175                 }
176             }
177             return OleSelectConstant.SOAP_EXCEPTION + " - " + errorMessage;
178         }
179     }
180 
181 
182     @Override
183     public String processBibInfoForForm(BibInfoBean bibInfoBean, String title, String author, String edition, String series, String publisher, String placeOfPublication, String yearOfPublication, String standardNumber, String typeOfStandardNumber,
184                                         String routeRequesterReceipt) throws Exception {
185         try {
186             String user;
187 /*            if(GlobalVariables.getUserSession()!=null){
188                 user = GlobalVariables.getUserSession().getPrincipalName();
189             }else{*/
190             kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
191             user = kualiConfigurationService.getPropertyValueAsString("userName");
192             // }
193             LOG.info("userName in processBibInfoForForm>>>>>>>>>>>>>>" + user);
194             GlobalVariables.setUserSession(new UserSession(user));
195             BuildFormBibInfoBean buildFormBibInfoBean = SpringContext.getBean(BuildFormBibInfoBean.class);
196             bibInfoBean = buildFormBibInfoBean.getBean(bibInfoBean, title, author, edition, series, publisher, placeOfPublication, yearOfPublication, standardNumber, typeOfStandardNumber, routeRequesterReceipt);
197             bibInfoBean = setBibInfoDefaultValues(bibInfoBean);
198             //bibInfoBean.setRequestSource(OleSelectConstant.REQUEST_SRC_TYPE_WEBFORM);
199             bibInfoBean.setRequisitionSource(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM);
200             bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_WEBFORM);
201             OleRequisitionCreateDocumentService createDocument = SpringContext.getBean(OleRequisitionCreateDocumentServiceImpl.class);
202             List<BibInfoBean> bibInfoBeanList = getBibInfoBeanList(bibInfoBean);
203             String docNumber = createDocument.saveRequisitionDocument(bibInfoBeanList, true);
204             return docNumber;
205         } catch (Exception e) {
206             LOG.error("Error processing for SOAP form document creation----" + e.getMessage(), e);
207             String errorMessage = null;
208             if (GlobalVariables.getMessageMap().hasErrors()) {
209                 Map<String, AutoPopulatingList<ErrorMessage>> map = GlobalVariables.getMessageMap().getErrorMessages();
210                 for (Map.Entry<String, AutoPopulatingList<ErrorMessage>> entry : map.entrySet()) {
211                     AutoPopulatingList<ErrorMessage> errors = entry.getValue();
212                     ErrorMessage error = errors.get(0);
213                     String[] params = error.getMessageParameters();
214                     errorMessage = params[0];
215                 }
216             }
217             return OleSelectConstant.SOAP_EXCEPTION + " - " + errorMessage;
218         }
219     }
220 
221     private List<BibInfoBean> getBibInfoBeanList(BibInfoBean bibInfoBean) throws Exception {
222         return Collections.singletonList(bibInfoBean);
223 
224     }
225 
226     public ConfigurationService getConfigurationService() {
227         return kualiConfigurationService;
228     }
229 
230     public void setConfigurationService(ConfigurationService kualiConfigurationService) {
231         this.kualiConfigurationService = kualiConfigurationService;
232     }
233 
234 
235 }