1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.module.purap.service.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.kuali.ole.module.purap.PurapConstants;
22  import org.kuali.ole.module.purap.document.ContractManagerAssignmentDocument;
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.service.impl.OleParameterConstants;
27  import org.kuali.rice.core.api.config.property.ConfigurationService;
28  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
29  
30  import java.text.DecimalFormat;
31  import java.text.NumberFormat;
32  
33  
34  
35  
36  public class ImageServiceImpl implements ImageService {
37      private static Log LOG = LogFactory.getLog(ImageServiceImpl.class);
38  
39      private ConfigurationService configurationService;
40      private ParameterService parameterService;
41  
42      public void setParameterService(ParameterService parameterService) {
43          this.parameterService = parameterService;
44      }
45  
46      public void setConfigurationService(ConfigurationService configurationService) {
47          this.configurationService = configurationService;
48      }
49  
50      
51  
52  
53      public String getPurchasingDirectorImage(String key, String campusCode, String location) {
54          LOG.debug("getPurchasingDirectorImage() started");
55  
56          String prefix = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PURCHASING_DIRECTOR_IMAGE_PREFIX);
57          String extension = "." + parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PURCHASING_DIRECTOR_IMAGE_EXTENSION);
58          return getFile(prefix, campusCode, key, extension, location);
59      }
60  
61      
62  
63  
64      public String getContractManagerImage(String key, Integer contractManagerId, String location) {
65          LOG.debug("getContractManagerImage() started");
66  
67          NumberFormat formatter = new DecimalFormat("00");
68          String cm = formatter.format(contractManagerId);
69  
70          String prefix = parameterService.getParameterValueAsString(ContractManagerAssignmentDocument.class, PurapConstants.CONTRACT_MANAGER_IMAGE_PREFIX);
71          String extension = "." + parameterService.getParameterValueAsString(ContractManagerAssignmentDocument.class, PurapConstants.CONTRACT_MANAGER_IMAGE_EXTENSION);
72          return getFile(prefix, cm, key, extension, location);
73      }
74  
75      
76  
77  
78      public String getLogo(String key, String campusCode, String location) {
79          if (LOG.isDebugEnabled()) {
80              LOG.debug("getLogo() started. key is " + key + ". campusCode is " + campusCode);
81          }
82  
83          String prefix = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.LOGO_IMAGE_PREFIX);
84          String extension = "." + parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.LOGO_IMAGE_EXTENSION);
85          return getFile(prefix, campusCode, key, extension, location);
86      }
87  
88      
89  
90  
91  
92  
93  
94  
95  
96  
97      protected String getFile(String prefix, String fileKey, String key, String extension, String location) {
98          LOG.debug("getFile() started");
99  
100         
101         String urlpath = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGE_LOCATION_URL);
102         
103         if (StringUtils.isEmpty(urlpath)) {
104             urlpath = configurationService.getPropertyValueAsString(OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY);
105         }
106 
107         if (urlpath == null) {
108             throw new PurapConfigurationException("Application Setting " + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + " is missing");
109         }
110         if (location == null) {
111             throw new PurapConfigurationException("Valid location to store temp image files was null");
112         }
113 
114         String completeUrl = urlpath + prefix + "_" + fileKey.toLowerCase() + extension;
115         if (LOG.isDebugEnabled()) {
116             LOG.debug("getFile() URL = " + completeUrl);
117         }
118         return completeUrl;
119     }
120 
121 }