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.module.purap.businessobject; 017 018 import java.util.LinkedHashMap; 019 import java.util.List; 020 021 import org.kuali.kfs.sys.KFSConstants; 022 import org.kuali.kfs.sys.context.SpringContext; 023 import org.kuali.rice.kew.exception.WorkflowException; 024 import org.kuali.rice.kns.bo.Note; 025 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; 026 import org.kuali.rice.kns.service.DataDictionaryService; 027 import org.kuali.rice.kns.service.DocumentService; 028 import org.kuali.rice.kns.service.KualiConfigurationService; 029 import org.kuali.rice.kns.service.NoteService; 030 import org.kuali.rice.kns.util.TypedArrayList; 031 032 /** 033 * Base class for Related View Business Objects. 034 */ 035 public abstract class AbstractRelatedView extends PersistableBusinessObjectBase { 036 037 private Integer accountsPayablePurchasingDocumentLinkIdentifier; 038 private Integer purapDocumentIdentifier; 039 private String documentNumber; 040 041 private List<Note> notes; 042 043 public Integer getAccountsPayablePurchasingDocumentLinkIdentifier() { 044 return accountsPayablePurchasingDocumentLinkIdentifier; 045 } 046 047 public void setAccountsPayablePurchasingDocumentLinkIdentifier(Integer accountsPayablePurchasingDocumentLinkIdentifier) { 048 this.accountsPayablePurchasingDocumentLinkIdentifier = accountsPayablePurchasingDocumentLinkIdentifier; 049 } 050 051 public Integer getPurapDocumentIdentifier() { 052 return purapDocumentIdentifier; 053 } 054 055 public void setPurapDocumentIdentifier(Integer purapDocumentIdentifier) { 056 this.purapDocumentIdentifier = purapDocumentIdentifier; 057 } 058 059 public String getDocumentNumber() { 060 return documentNumber; 061 } 062 063 public void setDocumentNumber(String documentNumber) { 064 this.documentNumber = documentNumber; 065 } 066 067 public List<Note> getNotes() { 068 if (notes == null) { 069 notes = new TypedArrayList(Note.class); 070 List<Note> tmpNotes = SpringContext.getBean(NoteService.class).getByRemoteObjectId(this.getObjectId()); 071 //FIXME if NoteService returns notes in descending order (newer ones first) then remove the following 072 // reverse the order of notes retrieved so that newest note is in the front 073 for (int i = tmpNotes.size()-1; i>=0; i--) { 074 Note note = tmpNotes.get(i); 075 notes.add(note); 076 } 077 } 078 079 return notes; 080 } 081 082 public String getUrl() { 083 return SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSConstants.WORKFLOW_URL_KEY) + "/DocHandler.do?docId=" + getDocumentNumber() + "&command=displayDocSearchView"; 084 } 085 086 public String getDocumentIdentifierString() { 087 if (purapDocumentIdentifier != null) { 088 return purapDocumentIdentifier.toString(); 089 } else { 090 return documentNumber; 091 } 092 } 093 094 /** 095 * Returns the document label according to the label specified in the data dictionary. 096 * 097 * @return 098 * @throws WorkflowException 099 */ 100 public String getDocumentLabel() throws WorkflowException{ 101 Class documentClass = SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(this.getDocumentNumber()).getClass(); 102 return SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByClass(documentClass); 103 } 104 105 /** 106 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 107 */ 108 protected LinkedHashMap toStringMapper() { 109 LinkedHashMap m = new LinkedHashMap(); 110 if (this.accountsPayablePurchasingDocumentLinkIdentifier != null) { 111 m.put("accountsPayablePurchasingDocumentLinkIdentifier", this.accountsPayablePurchasingDocumentLinkIdentifier.toString()); 112 } 113 return m; 114 } 115 }