/** * Saves the configuration settings for a field * * @param settings * @param configID */ @Override public void saveSettings(Map<Integer, Object> settings, Integer configID) { List<Integer> singleValueParameterCodes = getGeneralSettingsParameterCodes(); List<Integer> multipleValueParameterCodes = getMultipleIntegerParameterCodes(); for (Integer parameterCode : settings.keySet()) { if (singleValueParameterCodes != null && singleValueParameterCodes.contains(parameterCode)) { TGeneralSettingsBean generalSettingsBean = (TGeneralSettingsBean) settings.get(parameterCode); generalSettingsBean.setConfig(configID); GeneralSettingsBL.save(generalSettingsBean); } else { if (multipleValueParameterCodes != null && multipleValueParameterCodes.contains(parameterCode)) { List<TGeneralSettingsBean> multipleParameterList = (List<TGeneralSettingsBean>) settings.get(parameterCode); if (multipleParameterList != null) { for (TGeneralSettingsBean generalSettingsBean : multipleParameterList) { generalSettingsBean.setConfig(configID); GeneralSettingsBL.save(generalSettingsBean); } } } else { LOGGER.error( "Wrong paremeterCode " + parameterCode + " by saving the general settings for congigID " + configID); } } } }
/** * Loads a map with field settings for a configID - key: parameterCode - value: * TGeneralSettingsBean or a list of TGeneralSettingsBeans * * @param configID * @return */ @Override public Map<Integer, Object> loadSettings(Integer configID) { Map<Integer, Object> settings = new HashMap<Integer, Object>(); if (configID != null) { List<Integer> singleValueParameterCodes = getGeneralSettingsParameterCodes(); List<Integer> multipleValueParameterCodes = getMultipleIntegerParameterCodes(); List<TGeneralSettingsBean> generalSettingsBeans = GeneralSettingsBL.loadByConfig(configID); for (TGeneralSettingsBean generalSettingsBean : generalSettingsBeans) { Integer parameterCode = generalSettingsBean.getParameterCode(); if (parameterCode == null) { LOGGER.error( "Null parameter code by loading the general settings for congigID " + configID); } else { if (singleValueParameterCodes != null && singleValueParameterCodes.contains(parameterCode)) { settings.put(parameterCode, generalSettingsBean); } else { if (multipleValueParameterCodes != null && multipleValueParameterCodes.contains(parameterCode)) { List multipleParameterList = (List) settings.get(parameterCode); if (multipleParameterList == null) { multipleParameterList = new LinkedList(); settings.put(parameterCode, multipleParameterList); } multipleParameterList.add(generalSettingsBean); } else { LOGGER.error( "Wrong paremeterCode " + parameterCode + " by loading the general settings for congigID " + configID); } } } } } return settings; }
/** * Helper method for copying a TGeneralSettingsBean * * @param srcGeneralSettingsBean * @param destConfigID * @return */ private static TGeneralSettingsBean copyGeneralSettingsBean( TGeneralSettingsBean srcGeneralSettingsBean, Integer destConfigID) { TGeneralSettingsBean destGeneralSettingsBean = new TGeneralSettingsBean(); destGeneralSettingsBean.setParameterCode(srcGeneralSettingsBean.getParameterCode()); destGeneralSettingsBean.setIntegerValue(srcGeneralSettingsBean.getIntegerValue()); destGeneralSettingsBean.setDoubleValue(srcGeneralSettingsBean.getDoubleValue()); destGeneralSettingsBean.setTextValue(srcGeneralSettingsBean.getTextValue()); destGeneralSettingsBean.setDateValue(srcGeneralSettingsBean.getDateValue()); destGeneralSettingsBean.setValidValue(srcGeneralSettingsBean.getValidValue()); destGeneralSettingsBean.setConfig(destConfigID); return destGeneralSettingsBean; }