[FEATURE]
- adds three named queries in ResourceRepository - adds class annotations for repositories in ResourceRepository - adds class ResourceManager with the corresponding class annotations - adds the defined named queries in the class annotation of Resource - adds some entity constraints in Resource for 'name' and 'path' - corrects the implementation of the 'isNew'-method in ResourceRepository git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3662 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
ed43c999d9
commit
ba1e89fa76
|
|
@ -18,12 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.core;
|
package org.libreccm.core;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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.TypedQuery;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A repository class for retrieving, storing and deleting {@link Group}s.
|
* A repository class for retrieving, storing and deleting {@link Group}s.
|
||||||
|
|
@ -59,7 +58,7 @@ public class GroupRepository extends AbstractEntityRepository<Long, Group> {
|
||||||
final List<Group> result = query.getResultList();
|
final List<Group> result = query.getResultList();
|
||||||
|
|
||||||
//Check if result list is empty and if not return the first element.
|
//Check if result list is empty and if not return the first element.
|
||||||
//If their ist a result than there can only be one because the
|
//If their is a result than there can only be one because the
|
||||||
//name column of group has a unique constraint.
|
//name column of group has a unique constraint.
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.core;
|
package org.libreccm.core;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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.TypedQuery;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repository class for retrieving, storing and deleting permissions.
|
* Repository class for retrieving, storing and deleting permissions.
|
||||||
|
|
@ -57,7 +56,7 @@ public class PermissionRepository
|
||||||
@Override
|
@Override
|
||||||
public boolean isNew(final Permission entity) {
|
public boolean isNew(final Permission entity) {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new IllegalArgumentException("Entity to save can't be null");
|
throw new IllegalArgumentException("Entity to save can't be null.");
|
||||||
}
|
}
|
||||||
return entity.getPermissionId() == 0;
|
return entity.getPermissionId() == 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Lob;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
@ -37,6 +38,7 @@ import java.util.Objects;
|
||||||
* will be persisted into the database.
|
* will be persisted into the database.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(schema = "CCM_DOCREPO", name = "BLOB_OBJECTS")
|
@Table(schema = "CCM_DOCREPO", name = "BLOB_OBJECTS")
|
||||||
|
|
@ -83,11 +85,11 @@ public class BlobObject implements Serializable {
|
||||||
this.blobObjectId = blobObjectId;
|
this.blobObjectId = blobObjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Blob getContent() {
|
public byte[] getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContent(Blob content) {
|
public void setContent(byte[] content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import javax.persistence.Table;
|
||||||
* into the database. Instance variables are inherited from {@link Resource}.
|
* into the database. Instance variables are inherited from {@link Resource}.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(schema = "CCM_DOCREPO", name = "FILES")
|
@Table(schema = "CCM_DOCREPO", name = "FILES")
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import javax.persistence.Table;
|
||||||
* into the database. Instance variables are inherited from {@link Resource}.
|
* into the database. Instance variables are inherited from {@link Resource}.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(schema = "CCM_DOCREPO", name = "FOLDERS")
|
@Table(schema = "CCM_DOCREPO", name = "FOLDERS")
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import javax.persistence.Table;
|
||||||
* form {@link Portlet}.
|
* form {@link Portlet}.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(schema = "CCM_DOCREPO", name = "REC_UPD_DOCS_PORTLETS")
|
@Table(schema = "CCM_DOCREPO", name = "REC_UPD_DOCS_PORTLETS")
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import javax.persistence.Table;
|
||||||
* database. Instance variables are inherited from {@link Application}.
|
* database. Instance variables are inherited from {@link Application}.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(schema = "CCM_DOCREPO", name = "REPOSITORIES")
|
@Table(schema = "CCM_DOCREPO", name = "REPOSITORIES")
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,17 @@ import java.util.List;
|
||||||
* {@link Folder}
|
* {@link Folder}
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
*/
|
*/
|
||||||
@Entity(name = "DocRepoResource")
|
@Entity(name = "DocRepoResource")
|
||||||
@Table(schema = "CCM_DOCREPO", name = "RESOURCES")
|
@Table(schema = "CCM_DOCREPO", name = "RESOURCES")
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "findChildrenByParent",
|
|
||||||
query = "SELECT r FROM DocRepoResource r WHERE r.parent = :parentID"),
|
|
||||||
@NamedQuery(name = "findResourceByPath",
|
@NamedQuery(name = "findResourceByPath",
|
||||||
query = "SELECT r FROM DocRepoResource r WHERE r.path = :pathName")})
|
query = "SELECT r FROM DocRepoResource r WHERE r.path = :pathName"),
|
||||||
|
@NamedQuery(name = "findCreatedResourcesFromUser",
|
||||||
|
query = "SELECT r FROM DocRepoResource r WHERE r.creationUser = :user"),
|
||||||
|
@NamedQuery(name = "findModifiedResourcesFromUser",
|
||||||
|
query = "SELECT r FROM DocRepoResource r WHERE r.lastModifiedUser = :user")})
|
||||||
public abstract class Resource extends CcmObject {
|
public abstract class Resource extends CcmObject {
|
||||||
|
|
||||||
private static final long serialVersionUID = -910317798106611214L;
|
private static final long serialVersionUID = -910317798106611214L;
|
||||||
|
|
@ -60,7 +63,7 @@ public abstract class Resource extends CcmObject {
|
||||||
/**
|
/**
|
||||||
* Name of the {@code Resource}.
|
* Name of the {@code Resource}.
|
||||||
*/
|
*/
|
||||||
@Column(name = "NAME")
|
@Column(name = "NAME", length = 512, unique = true, nullable = false)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -80,7 +83,7 @@ public abstract class Resource extends CcmObject {
|
||||||
/**
|
/**
|
||||||
* Path to the {@code Resource}.
|
* Path to the {@code Resource}.
|
||||||
*/
|
*/
|
||||||
@Column(name = "PATH")
|
@Column(name = "PATH", unique = true)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.docrepo;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manager class for complex operations on {@code Resource}-objects.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class ResourceManager {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private transient ResourceRepository resourceRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -20,14 +20,26 @@ package org.libreccm.docrepo;
|
||||||
|
|
||||||
|
|
||||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||||
|
import org.libreccm.core.User;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repository class for retrieving, storing and deleting {@code Resource}s.
|
* Repository class for retrieving, storing and deleting {@code Resource}s.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version 01/10/2015
|
||||||
*/
|
*/
|
||||||
|
@RequestScoped
|
||||||
public class ResourceRepository extends AbstractAuditedEntityRepository<Long, Resource> {
|
public class ResourceRepository extends AbstractAuditedEntityRepository<Long, Resource> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private transient EntityManager entityManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getEntityId(Resource entity) {
|
public Long getEntityId(Resource entity) {
|
||||||
return entity.getObjectId();
|
return entity.getObjectId();
|
||||||
|
|
@ -40,8 +52,64 @@ public class ResourceRepository extends AbstractAuditedEntityRepository<Long, Re
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNew(Resource entity) {
|
public boolean isNew(Resource entity) {
|
||||||
return false;
|
if (entity == null) {
|
||||||
|
throw new IllegalArgumentException("Entity to save can't be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return entity.getObjectId() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a {@code Resource} by its {@code path}.
|
||||||
|
*
|
||||||
|
* @param pathName The {@code path} to the {@code Resource}.
|
||||||
|
*
|
||||||
|
* @return The {@code Resource} identified by the given {@code path}, if there is
|
||||||
|
* such a {@code Resource}, {@code null} if not.
|
||||||
|
*/
|
||||||
|
public Resource findByPathName(final String pathName) {
|
||||||
|
final TypedQuery<Resource> query = entityManager.createNamedQuery(
|
||||||
|
"findResourceByPath", Resource.class);
|
||||||
|
query.setParameter("pathName", pathName);
|
||||||
|
|
||||||
|
final List<Resource> result = query.getResultList();
|
||||||
|
|
||||||
|
//Check if the result list is empty and if not return the first
|
||||||
|
//element. If their is a result than there can only be one because
|
||||||
|
//the path column of resource has a unique constraint.
|
||||||
|
return result.isEmpty() ? null : result.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the {@code Resource}s, a given {@link User} created.
|
||||||
|
*
|
||||||
|
* @param creator The {@link User}, who created the {@code Resource}s.
|
||||||
|
*
|
||||||
|
* @return The {@code Resource}s, created by the given {@link User}, if there
|
||||||
|
* are such {@code Resource}s, {@code EmptyList} if not.
|
||||||
|
*/
|
||||||
|
public List<Resource> findForCreator(final User creator) {
|
||||||
|
final TypedQuery<Resource> query = entityManager.createNamedQuery(
|
||||||
|
"findCreatedResourcesFromUser", Resource.class);
|
||||||
|
query.setParameter("user", creator);
|
||||||
|
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the {@code Resource}s, a given {@link User} last modified.
|
||||||
|
*
|
||||||
|
* @param modifier The {@link User}, who last modified the {@code Resource}s.
|
||||||
|
*
|
||||||
|
* @return The {@code Resource}s, last modified by the given {@link User}, if
|
||||||
|
* there are such {@code Resource}s, {@code EmptyList} if not.
|
||||||
|
*/
|
||||||
|
public List<Resource> findForModifier(final User modifier) {
|
||||||
|
final TypedQuery<Resource> query = entityManager.createNamedQuery(
|
||||||
|
"findModifiedResourcesFromUser", Resource.class);
|
||||||
|
query.setParameter("user", modifier);
|
||||||
|
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue