@PreAuthorize("hasRole('ROLE_CAN_MANAGE_REMOTE_PROVIDERS')")
@RequestMapping(value="/{typeId}/configure", method = RequestMethod.POST)
public @ResponseBody Object configureFinish(@PathVariable("typeId") int typeId,
HttpServletRequest request) {
ResponseCode test = remoteProviderTypeService.checkConfiguration(
request.getParameter("username"),
request.getParameter("password"),
request.getParameter("apiKey"),
request.getParameter("matchSourceNumbers"),
request.getParameter("platform"),
typeId);
if (test.equals(ResponseCode.BAD_ID)) {
return RestResponse.failure("Unable to find that Remote Provider Type.");
} else if (test.equals(ResponseCode.NO_APPS)) {
String error = "We were unable to retrieve a list of applications using these credentials." +
" Please ensure that the credentials are valid and that there are applications " +
"available in the account.";
log.error(error);
return RestResponse.failure(error);
} else if (test.equals(ResponseCode.SUCCESS)) {
RemoteProviderType type = remoteProviderTypeService.load(typeId);
return ControllerUtils.writeSuccessObjectWithView(type, AllViews.TableRow.class);
} else {
log.warn("Response code was not success but we're still returning success. This shouldn't happen.");
return RestResponse.failure("Response was " + test);