1 package org.kuali.ole.service;
2
3 import com.thoughtworks.xstream.XStream;
4 import org.apache.log4j.Logger;
5 import org.jfree.util.Log;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.describe.bo.OleReceiptStatus;
8 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
9 import org.kuali.ole.docstore.common.document.Bib;
10 import org.kuali.ole.docstore.common.document.Bibs;
11 import org.kuali.ole.docstore.common.document.Item;
12 import org.kuali.ole.docstore.common.search.SearchCondition;
13 import org.kuali.ole.docstore.common.search.SearchParams;
14 import org.kuali.ole.docstore.common.search.SearchResponse;
15 import org.kuali.ole.select.bo.*;
16 import org.kuali.ole.select.businessobject.OleCopy;
17 import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
18 import org.kuali.ole.select.document.OlePurchaseOrderDocument;
19 import org.kuali.ole.service.impl.OLESerialReceivingService;
20 import org.kuali.ole.service.impl.OLESerialReceivingServiceImpl;
21 import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
24 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
25 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
26 import org.kuali.rice.krad.document.DocumentBase;
27 import org.kuali.rice.krad.service.BusinessObjectService;
28 import org.kuali.rice.krad.service.DocumentService;
29 import org.kuali.rice.krad.service.KRADServiceLocator;
30
31 import java.io.BufferedReader;
32 import java.io.FileNotFoundException;
33 import java.io.FileReader;
34 import java.io.IOException;
35 import java.util.*;
36
37
38
39
40
41
42
43
44
45
46
47 public class OLESerialReceivingImportProcessor {
48
49 private static final Logger LOG = Logger.getLogger(OLESerialReceivingImportProcessor.class);
50 public static final List<String> recordTypeList = getSerialRecordTypeList();
51 private BusinessObjectService businessObjectService = getBusinessObjectService();
52 private OLESerialReceivingService oleSerialReceivingService = getOleSerialReceivingService();
53 private DocstoreClientLocator docstoreClientLocator = getDocstoreClientLocator();
54 DocumentService documentService = GlobalResourceLoader.getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
55
56 public DocstoreClientLocator getDocstoreClientLocator() {
57
58 if (docstoreClientLocator == null) {
59 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
60
61 }
62 return docstoreClientLocator;
63 }
64
65 public OLESerialReceivingImportProcessor() {
66 getBusinessObjectService();
67 getOleSerialReceivingService();
68 }
69
70 public BusinessObjectService getBusinessObjectService() {
71 if (businessObjectService == null) {
72 businessObjectService = KRADServiceLocator.getBusinessObjectService();
73 }
74 return businessObjectService;
75 }
76
77 public OLESerialReceivingService getOleSerialReceivingService() {
78 if (oleSerialReceivingService == null) {
79 oleSerialReceivingService = new OLESerialReceivingServiceImpl();
80 }
81 return oleSerialReceivingService;
82 }
83
84
85
86
87
88
89
90
91
92 public OLESerialReceivingDocuments getOleSerialReceivingRecordList(String serialReceivingXMLContent) throws Exception {
93 LOG.debug("Start of getOleSerialReceivingRecordList ");
94 XStream xStream = new XStream();
95 xStream.omitField(FinancialSystemDocumentHeader.class, "documentHeader");
96 xStream.omitField(DocumentBase.class, "documentNumber");
97 xStream.omitField(DocumentBase.class, "pessimisticLocks");
98 xStream.omitField(DocumentBase.class, "documentHeader");
99 xStream.omitField(DocumentBase.class, "adHocRoutePersons");
100 xStream.omitField(DocumentBase.class, "adHocRouteWorkgroups");
101 xStream.omitField(DocumentBase.class, "notes");
102 xStream.omitField(PersistableBusinessObjectBase.class, "newCollectionRecord");
103 xStream.alias("serialReceivingRecord", OLESerialReceivingDocuments.class);
104 xStream.aliasField("serialReceivingDocuments", OLESerialReceivingDocuments.class, "oleSerialReceivingDocuments");
105 xStream.alias("serialReceivingDocument", OLESerialReceivingDocument.class);
106 xStream.aliasField("serialReceivingRecordHistories", OLESerialReceivingDocument.class, "oleSerialReceivingHistoryList");
107 xStream.aliasField("serialReceivingTypes", OLESerialReceivingDocument.class, "oleSerialReceivingTypes");
108 xStream.alias("serialReceivingRecordHistory", OLESerialReceivingHistory.class);
109 xStream.alias("serialReceivingType", OLESerialReceivingType.class);
110 OLESerialReceivingDocuments oleSerialReceivingDocuments = (OLESerialReceivingDocuments) xStream.fromXML(serialReceivingXMLContent);
111 LOG.debug("End of getOleSerialReceivingRecordList ");
112
113
114 return oleSerialReceivingDocuments;
115 }
116
117
118
119
120
121
122
123
124 public String getSerialReceivingXMLContent( OLESerialReceivingDocuments oleSerialReceivingDocuments) throws Exception {
125 LOG.debug("Start of getSerialReceivingXMLContent ");
126 XStream xStream = new XStream();
127 xStream.omitField(FinancialSystemDocumentHeader.class, "documentHeader");
128 xStream.omitField(DocumentBase.class, "documentNumber");
129 xStream.omitField(DocumentBase.class, "pessimisticLocks");
130 xStream.omitField(DocumentBase.class, "documentHeader");
131 xStream.omitField(DocumentBase.class, "adHocRoutePersons");
132 xStream.omitField(DocumentBase.class, "adHocRouteWorkgroups");
133 xStream.omitField(DocumentBase.class, "notes");
134 xStream.omitField(PersistableBusinessObjectBase.class, "newCollectionRecord");
135 xStream.alias("serialReceivingRecord", OLESerialReceivingDocuments.class);
136 xStream.aliasField("serialReceivingDocuments", OLESerialReceivingDocuments.class, "oleSerialReceivingDocuments");
137 xStream.alias("serialReceivingDocument", OLESerialReceivingDocument.class);
138 xStream.aliasField("serialReceivingRecordHistories", OLESerialReceivingDocument.class, "oleSerialReceivingHistoryList");
139 xStream.aliasField("serialReceivingTypes", OLESerialReceivingDocument.class, "oleSerialReceivingTypes");
140 xStream.alias("serialReceivingRecordHistory", OLESerialReceivingHistory.class);
141 xStream.alias("serialReceivingType", OLESerialReceivingType.class);
142 String content= xStream.toXML(oleSerialReceivingDocuments);
143 LOG.debug("End of getSerialReceivingXMLContent ");
144
145
146 return content;
147 }
148
149 public String getSerialReceivingDocumentXMLContent(OLESerialReceivingDocument oleSerialReceivingDocument) throws Exception {
150 LOG.debug("Start of getSerialReceivingDocumentXMLContent ");
151 XStream xStream = new XStream();
152 xStream.omitField(FinancialSystemDocumentHeader.class, "documentHeader");
153 xStream.omitField(DocumentBase.class, "documentNumber");
154 xStream.omitField(DocumentBase.class, "pessimisticLocks");
155 xStream.omitField(DocumentBase.class, "documentHeader");
156 xStream.omitField(DocumentBase.class, "adHocRoutePersons");
157 xStream.omitField(DocumentBase.class, "adHocRouteWorkgroups");
158 xStream.omitField(DocumentBase.class, "notes");
159 xStream.omitField(PersistableBusinessObjectBase.class, "newCollectionRecord");
160 xStream.alias("serialReceivingRecord", OLESerialReceivingDocuments.class);
161 xStream.aliasField("serialReceivingDocuments", OLESerialReceivingDocuments.class, "oleSerialReceivingDocuments");
162 xStream.alias("serialReceivingDocument", OLESerialReceivingDocument.class);
163 xStream.aliasField("serialReceivingRecordHistories", OLESerialReceivingDocument.class, "oleSerialReceivingHistoryList");
164 xStream.aliasField("serialReceivingTypes", OLESerialReceivingDocument.class, "oleSerialReceivingTypes");
165 xStream.alias("serialReceivingRecordHistory", OLESerialReceivingHistory.class);
166 xStream.alias("serialReceivingType", OLESerialReceivingType.class);
167 String content = xStream.toXML(oleSerialReceivingDocument);
168 LOG.debug("End of getSerialReceivingDocumentXMLContent ");
169 return content;
170 }
171
172
173
174
175
176
177 public String getSerialReceivingFailureDocumentsXmlContent(OLESerialReceivingFailureDocuments oleSerialReceivingFailureDocuments){
178 XStream xStream = new XStream();
179 xStream.omitField(FinancialSystemDocumentHeader.class, "documentHeader");
180 xStream.omitField(DocumentBase.class, "documentNumber");
181 xStream.omitField(DocumentBase.class, "pessimisticLocks");
182 xStream.omitField(DocumentBase.class, "documentHeader");
183 xStream.omitField(DocumentBase.class, "adHocRoutePersons");
184 xStream.omitField(DocumentBase.class, "adHocRouteWorkgroups");
185 xStream.omitField(DocumentBase.class, "notes");
186 xStream.omitField(PersistableBusinessObjectBase.class, "newCollectionRecord");
187 xStream.omitField(OLESerialReceivingDocument.class,"oleSerialReceivingHistoryList");
188 xStream.omitField(OLESerialReceivingDocument.class,"oleSerialReceivingTypes");
189 xStream.alias("SerialReceivingFailureDocumentRecord", OLESerialReceivingFailureDocuments.class);
190 xStream.alias("SerialReceivingFailureDocument",OLESerialReceivingFailureDocument.class);
191 xStream.alias("SerialReceivingDocument",OLESerialReceivingDocument.class);
192 xStream.aliasField("SerialReceivingFailureDocuments",OLESerialReceivingFailureDocuments.class,"oleSerialReceivingFailureDocuments");
193 String content = xStream.toXML(oleSerialReceivingFailureDocuments);
194 return content;
195 }
196
197
198
199
200
201
202 public String getSerialReceivingFailureTypesXmlContent(OLESerialReceivingFailureTypes oleSerialReceivingFailureTypes){
203 XStream xStream = new XStream();
204 xStream.omitField(FinancialSystemDocumentHeader.class, "documentHeader");
205 xStream.omitField(DocumentBase.class, "documentNumber");
206 xStream.omitField(DocumentBase.class, "pessimisticLocks");
207 xStream.omitField(DocumentBase.class, "documentHeader");
208 xStream.omitField(DocumentBase.class, "adHocRoutePersons");
209 xStream.omitField(DocumentBase.class, "adHocRouteWorkgroups");
210 xStream.omitField(DocumentBase.class, "notes");
211 xStream.omitField(PersistableBusinessObjectBase.class, "newCollectionRecord");
212 xStream.alias("SerialReceivingFailureTypeRecord",OLESerialReceivingFailureTypes.class);
213 xStream.alias("SerialReceivingFailureType",OLESerialReceivingFailureType.class);
214 xStream.alias("SerialReceivingType",OLESerialReceivingType.class);
215 xStream.aliasField("SerialReceivingFailureTypes",OLESerialReceivingFailureTypes.class,"oleSerialReceivingFailureTypes");
216 xStream.omitField(OLESerialReceivingType.class,"oleSerialReceivingDocument");
217 String content = xStream.toXML(oleSerialReceivingFailureTypes);
218 return content;
219 }
220
221 public String getSerialReceivingFailureHistoriesXmlContent(OLESerialReceivingFailureHistories oleSerialReceivingFailureHistories){
222 XStream xStream = new XStream();
223 xStream.omitField(FinancialSystemDocumentHeader.class, "documentHeader");
224 xStream.omitField(DocumentBase.class, "documentNumber");
225 xStream.omitField(DocumentBase.class, "pessimisticLocks");
226 xStream.omitField(DocumentBase.class, "documentHeader");
227 xStream.omitField(DocumentBase.class, "adHocRoutePersons");
228 xStream.omitField(DocumentBase.class, "adHocRouteWorkgroups");
229 xStream.omitField(DocumentBase.class, "notes");
230 xStream.omitField(PersistableBusinessObjectBase.class, "newCollectionRecord");
231 xStream.alias("SerialReceivingFailureHistoryRecord",OLESerialReceivingFailureHistories.class);
232 xStream.alias("SerialReceivingFailureHistory",OLESerialReceivingFailureHistory.class);
233 xStream.alias("SerialReceivingHistory",OLESerialReceivingHistory.class);
234 xStream.aliasField("SerialReceivingFailureHistories",OLESerialReceivingFailureHistories.class,"oleSerialReceivingFailureHistories");
235 xStream.omitField(OLESerialReceivingHistory.class,"oleSerialReceivingDocument");
236 String content = xStream.toXML(oleSerialReceivingFailureHistories);
237 return content;
238 }
239
240
241
242
243
244
245
246 public boolean isValidSubscriptionStatus(String subscriptionStatus) {
247 if (LOG.isDebugEnabled()){
248 LOG.debug("Start of isValidSubscriptionStatus for the status : "+subscriptionStatus);
249 }
250 boolean validStatus = false;
251 Map<String, String> subscriptionStatusMap = new HashMap<String, String>();
252 subscriptionStatusMap.put("receiptStatusCode", subscriptionStatus);
253 List<OleReceiptStatus> oleReceiptStatuses = (List<OleReceiptStatus>) businessObjectService.findMatching(OleReceiptStatus.class, subscriptionStatusMap);
254 if (oleReceiptStatuses.size() > 0) {
255 validStatus = true;
256 }
257 if (LOG.isDebugEnabled()){
258 LOG.debug("End of isValidSubscriptionStatus for the status : "+subscriptionStatus + ":" + validStatus);
259 }
260 return validStatus;
261 }
262
263
264
265
266
267
268
269
270 public boolean isValidPO(String poId, String bibId, String instanceId) {
271 if (LOG.isDebugEnabled()){
272 LOG.debug("Start of isValidPO : "+"poId : "+ poId+";bibId :" +bibId +";instanceId"+instanceId);
273 }
274 boolean validPo = true;
275 boolean validOrder = false;
276 if (poId != null && !poId.trim().isEmpty()) {
277 Map<String, String> poMap = new HashMap<String, String>();
278 poMap.put("itemTitleId", bibId);
279 List<OlePurchaseOrderItem> olePurchaseOrderItems = (List<OlePurchaseOrderItem>) businessObjectService.findMatching(OlePurchaseOrderItem.class, poMap);
280 if (olePurchaseOrderItems.size() == 0) {
281 if (LOG.isDebugEnabled()){
282 LOG.debug("There is no purchase order document for the poId :"+poId);
283 }
284 validPo = false;
285 } else {
286 for (OlePurchaseOrderItem olePurchaseOrderItem : olePurchaseOrderItems) {
287 if(olePurchaseOrderItem!=null && olePurchaseOrderItem.getPurchaseOrder()!=null && olePurchaseOrderItem.getPurchaseOrder().getPurapDocumentIdentifier()!=null && String.valueOf(olePurchaseOrderItem.getPurchaseOrder().getPurapDocumentIdentifier()).equals(poId)){
288 Integer purapItemId = olePurchaseOrderItem.getItemIdentifier();
289 Map<String,String> copyMap = new HashMap<String,String>();
290 copyMap.put("poItemId",String.valueOf(purapItemId));
291 copyMap.put("bibId",bibId);
292 copyMap.put("instanceId",instanceId);
293 Log.info("Finding the entry for the item id :"+purapItemId +" ;bibId : "+bibId +" ; instanceId : "+ instanceId +"in the copy table" );
294 List<OleCopy> oleCopies = (List<OleCopy>)businessObjectService.findMatching(OleCopy.class,copyMap);
295 if(oleCopies.size()>0){
296 validOrder = true;
297 }
298 }
299
300 }
301 }
302 } else{
303 validOrder=true;
304 }
305 return validPo && validOrder;
306
307 }
308
309
310 public boolean validBibAndInstance(String bibId,String instanceId){
311 if (LOG.isDebugEnabled()){
312 LOG.debug("Inside validBibAndInstance for the bibId :"+bibId +":Instance Id :"+instanceId);
313 }
314 boolean validBibInstance = false;
315 List<SearchCondition> searchConditions = new ArrayList<>();
316 SearchParams searchParams = new SearchParams();
317 searchConditions.add(searchParams.buildSearchCondition("AND", searchParams.buildSearchField("holdings", "bibIdentifier", bibId), "AND"));
318 searchConditions.add(searchParams.buildSearchCondition("AND", searchParams.buildSearchField("holdings", "id", instanceId), "AND"));
319 SearchResponse search = null;
320 searchParams.getSearchConditions().addAll(searchConditions);
321 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings","itemIdentifier"));
322 try {
323 search = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
324 } catch (Exception e) {
325 e.printStackTrace();
326 }
327 if (search.getTotalRecordCount() > 0) {
328 if (LOG.isDebugEnabled()){
329 LOG.debug("There is matching bibId for this instance id "+"BibId : "+bibId +";InstanceId : "+instanceId);
330 }
331 validBibInstance = true;
332 }
333 if (LOG.isDebugEnabled()){
334 LOG.debug("isValidBid : " +validBibInstance);
335 }
336 return validBibInstance;
337
338 }
339
340
341
342
343
344
345 private boolean isValidSerialReceivingRecordType(String recordType){
346 boolean valid = false;
347 if(recordType!=null && !recordType.trim().isEmpty()){
348 if(recordTypeList.contains(recordType)){
349 valid = true;
350 }
351 }
352 return valid;
353 }
354
355
356
357
358
359
360 public boolean validateSerialReceivingDocument(OLESerialReceivingDocument oleSerialReceivingDocument) {
361 if (LOG.isDebugEnabled()){
362 LOG.debug("Inside the validateSerialReceivingDocument : documentId : "+oleSerialReceivingDocument.getSerialReceivingRecordId());
363 }
364 boolean validDocument = false;
365 if(!isSerialRecordAlreadyExist(oleSerialReceivingDocument)){
366 if (isValidSerialReceivingRecordType(oleSerialReceivingDocument.getReceivingRecordType())) {
367 if (oleSerialReceivingDocument.getSerialReceiptLocation() != null) {
368 if (isValidSubscriptionStatus(oleSerialReceivingDocument.getSubscriptionStatus())) {
369 if (oleSerialReceivingDocument.getPoId() != null && !oleSerialReceivingDocument.getPoId().trim().isEmpty()) {
370 if (isValidPO(oleSerialReceivingDocument.getPoId(), oleSerialReceivingDocument.getBibId(), oleSerialReceivingDocument.getInstanceId())) {
371 validDocument = true;
372 } else{
373 oleSerialReceivingDocument.setValidPo(false);
374 validDocument = false;
375 }
376 } else if(oleSerialReceivingDocument.getPoId() == null || (oleSerialReceivingDocument.getPoId()!=null && oleSerialReceivingDocument.getPoId().trim().isEmpty())){
377 if(validBibAndInstance(oleSerialReceivingDocument.getBibId(),oleSerialReceivingDocument.getInstanceId())){
378 validDocument = true;
379 } else{
380 oleSerialReceivingDocument.setValidBibAndInstance(false);
381 validDocument=false;
382 }
383 } if(oleSerialReceivingDocument.getOleSerialReceivingTypes()!=null && oleSerialReceivingDocument.getOleSerialReceivingTypes().size()>0){
384 for(OLESerialReceivingType oleSerialReceivingRecordType : oleSerialReceivingDocument.getOleSerialReceivingTypes()){
385 if(!isValidSerialReceivingRecordType(oleSerialReceivingRecordType.getReceivingRecordType())){
386 oleSerialReceivingDocument.setValidChildRecordType(false);
387 oleSerialReceivingRecordType.setValidRecordType(false);
388 validDocument=false;
389 }
390 }
391 } if(oleSerialReceivingDocument.getOleSerialReceivingHistoryList()!=null && oleSerialReceivingDocument.getOleSerialReceivingHistoryList().size()>0){
392 for(OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()){
393 if(!isValidSerialReceivingRecordType(oleSerialReceivingHistory.getReceivingRecordType())){
394 oleSerialReceivingDocument.setValidChildHistoryRecordType(false);
395 oleSerialReceivingHistory.setValidRecordType(false);
396 validDocument = false;
397 }
398 }
399 }
400 } else{
401 oleSerialReceivingDocument.setValidSubscriptionStatus(false);
402 validDocument =false;
403 }
404 }else{
405 oleSerialReceivingDocument.setAvailableSerialReceiptLocation(false);
406 validDocument = false;
407 }
408 }
409 else{
410 oleSerialReceivingDocument.setValidRecordType(false);
411 validDocument = false;
412 }
413 }else{
414 oleSerialReceivingDocument.setRecordAlreadyExist(true);
415 validDocument = false;
416 }
417 if (LOG.isDebugEnabled()){
418 LOG.debug("Is validateSerialReceivingDocument : "+validDocument);
419 }
420 return validDocument;
421 }
422
423
424
425
426
427
428
429 public boolean isSerialRecordAlreadyExist(OLESerialReceivingDocument oleSerialReceivingDocument){
430 Map<String,String> serialMap = new HashMap<String,String>();
431 serialMap.put("bibId",oleSerialReceivingDocument.getBibId());
432 serialMap.put("instanceId",oleSerialReceivingDocument.getInstanceId());
433 List<OLESerialReceivingDocument> oleSerialReceivingDocumentList = (List<OLESerialReceivingDocument>)businessObjectService.findMatching(OLESerialReceivingDocument.class,serialMap);
434 if(oleSerialReceivingDocumentList.size()>0){
435 return true;
436 } else {
437 return false;
438 }
439 }
440
441
442
443
444
445
446 public OLESerialReceivingDocument generateSerialReceivingDocument(OLESerialReceivingDocument oleSerialReceivingDocument) {
447 if (LOG.isDebugEnabled()){
448 LOG.debug("Inside the generateSerialReceivingDocument : documentId : "+oleSerialReceivingDocument.getSerialReceivingRecordId());
449 }
450 if(validateSerialReceivingDocument(oleSerialReceivingDocument)){
451 try {
452 OLESerialReceivingDocument newDocument = (OLESerialReceivingDocument) documentService.getNewDocument("OLE_SER_RECV_REC");
453 newDocument.getDocumentHeader().setDocumentDescription(OLEConstants.SERIAL_REC_DESC);
454 oleSerialReceivingService.createNewWithExisting(newDocument, oleSerialReceivingDocument);
455 return (OLESerialReceivingDocument) documentService.saveDocument(newDocument);
456 } catch (Exception e) {
457 LOG.error(e, e);
458 }
459 }
460 return null;
461 }
462
463
464
465
466
467
468
469 public OLESerialReceivingRecordSummary createOLESerialReceivingDocumentFromXml(String xmlContent) {
470 LOG.debug("Inside createOLESerialReceivingDocumentFromXml");
471 int totalRecordSize=0;
472 int successfulRecordSize=0;
473 int failureRecordSize=0;
474 List<OLESerialReceivingDocument> successList = new ArrayList<OLESerialReceivingDocument>();
475 List<OLESerialReceivingDocument> failureList = new ArrayList<OLESerialReceivingDocument>();
476 OLESerialReceivingDocuments oleSerialReceivingDocuments = null;
477 try {
478 oleSerialReceivingDocuments = getOleSerialReceivingRecordList(xmlContent);
479 totalRecordSize = oleSerialReceivingDocuments.getOleSerialReceivingDocuments().size();
480 for (OLESerialReceivingDocument oleSerialReceivingDocument : oleSerialReceivingDocuments.getOleSerialReceivingDocuments()) {
481 OLESerialReceivingDocument oleSerialReceivingDocument1 = generateSerialReceivingDocument(oleSerialReceivingDocument);
482 if (oleSerialReceivingDocument1 != null) {
483 successList.add(oleSerialReceivingDocument1);
484 successfulRecordSize = successfulRecordSize+1;
485 } else{
486 failureList.add(oleSerialReceivingDocument);
487 failureRecordSize = failureRecordSize+1;
488 }
489 }
490 } catch (Exception e) {
491 LOG.error(e, e);
492 }
493 if (LOG.isDebugEnabled()){
494 LOG.debug("End of createOLESerialReceivingDocumentFromXml : total Number Of Successful Records = "+successList.size() +": Total number Of Failure Records : "+failureRecordSize);
495 }
496 return new OLESerialReceivingRecordSummary(totalRecordSize,successfulRecordSize,failureRecordSize,failureList);
497 }
498
499
500 public OLESerialReceivingRecordSummary createOLESerialReceivingDocumentFromCsv(String serialReceivingDocument,String serialReceivingType ,String serialReceivingHistory) {
501 LOG.debug("Inside createOLESerialReceivingDocumentFromCsv ");
502 int totalRecordSize = 0;
503 int docSuccessCount = 0;
504 int docFailureCount = 0;
505 List<OLESerialReceivingDocument> docFailureList = new ArrayList<>();
506 int hstrySucceesCount = 0;
507 int hstryFailureCount = 0;
508 List<OLESerialReceivingHistory> hstryFailureList = new ArrayList<>();
509 int typeSuccessCount = 0;
510 int typeFailureCount = 0;
511 List<OLESerialReceivingType> typeFailureList = new ArrayList<>();
512 List<OLESerialReceivingDocument> oleSerialReceivingDocumentList = new ArrayList<>();
513 Map<String, List<OLESerialReceivingType>> oleSerialReceivingTypeMap = new HashMap<>();
514 Map<String, List<OLESerialReceivingHistory>> oleSerialReceivingHistoryMap = new HashMap<>();
515 List<OLESerialReceivingDocument> serialReceivingDocumentList = new ArrayList<>();
516 List<String> serialIdList = new ArrayList<>();
517 try {
518 if (serialReceivingDocument != null && !serialReceivingDocument.trim().isEmpty()) {
519 oleSerialReceivingDocumentList = processSerialReceivingDocument(serialReceivingDocument);
520 if (serialReceivingType != null && !serialReceivingType.trim().isEmpty()) {
521 oleSerialReceivingTypeMap = processSerialReceivingType(serialReceivingType);
522 }
523 if (serialReceivingHistory != null && !serialReceivingHistory.trim().isEmpty()) {
524 oleSerialReceivingHistoryMap = processSerialReceivingHistory(serialReceivingHistory);
525 }
526 for (OLESerialReceivingDocument oleSerialReceivingDocument : oleSerialReceivingDocumentList) {
527 oleSerialReceivingDocument.setOleSerialReceivingTypes(oleSerialReceivingTypeMap.get(oleSerialReceivingDocument.getSerialReceivingRecordId()));
528 oleSerialReceivingDocument.setOleSerialReceivingHistoryList(oleSerialReceivingHistoryMap.get(oleSerialReceivingDocument.getSerialReceivingRecordId()));
529 serialReceivingDocumentList.add(oleSerialReceivingDocument);
530 }
531 for (OLESerialReceivingDocument oleSerialReceivingDocument : serialReceivingDocumentList) {
532 OLESerialReceivingDocument oleSerialReceivingDocument1 = generateSerialReceivingDocument(oleSerialReceivingDocument);
533 if (oleSerialReceivingDocument1 != null) {
534 docSuccessCount = docSuccessCount + 1;
535 if (oleSerialReceivingDocument.getOleSerialReceivingHistoryList() != null)
536 hstrySucceesCount = hstrySucceesCount + oleSerialReceivingDocument1.getOleSerialReceivingHistoryList().size();
537 if (oleSerialReceivingDocument.getOleSerialReceivingTypes() != null)
538 typeSuccessCount = typeSuccessCount + oleSerialReceivingDocument1.getOleSerialReceivingTypes().size();
539 } else {
540 if (oleSerialReceivingDocument.getOleSerialReceivingHistoryList() != null && oleSerialReceivingDocument.getOleSerialReceivingHistoryList().size()>0){
541 hstryFailureCount = hstryFailureCount + oleSerialReceivingDocument.getOleSerialReceivingHistoryList().size();
542 for(OLESerialReceivingHistory oleSerialReceivingHistory :oleSerialReceivingDocument.getOleSerialReceivingHistoryList()){
543 oleSerialReceivingHistory.setDocumentExist(true);
544 }
545 hstryFailureList.addAll(oleSerialReceivingDocument.getOleSerialReceivingHistoryList());
546 }
547 if (oleSerialReceivingDocument.getOleSerialReceivingTypes() != null && oleSerialReceivingDocument.getOleSerialReceivingTypes().size()>0) {
548 typeFailureCount = typeFailureCount + oleSerialReceivingDocument.getOleSerialReceivingTypes().size();
549 for(OLESerialReceivingType oleSerialReceivingType : oleSerialReceivingDocument.getOleSerialReceivingTypes()){
550 oleSerialReceivingType.setDocumentExist(true);
551 }
552 typeFailureList.addAll(oleSerialReceivingDocument.getOleSerialReceivingTypes());
553 }
554 oleSerialReceivingDocument.setOleSerialReceivingTypes(null);
555 oleSerialReceivingDocument.setOleSerialReceivingHistoryList(null);
556 docFailureList.add(oleSerialReceivingDocument);
557 docFailureCount = docFailureCount + 1;
558 }
559 serialIdList.add(oleSerialReceivingDocument.getSerialReceivingRecordId());
560
561 }
562 for (String serialReceivingRecordId : oleSerialReceivingHistoryMap.keySet()) {
563 if (!serialIdList.contains(serialReceivingRecordId)) {
564 List<OLESerialReceivingHistory> oleSerialReceivingHistoryList = oleSerialReceivingHistoryMap.get(serialReceivingRecordId);
565 if (oleSerialReceivingHistoryList != null) {
566 hstryFailureCount = hstryFailureCount+oleSerialReceivingHistoryList.size();
567 hstryFailureList.addAll(oleSerialReceivingHistoryList);
568 }
569 }
570 }
571 for (String serialReceivingRecordId : oleSerialReceivingTypeMap.keySet()) {
572 if (!serialIdList.contains(serialReceivingRecordId)) {
573 List<OLESerialReceivingType> oleSerialReceivingTypeList = oleSerialReceivingTypeMap.get(serialReceivingRecordId);
574 if (oleSerialReceivingTypeList != null) {
575 typeFailureCount = typeFailureCount + oleSerialReceivingTypeList.size();
576 typeFailureList.addAll(oleSerialReceivingTypeList);
577 }
578 }
579 }
580 totalRecordSize = oleSerialReceivingDocumentList.size();
581 } else {
582 if (serialReceivingHistory != null && !serialReceivingHistory.trim().isEmpty()) {
583 oleSerialReceivingHistoryMap = processSerialReceivingHistory(serialReceivingHistory);
584 for (String serialReceivingRecordId : oleSerialReceivingHistoryMap.keySet()) {
585 List<OLESerialReceivingHistory> oleSerialReceivingHistoryList = oleSerialReceivingHistoryMap.get(serialReceivingRecordId);
586 if (oleSerialReceivingHistoryList != null) {
587 for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingHistoryList) {
588 if (oleSerialReceivingHistory.getSerialReceivingRecordId() != null) {
589 Map oleSerialReceivingRecordIdMap = new HashMap();
590 oleSerialReceivingRecordIdMap.put("serialReceivingRecordId", oleSerialReceivingHistory.getSerialReceivingRecordId());
591 OLESerialReceivingDocument document = businessObjectService.findByPrimaryKey(OLESerialReceivingDocument.class, oleSerialReceivingRecordIdMap);
592 if (document != null) {
593 if (document.getOleSerialReceivingHistoryList() != null) {
594 document.getOleSerialReceivingHistoryList().add(oleSerialReceivingHistory);
595 } else {
596 List<OLESerialReceivingHistory> oleSerialReceivingHistories = new ArrayList<>();
597 oleSerialReceivingHistories.add(oleSerialReceivingHistory);
598 document.setOleSerialReceivingHistoryList(oleSerialReceivingHistories);
599 }
600 hstrySucceesCount = hstrySucceesCount + 1;
601 getBusinessObjectService().save(document);
602 } else {
603 hstryFailureCount = hstryFailureCount + 1;
604 hstryFailureList.add(oleSerialReceivingHistory);
605 }
606 }
607 }
608 }
609 }
610 }
611 if (serialReceivingType != null && !serialReceivingType.trim().isEmpty()) {
612 oleSerialReceivingTypeMap = processSerialReceivingType(serialReceivingType);
613 for (String serialReceivingRecordId : oleSerialReceivingTypeMap.keySet()) {
614 List<OLESerialReceivingType> oleSerialReceivingTypeList = oleSerialReceivingTypeMap.get(serialReceivingRecordId);
615 if (oleSerialReceivingTypeList != null) {
616 for (OLESerialReceivingType oleSerialReceivingType : oleSerialReceivingTypeList) {
617 if (oleSerialReceivingType.getSerialReceivingRecordId() != null) {
618 Map oleSerialReceivingRecordIdMap = new HashMap();
619 oleSerialReceivingRecordIdMap.put("serialReceivingRecordId", oleSerialReceivingType.getSerialReceivingRecordId());
620 OLESerialReceivingDocument document = businessObjectService.findByPrimaryKey(OLESerialReceivingDocument.class, oleSerialReceivingRecordIdMap);
621 if (document != null) {
622 if (document.getOleSerialReceivingTypes() != null) {
623 document.getOleSerialReceivingTypes().add(oleSerialReceivingType);
624 } else {
625 List<OLESerialReceivingType> oleSerialReceivingTypes = new ArrayList<>();
626 oleSerialReceivingTypes.add(oleSerialReceivingType);
627 document.setOleSerialReceivingTypes(oleSerialReceivingTypes);
628 }
629 typeSuccessCount = typeSuccessCount + 1;
630 getBusinessObjectService().save(document);
631 } else {
632 typeFailureCount = typeFailureCount + 1;
633 typeFailureList.add(oleSerialReceivingType);
634 }
635 }
636 }
637 }
638 }
639 }
640 }
641
642 } catch (Exception e) {
643 LOG.error(e, e);
644 }
645 if (LOG.isDebugEnabled()){
646 LOG.debug("totalRecordSize : "+totalRecordSize +","+"docSuccessCount : "+docSuccessCount +","+"docFailureCount : "+docFailureCount +","+"hstrySucceesCount : "+hstrySucceesCount +","+"hstryFailureCount : "+hstryFailureCount +","+"typeSuccessCount : "+typeSuccessCount +","+"typeFailureCount : "+typeFailureCount);
647 }
648 return new OLESerialReceivingRecordSummary(totalRecordSize, docSuccessCount, docFailureCount, docFailureList,hstrySucceesCount,hstryFailureCount,hstryFailureList,typeSuccessCount,typeFailureCount,typeFailureList);
649 }
650
651
652
653
654
655 public List<OLESerialReceivingDocument> processSerialReceivingDocument(String serialReceivingDocumentContent) {
656 Log.debug("inside processing Serial Receiving Document");
657 BufferedReader br = null;
658 String line = "";
659 String cvsSplitBy = getParameter(OLEConstants.SERIAL_LOADER_DELIMITER,OLEConstants.SELECT_NMSPC,OLEConstants.SELECT_CMPNT);
660 if(cvsSplitBy != null && cvsSplitBy.trim().isEmpty()){
661 cvsSplitBy = ",";
662 }
663
664 List<OLESerialReceivingDocument> oleSerialReceivingDocumentList = new ArrayList<>();
665 try {
666 br = new BufferedReader(new FileReader(serialReceivingDocumentContent));
667 String[] serialDocuments = null;
668 int count = 0;
669 while ((line = br.readLine()) != null) {
670 String[] documents = line.split(cvsSplitBy);
671 OLESerialReceivingDocument oleSerialReceivingDocument = new OLESerialReceivingDocument();
672 if (count == 0) {
673 serialDocuments = documents;
674 }
675 int index = 0;
676 if (count > 0) {
677 for (String document : documents) {
678 document=document.replace("\"","");
679 if (serialDocuments.length > index && serialDocuments[index]!=null) {
680 if (serialDocuments!=null && serialDocuments[index].equals("\"FDOC_NBR\"")) {
681 index++;
682 oleSerialReceivingDocument.getDocumentHeader().setDocumentNumber(document);
683 } else if (serialDocuments[index].equals("\"SER_RCV_REC_ID\"")) {
684 index++;
685 oleSerialReceivingDocument.setSerialReceivingRecordId(document);
686 } else if (serialDocuments[index].equals("\"BIB_ID\"")) {
687 index++;
688 oleSerialReceivingDocument.setBibId(document);
689 } else if (serialDocuments[index].equals("\"BOUND_LOC\"")) {
690 index++;
691 oleSerialReceivingDocument.setBoundLocation(document);
692 } else if (serialDocuments[index].equals("\"CALL_NUM\"")) {
693 index++;
694 oleSerialReceivingDocument.setCallNumber(document);
695 } else if (serialDocuments[index].equals("\"RCV_REC_TYP\"")) {
696 index++;
697 oleSerialReceivingDocument.setReceivingRecordType(document);
698 } else if (serialDocuments[index].equals("\"CLAIM\"")) {
699 index++;
700 if (document.equals("Y")) {
701 oleSerialReceivingDocument.setClaim(true);
702 } else {
703 oleSerialReceivingDocument.setClaim(false);
704 }
705 } else if (serialDocuments[index].equals("\"CLAIM_INTRVL_INFO\"")) {
706 index++;
707 oleSerialReceivingDocument.setClaimIntervalInformation(document);
708 } else if (serialDocuments[index].equals("\"COPY_NUM\"")) {
709 index++;
710 oleSerialReceivingDocument.setCopyNumber(document);
711 } else if (serialDocuments[index].equals("\"CORPORATE_AUTH\"")) {
712 index++;
713 oleSerialReceivingDocument.setCorporateAuthor(document);
714 } else if (serialDocuments[index].equals("\"CREATE_ITEM\"")) {
715 index++;
716 if (document.equals("Y")) {
717 oleSerialReceivingDocument.setCreateItem(true);
718 } else {
719 oleSerialReceivingDocument.setCreateItem(false);
720 }
721 } else if (serialDocuments[index].equals("\"GEN_RCV_NOTE\"")) {
722 index++;
723 oleSerialReceivingDocument.setGeneralReceivingNote(document);
724 } else if (serialDocuments[index].equals("\"INSTANCE_ID\"")) {
725 index++;
726 oleSerialReceivingDocument.setInstanceId(document);
727 } else if (serialDocuments[index].equals("\"ISSN\"")) {
728 index++;
729 oleSerialReceivingDocument.setIssn(document);
730 } else if (serialDocuments[index].equals("\"PO_ID\"")) {
731 index++;
732 oleSerialReceivingDocument.setPoId(document);
733 } else if (serialDocuments[index].equals("\"PRINT_LBL\"")) {
734 index++;
735 if (document.equals("Y")) {
736 oleSerialReceivingDocument.setPrintLabel(true);
737 } else {
738 oleSerialReceivingDocument.setPrintLabel(false);
739 }
740 } else if (serialDocuments[index].equals("\"PUBLIC_DISPLAY\"")) {
741 index++;
742 if (document.equals("Y")) {
743 oleSerialReceivingDocument.setPublicDisplay(true);
744 } else {
745 oleSerialReceivingDocument.setPublicDisplay(false);
746 }
747 } else if (serialDocuments[index].equals("\"PUBLISHER\"")) {
748 index++;
749 oleSerialReceivingDocument.setPublisher(document);
750 } else if (serialDocuments[index].equals("\"SER_RCPT_LOC\"")) {
751 index++;
752 oleSerialReceivingDocument.setSerialReceiptLocation(document);
753 } else if (serialDocuments[index].equals("\"SER_RCV_REC\"")) {
754 index++;
755 oleSerialReceivingDocument.setSerialReceiptLocation(document);
756 } else if (serialDocuments[index].equals("\"SUBSCR_STAT\"")) {
757 index++;
758 oleSerialReceivingDocument.setSubscriptionStatus(document);
759 } else if (serialDocuments[index].equals("\"TREATMENT_INSTR_NOTE\"")) {
760 index++;
761 oleSerialReceivingDocument.setTreatmentInstructionNote(document);
762 } else if (serialDocuments[index].equals("\"UNBOUND_LOC\"")) {
763 index++;
764 oleSerialReceivingDocument.setUnboundLocation(document);
765 } else if (serialDocuments[index].equals("\"URGENT_NOTE\"")) {
766 index++;
767 oleSerialReceivingDocument.setUrgentNote(document);
768 } else if (serialDocuments[index].equals("\"VENDOR\"")) {
769 index++;
770 oleSerialReceivingDocument.setVendorId(document);
771 } else if (serialDocuments[index].equals("\"CREATE_DATE\"")) {
772 index++;
773
774 } else if (serialDocuments[index].equals("\"OPTR_ID\"")) {
775 index++;
776 oleSerialReceivingDocument.setOperatorId(document);
777 } else if (serialDocuments[index].equals("\"MACH_ID\"")) {
778 index++;
779 oleSerialReceivingDocument.setMachineId(document);
780 } else if (serialDocuments[index].equals("\"SUBSCR_STAT_DT\"")) {
781 index++;
782
783 } else if (serialDocuments[index].equals("\"SR_TITLE\"")) {
784 index++;
785 oleSerialReceivingDocument.setTitle(document);
786 } else if (serialDocuments[index].equals("\"OBJ_ID\"")) {
787 index++;
788 oleSerialReceivingDocument.setObjectId(document);
789 } else if (serialDocuments[index].equals("\"VER_NBR\"")) {
790 index++;
791
792 } else if (serialDocuments[index].equals("\"ACTIVE\"")) {
793 index++;
794 if (document.equals("Y")) {
795 oleSerialReceivingDocument.setActive(true);
796 } else {
797 oleSerialReceivingDocument.setActive(false);
798 }
799 }
800 else {
801 index++;
802 }
803 }
804 }
805 oleSerialReceivingDocumentList.add(oleSerialReceivingDocument);
806 }
807 count++;
808 }
809 } catch (FileNotFoundException e) {
810 e.printStackTrace();
811 } catch (IOException e) {
812 e.printStackTrace();
813 } finally {
814 if (br != null) {
815 try {
816 br.close();
817 } catch (IOException e) {
818 e.printStackTrace();
819 }
820 }
821 }
822 return oleSerialReceivingDocumentList;
823 }
824
825
826 public Map<String, List<OLESerialReceivingHistory>> processSerialReceivingHistory(String serialReceivingHistoryContent) {
827 Map<String, List<OLESerialReceivingHistory>> oleSerialReceivingHistoryMap = new HashMap<>();
828
829 BufferedReader br = null;
830 String line = "";
831 String cvsSplitBy = getParameter(OLEConstants.SERIAL_LOADER_DELIMITER,OLEConstants.SELECT_NMSPC,OLEConstants.SELECT_CMPNT);
832 if(cvsSplitBy != null && cvsSplitBy.trim().isEmpty()){
833 cvsSplitBy = ",";
834 }
835 try {
836 br = new BufferedReader(new FileReader(serialReceivingHistoryContent));
837 String[] serialHistories = null;
838 int count = 0;
839 while ((line = br.readLine()) != null) {
840 String[] histories = line.split(cvsSplitBy);
841 OLESerialReceivingHistory oleSerialReceivingHistory = new OLESerialReceivingHistory();
842 if (count == 0) {
843 serialHistories = histories;
844 }
845 int index = 0;
846 if (count > 0) {
847 for (String history : histories) {
848 history=history.replace("\"","");
849 if (serialHistories!=null && serialHistories.length > index && serialHistories[index]!=null) {
850 if (serialHistories[index].equals("\"SER_RCPT_HIS_REC_ID\"")) {
851 index++;
852 oleSerialReceivingHistory.setSerialReceivingRecordHistoryId(history);
853 } else if (serialHistories[index].equals("\"SER_RCV_REC_ID\"")) {
854 index++;
855 oleSerialReceivingHistory.setSerialReceivingRecordId(history);
856 } else if (serialHistories[index].equals("\"RCV_REC_TYP\"")) {
857 index++;
858 oleSerialReceivingHistory.setReceivingRecordType(history);
859 } else if (serialHistories[index].equals("\"CHRON_LVL_1\"")) {
860 index++;
861 oleSerialReceivingHistory.setChronologyCaptionLevel1(history);
862 } else if (serialHistories[index].equals("\"CHRON_LVL_2\"")) {
863 index++;
864 oleSerialReceivingHistory.setChronologyCaptionLevel2(history);
865 } else if (serialHistories[index].equals("\"CHRON_LVL_3\"")) {
866 index++;
867 oleSerialReceivingHistory.setChronologyCaptionLevel3(history);
868 } else if (serialHistories[index].equals("\"CHRON_LVL_4\"")) {
869 index++;
870 oleSerialReceivingHistory.setChronologyCaptionLevel4(history);
871 } else if (serialHistories[index].equals("\"CLAIM_COUNT\"")) {
872 index++;
873 oleSerialReceivingHistory.setClaimCount(history);
874 } else if (serialHistories[index].equals("\"CLAIM_DATE\"")) {
875 index++;
876
877 } else if (serialHistories[index].equals("\"CLAIM_NOTE\"")) {
878 index++;
879 oleSerialReceivingHistory.setClaimNote(history);
880 } else if (serialHistories[index].equals("\"CLAIM_TYPE\"")) {
881 index++;
882 oleSerialReceivingHistory.setClaimType(history);
883 } else if (serialHistories[index].equals("\"CLAIM_RESP\"")) {
884 index++;
885 oleSerialReceivingHistory.setClaimResponse(history);
886 } else if (serialHistories[index].equals("\"ENUM_LVL_1\"")) {
887 index++;
888 oleSerialReceivingHistory.setEnumerationCaptionLevel1(history);
889 } else if (serialHistories[index].equals("\"ENUM_LVL_2\"")) {
890 index++;
891 oleSerialReceivingHistory.setEnumerationCaptionLevel2(history);
892 } else if (serialHistories[index].equals("\"ENUM_LVL_3\"")) {
893 index++;
894 oleSerialReceivingHistory.setEnumerationCaptionLevel3(history);
895 } else if (serialHistories[index].equals("\"ENUM_LVL_4\"")) {
896 index++;
897 oleSerialReceivingHistory.setEnumerationCaptionLevel4(history);
898 } else if (serialHistories[index].equals("\"ENUM_LVL_5\"")) {
899 index++;
900 oleSerialReceivingHistory.setEnumerationCaptionLevel5(history);
901 } else if (serialHistories[index].equals("\"ENUM_LVL_6\"")) {
902 index++;
903 oleSerialReceivingHistory.setEnumerationCaptionLevel6(history);
904 } else if (serialHistories[index].equals("\"PUB_DISPLAY\"")) {
905 index++;
906 if (history.equals("Y")) {
907 oleSerialReceivingHistory.setPublicDisplay(true);
908 } else {
909 oleSerialReceivingHistory.setPublicDisplay(false);
910 }
911 } else if (serialHistories[index].equals("\"SER_RCPT_NOTE\"")) {
912 index++;
913 oleSerialReceivingHistory.setSerialReceiptNote(history);
914 } else if (serialHistories[index].equals("\"OPTR_ID\"")) {
915 index++;
916 oleSerialReceivingHistory.setOperatorId(history);
917 } else if (serialHistories[index].equals("\"MACH_ID\"")) {
918 index++;
919 oleSerialReceivingHistory.setMachineId(history);
920 } else if (serialHistories[index].equals("\"RCPT_STAT\"")) {
921 index++;
922 oleSerialReceivingHistory.setReceiptStatus(history);
923 } else if (serialHistories[index].equals("\"RCPT_DATE\"")) {
924 index++;
925
926 } else if (serialHistories[index].equals("\"PUB_RCPT\"")) {
927 index++;
928 oleSerialReceivingHistory.setPublicReceipt(history);
929 } else if (serialHistories[index].equals("\"STAFF_ONLY_RCPT\"")) {
930 index++;
931 oleSerialReceivingHistory.setStaffOnlyReceipt(history);
932 } else if (serialHistories[index].equals("\"OBJ_ID\"")) {
933 index++;
934 oleSerialReceivingHistory.setObjectId(history);
935 } else if (serialHistories[index].equals("\"VER_NBR\"")) {
936 index++;
937
938 }
939 else {
940 index++;
941 }
942 }
943 }
944 boolean keyFound = false;
945 for (String serialReceivingRecordId : oleSerialReceivingHistoryMap.keySet()) {
946 if (oleSerialReceivingHistory!=null && oleSerialReceivingHistory.getSerialReceivingRecordId()!=null && oleSerialReceivingHistory.getSerialReceivingRecordId().equals(serialReceivingRecordId)) {
947 keyFound = true;
948 List<OLESerialReceivingHistory> oleSerialReceivingTypeList = oleSerialReceivingHistoryMap.get(serialReceivingRecordId);
949 oleSerialReceivingTypeList.add(oleSerialReceivingHistory);
950 }
951 }
952 if (!keyFound) {
953 List<OLESerialReceivingHistory> oleSerialReceivingTypeList = new ArrayList<>();
954 oleSerialReceivingTypeList.add(oleSerialReceivingHistory);
955 oleSerialReceivingHistoryMap.put(oleSerialReceivingHistory.getSerialReceivingRecordId(), oleSerialReceivingTypeList);
956 }
957 }
958 count++;
959 }
960 } catch (FileNotFoundException e) {
961 e.printStackTrace();
962 } catch (IOException e) {
963 e.printStackTrace();
964 } finally {
965 if (br != null) {
966 try {
967 br.close();
968 } catch (IOException e) {
969 e.printStackTrace();
970 }
971 }
972 }
973 return oleSerialReceivingHistoryMap;
974 }
975
976
977 public Map<String, List<OLESerialReceivingType>> processSerialReceivingType(String serialReceivingTypeContent) {
978 Map<String, List<OLESerialReceivingType>> oleSerialReceivingTypeMap = new HashMap<>();
979 BufferedReader br = null;
980 String line = "";
981 String cvsSplitBy = getParameter(OLEConstants.SERIAL_LOADER_DELIMITER,OLEConstants.SELECT_NMSPC,OLEConstants.SELECT_CMPNT);
982 if(cvsSplitBy != null && cvsSplitBy.trim().isEmpty()){
983 cvsSplitBy = ",";
984 }
985
986 try {
987 br = new BufferedReader(new FileReader(serialReceivingTypeContent));
988 String[] serialTypes = null;
989 int count = 0;
990 while ((line = br.readLine()) != null) {
991 String[] types = line.split(cvsSplitBy);
992 OLESerialReceivingType oleSerialReceivingType = new OLESerialReceivingType();
993 if (count == 0) {
994 serialTypes = types;
995 }
996 int index = 0;
997 if (count > 0) {
998 for (String type : types) {
999 type=type.replace("\"","");
1000 if (serialTypes!=null && serialTypes.length > index && serialTypes[index]!=null) {
1001 if (serialTypes[index].equals("\"SER_RCV_REC_TYP_ID\"")) {
1002 index++;
1003 oleSerialReceivingType.setSerialReceivingTypeId(type);
1004 } else if (serialTypes[index].equals("\"SER_RCV_REC_ID\"")) {
1005 index++;
1006 oleSerialReceivingType.setSerialReceivingRecordId(type);
1007 } else if (serialTypes[index].equals("\"RCV_REC_TYP\"")) {
1008 index++;
1009 oleSerialReceivingType.setReceivingRecordType(type);
1010 } else if (serialTypes[index].equals("\"ACTN_DATE\"")) {
1011 index++;
1012
1013 } else if (serialTypes[index].equals("\"ACTN_INTRVL\"")) {
1014 index++;
1015 oleSerialReceivingType.setActionInterval(type);
1016 } else if (serialTypes[index].equals("\"CHRON_CAPTN_LVL1\"")) {
1017 index++;
1018 oleSerialReceivingType.setChronologyCaptionLevel1(type);
1019 } else if (serialTypes[index].equals("\"CHRON_CAPTN_LVL2\"")) {
1020 index++;
1021 oleSerialReceivingType.setChronologyCaptionLevel2(type);
1022 } else if (serialTypes[index].equals("\"CHRON_CAPTN_LVL3\"")) {
1023 index++;
1024 oleSerialReceivingType.setChronologyCaptionLevel3(type);
1025 } else if (serialTypes[index].equals("\"CHRON_CAPTN_LVL4\"")) {
1026 index++;
1027 oleSerialReceivingType.setChronologyCaptionLevel4(type);
1028 } else if (serialTypes[index].equals("\"ENUM_CAPTN_LVL1\"")) {
1029 index++;
1030 oleSerialReceivingType.setEnumerationCaptionLevel1(type);
1031 } else if (serialTypes[index].equals("\"ENUM_CAPTN_LVL2\"")) {
1032 index++;
1033 oleSerialReceivingType.setEnumerationCaptionLevel2(type);
1034 } else if (serialTypes[index].equals("\"ENUM_CAPTN_LVL3\"")) {
1035 index++;
1036 oleSerialReceivingType.setEnumerationCaptionLevel3(type);
1037 } else if (serialTypes[index].equals("\"ENUM_CAPTN_LVL4\"")) {
1038 index++;
1039 oleSerialReceivingType.setEnumerationCaptionLevel4(type);
1040 } else if (serialTypes[index].equals("\"ENUM_CAPTN_LVL5\"")) {
1041 index++;
1042 oleSerialReceivingType.setEnumerationCaptionLevel5(type);
1043 } else if (serialTypes[index].equals("\"ENUM_CAPTN_LVL6\"")) {
1044 index++;
1045 oleSerialReceivingType.setEnumerationCaptionLevel6(type);
1046 } else if (serialTypes[index].equals("\"OBJ_ID\"")) {
1047 index++;
1048 oleSerialReceivingType.setObjectId(type);
1049 } else if (serialTypes[index].equals("\"VER_NBR\"")) {
1050 index++;
1051
1052 }
1053 else {
1054 index++;
1055 }
1056 }
1057 }
1058 boolean keyFound = false;
1059 for (String serialReceivingRecordId : oleSerialReceivingTypeMap.keySet()) {
1060 if (oleSerialReceivingType!=null && oleSerialReceivingType.getSerialReceivingRecordId()!=null && oleSerialReceivingType.getSerialReceivingRecordId().equals(serialReceivingRecordId)) {
1061 keyFound = true;
1062 List<OLESerialReceivingType> oleSerialReceivingTypeList = oleSerialReceivingTypeMap.get(serialReceivingRecordId);
1063 oleSerialReceivingTypeList.add(oleSerialReceivingType);
1064 }
1065 }
1066 if (!keyFound) {
1067 List<OLESerialReceivingType> oleSerialReceivingTypeList = new ArrayList<>();
1068 oleSerialReceivingTypeList.add(oleSerialReceivingType);
1069 oleSerialReceivingTypeMap.put(oleSerialReceivingType.getSerialReceivingRecordId(), oleSerialReceivingTypeList);
1070 }
1071 }
1072 count++;
1073 }
1074 } catch (FileNotFoundException e) {
1075 e.printStackTrace();
1076 } catch (IOException e) {
1077 e.printStackTrace();
1078 } finally {
1079 if (br != null) {
1080 try {
1081 br.close();
1082 } catch (IOException e) {
1083 e.printStackTrace();
1084 }
1085 }
1086 }
1087 return oleSerialReceivingTypeMap;
1088 }
1089
1090 public static List<String> getSerialRecordTypeList(){
1091 List<String> recordList = new ArrayList<String>();
1092 recordList.add(OLEConstants.RECORD_TYP_MAIN);
1093 recordList.add(OLEConstants.RECORD_TYP_SUPPLEMENTARY);
1094 recordList.add(OLEConstants.RECORD_TYP_INDEX);
1095 return recordList;
1096 }
1097
1098 public String getParameter(String name,String namespaceCode,String componentCode) {
1099 String parameter = "";
1100 try {
1101 Map<String, String> criteriaMap = new HashMap<String, String>();
1102 criteriaMap.put("namespaceCode", OLEConstants.SELECT_NMSPC);
1103 criteriaMap.put("componentCode", OLEConstants.SELECT_CMPNT);
1104 criteriaMap.put("name", name);
1105 List<ParameterBo> parametersList = (List<ParameterBo>) getBusinessObjectService().findMatching(ParameterBo.class, criteriaMap);
1106 for (ParameterBo parameterBo : parametersList) {
1107 parameter = parameterBo.getValue();
1108 }
1109 } catch (Exception e) {
1110 LOG.error(e, e);
1111 }
1112 return parameter;
1113 }
1114
1115 }