1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.businessobject;
17
18 import org.joda.time.DateTime;
19 import org.kuali.ole.sys.context.SpringContext;
20 import org.kuali.rice.kew.api.KewApiConstants;
21 import org.kuali.rice.kew.api.KewApiServiceLocator;
22 import org.kuali.rice.kew.api.doctype.DocumentType;
23 import org.kuali.rice.kew.api.exception.WorkflowException;
24 import org.kuali.rice.kns.service.DataDictionaryService;
25 import org.kuali.rice.krad.bo.Note;
26 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27 import org.kuali.rice.krad.datadictionary.exception.UnknownDocumentTypeException;
28 import org.kuali.rice.krad.document.Document;
29 import org.kuali.rice.krad.service.DocumentService;
30 import org.kuali.rice.krad.service.NoteService;
31 import org.kuali.rice.krad.util.KRADConstants;
32 import org.kuali.rice.krad.util.ObjectUtils;
33
34 import java.util.ArrayList;
35 import java.util.LinkedHashMap;
36 import java.util.List;
37
38
39
40
41 public abstract class AbstractRelatedView extends PersistableBusinessObjectBase {
42 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AbstractRelatedView.class);
43
44 private Integer accountsPayablePurchasingDocumentLinkIdentifier;
45 private Integer purapDocumentIdentifier;
46 private String documentNumber;
47 private String poNumberMasked;
48
49
50 private DateTime createDate;
51
52 public Integer getAccountsPayablePurchasingDocumentLinkIdentifier() {
53 return accountsPayablePurchasingDocumentLinkIdentifier;
54 }
55
56 public void setAccountsPayablePurchasingDocumentLinkIdentifier(Integer accountsPayablePurchasingDocumentLinkIdentifier) {
57 this.accountsPayablePurchasingDocumentLinkIdentifier = accountsPayablePurchasingDocumentLinkIdentifier;
58 }
59
60 public Integer getPurapDocumentIdentifier() {
61 return purapDocumentIdentifier;
62 }
63
64 public void setPurapDocumentIdentifier(Integer purapDocumentIdentifier) {
65 this.purapDocumentIdentifier = purapDocumentIdentifier;
66 }
67
68 public String getDocumentNumber() {
69 return documentNumber;
70 }
71
72 public void setDocumentNumber(String documentNumber) {
73 this.documentNumber = documentNumber;
74 }
75
76 public List<Note> getNotes() {
77 List<Note> notes = new ArrayList<Note>();
78
79 NoteService noteService = SpringContext.getBean(NoteService.class);
80 String document = findDocument(this.documentNumber).getDocumentHeader().getObjectId();
81 List<Note> tmpNotes = null;
82 if (document != null)
83 tmpNotes = noteService.getByRemoteObjectId(document);
84 notes.clear();
85
86 if (tmpNotes != null)
87 for (int i = tmpNotes.size() - 1; i >= 0; i--) {
88 Note note = tmpNotes.get(i);
89 notes.add(note);
90 }
91 return notes;
92 }
93
94 public String getUrl() {
95 String documentTypeName = this.getDocumentTypeName();
96 DocumentType docType = KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeName);
97 String docHandlerUrl = docType.getResolvedDocumentHandlerUrl();
98 int endSubString = docHandlerUrl.lastIndexOf("/");
99 String serverName = docHandlerUrl.substring(0, endSubString);
100 String handler = docHandlerUrl.substring(endSubString + 1, docHandlerUrl.lastIndexOf("?"));
101 if (handler.equals("OLEInvoice"))
102 return docHandlerUrl + "&" + KRADConstants.PARAMETER_DOC_ID + "=" + this.getDocumentNumber() + "&" + KRADConstants.PARAMETER_COMMAND + "=" + KewApiConstants.DOCSEARCH_COMMAND;
103 else
104 return serverName + "/" + KRADConstants.PORTAL_ACTION + "?channelTitle=" + docType.getName() + "&channelUrl=" + handler + "?" + KRADConstants.DISPATCH_REQUEST_PARAMETER + "=" + KRADConstants.DOC_HANDLER_METHOD + "&" + KRADConstants.PARAMETER_DOC_ID + "=" + this.getDocumentNumber() + "&" + KRADConstants.PARAMETER_COMMAND + "=" + KewApiConstants.DOCSEARCH_COMMAND;
105 }
106
107 public String getDocumentIdentifierString() {
108 if (purapDocumentIdentifier != null) {
109 return purapDocumentIdentifier.toString();
110 } else {
111 return documentNumber;
112 }
113 }
114
115
116
117
118
119
120
121
122
123 public String getDocumentLabel() throws WorkflowException {
124 return SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByTypeName(getDocumentTypeName());
125 }
126
127
128
129
130 public abstract String getDocumentTypeName();
131
132
133
134
135 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
136 LinkedHashMap m = new LinkedHashMap();
137 if (this.accountsPayablePurchasingDocumentLinkIdentifier != null) {
138 m.put("accountsPayablePurchasingDocumentLinkIdentifier", this.accountsPayablePurchasingDocumentLinkIdentifier.toString());
139 }
140 return m;
141 }
142
143
144
145
146
147
148
149 public String getPoNumberMasked() {
150 return poNumberMasked;
151 }
152
153
154
155
156
157
158 public void setPoNumberMasked(String poNumberMasked) {
159 this.poNumberMasked = poNumberMasked;
160 }
161
162 public String getApplicationDocumentStatus() {
163 Document document = findDocument(this.getDocumentNumber());
164 if (ObjectUtils.isNotNull(document)) {
165 return document.getDocumentHeader().getWorkflowDocument().getApplicationDocumentStatus();
166 }
167 return "";
168 }
169
170
171
172
173
174
175
176 protected Document findDocument(String documentHeaderId) {
177 Document document = null;
178
179 try {
180 document = SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(documentHeaderId);
181 } catch (WorkflowException ex) {
182 LOG.error("Exception encountered on finding the document: " + documentHeaderId, ex);
183 } catch (UnknownDocumentTypeException ex) {
184
185 LOG.error("Exception encountered on finding the document: " + documentHeaderId, ex);
186 }
187
188 return document;
189 }
190
191 public void setAppDocStatus(String appDocStatus) {
192 Document document = findDocument(this.getDocumentNumber());
193 if (ObjectUtils.isNotNull(document)) {
194 document.getDocumentHeader().getWorkflowDocument().setApplicationDocumentStatus(appDocStatus);
195 }
196 }
197
198
199
200
201
202
203 public DateTime getCreateDate() {
204 Document document = findDocument(this.getDocumentNumber());
205
206 return document.getDocumentHeader().getWorkflowDocument().getDateCreated();
207 }
208 }