Search in sources :

Example 1 with ResourceUtilizer

use of com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer 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;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ContentRecordVO(com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException) ResourceUtilizer(com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)

Example 2 with ResourceUtilizer

use of com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer in project entando-core by entando.

the class ResourceActionHelper method getReferencingObjects.

@Override
public Map<String, List> getReferencingObjects(String resourceId, HttpServletRequest request) throws ApsSystemException {
    Map<String, List> references = new HashMap<String, List>();
    try {
        String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(ResourceUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
            } catch (Throwable t) {
                _logger.error("error in getReferencingObjects", t);
                service = null;
            }
            if (service != null) {
                ResourceUtilizer resourceUtilizer = (ResourceUtilizer) service;
                List utilizers = resourceUtilizer.getResourceUtilizers(resourceId);
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(resourceUtilizer.getName() + "Utilizers", utilizers);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting referencing objects by resource '{}'", resourceId, t);
        throw new ApsSystemException("Errore in getReferencingObjects", t);
    }
    return references;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceUtilizer(com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)

Example 3 with ResourceUtilizer

use of com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer in project entando-core by entando.

the class CmsCacheWrapperManager method updateFromResourceChanged.

@Override
public void updateFromResourceChanged(ResourceChangedEvent event) {
    try {
        ResourceInterface resource = event.getResource();
        if (null == resource) {
            return;
        }
        List<String> utilizers = ((ResourceUtilizer) this.getContentManager()).getResourceUtilizers(resource.getId());
        for (int i = 0; i < utilizers.size(); i++) {
            String contentId = utilizers.get(i);
            Content content = this.getContentManager().loadContent(contentId, true);
            if (null != content) {
                this.releaseRelatedItems(content);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error notifing event {}", ResourceChangedEvent.class.getName(), t);
    }
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) ResourceUtilizer(com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)

Aggregations

ResourceUtilizer (com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)1 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)1