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
Former-commit-id: 251c2efb7a
pull/2/head
parent
b51ca7fcad
commit
9d18356999
|
|
@ -50,15 +50,12 @@ import javax.annotation.PostConstruct;
|
|||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.Order;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
import org.hibernate.envers.AuditReader;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -73,6 +70,9 @@ public class FolderBrowserController {
|
|||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Inject
|
||||
private AuditReader auditReader;
|
||||
|
||||
@Inject
|
||||
private CcmObjectRepository objectRepo;
|
||||
|
||||
|
|
@ -158,9 +158,11 @@ public class FolderBrowserController {
|
|||
criteriaQuery
|
||||
.select(builder.count(from))
|
||||
.where(builder.or(
|
||||
from.in(findSubFolders(folder, filterTerm)),
|
||||
from.in(findItemsInFolder(folder, filterTerm)))))
|
||||
.getSingleResult();
|
||||
from.in(findSubFolders(folder,
|
||||
filterTerm)),
|
||||
from.in(findItemsInFolder(folder,
|
||||
filterTerm))))).
|
||||
getSingleResult();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
|
|
@ -300,8 +302,9 @@ public class FolderBrowserController {
|
|||
return entityManager.createQuery(
|
||||
query.where(builder.and(
|
||||
builder.equal(from.get("parentCategory"), folder),
|
||||
builder.like(builder.lower(from.get("name")), filterTerm))))
|
||||
.getResultList();
|
||||
builder.
|
||||
like(builder.lower(from.get("name")), filterTerm)))).
|
||||
getResultList();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ import javax.persistence.TemporalType;
|
|||
import org.hibernate.search.annotations.IndexedEmbedded;
|
||||
|
||||
import javax.persistence.FetchType;
|
||||
import org.hibernate.envers.NotAudited;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
|
|
@ -104,7 +105,8 @@ import static org.librecms.CmsConstants.*;
|
|||
query = "SELECT i FROM ContentItem i "
|
||||
+ "JOIN i.categories c "
|
||||
+ "WHERE c.category = :folder "
|
||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' "
|
||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||
+ "' "
|
||||
+ "AND i.displayName = :name")
|
||||
,
|
||||
@NamedQuery(
|
||||
|
|
@ -112,7 +114,8 @@ import static org.librecms.CmsConstants.*;
|
|||
query = "SELECT COUNT(i) FROM ContentItem i "
|
||||
+ "JOIN i.categories c "
|
||||
+ "WHERE c.category = :folder "
|
||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' "
|
||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||
+ "' "
|
||||
+ "AND i.displayName = :name")
|
||||
,
|
||||
@NamedQuery(
|
||||
|
|
@ -260,6 +263,58 @@ public class ContentItem extends CcmObject implements Serializable {
|
|||
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
|
||||
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() {
|
||||
name = new LocalizedString();
|
||||
title = new LocalizedString();
|
||||
|
|
@ -376,6 +431,38 @@ public class ContentItem extends CcmObject implements Serializable {
|
|||
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
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.librecms.contentsection;
|
||||
|
||||
import java.util.Date;
|
||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.core.CcmObject;
|
||||
|
|
@ -31,6 +32,8 @@ import javax.enterprise.context.RequestScoped;
|
|||
import javax.inject.Inject;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import org.libreccm.security.Shiro;
|
||||
import org.libreccm.security.User;
|
||||
import org.libreccm.workflow.Workflow;
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +51,9 @@ public class ContentItemRepository
|
|||
@Inject
|
||||
private FolderRepository folderRepo;
|
||||
|
||||
@Inject
|
||||
private Shiro shiro;
|
||||
|
||||
@Override
|
||||
public Long getEntityId(final ContentItem item) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -270,7 +270,11 @@ create schema CCM_CORE;
|
|||
|
||||
create table CCM_CMS.CONTENT_ITEMS (
|
||||
ANCESTORS varchar(1024),
|
||||
CREATION_DATE timestamp,
|
||||
CREATION_USER_NAME varchar(255),
|
||||
ITEM_UUID varchar(255) not null,
|
||||
LAST_MODIFIED timestamp,
|
||||
LAST_MODIFING_USER_NAME varchar(255),
|
||||
LAUNCH_DATE date,
|
||||
VERSION varchar(255),
|
||||
OBJECT_ID bigint not null,
|
||||
|
|
|
|||
|
|
@ -270,7 +270,11 @@ create schema CCM_CORE;
|
|||
|
||||
create table CCM_CMS.CONTENT_ITEMS (
|
||||
ANCESTORS varchar(1024),
|
||||
CREATION_DATE timestamp,
|
||||
CREATION_USER_NAME varchar(255),
|
||||
ITEM_UUID varchar(255) not null,
|
||||
LAST_MODIFIED timestamp,
|
||||
LAST_MODIFING_USER_NAME varchar(255),
|
||||
LAUNCH_DATE date,
|
||||
VERSION varchar(255),
|
||||
OBJECT_ID int8 not null,
|
||||
|
|
|
|||
|
|
@ -270,7 +270,11 @@ create schema CCM_CORE;
|
|||
|
||||
create table CCM_CMS.CONTENT_ITEMS (
|
||||
ANCESTORS varchar(1024),
|
||||
CREATION_DATE timestamp,
|
||||
CREATION_USER_NAME varchar(255),
|
||||
ITEM_UUID varchar(255) not null,
|
||||
LAST_MODIFIED timestamp,
|
||||
LAST_MODIFING_USER_NAME varchar(255),
|
||||
LAUNCH_DATE date,
|
||||
VERSION varchar(255),
|
||||
OBJECT_ID bigint not null,
|
||||
|
|
|
|||
Loading…
Reference in New Issue