use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiDataObjectInterface method getDataObject.
public JAXBDataObject getDataObject(Properties properties) throws ApiException, Throwable {
JAXBDataObject jaxbDataObject = null;
String id = properties.getProperty("id");
try {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
DataObject mainDataObject = this.getPublicDataObject(id);
jaxbDataObject = this.getJAXBDataObjectInstance(mainDataObject, langCode);
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
if (!this.getDataObjectAuthorizationHelper().isAuth(user, mainDataObject)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required DataObject '" + id + "' does not allowed", Response.Status.FORBIDDEN);
}
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getDataObject", t);
throw new ApsSystemException("Error into API method", t);
}
return jaxbDataObject;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiDataObjectInterface method updateDataObject.
public StringApiResponse updateDataObject(JAXBDataObject jaxbDataObject, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbDataObject.getTypeCode();
DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(typeCode);
if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
}
DataObject content = (DataObject) jaxbDataObject.buildEntity(prototype, this.getCategoryManager());
DataObject masterData = this.getDataObjectManager().loadDataObject(content.getId(), false);
if (null == masterData) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + content.getId() + "' does not exist", Response.Status.CONFLICT);
} else if (!masterData.getMainGroup().equals(content.getMainGroup())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid main group " + content.getMainGroup() + " not equals then master " + masterData.getMainGroup(), Response.Status.CONFLICT);
}
response = this.validateAndSaveDataObject(content, properties);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating DataObject", t);
throw new ApsSystemException("Error updating 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 getDataObjectToHtml.
public String getDataObjectToHtml(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;
}
DataObject mainDataObject = this.getPublicDataObject(id);
Integer modelIdInteger = this.checkModel(modelId, mainDataObject);
if (null != modelIdInteger) {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
render = this.getRenderedDataObject(id, modelIdInteger, langCode);
}
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getDataObjectToHtml", t);
throw new ApsSystemException("Error into API method", t);
}
return render;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiDataObjectModelInterface 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);
}
DataObjectModel model = this.getDataObjectModelManager().getDataObjectModel(id);
if (null == model) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
}
try {
this.getDataObjectModelManager().removeDataObjectModel(model);
} catch (Throwable t) {
_logger.error("Error deleting model", t);
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 ApiGuiFragmentInterface method addGuiFragment.
public void addGuiFragment(JAXBGuiFragment jaxbGuiFragment) throws ApiException, Throwable {
try {
if (null != this.getGuiFragmentManager().getGuiFragment(jaxbGuiFragment.getCode())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + jaxbGuiFragment.getCode() + " already exists", Response.Status.CONFLICT);
}
GuiFragment guiFragment = jaxbGuiFragment.getGuiFragment();
if (StringUtils.isBlank(guiFragment.getCurrentGui())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued", Response.Status.CONFLICT);
}
this.getGuiFragmentManager().addGuiFragment(guiFragment);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error adding new fragment", t);
throw t;
}
}
Aggregations