CCM NG/ccm-cms: Additional fields for content item to provide easier access to auditing data.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4586 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2017-02-21 14:20:32 +00:00
parent d821dbe5d7
commit faa27466bf
8 changed files with 312 additions and 158 deletions

View File

@ -50,15 +50,12 @@ import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Join; import javax.persistence.criteria.Join;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import org.hibernate.envers.AuditReader;
/** /**
* *
@ -73,6 +70,9 @@ public class FolderBrowserController {
@Inject @Inject
private EntityManager entityManager; private EntityManager entityManager;
@Inject
private AuditReader auditReader;
@Inject @Inject
private CcmObjectRepository objectRepo; private CcmObjectRepository objectRepo;
@ -158,9 +158,11 @@ public class FolderBrowserController {
criteriaQuery criteriaQuery
.select(builder.count(from)) .select(builder.count(from))
.where(builder.or( .where(builder.or(
from.in(findSubFolders(folder, filterTerm)), from.in(findSubFolders(folder,
from.in(findItemsInFolder(folder, filterTerm))))) filterTerm)),
.getSingleResult(); from.in(findItemsInFolder(folder,
filterTerm))))).
getSingleResult();
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -300,8 +302,9 @@ public class FolderBrowserController {
return entityManager.createQuery( return entityManager.createQuery(
query.where(builder.and( query.where(builder.and(
builder.equal(from.get("parentCategory"), folder), builder.equal(from.get("parentCategory"), folder),
builder.like(builder.lower(from.get("name")), filterTerm)))) builder.
.getResultList(); like(builder.lower(from.get("name")), filterTerm)))).
getResultList();
} }

View File

@ -56,6 +56,7 @@ import javax.persistence.TemporalType;
import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.search.annotations.IndexedEmbedded;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import org.hibernate.envers.NotAudited;
import static org.librecms.CmsConstants.*; import static org.librecms.CmsConstants.*;
@ -104,7 +105,8 @@ import static org.librecms.CmsConstants.*;
query = "SELECT i FROM ContentItem i " query = "SELECT i FROM ContentItem i "
+ "JOIN i.categories c " + "JOIN i.categories c "
+ "WHERE c.category = :folder " + "WHERE c.category = :folder "
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
+ "' "
+ "AND i.displayName = :name") + "AND i.displayName = :name")
, ,
@NamedQuery( @NamedQuery(
@ -112,7 +114,8 @@ import static org.librecms.CmsConstants.*;
query = "SELECT COUNT(i) FROM ContentItem i " query = "SELECT COUNT(i) FROM ContentItem i "
+ "JOIN i.categories c " + "JOIN i.categories c "
+ "WHERE c.category = :folder " + "WHERE c.category = :folder "
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' " + "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
+ "' "
+ "AND i.displayName = :name") + "AND i.displayName = :name")
, ,
@NamedQuery( @NamedQuery(
@ -260,6 +263,58 @@ public class ContentItem extends CcmObject implements Serializable {
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private Workflow workflow; private Workflow workflow;
/**
* Date when the item was created. This information is also available from
* the revision managed by Envers, but getting access to them involves some
* complex queries. Also it is not possible to get the creation date (date
* of the first entity) together with the last modified date (date of the
* last revision/current revision) of the item.
*/
@Column(name = "CREATION_DATE")
@Temporal(TemporalType.TIMESTAMP)
@NotAudited
private Date creationDate;
/**
* Date the item was last modified. This information is also available from
* the revision managed by Envers, but getting access to them involves some
* complex queries. Also it is not possible to get the creation date (date
* of the first entity) together with the last modified date (date of the
* last revision/current revision) of the item.
*/
@Column(name = "LAST_MODIFIED")
@Temporal(TemporalType.TIMESTAMP)
@NotAudited
private Date lastModified;
/**
* The name of the user which created the item. This information is also
* available from the revision managed by Envers, but getting access to them
* involves some complex queries. Also it is not possible to get the
* creation user (the user which created the first entity) together with the
* last modifying user (user which created the last revision/current
* revision) of the item.
*
* Please note that there is no grantee that the user still exists.
*/
@Column(name = "CREATION_USER_NAME")
@NotAudited
private String creationUserName;
/**
* The name of the user which was the last one which modified the item. This
* information is also available from the revision managed by Envers, but
* getting access to them involves some complex queries. Also it is not
* possible to get the creation user (the user which created the first
* entity) together with the last modifying user (user which created the
* last revision/current revision) of the item.
*
* Please note that there is no grantee that the user still exists.
*/
@Column(name = "LAST_MODIFING_USER_NAME")
@NotAudited
private String lastModifyingUserName;
public ContentItem() { public ContentItem() {
name = new LocalizedString(); name = new LocalizedString();
title = new LocalizedString(); title = new LocalizedString();
@ -376,6 +431,38 @@ public class ContentItem extends CcmObject implements Serializable {
this.workflow = workflow; this.workflow = workflow;
} }
public Date getCreationDate() {
return new Date(creationDate.getTime());
}
public void setCreationDate(final Date creationDate) {
this.creationDate = new Date(creationDate.getTime());
}
public Date getLastModified() {
return new Date(lastModified.getTime());
}
public void setLastModified(final Date lastModified) {
this.lastModified = new Date(lastModified.getTime());
}
public String getCreationUserName() {
return creationUserName;
}
public void setCreationUserName(final String creationUserName) {
this.creationUserName = creationUserName;
}
public String getLastModifyingUserName() {
return lastModifyingUserName;
}
public void setLastModifyingUserName(final String lastModifyingUserName) {
this.lastModifyingUserName = lastModifyingUserName;
}
@Override @Override
public int hashCode() { public int hashCode() {
int hash = super.hashCode(); int hash = super.hashCode();

View File

@ -18,6 +18,7 @@
*/ */
package org.librecms.contentsection; package org.librecms.contentsection;
import java.util.Date;
import org.libreccm.auditing.AbstractAuditedEntityRepository; import org.libreccm.auditing.AbstractAuditedEntityRepository;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
@ -31,6 +32,8 @@ import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.libreccm.security.Shiro;
import org.libreccm.security.User;
import org.libreccm.workflow.Workflow; import org.libreccm.workflow.Workflow;
/** /**
@ -48,6 +51,9 @@ public class ContentItemRepository
@Inject @Inject
private FolderRepository folderRepo; private FolderRepository folderRepo;
@Inject
private Shiro shiro;
@Override @Override
public Long getEntityId(final ContentItem item) { public Long getEntityId(final ContentItem item) {
return item.getObjectId(); return item.getObjectId();
@ -347,4 +353,26 @@ public class ContentItemRepository
} }
} }
@Override
public void save(final ContentItem item) {
final Date now = new Date();
final Optional<User> user = shiro.getUser();
final String userName;
if (user.isPresent()) {
userName = user.get().getName();
} else {
userName = "--unknown--";
}
if (isNew(item)) {
item.setCreationDate(now);
item.setCreationUserName(userName);
} else {
item.setLastModified(now);
item.setLastModifyingUserName(userName);
}
super.save(item);
}
} }

View File

@ -0,0 +1,12 @@
alter table CCM_CMS.CONTENT_ITEMS
add column CREATION_DATE timestamp;
alter table CCM_CMS.CONTENT_ITEMS
add column CREATION_USER_NAME varchar(255);
alter table CCM_CMS.CONTENT_ITEMS
add column LAST_MODIFIED timestamp;
alter table CCM_CMS.CONTENT_ITEMS
add column LAST_MODIFING_USER_NAME varchar(255);

View File

@ -0,0 +1,12 @@
alter table CCM_CMS.CONTENT_ITEMS
add column CREATION_DATE timestamp;
alter table CCM_CMS.CONTENT_ITEMS
add column CREATION_USER_NAME varchar(255);
alter table CCM_CMS.CONTENT_ITEMS
add column LAST_MODIFIED timestamp;
alter table CCM_CMS.CONTENT_ITEMS
add column LAST_MODIFING_USER_NAME varchar(255);

View File

@ -270,7 +270,11 @@ create schema CCM_CORE;
create table CCM_CMS.CONTENT_ITEMS ( create table CCM_CMS.CONTENT_ITEMS (
ANCESTORS varchar(1024), ANCESTORS varchar(1024),
CREATION_DATE timestamp,
CREATION_USER_NAME varchar(255),
ITEM_UUID varchar(255) not null, ITEM_UUID varchar(255) not null,
LAST_MODIFIED timestamp,
LAST_MODIFING_USER_NAME varchar(255),
LAUNCH_DATE date, LAUNCH_DATE date,
VERSION varchar(255), VERSION varchar(255),
OBJECT_ID bigint not null, OBJECT_ID bigint not null,

View File

@ -270,7 +270,11 @@ create schema CCM_CORE;
create table CCM_CMS.CONTENT_ITEMS ( create table CCM_CMS.CONTENT_ITEMS (
ANCESTORS varchar(1024), ANCESTORS varchar(1024),
CREATION_DATE timestamp,
CREATION_USER_NAME varchar(255),
ITEM_UUID varchar(255) not null, ITEM_UUID varchar(255) not null,
LAST_MODIFIED timestamp,
LAST_MODIFING_USER_NAME varchar(255),
LAUNCH_DATE date, LAUNCH_DATE date,
VERSION varchar(255), VERSION varchar(255),
OBJECT_ID int8 not null, OBJECT_ID int8 not null,

View File

@ -270,7 +270,11 @@ create schema CCM_CORE;
create table CCM_CMS.CONTENT_ITEMS ( create table CCM_CMS.CONTENT_ITEMS (
ANCESTORS varchar(1024), ANCESTORS varchar(1024),
CREATION_DATE timestamp,
CREATION_USER_NAME varchar(255),
ITEM_UUID varchar(255) not null, ITEM_UUID varchar(255) not null,
LAST_MODIFIED timestamp,
LAST_MODIFING_USER_NAME varchar(255),
LAUNCH_DATE date, LAUNCH_DATE date,
VERSION varchar(255), VERSION varchar(255),
OBJECT_ID bigint not null, OBJECT_ID bigint not null,