001/*
002 * Copyright 2008 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.module.purap.businessobject;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.ole.integration.cab.CapitalAssetBuilderAssetTransactionType;
020import org.kuali.ole.integration.purap.CapitalAssetSystem;
021import org.kuali.ole.integration.purap.ItemCapitalAsset;
022import org.kuali.ole.module.purap.PurapConstants;
023import org.kuali.ole.module.purap.PurapPropertyConstants;
024import org.kuali.ole.module.purap.document.PurchasingDocument;
025import org.kuali.ole.sys.context.SpringContext;
026import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
027import org.kuali.rice.krad.service.KualiModuleService;
028import org.kuali.rice.krad.util.ObjectUtils;
029
030import java.util.LinkedHashMap;
031
032public abstract class PurchasingCapitalAssetItemBase extends PersistableBusinessObjectBase implements PurchasingCapitalAssetItem {
033
034    private Integer capitalAssetItemIdentifier;
035    private Integer itemIdentifier;
036    private String capitalAssetTransactionTypeCode;
037    private Integer capitalAssetSystemIdentifier;
038
039    private CapitalAssetBuilderAssetTransactionType capitalAssetTransactionType;
040    private CapitalAssetSystem purchasingCapitalAssetSystem;
041    private PurchasingDocument purchasingDocument;
042    private PurchasingItem purchasingItem;
043    private ItemCapitalAsset newPurchasingItemCapitalAssetLine;
044
045    public PurchasingCapitalAssetItemBase() {
046        super();
047        this.setNewPurchasingItemCapitalAssetLine(this.setupNewPurchasingItemCapitalAssetLine());
048    }
049
050    public PurchasingCapitalAssetItemBase(PurchasingDocument pd) {
051        setPurchasingDocument(pd);
052    }
053
054    public Integer getCapitalAssetItemIdentifier() {
055        return capitalAssetItemIdentifier;
056    }
057
058    public void setCapitalAssetItemIdentifier(Integer capitalAssetItemIdentifier) {
059        this.capitalAssetItemIdentifier = capitalAssetItemIdentifier;
060    }
061
062    public Integer getItemIdentifier() {
063        return itemIdentifier;
064    }
065
066    public void setItemIdentifier(Integer itemIdentifier) {
067        this.itemIdentifier = itemIdentifier;
068    }
069
070    public String getCapitalAssetTransactionTypeCode() {
071        return capitalAssetTransactionTypeCode;
072    }
073
074    public void setCapitalAssetTransactionTypeCode(String capitalAssetTransactionTypeCode) {
075        this.capitalAssetTransactionTypeCode = capitalAssetTransactionTypeCode;
076    }
077
078    public Integer getCapitalAssetSystemIdentifier() {
079        return capitalAssetSystemIdentifier;
080    }
081
082    public void setCapitalAssetSystemIdentifier(Integer capitalAssetSystemIdentifier) {
083        this.capitalAssetSystemIdentifier = capitalAssetSystemIdentifier;
084    }
085
086    public CapitalAssetBuilderAssetTransactionType getCapitalAssetTransactionType() {
087        return capitalAssetTransactionType = (CapitalAssetBuilderAssetTransactionType) SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CapitalAssetBuilderAssetTransactionType.class).retrieveExternalizableBusinessObjectIfNecessary(this, capitalAssetTransactionType, PurapPropertyConstants.ITEM_CAPITAL_ASSET_TRANSACTION_TYPE);
088    }
089
090    public CapitalAssetSystem getPurchasingCapitalAssetSystem() {
091        return purchasingCapitalAssetSystem;
092    }
093
094    public void setPurchasingCapitalAssetSystem(CapitalAssetSystem purchasingCapitalAssetSystem) {
095        this.purchasingCapitalAssetSystem = purchasingCapitalAssetSystem;
096    }
097
098    public PurchasingDocument getPurchasingDocument() {
099        if (ObjectUtils.isNull(this.purchasingDocument)) {
100            this.refreshReferenceObject("purchasingDocument");
101        }
102
103        return this.purchasingDocument;
104    }
105
106    public void setPurchasingDocument(PurchasingDocument pd) {
107        this.purchasingDocument = pd;
108    }
109
110    public PurchasingItem getPurchasingItem() {
111        PurchasingDocument pd = this.getPurchasingDocument();
112
113        if ((pd != null) && (this.getItemIdentifier() != null)) {
114            return pd.getPurchasingItem(this.getItemIdentifier());
115        } else {
116            return null;
117        }
118    }
119
120    public boolean isEmpty() {
121        if (this.getPurchasingDocument().getCapitalAssetSystemTypeCode().equals(PurapConstants.CapitalAssetSystemTypes.INDIVIDUAL)) {
122            return !(StringUtils.isNotEmpty(capitalAssetTransactionTypeCode) || !this.getPurchasingCapitalAssetSystem().isEmpty());
123        } else {
124            return !(StringUtils.isNotEmpty(capitalAssetTransactionTypeCode) || !this.getPurchasingDocument().getPurchasingCapitalAssetSystems().get(0).isEmpty());
125        }
126    }
127
128    public void setNewPurchasingItemCapitalAssetLine(ItemCapitalAsset newItemCapitalAssetLine) {
129        this.newPurchasingItemCapitalAssetLine = newItemCapitalAssetLine;
130    }
131
132    public ItemCapitalAsset getNewPurchasingItemCapitalAssetLine() {
133        return newPurchasingItemCapitalAssetLine;
134    }
135
136    public ItemCapitalAsset getAndResetNewPurchasingItemCapitalAssetLine() {
137        ItemCapitalAsset asset = getNewPurchasingItemCapitalAssetLine();
138        setNewPurchasingItemCapitalAssetLine(setupNewPurchasingItemCapitalAssetLine());
139        return asset;
140    }
141
142    public ItemCapitalAsset setupNewPurchasingItemCapitalAssetLine() {
143        ItemCapitalAsset asset = null;
144        return asset;
145    }
146
147    protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
148        LinkedHashMap m = new LinkedHashMap();
149        m.put("capitalAssetItemIdentifier", this.capitalAssetItemIdentifier);
150        return m;
151    }
152
153}