use of com.blackducksoftware.integration.hub.alert.web.model.ResponseBodyBuilder in project hub-alert by blackducksoftware.
the class LoginHandler method authenticateUser.
public ResponseEntity<String> authenticateUser(final HttpServletRequest request, final HttpServletResponse response, final LoginRestModel loginRestModel) {
final IntLogger logger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
try {
if (loginActions.authenticateUser(loginRestModel, logger)) {
final CsrfToken token = csrfTokenRepository.generateToken(request);
csrfTokenRepository.saveToken(token, request, response);
response.setHeader(token.getHeaderName(), token.getToken());
return createResponse(HttpStatus.OK, "{\"message\":\"Success\"}");
}
return createResponse(HttpStatus.UNAUTHORIZED, "User not administrator");
} catch (final IntegrationRestException e) {
logger.error(e.getMessage(), e);
return createResponse(HttpStatus.valueOf(e.getHttpStatusCode()), e.getHttpStatusMessage() + " : " + e.getMessage());
} catch (final AlertFieldException e) {
logger.error(e.getMessage(), e);
final ResponseBodyBuilder responseBodyBuilder = new ResponseBodyBuilder(0L, e.getMessage());
responseBodyBuilder.putErrors(e.getFieldErrors());
final String responseBody = responseBodyBuilder.build();
return createResponse(HttpStatus.BAD_REQUEST, responseBody);
} catch (final Exception e) {
logger.error(e.getMessage(), e);
return createResponse(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of com.blackducksoftware.integration.hub.alert.web.model.ResponseBodyBuilder in project hub-alert by blackducksoftware.
the class CommonConfigHandler method postConfig.
public ResponseEntity<String> postConfig(final R restModel) {
if (restModel == null) {
return createResponse(HttpStatus.BAD_REQUEST, "", "Required request body is missing " + configRestModelClass.getSimpleName());
}
if (!configActions.doesConfigExist(restModel.getId())) {
try {
configActions.validateConfig(restModel);
configActions.configurationChangeTriggers(restModel);
try {
final D updatedEntity = configActions.saveConfig(restModel);
return createResponse(HttpStatus.CREATED, updatedEntity.getId(), "Created");
} catch (final AlertException e) {
logger.error(e.getMessage(), e);
return createResponse(HttpStatus.INTERNAL_SERVER_ERROR, restModel.getId(), e.getMessage());
}
} catch (final AlertFieldException e) {
final ResponseBodyBuilder responseBuilder = new ResponseBodyBuilder(configActions.getObjectTransformer().stringToLong(restModel.getId()), "There were errors with the configuration.");
responseBuilder.putErrors(e.getFieldErrors());
return new ResponseEntity<>(responseBuilder.build(), HttpStatus.BAD_REQUEST);
}
}
return createResponse(HttpStatus.CONFLICT, restModel.getId(), "Provided id must not be in use. To update an existing configuration, use PUT.");
}
use of com.blackducksoftware.integration.hub.alert.web.model.ResponseBodyBuilder in project hub-alert by blackducksoftware.
the class CommonConfigHandler method putConfig.
public ResponseEntity<String> putConfig(final R restModel) {
if (restModel == null) {
return createResponse(HttpStatus.BAD_REQUEST, "", "Required request body is missing " + configRestModelClass.getSimpleName());
}
if (configActions.doesConfigExist(restModel.getId())) {
try {
configActions.validateConfig(restModel);
configActions.configurationChangeTriggers(restModel);
try {
final D updatedEntity = configActions.saveNewConfigUpdateFromSavedConfig(restModel);
return createResponse(HttpStatus.ACCEPTED, updatedEntity.getId(), "Updated");
} catch (final AlertException e) {
logger.error(e.getMessage(), e);
return createResponse(HttpStatus.INTERNAL_SERVER_ERROR, restModel.getId(), e.getMessage());
}
} catch (final AlertFieldException e) {
final ResponseBodyBuilder responseBuilder = new ResponseBodyBuilder(configActions.getObjectTransformer().stringToLong(restModel.getId()), "There were errors with the configuration.");
responseBuilder.putErrors(e.getFieldErrors());
return new ResponseEntity<>(responseBuilder.build(), HttpStatus.BAD_REQUEST);
}
}
return createResponse(HttpStatus.BAD_REQUEST, restModel.getId(), "No configuration with the specified id.");
}
Aggregations