private String setupAddOrEditForOneList(
      String masterConstant, String configurationConstant, String listName, String addOrEdit)
      throws SystemException, ApplicationException {
    MasterPersistence masterPersistence = new MasterPersistence();
    CustomValueDto valueList = masterPersistence.getLookUpEntity(masterConstant, DEFAULT_LOCALE);
    Short valueListId = valueList.getEntityId();
    CustomValueListElementDto valueListElement = valueList.getCustomValueListElements().get(0);

    addRequestParameter(ConfigurationConstants.ENTITY, configurationConstant);
    addRequestParameter(ConfigurationConstants.ADD_OR_EDIT, addOrEdit);
    SessionUtils.setAttribute(configurationConstant, valueListId, request);

    String originalName = "";

    if (addOrEdit.equals(ADD)) {
      CustomValueListElementDto newValueListElement = new CustomValueListElementDto();
      newValueListElement.setLookupValue(NEW_ELEMENT_NAME);
      String[] changesList = {
        MifosValueList.mapAddedCustomValueListElementToString(newValueListElement)
      };
      addRequestParameter(listName, changesList);
    } else { // edit
      originalName = valueListElement.getLookUpValue();
      valueListElement.setLookupValue(UPDATE_NAME);
      String[] changesList = {
        MifosValueList.mapUpdatedCustomValueListElementToString(valueListElement)
      };
      addRequestParameter(listName, changesList);
    }

    return originalName;
  }
 /**
  * Verify that the name of the first element has been changed, restore the original name, then
  * verify that an element was added to the list, then remove it to leave the list in its original
  * state.
  */
 private void verifyOneListAndRestoreOriginalValues(
     String masterConstant, String configurationConstant, String listName, String originalName)
     throws SystemException, ApplicationException {
   MasterPersistence masterPersistence = new MasterPersistence();
   CustomValueDto valueList = masterPersistence.getLookUpEntity(masterConstant, DEFAULT_LOCALE);
   List<CustomValueListElementDto> elementList = valueList.getCustomValueListElements();
   // compare the updated element
   CustomValueListElementDto valueListElement = elementList.get(0);
   Assert.assertEquals(UPDATE_NAME, valueListElement.getLookUpValue());
   // restore the original name
   masterPersistence.updateValueListElementForLocale(valueListElement.getLookUpId(), originalName);
   // compare the added element
   valueListElement = elementList.get(elementList.size() - 1);
   Assert.assertEquals(NEW_ELEMENT_NAME, valueListElement.getLookUpValue());
   // remove the added element from the list
   masterPersistence.deleteValueListElement(Integer.valueOf(valueListElement.getLookUpId()));
 }
  private String prepareForUpdate(
      String masterConstant,
      String configurationConstant,
      String listName,
      String addOrEdit,
      LookupOptionData data,
      String nameString)
      throws SystemException, ApplicationException {
    MasterPersistence masterPersistence = new MasterPersistence();
    CustomValueDto valueList = masterPersistence.getLookUpEntity(masterConstant, DEFAULT_LOCALE);
    Short valueListId = valueList.getEntityId();
    CustomValueListElementDto valueListElement = valueList.getCustomValueListElements().get(0);
    CustomValueListElementDto valueListElement1 = valueList.getCustomValueListElements().get(1);

    data.setValueListId(valueListId);

    String originalName = "";

    if (addOrEdit.equals(ADD)) {
      data.setLookupId(0);
    } else { // edit
      data.setLookupId(valueListElement.getLookUpId());

      originalName = valueListElement.getLookUpValue();
    }

    LookupOptionsActionForm form = new LookupOptionsActionForm();

    // if the name string is DUPLACATE, then set the name to the name of the
    // second element in the list (if it exists) to generate a duplicate
    // error
    if (nameString.equals(DUPLICATE) && valueListElement1 != null) {
      form.setLookupValue(valueListElement1.getLookUpValue());
    } else {
      form.setLookupValue(nameString);
    }
    form.setOneList(configurationConstant, valueList.getCustomValueListElements());
    setActionForm(form);

    return originalName;
  }