}
return jaxbMessage;
}
public StringApiResponse addMessage(JAXBMessage jaxbMessage) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String username = jaxbMessage.getId();
if (null != this.getMessageManager().getMessage(username)) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR,
"Message of user '" + username + "' already exist", Response.Status.CONFLICT);
}
IApsEntity profilePrototype = this.getMessageManager().getEntityPrototype(jaxbMessage.getTypeCode());
if (null == profilePrototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
"User Message type with code '" + jaxbMessage.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
}
Message message = (Message) jaxbMessage.buildEntity(profilePrototype, null);
List<ApiError> errors = this.validate(message);
if (errors.size() > 0) {
response.addErrors(errors);
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
this.getMessageManager().addMessage(message);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
ApsSystemUtils.logThrowable(t, this, "addMessage");
throw new ApsSystemException("Error adding Message", t);
}
return response;