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.fp.businessobject.format; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.kfs.sys.KFSConstants; 020 import org.kuali.kfs.sys.KFSKeyConstants; 021 import org.kuali.kfs.sys.context.SpringContext; 022 import org.kuali.rice.kns.service.KualiConfigurationService; 023 import org.kuali.rice.kns.web.format.Formatter; 024 025 public class CashDrawerStatusCodeFormatter extends Formatter { 026 private final String CLOSED_CD; 027 private final String CLOSED_MSG; 028 029 private final String OPEN_CD; 030 private final String OPEN_MSG; 031 032 private final String LOCKED_CD; 033 private final String LOCKED_MSG; 034 035 public CashDrawerStatusCodeFormatter() { 036 CLOSED_CD = KFSConstants.CashDrawerConstants.STATUS_CLOSED; 037 CLOSED_MSG = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashDrawer.CASH_DRAWER_STATUS_CLOSED); 038 039 OPEN_CD = KFSConstants.CashDrawerConstants.STATUS_OPEN; 040 OPEN_MSG = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashDrawer.CASH_DRAWER_STATUS_OPEN); 041 042 LOCKED_CD = KFSConstants.CashDrawerConstants.STATUS_LOCKED; 043 LOCKED_MSG = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashDrawer.CASH_DRAWER_STATUS_LOCKED); 044 } 045 046 047 /** 048 * Converts the given statusCode into a status message. 049 */ 050 protected Object convertToObject(String target) { 051 Object result = target; 052 053 if (target instanceof String) { 054 String message = (String) target; 055 056 if (StringUtils.equals(message, OPEN_MSG)) { 057 result = OPEN_CD; 058 } 059 else if (StringUtils.equals(message, CLOSED_MSG)) { 060 result = CLOSED_CD; 061 } 062 else if (StringUtils.equals(message, LOCKED_MSG)) { 063 result = LOCKED_CD; 064 } 065 } 066 067 return result; 068 } 069 070 /** 071 * Converts the given status message into a status code. 072 */ 073 public Object format(Object value) { 074 Object formatted = value; 075 076 if (value instanceof String) { 077 String statusCode = (String) value; 078 079 if (StringUtils.equals(statusCode, CLOSED_CD)) { 080 formatted = CLOSED_MSG; 081 } 082 else if (StringUtils.equals(statusCode, OPEN_CD)) { 083 formatted = OPEN_MSG; 084 } 085 else if (StringUtils.equals(statusCode, LOCKED_CD)) { 086 formatted = LOCKED_MSG; 087 } 088 } 089 090 return formatted; 091 } 092 093 }