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;
}
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;
}
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;
}
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;
}
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));
}
}
Aggregations