1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.fp.businessobject.format;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.sys.OLEConstants;
20  import org.kuali.ole.sys.OLEKeyConstants;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.rice.core.api.config.property.ConfigurationService;
23  import org.kuali.rice.core.web.format.Formatter;
24  
25  public class CashDrawerStatusCodeFormatter extends Formatter {
26      private final String CLOSED_CD;
27      private final String CLOSED_MSG;
28  
29      private final String OPEN_CD;
30      private final String OPEN_MSG;
31  
32      private final String LOCKED_CD;
33      private final String LOCKED_MSG;
34  
35      public CashDrawerStatusCodeFormatter() {
36          CLOSED_CD = OLEConstants.CashDrawerConstants.STATUS_CLOSED;
37          CLOSED_MSG = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashDrawer.CASH_DRAWER_STATUS_CLOSED);
38  
39          OPEN_CD = OLEConstants.CashDrawerConstants.STATUS_OPEN;
40          OPEN_MSG = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashDrawer.CASH_DRAWER_STATUS_OPEN);
41  
42          LOCKED_CD = OLEConstants.CashDrawerConstants.STATUS_LOCKED;
43          LOCKED_MSG = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.CashDrawer.CASH_DRAWER_STATUS_LOCKED);
44      }
45  
46  
47      
48  
49  
50      protected Object convertToObject(String target) {
51          Object result = target;
52  
53          if (target instanceof String) {
54              String message = (String) target;
55  
56              if (StringUtils.equals(message, OPEN_MSG)) {
57                  result = OPEN_CD;
58              }
59              else if (StringUtils.equals(message, CLOSED_MSG)) {
60                  result = CLOSED_CD;
61              }
62              else if (StringUtils.equals(message, LOCKED_MSG)) {
63                  result = LOCKED_CD;
64              }
65          }
66  
67          return result;
68      }
69  
70      
71  
72  
73      public Object format(Object value) {
74          Object formatted = value;
75  
76          if (value instanceof String) {
77              String statusCode = (String) value;
78  
79              if (StringUtils.equals(statusCode, CLOSED_CD)) {
80                  formatted = CLOSED_MSG;
81              }
82              else if (StringUtils.equals(statusCode, OPEN_CD)) {
83                  formatted = OPEN_MSG;
84              }
85              else if (StringUtils.equals(statusCode, LOCKED_CD)) {
86                  formatted = LOCKED_MSG;
87              }
88          }
89  
90          return formatted;
91      }
92  
93  }