use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ResponseBuilder method invokePutPostDeleteMethod.
protected Object invokePutPostDeleteMethod(ApiMethod apiMethod, Object bean, Properties parameters, Object bodyObject) throws ApiException, Throwable {
Object result = null;
try {
if (apiMethod.getHttpMethod().equals(ApiMethod.HttpMethod.DELETE)) {
result = this.invokeDeleteMethod(apiMethod, bean, parameters);
} else {
result = this.invokePutPostMethod(apiMethod, bean, parameters, bodyObject);
}
if (null != result)
return result;
StringApiResponse response = new StringApiResponse();
response.setResult(SUCCESS, null);
result = response;
} catch (NoSuchMethodException e) {
_logger.error("No such method '{}' of class '{}'", apiMethod.getSpringBeanMethod(), bean.getClass(), e);
throw new ApiException(IApiErrorCodes.API_METHOD_ERROR, "Method not supported - " + this.buildApiSignature(apiMethod), Response.Status.INTERNAL_SERVER_ERROR);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ApiException) {
throw (ApiException) e.getTargetException();
} else {
_logger.error("Error invoking method '{}' of class '{}'", apiMethod.getSpringBeanMethod(), bean.getClass());
throw new ApiException(IApiErrorCodes.API_METHOD_ERROR, "Error invoking Method - " + this.buildApiSignature(apiMethod), Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (Throwable t) {
_logger.error("Error invoking method '{}' of class '{}'", apiMethod.getSpringBeanMethod(), bean.getClass(), t);
throw t;
}
return result;
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiDataObjectInterface method validateAndSaveDataObject.
protected StringApiResponse validateAndSaveDataObject(DataObject dataObject, Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
if (!this.getDataObjectAuthorizationHelper().isAuth(user, dataObject)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject groups makes the new content not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
}
List<ApiError> errors = this.validate(dataObject);
if (errors.size() > 0) {
response.addErrors(errors);
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
String insertString = properties.getProperty("insert");
boolean insert = (null != insertString) ? Boolean.parseBoolean(insertString) : false;
if (!insert) {
this.getDataObjectManager().saveDataObject(dataObject);
} else {
this.getDataObjectManager().insertDataObject(dataObject);
}
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("error in validateAndSaveDataObject", t);
throw new ApsSystemException("Error adding dataObject", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiDataObjectInterface method deleteDataObject.
public StringApiResponse deleteDataObject(Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String id = properties.getProperty("id");
DataObject masterDataObject = this.getDataObjectManager().loadDataObject(id, false);
if (null == masterDataObject) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + id + "' does not exist", Response.Status.CONFLICT);
}
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
if (!this.getDataObjectAuthorizationHelper().isAuth(user, masterDataObject)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject groups makes the new dataObject not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
}
if (masterDataObject.isOnLine()) {
this.getDataObjectManager().removeDataObject(masterDataObject);
}
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error deleting DataObject", t);
throw new ApsSystemException("Error deleting DataObject", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiContentInterface method updateContent.
public StringApiResponse updateContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbContent.getTypeCode();
Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
}
Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
Content masterContent = this.getContentManager().loadContent(content.getId(), false);
if (null == masterContent) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + content.getId() + "' does not exist", Response.Status.CONFLICT);
} else if (!masterContent.getMainGroup().equals(content.getMainGroup())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid main group " + content.getMainGroup() + " not equals then master " + masterContent.getMainGroup(), Response.Status.CONFLICT);
}
response = this.validateAndSaveContent(content, properties);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating content", t);
throw new ApsSystemException("Error updating content", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiContentInterface method validateAndSaveContent.
protected StringApiResponse validateAndSaveContent(Content content, Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
if (!this.getContentAuthorizationHelper().isAuth(user, content)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content groups makes the new content not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
}
List<ApiError> errors = this.validate(content);
if (errors.size() > 0) {
response.addErrors(errors);
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
String insertOnLineString = properties.getProperty("insertOnLine");
boolean insertOnLine = (null != insertOnLineString) ? Boolean.parseBoolean(insertOnLineString) : false;
if (!insertOnLine) {
this.getContentManager().saveContent(content);
} else {
this.getContentManager().insertOnLineContent(content);
}
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("error in validateAndSaveContent", t);
throw new ApsSystemException("Error adding content", t);
}
return response;
}
Aggregations