View Javadoc
1   package org.kuali.ole.select.document.service.impl;
2   
3   import org.apache.commons.csv.CSVFormat;
4   import org.apache.commons.csv.CSVParser;
5   import org.apache.commons.csv.CSVRecord;
6   import org.apache.commons.lang.StringUtils;
7   import org.apache.log4j.Logger;
8   import org.kuali.ole.OLEConstants;
9   import org.kuali.ole.coa.businessobject.Account;
10  import org.kuali.ole.coa.businessobject.Chart;
11  import org.kuali.ole.coa.businessobject.ObjectCode;
12  import org.kuali.ole.coa.service.AccountService;
13  import org.kuali.ole.describe.bo.OleLocation;
14  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
15  
16  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
17  import org.kuali.ole.select.businessobject.*;
18  import org.kuali.ole.select.document.OLEPurchaseOrderBatchDocument;
19  import org.kuali.ole.select.document.OlePurchaseOrderDocument;
20  import org.kuali.ole.select.document.service.OLEPurchaseOrderBatchService;
21  import org.kuali.ole.select.document.service.OlePurchaseOrderService;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.ole.vnd.businessobject.VendorAddress;
24  import org.kuali.ole.vnd.businessobject.VendorDetail;
25  import org.kuali.rice.core.api.config.property.ConfigContext;
26  
27  import org.kuali.rice.core.api.util.type.KualiDecimal;
28  import org.kuali.rice.core.api.util.type.KualiInteger;
29  import org.kuali.rice.kew.api.KewApiConstants;
30  import org.kuali.rice.kew.api.exception.WorkflowException;
31  import org.kuali.rice.krad.UserSession;
32  import org.kuali.rice.krad.bo.AdHocRoutePerson;
33  import org.kuali.rice.krad.exception.ValidationException;
34  import org.kuali.rice.krad.service.BusinessObjectService;
35  import org.kuali.rice.krad.util.GlobalVariables;
36  import org.springframework.transaction.UnexpectedRollbackException;
37  import org.springframework.web.multipart.MultipartFile;
38  
39  import java.io.*;
40  import java.math.BigDecimal;
41  import java.nio.charset.Charset;
42  import java.text.SimpleDateFormat;
43  import java.util.*;
44  
45  /**
46   * Created with IntelliJ IDEA.
47   * User: gopalp
48   * Date: 5/18/15
49   * Time: 12:38 PM
50   * To change this template use File | Settings | File Templates.
51   */
52  public class OLEPurchaseOrderBatchServiceImpl implements OLEPurchaseOrderBatchService {
53  
54      protected static final Logger LOG = Logger.getLogger(OLEPurchaseOrderBatchServiceImpl.class);
55      private final String FILE_HEADER = "documentNumber,documentDescription,purapDocumentIdentifier," +
56              "vendorHeaderGeneratedIdentifier,vendorDetailAssignedIdentifier,assignedUserPrincipalName," +
57              "recurringPaymentTypeCode,poBeginDate,poEndDate,deliveryCampusCode,deliveryBuildingCode," +
58              "deliveryBuildingLine1Address,deliveryBuildingLine2Address,deliveryBuildingRoomNumber,deliveryStateCode," +
59              "deliveryPostalCode,deliveryCountryCode,deliveryToEmailAddress,deliveryToName,deliveryToPhoneNumber," +
60              "deliveryBuildingCode,deliveryInstructionText,itemLineNumber,itemCopyNumber,format,category," +
61              "itemPriceSource,requestSource,itemQuantity,itemNoOfParts,itemListPrice,itemPublicViewIndicator," +
62              "doNotClaim,itemRouteToRequestorIndicator,itemLocation,vendorItemPoNumber,accountingLineIndex," +
63              "chartOfAccountsCode,accountNumber,financialObjectCode,accountLinePercent";
64  
65      List<Chart> charts = new ArrayList<>();
66      List<Account> accounts = new ArrayList<>();
67      List<ObjectCode> objects = new ArrayList<>();
68      List<VendorDetail> vendorDetails = new ArrayList<VendorDetail>();
69      List<OleCategory> categories = new ArrayList<OleCategory>();
70      List<OleFormatType> formatTypes = new ArrayList<OleFormatType>();
71      List<OleItemPriceSource> itemPriceSources = new ArrayList<OleItemPriceSource>();
72      List<OleRequestSourceType> requestSourceTypes = new ArrayList<OleRequestSourceType>();
73      List<OleLocation> locations = new ArrayList<OleLocation>();
74      List<String> chartList = new ArrayList<>();
75      List<String> accountList = new ArrayList<>();
76      List<String> objectCodeList = new ArrayList<>();
77      List<String> vendorDetailList = new ArrayList<>();
78      List<String> categoryList = new ArrayList<>();
79      List<String> formatList = new ArrayList<>();
80      List<String> requestSourceList = new ArrayList<>();
81      List<String> priceSourceList = new ArrayList<>();
82      List<String> locationList = new ArrayList<>();
83      StringBuffer message;
84      public Integer poNumber = 0;
85      private FileWriter fileWriter = null;
86      private OlePurchaseOrderService olePurchaseOrderService;
87  
88      private BusinessObjectService businessObjectService;
89      private String fileSeparator = System.getProperty("file.separator");
90  
91      public void readFile(OLEPurchaseOrderBatchDocument olePurchaseOrderBatchDocument, UserSession userSession, File file) {
92          GlobalVariables.setUserSession(userSession);
93          charts = (List<Chart>) getBusinessObjectService().findAll(Chart.class);
94          accounts = (List<Account>) getBusinessObjectService().findAll(Account.class);
95          objects = (List<ObjectCode>) getBusinessObjectService().findAll(ObjectCode.class);
96          vendorDetails = (List<VendorDetail>) getBusinessObjectService().findAll(VendorDetail.class);
97          categories = (List<OleCategory>) getBusinessObjectService().findAll(OleCategory.class);
98          formatTypes = (List<OleFormatType>) getBusinessObjectService().findAll(OleFormatType.class);
99          itemPriceSources = (List<OleItemPriceSource>) getBusinessObjectService().findAll(OleItemPriceSource.class);
100         requestSourceTypes = (List<OleRequestSourceType>) getBusinessObjectService().findAll(OleRequestSourceType.class);
101         locations = (List<OleLocation>) getBusinessObjectService().findAll(OleLocation.class);
102         for (Chart chart : (List<Chart>) charts) {
103             chartList.add(chart.getChartOfAccountsCode());
104         }
105         for (Account account : (List<Account>) accounts) {
106             accountList.add(account.getAccountNumber() + account.getChartOfAccountsCode());
107         }
108         for (ObjectCode objectCode : (List<ObjectCode>) objects) {
109             objectCodeList.add(objectCode.getFinancialObjectCode() + objectCode.getChartOfAccountsCode());
110         }
111         for (VendorDetail vendorDetail : vendorDetails) {
112             vendorDetailList.add(vendorDetail.getVendorHeaderGeneratedIdentifier().toString());
113         }
114         for (OleCategory category : categories) {
115             categoryList.add(category.getCategory());
116         }
117         for (OleFormatType formatType : formatTypes) {
118             formatList.add(formatType.getFormatTypeName());
119         }
120         for (OleItemPriceSource itemPriceSource : itemPriceSources) {
121             priceSourceList.add(itemPriceSource.getItemPriceSource());
122         }
123         for (OleRequestSourceType requestSourceType : requestSourceTypes) {
124             requestSourceList.add(requestSourceType.getRequestSourceType());
125         }
126         for (OleLocation location : locations) {
127             locationList.add(location.getLocationCode());
128         }
129         try {
130             message = new StringBuffer();
131 
132 
133             List<Map> list = readCSVAndPreparePOs(file);
134 
135             message.append("\n");
136             message.append("Starting Purchase Order Bulk Amendment Document :" + olePurchaseOrderBatchDocument.getDocumentNumber());
137             message.append("\n");
138             message.append("\n");
139             OlePurchaseOrderDocument purchaseOrderDocument = null;
140             String poId = "";
141             for (int index = 0; index < list.size(); index++) {
142                 if (index == 0) {
143                     poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
144                 }
145                 if (list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString().equals(poId)) {
146                     poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
147                     if (validatePOFields(list.get(index))) {
148                         message.append("Started creating POA document for PO# : " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID));
149                         message.append("\n");
150                         purchaseOrderDocument = createPurchaseOrderAmendmentDocument(list.get(index), olePurchaseOrderBatchDocument.getDocumentNumber());
151                     } else {
152                         message.append("Creation of POA Document failed for PO# " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID) + " and Item Line Number :" + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO));
153                         message.append("\n");
154                         message.append("\n");
155                     }
156                 } else if (purchaseOrderDocument != null) {
157 
158                     try {
159                         if (!(poNumber.equals(purchaseOrderDocument.getPurapDocumentIdentifier()))) {
160                             String errorMessage = getOlePurchaseOrderService().createPurchaseOrderAmendmentDocument(purchaseOrderDocument, olePurchaseOrderBatchDocument.getDocumentNumber());
161                             if (StringUtils.isNotEmpty(errorMessage)) {
162                                 message.append(errorMessage);
163                                 message.append("Failed to create POA document for PO# : " + purchaseOrderDocument.getPurapDocumentIdentifier());
164                                 message.append("\n");
165                             } else {
166                                 message.append("Successfully created POA document for PO# : " + purchaseOrderDocument.getPurapDocumentIdentifier());
167                                 message.append("\n");
168                             }
169                         }
170                     } catch (Exception e) {
171                         message.append("Creation of POA Document failed for PO Doc# " + purchaseOrderDocument.getDocumentNumber());
172                         message.append("\n");
173                     }
174                     purchaseOrderDocument = null;
175                     poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
176                     if (list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString().equals(poId)) {
177                         if (validatePOFields(list.get(index))) {
178                             message.append("Started creating POA document for PO# : " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID));
179                             message.append("\n");
180                             purchaseOrderDocument = createPurchaseOrderAmendmentDocument(list.get(index), olePurchaseOrderBatchDocument.getDocumentNumber());
181 
182                         } else {
183                             message.append("Creation of POA Document failed for PO# " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID) + " and Item Line Number :" + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO));
184                             message.append("\n");
185                             message.append("\n");
186                         }
187                     }
188 
189 
190                 } else {
191                     if (purchaseOrderDocument == null) {
192                         poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
193                         if (list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString().equals(poId)) {
194                             if (validatePOFields(list.get(index))) {
195                                 message.append("Started creating POA document for PO# : " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID));
196                                 message.append("\n");
197                                 purchaseOrderDocument = createPurchaseOrderAmendmentDocument(list.get(index), olePurchaseOrderBatchDocument.getDocumentNumber());
198 
199                             } else {
200                                 message.append("Creation of POA Document failed for PO# " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID) + " and Item Line Number :" + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO));
201                                 message.append("\n");
202                                 message.append("\n");
203                             }
204                         }
205 
206                     }
207                 }
208             }
209             if (purchaseOrderDocument != null) {
210                 try {
211                     if (!(poNumber.equals(purchaseOrderDocument.getPurapDocumentIdentifier()))) {
212                         String errorMessage = getOlePurchaseOrderService().createPurchaseOrderAmendmentDocument(purchaseOrderDocument, olePurchaseOrderBatchDocument.getDocumentNumber());
213                         if (StringUtils.isNotEmpty(errorMessage)) {
214                             message.append(errorMessage);
215                             message.append("\n");
216                             message.append("Failed to create POA document for PO# : " + purchaseOrderDocument.getPurapDocumentIdentifier());
217                             message.append("\n");
218                         } else {
219                             message.append("Successfully created POA document for PO# : " + purchaseOrderDocument.getPurapDocumentIdentifier());
220                             message.append("\n");
221                         }
222                     }
223                 } catch (Exception e) {
224                     LOG.info("Error Occurred  " + e.getMessage());
225                 }
226             }
227             writeFile();
228         } catch (Exception e) {
229             message.append("Error Occurred while creating POA Document");
230             message.append("\n");
231         }
232 
233     }
234 
235     public List<Map> readCSVAndPreparePOs(File file)
236             throws IOException {
237 
238         List<Map> list = new ArrayList<>();
239 
240         String fileName;
241         if (file != null) {
242             File csvData = file;
243             CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.EXCEL);
244             Iterator<CSVRecord> iterator = parser.getRecords().iterator();
245             CSVRecord headerData = iterator.next();
246             while (iterator.hasNext()) {
247                 CSVRecord csvRecord = iterator.next();
248                 Map map = new HashMap();
249                 for (int x = 0; x < headerData.size(); x++) {
250                     map.put(headerData.get(x), csvRecord.get(x));
251                 }
252                 list.add(map);
253             }
254         }
255         return list;
256     }
257 
258     public OlePurchaseOrderDocument createPurchaseOrderAmendmentDocument(Map map, String documentNumber) {
259         String purapDocumentIdentifier = (String) map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID);
260         OlePurchaseOrderDocument purchaseOrderDocument = null;
261         if (purapDocumentIdentifier != null) {
262             if (purchaseOrderDocument == null) {
263                 Map poMap = new HashMap();
264                 poMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID, purapDocumentIdentifier);
265                 purchaseOrderDocument = getPODocumentByPrimaryKey(poMap);
266             }
267 
268             try {
269                 purchaseOrderDocument = updateDocument(purchaseOrderDocument, map);
270                 purchaseOrderDocument = updateVendor(purchaseOrderDocument, map);
271                 int lineNumber = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO).toString());
272                 purchaseOrderDocument = updateItem(purchaseOrderDocument, lineNumber, map);
273                 purchaseOrderDocument = updateAccount(purchaseOrderDocument, lineNumber, map);
274             } catch (UnexpectedRollbackException re) {
275                 message.append(re.getMessage());
276                 message.append("\n");
277             } catch (ValidationException ve) {
278                 message.append(ve.getMessage());
279                 message.append("\n");
280             } catch (Exception ex) {
281                 message.append("Failed to create POA document for PO document number : " + purchaseOrderDocument.getDocumentNumber());
282                 message.append("\n");
283 
284             }
285         }
286 //        sendFyiForAccount(purchaseOrderDocument);
287         return purchaseOrderDocument;
288     }
289 
290 
291     public OlePurchaseOrderDocument updateItem(OlePurchaseOrderDocument purchaseOrderDocument, int itemLineNumber, Map map) throws Exception {
292         for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderDocument.getItemsActiveOnly()) {
293             if (olePurchaseOrderItem.getItemLineNumber() != null && olePurchaseOrderItem.getItemLineNumber() == itemLineNumber) {
294                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_ITEM_NO).equals("null")) {
295                     olePurchaseOrderItem.setVendorItemPoNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_ITEM_NO).toString());
296                 } else {
297                     olePurchaseOrderItem.setVendorItemPoNumber("");
298                 }
299                 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC) != null) {
300                     olePurchaseOrderItem.setItemLocation(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC).toString());
301                 }
302                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIST_PRC).equals("null")) {
303                     olePurchaseOrderItem.setItemListPrice(new KualiDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIST_PRC).toString()));
304                 }
305                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_QTY).equals("null")) {
306                     olePurchaseOrderItem.setItemQuantity(new KualiDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_QTY).toString()));
307                 }
308                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).equals("null")) {
309                     olePurchaseOrderItem.setItemNoOfParts(new KualiInteger(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).toString()));
310                 }
311                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_PUB_VIEW_IND).equals("null")) {
312                     boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_PUB_VIEW_IND).toString());
313                     olePurchaseOrderItem.setItemPublicViewIndicator(indicator);
314                 }
315                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DO_NOT_CLAIM).equals("null")) {
316                     boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DO_NOT_CLAIM).toString());
317                     olePurchaseOrderItem.setDoNotClaim(indicator);
318                 }
319                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_ROUTE_IND).equals("null")) {
320                     boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_ROUTE_IND).toString());
321                     olePurchaseOrderItem.setItemRouteToRequestorIndicator(indicator);
322                 }
323                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).equals("null")) {
324                     olePurchaseOrderItem.setItemNoOfParts(new KualiInteger(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).toString()));
325                 }
326                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_COPY_NO).equals("null")) {
327                     olePurchaseOrderItem.setCopyNumber((map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_COPY_NO).toString()));
328                 }
329                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).equals("null")) {
330                     if (getFormatId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).toString()) != null) {
331                         olePurchaseOrderItem.setFormatTypeId(getFormatId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).toString()));
332                     }
333                 }
334                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).equals("null")) {
335                     if (getCategoryId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).toString()) != null) {
336                         olePurchaseOrderItem.setCategoryId(getCategoryId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).toString()));
337                     }
338                 }
339                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).equals("null")) {
340                     if (getItemPriceSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).toString()) != null) {
341                         olePurchaseOrderItem.setItemPriceSourceId(getItemPriceSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).toString()));
342                     }
343                 }
344                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).equals("null")) {
345                     if (getRequestSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).toString()) != null) {
346                         olePurchaseOrderItem.setRequestSourceTypeId(getRequestSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).toString()));
347                     }
348                 }
349             }
350         }
351         return purchaseOrderDocument;
352 
353     }
354 
355     public OlePurchaseOrderDocument updateAccount(OlePurchaseOrderDocument purchaseOrderDocument, int itemLineNumber, Map map) {
356         for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderDocument.getItemsActiveOnly()) {
357             if (olePurchaseOrderItem.getItemLineNumber() != null && olePurchaseOrderItem.getItemLineNumber() == itemLineNumber) {
358                 //for (PurApAccountingLine accountingLine : olePurchaseOrderItem.getSourceAccountingLines()) {
359                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LINE_INDEX).equals("null")) {
360                     int index = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LINE_INDEX).toString()) - 1;
361                     PurApAccountingLine accountingLine = olePurchaseOrderItem.getSourceAccountingLines().get(index);
362                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).equals("null")) {
363                         accountingLine.setChartOfAccountsCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString());
364                     }
365                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).equals("null")) {
366                         accountingLine.setAccountNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).toString());
367                     }
368                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).equals("null")) {
369                         accountingLine.setFinancialObjectCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).toString());
370                     }
371                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LIN_PERC).equals("null")) {
372                         accountingLine.setAccountLinePercent(new BigDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LIN_PERC).toString()));
373                     }
374 
375                 }
376             }
377         }
378         return purchaseOrderDocument;
379     }
380 
381     public OlePurchaseOrderDocument updateDocument(OlePurchaseOrderDocument purchaseOrderDocument, Map map) {
382 
383         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ST_CD).equals("null")) {
384             purchaseOrderDocument.setDeliveryStateCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ST_CD).toString());
385         }
386         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ROOM_NO).equals("null")) {
387             purchaseOrderDocument.setDeliveryBuildingRoomNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ROOM_NO).toString());
388         }
389         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE1_ADDR).equals("null")) {
390             purchaseOrderDocument.setDeliveryBuildingLine1Address(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE1_ADDR).toString());
391         }
392         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE2_ADDR).equals("null")) {
393             purchaseOrderDocument.setDeliveryBuildingLine2Address(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE2_ADDR).toString());
394         }
395         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_CAMPUS_CD).equals("null")) {
396             purchaseOrderDocument.setDeliveryCampusCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_CAMPUS_CD).toString());
397         }
398         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_COUNTRY_CD).equals("null")) {
399             purchaseOrderDocument.setDeliveryCountryCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_COUNTRY_CD).toString());
400         }
401         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_POSTAL_CD).equals("null")) {
402             purchaseOrderDocument.setDeliveryPostalCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_POSTAL_CD).toString());
403         }
404         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_BUL_CD).equals("null")) {
405             purchaseOrderDocument.setDeliveryBuildingCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_BUL_CD).toString());
406         }
407         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_EMAIL_ADDR).equals("null")) {
408             purchaseOrderDocument.setDeliveryToEmailAddress(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_EMAIL_ADDR).toString());
409         }
410         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_NAME).equals("null")) {
411             purchaseOrderDocument.setDeliveryToName(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_NAME).toString());
412         }
413         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_PHONE_NO).equals("null")) {
414             purchaseOrderDocument.setDeliveryToPhoneNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_PHONE_NO).toString());
415         }
416         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_INST_NT).equals("null")) {
417             purchaseOrderDocument.setDeliveryInstructionText(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_INST_NT).toString());
418         }
419 
420         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DOCUMENT_DESC).equals("null")) {
421             purchaseOrderDocument.getDocumentHeader().setDocumentDescription(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DOCUMENT_DESC).toString());
422         }
423         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ASSIGN_TO_PRCPL_NM).equals("null")) {
424             purchaseOrderDocument.setAssignedUserPrincipalName(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ASSIGN_TO_PRCPL_NM).toString());
425         }
426         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).equals("")) {
427             purchaseOrderDocument.setRecurringPaymentTypeCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).toString());
428         } else {
429             purchaseOrderDocument.setRecurringPaymentTypeCode(null);
430         }
431         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).equals("")) {
432             SimpleDateFormat format = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.TIMESTAMP_FORMAT);
433             purchaseOrderDocument.setPurchaseOrderBeginDate(java.sql.Date.valueOf(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).toString()));
434         } else {
435             purchaseOrderDocument.setPurchaseOrderBeginDate(null);
436         }
437         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).equals("")) {
438             SimpleDateFormat format = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.TIMESTAMP_FORMAT);
439             purchaseOrderDocument.setPurchaseOrderEndDate(java.sql.Date.valueOf(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).toString()));
440         } else {
441             purchaseOrderDocument.setPurchaseOrderEndDate(null);
442         }
443 
444         return purchaseOrderDocument;
445     }
446 
447     public OlePurchaseOrderDocument updateVendor(OlePurchaseOrderDocument purchaseOrderDocument, Map map) {
448         Map vendorMap = new HashMap();
449         vendorMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER, map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER));
450         vendorMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.VEN_DTL_ASSIGN_ID, map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VEN_DTL_ASSIGN_ID));
451         VendorDetail vendorDetail = getBusinessObjectService().findByPrimaryKey(VendorDetail.class, vendorMap);
452         if (vendorDetail != null) {
453             purchaseOrderDocument.setVendorName(vendorDetail.getVendorName());
454             purchaseOrderDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier());
455             purchaseOrderDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier());
456             purchaseOrderDocument.setVendorAliasName("");
457             purchaseOrderDocument.setVendorPaymentTermsCode(vendorDetail.getVendorPaymentTermsCode());
458             purchaseOrderDocument.setVendorShippingPaymentTermsCode(vendorDetail.getVendorShippingPaymentTermsCode());
459             for (VendorAddress vendorAddress : vendorDetail.getVendorAddresses()) {
460                 if (vendorAddress.isActive() && vendorAddress.isVendorDefaultAddressIndicator()) {
461                     purchaseOrderDocument.setVendorCityName(vendorAddress.getVendorCityName());
462                     purchaseOrderDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address());
463                     purchaseOrderDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address());
464                     purchaseOrderDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode());
465                     purchaseOrderDocument.setVendorStateCode(vendorAddress.getVendorStateCode());
466                     purchaseOrderDocument.setVendorPostalCode(vendorAddress.getVendorZipCode());
467                 }
468             }
469         }
470         return purchaseOrderDocument;
471     }
472 
473     public void writeFile() {
474         String fileName = OLEConstants.OLEPurchaseOrderBulkAmendment.FILE_NM;
475         String filePath = getPOBACSVDirectory() + fileSeparator + OLEConstants.POBA_DIRECTORY + fileSeparator;
476         try {
477             FileWriter fileWriter = new FileWriter(filePath+fileName);
478             fileWriter.append(message.toString());
479             fileWriter.flush();
480             fileWriter.close();
481             LOG.info("POBA output file created successfully");
482         } catch (IOException e) {
483             e.printStackTrace();
484         }
485     }
486 
487     public List<String> createFileForPOBA(OLEPurchaseOrderBatchDocument olePurchaseOrderBatchDocument) throws
488             Exception {
489 
490         String fileDirectory = getPOBACSVDirectory();
491         String fileName = fileDirectory + fileSeparator + OLEConstants.POBA_DIRECTORY + fileSeparator + olePurchaseOrderBatchDocument.getDocIdIngestFile().getOriginalFilename();
492         BufferedWriter documentOut = new BufferedWriter(new FileWriter(fileName));
493         String documentFileContent = new String(olePurchaseOrderBatchDocument.getDocIdIngestFile().getBytes());
494         documentOut.write(documentFileContent);
495         documentOut.close();
496         BufferedReader br = new BufferedReader(new FileReader(fileName));
497         String text = null;
498         List<String> poIds = new ArrayList<String>();
499         while ((text = br.readLine()) != null) {
500             if (StringUtils.isNotEmpty(text)) {
501                 poIds.add(text);
502             }
503         }
504         br.close();
505         return poIds;
506     }
507 
508     public boolean validatePOFields(Map map) {
509         String poId = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
510         Map invMap = new HashMap();
511 
512         boolean result = true;
513         if (!vendorDetailList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER))) {
514             message.append("Invalid Vendor Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER));
515             message.append("\n");
516             result = result & false;
517         }
518         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).equals("null") && !categoryList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD))) {
519             message.append("Invalid Category Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD));
520             message.append("\n");
521             result = result & false;
522         }
523         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).equals("null") && !formatList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD))) {
524             message.append("Invalid Format Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD));
525             message.append("\n");
526             result = result & false;
527         }
528         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).equals("null") && !priceSourceList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE))) {
529             message.append("Invalid Item Price Source Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE));
530             message.append("\n");
531             result = result & false;
532         }
533         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).equals("null") && !requestSourceList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE))) {
534             message.append("Invalid Request Source Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE));
535             message.append("\n");
536             result = result & false;
537         }
538         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC).equals("null") && !locationList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC))) {
539             message.append("Invalid Location code : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC));
540             message.append("\n");
541             result = result & false;
542         }
543         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD) != null && !chartList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD))) {
544             message.append("Invalid Chart code : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD));
545             message.append("\n");
546             result = result & false;
547         }
548         String accountNumber = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).toString() + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString();
549         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO) != null && !accountList.contains(accountNumber)) {
550             message.append("Invalid Account Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO));
551             message.append("\n");
552             result = result & false;
553         }
554         String objectCode = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).toString() + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString();
555         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD) != null && !objectCodeList.contains(objectCode)) {
556             message.append("Invalid Financial Object Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD));
557             message.append("\n");
558             result = result & false;
559         }
560         if (!result) {
561             poNumber = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString());
562         }
563         return result;
564     }
565 
566     private FileWriter getFileWriterForPOCSV() throws IOException {
567         String fileDirectory = getPOBACSVDirectory();
568         Date date = new Date();
569         String fileCreationDate = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.DATE_FORMAT).format(date).replace(":", "");
570 
571         String fileName = fileDirectory + fileSeparator + OLEConstants.POBA_DIRECTORY + fileSeparator + fileCreationDate + OLEConstants.OLEPurchaseOrderBulkAmendment.OUTPUT_FILE_NAME;
572         fileWriter = new FileWriter(fileName);
573         return fileWriter;
574     }
575 
576     public void downloadCSV(List<String> poIds) {
577         String NEW_LINE_SEPARATOR = "\n";
578         try {
579             fileWriter = getFileWriterForPOCSV();
580             fileWriter.append(FILE_HEADER.toString());
581             fileWriter.append(NEW_LINE_SEPARATOR);
582             for (String poid : poIds) {
583                 Map poMap = new HashMap();
584                 poMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID, poid);
585                 poMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_CUR_IND, true);
586                 OlePurchaseOrderDocument purchaseOrderDocument = getPODocumentByPrimaryKey(poMap);
587 
588                 for (Iterator iterator = purchaseOrderDocument.getItems().iterator(); iterator.hasNext(); ) {
589                     OlePurchaseOrderItem item = (OlePurchaseOrderItem) iterator.next();
590                     Integer accountingLineNumber = 1;
591                     if (item.getItemLineNumber() != null) {
592                         List<PurApAccountingLine> sourceAccountingLines = item.getSourceAccountingLines();
593                         for (Iterator<PurApAccountingLine> purApAccountingLineIterator = sourceAccountingLines.iterator(); purApAccountingLineIterator.hasNext(); ) {
594                             PurApAccountingLine accountingLine = purApAccountingLineIterator.next();
595                             writeValue(purchaseOrderDocument.getDocumentNumber());
596                             writeValue(purchaseOrderDocument.getDocumentHeader().getDocumentDescription());
597                             writeValue(purchaseOrderDocument.getPurapDocumentIdentifier().toString());
598                             writeValue(purchaseOrderDocument.getVendorHeaderGeneratedIdentifier().toString());
599                             writeValue(purchaseOrderDocument.getVendorDetailAssignedIdentifier().toString());
600                             writeValue(purchaseOrderDocument.getAssignedUserPrincipalName());
601                             writeValue(purchaseOrderDocument.getRecurringPaymentTypeCode());
602                             writeValue(purchaseOrderDocument.getPurchaseOrderBeginDate() != null ? purchaseOrderDocument.getPurchaseOrderBeginDate().toString() : null);
603                             writeValue(purchaseOrderDocument.getPurchaseOrderEndDate() != null ? purchaseOrderDocument.getPurchaseOrderEndDate().toString() : null);
604                             writeValue(purchaseOrderDocument.getDeliveryCampusCode());
605                             writeValue(purchaseOrderDocument.getDeliveryBuildingCode());
606                             writeValue(purchaseOrderDocument.getDeliveryBuildingLine1Address());
607                             writeValue(purchaseOrderDocument.getDeliveryBuildingLine2Address());
608                             writeValue(purchaseOrderDocument.getDeliveryBuildingRoomNumber());
609                             writeValue(purchaseOrderDocument.getDeliveryStateCode());
610                             writeValue(purchaseOrderDocument.getDeliveryPostalCode());
611                             writeValue(purchaseOrderDocument.getDeliveryCountryCode());
612                             writeValue(purchaseOrderDocument.getDeliveryToEmailAddress());
613                             writeValue(purchaseOrderDocument.getDeliveryToName());
614                             writeValue(purchaseOrderDocument.getDeliveryToPhoneNumber());
615                             writeValue(purchaseOrderDocument.getDeliveryBuildingCode());
616                             writeValue(purchaseOrderDocument.getDeliveryInstructionText());
617                             writeValue(item.getItemLineNumber().toString());
618                             writeValue(item.getCopyNumber());
619                             writeValue(item.getFormatTypeName() != null ? item.getFormatTypeName().getFormatTypeName() : null);
620                             writeValue(item.getCategory() != null ? item.getCategory().getCategory() : null);
621                             writeValue(item.getItemPriceSource() != null ? item.getItemPriceSource().getItemPriceSource() : null);
622                             writeValue(item.getOleRequestSourceType() != null ? item.getOleRequestSourceType().getRequestSourceType() : null);
623                             writeValue(item.getItemQuantity().toString());
624                             writeValue(item.getItemNoOfParts().toString());
625                             writeValue(item.getItemListPrice().toString());
626                             Boolean publicViewIndicator = item.isItemPublicViewIndicator();
627                             writeValue(publicViewIndicator.toString());
628                             Boolean doNotClaimIndicator = item.isDoNotClaim();
629                             writeValue(doNotClaimIndicator.toString());
630                             Boolean routeToRequestorIndicator = item.isItemRouteToRequestorIndicator();
631                             writeValue(routeToRequestorIndicator.toString());
632                             writeValue(item.getItemLocation());
633                             writeValue(item.getVendorItemPoNumber());
634                             writeValue(accountingLineNumber.toString());
635                             writeValue(accountingLine.getChartOfAccountsCode());
636                             writeValue(accountingLine.getAccountNumber());
637                             writeValue(accountingLine.getFinancialObjectCode());
638                             fileWriter.append("\"").append(accountingLine.getAccountLinePercent().toString()).append
639                                     ("\"");
640                             fileWriter.append(NEW_LINE_SEPARATOR);
641                             ++accountingLineNumber;
642                         }
643                     }
644                 }
645             }
646             fileWriter.flush();
647             fileWriter.close();
648         } catch (Exception e) {
649             LOG.info(e.getMessage());
650         }
651     }
652 
653     private void writeValue(String value) throws IOException {
654         fileWriter.append("\"");
655         fileWriter.append(value);
656         fileWriter.append("\"");
657         fileWriter.append(",");
658     }
659 
660     private OlePurchaseOrderDocument getPODocumentByPrimaryKey(Map poMap) {
661         return getBusinessObjectService().findByPrimaryKey(OlePurchaseOrderDocument.class, poMap);
662     }
663 
664     private BusinessObjectService getBusinessObjectService() {
665         if (null == businessObjectService) {
666             businessObjectService = SpringContext.getBean(BusinessObjectService.class);
667         }
668         return businessObjectService;
669     }
670 
671     private String getPOBACSVDirectory() {
672         return ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.STAGING_DIRECTORY);
673     }
674 
675     public void createPOBADirectory() {
676         String stagingDirectory = ConfigContext.getCurrentContextConfig().getProperty(org.kuali.ole.sys.OLEConstants.STAGING_DIRECTORY_KEY);
677         String fileLocation = stagingDirectory + fileSeparator + org.kuali.ole.sys.OLEConstants.POBA_DIRECTORY;
678         File fileLocationDir = new File(fileLocation);
679         if (!(fileLocationDir.exists())) {
680             fileLocationDir.mkdir();
681         }
682     }
683 
684     public OlePurchaseOrderService getOlePurchaseOrderService() {
685         if (olePurchaseOrderService == null) {
686             olePurchaseOrderService = (OlePurchaseOrderService) SpringContext.getService("olePurchaseOrderService");
687         }
688         return olePurchaseOrderService;
689     }
690 
691 
692     public void sendFyiForAccount(PurchaseOrderDocument po) {
693 
694         List<AdHocRoutePerson> fyiList = createFyiFiscalOfficerListForAmendGlEntries(po);
695         String annotation = "Amendment to Purchase Order " + po.getPurapDocumentIdentifier() + "( Document id " + po.getDocumentNumber() + ")" +
696                 " in the batch process(POBA).";
697         String responsibilityNote = " ";
698         if (fyiList != null && fyiList.size() > 0) {
699             for (AdHocRoutePerson adHocPerson : fyiList) {
700                 try {
701                     po.appSpecificRouteDocumentToUser(
702                             po.getDocumentHeader().getWorkflowDocument(),
703                             adHocPerson.getPerson().getPrincipalId(),
704                             annotation,
705                             responsibilityNote);
706                 } catch (WorkflowException e) {
707                     throw new RuntimeException("Error routing fyi for document with id " + po.getDocumentNumber(), e);
708                 }
709             }
710         }
711     }
712 
713     protected List<AdHocRoutePerson> createFyiFiscalOfficerListForAmendGlEntries(PurchaseOrderDocument po) {
714 
715         List<AdHocRoutePerson> adHocRoutePersons = new ArrayList<AdHocRoutePerson>();
716         Map fiscalOfficers = new HashMap();
717         AdHocRoutePerson adHocRoutePerson = null;
718         for (PurApAccountingLine account : (List<PurApAccountingLine>) po.getSourceAccountingLines()) {
719             Account acct = SpringContext.getBean(AccountService.class).getByPrimaryId(account.getChartOfAccountsCode(),
720                     account.getAccountNumber());
721             if (acct != null) {
722                 String principalName = acct.getAccountFiscalOfficerUser().getPrincipalName();
723                 if (fiscalOfficers.containsKey(principalName) == false) {
724                     fiscalOfficers.put(principalName, principalName);
725                     adHocRoutePerson = new AdHocRoutePerson();
726                     adHocRoutePerson.setId(principalName);
727                     adHocRoutePerson.setActionRequested(KewApiConstants.ACTION_REQUEST_FYI_REQ);
728                     adHocRoutePersons.add(adHocRoutePerson);
729                 }
730             }
731         }
732         return adHocRoutePersons;
733     }
734 
735     public Integer getCategoryId(String name) {
736         Integer id = null;
737         Map idMap = new HashMap();
738         idMap.put("category", name);
739         OleCategory category = getBusinessObjectService().findByPrimaryKey(OleCategory.class, idMap);
740         if (category != null) {
741             return category.getCategoryId().intValue();
742         }
743         return id;
744     }
745 
746     public Integer getFormatId(String name) {
747         Integer id = null;
748         Map idMap = new HashMap();
749         idMap.put("formatTypeName", name);
750         OleFormatType formatType = getBusinessObjectService().findByPrimaryKey(OleFormatType.class, idMap);
751         if (formatType != null) {
752             return formatType.getFormatTypeId().intValue();
753         }
754         return id;
755     }
756 
757     public Integer getItemPriceSourceId(String name) {
758         Integer id = null;
759         Map idMap = new HashMap();
760         idMap.put("itemPriceSource", name);
761         OleItemPriceSource itemPriceSource = getBusinessObjectService().findByPrimaryKey(OleItemPriceSource.class, idMap);
762         if (itemPriceSource != null) {
763             return itemPriceSource.getItemPriceSourceId().intValue();
764         }
765         return id;
766     }
767 
768     public Integer getRequestSourceId(String name) {
769         Integer id = null;
770         Map idMap = new HashMap();
771         idMap.put("requestSourceType", name);
772         OleRequestSourceType requestSourceType = getBusinessObjectService().findByPrimaryKey(OleRequestSourceType.class, idMap);
773         if (requestSourceType != null) {
774             return requestSourceType.getRequestSourceTypeId().intValue();
775         }
776         return id;
777     }
778 
779 
780     public void setFileWriter(FileWriter fileWriter) {
781         this.fileWriter = fileWriter;
782     }
783 
784     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
785         this.businessObjectService = businessObjectService;
786     }
787 }