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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations