[UPDATE]
- adds implementation to all resolveId-methods of the IdResolver-classes - modifies generateId-method for PermissionIdGenerator to match the trunk implementation of the idGenerator - adds missing findBy-methods to repositories git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4703 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
d524e7d9fc
commit
d47d36b21e
|
|
@ -80,6 +80,10 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
name = "Category.findByName",
|
||||
query = "SELECT c FROM Category c WHERE c.name = :name")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "Category.findByUuid",
|
||||
query = "SELECT c FROM Category c WHERE c.uuid = :uuid")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "Category.findParentCategory",
|
||||
query = "SELECT c.parentCategory FROM Category c WHERE c = :category")
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class CategoryIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
||||
return null;
|
||||
return categoryRepository.findByUuid(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,15 +26,15 @@ import org.libreccm.security.AuthorizationRequired;
|
|||
import org.libreccm.security.PermissionChecker;
|
||||
import org.libreccm.security.RequiresPrivilege;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Provides CRUB operations for {@link Category} objects.
|
||||
*
|
||||
|
|
@ -88,6 +88,25 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
|
|||
return query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a {@link Category} by its uuid.
|
||||
*
|
||||
* @param uuid The uuid of the item to find
|
||||
*
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<Category> findByUuid(final String uuid) {
|
||||
final TypedQuery<Category> query = getEntityManager().
|
||||
createNamedQuery("Category.findByUuid", Category.class);
|
||||
query.setParameter("uuid", uuid);
|
||||
|
||||
try {
|
||||
return Optional.of(query.getSingleResult());
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Category> findByPath(final String path) {
|
||||
if (path == null || path.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -21,11 +21,16 @@ package org.libreccm.core;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class CcmObjectIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private CcmObjectRepository ccmObjectRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(ObjectIdGenerator.IdKey idKey,
|
||||
Object pojo) {
|
||||
|
|
@ -36,7 +41,7 @@ public class CcmObjectIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
||||
return null;
|
||||
return ccmObjectRepository.findObjectByUuid(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,16 +18,14 @@
|
|||
*/
|
||||
package org.libreccm.core;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.ACCESS_DENIED;
|
||||
|
||||
/**
|
||||
* A repository class for {@link CcmObject}.
|
||||
|
|
@ -64,8 +62,9 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
|
|||
/**
|
||||
* Finds a {@link CcmObject} by its id.
|
||||
*
|
||||
@param objectId The id of the item to find.
|
||||
* @return
|
||||
* @param objectId The id of the item to find
|
||||
*
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<CcmObject> findObjectById(final long objectId) {
|
||||
final TypedQuery<CcmObject> query = getEntityManager().createNamedQuery(
|
||||
|
|
@ -79,6 +78,13 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a {@link CcmObject} by its uuid.
|
||||
*
|
||||
* @param uuid The uuid of the item to find
|
||||
*
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<CcmObject> findObjectByUuid(final String uuid) {
|
||||
final TypedQuery<CcmObject> query = getEntityManager().createNamedQuery(
|
||||
"CcmObject.findByUuid", CcmObject.class);
|
||||
|
|
|
|||
|
|
@ -21,11 +21,16 @@ package org.libreccm.security;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class GroupIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private GroupRepository groupRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,7 +41,7 @@ public class GroupIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
return null;
|
||||
return groupRepository.findByName(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,11 +21,16 @@ package org.libreccm.security;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class PartyIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private PartyRepository partyRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,8 +41,7 @@ public class PartyIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
// Find the user for the id (don't confuse that with the primary key!).
|
||||
return null;
|
||||
return partyRepository.findByName(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,16 +18,14 @@
|
|||
*/
|
||||
package org.libreccm.security;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Repository class for parties.
|
||||
|
|
@ -51,11 +49,11 @@ public class PartyRepository extends AbstractEntityRepository<Long, Party> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Finds a party (which can be a user or group) by its name.
|
||||
* Finds a {@link Party} (which can be a user or group) by its name.
|
||||
*
|
||||
* @param name
|
||||
* @param name The name of the item to find
|
||||
*
|
||||
* @return
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<Party> findByName(final String name) {
|
||||
final TypedQuery<Party> query = getEntityManager().createNamedQuery(
|
||||
|
|
|
|||
|
|
@ -58,6 +58,12 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
@Entity
|
||||
@Table(name = "PERMISSIONS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "Permission.findByCustomPermId",
|
||||
query = "SELECT p FROM Permission p "
|
||||
+ "WHERE p.grantedPrivilege = :privilege "
|
||||
+ "AND p.grantee = :grantee "
|
||||
+ "AND p.object = :object")
|
||||
,
|
||||
@NamedQuery(name = "Permission.existsForPrivilegeRoleObject",
|
||||
query = "SELECT COUNT(p) FROM Permission p "
|
||||
+ "WHERE p.grantedPrivilege = :privilege "
|
||||
|
|
@ -79,7 +85,7 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
+ "AND p.inherited = true")
|
||||
,
|
||||
@NamedQuery(name = "Permission.existsForPrivilegeAndRole",
|
||||
query = "SELECT count(p) FROM Permission p "
|
||||
query = "SELECT COUNT(p) FROM Permission p "
|
||||
+ "WHERE p.grantedPrivilege = :privilege "
|
||||
+ "AND p.grantee = :grantee "
|
||||
+ "AND p.object IS NULL")
|
||||
|
|
|
|||
|
|
@ -62,22 +62,15 @@ public class PermissionIdGenerator extends ObjectIdGenerator<String> {
|
|||
|
||||
final Permission permission = (Permission) forPojo;
|
||||
|
||||
String id = permission.getGrantedPrivilege() +
|
||||
permission.getPermissionId();
|
||||
boolean a = false, b = false;
|
||||
if (permission.getObject() != null) {
|
||||
id += permission.getObject().getUuid();
|
||||
a = true;
|
||||
}
|
||||
if (permission.getGrantee() != null) {
|
||||
id += permission.getGrantee().getName();
|
||||
b = true;
|
||||
if (permission.getGrantee() == null &&
|
||||
permission.getObject() == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
// if (!(a || b)) {
|
||||
// throw new IllegalStateException();
|
||||
// }
|
||||
|
||||
return id;
|
||||
return String.join("_",
|
||||
permission.getGrantedPrivilege(),
|
||||
String.valueOf(permission.getGrantee().getRoleId()),
|
||||
String.valueOf(permission.getObject().getObjectId())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,25 @@ package org.libreccm.security;
|
|||
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.libreccm.core.CcmObjectRepository;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class PermissionIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private PermissionRepository permissionRepository;
|
||||
@Inject
|
||||
private RoleRepository roleRepository;
|
||||
@Inject
|
||||
private CcmObjectRepository ccmObjectRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,8 +49,33 @@ public class PermissionIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
// Find the user for the id (don't confuse that with the primary key!).
|
||||
return null;
|
||||
String[] customPermId = id.key.toString().split("_");
|
||||
|
||||
String privilege = customPermId[0];
|
||||
final long granteeId = Long.getLong(customPermId[1]);
|
||||
final long objectId = Long.getLong(customPermId[2]);
|
||||
|
||||
final Optional<Role> grantee = roleRepository.findById(granteeId);
|
||||
if (!grantee.isPresent()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"Role with id \"%s\" was not found in the database," +
|
||||
" but has been associated with a permission.",
|
||||
granteeId));
|
||||
}
|
||||
final Optional<CcmObject> object = ccmObjectRepository.findObjectById
|
||||
(objectId);
|
||||
Optional<Permission> permission = permissionRepository
|
||||
.findByCustomPermId(privilege,
|
||||
grantee.get(),
|
||||
object.orElse(null));
|
||||
if (!permission.isPresent()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"Permission with privilege \"%s\", grantee \"%s and " +
|
||||
"object \"%s\" was not found in the database.",
|
||||
privilege, grantee.toString(), object.toString()));
|
||||
}
|
||||
|
||||
return permission.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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.security;
|
||||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A repository class for {@link Permission}.
|
||||
*
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/29/17
|
||||
*/
|
||||
@RequestScoped
|
||||
public class PermissionRepository
|
||||
extends AbstractEntityRepository<Long, Permission> {
|
||||
|
||||
@Override
|
||||
public Class<Permission> getEntityClass() {
|
||||
return Permission.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew(Permission entity) {
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException("Can't save null");
|
||||
}
|
||||
return entity.getPermissionId() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a {@link Permission} by the privilege, the grantee and the
|
||||
* object. Where the grantee has been granted the given privilege on the
|
||||
* given object.
|
||||
*
|
||||
* @param privilege The privilege, beeing granted
|
||||
* @param grantee The grantee, having the privilege
|
||||
* @param object The object, the privilege has been granted on
|
||||
*
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<Permission> findByCustomPermId(final String privilege,
|
||||
final Role grantee,
|
||||
final Object object) {
|
||||
final TypedQuery<Permission> query = getEntityManager().createNamedQuery(
|
||||
"Permission.findByCustomPermId", Permission.class);
|
||||
query.setParameter("privilege", privilege);
|
||||
query.setParameter("grantee", grantee);
|
||||
if (object != null)
|
||||
query.setParameter("object", object);
|
||||
|
||||
try {
|
||||
return Optional.of(query.getSingleResult());
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,11 +21,16 @@ package org.libreccm.security;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class RoleIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,8 +41,7 @@ public class RoleIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
// Find the user for the id (don't confuse that with the primary key!).
|
||||
return null;
|
||||
return roleRepository.findByName(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,11 +21,16 @@ package org.libreccm.security;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class UserIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,8 +41,7 @@ public class UserIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
// Find the user for the id (don't confuse that with the primary key!).
|
||||
return null;
|
||||
return userRepository.findByName(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
@Entity
|
||||
@Table(name = "WORKFLOW_ASSIGNABLE_TASKS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "AssignableTask.findByUuid",
|
||||
query = "SELECT t FROM AssignableTask t WHERE t.uuid = :uuid")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "AssignableTask.findLockedBy",
|
||||
query = "SELECT t FROM AssignableTask t WHERE t.lockingUser = :user")
|
||||
|
|
|
|||
|
|
@ -21,11 +21,16 @@ package org.libreccm.workflow;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class AssignableTaskIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private AssignableTaskRepository assignableTaskRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,8 +41,7 @@ public class AssignableTaskIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
// Find the user for the id (don't confuse that with the primary key!).
|
||||
return null;
|
||||
return assignableTaskRepository.findByUuid(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,11 +22,12 @@ import org.libreccm.core.AbstractEntityRepository;
|
|||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Repository for assignable tasks.
|
||||
|
|
@ -47,6 +48,25 @@ public class AssignableTaskRepository
|
|||
return task.getTaskId() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a {@link AssignableTask} by its uuid.
|
||||
*
|
||||
* @param uuid The uuid of the item to find
|
||||
*
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<AssignableTask> findByUuid(final String uuid) {
|
||||
final TypedQuery<AssignableTask> query = getEntityManager().createNamedQuery(
|
||||
"AssignableTask.findByUuid", AssignableTask.class);
|
||||
query.setParameter("uuid", uuid);
|
||||
|
||||
try {
|
||||
return Optional.of(query.getSingleResult());
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public List<AssignableTask> findEnabledTasksForWorkflow(
|
||||
final User user, final Workflow workflow) {
|
||||
final TypedQuery<AssignableTask> query = getEntityManager()
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
"PMD.TooManyMethods",
|
||||
"PMD.AvoidDuplicateLiterals"})
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "Task.findByUuid",
|
||||
query = "SELECT t FROM Task t WHERE t.uuid = :uuid")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "Task.countUnfinishedAndActiveTasksForWorkflow",
|
||||
query = "SELECT COUNT(t) FROM Task t "
|
||||
|
|
|
|||
|
|
@ -21,11 +21,16 @@ package org.libreccm.workflow;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class TaskIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private TaskRepository taskRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,8 +41,7 @@ public class TaskIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
// Find the user for the id (don't confuse that with the primary key!).
|
||||
return null;
|
||||
return taskRepository.findByUuid(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@ package org.libreccm.workflow;
|
|||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Repository for {@link Task}s.
|
||||
|
|
@ -41,10 +43,29 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
|
|||
public boolean isNew(final Task task) {
|
||||
return task.getTaskId() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initNewEntity(final Task task) {
|
||||
super.initNewEntity(task);
|
||||
task.setUuid(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a {@link Task} by its uuid.
|
||||
*
|
||||
* @param uuid The uuid of the item to find
|
||||
*
|
||||
* @return An optional either with the found item or empty
|
||||
*/
|
||||
public Optional<Task> findByUuid(final String uuid) {
|
||||
final TypedQuery<Task> query = getEntityManager().createNamedQuery(
|
||||
"Task.findByUuid", Task.class);
|
||||
query.setParameter("uuid", uuid);
|
||||
|
||||
try {
|
||||
return Optional.of(query.getSingleResult());
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,16 @@ package org.libreccm.workflow;
|
|||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 3/23/17
|
||||
*/
|
||||
public class WorkflowIdResolver implements ObjectIdResolver {
|
||||
@Inject
|
||||
private WorkflowRepository workflowRepository;
|
||||
|
||||
@Override
|
||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
||||
final Object pojo) {
|
||||
|
|
@ -36,8 +41,7 @@ public class WorkflowIdResolver implements ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
// Find the user for the id (don't confuse that with the primary key!).
|
||||
return null;
|
||||
return workflowRepository.findByUuid(id.key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class CoreDataImportTest {
|
|||
// TEST SECTION
|
||||
|
||||
@Test
|
||||
@InSequence(115)
|
||||
@InSequence(105)
|
||||
public void roleMembershipsShouldBeImported() {
|
||||
Assert.assertFalse(importHelper.importRoleMemberships());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue