001package org.kuali.ole.select.document;
002
003import org.kuali.ole.select.bo.OleLicenseRequestBo;
004import org.kuali.ole.service.OleLicenseRequestService;
005import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
006import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
007import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
008
009import java.util.ArrayList;
010import java.util.List;
011
012/**
013 * Created with IntelliJ IDEA.
014 * User: juliyamonicas
015 * Date: 6/27/13
016 * Time: 11:25 AM
017 * To change this template use File | Settings | File Templates.
018 */
019public class OLEEResourceLicense extends PersistableBusinessObjectBase {
020
021    private String oleEResourceLicenseId;
022    private String oleERSIdentifier;
023    private String oleLicenseRequestId;
024    private String licenseDocumentNumber;
025    private String attachments;
026    private String licenseStartDate;
027    private String licenseEndDate;
028    private String licensor;
029    private String documentDescription;
030    private DocumentRouteHeaderValue documentRouteHeaderValue = new DocumentRouteHeaderValue();
031    private OleLicenseRequestService oleLicenseRequestService;
032    private OleLicenseRequestBo oleLicenseRequestBo;
033    private OLEEResourceRecordDocument oleERSDocument = new OLEEResourceRecordDocument();
034    private String attachmentString = "No Attachments";
035
036    public String getLicensor() {
037        return licensor;
038    }
039
040    public void setLicensor(String licensor) {
041        this.licensor = licensor;
042    }
043
044    public String getDocumentDescription() {
045        return documentDescription;
046    }
047
048    public void setDocumentDescription(String documentDescription) {
049        this.documentDescription = documentDescription;
050    }
051
052    public String getAttachmentString() {
053        return attachmentString;
054    }
055
056    public void setAttachmentString(String attachmentString) {
057        this.attachmentString = attachmentString;
058    }
059
060    public String getOleEResourceLicenseId() {
061        return oleEResourceLicenseId;
062    }
063
064    public void setOleEResourceLicenseId(String oleEResourceLicenseId) {
065        this.oleEResourceLicenseId = oleEResourceLicenseId;
066    }
067
068    public String getOleERSIdentifier() {
069        return oleERSIdentifier;
070    }
071
072    public void setOleERSIdentifier(String oleERSIdentifier) {
073        this.oleERSIdentifier = oleERSIdentifier;
074    }
075
076    public String getOleLicenseRequestId() {
077        return oleLicenseRequestId;
078    }
079
080    public void setOleLicenseRequestId(String oleLicenseRequestId) {
081        this.oleLicenseRequestId = oleLicenseRequestId;
082    }
083
084    public String getLicenseDocumentNumber() {
085        return licenseDocumentNumber;
086    }
087
088    public void setLicenseDocumentNumber(String licenseDocumentNumber) {
089        this.licenseDocumentNumber = licenseDocumentNumber;
090    }
091
092
093    public String getAttachments() {
094        return attachments;
095    }
096
097    public void setAttachments(String attachments) {
098        this.attachments = attachments;
099    }
100
101    public String getLicenseStartDate() {
102        return licenseStartDate;
103    }
104
105    public void setLicenseStartDate(String licenseStartDate) {
106        this.licenseStartDate = licenseStartDate;
107    }
108
109    public String getLicenseEndDate() {
110        return licenseEndDate;
111    }
112
113    public void setLicenseEndDate(String licenseEndDate) {
114        this.licenseEndDate = licenseEndDate;
115    }
116
117    public DocumentRouteHeaderValue getDocumentRouteHeaderValue() {
118        return documentRouteHeaderValue;
119    }
120
121    public void setDocumentRouteHeaderValue(DocumentRouteHeaderValue documentRouteHeaderValue) {
122        this.documentRouteHeaderValue = documentRouteHeaderValue;
123    }
124
125    public OleLicenseRequestBo getOleLicenseRequestBo() {
126        if (oleLicenseRequestBo == null && documentRouteHeaderValue.getDocumentId() != null &&
127                documentRouteHeaderValue != null) {
128            oleLicenseRequestBo = getOleLicenseRequestService().getLicenseRequestFromDocumentContent(documentRouteHeaderValue.getDocContent());
129        }
130        return oleLicenseRequestBo;
131    }
132
133    public void setOleLicenseRequestBo(OleLicenseRequestBo oleLicenseRequestBo) {
134        this.oleLicenseRequestBo = oleLicenseRequestBo;
135    }
136
137    public OleLicenseRequestService getOleLicenseRequestService() {
138        if (oleLicenseRequestService == null) {
139            oleLicenseRequestService = GlobalResourceLoader.getService("oleLicenseRequestService");
140        }
141        return oleLicenseRequestService;
142    }
143
144    public OLEEResourceRecordDocument getOleERSDocument() {
145        return oleERSDocument;
146    }
147
148    public void setOleERSDocument(OLEEResourceRecordDocument oleERSDocument) {
149        this.oleERSDocument = oleERSDocument;
150    }
151
152    public String getAttachmentDisplay() {
153        String attachmentLinkLabel = "";
154        List<String> lists = new ArrayList<>();
155        lists.add(getDocumentRouteHeaderValue().getDocumentId());
156
157        for (String list : lists) {
158            int i = getOleLicenseRequestService().getLicenseAttachments(getDocumentRouteHeaderValue().getDocumentId());
159            if (i > 1) {
160                attachmentLinkLabel = "Multiple Attachments";
161            } else if (i == 1) {
162                attachmentLinkLabel = "View Attachments";
163            } else if (i == 0) {
164                attachmentLinkLabel = "No Attachments";
165            } else {
166            }
167        }
168
169        return attachmentLinkLabel;
170
171    }
172
173    public String getUrl() {
174        String link = "";
175        List<String> list = new ArrayList<>();
176        list.add(getDocumentRouteHeaderValue().getDocumentId());
177        for (String l : list) {
178            int i = getOleLicenseRequestService().getLicenseAttachments(getDocumentRouteHeaderValue().getDocumentId());
179            if (i > 1) {
180                link ="oleLicenseRequest?methodToCall=getDocument&amp;viewId=OLEEresourceAgreementView&amp;documentClass=org.kuali.rice.krad.web.form.MaintenanceDocumentForm&amp;docId=" + getDocumentRouteHeaderValue().getDocumentId();
181            }
182            else if (i == 1) {
183                link = "oleLicenseRequest?methodToCall=downloadDocument&amp;documentClass=org.kuali.rice.krad.web.form.MaintenanceDocumentForm&amp;docId=" + getDocumentRouteHeaderValue().getDocumentId() + "&amp;command=displayDocSearchView&amp;selectedLineIndex=0";
184            }
185            else {
186            }
187        }
188
189        return link;
190
191    }
192}