Search in sources :

Example 6 with ContentRecordVO

use of com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO in project entando-core by entando.

the class ContentInspectionAction method getReferencingContents.

/**
 * Return the list of the referencing contents.
 * @return the list of the referencing contents.
 * @deprecated use getReferencingContentsId() method
 */
public List<ContentRecordVO> getReferencingContents() {
    List<ContentRecordVO> referencingContents = new ArrayList<ContentRecordVO>();
    try {
        List<String> referencingContentsId = this.getReferencingContentsId();
        if (null != referencingContentsId) {
            for (int i = 0; i < referencingContentsId.size(); i++) {
                ContentRecordVO currentReferencedContent = this.getContentManager().loadContentVO(referencingContentsId.get(i));
                referencingContents.add(currentReferencedContent);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error getting referencing contents by content {}", this.getContentId(), t);
        String msg = "Error getting referencing contents by content " + this.getContentId();
        throw new RuntimeException(msg, t);
    }
    return referencingContents;
}
Also used : ContentRecordVO(com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO) ArrayList(java.util.ArrayList)

Example 7 with ContentRecordVO

use of com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO in project entando-core by entando.

the class ContentLinkAction method joinContentLink.

public String joinContentLink() {
    ContentRecordVO contentVo = this.getContentVo(this.getContentId());
    if (null == contentVo || !contentVo.isOnLine()) {
        _logger.error("Content '{}' does not exists or is not public", this.getContentId());
        return FAILURE;
    }
    if (this.isContentOnPageType()) {
        // Fa il forward alla scelta pagina di destinazione
        return "configContentOnPageLink";
    } else {
        String[] destinations = { null, this.getContentId(), null };
        this.buildEntryContentAnchorDest();
        this.getLinkAttributeHelper().joinLink(destinations, SymbolicLink.CONTENT_TYPE, this.getRequest());
        return SUCCESS;
    }
}
Also used : ContentRecordVO(com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)

Example 8 with ContentRecordVO

use of com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO in project entando-core by entando.

the class PageLinkAction method getContentVo.

public ContentRecordVO getContentVo(String contentId) {
    ContentRecordVO contentVo = null;
    try {
        IContentManager contentManager = (IContentManager) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_MANAGER, this.getRequest());
        contentVo = contentManager.loadContentVO(contentId);
    } catch (Throwable t) {
        _logger.error("error in getContentVo for content {}", contentId, t);
        throw new RuntimeException("Errore in caricamento contenuto vo", t);
    }
    return contentVo;
}
Also used : IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) ContentRecordVO(com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)

Example 9 with ContentRecordVO

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

Example 10 with ContentRecordVO

use of com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO 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)

Aggregations

ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)18 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 ArrayList (java.util.ArrayList)2 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)2 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)1 ApsProperties (com.agiletec.aps.util.ApsProperties)1 ContentUtilizer (com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer)1 IContentManager (com.agiletec.plugins.jacms.aps.system.services.content.IContentManager)1 ResourceUtilizer (com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)1 Properties (java.util.Properties)1 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)1 ContentJO (org.entando.entando.plugins.jacms.apsadmin.content.rs.model.ContentJO)1