use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiWidgetTypeInterface method getWidgetType.
public JAXBWidgetType getWidgetType(Properties properties) throws ApiException, Throwable {
String widgetTypeCode = properties.getProperty("code");
JAXBWidgetType jaxbWidgetType = null;
try {
WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(widgetTypeCode);
if (null == widgetType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code '" + widgetTypeCode + "' does not exist", Response.Status.CONFLICT);
}
GuiFragment singleGuiFragment = null;
List<GuiFragment> fragments = new ArrayList<GuiFragment>();
if (!widgetType.isLogic()) {
singleGuiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetTypeCode);
} else {
List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetTypeCode);
if (null != fragmentCodes) {
for (int i = 0; i < fragmentCodes.size(); i++) {
String fragmentCode = fragmentCodes.get(i);
GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
if (null != fragment) {
fragments.add(fragment);
}
}
}
}
jaxbWidgetType = new JAXBWidgetType(widgetType, singleGuiFragment, fragments);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error creating widget type - code '{}'", widgetTypeCode, t);
throw t;
}
return jaxbWidgetType;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class JAXBWidgetType method getModifiedWidgetType.
public WidgetType getModifiedWidgetType(IWidgetTypeManager widgetTypeManager) throws ApiException {
WidgetType type = widgetTypeManager.getWidgetType(this.getCode());
type.setTitles(this.getTitles());
if (type.isLogic()) {
ApsProperties configuration = this.getConfig();
type.setConfig(configuration);
} else {
List<WidgetTypeParameter> parameters = this.getTypeParameters();
if (null != parameters && !parameters.isEmpty()) {
// type.setAction("configSimpleParameter");
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Parameters of existing widget mustn't been changed", Response.Status.CONFLICT);
}
}
type.setMainGroup(this.getMainGroup());
// type.setPluginCode(this.getPluginCode());
return type;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiContentInterface method getContentsToHtml.
public String getContentsToHtml(Properties properties) throws Throwable {
StringBuilder render = new StringBuilder();
try {
String modelId = properties.getProperty("modelId");
if (null == modelId || modelId.trim().length() == 0) {
return null;
}
String contentType = properties.getProperty("contentType");
Content prototype = (Content) this.getContentManager().getEntityPrototype(contentType);
Integer modelIdInteger = this.checkModel(modelId, prototype);
if (null == modelIdInteger) {
return null;
}
List<String> contentsId = this.extractContents(properties);
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
render.append(this.getItemsStartElement());
for (int i = 0; i < contentsId.size(); i++) {
render.append(this.getItemStartElement());
String renderedContent = this.getRenderedContent(contentsId.get(i), modelIdInteger, langCode);
if (null != renderedContent) {
render.append(renderedContent);
}
render.append(this.getItemEndElement());
}
render.append(this.getItemsEndElement());
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getContentsToHtml", t);
throw new ApsSystemException("Error into API method", t);
}
return render.toString();
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiContentInterface method getContent.
public JAXBContent getContent(Properties properties) throws ApiException, Throwable {
JAXBContent jaxbContent = null;
String id = properties.getProperty("id");
try {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
Content mainContent = this.getPublicContent(id);
jaxbContent = this.getJAXBContentInstance(mainContent, langCode);
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
if (!this.getContentAuthorizationHelper().isAuth(user, mainContent)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required content '" + id + "' does not allowed", Response.Status.FORBIDDEN);
}
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getContent", t);
throw new ApsSystemException("Error into API method", t);
}
return jaxbContent;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiContentInterface method updateContentText.
public void updateContentText(JAXBContentAttribute jaxbContentAttribute, Properties properties) throws ApiException, Throwable {
try {
String contentId = jaxbContentAttribute.getContentId();
Content masterContent = this.getContentManager().loadContent(jaxbContentAttribute.getContentId(), true);
if (null == masterContent) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + contentId + "' does not exist", Response.Status.CONFLICT);
}
String attributeName = jaxbContentAttribute.getAttributeName();
AttributeInterface attribute = (AttributeInterface) masterContent.getAttribute(attributeName);
if (null == attribute) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content Attribute with code '" + attributeName + "' does not exist into content " + contentId, Response.Status.CONFLICT);
} else if (!(attribute instanceof ITextAttribute)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content Attribute with code '" + attributeName + "' isn't a Text Atttribute", Response.Status.CONFLICT);
}
String langCode = jaxbContentAttribute.getLangCode();
String value = jaxbContentAttribute.getValue();
if (StringUtils.isEmpty(langCode) || StringUtils.isEmpty(value)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "LangCode or value is Empty", Response.Status.CONFLICT);
}
((ITextAttribute) attribute).setText(value, langCode);
this.getContentManager().insertOnLineContent(masterContent);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error updating content attribute", t);
throw new ApsSystemException("Error updating content attribute", t);
}
}
Aggregations