Search in sources :

Example 1 with FeeUpdateRequest

use of org.mifos.dto.domain.FeeUpdateRequest in project head by mifos.

the class FeeAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    FeeActionForm feeActionForm = (FeeActionForm) form;
    FeeStatus feeStatus = feeActionForm.getFeeStatusValue();
    String forward = "";
    Short feeStatusValue = null;
    String whereToForward = "";
    if (feeStatus != null) {
        feeStatusValue = feeStatus.getValue();
    }
    FeeUpdateRequest feeUpdateRequest = new FeeUpdateRequest(Short.valueOf(feeActionForm.getFeeId()), feeActionForm.getCurrencyId(), feeActionForm.getAmount(), feeStatusValue, feeActionForm.getRateValue());
    if (feeUpdateRequest.getFeeStatusValue() == 2) {
        this.feeServiceFacade.updateFee(feeUpdateRequest);
        try {
            boolean remove = feeActionForm.isToRemove();
            this.feeServiceFacade.removeFee(feeUpdateRequest, remove);
            whereToForward = REMOVE_SUCCESS;
        } catch (MifosRuntimeException e) {
            ActionMessages messages = new ActionMessages();
            messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Fees.feeCannotBeRemoved"));
            saveMessages(request, messages);
            whereToForward = UPDATE_SUCCESS;
        }
    } else if (feeActionForm.isToRemove() && feeUpdateRequest.getFeeStatusValue() == 1) {
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Fees.feeCantBeRemove"));
        saveErrors(request, errors);
        whereToForward = UPDATE_FAILURE;
    } else {
        this.feeServiceFacade.updateFee(feeUpdateRequest);
        whereToForward = UPDATE_SUCCESS;
    }
    if (whereToForward.equals(UPDATE_SUCCESS)) {
        forward = ActionForwards.update_success.toString();
    } else if (whereToForward.equals(UPDATE_FAILURE)) {
        forward = ActionForwards.update_failure.toString();
    } else if (whereToForward.equals(REMOVE_SUCCESS)) {
        forward = ActionForwards.remove_fee_success.toString();
    }
    return mapping.findForward(forward);
}
Also used : FeeActionForm(org.mifos.accounts.fees.struts.actionforms.FeeActionForm) ActionMessages(org.apache.struts.action.ActionMessages) FeeUpdateRequest(org.mifos.dto.domain.FeeUpdateRequest) ActionMessage(org.apache.struts.action.ActionMessage) FeeStatus(org.mifos.accounts.fees.util.helpers.FeeStatus) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

ActionMessage (org.apache.struts.action.ActionMessage)1 ActionMessages (org.apache.struts.action.ActionMessages)1 FeeActionForm (org.mifos.accounts.fees.struts.actionforms.FeeActionForm)1 FeeStatus (org.mifos.accounts.fees.util.helpers.FeeStatus)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 FeeUpdateRequest (org.mifos.dto.domain.FeeUpdateRequest)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1