Search in sources :

Example 6 with IContentManager

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

the class TestContentAuthorization method testCheckAdminUser.

public void testCheckAdminUser() throws Throwable {
    UserDetails adminUser = this.getUser("admin");
    assertNotNull(adminUser);
    assertEquals("admin", adminUser.getUsername());
    assertEquals(1, adminUser.getAuthorizations().size());
    IContentManager contentManager = (IContentManager) this.getService(JacmsSystemConstants.CONTENT_MANAGER);
    Content content = contentManager.loadContent("ART111", true);
    boolean check = this._authorizationManager.isAuth(adminUser, content);
    assertTrue(check);
    content = contentManager.loadContent("EVN25", true);
    check = this._authorizationManager.isAuth(adminUser, content);
    assertTrue(check);
    content = contentManager.loadContent("EVN41", true);
    check = this._authorizationManager.isAuth(adminUser, content);
    assertTrue(check);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 7 with IContentManager

use of com.agiletec.plugins.jacms.aps.system.services.content.IContentManager 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 8 with IContentManager

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

the class ContentActionHelper method scanReferences.

/**
 * Controlla le referenziazioni di un contenuto. Verifica la referenziazione
 * di un contenuto con altri contenuti o pagine nel caso di operazioni di
 * ripubblicazione di contenuti non del gruppo ad accesso libero.
 * L'operazione si rende necessaria per ovviare a casi nel cui il contenuto,
 * di un particolare gruppo, sia stato pubblicato precedentemente in una
 * pagina o referenziato in un'altro contenuto grazie alla associazione di
 * questo con altri gruppi abilitati alla visualizzazione. Il controllo
 * evidenzia quali devono essere i gruppi al quale il contenuto deve essere
 * necessariamente associato (ed il perchè) per salvaguardare le precedenti
 * relazioni.
 *
 * @param content
 * Il contenuto da analizzare.
 * @param action
 * L'action da valorizzare con i messaggi di errore.
 * @throws ApsSystemException
 * In caso di errore.
 */
@Override
public void scanReferences(Content content, ActionSupport action) throws ApsSystemException {
    if (!Group.FREE_GROUP_NAME.equals(content.getMainGroup()) && !content.getGroups().contains(Group.FREE_GROUP_NAME)) {
        HttpServletRequest request = ServletActionContext.getRequest();
        try {
            String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(ContentUtilizer.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 loading ReferencingObject ", t);
                    service = null;
                }
                if (service != null) {
                    ContentUtilizer contentUtilizer = (ContentUtilizer) service;
                    List<Object> utilizers = contentUtilizer.getContentUtilizers(content.getId());
                    if (null == utilizers) {
                        continue;
                    }
                    Lang lang = this.getLangManager().getDefaultLang();
                    for (int j = 0; j < utilizers.size(); j++) {
                        Object object = utilizers.get(j);
                        if (service instanceof IContentManager && object instanceof String) {
                            // Content
                            // ID
                            Content refContent = this.getContentManager().loadContent(object.toString(), true);
                            if (!content.getMainGroup().equals(refContent.getMainGroup()) && !content.getGroups().contains(refContent.getMainGroup())) {
                                String[] args = { this.getGroupManager().getGroup(refContent.getMainGroup()).getDescription(), object.toString() + " '" + refContent.getDescription() + "'" };
                                action.addFieldError("mainGroup", action.getText("error.content.referencedContent.wrongGroups", args));
                            }
                        } else if (object instanceof IPage) {
                            // Content ID
                            IPage page = (IPage) object;
                            // page online, must be done the same check
                            if (!CmsPageUtil.isContentPublishableOnPageOnline(content, page)) {
                                PageMetadata metadata = page.getMetadata();
                                List<String> pageGroups = new ArrayList<String>();
                                pageGroups.add(page.getGroup());
                                if (metadata != null && null != metadata.getExtraGroups()) {
                                    pageGroups.addAll(metadata.getExtraGroups());
                                }
                                String[] args = { pageGroups.toString(), page.getTitle(lang.getCode()) };
                                action.addFieldError("mainGroup", action.getText("error.content.referencedPage.wrongGroups", args));
                            }
                        }
                    }
                }
            }
        } catch (Throwable t) {
            throw new ApsSystemException("Error in hasReferencingObject method", t);
        }
    }
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ContentUtilizer(com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(com.agiletec.aps.system.services.page.IPage) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with IContentManager

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

the class PageAction method validate.

@Override
public void validate() {
    super.validate();
    try {
        if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT) {
            return;
        }
        IContentManager contentManager = (IContentManager) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_MANAGER, this.getRequest());
        IPage page = this.createTempPage();
        Collection<Content> contents = this.getPublishedContents(this.getPageCode());
        for (Content content : contents) {
            if (null != content && !CmsPageUtil.isContentPublishableOnPageDraft(content, page)) {
                List<String> contentGroups = new ArrayList<String>();
                contentGroups.add(content.getMainGroup());
                if (null != content.getGroups()) {
                    contentGroups.addAll(content.getGroups());
                }
                this.addFieldError("extraGroups", this.getText("error.page.extraGoups.invalidGroupsForPublishedContent", new String[] { contentGroups.toString(), content.getId(), content.getDescription() }));
            }
        }
        List<String> linkingContentsVo = ((PageUtilizer) contentManager).getPageUtilizers(this.getPageCode());
        if (null != linkingContentsVo) {
            for (int i = 0; i < linkingContentsVo.size(); i++) {
                String contentId = linkingContentsVo.get(i);
                Content linkingContent = contentManager.loadContent(contentId, true);
                if (null != linkingContent && !CmsPageUtil.isPageLinkableByContentDraft(page, linkingContent)) {
                    this.addFieldError("extraGroups", this.getText("error.page.extraGoups.pageHasToBeFree", new String[] { linkingContent.getId(), linkingContent.getDescription() }));
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error on validate page", t);
        throw new RuntimeException("Error on validate page", t);
    }
}
Also used : PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) IPage(com.agiletec.aps.system.services.page.IPage) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList)

Aggregations

IContentManager (com.agiletec.plugins.jacms.aps.system.services.content.IContentManager)9 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)5 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 IPage (com.agiletec.aps.system.services.page.IPage)2 IContentModelManager (com.agiletec.plugins.jacms.aps.system.services.contentmodel.IContentModelManager)2 IContentPageMapperManager (com.agiletec.plugins.jacms.aps.system.services.contentpagemapper.IContentPageMapperManager)2 IContentDispenser (com.agiletec.plugins.jacms.aps.system.services.dispenser.IContentDispenser)2 ILinkResolverManager (com.agiletec.plugins.jacms.aps.system.services.linkresolver.ILinkResolverManager)2 IContentRenderer (com.agiletec.plugins.jacms.aps.system.services.renderer.IContentRenderer)2 IResourceManager (com.agiletec.plugins.jacms.aps.system.services.resource.IResourceManager)2 ICmsSearchEngineManager (com.agiletec.plugins.jacms.aps.system.services.searchengine.ICmsSearchEngineManager)2 ArrayList (java.util.ArrayList)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 ICategoryManager (com.agiletec.aps.system.services.category.ICategoryManager)1 Group (com.agiletec.aps.system.services.group.Group)1 Lang (com.agiletec.aps.system.services.lang.Lang)1 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)1 PageUtilizer (com.agiletec.aps.system.services.page.PageUtilizer)1 Widget (com.agiletec.aps.system.services.page.Widget)1 ApsProperties (com.agiletec.aps.util.ApsProperties)1