001package org.kuali.ole.select.document;
002
003import org.joda.time.DateTime;
004import org.kuali.ole.OLEConstants;
005import org.kuali.ole.describe.bo.OleStatisticalSearchingCodes;
006import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
007import org.kuali.ole.docstore.common.document.EHoldings;
008import org.kuali.ole.docstore.common.document.Holdings;
009import org.kuali.ole.docstore.common.document.content.instance.Link;
010import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
011import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
012import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
013import org.kuali.ole.select.bo.*;
014import org.kuali.ole.select.businessobject.OleCopy;
015import org.kuali.ole.select.form.OLEEResourceRecordForm;
016import org.kuali.ole.service.OLEEResourceSearchService;
017import org.kuali.ole.sys.context.SpringContext;
018import org.kuali.ole.vnd.businessobject.VendorDetail;
019import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
020import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
021import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
022import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
023import org.kuali.rice.krad.document.TransactionalDocumentBase;
024import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
025import org.kuali.rice.krad.service.BusinessObjectService;
026import org.kuali.rice.krad.service.KRADServiceLocator;
027import org.kuali.rice.krad.util.GlobalVariables;
028import org.springframework.util.StringUtils;
029
030import java.lang.reflect.Method;
031import java.math.BigDecimal;
032import java.sql.Date;
033import java.util.ArrayList;
034import java.util.HashMap;
035import java.util.List;
036import java.util.Map;
037
038/**
039 * Created with IntelliJ IDEA.
040 * User: srinivasane
041 * Date: 6/21/13
042 * Time: 12:03 PM
043 * To change this template use File | Settings | File Templates.
044 */
045public class OLEEResourceRecordDocument extends TransactionalDocumentBase {
046
047    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEEResourceRecordDocument.class);
048    private BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
049    private OLEEResourceSearchService oleEResourceSearchService = null;
050
051    private String oleERSIdentifier;
052    private String title;
053    private String description;
054    private String publisher;
055    private String gokbIdentifier;
056    private String isbn;
057    private String ISBN;
058    private String oclc;
059    private String platformProvider;
060    private String statusId;
061    private String statusName;
062    private String statusDate;
063    private String fundCode;
064    private Integer vendorDetailAssignedIdentifier;
065    private Integer vendorHeaderGeneratedIdentifier;
066    private String vendorName;
067    private String vendorId;
068    private String estimatedPrice;
069    private BigDecimal orderTypeId;
070    private String paymentTypeId;
071    private String packageTypeId;
072    private String packageScopeId;
073    private boolean breakable;
074    private boolean fixedTitleList;
075    private String noteId;
076    private String publicDisplayNote;
077    private String reqSelComment;
078    private String reqPriority;
079    private String techRequirements;
080    private String accessTypeId;
081    private String numOfSimultaneousUsers;
082    private String authenticationTypeId;
083    private String accessLocationId;
084    private List<String> accessLocation = new ArrayList<>();
085    private boolean trialNeeded;
086    private String trialStatus;
087    private boolean licenseNeeded;
088    private String licenseReqStatus;
089    private String orderPayStatus;
090    private String activationStatus;
091    private String documentNumber;
092    private boolean selectFlag;
093    private Integer statisticalSearchingCodeId;
094    private String statisticalSearchingCode;
095    private String selectInstance;
096    private String defaultCoverage;
097    private String defaultCoverageView;
098    private String defaultPerpetualAccess;
099    private String defaultPerpetualAccessView;
100    private OLEEResourceInstance oleERSInstance;
101    private boolean eInstanceFlag;
102    private String dummyDefaultCoverage;
103    private String dummyDefaultPerpetualAccess;
104    private boolean isCovEdited = false;
105    private boolean isPerAccEdited = false;
106    private String covStartDate;
107    private String covEndDate;
108    private String perAccStartDate;
109    private String perAccEndDate;
110
111    private OLEAccessType oleAccessType;
112    private OLEPackageScope olePackageScope;
113    private OLEPackageType olePackageType;
114    private OLEPaymentType olePaymentType;
115    private OLERequestPriority oleRequestPriority;
116    private OLEAuthenticationType oleAuthenticationType;
117    private OleStatisticalSearchingCodes oleStatisticalCode;
118    private OLEEResourceStatus oleeResourceStatus;
119    private VendorDetail vendorDetail;
120    private PurchaseOrderType orderType;
121
122    private List<OLEMaterialTypeList> oleMaterialTypes = new ArrayList<OLEMaterialTypeList>();
123    private List<OLEContentTypes> oleContentTypes = new ArrayList<OLEContentTypes>();
124    private List<OLEFormatTypeList> oleFormatTypes = new ArrayList<OLEFormatTypeList>();
125    private List<OLEEResourceNotes> eresNotes = new ArrayList<OLEEResourceNotes>();
126    private List<OLEEResourceRequestor> requestors = new ArrayList<OLEEResourceRequestor>();
127    private List<OLEEResourceSelector> selectors = new ArrayList<OLEEResourceSelector>();
128    private List<OLEEResourceReqSelComments> reqSelComments = new ArrayList<OLEEResourceReqSelComments>();
129    private List<OLEEResourceEventLog> oleERSEventLogs = new ArrayList<OLEEResourceEventLog>();
130    private List<OLEEResourceLicense> oleERSLicenseRequests = new ArrayList<OLEEResourceLicense>();
131    private List<OLEEResourceInstance> oleERSInstances = new ArrayList<OLEEResourceInstance>();
132    private List<OLEEResourceInvoices> oleERSInvoices = new ArrayList<>();
133    private List<OLEEResourceInvoices> eRSInvoices = new ArrayList<>();
134    private List<OleCopy> copyList = new ArrayList<>();
135    private List<OLEEResourcePO> oleERSPOItems = new ArrayList<>();
136    private List<OLEEResourcePO> eRSPOItems = new ArrayList<>();
137    private OLEEResourceRecordForm form;
138    private String status=null;
139    private DocstoreClientLocator docstoreClientLocator;
140
141    public DocstoreClientLocator getDocstoreClientLocator() {
142
143        if (docstoreClientLocator == null) {
144            docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
145        }
146        return docstoreClientLocator;
147    }
148    public OLEEResourceRecordDocument() {
149        getOleMaterialTypes().add(new OLEMaterialTypeList());
150        getOleFormatTypes().add(new OLEFormatTypeList());
151        getOleContentTypes().add(new OLEContentTypes());
152        getRequestors().add(new OLEEResourceRequestor());
153        getSelectors().add(new OLEEResourceSelector());
154        getReqSelComments().add(new OLEEResourceReqSelComments());
155        getEresNotes().add(new OLEEResourceNotes());
156    }
157
158    public String getStatusName() {
159        if (getStatusId() != null) {
160            oleeResourceStatus = boService.findBySinglePrimaryKey(OLEEResourceStatus.class, statusId);
161            statusName = oleeResourceStatus.getOleEResourceStatusName();
162        }
163        return statusName;
164    }
165
166    public OLEEResourceSearchService getOleEResourceSearchService() {
167        if (oleEResourceSearchService == null) {
168            oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
169        }
170        return oleEResourceSearchService;
171    }
172
173    public void setStatusName(String statusName) {
174        this.statusName = statusName;
175    }
176
177    public OLEEResourceRecordForm getForm() {
178        return form;
179    }
180
181    public void setForm(OLEEResourceRecordForm form) {
182        this.form = form;
183    }
184
185    public String getOleERSIdentifier() {
186        return oleERSIdentifier;
187    }
188
189    public String getISBN() {
190        return ISBN;
191    }
192
193    public void setISBN(String ISBN) {
194        this.ISBN = ISBN;
195    }
196
197    public String getOclc() {
198        return oclc;
199    }
200
201    public void setOclc(String oclc) {
202        this.oclc = oclc;
203    }
204
205    public void setOleERSIdentifier(String oleERSIdentifier) {
206        this.oleERSIdentifier = oleERSIdentifier;
207    }
208
209    public String getVendorId() {
210        return vendorId;
211    }
212
213    public void setVendorId(String vendorId) {
214        this.vendorId = vendorId;
215    }
216
217    public String getStatisticalSearchingCode() {
218        return statisticalSearchingCode;
219    }
220
221    public void setStatisticalSearchingCode(String statisticalSearchingCode) {
222        this.statisticalSearchingCode = statisticalSearchingCode;
223    }
224
225    public Integer getStatisticalSearchingCodeId() {
226        return statisticalSearchingCodeId;
227    }
228
229    public void setStatisticalSearchingCodeId(Integer statisticalSearchingCodeId) {
230        this.statisticalSearchingCodeId = statisticalSearchingCodeId;
231    }
232
233    public String getTitle() {
234        return title;
235    }
236
237    public void setTitle(String title) {
238        this.title = title;
239    }
240
241    public String getDescription() {
242        return description;
243    }
244
245    public void setDescription(String description) {
246        this.description = description;
247    }
248
249    public String getPublisher() {
250        return publisher;
251    }
252
253    public void setPublisher(String publisher) {
254        this.publisher = publisher;
255    }
256
257    public String getGokbIdentifier() {
258        return gokbIdentifier;
259    }
260
261    public void setGokbIdentifier(String gokbIdentifier) {
262        this.gokbIdentifier = gokbIdentifier;
263    }
264
265    public String getIsbn() {
266        return isbn;
267    }
268
269    public void setIsbn(String isbn) {
270        this.isbn = isbn;
271    }
272
273    public String getPlatformProvider() {
274        return platformProvider;
275    }
276
277    public void setPlatformProvider(String platformProvider) {
278        this.platformProvider = platformProvider;
279    }
280
281    public String getStatusId() {
282        return statusId;
283    }
284
285    public void setStatusId(String statusId) {
286        this.statusId = statusId;
287    }
288
289    public String getStatusDate() {
290        if (this.statusDate != null) {
291            return statusDate.substring(0, 10);
292        } else
293            return new Date(System.currentTimeMillis()).toString().substring(0, 10);
294    }
295
296    public void setStatusDate(String statusDate) {
297        this.statusDate = statusDate;
298    }
299
300    public String getFundCode() {
301        return fundCode;
302    }
303
304    public void setFundCode(String fundCode) {
305        this.fundCode = fundCode;
306    }
307
308    public String getEstimatedPrice() {
309        return estimatedPrice;
310    }
311
312    public void setEstimatedPrice(String estimatedPrice) {
313        this.estimatedPrice = estimatedPrice;
314    }
315
316    public BigDecimal getOrderTypeId() {
317        return orderTypeId;
318    }
319
320    public void setOrderTypeId(BigDecimal orderTypeId) {
321        this.orderTypeId = orderTypeId;
322    }
323
324    public String getPaymentTypeId() {
325        return paymentTypeId;
326    }
327
328    public void setPaymentTypeId(String paymentTypeId) {
329        this.paymentTypeId = paymentTypeId;
330    }
331
332    public String getPackageTypeId() {
333        return packageTypeId;
334    }
335
336    public void setPackageTypeId(String packageTypeId) {
337        this.packageTypeId = packageTypeId;
338    }
339
340    public String getPackageScopeId() {
341        return packageScopeId;
342    }
343
344    public void setPackageScopeId(String packageScopeId) {
345        this.packageScopeId = packageScopeId;
346    }
347
348    public boolean isBreakable() {
349        return breakable;
350    }
351
352    public void setBreakable(boolean breakable) {
353        this.breakable = breakable;
354    }
355
356    public boolean isFixedTitleList() {
357        return fixedTitleList;
358    }
359
360    public void setFixedTitleList(boolean fixedTitleList) {
361        this.fixedTitleList = fixedTitleList;
362    }
363
364    public String getNoteId() {
365        return noteId;
366    }
367
368    public void setNoteId(String noteId) {
369        this.noteId = noteId;
370    }
371
372    public String getPublicDisplayNote() {
373        return publicDisplayNote;
374    }
375
376    public void setPublicDisplayNote(String publicDisplayNote) {
377        this.publicDisplayNote = publicDisplayNote;
378    }
379
380    public String getReqSelComment() {
381        return reqSelComment;
382    }
383
384    public void setReqSelComment(String reqSelComment) {
385        this.reqSelComment = reqSelComment;
386    }
387
388    public String getReqPriority() {
389        return reqPriority;
390    }
391
392    public void setReqPriority(String reqPriority) {
393        this.reqPriority = reqPriority;
394    }
395
396    public String getTechRequirements() {
397        return techRequirements;
398    }
399
400    public void setTechRequirements(String techRequirements) {
401        this.techRequirements = techRequirements;
402    }
403
404    public String getAccessTypeId() {
405        return accessTypeId;
406    }
407
408    public void setAccessTypeId(String accessTypeId) {
409        this.accessTypeId = accessTypeId;
410    }
411
412    public String getNumOfSimultaneousUsers() {
413        return numOfSimultaneousUsers;
414    }
415
416    public void setNumOfSimultaneousUsers(String numOfSimultaneousUsers) {
417        this.numOfSimultaneousUsers = numOfSimultaneousUsers;
418    }
419
420    public String getAuthenticationTypeId() {
421        return authenticationTypeId;
422    }
423
424    public void setAuthenticationTypeId(String authenticationTypeId) {
425        this.authenticationTypeId = authenticationTypeId;
426    }
427
428    public String getAccessLocationId() {
429        return accessLocationId;
430    }
431
432    public void setAccessLocationId(String accessLocationId) {
433        this.accessLocationId = accessLocationId;
434    }
435
436    public List<String> getAccessLocation() {
437        return accessLocation;
438    }
439
440    public void setAccessLocation(List<String> accessLocation) {
441        this.accessLocation = accessLocation;
442    }
443
444    public boolean isTrialNeeded() {
445        return trialNeeded;
446    }
447
448    public void setTrialNeeded(boolean trialNeeded) {
449        this.trialNeeded = trialNeeded;
450    }
451
452    public String getTrialStatus() {
453        return trialStatus;
454    }
455
456    public void setTrialStatus(String trialStatus) {
457        this.trialStatus = trialStatus;
458    }
459
460    public boolean isLicenseNeeded() {
461        return licenseNeeded;
462    }
463
464    public void setLicenseNeeded(boolean licenseNeeded) {
465        this.licenseNeeded = licenseNeeded;
466    }
467
468    public String getLicenseReqStatus() {
469        return licenseReqStatus;
470    }
471
472    public void setLicenseReqStatus(String licenseReqStatus) {
473        this.licenseReqStatus = licenseReqStatus;
474    }
475
476    public String getOrderPayStatus() {
477        return orderPayStatus;
478    }
479
480    public void setOrderPayStatus(String orderPayStatus) {
481        this.orderPayStatus = orderPayStatus;
482    }
483
484    public String getActivationStatus() {
485        return activationStatus;
486    }
487
488    public void setActivationStatus(String activationStatus) {
489        this.activationStatus = activationStatus;
490    }
491
492    public OLEAccessType getOleAccessType() {
493        return oleAccessType;
494    }
495
496    public void setOleAccessType(OLEAccessType oleAccessType) {
497        this.oleAccessType = oleAccessType;
498    }
499
500    public OLEPackageScope getOlePackageScope() {
501        return olePackageScope;
502    }
503
504    public void setOlePackageScope(OLEPackageScope olePackageScope) {
505        this.olePackageScope = olePackageScope;
506    }
507
508    public OLEPackageType getOlePackageType() {
509        return olePackageType;
510    }
511
512    public void setOlePackageType(OLEPackageType olePackageType) {
513        this.olePackageType = olePackageType;
514    }
515
516    public OLEPaymentType getOlePaymentType() {
517        return olePaymentType;
518    }
519
520    public void setOlePaymentType(OLEPaymentType olePaymentType) {
521        this.olePaymentType = olePaymentType;
522    }
523
524    public OLERequestPriority getOleRequestPriority() {
525        return oleRequestPriority;
526    }
527
528    public void setOleRequestPriority(OLERequestPriority oleRequestPriority) {
529        this.oleRequestPriority = oleRequestPriority;
530    }
531
532    public OLEAuthenticationType getOleAuthenticationType() {
533        return oleAuthenticationType;
534    }
535
536    public void setOleAuthenticationType(OLEAuthenticationType oleAuthenticationType) {
537        this.oleAuthenticationType = oleAuthenticationType;
538    }
539
540    public OLEEResourceStatus getOleeResourceStatus() {
541        return oleeResourceStatus;
542    }
543
544    public void setOleeResourceStatus(OLEEResourceStatus oleeResourceStatus) {
545        this.oleeResourceStatus = oleeResourceStatus;
546    }
547
548    public List<OLEFormatTypeList> getOleFormatTypes() {
549        return oleFormatTypes;
550    }
551
552    public void setOleFormatTypes(List<OLEFormatTypeList> oleFormatTypes) {
553        this.oleFormatTypes = oleFormatTypes;
554    }
555
556    public List<OLEMaterialTypeList> getOleMaterialTypes() {
557        return oleMaterialTypes;
558    }
559
560    public void setOleMaterialTypes(List<OLEMaterialTypeList> oleMaterialTypes) {
561        this.oleMaterialTypes = oleMaterialTypes;
562    }
563
564    public List<OLEContentTypes> getOleContentTypes() {
565        return oleContentTypes;
566    }
567
568    public void setOleContentTypes(List<OLEContentTypes> oleContentTypes) {
569        this.oleContentTypes = oleContentTypes;
570    }
571
572    public List<OLEEResourceNotes> getEresNotes() {
573        return eresNotes;
574    }
575
576    public void setEresNotes(List<OLEEResourceNotes> eresNotes) {
577        this.eresNotes = eresNotes;
578    }
579
580    public List<OLEEResourceRequestor> getRequestors() {
581        return requestors;
582    }
583
584    public void setRequestors(List<OLEEResourceRequestor> requestors) {
585        this.requestors = requestors;
586    }
587
588    public List<OLEEResourceSelector> getSelectors() {
589        return selectors;
590    }
591
592    public void setSelectors(List<OLEEResourceSelector> selectors) {
593        this.selectors = selectors;
594    }
595
596    public List<OLEEResourceReqSelComments> getReqSelComments() {
597        return reqSelComments;
598    }
599
600    public void setReqSelComments(List<OLEEResourceReqSelComments> reqSelComments) {
601        this.reqSelComments = reqSelComments;
602    }
603
604    public String getDocumentNumber() {
605        return documentNumber;
606    }
607
608    public void setDocumentNumber(String documentNumber) {
609        this.documentNumber = documentNumber;
610    }
611
612    public List<OLEEResourceEventLog> getOleERSEventLogs() {
613        return oleERSEventLogs;
614    }
615
616    public void setOleERSEventLogs(List<OLEEResourceEventLog> oleERSEventLogs) {
617        this.oleERSEventLogs = oleERSEventLogs;
618    }
619
620    public List<OLEEResourceLicense> getOleERSLicenseRequests() {
621        return oleERSLicenseRequests;
622    }
623
624    public void setOleERSLicenseRequests(List<OLEEResourceLicense> oleERSLicenseRequests) {
625        this.oleERSLicenseRequests = oleERSLicenseRequests;
626    }
627
628    public boolean isSelectFlag() {
629        return selectFlag;
630    }
631
632    public void setSelectFlag(boolean selectFlag) {
633        this.selectFlag = selectFlag;
634    }
635
636    public String getSelectInstance() {
637        return selectInstance;
638    }
639
640    public void setSelectInstance(String selectInstance) {
641        this.selectInstance = selectInstance;
642    }
643
644    public String getDefaultCoverage() {
645        return defaultCoverage;
646    }
647
648    public void setDefaultCoverage(String defaultCoverage) {
649        this.defaultCoverage = defaultCoverage;
650    }
651
652    public String getDefaultPerpetualAccess() {
653        return defaultPerpetualAccess;
654    }
655
656    public void setDefaultPerpetualAccess(String defaultPerpetualAccess) {
657        this.defaultPerpetualAccess = defaultPerpetualAccess;
658    }
659
660    public String getDefaultCoverageView() {
661        return defaultCoverageView;
662    }
663
664    public void setDefaultCoverageView(String defaultCoverageView) {
665        this.defaultCoverageView = defaultCoverageView;
666    }
667
668    public String getDefaultPerpetualAccessView() {
669        return defaultPerpetualAccessView;
670    }
671
672    public void setDefaultPerpetualAccessView(String defaultPerpetualAccessView) {
673        this.defaultPerpetualAccessView = defaultPerpetualAccessView;
674    }
675
676    public List<OLEEResourceInstance> getOleERSInstances() {
677        return oleERSInstances;
678    }
679
680    public void setOleERSInstances(List<OLEEResourceInstance> oleERSInstances) {
681        this.oleERSInstances = oleERSInstances;
682    }
683
684    public List<OleCopy> getCopyList() {
685        return copyList;
686    }
687
688    public void setCopyList(List<OleCopy> copyList) {
689        this.copyList = copyList;
690    }
691
692    public List<OLEEResourcePO> getOleERSPOItems() {
693        return oleERSPOItems;
694    }
695
696    public void setOleERSPOItems(List<OLEEResourcePO> oleERSPOItems) {
697        this.oleERSPOItems = oleERSPOItems;
698    }
699
700    public VendorDetail getVendorDetail() {
701        return vendorDetail;
702    }
703
704    public void setVendorDetail(VendorDetail vendorDetail) {
705        this.vendorDetail = vendorDetail;
706    }
707
708    public PurchaseOrderType getOrderType() {
709        return orderType;
710    }
711
712    public void setOrderType(PurchaseOrderType orderType) {
713        this.orderType = orderType;
714    }
715
716    public String getVendorName() {
717        return vendorName;
718    }
719
720    public void setVendorName(String vendorName) {
721        this.vendorName = vendorName;
722    }
723
724    public Integer getVendorDetailAssignedIdentifier() {
725        return vendorDetailAssignedIdentifier;
726    }
727
728    public void setVendorDetailAssignedIdentifier(Integer vendorDetailAssignedIdentifier) {
729        this.vendorDetailAssignedIdentifier = vendorDetailAssignedIdentifier;
730    }
731
732    public Integer getVendorHeaderGeneratedIdentifier() {
733        return vendorHeaderGeneratedIdentifier;
734    }
735
736    public void setVendorHeaderGeneratedIdentifier(Integer vendorHeaderGeneratedIdentifier) {
737        this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
738    }
739
740    public OleStatisticalSearchingCodes getOleStatisticalCode() {
741        return oleStatisticalCode;
742    }
743
744    public void setOleStatisticalCode(OleStatisticalSearchingCodes oleStatisticalCode) {
745        this.oleStatisticalCode = oleStatisticalCode;
746    }
747
748    public OLEEResourceInstance getOleERSInstance() {
749        return oleERSInstance;
750    }
751
752    public void setOleERSInstance(OLEEResourceInstance oleERSInstance) {
753        this.oleERSInstance = oleERSInstance;
754    }
755
756    public List<OLEEResourceInvoices> getOleERSInvoices() {
757        return oleERSInvoices;
758    }
759
760    public void setOleERSInvoices(List<OLEEResourceInvoices> oleERSInvoices) {
761        this.oleERSInvoices = oleERSInvoices;
762    }
763
764    public boolean iseInstanceFlag() {
765        return eInstanceFlag;
766    }
767
768    public void seteInstanceFlag(boolean eInstanceFlag) {
769        this.eInstanceFlag = eInstanceFlag;
770    }
771
772    public String getDummyDefaultCoverage() {
773        return dummyDefaultCoverage;
774    }
775
776    public void setDummyDefaultCoverage(String dummyDefaultCoverage) {
777        this.dummyDefaultCoverage = dummyDefaultCoverage;
778    }
779
780    public String getDummyDefaultPerpetualAccess() {
781        return dummyDefaultPerpetualAccess;
782    }
783
784    public void setDummyDefaultPerpetualAccess(String dummyDefaultPerpetualAccess) {
785        this.dummyDefaultPerpetualAccess = dummyDefaultPerpetualAccess;
786    }
787
788    public boolean isCovEdited() {
789        return isCovEdited;
790    }
791
792    public void setCovEdited(boolean covEdited) {
793        isCovEdited = covEdited;
794    }
795
796    public boolean isPerAccEdited() {
797        return isPerAccEdited;
798    }
799
800    public void setPerAccEdited(boolean perAccEdited) {
801        isPerAccEdited = perAccEdited;
802    }
803
804    public String getCovStartDate() {
805        return covStartDate;
806    }
807
808    public void setCovStartDate(String covStartDate) {
809        this.covStartDate = covStartDate;
810    }
811
812    public String getCovEndDate() {
813        return covEndDate;
814    }
815
816    public void setCovEndDate(String covEndDate) {
817        this.covEndDate = covEndDate;
818    }
819
820    public String getPerAccStartDate() {
821        return perAccStartDate;
822    }
823
824    public void setPerAccStartDate(String perAccStartDate) {
825        this.perAccStartDate = perAccStartDate;
826    }
827
828    public String getPerAccEndDate() {
829        return perAccEndDate;
830    }
831
832    public void setPerAccEndDate(String perAccEndDate) {
833        this.perAccEndDate = perAccEndDate;
834    }
835
836    public List<OLEEResourceInvoices> geteRSInvoices() {
837        return eRSInvoices;
838    }
839
840    public void seteRSInvoices(List<OLEEResourceInvoices> eRSInvoices) {
841        this.eRSInvoices = eRSInvoices;
842    }
843
844    public List<OLEEResourcePO> geteRSPOItems() {
845        return eRSPOItems;
846    }
847
848    public void seteRSPOItems(List<OLEEResourcePO> eRSPOItems) {
849        this.eRSPOItems = eRSPOItems;
850    }
851
852    public void setResultDetails(DocumentSearchResult searchResult, List<OLESearchCondition> oleSearchEresources) {
853        List<DocumentAttribute> documentAttributes = searchResult.getDocumentAttributes();
854        for (DocumentAttribute docAttribute : documentAttributes) {
855            String name = docAttribute.getName();
856            if (OLEConstants.OLEEResourceRecord.ERESOURCE_RESULT_FIELDS.contains(name)) {
857                if (name.equals(OLEConstants.OLEEResourceRecord.ERESOURCE_TITLE)) {
858                    name = OLEConstants.OLEEResourceRecord.ERESOURCE_TITLE;
859                }
860                Method getMethod;
861                try {
862                    getMethod = getSetMethod(OLEEResourceRecordDocument.class, name, new Class[]{String.class});
863                    getMethod.invoke(this, docAttribute.getValue().toString());
864                } catch (Exception ex) {
865                    ex.printStackTrace();
866                }
867            }
868        }
869    }
870
871    private Method getSetMethod(Class targetClass, String attr, Class[] objectAttributes) throws Exception {
872        Method method = targetClass.getMethod("set" + StringUtils.capitalize(attr), objectAttributes);
873        return method;
874    }
875
876    @Override
877    public void prepareForSave(KualiDocumentEvent event) {
878        // TODO Auto-generated method stub
879        // first populate, then call super
880        super.prepareForSave(event);
881        try {
882            LOG.debug("###########Inside OLEEResourceRecordDocument " + "prepareForSave###########");
883            if (this.getStatisticalSearchingCode() != null && (!"".equals(this.getStatisticalSearchingCode().trim()))) {
884                this.setStatisticalSearchingCodeId(Integer.parseInt(this.getStatisticalSearchingCode()));
885                Map statisticalCodeMap = new HashMap<>();
886                statisticalCodeMap.put(OLEConstants.OLEEResourceRecord.STATISTICAL_SEARCH_CD_ID, this.getStatisticalSearchingCodeId());
887                OleStatisticalSearchingCodes oleStatisticalSearchingCodes = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleStatisticalSearchingCodes.class, statisticalCodeMap);
888                if(oleStatisticalSearchingCodes != null) {
889                    this.setOleStatisticalCode(oleStatisticalSearchingCodes);
890                }
891            }
892            String vendorId = this.getVendorId();
893            if (vendorId != null && !vendorId.isEmpty()) {
894                String[] vendorDetails = vendorId.split("-");
895                this.setVendorHeaderGeneratedIdentifier(vendorDetails.length > 0 ? Integer.parseInt(vendorDetails[0]) : 0);
896                this.setVendorDetailAssignedIdentifier(vendorDetails.length > 1 ? Integer.parseInt(vendorDetails[1]) : 0);
897                Map vendorMap = new HashMap<>();
898                vendorMap.put(OLEConstants.OLEEResourceRecord.VENDOR_HEADER_GEN_ID, this.getVendorHeaderGeneratedIdentifier());
899                vendorMap.put(OLEConstants.OLEEResourceRecord.VENDOR_DETAILED_ASSIGNED_ID, this.getVendorDetailAssignedIdentifier());
900                VendorDetail vendorDetailDoc = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(VendorDetail.class, vendorMap);
901                if (vendorDetailDoc != null) {
902                    this.setVendorName(vendorDetailDoc.getVendorName());
903                }
904            }
905            String accessId = "";
906            if (this.getAccessLocation().size() > 0) {
907                List<String> accessLocationId = this.getAccessLocation();
908                if (accessLocationId.size() > 0) {
909                    for (String accessLocation : accessLocationId) {
910                        accessId += accessLocation;
911                        accessId += OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR;
912                    }
913                    this.setAccessLocationId(accessId.substring(0, (accessId.lastIndexOf(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR))));
914                }
915            }
916            this.setLicenseReqStatus("");
917            List<OLEEResourceLicense> oleERSLicenses = this.getOleERSLicenseRequests();
918            List<DateTime> modifiedDateList = new ArrayList<>();
919            DateTime lastModifiedDate = null;
920            if (oleERSLicenses.size() > 0) {
921                for (int i = oleERSLicenses.size()-1; i >= 0; i--) {
922                    DateTime appStatus = oleERSLicenses.get(i).getDocumentRouteHeaderValue().getApplicationDocumentStatusDate();
923                    if (!OLEConstants.OLEEResourceRecord.ERESOURCE_STATUSES.contains(appStatus) &&
924                            (!oleERSLicenses.get(i).getDocumentRouteHeaderValue().getAppDocStatus().equalsIgnoreCase(
925                                    OLEConstants.OLEEResourceRecord.LICENSE_FINAL_STATUS))) {
926                        modifiedDateList.add(appStatus);
927                    }
928                    DocumentRouteHeaderValue documentRouteHeaderValue = oleERSLicenses.get(i).getDocumentRouteHeaderValue();
929                    if(documentRouteHeaderValue != null) {
930                        String licenceTitle = documentRouteHeaderValue.getDocTitle();
931                        if(licenceTitle != null && !licenceTitle.isEmpty()) {
932                            licenceTitle = licenceTitle.substring(26);
933                        }
934                        oleERSLicenses.get(i).setDocumentDescription(licenceTitle);
935                    }
936                }
937                for (int modifiedDate = 0; modifiedDate<modifiedDateList.size(); modifiedDate++) {
938                    DateTime dateTime = modifiedDateList.get(modifiedDate);
939                    if (lastModifiedDate == null) {
940                        lastModifiedDate = dateTime;
941                    } else {
942                        if (dateTime.isAfter(lastModifiedDate)) {
943                            lastModifiedDate = dateTime;
944                        }
945                    }
946                }
947                for (int i = oleERSLicenses.size()-1; i >= 0; i--) {
948                    if (lastModifiedDate != null && lastModifiedDate.equals(oleERSLicenses.get(i).getDocumentRouteHeaderValue().getApplicationDocumentStatusDate())) {
949                        this.setLicenseReqStatus(oleERSLicenses.get(i).getDocumentRouteHeaderValue().getApplicationDocumentStatus());
950                    }
951                }
952            }
953        } catch (Exception e) {
954            LOG.error("Exception during prepareForSave()", e);
955            throw new RuntimeException(e);
956        }
957        Map statusMap = new HashMap<>();
958        statusMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, this.getOleERSIdentifier());
959        OLEEResourceRecordDocument oleERSDoc = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, statusMap);
960        if (oleERSDoc != null) {
961            status = oleERSDoc.getStatusName();
962        }
963        OLEEResourceEventLog oleEResourceEventLog = new OLEEResourceEventLog();
964        if (status == null){
965            oleEResourceEventLog.setCurrentTimeStamp();
966            oleEResourceEventLog.setEventUser(GlobalVariables.getUserSession().getPrincipalName());
967            oleEResourceEventLog.setEventType(OLEConstants.OLEEResourceRecord.SYSTEM);
968            oleEResourceEventLog.setEventNote(OLEConstants.OLEEResourceRecord.STATUS_IS+getStatusName());
969            this.getOleERSEventLogs().add(oleEResourceEventLog);
970        }
971        else if (!status.equals(getStatusName())){
972            oleEResourceEventLog.setCurrentTimeStamp();
973            oleEResourceEventLog.setEventUser(GlobalVariables.getUserSession().getPrincipalName());
974            oleEResourceEventLog.setEventType(OLEConstants.OLEEResourceRecord.SYSTEM);
975            oleEResourceEventLog.setEventNote(OLEConstants.OLEEResourceRecord.STATUS_FROM+ status +OLEConstants.OLEEResourceRecord.STATUS_TO+getStatusName());
976            this.getOleERSEventLogs().add(oleEResourceEventLog);
977        }
978        status=getStatusName();
979        String defaultCov = this.getDummyDefaultCoverage();
980        if(defaultCov != null && !defaultCov.isEmpty() && !this.isCovEdited()) {
981            this.setCovEdited(true);
982            getOleEResourceSearchService().getDefaultCovDatesToPopup(this,defaultCov);
983        }
984        String defaultPerAcc = this.getDummyDefaultPerpetualAccess();
985        if(defaultPerAcc != null && !defaultPerAcc.isEmpty() && !this.isPerAccEdited()) {
986            this.setPerAccEdited(true);
987            getOleEResourceSearchService().getDefaultPerAccDatesToPopup(this,defaultPerAcc);
988        }
989        getOleEResourceSearchService().saveDefaultCoverageDate(this);
990        getOleEResourceSearchService().saveDefaultPerpetualAccessDate(this);
991        try {
992            getOleEResourceSearchService().saveEResourceInstanceToDocstore(this);
993        } catch (Exception e) {
994            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
995        }
996
997    }
998
999    public void processAfterRetrieve() {
1000        super.processAfterRetrieve();
1001        if (this.getStatisticalSearchingCodeId() != null) {
1002            this.setStatisticalSearchingCode(this.getStatisticalSearchingCodeId().toString());
1003        }
1004        String accessLocationId = this.getAccessLocationId();
1005        if (accessLocationId != null && !accessLocationId.isEmpty()) {
1006            String[] accessLocation = accessLocationId.split(OLEConstants.OLEEResourceRecord.ACCESS_LOCATION_SEPARATOR);
1007            List<String> accessLocations = new ArrayList<>();
1008            for (String accessLocId : accessLocation) {
1009                accessLocations.add(accessLocId);
1010            }
1011            this.setAccessLocation(accessLocations);
1012        }
1013        this.setLicenseReqStatus("");
1014        List<OLEEResourceLicense> oleERSLicenses = this.getOleERSLicenseRequests();
1015        List<DateTime> modifiedDateList = new ArrayList<>();
1016        DateTime lastModifiedDate = null;
1017        if (oleERSLicenses.size() > 0) {
1018            for (int i = oleERSLicenses.size()-1; i >= 0; i--) {
1019                DateTime appStatus = oleERSLicenses.get(i).getDocumentRouteHeaderValue().getApplicationDocumentStatusDate();
1020                if (!OLEConstants.OLEEResourceRecord.ERESOURCE_STATUSES.contains(appStatus) &&
1021                        (!oleERSLicenses.get(i).getDocumentRouteHeaderValue().getAppDocStatus().equalsIgnoreCase(
1022                                OLEConstants.OLEEResourceRecord.LICENSE_FINAL_STATUS))) {
1023                    modifiedDateList.add(appStatus);
1024                }
1025                DocumentRouteHeaderValue documentRouteHeaderValue = oleERSLicenses.get(i).getDocumentRouteHeaderValue();
1026                if(documentRouteHeaderValue != null) {
1027                    String licenceTitle = documentRouteHeaderValue.getDocTitle();
1028                    if(licenceTitle != null && !licenceTitle.isEmpty()) {
1029                        licenceTitle = licenceTitle.substring(26);
1030                    }
1031                    oleERSLicenses.get(i).setDocumentDescription(licenceTitle);
1032                }
1033            }
1034            for (int modifiedDate = 0; modifiedDate<modifiedDateList.size(); modifiedDate++) {
1035                DateTime dateTime = modifiedDateList.get(modifiedDate);
1036                if (lastModifiedDate == null) {
1037                    lastModifiedDate = dateTime;
1038                } else {
1039                    if (dateTime.isAfter(lastModifiedDate)) {
1040                        lastModifiedDate = dateTime;
1041                    }
1042                }
1043            }
1044            for (int i = oleERSLicenses.size()-1; i >= 0; i--) {
1045                if (lastModifiedDate!=null && lastModifiedDate.equals(oleERSLicenses.get(i).getDocumentRouteHeaderValue().getApplicationDocumentStatusDate())) {
1046                    this.setLicenseReqStatus(oleERSLicenses.get(i).getDocumentRouteHeaderValue().getApplicationDocumentStatus());
1047                }
1048            }
1049        }
1050        List<OLEEResourceInstance> oleERSInstances = this.getOleERSInstances();
1051        OLEEResourceInstance oleeResourceInstance = null;
1052        List<Holdings> holdingsList = new ArrayList<Holdings>();
1053        List<String> instanceId = new ArrayList<String>();
1054        if (oleERSInstances.size() > 0) {
1055            for (OLEEResourceInstance oleERSInstance : oleERSInstances) {
1056                    instanceId.add(oleERSInstance.getInstanceId());
1057            }
1058        }
1059        if (instanceId.size() > 0) {
1060            for(String id:instanceId){
1061                try {
1062                    holdingsList.add(getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(id));
1063                } catch (Exception e) {
1064                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
1065                }
1066            }
1067        }
1068        for (Holdings holdings:holdingsList){
1069            if(holdings instanceof EHoldings){
1070                HoldingOlemlRecordProcessor holdingOlemlRecordProcessor=new HoldingOlemlRecordProcessor();
1071                OleHoldings oleHoldings=holdingOlemlRecordProcessor.fromXML(holdings.getContent());
1072                for (OLEEResourceInstance oleERSInstance : oleERSInstances) {
1073                    if (holdings.getId().equals(oleERSInstance.getInstanceId())) {
1074                        oleeResourceInstance = oleERSInstance;
1075                        StringBuffer urls = new StringBuffer();
1076                        for(Link link :oleHoldings.getLink()){
1077                            urls.append(link.getUrl());
1078                            urls.append(",");
1079                        }
1080                        if (urls != null && urls.length() > 0) {
1081                            String url = urls.substring(0, urls.lastIndexOf(","));
1082                            oleeResourceInstance.setUrl(url);
1083                        }
1084                    }
1085                }
1086            }
1087
1088        }
1089        getOleEResourceSearchService().getDefaultCovergeDate(this);
1090        getOleEResourceSearchService().getDefaultPerpetualAccessDate(this);
1091        getOleEResourceSearchService().getPOInvoiceForERS(this);
1092        getOleEResourceSearchService().getPOAndInvoiceItemsWithoutDuplicate(this);
1093    }
1094}