use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiDataObjectInterface method getDataObjectsToHtml.
public String getDataObjectsToHtml(Properties properties) throws Throwable {
StringBuilder render = new StringBuilder();
try {
String modelId = properties.getProperty("modelId");
if (null == modelId || modelId.trim().length() == 0) {
return null;
}
String dataType = properties.getProperty("dataType");
DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(dataType);
Integer modelIdInteger = this.checkModel(modelId, prototype);
if (null == modelIdInteger) {
return null;
}
List<String> dataObjectsId = this.extractDataObjects(properties);
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
render.append(this.getItemsStartElement());
for (int i = 0; i < dataObjectsId.size(); i++) {
render.append(this.getItemStartElement());
String renderedData = this.getRenderedDataObject(dataObjectsId.get(i), modelIdInteger, langCode);
if (null != renderedData) {
render.append(renderedData);
}
render.append(this.getItemEndElement());
}
render.append(this.getItemsEndElement());
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getDataObjectsToHtml", 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 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.ApiException in project entando-core by entando.
the class ApiDataObjectInterface method buildSearchBean.
protected ApiDataObjectListBean buildSearchBean(Properties properties) throws ApiException, Throwable {
ApiDataObjectListBean bean = null;
try {
String dataType = properties.getProperty("dataType");
if (null == this.getDataObjectManager().getSmallDataTypesMap().get(dataType)) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "DataObject Type '" + dataType + "' does not exist", Response.Status.CONFLICT);
}
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
String filtersParam = properties.getProperty("filters");
EntitySearchFilter[] filters = this.getDataObjectListHelper().getFilters(dataType, filtersParam, langCode);
String[] categoryCodes = null;
String categoriesParam = properties.getProperty("categories");
if (null != categoriesParam && categoriesParam.trim().length() > 0) {
categoryCodes = categoriesParam.split(IDataTypeListHelper.CATEGORIES_SEPARATOR);
}
bean = new ApiDataObjectListBean(dataType, filters, categoryCodes);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in buildSearchBean", t);
throw new ApsSystemException("Error into API method", t);
}
return bean;
}
use of org.entando.entando.aps.system.services.api.model.ApiException 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.ApiException in project entando-core by entando.
the class ApiWidgetTypeInterface method addWidgetType.
public void addWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
try {
WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
if (null != widgetType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " already exists", Response.Status.CONFLICT);
}
widgetType = jaxbWidgetType.getNewWidgetType(this.getWidgetTypeManager());
if (!widgetType.isLogic() && StringUtils.isBlank(jaxbWidgetType.getGui())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Gui is mandatory", Response.Status.CONFLICT);
}
if (widgetType.isLogic() && (StringUtils.isNotBlank(jaxbWidgetType.getGui()) || (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0))) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment mustn't be added on the new logic widget type", Response.Status.CONFLICT);
}
if (widgetType.isLogic() && this.isInternalServletWidget(widgetType.getParentType().getCode())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Logic type with parent 'Internal Servlet' widget mustn't be added", Response.Status.CONFLICT);
}
this.getWidgetTypeManager().addWidgetType(widgetType);
if (!widgetType.isLogic()) {
this.checkAndSaveFragment(widgetType, jaxbWidgetType, true, null, addedFragments, updatedFragments);
}
} catch (ApiException ae) {
this.revertPreviousObject(null, addedFragments, updatedFragments);
throw ae;
} catch (Throwable t) {
this.revertPreviousObject(null, addedFragments, updatedFragments);
this.getWidgetTypeManager().deleteWidgetType(jaxbWidgetType.getCode());
_logger.error("Error adding new widget type", t);
throw t;
}
}
Aggregations