Search in sources :

Example 1 with ContentUtilizer

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

the class ContentHelper method getContentUtilizers.

@Override
public List<ContentUtilizer> getContentUtilizers() {
    ApplicationContext applicationContext = this.getApplicationContext();
    String[] defNames = applicationContext.getBeanNamesForType(ContentUtilizer.class);
    List<ContentUtilizer> contentUtilizers = new ArrayList<ContentUtilizer>(defNames.length);
    for (String defName : defNames) {
        Object service = null;
        try {
            service = applicationContext.getBean(defName);
            if (service != null) {
                ContentUtilizer contentUtilizer = (ContentUtilizer) service;
                contentUtilizers.add(contentUtilizer);
            }
        } catch (Throwable t) {
            _logger.error("error loading ReferencingObject {}", defName, t);
        }
    }
    return contentUtilizers;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ArrayList(java.util.ArrayList) ContentUtilizer(com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer)

Example 2 with ContentUtilizer

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

the class ContentAction method getShowingPageSelectItems.

/**
 * Return the list of the showing pages of the current content on edit
 *
 * @return The list of the showing pages.
 */
public List<SelectItem> getShowingPageSelectItems() {
    List<SelectItem> pageItems = new ArrayList<SelectItem>();
    try {
        Content content = this.getContent();
        if (null != content) {
            IPage defaultViewerPage = this.getPageManager().getOnlinePage(content.getViewPage());
            if (null != defaultViewerPage && CmsPageUtil.isOnlineFreeViewerPage(defaultViewerPage, null)) {
                pageItems.add(new SelectItem("", this.getText("label.default")));
            }
            if (null == content.getId())
                return pageItems;
            ContentUtilizer pageManagerWrapper = (ContentUtilizer) ApsWebApplicationUtils.getBean(JacmsSystemConstants.PAGE_MANAGER_WRAPPER, this.getRequest());
            List<IPage> pages = pageManagerWrapper.getContentUtilizers(content.getId());
            for (int i = 0; i < pages.size(); i++) {
                IPage page = pages.get(i);
                String pageCode = page.getCode();
                pageItems.add(new SelectItem(pageCode, super.getTitle(pageCode, page.getTitles())));
            }
        }
    } catch (Throwable t) {
        _logger.error("Error on extracting showing pages", t);
        throw new RuntimeException("Error on extracting showing pages", t);
    }
    return pageItems;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) SelectItem(com.agiletec.aps.util.SelectItem) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList) ContentUtilizer(com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer)

Example 3 with ContentUtilizer

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

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

Aggregations

ContentUtilizer (com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)3 ArrayList (java.util.ArrayList)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 IPage (com.agiletec.aps.system.services.page.IPage)2 Lang (com.agiletec.aps.system.services.lang.Lang)1 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)1 UserDetails (com.agiletec.aps.system.services.user.UserDetails)1 SelectItem (com.agiletec.aps.util.SelectItem)1 IContentManager (com.agiletec.plugins.jacms.aps.system.services.content.IContentManager)1 ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)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 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)1 ApplicationContext (org.springframework.context.ApplicationContext)1