CCM NG/ccm-core:
- Several additions for Workflow management (Queries etc.) required by the Workflow forms in ccm-cms - Some additions in the BaseServlet and BaseApplicationServlet, primarly initalisation stuff - RowData class for use as bridge between CDI classes and Bebop tables git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4439 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
e54ef0e7a8
commit
4fc5edc59c
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* 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 com.arsdigita.bebop.table;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used as an bridge between a CDI based Controller class and
|
||||||
|
* a Bebop {@link TableModel}. The Controller provides a (transactional) method
|
||||||
|
* for retrieving the data to show in the table. The table model simply retrieves
|
||||||
|
* the Controller bean using the {@link CdiUtil} and uses the returned list of
|
||||||
|
* objects of this class for creating the table rows.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
* @param <K> Type of the row key.
|
||||||
|
*/
|
||||||
|
public class RowData<K> {
|
||||||
|
|
||||||
|
private K rowKey;
|
||||||
|
|
||||||
|
private final List<String> cols;
|
||||||
|
|
||||||
|
public RowData(final int numCols) {
|
||||||
|
cols = new ArrayList<>(numCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
public K getRowKey() {
|
||||||
|
return rowKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRowKey(final K rowKey) {
|
||||||
|
this.rowKey = rowKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColData(final int colIndex) {
|
||||||
|
return cols.get(colIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColData(final int colIndex, final String data) {
|
||||||
|
cols.set(colIndex, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -18,8 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.web;
|
package com.arsdigita.web;
|
||||||
|
|
||||||
|
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||||
|
import com.arsdigita.dispatcher.InitialRequestContext;
|
||||||
|
import com.arsdigita.dispatcher.RequestContext;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
import org.libreccm.web.ApplicationRepository;
|
||||||
import org.libreccm.web.CcmApplication;
|
import org.libreccm.web.CcmApplication;
|
||||||
|
|
||||||
|
|
@ -92,7 +95,7 @@ public abstract class BaseApplicationServlet extends BaseServlet {
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
private ApplicationRepository appRepository;
|
private ApplicationRepository appRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Augments the context of the request and delegates to {@link
|
* Augments the context of the request and delegates to {@link
|
||||||
|
|
@ -120,7 +123,9 @@ public abstract class BaseApplicationServlet extends BaseServlet {
|
||||||
// final RequestContext rc = makeLegacyContext(
|
// final RequestContext rc = makeLegacyContext(
|
||||||
// request, app, Web.getUserContext());
|
// request, app, Web.getUserContext());
|
||||||
//
|
//
|
||||||
// DispatcherHelper.setRequestContext(request, rc);
|
final RequestContext context = new InitialRequestContext(request,
|
||||||
|
getServletContext());
|
||||||
|
DispatcherHelper.setRequestContext(request, context);
|
||||||
//
|
//
|
||||||
// final ServletException[] servletException = {null};
|
// final ServletException[] servletException = {null};
|
||||||
// final IOException[] ioException = {null};
|
// final IOException[] ioException = {null};
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.web;
|
package com.arsdigita.web;
|
||||||
|
|
||||||
|
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -87,6 +89,8 @@ public abstract class BaseServlet extends HttpServlet {
|
||||||
final HttpServletResponse response)
|
final HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
InternalRequestLocal.prepareAll(request);
|
||||||
|
DispatcherHelper.setRequest(request);
|
||||||
Web.init(request, getServletContext());
|
Web.init(request, getServletContext());
|
||||||
Web.getWebContext().setRequestURL(getRequestURL(request));
|
Web.getWebContext().setRequestURL(getRequestURL(request));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,25 @@ import javax.persistence.TemporalType;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "WORKFLOW_USER_TASKS", schema = DB_SCHEMA)
|
@Table(name = "WORKFLOW_USER_TASKS", schema = DB_SCHEMA)
|
||||||
@NamedQueries(
|
@NamedQueries({
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "UserTask.findLockedBy",
|
name = "UserTask.findLockedBy",
|
||||||
query = "SELECT t FROM UserTask t WHERE t.lockingUser = :user")
|
query = "SELECT t FROM UserTask t WHERE t.lockingUser = :user")
|
||||||
)
|
,
|
||||||
|
@NamedQuery(
|
||||||
|
name = "UserTask.findEnabledTasksForWorkflow",
|
||||||
|
query = "SELECT t FROM UserTask t "
|
||||||
|
+ "WHERE t.lockingUser = :user "
|
||||||
|
+ "AND t.workflow = :workflow"
|
||||||
|
)
|
||||||
|
,
|
||||||
|
@NamedQuery(
|
||||||
|
name = "UserTask.findAssignedTasks",
|
||||||
|
query = "SELECT t FROM UserTask t "
|
||||||
|
+ "WHERE t.assignments.role IN :roles "
|
||||||
|
+ "AND t.assignments.workflow = :workflow "
|
||||||
|
+ "AND t.active = true")
|
||||||
|
})
|
||||||
//Can't reduce complexity yet
|
//Can't reduce complexity yet
|
||||||
@SuppressWarnings({"PMD.CyclomaticComplexity",
|
@SuppressWarnings({"PMD.CyclomaticComplexity",
|
||||||
"PMD.StdCyclomaticComplexity",
|
"PMD.StdCyclomaticComplexity",
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,21 @@
|
||||||
package org.libreccm.workflow;
|
package org.libreccm.workflow;
|
||||||
|
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
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.enterprise.context.RequestScoped;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class UserTaskRepository extends AbstractEntityRepository<Long, UserTask>{
|
public class UserTaskRepository extends AbstractEntityRepository<Long, UserTask> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<UserTask> getEntityClass() {
|
public Class<UserTask> getEntityClass() {
|
||||||
|
|
@ -38,7 +44,30 @@ public class UserTaskRepository extends AbstractEntityRepository<Long, UserTask>
|
||||||
public boolean isNew(final UserTask task) {
|
public boolean isNew(final UserTask task) {
|
||||||
return task.getTaskId() == 0;
|
return task.getTaskId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<UserTask> findEnabledTasksForWorkflow(final User user,
|
||||||
|
final Workflow workflow) {
|
||||||
|
final TypedQuery<UserTask> query = getEntityManager().createNamedQuery(
|
||||||
|
"UserTask.findEnabledTasksForWorkflow", UserTask.class);
|
||||||
|
query.setParameter("user", user);
|
||||||
|
query.setParameter("workflow", workflow);
|
||||||
|
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserTask> getAssignedTasks(final User user,
|
||||||
|
final Workflow workflow) {
|
||||||
|
final TypedQuery<UserTask> query = getEntityManager().createNamedQuery(
|
||||||
|
"UserTask.findAssignedTasks", UserTask.class);
|
||||||
|
final List<Role> roles = user.getRoleMemberships()
|
||||||
|
.stream()
|
||||||
|
.map(membership -> membership.getRole())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
query.setParameter("roles", roles );
|
||||||
|
query.setParameter("workflow", workflow);
|
||||||
|
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -36,6 +36,7 @@ import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -71,17 +72,17 @@ public class WorkflowManager {
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Workflow createWorkflow(final WorkflowTemplate template) {
|
public Workflow createWorkflow(final WorkflowTemplate template) {
|
||||||
final Workflow workflow = new Workflow();
|
final Workflow workflow = new Workflow();
|
||||||
|
|
||||||
final LocalizedString name = new LocalizedString();
|
final LocalizedString name = new LocalizedString();
|
||||||
template.getName().getValues().forEach(
|
template.getName().getValues().forEach(
|
||||||
(locale, str) -> name.addValue(locale, str));
|
(locale, str) -> name.addValue(locale, str));
|
||||||
workflow.setName(name);
|
workflow.setName(name);
|
||||||
|
|
||||||
final LocalizedString description = new LocalizedString();
|
final LocalizedString description = new LocalizedString();
|
||||||
template.getDescription().getValues().forEach(
|
template.getDescription().getValues().forEach(
|
||||||
(locale, str) -> description.addValue(locale, str));
|
(locale, str) -> description.addValue(locale, str));
|
||||||
workflow.setDescription(description);
|
workflow.setDescription(description);
|
||||||
|
|
||||||
final Map<Long, Task> tasks = new HashMap<>();
|
final Map<Long, Task> tasks = new HashMap<>();
|
||||||
|
|
||||||
template.getTasks().forEach(taskTemplate -> createTask(taskTemplate,
|
template.getTasks().forEach(taskTemplate -> createTask(taskTemplate,
|
||||||
|
|
@ -142,9 +143,9 @@ public class WorkflowManager {
|
||||||
} else {
|
} else {
|
||||||
writeMethod.invoke(task, value);
|
writeMethod.invoke(task, value);
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException |
|
} catch (IllegalAccessException
|
||||||
IllegalArgumentException |
|
| IllegalArgumentException
|
||||||
InvocationTargetException ex) {
|
| InvocationTargetException ex) {
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,4 +276,35 @@ public class WorkflowManager {
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void start(final Workflow workflow) {
|
||||||
|
if (workflow.getTasks() != null && !workflow.getTasks().isEmpty()) {
|
||||||
|
final Task first = workflow.getTasks().get(0);
|
||||||
|
|
||||||
|
if (first instanceof UserTask) {
|
||||||
|
final User user = shiro.getUser();
|
||||||
|
lockTask((UserTask) first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the state of a workflow.
|
||||||
|
*
|
||||||
|
* @param workflow
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getState(final Workflow workflow) {
|
||||||
|
|
||||||
|
final Optional<Task> activeTask = workflow.getTasks()
|
||||||
|
.stream()
|
||||||
|
.filter(task -> task.isActive())
|
||||||
|
.findAny();
|
||||||
|
|
||||||
|
if (activeTask.isPresent()) {
|
||||||
|
return WorkflowConstants.STARTED;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue