use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiResourceInterface method deleteResource.
private StringApiResponse deleteResource(Properties properties, String expectedTypeCode) throws ApiException, Throwable {
StringApiResponse response = null;
try {
String id = properties.getProperty("id");
ResourceInterface resource = this.getResourceManager().loadResource(id);
if (null != resource && !resource.getType().equals(expectedTypeCode)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid resource type - '" + resource.getType() + "'", Response.Status.CONFLICT);
}
properties.setProperty(RESOURCE_TYPE_CODE_PARAM, expectedTypeCode);
response = this.deleteResource(properties, resource);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting resource", t);
// ApsSystemUtils.logThrowable(t, this, "deleteResource");
throw new ApsSystemException("Error deleting resource", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiResourceInterface method getResource.
public JAXBResource getResource(Properties properties) throws Throwable {
JAXBResource jaxbResource = null;
String id = properties.getProperty("id");
String resourceTypeCode = properties.getProperty(RESOURCE_TYPE_CODE_PARAM);
try {
ResourceInterface resource = this.getResourceManager().loadResource(id);
if (null == resource || !resource.getType().equalsIgnoreCase(resourceTypeCode)) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Null resource by id '" + id + "'", Response.Status.CONFLICT);
}
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
String groupName = resource.getMainGroup();
if (!Group.FREE_GROUP_NAME.equals(groupName) && !this.getAuthorizationManager().isAuthOnGroup(user, groupName)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required resource '" + id + "' does not allowed", Response.Status.FORBIDDEN);
}
jaxbResource = new JAXBResource(resource);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getResource", t);
throw new ApsSystemException("Error into API method", t);
}
return jaxbResource;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiDataObjectModelInterface method getModel.
public DataObjectModel getModel(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);
}
return model;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiGuiFragmentInterface method deleteGuiFragment.
public void deleteGuiFragment(Properties properties) throws ApiException, Throwable {
String code = properties.getProperty("code");
try {
GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
if (null == guiFragment) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' does not exist", Response.Status.CONFLICT);
}
if (guiFragment.isLocked()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' are locked", Response.Status.CONFLICT);
}
Map<String, List<Object>> references = new HashMap<String, List<Object>>();
ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory();
String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class);
for (int i = 0; i < defNames.length; i++) {
Object service = null;
try {
service = this.getBeanFactory().getBean(defNames[i]);
} catch (Throwable t) {
_logger.error("error extracting bean with name '{}'", defNames[i], t);
throw new ApsSystemException("error extracting bean with name '" + defNames[i] + "'", t);
}
if (service != null) {
GuiFragmentUtilizer guiFragUtilizer = (GuiFragmentUtilizer) service;
List<Object> utilizers = guiFragUtilizer.getGuiFragmentUtilizers(code);
if (utilizers != null && !utilizers.isEmpty()) {
references.put(guiFragUtilizer.getName(), utilizers);
}
}
}
if (!references.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + code + " has references with other object", Response.Status.CONFLICT);
}
this.getGuiFragmentManager().deleteGuiFragment(code);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting fragment throw api", t);
throw t;
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiGuiFragmentInterface method updateGuiFragment.
public void updateGuiFragment(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() + "' does not exist", 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().updateGuiFragment(guiFragment);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error updating fragment", t);
throw t;
}
}
Aggregations