Search in sources :

Example 1 with CmsAttributeReference

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

the class BaseContentGroupBulkCommand method checkContentReferences.

protected boolean checkContentReferences(Content content) {
    List<Lang> systemLangs = this.getSystemLangs();
    IPageManager pageManager = this.getPageManager();
    SymbolicLinkValidator validator = new SymbolicLinkValidator(this.getApplier(), pageManager);
    for (AttributeInterface attribute : content.getAttributeList()) {
        if (attribute instanceof IReferenceableAttribute) {
            List<CmsAttributeReference> references = ((IReferenceableAttribute) attribute).getReferences(systemLangs);
            if (references != null) {
                for (CmsAttributeReference reference : references) {
                    SymbolicLink symbolicLink = this.convertToSymbolicLink(reference);
                    if (symbolicLink != null) {
                        String result = validator.scan(symbolicLink, content);
                        if (ICmsAttributeErrorCodes.INVALID_CONTENT_GROUPS.equals(result) || ICmsAttributeErrorCodes.INVALID_RESOURCE_GROUPS.equals(result) || ICmsAttributeErrorCodes.INVALID_PAGE_GROUPS.equals(result)) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : IReferenceableAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute) IPageManager(com.agiletec.aps.system.services.page.IPageManager) SymbolicLinkValidator(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator) Lang(com.agiletec.aps.system.services.lang.Lang) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference) SymbolicLink(com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 2 with CmsAttributeReference

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

the class ContentInspectionAction method getReferencedContentsId.

/**
 * Return the list of the id of the referenced contents
 * @return The list of content id.
 */
public List<String> getReferencedContentsId() {
    List<String> referencedContentsId = new ArrayList<String>();
    try {
        Content content = this.getContent();
        if (null == content)
            return referencedContentsId;
        EntityAttributeIterator attributeIter = new EntityAttributeIterator(content);
        while (attributeIter.hasNext()) {
            AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
            if (currAttribute instanceof IReferenceableAttribute) {
                IReferenceableAttribute cmsAttribute = (IReferenceableAttribute) currAttribute;
                List<CmsAttributeReference> refs = cmsAttribute.getReferences(this.getLangs());
                for (int scanRefs = 0; scanRefs < refs.size(); scanRefs++) {
                    CmsAttributeReference ref = refs.get(scanRefs);
                    String contentId = ref.getRefContent();
                    if (null == contentId)
                        continue;
                    if (!referencedContentsId.contains(contentId))
                        referencedContentsId.add(contentId);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error getting referenced contents id by content {}", this.getContentId(), t);
        String msg = "Error getting referenced contents id by content " + this.getContentId();
        throw new RuntimeException(msg, t);
    }
    return referencedContentsId;
}
Also used : IReferenceableAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 3 with CmsAttributeReference

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

the class ContentInspectionAction method getReferencedPages.

public List<IPage> getReferencedPages() {
    List<IPage> referencedPages = new ArrayList<IPage>();
    try {
        Content content = this.getContent();
        if (null == content)
            return referencedPages;
        EntityAttributeIterator attributeIter = new EntityAttributeIterator(content);
        while (attributeIter.hasNext()) {
            AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
            if (currAttribute instanceof IReferenceableAttribute) {
                IReferenceableAttribute cmsAttribute = (IReferenceableAttribute) currAttribute;
                List<CmsAttributeReference> refs = cmsAttribute.getReferences(this.getLangs());
                for (int scanRefs = 0; scanRefs < refs.size(); scanRefs++) {
                    CmsAttributeReference ref = refs.get(scanRefs);
                    if (null == ref.getRefPage())
                        continue;
                    IPage page = this.getPageManager().getOnlinePage(ref.getRefPage());
                    if (null == page)
                        continue;
                    if (!referencedPages.contains(page)) {
                        referencedPages.add(page);
                    }
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error getting referenced pages by content {}", this.getContentId(), t);
        String msg = "Error getting referenced pages by content " + this.getContentId();
        throw new RuntimeException(msg, t);
    }
    return referencedPages;
}
Also used : IReferenceableAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 4 with CmsAttributeReference

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

the class AbstractResourceAttribute method getReferences.

@Override
public List<CmsAttributeReference> getReferences(List<Lang> systemLangs) {
    List<CmsAttributeReference> refs = new ArrayList<>();
    for (int i = 0; i < systemLangs.size(); i++) {
        Lang lang = systemLangs.get(i);
        ResourceInterface res = this.getResource(lang.getCode());
        if (null != res) {
            CmsAttributeReference ref = new CmsAttributeReference(null, null, res.getId());
            refs.add(ref);
        }
    }
    return refs;
}
Also used : ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference)

Example 5 with CmsAttributeReference

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

the class CmsHypertextAttribute method getReferences.

@Override
public List<CmsAttributeReference> getReferences(List<Lang> systemLangs) {
    List<CmsAttributeReference> refs = new ArrayList<>();
    for (Lang lang : systemLangs) {
        String text = this.getTextMap().get(lang.getCode());
        List<SymbolicLink> links = HypertextAttributeUtil.getSymbolicLinksOnText(text);
        if (null != links && !links.isEmpty()) {
            for (SymbolicLink symbLink : links) {
                if (symbLink.getDestType() != SymbolicLink.URL_TYPE) {
                    CmsAttributeReference ref = new CmsAttributeReference(symbLink.getPageDest(), symbLink.getContentDest(), symbLink.getResourceDest());
                    refs.add(ref);
                }
            }
        }
    }
    return refs;
}
Also used : ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference) SymbolicLink(com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)

Aggregations

CmsAttributeReference (com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference)7 ArrayList (java.util.ArrayList)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 IReferenceableAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute)4 EntityAttributeIterator (com.agiletec.aps.system.common.util.EntityAttributeIterator)3 Lang (com.agiletec.aps.system.services.lang.Lang)3 SymbolicLink (com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)2 IPage (com.agiletec.aps.system.services.page.IPage)1 IPageManager (com.agiletec.aps.system.services.page.IPageManager)1 SymbolicLinkValidator (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator)1 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)1 BatchUpdateException (java.sql.BatchUpdateException)1 PreparedStatement (java.sql.PreparedStatement)1