protected void logInfo(String message) { logger.info(message); }
protected void logDebug(String message) { logger.debug(message); }
public abstract class BaseCommand { private TxtResourceBundle resourceBundle = TxtResourceBundle.getInstance(); private TxtLogger logger = TxtLogger.getInstance(this.getClass().getName()); protected String getMessage(String key) { return resourceBundle.getMesage(key); } protected String replaceDynTags(String message, String dynamicKey, String dynamicValue) { return message.replace(dynamicKey, dynamicValue); } protected void logInfo(String message) { logger.info(message); } protected void logDebug(String message) { logger.debug(message); } protected String getParameter(UserRequest userRequest, int index) throws TxtException { String param = null; try { param = userRequest.getParamList().get(index).trim(); } catch (Exception e) { throw new TxtException(TxtExceptionCodes.ERROR.INVALID_COMMAND); } return param; } protected List<String> getParamterList(UserRequest userRequest, int index) throws TxtException { List<String> lstParams = new LinkedList<String>(); try { String csvParams = userRequest.getParamList().get(index); StringTokenizer tokenizer = new StringTokenizer(csvParams, ","); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken().trim(); lstParams.add(token); } } catch (Exception e) { e.printStackTrace(); throw new TxtException(TxtExceptionCodes.ERROR.INVALID_COMMAND); } return lstParams; } protected boolean checkAccess(UserRequest userRequest, ServiceCodes code) throws TxtException { User user = new UserDAO().findUserByMobileNo(userRequest.getMobileNo()); if (user == null) { throw new TxtException(TxtExceptionCodes.ERROR.USER_NOT_FOUND); } boolean isAccess = false; for (String serviceCode : user.getLstServices()) { if (code.name().equalsIgnoreCase(serviceCode)) { isAccess = true; break; } } if (!isAccess) { throw new TxtException(TxtExceptionCodes.ERROR.SERVICE_NOT_REGISTER); } return isAccess; } }