use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiContentModelInterface method deleteModel.
public void deleteModel(Properties properties) throws ApiException, Throwable {
String idString = properties.getProperty("id");
int id = 0;
try {
id = Integer.parseInt(idString);
} catch (NumberFormatException e) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Invalid number format for 'id' parameter - '" + idString + "'", Response.Status.CONFLICT);
}
ContentModel model = this.getContentModelManager().getContentModel(id);
if (null == model) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
}
try {
this.getContentModelManager().removeContentModel(model);
} catch (Throwable t) {
_logger.error("Error deleting model", t);
// ApsSystemUtils.logThrowable(t, this, "deleteModel");
throw new ApsSystemException("Error deleting model", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiContentModelInterface method getModel.
public ContentModel getModel(Properties properties) throws ApiException, Throwable {
String idString = properties.getProperty("id");
int id = 0;
try {
id = Integer.parseInt(idString);
} catch (NumberFormatException e) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Invalid number format for 'id' parameter - '" + idString + "'", Response.Status.CONFLICT);
}
ContentModel model = this.getContentModelManager().getContentModel(id);
if (null == model) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
}
return model;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiResourceInterface method addResource.
public StringApiResponse addResource(JAXBResource jaxbResource, Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
BaseResourceDataBean bean = null;
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
this.check(jaxbResource, user, response, true);
if (null != response.getErrors() && !response.getErrors().isEmpty()) {
return response;
}
bean = jaxbResource.createBataBean(this.getCategoryManager());
String id = bean.getResourceId();
if (null != id && id.trim().length() > 0) {
Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
Matcher matcher = pattern.matcher(id);
if (!matcher.matches()) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "The resourceId can contain only alphabetic characters", Response.Status.CONFLICT);
}
}
this.getResourceManager().addResource(bean);
response.setResult(IResponseBuilder.SUCCESS);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in addResource", t);
throw new ApsSystemException("Error into API method", t);
} finally {
if (null != bean && null != bean.getFile()) {
bean.getFile().delete();
}
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiEntityTypeInterface method addEntityType.
public StringApiResponse addEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
IEntityManager manager = this.getEntityManager();
String typeCode = jaxbEntityType.getTypeCode();
IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
if (null != masterEntityType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' already exists");
}
if (typeCode == null || typeCode.length() != 3) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
}
Map<String, AttributeInterface> attributes = manager.getEntityAttributePrototypes();
IApsEntity newEntityType = jaxbEntityType.buildEntityType(manager.getEntityClass(), attributes);
this.checkNewEntityType(jaxbEntityType, newEntityType, response);
((IEntityTypesConfigurer) manager).addEntityPrototype(newEntityType);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error extracting entity type", t);
// ApsSystemUtils.logThrowable(t, this, "getEntityType");
throw new ApsSystemException("Error extracting entity type", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiEntityTypeInterface method getEntityType.
public JAXBEntityType getEntityType(Properties properties) throws Throwable {
JAXBEntityType jaxbEntityType = null;
try {
IEntityManager manager = this.getEntityManager();
String typeCode = properties.getProperty(this.getTypeCodeParamName());
IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
if (null == masterEntityType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' does not exist");
}
jaxbEntityType = this.createJAXBEntityType(masterEntityType);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error extracting entity type", t);
// ApsSystemUtils.logThrowable(t, this, "getEntityType");
throw new ApsSystemException("Error extracting entity type", t);
}
return jaxbEntityType;
}
Aggregations