Search in sources :

Example 1 with InvalidSaveCollectionSheetReason

use of org.mifos.application.servicefacade.InvalidSaveCollectionSheetReason 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

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 CollectionSheetErrorsDto (org.mifos.application.servicefacade.CollectionSheetErrorsDto)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 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1