use of org.entando.entando.aps.system.services.api.model.ApiException 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.ApiException in project entando-core by entando.
the class ApiWidgetTypeInterface method deleteWidgetType.
public void deleteWidgetType(Properties properties) throws ApiException, Throwable {
String code = properties.getProperty("code");
try {
WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(code);
if (null == widgetType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Widget Type with code " + code + " does not exists", Response.Status.CONFLICT);
}
if (widgetType.isLocked()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Widget Type '" + code + "' is locked", Response.Status.CONFLICT);
}
List<IPage> referencedPages = this.getPageManager().getDraftWidgetUtilizers(code);
if (null != referencedPages && !referencedPages.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Widget Type '" + code + "' is published into some pages", Response.Status.CONFLICT);
}
this.getWidgetTypeManager().deleteWidgetType(code);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting widget type throw api", t);
throw t;
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException 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.ApiException in project entando-core by entando.
the class ApiContentInterface method extractContents.
protected List<String> extractContents(Properties properties) throws Throwable {
List<String> contentsId = null;
try {
ApiContentListBean bean = this.buildSearchBean(properties);
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
contentsId = this.getContentListHelper().getContentsId(bean, user);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in extractContents", t);
throw new ApsSystemException("Error into API method", t);
}
return contentsId;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiContentInterface method getContentToHtml.
public String getContentToHtml(Properties properties) throws ApiException, Throwable {
String render = null;
String id = properties.getProperty("id");
String modelId = properties.getProperty("modelId");
try {
if (null == modelId || modelId.trim().length() == 0) {
return null;
}
Content mainContent = this.getPublicContent(id);
Integer modelIdInteger = this.checkModel(modelId, mainContent);
if (null != modelIdInteger) {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
render = this.getRenderedContent(id, modelIdInteger, langCode);
}
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getContentToHtml", t);
throw new ApsSystemException("Error into API method", t);
}
return render;
}
Aggregations