use of org.mifos.config.util.helpers.LookupOptionData in project head by mifos.
the class LookupOptionsAction method update.
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.debug("Inside update method");
// setHiddenFields(request);
LookupOptionsActionForm lookupOptionsActionForm = (LookupOptionsActionForm) form;
LookupOptionData data = (LookupOptionData) SessionUtils.getAttribute(ConfigurationConstants.LOOKUP_OPTION_DATA, request);
data.setLookupValue(lookupOptionsActionForm.getLookupValue());
String entity = request.getParameter(ConfigurationConstants.ENTITY);
if (data.getLookupId() > 0) {
legacyMasterDao.updateValueListElementForLocale(data.getLookupId(), data.getLookupValue());
} else {
LookUpValueEntity newLookupValue = legacyMasterDao.addValueListElementForLocale(DynamicLookUpValueCreationTypes.LookUpOption, data.getValueListId(), data.getLookupValue());
/*
* Add a special case for payment types since we not only need to create a new
* lookup value but also a new PaymentTypeEntity when adding an entry
*/
if (entity.equals(ConfigurationConstants.CONFIG_PAYMENT_TYPE)) {
PaymentTypeEntity newPaymentType = new PaymentTypeEntity(newLookupValue);
legacyMasterDao.createOrUpdate(newPaymentType);
StaticHibernateUtil.commitTransaction();
}
}
return mapping.findForward(ActionForwards.update_success.toString());
}
use of org.mifos.config.util.helpers.LookupOptionData in project head by mifos.
the class LookupOptionsActionStrutsTest method testNoSelectionToEdit.
@Test
public void testNoSelectionToEdit() throws Exception {
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
setRequestPathInfo("/lookupOptionsAction.do");
addRequestParameter("method", "addEditLookupOption");
String errorNoSelection = "errors.selectvalue";
for (int listIndex = 0; listIndex < configurationNameSet.length; ++listIndex) {
flowKey = createFlow(request, LookupOptionsAction.class);
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
LookupOptionData data = new LookupOptionData();
setupNoSelectionForOneList(configurationNameSet[listIndex][MASTER_CONSTANT], configurationNameSet[listIndex][CONFIG_CONSTANT], configurationNameSet[listIndex][LIST_NAME]);
SessionUtils.setAttribute(ConfigurationConstants.LOOKUP_OPTION_DATA, data, request);
actionPerform();
String[] errorMessages = { errorNoSelection };
verifyActionErrors(errorMessages);
verifyInputForward();
}
}
use of org.mifos.config.util.helpers.LookupOptionData in project head by mifos.
the class LookupOptionsAction method addEditLookupOption.
@TransactionDemarcate(joinToken = true)
public ActionForward addEditLookupOption(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
LookupOptionsActionForm lookupOptionsActionForm = (LookupOptionsActionForm) form;
String entity = request.getParameter(ConfigurationConstants.ENTITY);
String addOrEdit = request.getParameter(ConfigurationConstants.ADD_OR_EDIT);
LookupOptionData data = new LookupOptionData();
boolean setLookupData = setLookupOptionData(entity, data, request, addOrEdit, lookupOptionsActionForm);
if (setLookupData) {
SessionUtils.setAttribute(ConfigurationConstants.LOOKUP_OPTION_DATA, data, request);
return mapping.findForward(ActionForwards.addEditLookupOption_success.toString());
}
return mapping.findForward(ActionForwards.addEditLookupOption_failure.toString());
}
use of org.mifos.config.util.helpers.LookupOptionData in project head by mifos.
the class LookupOptionsActionStrutsTest method testUpdate.
@Test
public void testUpdate() throws Exception {
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
for (int listIndex = 0; listIndex < configurationNameSet.length; ++listIndex) {
String originalValue = "";
StaticHibernateUtil.getSessionTL();
for (int operationIndex = 0; operationIndex < operations.length; ++operationIndex) {
createFlowAndAddToRequest(LookupOptionsAction.class);
setRequestPathInfo("/lookupOptionsAction.do");
addRequestParameter("method", "update");
LookupOptionData data = new LookupOptionData();
originalValue = prepareForUpdate(configurationNameSet[listIndex][MASTER_CONSTANT], configurationNameSet[listIndex][CONFIG_CONSTANT], configurationNameSet[listIndex][LIST_NAME], operations[operationIndex], data, names[operationIndex]);
SessionUtils.setAttribute(ConfigurationConstants.LOOKUP_OPTION_DATA, data, request);
addRequestParameter(ConfigurationConstants.ENTITY, configurationNameSet[listIndex][CONFIG_CONSTANT]);
actionPerform();
verifyNoActionErrors();
verifyNoActionMessages();
verifyForward(ActionForwards.update_success.toString());
}
StaticHibernateUtil.flushAndClearSession();
StaticHibernateUtil.startTransaction();
verifyOneListAndRestoreOriginalValues(configurationNameSet[listIndex][MASTER_CONSTANT], configurationNameSet[listIndex][CONFIG_CONSTANT], configurationNameSet[listIndex][LIST_NAME], originalValue);
}
}
use of org.mifos.config.util.helpers.LookupOptionData in project head by mifos.
the class LookupOptionsActionStrutsTest method testBadStringUpdate.
@Test
public void testBadStringUpdate() throws Exception {
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
setRequestPathInfo("/lookupOptionsAction.do");
addRequestParameter("method", "update");
String tooShort = "";
String tooLong = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0";
ResourceBundle resources = ResourceBundle.getBundle(FilePaths.CONFIGURATION_UI_RESOURCE_PROPERTYFILE, request.getLocale());
String errorTooShort = resources.getString("errors.novalue");
String errorTooLong = resources.getString("errors.toolong");
errorTooLong = errorTooLong.replace("{0}", LookUpValueLocaleEntity.MAX_LOOKUP_VALUE_STRING_LENGTH.toString());
String errorDuplicate = "errors.duplicatevalue";
String[] names = { tooShort, tooShort, tooLong, tooLong, DUPLICATE, DUPLICATE };
String[] operations = { ADD, EDIT, ADD, EDIT, ADD, EDIT };
String[] errors = { errorTooShort, errorTooShort, errorTooLong, errorTooLong, errorDuplicate, errorDuplicate };
for (int operationIndex = 0; operationIndex < operations.length; ++operationIndex) {
flowKey = createFlow(request, LookupOptionsAction.class);
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
LookupOptionData data = new LookupOptionData();
prepareForUpdate(configurationNameSet[0][MASTER_CONSTANT], configurationNameSet[0][CONFIG_CONSTANT], configurationNameSet[0][LIST_NAME], operations[operationIndex], data, names[operationIndex]);
SessionUtils.setAttribute(ConfigurationConstants.LOOKUP_OPTION_DATA, data, request);
addRequestParameter(ConfigurationConstants.ENTITY, configurationNameSet[0][CONFIG_CONSTANT]);
actionPerform();
String[] errorMessages = { errors[operationIndex] };
verifyActionErrors(errorMessages);
verifyInputForward();
}
}
Aggregations