001package org.kuali.ole.describe.form;
002
003/**
004 * Created with IntelliJ IDEA.
005 * User: pp7788
006 * Date: 12/11/12
007 * Time: 2:57 PM
008 * To change this template use File | Settings | File Templates.
009 */
010
011import org.kuali.ole.docstore.common.document.content.instance.*;
012import org.kuali.ole.describe.bo.InstanceRecordMetaData;
013import org.kuali.ole.describe.bo.SourceEditorForUI;
014import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
015import org.kuali.ole.select.document.OlePurchaseOrderDocument;
016import org.kuali.ole.sys.OLEConstants;
017import org.kuali.rice.core.api.config.property.ConfigContext;
018import org.kuali.rice.krad.service.BusinessObjectService;
019import org.kuali.rice.krad.service.KRADServiceLocator;
020
021import java.util.HashMap;
022import java.util.List;
023import java.util.Map;
024
025/**
026 * InstanceEditorForm is the form class for Instance Editor
027 */
028public class WorkInstanceOlemlForm extends EditorForm {
029
030    private InstanceRecordMetaData itemRecordMetaData = new InstanceRecordMetaData();
031    private InstanceRecordMetaData holdingRecordMetaData = new InstanceRecordMetaData();
032    private OleHoldings selectedHolding;
033    private Instance instance;
034    private Item selectedItem;
035    private SourceEditorForUI selectedSourceHolding;
036    private String oldItemStatus;
037    private String redirectUrl;
038    private String currentBarcode;
039    private String proxyBarcode;
040    private BusinessObjectService businessObjectService;
041    public WorkInstanceOlemlForm() {
042        getSelectedHolding().getUri().add(new Uri());
043        getSelectedHolding().getNote().add(new Note());
044        getSelectedHolding().getExtentOfOwnership().add(new ExtentOfOwnership());
045        getSelectedHolding().getExtentOfOwnership().get(0).getNote().add(new Note());
046        getSelectedItem().getNote().add(new Note());
047    }
048
049    /**
050     * Gets the instance of BusinessObjectService
051     *
052     * @return businessObjectService(BusinessObjectService)
053     */
054    public BusinessObjectService getBusinessObjectService() {
055        if (null == businessObjectService) {
056            businessObjectService = KRADServiceLocator.getBusinessObjectService();
057        }
058        return businessObjectService;
059    }
060
061    public String getMessage() {
062        return message;
063    }
064
065    public void setMessage(String message) {
066        this.message = message;
067    }
068
069    public InstanceRecordMetaData getItemRecordMetaData() {
070        return itemRecordMetaData;
071    }
072
073    public String getCurrentBarcode() {
074        return currentBarcode;
075    }
076
077    public void setCurrentBarcode(String currentBarcode) {
078        this.currentBarcode = currentBarcode;
079    }
080
081    public String getProxyBarcode() {
082        return proxyBarcode;
083    }
084
085    public void setProxyBarcode(String proxyBarcode) {
086        this.proxyBarcode = proxyBarcode;
087    }
088
089    public void setItemRecordMetaData(InstanceRecordMetaData itemRecordMetaData) {
090        this.itemRecordMetaData = itemRecordMetaData;
091    }
092
093    public InstanceRecordMetaData getHoldingRecordMetaData() {
094        return holdingRecordMetaData;
095    }
096
097    public void setHoldingRecordMetaData(InstanceRecordMetaData holdingRecordMetaData) {
098        this.holdingRecordMetaData = holdingRecordMetaData;
099    }
100
101    public OleHoldings getSelectedHolding() {
102        if (null == selectedHolding) {
103            selectedHolding = new OleHoldings();
104            selectedHolding.setCallNumber(new CallNumber());
105        }
106        return selectedHolding;
107    }
108
109    public void setSelectedHolding(OleHoldings selectedHolding) {
110        this.selectedHolding = selectedHolding;
111    }
112
113    public Instance getInstance() {
114        return instance;
115    }
116
117    public void setInstance(Instance instance) {
118        this.instance = instance;
119    }
120
121    public Item getSelectedItem() {
122        if (null == selectedItem) {
123            selectedItem = new Item();
124            selectedItem.setCallNumber(new CallNumber());
125        }
126        return selectedItem;
127    }
128
129    public void setSelectedItem(Item selectedItem) {
130        this.selectedItem = selectedItem;
131    }
132
133    public SourceEditorForUI getSelectedSourceHolding() {
134        return selectedSourceHolding;
135    }
136
137    public void setSelectedSourceHolding(SourceEditorForUI selectedSourceHolding) {
138        this.selectedSourceHolding = selectedSourceHolding;
139    }
140
141    public String getOldItemStatus() {
142        return oldItemStatus;
143    }
144
145    public void setOldItemStatus(String oldItemStatus) {
146        this.oldItemStatus = oldItemStatus;
147    }
148
149    public String getRedirectUrl() {
150        String purchaseOrderLineItemIdentifier = this.getSelectedItem().getPurchaseOrderLineItemIdentifier();
151        if (purchaseOrderLineItemIdentifier != null && !"".equals(purchaseOrderLineItemIdentifier)) {
152            Map poNumber = new HashMap();
153            poNumber.put(OLEConstants.PUR_DOC_IDENTIFIER, purchaseOrderLineItemIdentifier);
154            List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = (List) getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class, poNumber);
155            for (OlePurchaseOrderDocument olePurchaseOrderDocument : olePurchaseOrderDocumentList) {
156                if (olePurchaseOrderDocument != null) {
157                    boolean validPO = olePurchaseOrderDocument!=null ? olePurchaseOrderDocument.getPurchaseOrderCurrentIndicatorForSearching() : false;
158                    if (validPO){
159                        redirectUrl = ConfigContext.getCurrentContextConfig().getProperty("kew.url") + OLEConstants.PO_LINE_ITEM_URL + olePurchaseOrderDocument.getDocumentNumber();
160                    }
161                }
162            }
163        }
164        return redirectUrl;
165    }
166
167    public void setRedirectUrl(String redirectUrl) {
168        this.redirectUrl = redirectUrl;
169    }
170
171
172}