Search in sources :

Example 1 with CollectionSheetErrorsDto

use of org.mifos.application.servicefacade.CollectionSheetErrorsDto in project head by mifos.

the class CollectionSheetEntryAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws PageExpiredException {
    logTrackingInfo("create", request, form);
    final BulkEntryActionForm collectionSheetActionForm = (BulkEntryActionForm) form;
    final CollectionSheetEntryGridDto previousCollectionSheetEntryDto = retrieveFromRequestCollectionSheetEntryDto(request);
    final CollectionSheetEntryDecomposedDto decomposedViews = new CollectionSheetEntryViewTranslator().toDecomposedView(previousCollectionSheetEntryDto.getBulkEntryParent());
    logBeforeSave(request, collectionSheetActionForm, previousCollectionSheetEntryDto);
    final long beforeSaveData = System.currentTimeMillis();
    final CollectionSheetErrorsDto collectionSheetErrors = this.collectionSheetServiceFacade.saveCollectionSheet(previousCollectionSheetEntryDto, getUserContext(request).getId());
    logAfterSave(request, decomposedViews, System.currentTimeMillis() - beforeSaveData, collectionSheetErrors.isDatabaseError());
    storeOnRequestErrorAndCollectionSheetData(request, decomposedViews, collectionSheetErrors);
    request.setAttribute(CollectionSheetEntryConstants.CENTER, previousCollectionSheetEntryDto.getBulkEntryParent().getCustomerDetail().getDisplayName());
    setErrorMessagesIfErrorsExist(request, collectionSheetErrors);
    /*
         * Visit CREATESUCCESS if user entered data that breaks business rules, such as withdrawing more than the total
         * amount in a savings account. Is this intended? It seems like we wouldn't want to even call
         * saveCollectionSheet if business rules were violated in this manner.
         *
         * JohnW: Yes it is intended. The collection sheet logic 'does what it can' in terms of updating accounts. It
         * allows for accounts with no issues to be persisted while building up error lists (warning lists really) for
         * accounts that have problems (including breaking business rules) preventing them being persisted.
         *
         * So, in summary, what happens is, although "saveCollectionSheet" is called, part of the responsibility of the
         * "saveCollectionSheet" process is to identify for each account if rules are broken. Only accounts that 'pass'
         * are saved, the others are identified so that a warning message can be shown.
         */
    return mapping.findForward(CollectionSheetEntryConstants.CREATESUCCESS);
}
Also used : BulkEntryActionForm(org.mifos.application.collectionsheet.struts.actionforms.BulkEntryActionForm) CollectionSheetEntryDecomposedDto(org.mifos.application.servicefacade.CollectionSheetEntryDecomposedDto) CollectionSheetErrorsDto(org.mifos.application.servicefacade.CollectionSheetErrorsDto) CollectionSheetEntryViewTranslator(org.mifos.application.servicefacade.CollectionSheetEntryViewTranslator) CollectionSheetEntryGridDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with CollectionSheetErrorsDto

use of org.mifos.application.servicefacade.CollectionSheetErrorsDto in project head by mifos.

the class CollectionSheetRESTController method saveCollectionSheet.

@RequestMapping(value = "/collectionsheet/save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> saveCollectionSheet(@RequestBody JSONSaveCollectionsheet request) throws Throwable {
    Map<String, Object> map = new HashMap<String, Object>();
    ObjectMapper om = createObjectMapper();
    List<InvalidSaveCollectionSheetReason> reasons = new ArrayList<InvalidSaveCollectionSheetReason>();
    CollectionSheetErrorsDto errors = null;
    SaveCollectionSheetDto saveCollectionSheetDto = null;
    try {
        saveCollectionSheetDto = om.readValue(request.getJson(), SaveCollectionSheetDto.class);
    } catch (JsonMappingException e) {
        if (e.getCause() instanceof SaveCollectionSheetException) {
            reasons.addAll(((SaveCollectionSheetException) e.getCause()).getInvalidSaveCollectionSheetReasons());
        } else {
            throw e.getCause();
        }
    }
    if (saveCollectionSheetDto != null) {
        try {
            errors = collectionSheetServiceFacade.saveCollectionSheet(saveCollectionSheetDto);
            map.put("errors", errors != null ? errors.getErrorText() : null);
        } catch (MifosRuntimeException e) {
            map.put("errors", e.getMessage());
        }
    }
    map.put("invalidCollectionSheet", reasons);
    return map;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SaveCollectionSheetDto(org.mifos.application.servicefacade.SaveCollectionSheetDto) InvalidSaveCollectionSheetReason(org.mifos.application.servicefacade.InvalidSaveCollectionSheetReason) SaveCollectionSheetException(org.mifos.application.servicefacade.SaveCollectionSheetException) CollectionSheetErrorsDto(org.mifos.application.servicefacade.CollectionSheetErrorsDto) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) MifosRuntimeException(org.mifos.core.MifosRuntimeException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CollectionSheetErrorsDto (org.mifos.application.servicefacade.CollectionSheetErrorsDto)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 CollectionSheetEntryGridDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto)1 BulkEntryActionForm (org.mifos.application.collectionsheet.struts.actionforms.BulkEntryActionForm)1 CollectionSheetEntryDecomposedDto (org.mifos.application.servicefacade.CollectionSheetEntryDecomposedDto)1 CollectionSheetEntryViewTranslator (org.mifos.application.servicefacade.CollectionSheetEntryViewTranslator)1 InvalidSaveCollectionSheetReason (org.mifos.application.servicefacade.InvalidSaveCollectionSheetReason)1 SaveCollectionSheetDto (org.mifos.application.servicefacade.SaveCollectionSheetDto)1 SaveCollectionSheetException (org.mifos.application.servicefacade.SaveCollectionSheetException)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1