CCM NG/ccm-core: Some JavaDoc for Workflow and related classes (more to come)

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4443 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-11-17 12:11:35 +00:00
parent 1b83b1587a
commit 17a2157b5c
11 changed files with 400 additions and 145 deletions

View File

@ -35,28 +35,48 @@ import javax.persistence.JoinColumn;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.libreccm.core.Identifiable;
/** /**
* A comment for a task. Comments are intended for other users, for example to
* inform them about problems etc. with the object.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@Entity @Entity
@Table(name = "WORKFLOW_TASK_COMMENTS", schema = CoreConstants.DB_SCHEMA) @Table(name = "WORKFLOW_TASK_COMMENTS", schema = CoreConstants.DB_SCHEMA)
public class TaskComment implements Serializable { public class TaskComment implements Identifiable, Serializable {
private static final long serialVersionUID = 3842991529698351698L; private static final long serialVersionUID = 3842991529698351698L;
/**
* Database ID of the comment.
*/
@Id @Id
@Column(name = "COMMENT_ID") @Column(name = "COMMENT_ID")
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private long commentId; private long commentId;
/**
* The UUID of the comment.
*/
@Column(name = "uuid", unique = true, nullable = false)
@NotNull
private String uuid;
/**
* The comment.
*/
@Column(name = "COMMENT") @Column(name = "COMMENT")
@Basic @Basic
@Lob @Lob
@Type(type = "org.hibernate.type.TextType") @Type(type = "org.hibernate.type.TextType")
private String comment; private String comment;
/**
* The author of the comment.
*/
@OneToOne @OneToOne
@JoinColumn(name = "AUTHOR_ID") @JoinColumn(name = "AUTHOR_ID")
private User author; private User author;
@ -69,6 +89,15 @@ public class TaskComment implements Serializable {
this.commentId = commentId; this.commentId = commentId;
} }
@Override
public String getUuid() {
return uuid;
}
protected void setUuid(final String uuid) {
this.uuid = uuid;
}
public String getComment() { public String getComment() {
return comment; return comment;
} }
@ -89,6 +118,7 @@ public class TaskComment implements Serializable {
public int hashCode() { public int hashCode() {
int hash = 3; int hash = 3;
hash = 67 * hash + (int) (commentId ^ (commentId >>> 32)); hash = 67 * hash + (int) (commentId ^ (commentId >>> 32));
hash = 67 * hash + Objects.hashCode(uuid);
hash = 67 * hash + Objects.hashCode(comment); hash = 67 * hash + Objects.hashCode(comment);
hash = 67 * hash + Objects.hashCode(author); hash = 67 * hash + Objects.hashCode(author);
return hash; return hash;
@ -113,6 +143,9 @@ public class TaskComment implements Serializable {
if (commentId != other.getCommentId()) { if (commentId != other.getCommentId()) {
return false; return false;
} }
if (!Objects.equals(uuid, other.getUuid())) {
return false;
}
if (!Objects.equals(comment, other.getComment())) { if (!Objects.equals(comment, other.getComment())) {
return false; return false;
} }
@ -131,11 +164,13 @@ public class TaskComment implements Serializable {
public String toString(final String data) { public String toString(final String data) {
return String.format("%s{ " return String.format("%s{ "
+ "commentId = %d, " + "commentId = %d, "
+ "uuid = \"%s\""
+ "comment = \"%s\", " + "comment = \"%s\", "
+ "author = %s%s" + "author = %s%s"
+ " }", + " }",
super.toString(), super.toString(),
commentId, commentId,
uuid,
comment, comment,
Objects.toString(author), Objects.toString(author),
data); data);

View File

@ -23,22 +23,20 @@ import org.apache.logging.log4j.Logger;
import org.libreccm.core.CoreConstants; import org.libreccm.core.CoreConstants;
import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege; import org.libreccm.security.RequiresPrivilege;
import org.libreccm.security.Role;
import org.libreccm.security.RoleRepository;
import org.libreccm.security.Shiro; import org.libreccm.security.Shiro;
import org.libreccm.security.User; import org.libreccm.security.User;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.UUID;
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.transaction.Transactional; import javax.transaction.Transactional;
/** /**
* Manager for {@link Task}s. The logic of some of this methods has been taken
* from the old implementation without changes.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@ -56,12 +54,15 @@ public class TaskManager {
@Inject @Inject
private TaskRepository taskRepo; private TaskRepository taskRepo;
@Inject
private RoleRepository roleRepo;
@Inject @Inject
private Shiro shiro; private Shiro shiro;
/**
* Adds a {@link Task} to a {@link Workflow}.
*
* @param workflow The workflow to which the task is added.
* @param task The task to add.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -73,6 +74,12 @@ public class TaskManager {
taskRepo.save(task); taskRepo.save(task);
} }
/**
* Removes a {@link Task} from a {@link Workflow}.
*
* @param workflow The workflow from which the task is removed.
* @param task The task to remove.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -84,6 +91,14 @@ public class TaskManager {
taskRepo.save(task); taskRepo.save(task);
} }
/**
* Adds a dependent {@link Task} to another {@code Task}.
*
* @param parent The task to which the dependent task is added.
* @param task The dependent task.
* @throws CircularTaskDependencyException If a circular dependency is
* detected.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -99,6 +114,12 @@ public class TaskManager {
taskRepo.save(parent); taskRepo.save(parent);
} }
/**
* Removes a dependent task.
*
* @param parent The task from which the dependent task is removed.
* @param task The dependent task to remove.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -110,6 +131,13 @@ public class TaskManager {
taskRepo.save(parent); taskRepo.save(parent);
} }
/**
* Helper method for checking for circular dependencies.
*
* @param task1
* @param task2
* @throws CircularTaskDependencyException
*/
private void checkForCircularDependencies(final Task task1, private void checkForCircularDependencies(final Task task1,
final Task task2) final Task task2)
throws CircularTaskDependencyException { throws CircularTaskDependencyException {
@ -134,14 +162,30 @@ public class TaskManager {
return false; return false;
} }
/**
* Adds a new {@link TaskComment} containing the provided comment to a
* {@link Task}. The author of the comment is the current user.
*
* @param task The task to which the comment is added.
* @param comment The comment to add.
*/
public void addComment(final Task task, final String comment) { public void addComment(final Task task, final String comment) {
addComment(task, shiro.getUser(), comment); addComment(task, shiro.getUser(), comment);
} }
/**
* Adds a new {@link TaskComment} containing the provided comment to a
* {@link Task}.
*
* @param task The task to which the comment is added.
* @param author the author of the comment.
* @param comment The comment to add.
*/
public void addComment(final Task task, public void addComment(final Task task,
final User author, final User author,
final String comment) { final String comment) {
final TaskComment taskComment = new TaskComment(); final TaskComment taskComment = new TaskComment();
taskComment.setUuid(UUID.randomUUID().toString());
taskComment.setAuthor(author); taskComment.setAuthor(author);
taskComment.setComment(comment); taskComment.setComment(comment);
@ -151,11 +195,22 @@ public class TaskManager {
taskRepo.save(task); taskRepo.save(task);
} }
/**
* Removes a comment from a task.
*
* @param task The task from which the comment is removed.
* @param comment The comment to remove.
*/
public void removeComment(final Task task, final TaskComment comment) { public void removeComment(final Task task, final TaskComment comment) {
task.removeComment(comment); task.removeComment(comment);
taskRepo.save(task); taskRepo.save(task);
} }
/**
* Enables a {@link Task}.
*
* @param task The task to enable.
*/
public void enable(final Task task) { public void enable(final Task task) {
switch (task.getTaskState()) { switch (task.getTaskState()) {
case DISABLED: case DISABLED:
@ -174,11 +229,21 @@ public class TaskManager {
} }
} }
/**
* Disables a {@link Task}.
*
* @param task The task to disable.
*/
public void disable(final Task task) { public void disable(final Task task) {
task.setTaskState(TaskState.DISABLED); task.setTaskState(TaskState.DISABLED);
taskRepo.save(task); taskRepo.save(task);
} }
/**
* Finishes a {@link Task}.
*
* @param task The task to finish.
*/
public void finish(final Task task) { public void finish(final Task task) {
if (task == null) { if (task == null) {
throw new IllegalArgumentException("Can't finished null..."); throw new IllegalArgumentException("Can't finished null...");
@ -196,6 +261,13 @@ public class TaskManager {
task.getDependentTasks().forEach(dependent -> updateState(dependent)); task.getDependentTasks().forEach(dependent -> updateState(dependent));
} }
/**
* Helper method for updating the state of {@link Task}. Called by
* {@link #finish(org.libreccm.workflow.Task)} to update the state of all
* dependent tasks.
*
* @param task
*/
protected void updateState(final Task task) { protected void updateState(final Task task) {
LOGGER.debug("Updating state for task {}...", LOGGER.debug("Updating state for task {}...",
Objects.toString(task)); Objects.toString(task));

View File

@ -23,6 +23,7 @@ import org.libreccm.core.AbstractEntityRepository;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
/** /**
* Repository for {@link Task}s.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */

View File

@ -19,6 +19,7 @@
package org.libreccm.workflow; package org.libreccm.workflow;
/** /**
* The possible states of a {@link Task}.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */

View File

@ -48,8 +48,12 @@ import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.libreccm.core.Identifiable;
/** /**
* A workflow is a collection of tasks which are performed on an object. Tasks
* can depend on each other.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@ -62,19 +66,35 @@ import javax.persistence.Table;
query = "SELECT w FROM Workflow w " query = "SELECT w FROM Workflow w "
+ "WHERE W.object = :object") + "WHERE W.object = :object")
}) })
public class Workflow implements Serializable { public class Workflow implements Identifiable, Serializable {
private static final long serialVersionUID = 4322500264543325829L; private static final long serialVersionUID = 4322500264543325829L;
/**
* Database id of the workflow.
*/
@Id @Id
@Column(name = "WORKFLOW_ID") @Column(name = "WORKFLOW_ID")
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private long workflowId; private long workflowId;
/**
* UUID of the workflow.
*/
@Column(name = "uuid", unique = true, nullable = false)
@NotNull
private String uuid;
/**
* The template which was used the generate the workflow.
*/
@ManyToOne @ManyToOne
@JoinColumn(name = "TEMPLATE_ID") @JoinColumn(name = "TEMPLATE_ID")
private WorkflowTemplate template; private WorkflowTemplate template;
/**
* Human readable name of the workflow.
*/
@Embedded @Embedded
@AssociationOverride( @AssociationOverride(
name = "values", name = "values",
@ -84,6 +104,9 @@ public class Workflow implements Serializable {
@JoinColumn(name = "WORKFLOW_ID")})) @JoinColumn(name = "WORKFLOW_ID")}))
private LocalizedString name; private LocalizedString name;
/**
* Description of the workflow.
*/
@Embedded @Embedded
@AssociationOverride( @AssociationOverride(
name = "values", name = "values",
@ -94,21 +117,38 @@ public class Workflow implements Serializable {
})) }))
private LocalizedString description; private LocalizedString description;
/**
* The current state of the workflow.
*/
@Column(name = "WORKFLOW_STATE") @Column(name = "WORKFLOW_STATE")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private WorkflowState state; private WorkflowState state;
/**
* Is the workflow active?
*/
@Column(name = "ACTIVE") @Column(name = "ACTIVE")
private boolean active; private boolean active;
/**
* The task state of the workflow. This field is a leftover from the old
* implementation of workflow were workflow extended {@link Task}. Because
* we wanted to keep the basic logic this field is here.
*/
@Column(name = "TASKS_STATE") @Column(name = "TASKS_STATE")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private TaskState tasksState; private TaskState tasksState;
/**
* The object for which this workflow was generated.
*/
@OneToOne @OneToOne
@JoinColumn(name = "OBJECT_ID") @JoinColumn(name = "OBJECT_ID")
private CcmObject object; private CcmObject object;
/**
* The tasks belonging to this workflow.
*/
@OneToMany(mappedBy = "workflow") @OneToMany(mappedBy = "workflow")
private List<Task> tasks; private List<Task> tasks;
@ -124,10 +164,19 @@ public class Workflow implements Serializable {
return workflowId; return workflowId;
} }
public void setWorkflowId(final long workflowId) { protected void setWorkflowId(final long workflowId) {
this.workflowId = workflowId; this.workflowId = workflowId;
} }
@Override
public String getUuid() {
return uuid;
}
protected void setUuid(final String uuid) {
this.uuid = uuid;
}
public WorkflowTemplate getTemplate() { public WorkflowTemplate getTemplate() {
return template; return template;
} }
@ -207,8 +256,9 @@ public class Workflow implements Serializable {
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 5; int hash = 5;
hash = 79 * hash + (int) (this.workflowId ^ (this.workflowId >>> 32)); hash = 79 * hash + (int) (workflowId ^ (workflowId >>> 32));
hash = 79 * hash + Objects.hashCode(this.name); hash = 79 * hash + Objects.hashCode(uuid);
hash = 79 * hash + Objects.hashCode(name);
hash = 79 * hash + Objects.hashCode(description); hash = 79 * hash + Objects.hashCode(description);
hash = 79 * hash + Objects.hashCode(state); hash = 79 * hash + Objects.hashCode(state);
hash = 79 * hash + (active ? 1 : 0); hash = 79 * hash + (active ? 1 : 0);
@ -234,6 +284,10 @@ public class Workflow implements Serializable {
return false; return false;
} }
if (!Objects.equals(uuid, other.getUuid())) {
return false;
}
if (!Objects.equals(name, other.getName())) { if (!Objects.equals(name, other.getName())) {
return false; return false;
} }
@ -270,6 +324,7 @@ public class Workflow implements Serializable {
public String toString(final String data) { public String toString(final String data) {
return String.format("%s{ " return String.format("%s{ "
+ "workflowId = %d, " + "workflowId = %d, "
+ "uuid = \"%s\", "
+ "name = \"%s\", " + "name = \"%s\", "
+ "description = \"%s\", " + "description = \"%s\", "
+ "state = \"%s\", " + "state = \"%s\", "
@ -278,6 +333,7 @@ public class Workflow implements Serializable {
+ " }", + " }",
super.toString(), super.toString(),
workflowId, workflowId,
uuid,
Objects.toString(name), Objects.toString(name),
Objects.toString(description), Objects.toString(description),
Objects.toString(state), Objects.toString(state),

View File

@ -1,37 +0,0 @@
/*
* Copyright (C) 2016 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.workflow;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public final class WorkflowConstants {
private WorkflowConstants() {
//Nothing
}
public final static int NONE = -1;
public final static int STARTED = 0;
public final static int STOPPED = 1;
public final static int DELETED = 2;
public final static int INIT = 3;
}

View File

@ -49,8 +49,18 @@ import javax.inject.Inject;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import org.apache.shiro.subject.Subject;
/** /**
* Manager for {@link Workflow}s. The logic of some of these classes has been
* ported from the workflow implementation. The methods have only been edited to
* fit into the new architecture.
*
* Most of the methods of this manager require the {@code ADMIN} privilege. To
* use this methods with other users the caller has the check the permissions
* first and than wrap the call to the method of this class into a new context
* with the system user by using
* {@link Subject#execute(java.util.concurrent.Callable)}.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@ -80,6 +90,9 @@ public class WorkflowManager {
private Locale defaultLocale; private Locale defaultLocale;
/**
* Populates the {@link #defaultLocale} field.
*/
@PostConstruct @PostConstruct
private void init() { private void init() {
final KernelConfig kernelConfig = confManager.findConfiguration( final KernelConfig kernelConfig = confManager.findConfiguration(
@ -87,11 +100,29 @@ public class WorkflowManager {
defaultLocale = kernelConfig.getDefaultLocale(); defaultLocale = kernelConfig.getDefaultLocale();
} }
/**
* Creates an {@link Workflow} for the provided {@link CcmObject} using the
* provided {@link WorkflowTemplate}.
*
* @param template The template which is used to create the new workflow.
* @param object The object for which th workflow is generated.
* @return The new workflow.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public Workflow createWorkflow(final WorkflowTemplate template, public Workflow createWorkflow(final WorkflowTemplate template,
final CcmObject object) { final CcmObject object) {
if (template == null) {
throw new IllegalArgumentException(
"Can't create a workflow without a template.");
}
if (object == null) {
throw new IllegalArgumentException(
"Can't create a workflow without an object.");
}
final Workflow workflow = new Workflow(); final Workflow workflow = new Workflow();
final LocalizedString name = new LocalizedString(); final LocalizedString name = new LocalizedString();
@ -120,6 +151,15 @@ public class WorkflowManager {
return workflow; return workflow;
} }
/**
* Helper method for
* {@link #createWorkflow(org.libreccm.workflow.WorkflowTemplate, org.libreccm.core.CcmObject)}
* for creating the tasks of the new workflow from the tasks of the workflow
* template.
*
* @param template The template for the task from the workflow template.
* @param tasks A map for storing the new tasks.
*/
private void createTask(final Task template, final Map<Long, Task> tasks) { private void createTask(final Task template, final Map<Long, Task> tasks) {
final Class<? extends Task> templateClass = template.getClass(); final Class<? extends Task> templateClass = template.getClass();
final Task task; final Task task;
@ -177,6 +217,16 @@ public class WorkflowManager {
} }
} }
/**
* Helper method for
* {@link #createWorkflow(org.libreccm.workflow.WorkflowTemplate, org.libreccm.core.CcmObject)}
* and {@link #createTask(org.libreccm.workflow.Task, java.util.Map)} for
* creating the task dependencies.
*
* @param template
* @param task
* @param tasks
*/
private void fixTaskDependencies(final Task template, private void fixTaskDependencies(final Task template,
final Task task, final Task task,
final Map<Long, Task> tasks) { final Map<Long, Task> tasks) {
@ -193,6 +243,13 @@ public class WorkflowManager {
} }
} }
/**
* Finds the enabled {@link Task}s of a {@link Workflow}.
*
* @param workflow The workflow.
* @return A unmodifiable list of the enabled tasks of the provided
* {@code workflow}.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -212,6 +269,13 @@ public class WorkflowManager {
return Collections.unmodifiableList(query.getResultList()); return Collections.unmodifiableList(query.getResultList());
} }
/**
* Finds the finished {@link Task}s of a workflow.
*
* @param workflow The workflow.
* @return An unmodifiable list of the finished tasks of the provided
* {@code Workflow}.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -223,6 +287,13 @@ public class WorkflowManager {
return Collections.unmodifiableList(query.getResultList()); return Collections.unmodifiableList(query.getResultList());
} }
/**
* Finds the {@link Task}s of a {@link Workflow} which are overdue.
*
* @param workflow The workflow.
* @return A unmodifiable list of the overdue tasks of the provided
* {@code workflow}.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -235,6 +306,11 @@ public class WorkflowManager {
return Collections.unmodifiableList(query.getResultList()); return Collections.unmodifiableList(query.getResultList());
} }
/**
* Starts a {@link Workflow}.
*
* @param workflow The workflow to start.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -255,6 +331,11 @@ public class WorkflowManager {
workflowRepo.save(workflow); workflowRepo.save(workflow);
} }
/**
* Helper method for updating the state of a {@link Workflow}.
*
* @param workflow The workflow to update.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -286,6 +367,11 @@ public class WorkflowManager {
} }
} }
/**
* Stops a workflow.
*
* @param workflow The workflow to stop.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -294,6 +380,11 @@ public class WorkflowManager {
workflowRepo.save(workflow); workflowRepo.save(workflow);
} }
/**
* Finished a {@link Workflow}.
*
* @param workflow The workflow to finish.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -309,6 +400,11 @@ public class WorkflowManager {
} }
/**
* Enables a {@link Workflow}.
*
* @param workflow The workflow to enable.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -338,6 +434,11 @@ public class WorkflowManager {
} }
} }
/**
* Disables a {@link Workflow}.
*
* @param workflow The workflow to disable.
*/
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)

View File

@ -22,12 +22,14 @@ import org.libreccm.core.AbstractEntityRepository;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
/** /**
* Repository for {@link Workflow}s.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@ -44,6 +46,19 @@ public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow>
return workflow.getWorkflowId() == 0; return workflow.getWorkflowId() == 0;
} }
@Override
public void initNewEntity(final Workflow workflow) {
workflow.setUuid(UUID.randomUUID().toString());
}
/**
* Finds the workflow for an given object if the object has workflow.
*
* @param object The object
* @return An {@link Optional} containing the workflow assigned to the
* {@code object} if the object has a workflow. Otherwise an empty
* {@link Optional} is returned.
*/
public Optional<Workflow> findWorkflowForObject(final CcmObject object) { public Optional<Workflow> findWorkflowForObject(final CcmObject object) {
if (object == null) { if (object == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

View File

@ -19,6 +19,7 @@
package org.libreccm.workflow; package org.libreccm.workflow;
/** /**
* The possible states of a workflow.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@ -28,6 +29,6 @@ public enum WorkflowState {
STOPPED, STOPPED,
DELETED, DELETED,
INIT, INIT,
NONE NONE;
} }

View File

@ -28,6 +28,8 @@ import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
/** /**
* Objects of these class are used as templates for new workflows. The tasks
* in the template are copied when a new workflow is generated.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@ -37,6 +39,13 @@ public class WorkflowTemplate extends Workflow implements Serializable {
private static final long serialVersionUID = 5770519379144947171L; private static final long serialVersionUID = 5770519379144947171L;
/**
* A workflow template has no object. Therefore the {@code setObject(CcmObject)
* method has been overwritten the throw an {@link UnsupportedOperationException}
* when called on the workflow template.
*
* @param object
*/
@Override @Override
protected void setObject(final CcmObject object) { protected void setObject(final CcmObject object) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(

View File

@ -23,6 +23,7 @@ import org.libreccm.core.AbstractEntityRepository;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
/** /**
* A repository for {@link WorkflowTemplate}s.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */