Search in sources :

Example 11 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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)

Example 12 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project head by mifos.

the class GroupRESTController method createGroup.

@RequestMapping(value = "group/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createGroup(@RequestBody String request) throws Throwable {
    ObjectMapper om = createGroupMapping();
    CreateGroupCreationDetailDto creationDetail = null;
    MeetingBO meetingBO = null;
    try {
        creationDetail = om.readValue(request, CreateGroupCreationDetailDto.class);
    } catch (JsonMappingException e) {
        throw e.getCause();
    }
    validate(creationDetail);
    meetingBO = (MeetingBO) creationDetail.getMeeting().toBO();
    GroupCreationDetail group = createGroup(creationDetail);
    CustomerDetailsDto groupDetails = groupServiceFacade.createNewGroup(group, meetingBO.toDto());
    GroupInformationDto groupInfo = groupServiceFacade.getGroupInformationDto(groupDetails.getGlobalCustNum());
    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("globalCusNum", groupInfo.getGroupDisplay().getGlobalCustNum());
    map.put("accountNum", groupInfo.getCustomerAccountSummary().getGlobalAccountNum());
    map.put("address", groupInfo.getAddress().getDisplayAddress());
    map.put("city", groupInfo.getAddress().getCity());
    map.put("state", groupInfo.getAddress().getState());
    map.put("country", groupInfo.getAddress().getCountry());
    map.put("postal code", groupInfo.getAddress().getZip());
    map.put("phone", groupInfo.getAddress().getPhoneNumber());
    map.put("dispalyName", groupInfo.getGroupDisplay().getDisplayName());
    map.put("externalId", groupInfo.getGroupDisplay().getExternalId());
    map.put("loanOfficer", groupInfo.getGroupDisplay().getLoanOfficerName());
    return map;
}
Also used : HashMap(java.util.HashMap) MeetingBO(org.mifos.application.meeting.business.MeetingBO) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) CreateGroupCreationDetailDto(org.mifos.application.servicefacade.CreateGroupCreationDetailDto) GroupCreationDetail(org.mifos.dto.domain.GroupCreationDetail) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) GroupInformationDto(org.mifos.dto.screen.GroupInformationDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project head by mifos.

the class LoanAccountRESTController method createLoanAccount.

@RequestMapping(value = "/account/loan/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createLoanAccount(@RequestBody String request) throws Throwable {
    ObjectMapper om = createLoanAccountMapping();
    Map<String, String> map = new HashMap<String, String>();
    CreationLoanAccountDto creationDetails = null;
    try {
        creationDetails = om.readValue(request, CreationLoanAccountDto.class);
    } catch (JsonMappingException e) {
        e.getCause();
    }
    loanValidator(creationDetails);
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    LoanCreationResultDto loanResult = null;
    LoanBO loanInfo = null;
    CreateLoanAccount loanAccount = createLoan(creationDetails);
    if (creationDetails.getGlim()) {
        List<GroupMemberAccountDto> memberAccounts = creationDetails.glimsAsGroupMemberAccountDto(creationDetails.getGlimAccounts());
        CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, creationDetails.getLoanAmount(), loanAccount);
        loanResult = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, questionGroups, null);
        List<LoanBO> individuals = loanDao.findIndividualLoans(loanResult.getAccountId());
        for (int i = 0; i < individuals.size(); i++) {
            map.put("individualCustomer[" + i + "]", individuals.get(i).getCustomer().getDisplayName());
            map.put("individualAccount[" + i + "]", individuals.get(i).getGlobalAccountNum());
            map.put("individualAmmount[" + i + "]", individuals.get(i).getLoanAmount().toString());
        }
    } else {
        loanResult = loanAccountServiceFacade.createLoan(loanAccount, questionGroups, null);
    }
    loanInfo = loanDao.findByGlobalAccountNum(loanResult.getGlobalAccountNum());
    map.put("status", "success");
    map.put("accountNum", loanInfo.getGlobalAccountNum());
    map.put("GLIM", creationDetails.getGlim().toString());
    map.put("customer", loanInfo.getCustomer().getDisplayName());
    map.put("loanAmmount", loanInfo.getLoanAmount().toString());
    map.put("noOfInstallments", loanInfo.getNoOfInstallments().toString());
    map.put("externalId", loanInfo.getExternalId());
    return map;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) GroupMemberAccountDto(org.mifos.clientportfolio.newloan.applicationservice.GroupMemberAccountDto) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto) CreateGlimLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CreationLoanAccountDto(org.mifos.application.servicefacade.CreationLoanAccountDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project openhab1-addons by openhab.

the class OpenPathsBinding method getUserLocation.

@SuppressWarnings("unchecked")
private Location getUserLocation(String accessKey, String secretKey) {
    // build the OAuth service using the access/secret keys
    OAuthService service = new ServiceBuilder().provider(new OpenPathsApi()).apiKey(accessKey).apiSecret(secretKey).build();
    // build the request
    OAuthRequest request = new OAuthRequest(Verb.GET, "https://openpaths.cc/api/1");
    service.signRequest(Token.empty(), request);
    request.addQuerystringParameter("num_points", "1");
    // send the request and check we got a successful response
    Response response = request.send();
    if (!response.isSuccessful()) {
        logger.error("Failed to request the OpenPaths location, response code: " + response.getCode());
        return null;
    }
    // parse the response to build our location object
    Map<String, Object> locationData;
    String toParse = "{}";
    try {
        ObjectMapper jsonReader = new ObjectMapper();
        toParse = response.getBody();
        toParse = toParse.substring(1, toParse.length() - 2);
        locationData = jsonReader.readValue(toParse, Map.class);
    } catch (JsonParseException e) {
        logger.error("Error parsing JSON:\n" + toParse, e);
        return null;
    } catch (JsonMappingException e) {
        logger.error("Error mapping JSON:\n" + toParse, e);
        return null;
    } catch (IOException e) {
        logger.error("An I/O error occured while decoding JSON:\n" + response.getBody());
        return null;
    }
    float latitude = Float.parseFloat(locationData.get("lat").toString());
    float longitude = Float.parseFloat(locationData.get("lon").toString());
    String device = locationData.get("device").toString();
    return new Location(latitude, longitude, device);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ServiceBuilder(org.scribe.builder.ServiceBuilder) Response(org.scribe.model.Response) OAuthService(org.scribe.oauth.OAuthService) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 15 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project oxTrust by GluuFederation.

the class UpdatePersonAction method getDeviceata.

private DeviceData getDeviceata(String data) {
    ObjectMapper mapper = new ObjectMapper();
    // JSON from file to Object
    DeviceData obj = null;
    try {
        obj = mapper.readValue(data, DeviceData.class);
    } catch (JsonParseException e) {
        // TODO Auto-generated catch block
        log.error("Failed to convert device string to object JsonParseException", e);
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        log.error("Failed to convert device string to object JsonMappingException", e);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        log.error("Failed to convert device string to object IOException", e);
    }
    return obj;
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) DeviceData(org.xdi.oxauth.model.fido.u2f.protocol.DeviceData) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)42 IOException (java.io.IOException)34 JsonParseException (org.codehaus.jackson.JsonParseException)33 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)15 TypeReference (org.codehaus.jackson.type.TypeReference)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 Map (java.util.Map)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 BlogsMoreResponse (cn.eoe.app.entity.BlogsMoreResponse)2 NewsMoreResponse (cn.eoe.app.entity.NewsMoreResponse)2 WikiMoreResponse (cn.eoe.app.entity.WikiMoreResponse)2 ByteString (com.linkedin.data.ByteString)2 PhysicalSourceConfig (com.linkedin.databus2.relay.config.PhysicalSourceConfig)2 InputStream (java.io.InputStream)2