Search in sources :

Example 36 with Content

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

the class AbstractResourceAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        if (null == this.getResources()) {
            return errors;
        }
        List<Lang> langs = super.getLangManager().getLangs();
        for (int i = 0; i < langs.size(); i++) {
            Lang lang = langs.get(i);
            ResourceInterface resource = this.getResource(lang.getCode());
            if (null == resource) {
                continue;
            }
            AttributeTracer resourceTracer = (AttributeTracer) tracer.clone();
            resourceTracer.setLang(lang);
            String resourceMainGroup = resource.getMainGroup();
            Content parentContent = (Content) this.getParentEntity();
            if (!resourceMainGroup.equals(Group.FREE_GROUP_NAME) && !resourceMainGroup.equals(parentContent.getMainGroup()) && !parentContent.getGroups().contains(resourceMainGroup)) {
                AttributeFieldError fieldError = new AttributeFieldError(this, ICmsAttributeErrorCodes.INVALID_RESOURCE_GROUPS, resourceTracer);
                fieldError.setMessage("Invalid resource group - " + resourceMainGroup);
                errors.add(fieldError);
            }
        }
    } catch (Throwable t) {
        logger.error("Error validating text attribute", t);
        throw new RuntimeException("Error validating text attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 37 with Content

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

the class ContentTypeDOM method createEntityType.

@Override
protected IApsEntity createEntityType(Element contentElem, Class entityClass) throws ApsSystemException {
    Content content = (Content) super.createEntityType(contentElem, entityClass);
    content.setId(null);
    String viewPage = this.extractXmlAttribute(contentElem, "viewpage", true);
    if (!viewPage.equals(NULL_VALUE)) {
        content.setViewPage(viewPage);
    }
    String listModel = this.extractXmlAttribute(contentElem, "listmodel", true);
    if (!listModel.equals(NULL_VALUE)) {
        content.setListModel(listModel);
    }
    String defaultModel = this.extractXmlAttribute(contentElem, "defaultmodel", true);
    if (!defaultModel.equals(NULL_VALUE)) {
        content.setDefaultModel(defaultModel);
    }
    content.setStatus(Content.STATUS_NEW);
    return content;
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 38 with Content

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

the class BaseContentDispenser method getRenderizationInfo.

protected ContentRenderizationInfo getRenderizationInfo(PublicContentAuthorizationInfo authInfo, String contentId, long modelId, String langCode, RequestContext reqCtx, boolean cacheable) {
    ContentRenderizationInfo renderInfo = null;
    try {
        UserDetails currentUser = (null != reqCtx) ? (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER) : null;
        List<Group> userGroups = (null != currentUser) ? this.getAuthorizationManager().getUserGroups(currentUser) : new ArrayList<Group>();
        if (authInfo.isUserAllowed(userGroups)) {
            renderInfo = this.getBaseRenderizationInfo(authInfo, contentId, modelId, langCode, currentUser, reqCtx, cacheable);
            if (null == renderInfo) {
                return null;
            }
        } else {
            String renderedContent = "Current user '" + currentUser.getUsername() + "' can't view this content";
            Content contentToRender = this.getContentManager().loadContent(contentId, true, cacheable);
            renderInfo = new ContentRenderizationInfo(contentToRender, renderedContent, modelId, langCode, null);
            renderInfo.setRenderedContent(renderedContent);
            return renderInfo;
        }
    } catch (Throwable t) {
        _logger.error("Error while rendering content {}", contentId, t);
        return null;
    }
    return renderInfo;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 39 with Content

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

the class BaseContentDispenser method getBaseRenderizationInfo.

public ContentRenderizationInfo getBaseRenderizationInfo(PublicContentAuthorizationInfo authInfo, String contentId, long modelId, String langCode, UserDetails currentUser, RequestContext reqCtx, boolean cacheable) {
    ContentRenderizationInfo renderInfo = null;
    try {
        List<Group> userGroups = (null != currentUser) ? this.getAuthorizationManager().getUserGroups(currentUser) : new ArrayList<Group>();
        if (authInfo.isUserAllowed(userGroups)) {
            Content contentToRender = this.getContentManager().loadContent(contentId, true, cacheable);
            String renderedContent = this.buildRenderedContent(contentToRender, modelId, langCode, reqCtx);
            if (null != renderedContent && renderedContent.trim().length() > 0) {
                List<AttributeRole> roles = this.getContentManager().getAttributeRoles();
                renderInfo = new ContentRenderizationInfo(contentToRender, renderedContent, modelId, langCode, roles);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error while rendering content {}", contentId, t);
        return null;
    }
    return renderInfo;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeRole(com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)

Example 40 with Content

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

the class TestActivityStream method testActivityStreamSearchBean.

public void testActivityStreamSearchBean() throws Throwable {
    // "coach" group
    Content content = this._contentManager.loadContent("EVN41", false);
    String contentOnSessionMarker = AbstractContentAction.buildContentOnSessionMarker(content, ApsAdminSystemConstants.ADD);
    content.setId(null);
    String contentId = null;
    Date dateBeforeSave = new Date();
    Thread.sleep(1000);
    try {
        this.getRequest().getSession().setAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_PREXIX + contentOnSessionMarker, content);
        this.initContentAction("/do/jacms/Content", "save", contentOnSessionMarker);
        this.setUserOnSession("admin");
        String result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        contentId = content.getId();
        assertNotNull(this._contentManager.loadContent(contentId, false));
        super.waitThreads(IActionLogManager.LOG_APPENDER_THREAD_NAME_PREFIX);
        Date firstDate = new Date();
        ActionLogRecordSearchBean searchBean = this._helper.createSearchBean("admin", null, null, null, null, null);
        List<Integer> ids = this._actionLoggerManager.getActionRecords(searchBean);
        assertEquals(1, ids.size());
        ActivityStreamSeachBean activityStreamSeachBean = new ActivityStreamSeachBean();
        activityStreamSeachBean.setEndCreation(firstDate);
        List<Integer> activityStreamEndDate = this._actionLoggerManager.getActivityStream(activityStreamSeachBean);
        assertEquals(1, activityStreamEndDate.size());
        activityStreamSeachBean = new ActivityStreamSeachBean();
        activityStreamSeachBean.setEndUpdate(dateBeforeSave);
        List<Integer> activityStreamDateBeforeSave = this._actionLoggerManager.getActivityStream(activityStreamSeachBean);
        assertEquals(0, activityStreamDateBeforeSave.size());
        Thread.sleep(1000);
        this.getRequest().getSession().setAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_PREXIX + contentOnSessionMarker, content);
        this.initContentAction("/do/jacms/Content", "save", contentOnSessionMarker);
        this.setUserOnSession("admin");
        result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        contentId = content.getId();
        assertNotNull(this._contentManager.loadContent(contentId, false));
        super.waitThreads(IActionLogManager.LOG_APPENDER_THREAD_NAME_PREFIX);
        activityStreamSeachBean = new ActivityStreamSeachBean();
        activityStreamSeachBean.setStartUpdate(dateBeforeSave);
        activityStreamSeachBean.setEndUpdate(firstDate);
        List<Integer> activityStreamBetweenSave = this._actionLoggerManager.getActivityStream(activityStreamSeachBean);
        assertEquals(1, activityStreamBetweenSave.size());
        activityStreamSeachBean = new ActivityStreamSeachBean();
        activityStreamSeachBean.setStartUpdate(dateBeforeSave);
        activityStreamSeachBean.setEndUpdate(new Date());
        List<Integer> activityStreamBetweenSave2 = this._actionLoggerManager.getActivityStream(activityStreamSeachBean);
        assertEquals(2, activityStreamBetweenSave2.size());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._contentManager.deleteContent(content);
        assertNull(this._contentManager.loadContent(contentId, false));
    }
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ActivityStreamSeachBean(org.entando.entando.aps.system.services.actionlog.model.ActivityStreamSeachBean) ActionLogRecordSearchBean(org.entando.entando.aps.system.services.actionlog.model.ActionLogRecordSearchBean) Date(java.util.Date)

Aggregations

Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)227 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)55 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)35 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)29 ArrayList (java.util.ArrayList)26 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)17 ActionSupport (com.opensymphony.xwork2.ActionSupport)14 List (java.util.List)14 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)13 HttpSession (javax.servlet.http.HttpSession)13 UserDetails (com.agiletec.aps.system.services.user.UserDetails)12 IPage (com.agiletec.aps.system.services.page.IPage)10 Date (java.util.Date)8 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)7 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)7 LinkAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute)7 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)7 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)7 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)6 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6