use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiWidgetTypeInterface method updateWidgetType.
public StringApiResponse updateWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
WidgetType widgetTypeToUpdate = null;
List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
try {
widgetTypeToUpdate = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
if (null == widgetTypeToUpdate) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " does not exists", Response.Status.CONFLICT);
}
WidgetType widgetType = jaxbWidgetType.getModifiedWidgetType(this.getWidgetTypeManager());
this.checkAndSaveFragment(widgetType, jaxbWidgetType, false, response, addedFragments, updatedFragments);
this.getWidgetTypeManager().updateWidgetType(widgetType.getCode(), widgetType.getTitles(), widgetType.getConfig(), widgetType.getMainGroup());
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
throw ae;
} catch (Throwable t) {
this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
_logger.error("Error updating widget type", t);
throw t;
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiContentInterface method addContent.
public StringApiResponse addContent(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());
if (null != content.getId()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "You cannot specify Content Id", Response.Status.CONFLICT);
}
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
content.setFirstEditor((null != user) ? user.getUsername() : SystemConstants.GUEST_USER_NAME);
response = this.validateAndSaveContent(content, properties);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error adding content", t);
throw new ApsSystemException("Error adding content", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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.StringApiResponse in project entando-core by entando.
the class ApiResourceInterface method updateResource.
public StringApiResponse updateResource(JAXBResource jaxbResource, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
BaseResourceDataBean bean = null;
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
this.check(jaxbResource, user, response, false);
if (null != response.getErrors() && !response.getErrors().isEmpty()) {
return response;
}
bean = jaxbResource.createBataBean(this.getCategoryManager());
this.getResourceManager().updateResource(bean);
response.setResult(IResponseBuilder.SUCCESS);
} catch (Throwable t) {
_logger.error("error in updateResource", 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.StringApiResponse 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;
}
Aggregations