1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.pdf;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.businessobject.PurchaseOrderContractLanguage;
21 import org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorQuote;
22 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23 import org.kuali.ole.module.purap.exception.PurapConfigurationException;
24 import org.kuali.ole.module.purap.service.ImageService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEPropertyConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.service.impl.OleParameterConstants;
29 import org.kuali.ole.vnd.businessobject.CampusParameter;
30 import org.kuali.rice.core.api.config.property.ConfigurationService;
31 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32 import org.kuali.rice.krad.service.BusinessObjectService;
33
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37
38
39
40
41 public class PurchaseOrderTransmitParameters implements PurchaseOrderParameters {
42
43 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderTransmitParameters.class);
44
45 private String imageTempLocation;
46 private String key;
47 private String logoImage;
48 private String directorSignatureImage;
49 private String contractManagerSignatureImage;
50 private CampusParameter campusParameter;
51 private String statusInquiryUrl;
52 private String contractLanguage;
53 private String contractManagerCampusCode;
54 private boolean useImage;
55
56
57 private String pdfFileLocation;
58 private String pdfFileName;
59
60
61 String recipientFaxNumber;
62 String vendorName;
63 String faxDescription;
64
65 public PurchaseOrderTransmitParameters() {
66
67 }
68
69 @Override
70 public void setPurchaseOrderPdfParameters(PurchaseOrderDocument po) {
71 setPurchaseOrderPdfParameters(po, null);
72 }
73
74 @Override
75 public void setPurchaseOrderPdfParameters(PurchaseOrderDocument po, PurchaseOrderVendorQuote povq) {
76
77
78 this.key = povq == null ? po.getPurapDocumentIdentifier().toString() : po.getPurapDocumentIdentifier().toString() + povq.getPurchaseOrderVendorQuoteIdentifier().toString();
79 String campusCode = po.getDeliveryCampusCode().toLowerCase();
80 boolean useImage = true;
81 if (SpringContext.getBean(ParameterService.class).parameterExists(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
82 useImage = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
83 }
84
85
86 if (useImage) {
87 if (getImageTempLocation() == null) {
88 throw new PurapConfigurationException("IMAGE_TEMP_PATH is missing");
89 }
90
91
92 if ((this.logoImage = SpringContext.getBean(ImageService.class).getLogo(key, campusCode, imageTempLocation)) == null) {
93 throw new PurapConfigurationException("logoImage is null.");
94 }
95 if ((this.directorSignatureImage = SpringContext.getBean(ImageService.class).getPurchasingDirectorImage(key, campusCode, imageTempLocation)) == null) {
96 throw new PurapConfigurationException("directorSignatureImage is null.");
97 }
98 if ((this.contractManagerSignatureImage = SpringContext.getBean(ImageService.class).getContractManagerImage(key, po.getContractManagerCode(), imageTempLocation)) == null) {
99 throw new PurapConfigurationException("contractManagerSignatureImage is null.");
100 }
101 }
102
103 Map<String, Object> criteria = new HashMap<String, Object>();
104 criteria.put(OLEPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
105 this.campusParameter = ((List<CampusParameter>) SpringContext.getBean(BusinessObjectService.class).findMatching(CampusParameter.class, criteria)).get(0);
106
107 if (getStatusInquiryUrl() == null) {
108 LOG.debug("generatePurchaseOrderPdf() ended");
109 throw new PurapConfigurationException("Application Setting INVOICE_STATUS_INQUIRY_URL is missing.");
110 }
111
112 StringBuffer contractLanguage = new StringBuffer();
113 criteria.put(OLEPropertyConstants.ACTIVE, true);
114 List<PurchaseOrderContractLanguage> contractLanguageList = (List<PurchaseOrderContractLanguage>) (SpringContext.getBean(BusinessObjectService.class).findMatching(PurchaseOrderContractLanguage.class, criteria));
115 if (!contractLanguageList.isEmpty()) {
116 int lineNumber = 1;
117 for (PurchaseOrderContractLanguage row : contractLanguageList) {
118 if (row.getCampusCode().equals(po.getDeliveryCampusCode())) {
119 contractLanguage.append(lineNumber + " " + row.getPurchaseOrderContractLanguageDescription() + "\n");
120 ++lineNumber;
121 }
122 }
123 }
124
125 this.contractLanguage = contractLanguage.toString();
126
127 if (getPdfFileLocation() == null) {
128 LOG.debug("savePurchaseOrderPdf() ended");
129 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
130 }
131
132 String environment = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.ENVIRONMENT_KEY);
133
134 this.pdfFileName = povq != null ? "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_Quote" + povq.getPurchaseOrderVendorQuoteIdentifier().toString() + "_" + environment + "_" + System.currentTimeMillis() + ".pdf" :
135 "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_" + environment + "_" + System.currentTimeMillis() + ".pdf";
136
137
138 this.contractManagerCampusCode = po.getContractManager().getContractManagerPerson() != null ? po.getContractManager().getContractManagerPerson().getCampusCode() : "";
139 this.contractLanguage = contractLanguage.toString();
140
141 }
142
143
144 @Override
145 public void setPurchaseOrderFaxParameters(PurchaseOrderDocument po, PurchaseOrderVendorQuote povq) {
146
147
148 if (getPdfFileLocation() == null) {
149 LOG.debug("savePurchaseOrderPdf() ended");
150 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
151 }
152
153
154 this.pdfFileName = povq != null ? "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_Quote" + povq.getPurchaseOrderVendorQuoteIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf" :
155 "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf";
156
157
158 this.faxDescription = povq != null ? "PO: " + po.getPurapDocumentIdentifier() + " Quote ID: " + povq.getPurchaseOrderVendorQuoteIdentifier() :
159 "PO: " + po.getPurapDocumentIdentifier() + " Cntrct Mgr: " + po.getContractManager().getContractManagerCode();
160
161 String productionEnvironmentCode = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.PROD_ENVIRONMENT_CODE_KEY);
162 String environmentCode = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.ENVIRONMENT_KEY);
163
164 if (!StringUtils.equals(productionEnvironmentCode, environmentCode)) {
165 this.faxDescription = environmentCode + " TEST - " + this.faxDescription;
166 }
167
168 this.vendorName = povq != null ? povq.getVendorName() : po.getVendorName();
169
170
171 }
172
173
174 @Override
175 public void setPurchaseOrderPdfAndFaxParameters(PurchaseOrderDocument po) {
176 setPurchaseOrderPdfAndFaxParameters(po, null);
177 }
178
179 @Override
180 public void setPurchaseOrderPdfAndFaxParameters(PurchaseOrderDocument po, PurchaseOrderVendorQuote povq) {
181
182 this.key = povq == null ? po.getPurapDocumentIdentifier().toString() : po.getPurapDocumentIdentifier().toString() + povq.getPurchaseOrderVendorQuoteIdentifier().toString();
183 String campusCode = po.getDeliveryCampusCode().toLowerCase();
184
185
186
187
188 boolean useImage = true;
189 if (SpringContext.getBean(ParameterService.class).parameterExists(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
190 useImage = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
191 }
192
193
194 if (useImage) {
195 if (getImageTempLocation() == null) {
196 throw new PurapConfigurationException("IMAGE_TEMP_PATH is missing");
197 }
198
199
200 if ((this.logoImage = SpringContext.getBean(ImageService.class).getLogo(key, campusCode, imageTempLocation)) == null) {
201 throw new PurapConfigurationException("logoImage is null.");
202 }
203 if ((this.directorSignatureImage = SpringContext.getBean(ImageService.class).getPurchasingDirectorImage(key, campusCode, imageTempLocation)) == null) {
204 throw new PurapConfigurationException("directorSignatureImage is null.");
205 }
206 if ((this.contractManagerSignatureImage = SpringContext.getBean(ImageService.class).getContractManagerImage(key, po.getContractManagerCode(), imageTempLocation)) == null) {
207 throw new PurapConfigurationException("contractManagerSignatureImage is null.");
208 }
209 }
210
211 Map<String, Object> criteria = new HashMap<String, Object>();
212 criteria.put(OLEPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
213 this.campusParameter = ((List<CampusParameter>) SpringContext.getBean(BusinessObjectService.class).findMatching(CampusParameter.class, criteria)).get(0);
214
215 if (getStatusInquiryUrl() == null) {
216 LOG.debug("generatePurchaseOrderPdf() ended");
217 throw new PurapConfigurationException("Application Setting INVOICE_STATUS_INQUIRY_URL is missing.");
218 }
219
220 StringBuffer contractLanguage = new StringBuffer();
221 criteria.put(OLEPropertyConstants.ACTIVE, true);
222 List<PurchaseOrderContractLanguage> contractLanguageList = (List<PurchaseOrderContractLanguage>) (SpringContext.getBean(BusinessObjectService.class).findMatching(PurchaseOrderContractLanguage.class, criteria));
223 if (!contractLanguageList.isEmpty()) {
224 int lineNumber = 1;
225 for (PurchaseOrderContractLanguage row : contractLanguageList) {
226 if (row.getCampusCode().equals(po.getDeliveryCampusCode())) {
227 contractLanguage.append(lineNumber + " " + row.getPurchaseOrderContractLanguageDescription() + "\n");
228 ++lineNumber;
229 }
230 }
231 }
232
233 this.contractLanguage = contractLanguage.toString();
234
235 if (getPdfFileLocation() == null) {
236 LOG.debug("savePurchaseOrderPdf() ended");
237 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
238 }
239
240 this.pdfFileName = povq != null ? "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_Quote" + povq.getPurchaseOrderVendorQuoteIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf" :
241 "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf";
242
243
244 this.contractManagerCampusCode = po.getContractManager().getContractManagerPerson() != null ? po.getContractManager().getContractManagerPerson().getCampusCode() : "";
245
246
247
248 this.faxDescription = povq != null ? "PO: " + po.getPurapDocumentIdentifier() + " Quote ID: " + povq.getPurchaseOrderVendorQuoteIdentifier() :
249 "PO: " + po.getPurapDocumentIdentifier() + " Cntrct Mgr: " + po.getContractManager().getContractManagerCode();
250
251 String productionEnvironmentCode = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.PROD_ENVIRONMENT_CODE_KEY);
252 String environmentCode = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.ENVIRONMENT_KEY);
253
254 if (!StringUtils.equals(productionEnvironmentCode, environmentCode)) {
255 this.faxDescription = environmentCode + " TEST - " + this.faxDescription;
256 }
257
258 this.vendorName = povq != null ? povq.getVendorName() : po.getVendorName();
259 this.recipientFaxNumber = povq == null ? po.getVendorFaxNumber() : povq.getVendorFaxNumber();
260
261
262 }
263
264
265 public String getContractManagerCampusCode() {
266 return contractManagerCampusCode;
267 }
268
269 public void setContractManagerCampusCode(String contractManagerCampusCode) {
270 this.contractManagerCampusCode = contractManagerCampusCode;
271 }
272
273 public String getPdfFileName() {
274 return pdfFileName;
275 }
276
277 public void setPdfFileName(String pdfFileName) {
278 this.pdfFileName = pdfFileName;
279 }
280
281 public String getPdfFileLocation() {
282 if (pdfFileLocation == null) {
283 pdfFileLocation = SpringContext.getBean(ParameterService.class).getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_DIRECTORY);
284 }
285 return pdfFileLocation;
286 }
287
288 public void setPdfFileLocation(String pdfFileLocation) {
289 this.pdfFileLocation = pdfFileLocation;
290 }
291
292 public CampusParameter getCampusParameter() {
293 return campusParameter;
294 }
295
296 public void setCampusParameter(CampusParameter campusParameter) {
297 this.campusParameter = campusParameter;
298 }
299
300 public String getContractLanguage() {
301 return contractLanguage;
302 }
303
304 public void setContractLanguage(String contractLanguage) {
305 this.contractLanguage = contractLanguage;
306 }
307
308 public String getContractManagerSignatureImage() {
309 return contractManagerSignatureImage;
310 }
311
312 public void setContractManagerSignatureImage(String contractManagerSignatureImage) {
313 this.contractManagerSignatureImage = contractManagerSignatureImage;
314 }
315
316 public String getDirectorSignatureImage() {
317 return directorSignatureImage;
318 }
319
320 public void setDirectorSignatureImage(String directorSignatureImage) {
321 this.directorSignatureImage = directorSignatureImage;
322 }
323
324 public String getImageTempLocation() {
325 if (imageTempLocation == null) {
326 imageTempLocation = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.TEMP_DIRECTORY_KEY) + "/";
327 }
328 return imageTempLocation;
329 }
330
331 public void setImageTempLocation(String imageTempLocation) {
332 this.imageTempLocation = imageTempLocation;
333 }
334
335 public String getKey() {
336 return key;
337 }
338
339 public void setKey(String key) {
340 this.key = key;
341 }
342
343 public String getLogoImage() {
344 return logoImage;
345 }
346
347 public void setLogoImage(String logoImage) {
348 this.logoImage = logoImage;
349 }
350
351 public String getStatusInquiryUrl() {
352 if (statusInquiryUrl == null) {
353 statusInquiryUrl = SpringContext.getBean(ParameterService.class).getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.STATUS_INQUIRY_URL);
354 }
355 return statusInquiryUrl;
356 }
357
358 public void setStatusInquiryUrl(String statusInquiryUrl) {
359 this.statusInquiryUrl = statusInquiryUrl;
360 }
361
362 public boolean isUseImage() {
363 return useImage;
364 }
365
366 public void setUseImage(boolean useImage) {
367 this.useImage = useImage;
368 }
369
370 public String getRecipientFaxNumber() {
371 return recipientFaxNumber;
372 }
373
374 public void setRecipientFaxNumber(String recipientFaxNumber) {
375 this.recipientFaxNumber = recipientFaxNumber;
376 }
377
378 public String getVendorName() {
379 return vendorName;
380 }
381
382 public void setVendorName(String vendorName) {
383 this.vendorName = vendorName;
384 }
385
386 public String getFaxDescription() {
387 return faxDescription;
388 }
389
390 public void setFaxDescription(String faxDescription) {
391 this.faxDescription = faxDescription;
392 }
393
394
395 }