use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiContentInterface method deleteContent.
public StringApiResponse deleteContent(Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String id = properties.getProperty("id");
Content masterContent = this.getContentManager().loadContent(id, false);
if (null == masterContent) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content 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.getContentAuthorizationHelper().isAuth(user, masterContent)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content groups makes the new content not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
}
List<String> references = ((ContentUtilizer) this.getContentManager()).getContentUtilizers(id);
if (references != null && references.size() > 0) {
boolean found = false;
for (int i = 0; i < references.size(); i++) {
String reference = references.get(i);
ContentRecordVO record = this.getContentManager().loadContentVO(reference);
if (null != record) {
found = true;
response.addError(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Content " + id + " referenced to content " + record.getId() + " - '" + record.getDescr() + "'", Response.Status.CONFLICT));
}
}
if (found) {
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
}
if (masterContent.isOnLine()) {
this.getContentManager().removeOnLineContent(masterContent);
}
String removeWorkVersionString = properties.getProperty("removeWorkVersion");
boolean removeWorkVersion = (null != removeWorkVersionString) ? Boolean.parseBoolean(removeWorkVersionString) : false;
if (removeWorkVersion) {
this.getContentManager().deleteContent(masterContent);
}
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error deleting content", t);
throw new ApsSystemException("Error deleting content", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiResourceInterface method deleteResource.
private StringApiResponse deleteResource(Properties properties, ResourceInterface resource) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
try {
String id = properties.getProperty("id");
if (null == resource) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Resource 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.getAuthorizationManager().isAuthOnGroup(user, resource.getMainGroup())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Resource not allowed for user '" + user.getUsername() + "' - resource group '" + resource.getMainGroup() + "'", Response.Status.FORBIDDEN);
}
List<String> references = ((ResourceUtilizer) this.getContentManager()).getResourceUtilizers(id);
if (references != null && references.size() > 0) {
boolean found = false;
for (int i = 0; i < references.size(); i++) {
String reference = references.get(i);
ContentRecordVO record = this.getContentManager().loadContentVO(reference);
if (null != record) {
found = true;
response.addError(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Resource " + id + " referenced to content " + record.getId() + " - '" + record.getDescr() + "'", Response.Status.CONFLICT));
}
}
if (found) {
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
}
this.getResourceManager().deleteResource(resource);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} 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.StringApiResponse in project entando-core by entando.
the class ApiResourceInterface method deleteResource.
/**
* Delete a Resource. The method can be called by Entando API Engine.
* @param properties The properties of the DELETE method call.
* @throws Throwable Il case of error.
*/
public StringApiResponse deleteResource(Properties properties) throws Throwable {
StringApiResponse response = null;
try {
String id = properties.getProperty("id");
ResourceInterface resource = this.getResourceManager().loadResource(id);
response = this.deleteResource(properties, resource);
} 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.StringApiResponse 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.StringApiResponse in project entando-core by entando.
the class TestApiI18nLabelInterface method testCreateNewLabel.
protected void testCreateNewLabel(MediaType mediaType) throws Throwable {
String key = "TEST_LABEL_KEY";
String label = this._i18nManager.getLabel(key, "it");
assertNull(label);
ApsProperties labels = new ApsProperties();
labels.put("en", "Test label");
labels.put("it", "Label di Test");
JAXBI18nLabel jaxbLabel = new JAXBI18nLabel(key, labels);
ApiResource labelResource = this.getApiCatalogManager().getResource("core", "i18nlabel");
ApiMethod postMethod = labelResource.getPostMethod();
Properties properties = super.createApiProperties("admin", "it", mediaType);
try {
Object response = this.getResponseBuilder().createResponse(postMethod, jaxbLabel, properties);
assertNotNull(response);
assertTrue(response instanceof StringApiResponse);
assertEquals(IResponseBuilder.SUCCESS, ((StringApiResponse) response).getResult());
label = this._i18nManager.getLabel(key, "it");
assertEquals("Label di Test", label);
} catch (Exception e) {
throw e;
} finally {
this._i18nManager.deleteLabelGroup(key);
}
}
Aggregations