001    /*
002     * Copyright 2011 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     */
016    package org.kuali.kfs.fp.businessobject;
017    
018    import java.util.HashMap;
019    import java.util.LinkedHashMap;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.apache.commons.lang.StringUtils;
024    import org.kuali.kfs.integration.cam.CapitalAssetManagementAsset;
025    import org.kuali.kfs.integration.cam.CapitalAssetManagementAssetType;
026    import org.kuali.kfs.sys.KFSPropertyConstants;
027    import org.kuali.kfs.sys.context.SpringContext;
028    import org.kuali.kfs.vnd.businessobject.VendorDetail;
029    import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
030    import org.kuali.rice.kns.service.KualiModuleService;
031    import org.kuali.rice.kns.util.ObjectUtils;
032    import org.kuali.rice.kns.util.TypedArrayList;
033    
034    public class CapitalAssetInformation extends PersistableBusinessObjectBase {
035    
036        private String documentNumber;
037        private Integer vendorHeaderGeneratedIdentifier;
038        private Integer vendorDetailAssignedIdentifier;
039        private String vendorName;
040        private Long capitalAssetNumber;
041        private Integer capitalAssetQuantity;
042        private String capitalAssetTypeCode;
043        private String capitalAssetManufacturerName;
044        private String capitalAssetDescription;
045        private String capitalAssetManufacturerModelNumber;
046        
047    
048        private CapitalAssetManagementAsset capitalAssetManagementAsset;
049        private CapitalAssetManagementAssetType capitalAssetManagementAssetType;
050        private List<CapitalAssetInformationDetail> capitalAssetInformationDetails;
051    
052        private VendorDetail vendorDetail;
053        // non-persistent field
054        private Integer nextItemLineNumber;
055    
056        /**
057         * Constructs a CapitalAssetInformation.java.
058         */
059        public CapitalAssetInformation() {
060            super();
061            capitalAssetInformationDetails = new TypedArrayList(CapitalAssetInformationDetail.class);
062        }
063    
064        protected LinkedHashMap toStringMapper() {
065            LinkedHashMap m = new LinkedHashMap();
066    
067            m.put("documentNumber", getDocumentNumber());
068    
069            return m;
070        }
071    
072        public String getCapitalAssetDescription() {
073            return capitalAssetDescription;
074        }
075    
076        public void setCapitalAssetDescription(String capitalAssetDescription) {
077            this.capitalAssetDescription = capitalAssetDescription;
078        }
079    
080        public String getCapitalAssetManufacturerModelNumber() {
081            return capitalAssetManufacturerModelNumber;
082        }
083    
084        public void setCapitalAssetManufacturerModelNumber(String capitalAssetManufacturerModelNumber) {
085            this.capitalAssetManufacturerModelNumber = capitalAssetManufacturerModelNumber;
086        }
087    
088        public String getCapitalAssetManufacturerName() {
089            return capitalAssetManufacturerName;
090        }
091    
092        public void setCapitalAssetManufacturerName(String capitalAssetManufacturerName) {
093            this.capitalAssetManufacturerName = capitalAssetManufacturerName;
094        }
095    
096        public Long getCapitalAssetNumber() {
097            return capitalAssetNumber;
098        }
099    
100        public void setCapitalAssetNumber(Long capitalAssetNumber) {
101            this.capitalAssetNumber = capitalAssetNumber;
102        }
103    
104        public Integer getCapitalAssetQuantity() {
105            // Return capitalAssetQuantity first if it already set. Otherwise, return the size of details. If the order is reversed, the
106            // user input of quantity may be overridden.
107            if (this.capitalAssetQuantity != null) {
108                return this.capitalAssetQuantity;
109            }
110    
111            if (ObjectUtils.isNotNull(capitalAssetInformationDetails) && !capitalAssetInformationDetails.isEmpty()) {
112                return capitalAssetInformationDetails.size();
113            }
114            return null;
115        }
116    
117        public void setCapitalAssetQuantity(Integer capitalAssetQuantity) {
118            this.capitalAssetQuantity = capitalAssetQuantity;
119        }
120    
121    
122        public String getCapitalAssetTypeCode() {
123            return capitalAssetTypeCode;
124        }
125    
126        public void setCapitalAssetTypeCode(String capitalAssetTypeCode) {
127            this.capitalAssetTypeCode = capitalAssetTypeCode;
128        }
129    
130        public String getDocumentNumber() {
131            return documentNumber;
132        }
133    
134        public void setDocumentNumber(String documentNumber) {
135            this.documentNumber = documentNumber;
136        }
137    
138        public Integer getVendorDetailAssignedIdentifier() {
139            return vendorDetailAssignedIdentifier;
140        }
141    
142        public void setVendorDetailAssignedIdentifier(Integer vendorDetailedAssignedIdentifier) {
143            this.vendorDetailAssignedIdentifier = vendorDetailedAssignedIdentifier;
144        }
145    
146        public Integer getVendorHeaderGeneratedIdentifier() {
147            return vendorHeaderGeneratedIdentifier;
148        }
149    
150        public void setVendorHeaderGeneratedIdentifier(Integer vendorHeaderGeneratedIdentifier) {
151            this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
152        }
153    
154        /**
155         * Gets the capitalAssetManagementAsset attribute.
156         * 
157         * @return Returns the capitalAssetManagementAsset.
158         */
159        public CapitalAssetManagementAsset getCapitalAssetManagementAsset() {
160            capitalAssetManagementAsset = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CapitalAssetManagementAsset.class).retrieveExternalizableBusinessObjectIfNecessary(this, capitalAssetManagementAsset, KFSPropertyConstants.CAPITAL_ASSET_MANAGEMENT_ASSET);
161            return capitalAssetManagementAsset;
162        }
163    
164        /**
165         * Sets the capitalAssetManagementAsset attribute value.
166         * 
167         * @param capitalAssetManagementAsset The capitalAssetManagementAsset to set.
168         */
169        public void setCapitalAssetManagementAsset(CapitalAssetManagementAsset capitalAssetManagementAsset) {
170            this.capitalAssetManagementAsset = capitalAssetManagementAsset;
171        }
172    
173        /**
174         * Gets the capitalAssetManagementAssetType attribute.
175         * 
176         * @return Returns the capitalAssetManagementAssetType.
177         */
178        public CapitalAssetManagementAssetType getCapitalAssetManagementAssetType() {
179            capitalAssetManagementAssetType = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CapitalAssetManagementAssetType.class).retrieveExternalizableBusinessObjectIfNecessary(this, capitalAssetManagementAssetType, KFSPropertyConstants.CAPITAL_ASSET_MANAGEMENT_ASSET_TYPE);
180            return capitalAssetManagementAssetType;
181        }
182    
183        /**
184         * Sets the capitalAssetManagementAssetType attribute value.
185         * 
186         * @param capitalAssetManagementAssetType The capitalAssetManagementAssetType to set.
187         */
188        @Deprecated
189        public void setCapitalAssetManagementAssetType(CapitalAssetManagementAssetType capitalAssetManagementAssetType) {
190            this.capitalAssetManagementAssetType = capitalAssetManagementAssetType;
191        }
192    
193        /**
194         * Gets the vendorDetail attribute.
195         * 
196         * @return Returns the vendorDetail.
197         */
198        public VendorDetail getVendorDetail() {
199            return vendorDetail;
200        }
201    
202        /**
203         * Sets the vendorDetail attribute value.
204         * 
205         * @param vendorDetail The vendorDetail to set.
206         */
207        @Deprecated
208        public void setVendorDetail(VendorDetail vendorDetail) {
209            this.vendorDetail = vendorDetail;
210        }
211    
212        /**
213         * Returns a map with the primitive field names as the key and the primitive values as the map value.
214         * 
215         * @return Map a map with the primitive field names as the key and the primitive values as the map value.
216         */
217        public Map<String, Object> getValuesMap() {
218            Map<String, Object> simpleValues = new HashMap<String, Object>();
219    
220            simpleValues.put(KFSPropertyConstants.DOCUMENT_NUMBER, this.getDocumentNumber());
221            simpleValues.put(KFSPropertyConstants.VENDOR_HEADER_GENERATED_ID, this.getVendorHeaderGeneratedIdentifier());
222            simpleValues.put(KFSPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, this.getVendorDetailAssignedIdentifier());
223            simpleValues.put(KFSPropertyConstants.VENDOR_NAME, this.getVendorName());
224            simpleValues.put(KFSPropertyConstants.CAPITAL_ASSET_NUMBER, this.getCapitalAssetNumber());
225            simpleValues.put(KFSPropertyConstants.CAPITAL_ASSET_TYPE_CODE, this.getCapitalAssetTypeCode());
226    
227            return simpleValues;
228        }
229    
230        /**
231         * Gets the vendorName attribute.
232         * 
233         * @return Returns the vendorName.
234         */
235        public String getVendorName() {
236            if (ObjectUtils.isNotNull(vendorDetail)) {
237                vendorName = vendorDetail.getVendorName();
238            }
239            else if (StringUtils.isNotBlank(vendorName) && vendorName.indexOf(" > ") > 0){
240                    vendorName = vendorName.substring(vendorName.indexOf(" > ") + 2, vendorName.length());
241            }
242    
243            return vendorName;
244        }
245    
246        /**
247         * Sets the vendorName attribute value.
248         * 
249         * @param vendorName The vendorName to set.
250         */
251        public void setVendorName(String vendorName) {
252            this.vendorName = vendorName;
253        }
254    
255        /**
256         * Gets the capitalAssetInformationDetails attribute.
257         * 
258         * @return Returns the capitalAssetInformationDetails.
259         */
260        public List<CapitalAssetInformationDetail> getCapitalAssetInformationDetails() {
261            return capitalAssetInformationDetails;
262        }
263    
264        /**
265         * Sets the capitalAssetInformationDetails attribute value.
266         * 
267         * @param capitalAssetInformationDetails The capitalAssetInformationDetails to set.
268         */
269        public void setCapitalAssetInformationDetails(List<CapitalAssetInformationDetail> capitalAssetInformationDetails) {
270            this.capitalAssetInformationDetails = capitalAssetInformationDetails;
271        }
272    
273        /**
274         * Gets the nextItemLineNumber attribute. 
275         * @return Returns the nextItemLineNumber.
276         */
277        public Integer getNextItemLineNumber() {
278            return nextItemLineNumber;
279        }
280    
281        /**
282         * Sets the nextItemLineNumber attribute value.
283         * @param nextItemLineNumber The nextItemLineNumber to set.
284         */
285        public void setNextItemLineNumber(Integer nextItemLineNumber) {
286            this.nextItemLineNumber = nextItemLineNumber;
287        }
288        
289        
290    }