Removed depcrecated package com.arsdigita.cms.ui.workflow
parent
0ca8ef950e
commit
b991a14d82
|
|
@ -41,7 +41,6 @@ import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.PageLocations;
|
import com.arsdigita.cms.PageLocations;
|
||||||
import com.arsdigita.cms.dispatcher.CMSPage;
|
import com.arsdigita.cms.dispatcher.CMSPage;
|
||||||
import com.arsdigita.cms.ui.authoring.WizardSelector;
|
import com.arsdigita.cms.ui.authoring.WizardSelector;
|
||||||
import com.arsdigita.cms.ui.workflow.ItemWorkflowAdminPane;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
|
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
|
||||||
|
|
@ -158,7 +157,6 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
|
|
||||||
private final ContentItemRequestLocal itemRequestLocal;
|
private final ContentItemRequestLocal itemRequestLocal;
|
||||||
|
|
||||||
private final ItemWorkflowAdminPane workflowPane;
|
|
||||||
|
|
||||||
private final WizardSelector wizardPane;
|
private final WizardSelector wizardPane;
|
||||||
|
|
||||||
|
|
@ -278,7 +276,6 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
|
|
||||||
// Create panels.
|
// Create panels.
|
||||||
wizardPane = new WizardSelector(itemSelectionModel, typeSelectionModel);
|
wizardPane = new WizardSelector(itemSelectionModel, typeSelectionModel);
|
||||||
workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX
|
|
||||||
|
|
||||||
// Create tabbed pane.
|
// Create tabbed pane.
|
||||||
tabbedPane = new TabbedPane();
|
tabbedPane = new TabbedPane();
|
||||||
|
|
@ -289,8 +286,6 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
tabbedPane.
|
tabbedPane.
|
||||||
addTab(new Label(gz("cms.ui.item.authoring")), wizardPane);
|
addTab(new Label(gz("cms.ui.item.authoring")), wizardPane);
|
||||||
|
|
||||||
tabbedPane.addTab(new Label(gz("cms.ui.item.workflow")),
|
|
||||||
workflowPane);
|
|
||||||
|
|
||||||
tabbedPane.addActionListener(new ActionListener() {
|
tabbedPane.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,6 @@ import org.librecms.contentsection.ContentType;
|
||||||
|
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
import com.arsdigita.cms.ui.ContentItemPage;
|
||||||
import com.arsdigita.cms.ui.workflow.AssignedTaskSection;
|
|
||||||
import com.arsdigita.cms.ui.workflow.AssignedTaskTable;
|
|
||||||
import com.arsdigita.cms.ui.workflow.TaskFinishForm;
|
|
||||||
import com.arsdigita.cms.ui.workflow.TaskRequestLocal;
|
|
||||||
import com.arsdigita.cms.ui.workflow.WorkflowRequestLocal;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||||
import com.arsdigita.toolbox.ui.ModalPanel;
|
import com.arsdigita.toolbox.ui.ModalPanel;
|
||||||
|
|
@ -121,9 +116,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
||||||
|
|
||||||
private final ItemSelectionModel selectionModel;
|
private final ItemSelectionModel selectionModel;
|
||||||
|
|
||||||
private final WorkflowRequestLocal workflowRequestLocal;
|
|
||||||
|
|
||||||
private final AssignedTaskTable assignedTaskTable;
|
|
||||||
|
|
||||||
private final SequentialMap labels;
|
private final SequentialMap labels;
|
||||||
|
|
||||||
|
|
@ -137,7 +130,6 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
||||||
|
|
||||||
private final SimpleContainer stepsContainer;
|
private final SimpleContainer stepsContainer;
|
||||||
|
|
||||||
private final TaskFinishForm taskFinishForm;
|
|
||||||
|
|
||||||
private final StringParameter selectedLanguageParam;
|
private final StringParameter selectedLanguageParam;
|
||||||
|
|
||||||
|
|
@ -339,10 +331,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
||||||
|
|
||||||
list.addChangeListener(new StepListener());
|
list.addChangeListener(new StepListener());
|
||||||
|
|
||||||
taskFinishForm = new TaskFinishForm(new TaskSelectionRequestLocal());
|
|
||||||
bodyPanel.add(taskFinishForm);
|
|
||||||
|
|
||||||
bodyPanel.connect(taskFinishForm);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -570,28 +559,6 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class TaskSelectionRequestLocal extends TaskRequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
final String key = assignedTaskTable
|
|
||||||
.getRowSelectionModel()
|
|
||||||
.getSelectedKey(state)
|
|
||||||
.toString();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final TaskRepository taskRepo = cdiUtil
|
|
||||||
.findBean(TaskRepository.class);
|
|
||||||
|
|
||||||
final Task task = taskRepo
|
|
||||||
.findById(Long.parseLong(key))
|
|
||||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
|
||||||
.format("No Task with ID %s in the database.",
|
|
||||||
key)));
|
|
||||||
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,110 +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 com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.table.RowData;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.security.Shiro;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.workflow.AssignableTask;
|
|
||||||
import org.libreccm.workflow.AssignableTaskRepository;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.libreccm.workflow.WorkflowManager;
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controller for the assigned task components.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RequestScoped
|
|
||||||
public class AssignedTaskController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private WorkflowManager workflowManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private AssignableTaskRepository userTaskRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private Shiro shiro;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ConfigurationManager confManager;
|
|
||||||
|
|
||||||
private Locale defaultLocale;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
private void init() {
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<RowData<Long>> getAssignedTasks(final Workflow workflow) {
|
|
||||||
final User user = shiro.getUser().get();
|
|
||||||
final List<AssignableTask> tasks = userTaskRepo.getAssignedTasks(user,
|
|
||||||
workflow);
|
|
||||||
|
|
||||||
return tasks
|
|
||||||
.stream()
|
|
||||||
.map(task -> createRowData(task))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private RowData<Long> createRowData(final AssignableTask task) {
|
|
||||||
|
|
||||||
final RowData<Long> rowData = new RowData<>(3);
|
|
||||||
|
|
||||||
rowData.setRowKey(task.getTaskId());
|
|
||||||
|
|
||||||
// Change when Workflow forms provide fields to enter localised label.
|
|
||||||
rowData.setColData(0, task.getLabel().getValue(defaultLocale));
|
|
||||||
|
|
||||||
if (task.isLocked()) {
|
|
||||||
rowData.setColData(1, task.getLockingUser().getName());
|
|
||||||
} else {
|
|
||||||
rowData.setColData(1, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task instanceof CmsTask
|
|
||||||
&& ((CmsTask) task).getTaskType() == CmsTaskType.DEPLOY) {
|
|
||||||
rowData.setColData(2, null);
|
|
||||||
} else {
|
|
||||||
rowData.setColData(2, "cms.ui.workflow.task.finish");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rowData;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,268 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
|
||||||
import com.arsdigita.toolbox.ui.Section;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Shiro;
|
|
||||||
import org.libreccm.workflow.AssignableTask;
|
|
||||||
import org.libreccm.workflow.AssignableTaskManager;
|
|
||||||
import org.libreccm.workflow.AssignableTaskRepository;
|
|
||||||
import org.libreccm.workflow.WorkflowManager;
|
|
||||||
import org.libreccm.workflow.WorkflowState;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author unknown
|
|
||||||
* @author Sören Bernstein <quasi@quasiweb.de>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public final class AssignedTaskSection extends Section {
|
|
||||||
|
|
||||||
private final WorkflowRequestLocal m_workflow;
|
|
||||||
private final WorkflowFacade m_facade;
|
|
||||||
|
|
||||||
public AssignedTaskSection(final WorkflowRequestLocal workflow,
|
|
||||||
final Component subject) {
|
|
||||||
super(gz("cms.ui.workflow.task.assigned"));
|
|
||||||
|
|
||||||
m_workflow = workflow;
|
|
||||||
m_facade = new WorkflowFacade(m_workflow);
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(subject);
|
|
||||||
group.addAction(new RestartLink());
|
|
||||||
//jensp 2014-06-06 Removed this two links because the funcationality they provide should
|
|
||||||
//be accessible from this place.
|
|
||||||
//group.addAction(new LockLink());
|
|
||||||
//group.addAction(new UnlockLink());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
return m_workflow.getWorkflow(state) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RestartLink extends ActionLink {
|
|
||||||
|
|
||||||
RestartLink() {
|
|
||||||
super(new Label(gz("cms.ui.workflow.restart_stopped_workflow")));
|
|
||||||
|
|
||||||
setClassAttr("restartWorkflowLink");
|
|
||||||
addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
return m_facade.workflowState(state, WorkflowState.INIT)
|
|
||||||
|| m_facade.workflowState(state, WorkflowState.STOPPED);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
m_facade.restartWorkflow(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LockLink extends ActionLink {
|
|
||||||
|
|
||||||
LockLink() {
|
|
||||||
super(new Label(gz("cms.ui.workflow.task.assigned.lock_all")));
|
|
||||||
|
|
||||||
addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
return m_facade.workflowState(state, WorkflowState.STARTED)
|
|
||||||
&& m_facade.tasksExist(state)
|
|
||||||
&& !m_facade.tasksLocked(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
m_facade.lockTasks(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UnlockLink extends ActionLink {
|
|
||||||
|
|
||||||
UnlockLink() {
|
|
||||||
super(new Label(gz("cms.ui.workflow.task.assigned.unlock_all")));
|
|
||||||
|
|
||||||
addActionListener(new UnlockLink.Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
return m_facade.workflowState(state, WorkflowState.STARTED)
|
|
||||||
&& m_facade.tasksExist(state)
|
|
||||||
&& m_facade.tasksLocked(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
m_facade.unlockTasks(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class WorkflowFacade {
|
|
||||||
|
|
||||||
private final WorkflowRequestLocal m_flow;
|
|
||||||
private final TaskListRequestLocal m_tasks;
|
|
||||||
|
|
||||||
WorkflowFacade(final WorkflowRequestLocal flow) {
|
|
||||||
m_flow = flow;
|
|
||||||
m_tasks = new TaskListRequestLocal();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TaskListRequestLocal extends RequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
final Workflow workflow = m_flow.getWorkflow(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final AssignableTaskRepository userTaskRepo = cdiUtil.findBean(
|
|
||||||
AssignableTaskRepository.class);
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
return userTaskRepo.findEnabledTasksForWorkflow(
|
|
||||||
shiro.getUser().get(), workflow);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final List<AssignableTask> getTasks(final PageState state) {
|
|
||||||
return (List<AssignableTask>) get(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
final void restartWorkflow(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowManager workflowManager = cdiUtil.findBean(
|
|
||||||
WorkflowManager.class);
|
|
||||||
final Workflow workflow = m_flow.getWorkflow(state);
|
|
||||||
workflowManager.start(workflow);
|
|
||||||
|
|
||||||
// Lock tasks if not locked
|
|
||||||
if (!tasksLocked(state)) {
|
|
||||||
lockTasks(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final void lockTasks(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final AssignableTaskManager taskManager = cdiUtil.findBean(
|
|
||||||
AssignableTaskManager.class);
|
|
||||||
|
|
||||||
for (final AssignableTask task : m_tasks.getTasks(state)) {
|
|
||||||
if (relevant(task) && !task.isLocked()) {
|
|
||||||
taskManager.lockTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final void unlockTasks(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final AssignableTaskManager taskManager = cdiUtil.findBean(
|
|
||||||
AssignableTaskManager.class);
|
|
||||||
|
|
||||||
for (final AssignableTask task : m_tasks.getTasks(state)) {
|
|
||||||
if (relevant(task) && task.isLocked()) {
|
|
||||||
taskManager.unlockTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean tasksLocked(final PageState state) {
|
|
||||||
for (final AssignableTask task : m_tasks.getTasks(state)) {
|
|
||||||
if (relevant(task) && !task.isLocked()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean workflowState(final PageState state,
|
|
||||||
WorkflowState processState) {
|
|
||||||
final Workflow workflow = m_flow.getWorkflow(state);
|
|
||||||
|
|
||||||
return workflow.getState() == processState;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean tasksExist(final PageState state) {
|
|
||||||
return !m_tasks.getTasks(state).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean relevant(final AssignableTask task) {
|
|
||||||
if (task instanceof CmsTask) {
|
|
||||||
final CmsTask cmsTask = (CmsTask) task;
|
|
||||||
|
|
||||||
return cmsTask.getTaskType() == CmsTaskType.AUTHOR
|
|
||||||
|| cmsTask.getTaskType() == CmsTaskType.EDIT;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static GlobalizedMessage gz(final String key) {
|
|
||||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static String lz(final String key) {
|
|
||||||
return (String) gz(key).localize();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,162 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.TableActionAdapter;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Shiro;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.workflow.AssignableTask;
|
|
||||||
import org.libreccm.workflow.AssignableTaskManager;
|
|
||||||
import org.libreccm.workflow.AssignableTaskRepository;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public final class AssignedTaskTable extends Table {
|
|
||||||
|
|
||||||
public AssignedTaskTable(final WorkflowRequestLocal workflow) {
|
|
||||||
|
|
||||||
super(new AssignedTaskTableModelBuilder(workflow),
|
|
||||||
new String[]{lz("cms.ui.name"), "", ""});
|
|
||||||
|
|
||||||
// XXX The string array and setHeader(null) are a product of
|
|
||||||
// messed up Table behavior.
|
|
||||||
setEmptyView(new Label(gz("cms.ui.workflow.task.assigned.none")));
|
|
||||||
|
|
||||||
addTableActionListener(new LockListener());
|
|
||||||
|
|
||||||
getColumn(1).setCellRenderer(new CellRenderer());
|
|
||||||
getColumn(2).setCellRenderer(new DefaultTableCellRenderer(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class LockListener extends TableActionAdapter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void cellSelected(final TableActionEvent event) {
|
|
||||||
final int column = event.getColumn();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final AssignableTaskRepository userTaskRepo = cdiUtil
|
|
||||||
.findBean(AssignableTaskRepository.class);
|
|
||||||
final AssignableTaskManager taskManager = cdiUtil
|
|
||||||
.findBean(AssignableTaskManager.class);
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
|
|
||||||
if (column == 1) {
|
|
||||||
final AssignableTask task = userTaskRepo.findById((Long) event
|
|
||||||
.getRowKey()).get();
|
|
||||||
final User currentUser = shiro.getUser().get();
|
|
||||||
final User lockingUser = task.getLockingUser();
|
|
||||||
if (task.isLocked()
|
|
||||||
&& lockingUser != null
|
|
||||||
&& lockingUser.equals(currentUser)) {
|
|
||||||
taskManager.unlockTask(task);
|
|
||||||
} else {
|
|
||||||
taskManager.lockTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CellRenderer implements TableCellRenderer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
// SF patch [ 1587168 ] Show locking user
|
|
||||||
final BoxPanel panel = new BoxPanel();
|
|
||||||
final String lockingUserName = (String) value;
|
|
||||||
if (lockingUserName != null) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
|
|
||||||
final Optional<User> currentUser = shiro.getUser();
|
|
||||||
if (currentUser.isPresent()
|
|
||||||
&& currentUser.get().getName().equals(lockingUserName)) {
|
|
||||||
panel.add(new ControlLink(new Label(
|
|
||||||
new GlobalizedMessage("cms.ui.workflow.task.unlock",
|
|
||||||
CmsConstants.CMS_BUNDLE))));
|
|
||||||
panel.add(new Label(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.task.locked_by_you",
|
|
||||||
CmsConstants.CMS_BUNDLE)));
|
|
||||||
} else {
|
|
||||||
panel.add(new ControlLink(new Label(
|
|
||||||
new GlobalizedMessage("cms.ui.workflow.task.takeover",
|
|
||||||
CmsConstants.CMS_BUNDLE))));
|
|
||||||
panel.add(new Label(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.task.locked_by",
|
|
||||||
CmsConstants.CMS_BUNDLE,
|
|
||||||
new String[]{lockingUserName})));
|
|
||||||
}
|
|
||||||
|
|
||||||
// final StringBuilder sb = new StringBuilder("Locked by <br />");
|
|
||||||
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
// final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
// if (shiro.getUser().isPresent()
|
|
||||||
// && lockingUserName.equals(shiro.getUser().get()
|
|
||||||
// .getName())) {
|
|
||||||
// sb.append("you");
|
|
||||||
// panel.add(new ControlLink(new Label(
|
|
||||||
// gz("cms.ui.workflow.task.unlock"))));
|
|
||||||
// } else {
|
|
||||||
// sb.append(lockingUserName);
|
|
||||||
// panel.add(new ControlLink(new Label(
|
|
||||||
// gz("cms.ui.workflow.task.takeover"))));
|
|
||||||
// }
|
|
||||||
// panel.add(new Label(sb.toString(), false));
|
|
||||||
} else {
|
|
||||||
panel.add(new ControlLink(
|
|
||||||
new Label(gz("cms.ui.workflow.task.lock"))));
|
|
||||||
}
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static GlobalizedMessage gz(final String key) {
|
|
||||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static String lz(final String key) {
|
|
||||||
return (String) gz(key).localize();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,126 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the CCM Public
|
|
||||||
* License (the "License"); you may not use this file except in
|
|
||||||
* compliance with the License. You may obtain a copy of the
|
|
||||||
* License at http://www.redhat.com/licenses/ccmpl.html.
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an
|
|
||||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
||||||
* or implied. See the License for the specific language
|
|
||||||
* governing rights and limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
|
||||||
import com.arsdigita.bebop.table.RowData;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.WorkflowState;
|
|
||||||
|
|
||||||
class AssignedTaskTableModelBuilder extends AbstractTableModelBuilder {
|
|
||||||
|
|
||||||
private final WorkflowRequestLocal workflowRequestLocal;
|
|
||||||
|
|
||||||
public AssignedTaskTableModelBuilder(
|
|
||||||
final WorkflowRequestLocal workflowRequestLocal) {
|
|
||||||
this.workflowRequestLocal = workflowRequestLocal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
return new AssignedTaskTableModel(workflowRequestLocal
|
|
||||||
.getWorkflow(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class AssignedTaskTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Iterator<RowData<Long>> m_iter;
|
|
||||||
// private CmsTask m_task;
|
|
||||||
private RowData<Long> rowData;
|
|
||||||
|
|
||||||
AssignedTaskTableModel(final Workflow workflow) {
|
|
||||||
Assert.exists(workflow, Workflow.class);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowState workflowState = workflow.getState();
|
|
||||||
|
|
||||||
if (workflowState == WorkflowState.STARTED) {
|
|
||||||
final AssignedTaskController controller = cdiUtil.findBean(
|
|
||||||
AssignedTaskController.class);
|
|
||||||
m_iter = controller.getAssignedTasks(workflow).iterator();
|
|
||||||
} else {
|
|
||||||
m_iter = Collections.emptyIterator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean nextRow() {
|
|
||||||
if (m_iter.hasNext()) {
|
|
||||||
rowData = m_iter.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getKeyAt(final int column) {
|
|
||||||
return rowData.getRowKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getElementAt(final int column) {
|
|
||||||
switch (column) {
|
|
||||||
case 0:
|
|
||||||
return rowData.getColData(0);
|
|
||||||
case 1:
|
|
||||||
return rowData.getColData(1);
|
|
||||||
case 2:
|
|
||||||
// return rowData.getColData(2);
|
|
||||||
if (rowData.getColData(2) == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
// return rowData.getColData(2);
|
|
||||||
return new ControlLink(new Label(new GlobalizedMessage(
|
|
||||||
rowData.getColData(2), CmsConstants.CMS_BUNDLE)));
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(String.format(
|
|
||||||
"Illegal column index %d. Valid column index: 0, 1, 2",
|
|
||||||
column));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static GlobalizedMessage gz(final String key) {
|
|
||||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static String lz(final String key) {
|
|
||||||
return (String) gz(key).localize();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,232 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the CCM Public
|
|
||||||
* License (the "License"); you may not use this file except in
|
|
||||||
* compliance with the License. You may obtain a copy of the
|
|
||||||
* License at http://www.redhat.com/licenses/ccmpl.html.
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an
|
|
||||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
||||||
* or implied. See the License for the specific language
|
|
||||||
* governing rights and limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.event.FormValidationListener;
|
|
||||||
import com.arsdigita.bebop.event.PrintEvent;
|
|
||||||
import com.arsdigita.bebop.event.PrintListener;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.OptionGroup;
|
|
||||||
import com.arsdigita.bebop.form.SingleSelect;
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
|
||||||
import com.arsdigita.cms.ui.BaseForm;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.CircularTaskDependencyException;
|
|
||||||
import org.libreccm.workflow.TaskDependency;
|
|
||||||
import org.libreccm.workflow.TaskManager;
|
|
||||||
import org.libreccm.workflow.TaskRepository;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author <a href="jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class BaseTaskForm extends BaseForm {
|
|
||||||
|
|
||||||
private final WorkflowRequestLocal workflowRequestLocal;
|
|
||||||
|
|
||||||
private final TextField nameTextField;
|
|
||||||
private final TextArea descriptionTextArea;
|
|
||||||
private final OptionGroup typeOptionGroup;
|
|
||||||
private final OptionGroup dependenciesOptionGroup;
|
|
||||||
|
|
||||||
BaseTaskForm(final String key,
|
|
||||||
final GlobalizedMessage message,
|
|
||||||
final WorkflowRequestLocal workflowRequestLocal) {
|
|
||||||
|
|
||||||
super(key, message);
|
|
||||||
|
|
||||||
this.workflowRequestLocal = workflowRequestLocal;
|
|
||||||
|
|
||||||
nameTextField = new Name("name", 200, true);
|
|
||||||
addField(gz("cms.ui.workflow.task.name"), nameTextField);
|
|
||||||
|
|
||||||
typeOptionGroup = new SingleSelect(new StringParameter("task_type"));
|
|
||||||
addField(gz("cms.ui.workflow.task.type"), typeOptionGroup);
|
|
||||||
|
|
||||||
try {
|
|
||||||
typeOptionGroup.addPrintListener(new TaskTypePrintListener());
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
descriptionTextArea = new Description("desc", 4000, true);
|
|
||||||
addField(gz("cms.ui.workflow.task.description"), descriptionTextArea);
|
|
||||||
|
|
||||||
dependenciesOptionGroup = new CheckboxGroup("dep");
|
|
||||||
addField(gz("cms.ui.workflow.task.dependencies"),
|
|
||||||
dependenciesOptionGroup);
|
|
||||||
|
|
||||||
addAction(new Finish());
|
|
||||||
addAction(new Cancel());
|
|
||||||
|
|
||||||
addSecurityListener(AdminPrivileges.ADMINISTER_WORKFLOWS);
|
|
||||||
addValidationListener(new ValidationListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ValidationListener implements FormValidationListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void validate(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final String name = (String) nameTextField.getValue(event
|
|
||||||
.getPageState());
|
|
||||||
|
|
||||||
// XXX do a dupe check here ala commented out code below
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected WorkflowRequestLocal getWorkflowRequestLocal() {
|
|
||||||
return workflowRequestLocal;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TextField getNameTextField() {
|
|
||||||
return nameTextField;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TextArea getDescriptionTextArea() {
|
|
||||||
return descriptionTextArea;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected OptionGroup getTypeOptionGroup() {
|
|
||||||
return typeOptionGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected OptionGroup getDependenciesOptionGroup() {
|
|
||||||
return dependenciesOptionGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
protected void addValidationListener() {
|
|
||||||
addValidationListener(new DataQueryExistsListener(ERROR_MSG) {
|
|
||||||
private final String QUERY_NAME =
|
|
||||||
"com.arsdigita.workflow.simple.getTasks";
|
|
||||||
|
|
||||||
public void validate(FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
String name = (String) m_name.getValue(event.getPageState());
|
|
||||||
if ( name != null ) {
|
|
||||||
super.validate(event);
|
|
||||||
} else {
|
|
||||||
// Do nothing. Let the NotNullValidationListener fire.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataQuery getDataQuery(FormSectionEvent e) {
|
|
||||||
PageState s = e.getPageState();
|
|
||||||
Session session = SessionManager.getSession();
|
|
||||||
DataQuery query = session.retrieveQuery(QUERY_NAME);
|
|
||||||
Filter f = query.addFilter("lower(taskLabel) = lower(:label)");
|
|
||||||
f.set("label", ((String) m_name.getValue(s)).trim());
|
|
||||||
Filter parentFilter = query.addFilter("taskParentId = :parent_id");
|
|
||||||
parentFilter.set("parent_id", m_processes.getSelectedKey(s));
|
|
||||||
Filter itemFilter = query.addNotEqualsFilter
|
|
||||||
("taskId", (BigDecimal)m_id.getValue(s));
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// Fix this one too
|
|
||||||
private class TaskTypePrintListener implements PrintListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void prepare(final PrintEvent event) {
|
|
||||||
|
|
||||||
final OptionGroup target = (OptionGroup) event.getTarget();
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
for (final CmsTaskType type : CmsTaskType.values()) {
|
|
||||||
final GlobalizedMessage label = new GlobalizedMessage(
|
|
||||||
String.format("cms.workflow.task_type.%s", type.toString()),
|
|
||||||
CmsConstants.CMS_BUNDLE);
|
|
||||||
|
|
||||||
target.addOption(new Option(type.toString(), new Label(label)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method decides which dependencies have to be removed and which ones
|
|
||||||
* newly added. Unfortunately we cannot just do "remove all", and add the
|
|
||||||
* new ones in since it is possible that Tasks will fire events when
|
|
||||||
* dependencies are added and removed.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
final void processDependencies(final Task task,
|
|
||||||
final String[] selectedDependencies) {
|
|
||||||
final List<TaskDependency> blockedTasks = task.getBlockedTasks();
|
|
||||||
final Map<Long, Task> toAdd = new HashMap<>();
|
|
||||||
// Everything is to be removed unless it is in the array.
|
|
||||||
final Map<Long, Task> toRemove = blockedTasks
|
|
||||||
.stream()
|
|
||||||
.map(TaskDependency::getBlockedTask)
|
|
||||||
.collect(Collectors.toMap(Task::getTaskId,
|
|
||||||
dependency -> dependency));
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final TaskRepository taskRepo = cdiUtil.findBean(TaskRepository.class);
|
|
||||||
final TaskManager taskManager = cdiUtil.findBean(TaskManager.class);
|
|
||||||
|
|
||||||
Long selectedId;
|
|
||||||
Object addedTask;
|
|
||||||
if (selectedDependencies != null) {
|
|
||||||
for (String selectedDependency : selectedDependencies) {
|
|
||||||
selectedId = Long.parseLong(selectedDependency);
|
|
||||||
addedTask = toRemove.remove(selectedId);
|
|
||||||
if (addedTask == null) {
|
|
||||||
toAdd.put(selectedId, taskRepo.findById(selectedId).get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Task taskToRemove : toRemove.values()) {
|
|
||||||
taskManager.removeDependentTask(task, taskToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Task taskToAdd : toAdd.values()) {
|
|
||||||
try {
|
|
||||||
taskManager.addDependentTask(task, taskToAdd);
|
|
||||||
} catch (CircularTaskDependencyException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.event.FormValidationListener;
|
|
||||||
import com.arsdigita.cms.ui.BaseForm;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Uday Mathur
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class BaseWorkflowForm extends BaseForm {
|
|
||||||
|
|
||||||
final Name m_title;
|
|
||||||
final Description m_description;
|
|
||||||
|
|
||||||
BaseWorkflowForm(final String key, final GlobalizedMessage message) {
|
|
||||||
super(key, message);
|
|
||||||
|
|
||||||
m_title = new Name("name", 200, true);
|
|
||||||
addField(gz("cms.ui.workflow.name"), m_title);
|
|
||||||
|
|
||||||
m_description = new Description("desc", 4000, true);
|
|
||||||
addField(gz("cms.ui.workflow.description"), m_description);
|
|
||||||
|
|
||||||
addAction(new Finish());
|
|
||||||
addAction(new Cancel());
|
|
||||||
|
|
||||||
addSecurityListener(AdminPrivileges.ADMINISTER_WORKFLOWS);
|
|
||||||
addValidationListener(new ValidationListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ValidationListener implements FormValidationListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void validate(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final String name = (String) m_title.getValue(event.getPageState());
|
|
||||||
|
|
||||||
// XXX do a dupe check here ala commented out code below
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
protected void addValidationListener(Form f) {
|
|
||||||
f.addValidationListener(new DataQueryExistsListener(ERROR_MSG) {
|
|
||||||
private final String QUERY_NAME =
|
|
||||||
"com.arsdigita.workflow.simple.getProcessDefinitions";
|
|
||||||
|
|
||||||
|
|
||||||
public void validate(FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
String name = (String) m_title.getValue(event.getPageState());
|
|
||||||
if ( name != null ) {
|
|
||||||
super.validate(event);
|
|
||||||
} else {
|
|
||||||
// Do nothing. The NotNullValidation listener should kick in.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataQuery getDataQuery(FormSectionEvent e) {
|
|
||||||
PageState s = e.getPageState();
|
|
||||||
Session session = SessionManager.getSession();
|
|
||||||
DataQuery query = session.retrieveQuery(QUERY_NAME);
|
|
||||||
Filter listenerFilter = query.addFilter("lower(processDefinitionLabel) = lower(:label)");
|
|
||||||
listenerFilter.set("label", ((String) m_title.getValue(s)).trim());
|
|
||||||
Filter itemFilter = query.addNotEqualsFilter
|
|
||||||
("processDefinitionId", m_id.getValue(s));
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
@ -1,320 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
|
||||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
|
||||||
import com.arsdigita.cms.ui.VisibilityComponent;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
|
||||||
import com.arsdigita.toolbox.ui.Property;
|
|
||||||
import com.arsdigita.toolbox.ui.PropertyList;
|
|
||||||
import com.arsdigita.toolbox.ui.Section;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Shiro;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.TaskManager;
|
|
||||||
import org.libreccm.workflow.TaskRepository;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
abstract class BaseWorkflowItemPane extends BaseItemPane {
|
|
||||||
|
|
||||||
final WorkflowRequestLocal workflowRequestLocal;
|
|
||||||
final TaskRequestLocal taskRequestLocal;
|
|
||||||
|
|
||||||
ActionGroup actionGroup;
|
|
||||||
final TaskTable taskTable;
|
|
||||||
|
|
||||||
final SimpleContainer detailPane;
|
|
||||||
final TaskItemPane taskItemPane;
|
|
||||||
final SummarySection summarySection;
|
|
||||||
|
|
||||||
public BaseWorkflowItemPane(final WorkflowRequestLocal workflow,
|
|
||||||
final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
workflowRequestLocal = workflow;
|
|
||||||
|
|
||||||
taskTable = new TaskTable();
|
|
||||||
taskRequestLocal = new TaskSelectionRequestLocal();
|
|
||||||
|
|
||||||
detailPane = new SimpleContainer();
|
|
||||||
|
|
||||||
// Tasks
|
|
||||||
final FinishLink taskFinishLink = new FinishLink();
|
|
||||||
|
|
||||||
final ActionLink taskAddLink = new ActionLink(new Label(gz(
|
|
||||||
"cms.ui.workflow.task.add")));
|
|
||||||
final TaskAddForm taskAddForm = new TaskAddForm(workflowRequestLocal,
|
|
||||||
taskTable
|
|
||||||
.getRowSelectionModel());
|
|
||||||
|
|
||||||
final ActionLink taskEditLink = new ActionLink(new Label(gz(
|
|
||||||
"cms.ui.workflow.task.edit")));
|
|
||||||
final TaskEditForm taskEditForm = new TaskEditForm(workflowRequestLocal,
|
|
||||||
taskRequestLocal);
|
|
||||||
|
|
||||||
final ActionLink taskDeleteLink = new ActionLink(new Label(gz(
|
|
||||||
"cms.ui.workflow.task.delete")));
|
|
||||||
final TaskDeleteForm taskDeleteForm = new TaskDeleteForm();
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new Label(gz(
|
|
||||||
"cms.ui.workflow.task.return")));
|
|
||||||
backLink.addActionListener(new ResetListener());
|
|
||||||
|
|
||||||
taskItemPane = new TaskItemPane(workflowRequestLocal, taskRequestLocal,
|
|
||||||
taskFinishLink, taskEditLink,
|
|
||||||
taskDeleteLink, backLink);
|
|
||||||
|
|
||||||
summarySection = new SummarySection(editLink, deleteLink);
|
|
||||||
detailPane.add(summarySection);
|
|
||||||
detailPane.add(new TaskSection(taskAddLink));
|
|
||||||
|
|
||||||
add(detailPane);
|
|
||||||
setDefault(detailPane);
|
|
||||||
add(taskItemPane);
|
|
||||||
add(taskAddForm);
|
|
||||||
add(taskEditForm);
|
|
||||||
add(taskDeleteForm);
|
|
||||||
|
|
||||||
connect(taskTable, 0, taskItemPane);
|
|
||||||
|
|
||||||
connect(taskAddLink, taskAddForm);
|
|
||||||
connect(taskAddForm, taskItemPane);
|
|
||||||
|
|
||||||
connect(taskEditLink, taskEditForm);
|
|
||||||
connect(taskEditForm);
|
|
||||||
|
|
||||||
connect(taskDeleteLink, taskDeleteForm);
|
|
||||||
connect(taskDeleteForm, detailPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class AdminVisible extends VisibilityComponent {
|
|
||||||
|
|
||||||
public AdminVisible(final Component child) {
|
|
||||||
super(child, AdminPrivileges.ADMINISTER_WORKFLOWS);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class FinishLink extends ActionLink {
|
|
||||||
|
|
||||||
FinishLink() {
|
|
||||||
super(new Label(gz("cms.ui.workflow.task.finish")));
|
|
||||||
|
|
||||||
addActionListener(new Listener());
|
|
||||||
addActionListener(new ResetListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
final CmsTask task = taskRequestLocal.getTask(state);
|
|
||||||
final User lockingUser = task.getLockingUser();
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
final User currentUser = shiro.getUser().get();
|
|
||||||
|
|
||||||
return task.isLocked() && (lockingUser == null
|
|
||||||
|| lockingUser.equals(currentUser));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final TaskManager taskManager = cdiUtil.findBean(
|
|
||||||
TaskManager.class);
|
|
||||||
|
|
||||||
final Task task = taskRequestLocal.getTask(state);
|
|
||||||
taskManager.finish(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reset(final PageState state) {
|
|
||||||
super.reset(state);
|
|
||||||
|
|
||||||
taskTable.getRowSelectionModel().clearSelection(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TaskDeleteForm extends BaseDeleteForm {
|
|
||||||
|
|
||||||
TaskDeleteForm() {
|
|
||||||
super(new Label(gz("cms.ui.workflow.task.delete_prompt")));
|
|
||||||
|
|
||||||
addSecurityListener(AdminPrivileges.ADMINISTER_WORKFLOWS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final TaskRepository taskRepo = cdiUtil.findBean(
|
|
||||||
TaskRepository.class);
|
|
||||||
|
|
||||||
final Task task = taskRequestLocal.getTask(state);
|
|
||||||
taskRepo.delete(task);
|
|
||||||
|
|
||||||
taskTable.getRowSelectionModel().clearSelection(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TaskSelectionRequestLocal extends TaskRequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
|
|
||||||
final Long key = Long.parseLong(taskTable.getRowSelectionModel()
|
|
||||||
.getSelectedKey(state).toString());
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final TaskRepository taskRepo = cdiUtil.findBean(
|
|
||||||
TaskRepository.class);
|
|
||||||
|
|
||||||
final CmsTask task = (CmsTask) taskRepo
|
|
||||||
.findById(key)
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Task with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
key)));
|
|
||||||
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class SummarySection extends Section {
|
|
||||||
|
|
||||||
SummarySection(final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
setHeading(new Label(gz("cms.ui.workflow.details")));
|
|
||||||
|
|
||||||
actionGroup = new ActionGroup();
|
|
||||||
setBody(actionGroup);
|
|
||||||
|
|
||||||
actionGroup.setSubject(new Properties());
|
|
||||||
actionGroup.addAction(new AdminVisible(editLink),
|
|
||||||
ActionGroup.EDIT);
|
|
||||||
actionGroup.addAction(new AdminVisible(deleteLink),
|
|
||||||
ActionGroup.DELETE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Properties extends PropertyList {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final List<Property> properties(final PageState state) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final List<Property> props = super.properties(state);
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final Workflow workflow
|
|
||||||
= ((Optional<Workflow>) workflowRequestLocal
|
|
||||||
.get(state)).get();
|
|
||||||
|
|
||||||
// final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
// final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final WorkflowAdminPaneController controller = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
props.addAll(controller.getWorkflowProperties(workflow));
|
|
||||||
// props.add(new Property(gz("cms.ui.workflow.name"),
|
|
||||||
// workflow.getName()
|
|
||||||
// .getValue(defaultLocale)));
|
|
||||||
// props.add(new Property(
|
|
||||||
// gz("cms.ui.workflow.description"),
|
|
||||||
// workflow.getDescription().getValue(defaultLocale)));
|
|
||||||
// if (workflow.getState() == null) {
|
|
||||||
// props.add(new Property(gz("cms.ui.workflow.current_state"),
|
|
||||||
// gz("cms.ui.workflow.current_state.none")));
|
|
||||||
// } else {
|
|
||||||
// props.add(new Property(gz("cms.ui.workflow.current_state"),
|
|
||||||
// workflow.getState().toString()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class TaskSection extends Section {
|
|
||||||
|
|
||||||
TaskSection(final ActionLink taskAddLink) {
|
|
||||||
setHeading(new Label(gz("cms.ui.workflow.tasks")));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(taskTable);
|
|
||||||
group.addAction(new AdminVisible(taskAddLink), ActionGroup.ADD);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String[] COLUMNS = new String[]{
|
|
||||||
lz("cms.ui.workflow.task.name"),
|
|
||||||
lz("cms.ui.workflow.task.description"),
|
|
||||||
lz("cms.ui.workflow.task.dependencies"),
|
|
||||||
lz("cms.ui.workflow.task.state")
|
|
||||||
};
|
|
||||||
|
|
||||||
private class TaskTable extends Table {
|
|
||||||
|
|
||||||
public TaskTable() {
|
|
||||||
super(new TaskTableModelBuilder(workflowRequestLocal), COLUMNS);
|
|
||||||
|
|
||||||
setEmptyView(new Label(gz("cms.ui.workflow.task.none")));
|
|
||||||
|
|
||||||
getColumn(0).setCellRenderer(new DefaultTableCellRenderer(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.cms.ui.BaseForm;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.TaskManager;
|
|
||||||
import org.libreccm.workflow.TaskRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Justin Ross
|
|
||||||
* @author <a href="mailto:jens.pelzetter">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class CommentAddForm extends BaseForm {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
CommentAddForm.class);
|
|
||||||
|
|
||||||
private final TaskRequestLocal selectedTask;
|
|
||||||
private final TextArea comment;
|
|
||||||
|
|
||||||
public CommentAddForm(final TaskRequestLocal task) {
|
|
||||||
super("addComment", gz("cms.ui.workflow.task.comment.add"));
|
|
||||||
|
|
||||||
this.selectedTask = task;
|
|
||||||
|
|
||||||
comment = new TextArea("Comment");
|
|
||||||
comment.setWrap(TextArea.SOFT);
|
|
||||||
comment.setRows(5);
|
|
||||||
comment.setCols(40);
|
|
||||||
|
|
||||||
addComponent(comment);
|
|
||||||
|
|
||||||
addAction(new Finish());
|
|
||||||
addAction(new Cancel());
|
|
||||||
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
LOGGER.debug("Processing comment add");
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
if (comment.getValue(state) != null
|
|
||||||
&& !((String) comment.getValue(state)).isEmpty()) {
|
|
||||||
final CmsTask task = selectedTask.getTask(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final TaskFinishFormController controller = cdiUtil
|
|
||||||
.findBean(TaskFinishFormController.class);
|
|
||||||
controller.addComment(task, (String) comment.getValue(state));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.bebop.parameters.LongParameter;
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.WorkflowRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Panel for applying a workflow template to a content item. By
|
|
||||||
* default this panel display a list of workflows that can be applied
|
|
||||||
* to the content item. If a workflow is applied, it displays the item
|
|
||||||
* details page.
|
|
||||||
*
|
|
||||||
* @author Uday Mathur
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ItemWorkflowAdminPane extends BaseItemPane {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel m_model;
|
|
||||||
private final WorkflowRequestLocal m_workflow;
|
|
||||||
|
|
||||||
private final LayoutPanel m_detailPane;
|
|
||||||
private final LayoutPanel m_selectPane;
|
|
||||||
|
|
||||||
public ItemWorkflowAdminPane(final LongParameter itemIdParameter) {
|
|
||||||
m_model = new ItemWorkflowSelectionModel(itemIdParameter);
|
|
||||||
m_workflow = new SelectionRequestLocal();
|
|
||||||
|
|
||||||
final ActionLink editLink = new ActionLink
|
|
||||||
(new Label(gz("cms.ui.workflow.edit")));
|
|
||||||
|
|
||||||
final WorkflowEditForm editForm = new WorkflowEditForm(m_workflow);
|
|
||||||
|
|
||||||
final ActionLink deleteLink = new ActionLink
|
|
||||||
(new Label(gz("cms.ui.workflow.delete")));
|
|
||||||
|
|
||||||
final WorkflowDeleteForm deleteForm = new WorkflowDeleteForm
|
|
||||||
(m_workflow);
|
|
||||||
|
|
||||||
m_detailPane = new LayoutPanel();
|
|
||||||
m_detailPane.setBody(new ItemWorkflowItemPane
|
|
||||||
(m_workflow, editLink, deleteLink));
|
|
||||||
|
|
||||||
final ItemWorkflowSelectForm workflowSelectForm =
|
|
||||||
new ItemWorkflowSelectForm();
|
|
||||||
|
|
||||||
m_selectPane = new LayoutPanel();
|
|
||||||
m_selectPane.setBody(workflowSelectForm);
|
|
||||||
|
|
||||||
add(m_detailPane);
|
|
||||||
setDefault(m_detailPane);
|
|
||||||
add(m_selectPane);
|
|
||||||
add(editForm);
|
|
||||||
add(deleteForm);
|
|
||||||
|
|
||||||
connect(workflowSelectForm, m_detailPane);
|
|
||||||
connect(editLink, editForm);
|
|
||||||
connect(deleteLink, deleteForm);
|
|
||||||
connect(deleteForm, m_selectPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SelectionRequestLocal extends WorkflowRequestLocal {
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
final String workflowId = m_model.getSelectedKey(state).toString();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowRepository workflowRepo = cdiUtil.findBean(WorkflowRepository.class);
|
|
||||||
return workflowRepo.findById(Long.parseLong(workflowId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (state.isVisibleOnPage(ItemWorkflowAdminPane.this)
|
|
||||||
&& m_model.getSelectedKey(state) == null) {
|
|
||||||
push(state, m_selectPane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,169 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.libreccm.workflow.TaskRepository;
|
|
||||||
import org.libreccm.workflow.WorkflowManager;
|
|
||||||
import org.libreccm.workflow.WorkflowState;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
final class ItemWorkflowItemPane extends BaseWorkflowItemPane {
|
|
||||||
|
|
||||||
private final AssignedTaskTable assignedTaskTable;
|
|
||||||
|
|
||||||
public ItemWorkflowItemPane(final WorkflowRequestLocal workflowRequestLocal,
|
|
||||||
final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
|
|
||||||
super(workflowRequestLocal, editLink, deleteLink);
|
|
||||||
|
|
||||||
actionGroup.addAction(new AdminVisible(new StartLink()));
|
|
||||||
actionGroup.addAction(new AdminVisible(new StopLink()));
|
|
||||||
|
|
||||||
assignedTaskTable = new AssignedTaskTable(workflowRequestLocal);
|
|
||||||
detailPane.add(new AssignedTaskSection(workflowRequestLocal,
|
|
||||||
assignedTaskTable));
|
|
||||||
|
|
||||||
final TaskFinishForm taskFinishForm = new TaskFinishForm(
|
|
||||||
new TaskSelectionRequestLocal());
|
|
||||||
add(taskFinishForm);
|
|
||||||
|
|
||||||
connect(assignedTaskTable, 2, taskFinishForm);
|
|
||||||
connect(taskFinishForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class TaskSelectionRequestLocal extends TaskRequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
final String taskId = assignedTaskTable.getRowSelectionModel().
|
|
||||||
getSelectedKey(state).toString();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final TaskRepository taskRepo = cdiUtil.findBean(
|
|
||||||
TaskRepository.class);
|
|
||||||
|
|
||||||
return (CmsTask) taskRepo.findById(Long.parseLong(taskId)).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasAdmin(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
|
||||||
|
|
||||||
return permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_WORKFLOWS, section);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class StopLink extends ActionLink {
|
|
||||||
|
|
||||||
StopLink() {
|
|
||||||
super(new Label(gz("cms.ui.item.workflow.stop")));
|
|
||||||
|
|
||||||
addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
final Workflow workflow = workflowRequestLocal.getWorkflow(state);
|
|
||||||
|
|
||||||
return workflow.getState() == WorkflowState.STARTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (hasAdmin(state)) {
|
|
||||||
final Workflow workflow = workflowRequestLocal.getWorkflow(
|
|
||||||
state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowManager workflowManager = cdiUtil.findBean(
|
|
||||||
WorkflowManager.class);
|
|
||||||
workflowManager.stop(workflow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class StartLink extends ActionLink {
|
|
||||||
|
|
||||||
StartLink() {
|
|
||||||
super(new Label(gz("cms.ui.item.workflow.start")));
|
|
||||||
|
|
||||||
addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
final Workflow workflow = workflowRequestLocal.getWorkflow(state);
|
|
||||||
|
|
||||||
// Start link should be visible if the workflow state is stopped
|
|
||||||
// or init
|
|
||||||
return workflow.getState() == WorkflowState.STOPPED
|
|
||||||
|| workflow.getState() == WorkflowState.INIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (hasAdmin(state)) {
|
|
||||||
final Workflow workflow = workflowRequestLocal.getWorkflow(
|
|
||||||
state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil =CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowManager workflowManager = cdiUtil.findBean(
|
|
||||||
WorkflowManager.class);
|
|
||||||
workflowManager.start(workflow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.form.RadioGroup;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
|
||||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
import com.arsdigita.cms.ui.CMSForm;
|
|
||||||
import com.arsdigita.web.Web;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.WorkflowManager;
|
|
||||||
import org.libreccm.workflow.WorkflowRepository;
|
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This panel displays a radio group of available Workflow Templates in this
|
|
||||||
* content section that can be applied to this item.
|
|
||||||
*
|
|
||||||
* @author Uday Mathur
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class ItemWorkflowSelectForm extends CMSForm {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
ItemWorkflowSelectForm.class);
|
|
||||||
|
|
||||||
private RadioGroup radioGroup;
|
|
||||||
|
|
||||||
public ItemWorkflowSelectForm() {
|
|
||||||
super("applyWorkflow", new SimpleContainer());
|
|
||||||
|
|
||||||
addFormWidgets();
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addFormWidgets() {
|
|
||||||
radioGroup = new RadioGroup(new BigDecimalParameter("workflowSelect"));
|
|
||||||
radioGroup.setClassAttr("vertical");
|
|
||||||
|
|
||||||
try {
|
|
||||||
radioGroup.addPrintListener(new WorkflowsOptionPrintListener());
|
|
||||||
} catch (TooManyListenersException t) {
|
|
||||||
LOGGER.error("Too many listeners", t);
|
|
||||||
}
|
|
||||||
|
|
||||||
radioGroup.addValidationListener(new NotNullValidationListener());
|
|
||||||
add(radioGroup);
|
|
||||||
|
|
||||||
add(new Submit("apply_wf", "Apply Workflow"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a FormProcessListener to that applies a clone of the
|
|
||||||
* WorkflowTemplate to this ContentItem. In case of double-click, no change
|
|
||||||
* is made.
|
|
||||||
*/
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final Long flowId = (Long) radioGroup.getValue(state);
|
|
||||||
|
|
||||||
final ContentItem item = CMS.getContext().getContentItem();
|
|
||||||
|
|
||||||
if (item.getWorkflow() == null) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowRepository templateRepo = cdiUtil.
|
|
||||||
findBean(WorkflowRepository.class);
|
|
||||||
final WorkflowManager workflowManager = cdiUtil.findBean(
|
|
||||||
WorkflowManager.class);
|
|
||||||
|
|
||||||
final Workflow template = templateRepo
|
|
||||||
.findById(flowId)
|
|
||||||
.get();
|
|
||||||
workflowManager.createWorkflow(template, item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.parameters.LongParameter;
|
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
|
||||||
|
|
||||||
class ItemWorkflowSelectionModel extends ParameterSingleSelectionModel {
|
|
||||||
|
|
||||||
private final ItemSelectionModel itemSelectionModel;
|
|
||||||
|
|
||||||
public ItemWorkflowSelectionModel(final LongParameter itemIdParameter) {
|
|
||||||
super(itemIdParameter);
|
|
||||||
itemSelectionModel = new ItemSelectionModel(itemIdParameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemWorkflowSelectionModel(
|
|
||||||
final ItemSelectionModel itemSelectionModel) {
|
|
||||||
super(itemSelectionModel.getStateParameter());
|
|
||||||
this.itemSelectionModel = itemSelectionModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getSelectedKey(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(ContentItemRepository.class);
|
|
||||||
final ContentItem item = itemRepo.findById((Long) super.getSelectedKey(
|
|
||||||
state)).get();
|
|
||||||
|
|
||||||
return item.getWorkflow().getWorkflowId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemSelectionModel getItemSelectionModel() {
|
|
||||||
return itemSelectionModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.event.PrintEvent;
|
|
||||||
import com.arsdigita.bebop.event.PrintListener;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.OptionGroup;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Justin Ross
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class TaskAddForm extends BaseTaskForm {
|
|
||||||
|
|
||||||
protected final static String ERROR_MSG = "A workflow template with that "
|
|
||||||
+ "name already exists in this "
|
|
||||||
+ "content section.";
|
|
||||||
|
|
||||||
private final SingleSelectionModel<Long> selectedWorkflowId;
|
|
||||||
|
|
||||||
public TaskAddForm(final WorkflowRequestLocal workflow,
|
|
||||||
final SingleSelectionModel<Long> selectedWorkflowId) {
|
|
||||||
|
|
||||||
super("task", gz("cms.ui.workflow.task.add"), workflow);
|
|
||||||
|
|
||||||
this.selectedWorkflowId = selectedWorkflowId;
|
|
||||||
|
|
||||||
try {
|
|
||||||
super
|
|
||||||
.getDependenciesOptionGroup()
|
|
||||||
.addPrintListener(new DependencyPrinter());
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DependencyPrinter implements PrintListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void prepare(final PrintEvent event) {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
final List<Task> tasks = controller
|
|
||||||
.getTasksForWorkflow(getWorkflowRequestLocal()
|
|
||||||
.getWorkflow(state));
|
|
||||||
|
|
||||||
final OptionGroup options = (OptionGroup) event.getTarget();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
options.clearOptions();
|
|
||||||
tasks.forEach(task -> options.addOption(new Option(
|
|
||||||
Long.toString(task.getTaskId()),
|
|
||||||
new Text(task.getLabel().getValue(defaultLocale)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
final CmsTask task = controller.addTask(
|
|
||||||
getWorkflowRequestLocal().getWorkflow(state),
|
|
||||||
(String) getNameTextField().getValue(state),
|
|
||||||
(String) getDescriptionTextArea().getValue(state),
|
|
||||||
CmsTaskType.valueOf((String) getTypeOptionGroup()
|
|
||||||
.getValue(state)),
|
|
||||||
(String[]) getDependenciesOptionGroup().getValue(state));
|
|
||||||
|
|
||||||
selectedWorkflowId.setSelectedKey(state, task.getTaskId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,212 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ColumnPanel;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.GridPanel;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.bebop.event.FormInitListener;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.OptionGroup;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.CMSForm;
|
|
||||||
import com.arsdigita.cms.ui.ListOptionPrintListener;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
import org.libreccm.workflow.AssignableTaskManager;
|
|
||||||
import org.libreccm.workflow.TaskAssignment;
|
|
||||||
import org.libreccm.workflow.WorkflowManager;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
class TaskAddRole extends CMSForm {
|
|
||||||
|
|
||||||
private final TaskRequestLocal m_task;
|
|
||||||
private final OptionGroup m_roles;
|
|
||||||
private final Submit m_add;
|
|
||||||
private final Submit m_cancel;
|
|
||||||
|
|
||||||
TaskAddRole(final TaskRequestLocal task) {
|
|
||||||
super("GroupAssignForm");
|
|
||||||
|
|
||||||
m_task = task;
|
|
||||||
|
|
||||||
add(new Label(gz("cms.ui.workflow.task.roles")), ColumnPanel.TOP);
|
|
||||||
|
|
||||||
m_roles = new CheckboxGroup("roles");
|
|
||||||
add(m_roles);
|
|
||||||
|
|
||||||
try {
|
|
||||||
m_roles.addPrintListener(new RoleOptionPrintListener());
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException("TooManyListeners: " + ex
|
|
||||||
.getMessage(), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
final SimpleContainer submits = new SimpleContainer();
|
|
||||||
add(submits, GridPanel.FULL_WIDTH | GridPanel.CENTER);
|
|
||||||
|
|
||||||
m_add = new Submit("add", gz("cms.ui.finish"));
|
|
||||||
submits.add(m_add);
|
|
||||||
|
|
||||||
m_cancel = new Submit("cancel", gz("cms.ui.cancel"));
|
|
||||||
submits.add(m_cancel);
|
|
||||||
|
|
||||||
addInitListener(new InitListener());
|
|
||||||
addSubmissionListener(new SubmissionListener());
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InitListener implements FormInitListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void init(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
final List<Role> roles = controller.findAssignees(task);
|
|
||||||
|
|
||||||
m_roles.setValue(state, roles);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
if (m_add.isSelected(state)) {
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
// final AssignableTaskManager taskManager = cdiUtil.findBean(
|
|
||||||
// AssignableTaskManager.class);
|
|
||||||
// final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
// RoleRepository.class);
|
|
||||||
//
|
|
||||||
// task.getAssignments().forEach(assignment -> {
|
|
||||||
// taskManager.retractTask(task, assignment.getRole());
|
|
||||||
// });
|
|
||||||
|
|
||||||
final String[] roleIds = (String[]) m_roles.getValue(state);
|
|
||||||
|
|
||||||
// if (roleIds != null) {
|
|
||||||
// for (final String roleId : roleIds) {
|
|
||||||
// final Role role = roleRepository.findById(Long
|
|
||||||
// .parseLong(roleId)).get();
|
|
||||||
// taskManager.assignTask(task, role);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
controller.assignTask(task, roleIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SubmissionListener implements FormSubmissionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void submitted(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
if (!permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_WORKFLOWS)) {
|
|
||||||
throw new FormProcessException(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.insufficient_privileges",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RoleOptionPrintListener extends ListOptionPrintListener<Role> {
|
|
||||||
|
|
||||||
public static final String QUERY_NAME
|
|
||||||
= "com.arsdigita.cms.getStaffRoles";
|
|
||||||
|
|
||||||
public RoleOptionPrintListener() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Role> getDataQuery(final PageState state) {
|
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
return controller.findRoles(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKey(final Role role) {
|
|
||||||
return Long.toString(role.getRoleId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue(final Role role) {
|
|
||||||
return role.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GlobalizedMessage gz(final String key) {
|
|
||||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,165 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.cms.ui.UserAddForm;
|
|
||||||
import com.arsdigita.cms.ui.UserSearchForm;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.workflow.AssignableTask;
|
|
||||||
|
|
||||||
import com.arsdigita.xml.Element;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
import org.libreccm.workflow.WorkflowManager;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains forms to search and add users as Task Assignees.
|
|
||||||
*
|
|
||||||
* @author Uday Mathur
|
|
||||||
* @author <a href="mailto:pihman@arsdigita.com">Michael Pih</a>
|
|
||||||
*/
|
|
||||||
class TaskAddUser extends SimpleContainer {
|
|
||||||
|
|
||||||
private final TaskRequestLocal m_task;
|
|
||||||
|
|
||||||
private SearchForm m_search;
|
|
||||||
private AddForm m_add;
|
|
||||||
|
|
||||||
public TaskAddUser(final TaskRequestLocal task) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
m_task = task;
|
|
||||||
|
|
||||||
m_search = new SearchForm();
|
|
||||||
add(m_search);
|
|
||||||
|
|
||||||
m_add = new AddForm();
|
|
||||||
add(m_add);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserSearchForm getSearchForm() {
|
|
||||||
return m_search;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserAddForm getAddForm() {
|
|
||||||
return m_add;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void generateXML(final PageState state,
|
|
||||||
final Element parent) {
|
|
||||||
if (isVisible(state)) {
|
|
||||||
final FormData one = m_search.getFormData(state);
|
|
||||||
final FormData two = m_add.getForm().getFormData(state);
|
|
||||||
|
|
||||||
if (one != null && (one.isSubmission() || two.isSubmission())) {
|
|
||||||
m_search.generateXML(state, parent);
|
|
||||||
m_add.generateXML(state, parent);
|
|
||||||
} else {
|
|
||||||
m_search.generateXML(state, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SearchForm extends UserSearchForm {
|
|
||||||
|
|
||||||
private final Submit m_cancel;
|
|
||||||
|
|
||||||
public SearchForm() {
|
|
||||||
super("user-search");
|
|
||||||
|
|
||||||
m_cancel = new Submit("cancel", gz("cms.ui.cancel"));
|
|
||||||
|
|
||||||
add(m_cancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AddForm extends UserAddForm {
|
|
||||||
|
|
||||||
public AddForm() {
|
|
||||||
super(m_search.getSearchWidget());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final List<User> makeQuery(final PageState state) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepo = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
|
|
||||||
final String search = (String) getSearchWidget().getValue(state);
|
|
||||||
|
|
||||||
return userRepo.filtered(search);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final FormData data = event.getFormData();
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final String[] users = (String[]) data.get("users");
|
|
||||||
|
|
||||||
if (users == null) {
|
|
||||||
throw new FormProcessException(new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.no_users_were_selected",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
} else {
|
|
||||||
// Add each checked user to the task.
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowManager workflowManager = cdiUtil.findBean(
|
|
||||||
WorkflowManager.class);
|
|
||||||
final UserRepository userRepo = cdiUtil.findBean(UserRepository.class);
|
|
||||||
|
|
||||||
final AssignableTask task = m_task.getTask(state);
|
|
||||||
User user;
|
|
||||||
|
|
||||||
for (int i = 0; i < users.length; i++) {
|
|
||||||
user = userRepo.findById(Long.parseLong(users[i])).get();
|
|
||||||
|
|
||||||
//ToDo
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GlobalizedMessage gz(final String key) {
|
|
||||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String lz(final String key) {
|
|
||||||
return (String) gz(key).localize();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,164 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.FormInitListener;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.event.PrintEvent;
|
|
||||||
import com.arsdigita.bebop.event.PrintListener;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.OptionGroup;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.TaskDependency;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Justin Ross
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class TaskEditForm extends BaseTaskForm {
|
|
||||||
|
|
||||||
private TaskRequestLocal selectedTask;
|
|
||||||
|
|
||||||
public TaskEditForm(final WorkflowRequestLocal workflow,
|
|
||||||
final TaskRequestLocal selectedTask) {
|
|
||||||
super("task", gz("cms.ui.workflow.task.edit"), workflow);
|
|
||||||
|
|
||||||
this.selectedTask = selectedTask;
|
|
||||||
|
|
||||||
try {
|
|
||||||
getDependenciesOptionGroup()
|
|
||||||
.addPrintListener(new DependencyPrinter());
|
|
||||||
} catch (TooManyListenersException tmle) {
|
|
||||||
throw new UncheckedWrapperException(tmle);
|
|
||||||
}
|
|
||||||
|
|
||||||
addInitListener(new InitListener());
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DependencyPrinter implements PrintListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void prepare(final PrintEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final Workflow workflow = getWorkflowRequestLocal()
|
|
||||||
.getWorkflow(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
final List<Task> tasks = controller.getTasksForWorkflow(workflow);
|
|
||||||
|
|
||||||
final OptionGroup options = (OptionGroup) event.getTarget();
|
|
||||||
options.clearOptions();
|
|
||||||
|
|
||||||
tasks.forEach(task -> addOption(task, state, options));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addOption(final Task task,
|
|
||||||
final PageState state,
|
|
||||||
final OptionGroup options) {
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
if (selectedTask.getTask(state).getTaskId() != task.getTaskId()) {
|
|
||||||
options.addOption(new Option(
|
|
||||||
Long.toString(task.getTaskId()),
|
|
||||||
task.getLabel().getValue(defaultLocale)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InitListener implements FormInitListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void init(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final CmsTask task = selectedTask.getTask(state);
|
|
||||||
|
|
||||||
final Locale defaultLocale = KernelConfig
|
|
||||||
.getConfig()
|
|
||||||
.getDefaultLocale();
|
|
||||||
|
|
||||||
getNameTextField().setValue(state,
|
|
||||||
task.getLabel().getValue(defaultLocale));
|
|
||||||
getDescriptionTextArea().setValue(
|
|
||||||
state,
|
|
||||||
task.getDescription().getValue(defaultLocale));
|
|
||||||
getTypeOptionGroup().setValue(state, task.getTaskType().toString());
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil.findBean(
|
|
||||||
WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
final List<TaskDependency> blockedTasks = controller.getBlockedTasks(task);
|
|
||||||
final List<String> depIdList = blockedTasks
|
|
||||||
.stream()
|
|
||||||
.map(TaskDependency::getBlockedTask)
|
|
||||||
.map(blockedTask -> Long.toString(blockedTask.getTaskId()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
getDependenciesOptionGroup().setValue(state, depIdList.toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final CmsTask task = selectedTask.getTask(state);
|
|
||||||
|
|
||||||
final String name = (String) getNameTextField().getValue(state);
|
|
||||||
final String desc = (String) getDescriptionTextArea()
|
|
||||||
.getValue(state);
|
|
||||||
final CmsTaskType taskType = CmsTaskType
|
|
||||||
.valueOf((String) getTypeOptionGroup().getValue(state));
|
|
||||||
final String[] deps = (String[]) getDependenciesOptionGroup()
|
|
||||||
.getValue(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
controller.updateTask(task, name, desc, taskType, deps);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,263 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.FormInitListener;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.event.FormValidationListener;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.RadioGroup;
|
|
||||||
import com.arsdigita.bebop.parameters.BooleanParameter;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
|
|
||||||
import com.arsdigita.web.RedirectSignal;
|
|
||||||
import com.arsdigita.web.URL;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.librecms.CMSConfig;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.libreccm.workflow.AssignableTask;
|
|
||||||
import org.libreccm.workflow.TaskDependency;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* A form that prompts the user to comment on and approve tasks and then
|
|
||||||
* finishes the task if it was approved.</p>
|
|
||||||
*
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public final class TaskFinishForm extends CommentAddForm {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
TaskFinishForm.class);
|
|
||||||
private final TaskRequestLocal m_task;
|
|
||||||
private final Label m_approvePrompt;
|
|
||||||
private final RadioGroup m_approve;
|
|
||||||
|
|
||||||
public TaskFinishForm(final TaskRequestLocal task) {
|
|
||||||
super(task);
|
|
||||||
|
|
||||||
m_task = task;
|
|
||||||
|
|
||||||
m_approve = new RadioGroup(new BooleanParameter("approve"));
|
|
||||||
m_approve.addOption(new Option(
|
|
||||||
"true",
|
|
||||||
new Label(gz("cms.ui.workflow.task.approve"))));
|
|
||||||
m_approve.addOption(new Option(
|
|
||||||
"false",
|
|
||||||
new Label(gz("cms.ui.workflow.task.reject"))));
|
|
||||||
|
|
||||||
m_approvePrompt = new Label(gz("cms.ui.workflow.task.approve_prompt"));
|
|
||||||
|
|
||||||
addComponent(m_approvePrompt);
|
|
||||||
addComponent(m_approve);
|
|
||||||
|
|
||||||
addInitListener(new InitListener());
|
|
||||||
addValidationListener(new ValidationListener());
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InitListener implements FormInitListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void init(final FormSectionEvent e) {
|
|
||||||
LOGGER.debug("Initializing task finish");
|
|
||||||
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (isVisible(state)) {
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
if (requiresApproval(task)) {
|
|
||||||
m_approvePrompt.setVisible(state, true);
|
|
||||||
m_approve.setVisible(state, true);
|
|
||||||
} else {
|
|
||||||
m_approvePrompt.setVisible(state, false);
|
|
||||||
m_approve.setVisible(state, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ValidationListener implements FormValidationListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void validate(final FormSectionEvent e)
|
|
||||||
throws FormProcessException {
|
|
||||||
LOGGER.debug("Validating task finish");
|
|
||||||
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
if (requiresApproval(task) && m_approve.getValue(state) == null) {
|
|
||||||
throw new FormProcessException(new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.task.approval_or_reject_required",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
LOGGER.debug("Processing task finish");
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
boolean finishedTask = false;
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
final Optional<ContentItem> item = itemRepo.findItemWithWorkflow(
|
|
||||||
task.getWorkflow());
|
|
||||||
|
|
||||||
if (!item.isPresent()) {
|
|
||||||
throw new UncheckedWrapperException(
|
|
||||||
"Workflow not assigned to an item");
|
|
||||||
}
|
|
||||||
|
|
||||||
permissionChecker.checkPermission(task.getTaskType().getPrivilege(),
|
|
||||||
item.get());
|
|
||||||
|
|
||||||
final TaskFinishFormController controller = cdiUtil
|
|
||||||
.findBean(TaskFinishFormController.class);
|
|
||||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
|
||||||
ConfigurationManager.class);
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
|
|
||||||
if (requiresApproval(task)) {
|
|
||||||
LOGGER.debug("The task requires approval; checking to see "
|
|
||||||
+ "if it's approved");
|
|
||||||
|
|
||||||
// XXX I think the fact that this returns a Boolean is
|
|
||||||
// the effect of broken parameter marshalling in
|
|
||||||
// Bebop.
|
|
||||||
final Boolean isApproved = (Boolean) m_approve.getValue(state);
|
|
||||||
|
|
||||||
if (isApproved.equals(Boolean.TRUE)) {
|
|
||||||
LOGGER.debug("The task is approved; finishing the task");
|
|
||||||
|
|
||||||
controller.finish(task);
|
|
||||||
finishedTask = true;
|
|
||||||
} else {
|
|
||||||
LOGGER.debug("The task is rejected; reenabling dependent "
|
|
||||||
+ "tasks");
|
|
||||||
|
|
||||||
// Reenable the previous tasks.
|
|
||||||
for (final TaskDependency blockedTask : task
|
|
||||||
.getBlockedTasks()) {
|
|
||||||
LOGGER.debug("Reenabling task {}",
|
|
||||||
blockedTask
|
|
||||||
.getBlockedTask()
|
|
||||||
.getLabel()
|
|
||||||
.getValue(kernelConfig
|
|
||||||
.getDefaultLocale()));
|
|
||||||
|
|
||||||
controller.enable(blockedTask.getBlockedTask());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOGGER.debug("The task does not require approval; finishing it");
|
|
||||||
|
|
||||||
controller.finish(task);
|
|
||||||
finishedTask = true;
|
|
||||||
}
|
|
||||||
if (finishedTask) {
|
|
||||||
final Workflow workflow = task.getWorkflow();
|
|
||||||
final List<AssignableTask> tasks = controller.findEnabledTasks(
|
|
||||||
workflow);
|
|
||||||
for (final AssignableTask currentTask : tasks) {
|
|
||||||
if (!(currentTask instanceof CmsTask)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CmsTask currentCmsTask = (CmsTask) currentTask;
|
|
||||||
final String privilege = currentCmsTask.getTaskType()
|
|
||||||
.getPrivilege();
|
|
||||||
if (permissionChecker.isPermitted(privilege,
|
|
||||||
workflow.getObject())) {
|
|
||||||
//Lock task for current user
|
|
||||||
controller.lock(currentCmsTask);
|
|
||||||
|
|
||||||
if (CmsTaskType.DEPLOY == currentCmsTask.getTaskType()) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.there(
|
|
||||||
state.getRequest(),
|
|
||||||
controller
|
|
||||||
.getContentItemPublishUrl(item.get())),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// redirect to /content-center if streamlined creation mode is active.
|
|
||||||
final CMSConfig cmsConfig = confManager.findConfiguration(
|
|
||||||
CMSConfig.class);
|
|
||||||
if (cmsConfig.isUseStreamlinedCreation()) {
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.there(state.getRequest(),
|
|
||||||
CmsConstants.CONTENT_CENTER_URL),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean requiresApproval(final CmsTask task) {
|
|
||||||
return task.getTaskType() != CmsTaskType.AUTHOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,139 +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 com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
|
||||||
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.Shiro;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.workflow.AssignableTask;
|
|
||||||
import org.libreccm.workflow.AssignableTaskManager;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.TaskManager;
|
|
||||||
import org.libreccm.workflow.TaskRepository;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RequestScoped
|
|
||||||
public class TaskFinishFormController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentItemRepository itemRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TaskRepository taskRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TaskManager taskManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private AssignableTaskManager assignableTaskManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private Shiro shiro;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<AssignableTask> findEnabledTasks(final Workflow workflow) {
|
|
||||||
final User user = shiro.getUser().get();
|
|
||||||
final List<Role> roles = user.getRoleMemberships().stream()
|
|
||||||
.map(membership -> membership.getRole())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return assignableTaskManager.findAssignedTasks(workflow, roles);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void addComment(final CmsTask task, final String comment) {
|
|
||||||
|
|
||||||
final Task theTask = taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Task with ID %d in the database.",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
taskManager.addComment(theTask, comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void lock(final AssignableTask task) {
|
|
||||||
|
|
||||||
final AssignableTask theTask = (AssignableTask) taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Task with ID %d in the database.",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
assignableTaskManager.unlockTask(theTask);
|
|
||||||
assignableTaskManager.lockTask(theTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void enable(final Task task) {
|
|
||||||
|
|
||||||
final Task theTask = taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Task with ID %d in the database.",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
taskManager.enable(theTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void finish(final CmsTask task) {
|
|
||||||
|
|
||||||
final Task theTask = taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Task with ID %d in the database.",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
taskManager.finish(theTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public String getContentItemPublishUrl(final ContentItem item) {
|
|
||||||
|
|
||||||
final ContentItem contentItem = itemRepo
|
|
||||||
.findById(item.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No ContentItem with ID %d in the database.",
|
|
||||||
item.getObjectId())));
|
|
||||||
|
|
||||||
return ContentItemPage.getItemURL(contentItem,
|
|
||||||
ContentItemPage.PUBLISHING_TAB);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,479 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the CCM Public
|
|
||||||
* License (the "License"); you may not use this file except in
|
|
||||||
* compliance with the License. You may obtain a copy of the
|
|
||||||
* License at http://www.redhat.com/licenses/ccmpl.html.
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an
|
|
||||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
||||||
* or implied. See the License for the specific language
|
|
||||||
* governing rights and limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.bebop.event.TableActionAdapter;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
|
||||||
import com.arsdigita.cms.ui.VisibilityComponent;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
|
||||||
import com.arsdigita.toolbox.ui.Property;
|
|
||||||
import com.arsdigita.toolbox.ui.PropertyList;
|
|
||||||
import com.arsdigita.toolbox.ui.Section;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
import org.libreccm.security.Shiro;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.AssignableTask;
|
|
||||||
import org.libreccm.workflow.AssignableTaskManager;
|
|
||||||
import org.libreccm.workflow.TaskDependency;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
final class TaskItemPane extends BaseItemPane {
|
|
||||||
|
|
||||||
private final WorkflowRequestLocal m_workflow;
|
|
||||||
private final TaskRequestLocal m_task;
|
|
||||||
|
|
||||||
private final SimpleContainer m_detailPane;
|
|
||||||
|
|
||||||
TaskItemPane(final WorkflowRequestLocal workflow,
|
|
||||||
final TaskRequestLocal task,
|
|
||||||
final ActionLink finishLink,
|
|
||||||
final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink,
|
|
||||||
final ActionLink backLink) {
|
|
||||||
m_workflow = workflow;
|
|
||||||
m_task = task;
|
|
||||||
|
|
||||||
m_detailPane = new SimpleContainer();
|
|
||||||
m_detailPane.add(new Navigation(backLink));
|
|
||||||
m_detailPane.add(new SummarySection(finishLink, editLink, deleteLink));
|
|
||||||
|
|
||||||
// Users
|
|
||||||
final ActionLink userAddLink = new ActionLink(new Label(gz(
|
|
||||||
"cms.ui.workflow.task.user.add")));
|
|
||||||
|
|
||||||
final TaskAddUser userAddPane = new TaskAddUser(m_task);
|
|
||||||
|
|
||||||
final Form search = userAddPane.getSearchForm();
|
|
||||||
final Form add = userAddPane.getAddForm().getForm();
|
|
||||||
|
|
||||||
// Roles
|
|
||||||
final ActionLink roleAddLink = new ActionLink(new Label(gz(
|
|
||||||
"cms.ui.workflow.task.role.add")));
|
|
||||||
|
|
||||||
final TaskAddRole roleAddForm = new TaskAddRole(m_task);
|
|
||||||
|
|
||||||
m_detailPane.add(new RoleSection(roleAddLink));
|
|
||||||
|
|
||||||
add(m_detailPane);
|
|
||||||
setDefault(m_detailPane);
|
|
||||||
add(userAddPane);
|
|
||||||
add(roleAddForm);
|
|
||||||
|
|
||||||
userAddLink.addActionListener(new NavigationListener(userAddPane));
|
|
||||||
search.addSubmissionListener(new CancelListener(search));
|
|
||||||
add.addSubmissionListener(new CancelListener(add));
|
|
||||||
add.addProcessListener(new FormNavigationListener(m_detailPane));
|
|
||||||
|
|
||||||
connect(roleAddLink, roleAddForm);
|
|
||||||
resume(roleAddForm, m_detailPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasAdmin(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
return permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_WORKFLOWS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AdminVisible extends VisibilityComponent {
|
|
||||||
|
|
||||||
public AdminVisible(final Component child) {
|
|
||||||
super(child, AdminPrivileges.ADMINISTER_WORKFLOWS);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AssigneeVisible extends AdminVisible {
|
|
||||||
|
|
||||||
private final Component m_child;
|
|
||||||
private final Assigned m_assigned;
|
|
||||||
|
|
||||||
public AssigneeVisible(final Component child) {
|
|
||||||
super(child);
|
|
||||||
|
|
||||||
m_child = child;
|
|
||||||
m_assigned = new Assigned();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
if (m_child.isVisible(state)) {
|
|
||||||
return m_assigned.isAssigned(state) || hasPermission(state);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Assigned extends RequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
if (assigned(state)) {
|
|
||||||
return Boolean.TRUE;
|
|
||||||
} else {
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean assigned(final PageState state) {
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final AssignableTaskManager taskManager = cdiUtil.findBean(
|
|
||||||
AssignableTaskManager.class);
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
|
|
||||||
final User user = shiro.getUser().get();
|
|
||||||
|
|
||||||
final List<AssignableTask> tasks = taskManager.lockedBy(user);
|
|
||||||
|
|
||||||
return tasks.contains(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isAssigned(final PageState state) {
|
|
||||||
return ((Boolean) get(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class VisibilityListener implements ActionListener {
|
|
||||||
|
|
||||||
private final TableColumn m_column;
|
|
||||||
|
|
||||||
VisibilityListener(final TableColumn column) {
|
|
||||||
m_column = column;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (state.isVisibleOnPage(TaskItemPane.this) && !hasAdmin(state)) {
|
|
||||||
m_column.setVisible(state, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Navigation extends ActionGroup {
|
|
||||||
|
|
||||||
Navigation(final ActionLink backLink) {
|
|
||||||
addAction(backLink, ActionGroup.RETURN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SummarySection extends Section {
|
|
||||||
|
|
||||||
SummarySection(final ActionLink finishLink,
|
|
||||||
final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
setHeading(new Label(gz("cms.ui.workflow.task.details")));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(new Properties());
|
|
||||||
group.addAction(new AssigneeVisible(new LockLink()));
|
|
||||||
group.addAction(new AssigneeVisible(new UnlockLink()));
|
|
||||||
group.addAction(new AssigneeVisible(finishLink));
|
|
||||||
group.addAction(new AdminVisible(editLink), ActionGroup.EDIT);
|
|
||||||
group.addAction(new AdminVisible(deleteLink), ActionGroup.DELETE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LockLink extends ActionLink {
|
|
||||||
|
|
||||||
LockLink() {
|
|
||||||
super(new Label(gz("cms.ui.workflow.task.lock")));
|
|
||||||
|
|
||||||
addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
return task.isActive() && !task.isLocked();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (hasAdmin(state)) {
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final AssignableTaskManager taskManager = cdiUtil
|
|
||||||
.findBean(AssignableTaskManager.class);
|
|
||||||
taskManager.lockTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UnlockLink extends ActionLink {
|
|
||||||
|
|
||||||
UnlockLink() {
|
|
||||||
super(new Label(gz("cms.ui.workflow.task.unlock")));
|
|
||||||
|
|
||||||
addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isVisible(final PageState state) {
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
return task.isActive() && task.isLocked();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (hasAdmin(state)) {
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final AssignableTaskManager taskManager = cdiUtil
|
|
||||||
.findBean(AssignableTaskManager.class);
|
|
||||||
taskManager.unlockTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Properties extends PropertyList {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final List<Property> properties(final PageState state) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final List<Property> props = super.properties(state);
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
props.add(new Property(gz("cms.ui.workflow.task.name"),
|
|
||||||
task.getLabel().getValue(defaultLocale)));
|
|
||||||
props.add(new Property(gz("cms.ui.workflow.task.description"),
|
|
||||||
task.getDescription().getValue(
|
|
||||||
defaultLocale)));
|
|
||||||
props.add(new Property(gz("cms.ui.workflow.task.dependencies"),
|
|
||||||
deps(task)));
|
|
||||||
if (task.getTaskState() == null) {
|
|
||||||
props.add(new Property(gz("cms.ui.workflow.task.state"),
|
|
||||||
gz("cms.ui.workflow.task.state.none")));
|
|
||||||
} else {
|
|
||||||
props.add(new Property(gz("cms.ui.workflow.task.state"),
|
|
||||||
task.getTaskState().toString()));
|
|
||||||
}
|
|
||||||
if (task.isLocked()) {
|
|
||||||
props.add(new Property(gz("cms.ui.workflow.task.locked"),
|
|
||||||
gz("cms.ui.yes")));
|
|
||||||
} else {
|
|
||||||
props.add(new Property(gz("cms.ui.workflow.task.locked"),
|
|
||||||
gz("cms.ui.no")));
|
|
||||||
}
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String deps(final CmsTask task) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
final List<TaskDependency> blockedTasks = controller
|
|
||||||
.getBlockedTasks(task);
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
return blockedTasks
|
|
||||||
.stream()
|
|
||||||
.map(TaskDependency::getBlockedTask)
|
|
||||||
.map(blockedTask -> blockedTask.getLabel().getValue(
|
|
||||||
defaultLocale))
|
|
||||||
.collect(Collectors.joining(", "));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RoleSection extends Section {
|
|
||||||
|
|
||||||
public RoleSection(final ActionLink roleAddLink) {
|
|
||||||
setHeading(new Label(gz("cms.ui.workflow.task.roles")));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(new RoleTable());
|
|
||||||
group.addAction(new AdminVisible(roleAddLink), ActionGroup.ADD);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RoleTable extends Table {
|
|
||||||
|
|
||||||
public RoleTable() {
|
|
||||||
super(new RoleTableModelBuilder(m_task),
|
|
||||||
new String[]{
|
|
||||||
lz("cms.ui.workflow.task.role.name"),
|
|
||||||
lz("cms.ui.workflow.task.role.delete")
|
|
||||||
});
|
|
||||||
|
|
||||||
setEmptyView(new Label(gz("cms.ui.workflow.task.role.none")));
|
|
||||||
|
|
||||||
getColumn(1).setCellRenderer(new DefaultTableCellRenderer(true));
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionAdapter() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final int column = event.getColumn();
|
|
||||||
|
|
||||||
if (column == 1) {
|
|
||||||
if (hasAdmin(state)) {
|
|
||||||
final CmsTask task = m_task.getTask(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller =
|
|
||||||
cdiUtil.findBean(WorkflowAdminPaneController.class);
|
|
||||||
controller.removeAssignment(task,
|
|
||||||
(String) event.getRowKey());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addActionListener(new VisibilityListener(getColumn(1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class RoleTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final TaskRequestLocal m_task;
|
|
||||||
|
|
||||||
public RoleTableModelBuilder(final TaskRequestLocal task) {
|
|
||||||
m_task = task;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
return new Model(m_task.getTask(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Model implements TableModel {
|
|
||||||
|
|
||||||
private final List<Role> roles;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
private Model(final CmsTask task) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil.findBean(
|
|
||||||
WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
roles = controller.findAssignees(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int getColumnCount() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < roles.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getKeyAt(final int column) {
|
|
||||||
return Long.toString(roles.get(index).getRoleId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getElementAt(final int column) {
|
|
||||||
switch (column) {
|
|
||||||
case 0:
|
|
||||||
return roles.get(index).getName();
|
|
||||||
case 1:
|
|
||||||
return lz("cms.ui.workflow.task.role.delete");
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
|
|
||||||
public abstract class TaskRequestLocal extends RequestLocal {
|
|
||||||
|
|
||||||
public final CmsTask getTask(final PageState state) {
|
|
||||||
final CmsTask task = (CmsTask) get(state);
|
|
||||||
|
|
||||||
Assert.exists(task, "CmsTask task");
|
|
||||||
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,161 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
class TaskTableModelBuilder extends AbstractTableModelBuilder {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
TaskTableModelBuilder.class);
|
|
||||||
|
|
||||||
private final WorkflowRequestLocal workflow;
|
|
||||||
|
|
||||||
TaskTableModelBuilder(final WorkflowRequestLocal workflow) {
|
|
||||||
this.workflow = workflow;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
LOGGER.debug("Creating a new table model for the current request");
|
|
||||||
|
|
||||||
return new Model(workflow.getWorkflow(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Model implements TableModel {
|
|
||||||
|
|
||||||
private Task currentTask;
|
|
||||||
private Iterator<Task> tasksIterator;
|
|
||||||
private Map<Task, String> dependencies;
|
|
||||||
|
|
||||||
private Model(final Workflow workflow) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil.findBean(
|
|
||||||
WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
final TaskTableModelData data = controller
|
|
||||||
.getTaskTableModelData(workflow);
|
|
||||||
tasksIterator = data.getTasks();
|
|
||||||
dependencies = data.getDependencies();
|
|
||||||
|
|
||||||
|
|
||||||
// final Iterator<Task> tasksIter = controller
|
|
||||||
// .getTasksForWorkflow(workflow)
|
|
||||||
// .iterator();
|
|
||||||
// GraphSet graphSet = new GraphSet();
|
|
||||||
//
|
|
||||||
// while (tasksIter.hasNext()) {
|
|
||||||
// Task task = tasksIter.next();
|
|
||||||
// final Iterator<Task> deps = task.getDependsOn().iterator();
|
|
||||||
// final StringBuffer buffer = new StringBuffer();
|
|
||||||
// while (deps.hasNext()) {
|
|
||||||
// Task dep = deps.next();
|
|
||||||
// graphSet.addEdge(task, dep, null);
|
|
||||||
// buffer
|
|
||||||
// .append(dep.getLabel())
|
|
||||||
// .append(", ");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// final int len = buffer.length();
|
|
||||||
// if (len >= 2) {
|
|
||||||
// buffer.setLength(len - 2);
|
|
||||||
// } else {
|
|
||||||
// graphSet.addNode(task);
|
|
||||||
// }
|
|
||||||
// m_dependencies.put(task, buffer.toString());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// List tasks = new ArrayList();
|
|
||||||
// outer:
|
|
||||||
// while (graphSet.nodeCount() > 0) {
|
|
||||||
// List list = Graphs.getSinkNodes(graphSet);
|
|
||||||
// for (Iterator it = list.iterator(); it.hasNext();) {
|
|
||||||
// Task t = (Task) it.next();
|
|
||||||
// tasks.add(t);
|
|
||||||
// graphSet.removeNode(t);
|
|
||||||
// continue outer;
|
|
||||||
// }
|
|
||||||
// // break loop if no nodes removed
|
|
||||||
// LOGGER.error("found possible loop in tasks for " + workflow);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// m_tasks = tasks.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean nextRow() {
|
|
||||||
if (tasksIterator.hasNext()) {
|
|
||||||
currentTask = tasksIterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getKeyAt(final int column) {
|
|
||||||
return currentTask.getTaskId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getElementAt(final int column) {
|
|
||||||
final Locale defaultLocale = KernelConfig.getConfig().getDefaultLocale();
|
|
||||||
|
|
||||||
switch (column) {
|
|
||||||
case 0:
|
|
||||||
return currentTask.getLabel().getValue(defaultLocale);
|
|
||||||
case 1:
|
|
||||||
return currentTask.getDescription().getValue(defaultLocale);
|
|
||||||
case 2:
|
|
||||||
return dependencies.get(currentTask);
|
|
||||||
case 3:
|
|
||||||
return "";
|
|
||||||
// return m_task.getStateString();
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 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.cms.ui.workflow;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class TaskTableModelData {
|
|
||||||
|
|
||||||
private final Iterator<Task> tasks;
|
|
||||||
private final Map<Task, String> dependencies;
|
|
||||||
|
|
||||||
protected TaskTableModelData(final Iterator<Task> tasks,
|
|
||||||
final Map<Task, String> dependencies) {
|
|
||||||
this.tasks = tasks;
|
|
||||||
this.dependencies = dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator<Task> getTasks() {
|
|
||||||
return tasks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Task, String> getDependencies() {
|
|
||||||
return dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,486 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 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.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
import com.arsdigita.toolbox.ui.Property;
|
|
||||||
import com.arsdigita.util.GraphSet;
|
|
||||||
import com.arsdigita.util.Graphs;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
import org.libreccm.workflow.AssignableTaskManager;
|
|
||||||
import org.libreccm.workflow.CircularTaskDependencyException;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.TaskDependency;
|
|
||||||
import org.libreccm.workflow.TaskManager;
|
|
||||||
import org.libreccm.workflow.TaskRepository;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.libreccm.workflow.WorkflowRepository;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
import org.librecms.contentsection.ContentSectionManager;
|
|
||||||
import org.librecms.contentsection.ContentSectionRepository;
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RequestScoped
|
|
||||||
public class WorkflowAdminPaneController {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager
|
|
||||||
.getLogger(WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ConfigurationManager confManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentSectionRepository sectionRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentSectionManager sectionManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private WorkflowRepository workflowRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TaskRepository taskRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TaskManager taskManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private AssignableTaskManager assignableTaskManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RoleRepository roleRepo;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<Workflow> retrieveWorkflows(final ContentSection section) {
|
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
|
||||||
.findById(section.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No ContentSection with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
section.getObjectId())));
|
|
||||||
|
|
||||||
return new ArrayList<>(contentSection.getWorkflowTemplates());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public List<Map<String, String>> listWorkflowTemplates(
|
|
||||||
final ContentSection section
|
|
||||||
) {
|
|
||||||
final List<Workflow> templates = retrieveWorkflows(section);
|
|
||||||
return templates
|
|
||||||
.stream()
|
|
||||||
.map(this::buildWorkflowTemplateListItem)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> buildWorkflowTemplateListItem(
|
|
||||||
final Workflow workflow
|
|
||||||
) {
|
|
||||||
final Map<String, String> item = new HashMap<>();
|
|
||||||
item.put(
|
|
||||||
WorkflowListModelBuilder.WORKFLOW_TEMPLATE_ID,
|
|
||||||
Long.toString(workflow.getWorkflowId())
|
|
||||||
);
|
|
||||||
item.put(
|
|
||||||
WorkflowListModelBuilder.WORKFLOW_TEMPLATE_NAME,
|
|
||||||
workflow
|
|
||||||
.getName()
|
|
||||||
.getValue(KernelConfig.getConfig().getDefaultLocale()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<Property> getWorkflowProperties(final Workflow ofWorkflow) {
|
|
||||||
final Workflow workflow = workflowRepo
|
|
||||||
.findById(ofWorkflow.getWorkflowId())
|
|
||||||
.orElseThrow(
|
|
||||||
() -> new IllegalArgumentException(
|
|
||||||
String.format(
|
|
||||||
"No Workflow with ID %d available.",
|
|
||||||
ofWorkflow.getWorkflowId()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final List<Property> properties = new ArrayList<>();
|
|
||||||
properties.add(
|
|
||||||
new Property(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.name", CmsConstants.CMS_BUNDLE
|
|
||||||
),
|
|
||||||
workflow.getName().getValue(defaultLocale)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
properties.add(
|
|
||||||
new Property(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.description",
|
|
||||||
CmsConstants.CMS_BUNDLE
|
|
||||||
),
|
|
||||||
workflow.getDescription().getValue(defaultLocale)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (workflow.getState() == null) {
|
|
||||||
properties.add(
|
|
||||||
new Property(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.current_state",
|
|
||||||
CmsConstants.CMS_BUNDLE
|
|
||||||
),
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.current_state.none",
|
|
||||||
CmsConstants.CMS_BUNDLE
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
properties.add(
|
|
||||||
new Property(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.workflow.current_state",
|
|
||||||
CmsConstants.CMS_BUNDLE
|
|
||||||
),
|
|
||||||
workflow.getState().toString()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public Workflow createWorkflow(final ContentSection section,
|
|
||||||
final String name,
|
|
||||||
final String desc) {
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
|
||||||
.findById(section.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No ContentSection with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
section.getObjectId())));
|
|
||||||
|
|
||||||
final Workflow workflowTemplate = new Workflow();
|
|
||||||
workflowTemplate.setAbstractWorkflow(true);
|
|
||||||
workflowTemplate.getName().putValue(defaultLocale, name);
|
|
||||||
workflowTemplate.getDescription().putValue(defaultLocale, desc);
|
|
||||||
|
|
||||||
workflowRepo.save(workflowTemplate);
|
|
||||||
|
|
||||||
sectionManager.addWorkflowTemplateToContentSection(workflowTemplate,
|
|
||||||
contentSection);
|
|
||||||
|
|
||||||
return workflowTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<Task> getTasksForWorkflow(final Workflow workflow) {
|
|
||||||
|
|
||||||
final Workflow theWorkflow = workflowRepo
|
|
||||||
.findById(workflow.getWorkflowId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Workflow with ID %d in the database. Where did that ID come from?",
|
|
||||||
workflow.getWorkflowId())));
|
|
||||||
|
|
||||||
return new ArrayList<>(theWorkflow.getTasks());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public CmsTask addTask(final Workflow workflow,
|
|
||||||
final String name,
|
|
||||||
final String desc,
|
|
||||||
final CmsTaskType type,
|
|
||||||
final String[] deps) {
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final Workflow theWorkflow = workflowRepo
|
|
||||||
.findById(workflow.getWorkflowId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Workflow with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
workflow.getWorkflowId())));
|
|
||||||
final CmsTask task = new CmsTask();
|
|
||||||
|
|
||||||
task.getLabel().putValue(defaultLocale, name);
|
|
||||||
task.getDescription().putValue(defaultLocale, desc);
|
|
||||||
task.setTaskType(type);
|
|
||||||
// task.setActive(true);
|
|
||||||
|
|
||||||
taskRepo.save(task);
|
|
||||||
|
|
||||||
taskManager.addTask(theWorkflow, task);
|
|
||||||
|
|
||||||
processDependencies(task, deps);
|
|
||||||
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void updateTask(final Task task,
|
|
||||||
final String name,
|
|
||||||
final String desc,
|
|
||||||
final CmsTaskType type,
|
|
||||||
final String[] deps) {
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final CmsTask theTask = (CmsTask) taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Task with ID %d in the database. Where did that ID come from?",
|
|
||||||
task.getTaskId())));
|
|
||||||
theTask.getLabel().putValue(defaultLocale, name);
|
|
||||||
theTask.getDescription().putValue(defaultLocale, desc);
|
|
||||||
theTask.setTaskType(type);
|
|
||||||
|
|
||||||
taskRepo.save(theTask);
|
|
||||||
|
|
||||||
processDependencies(theTask, deps);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method decides which dependencies have to be removed and which ones
|
|
||||||
* newly added. Unfortunately we cannot just do "remove all", and add the
|
|
||||||
* new ones in since it is possible that Tasks will fire events when
|
|
||||||
* dependencies are added and removed.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void processDependencies(final Task task,
|
|
||||||
final String[] selectedDependencies) {
|
|
||||||
final List<TaskDependency> blockedTasks = task.getBlockedTasks();
|
|
||||||
final Map<Long, Task> toAdd = new HashMap<>();
|
|
||||||
// Everything is to be removed unless it is in the array.
|
|
||||||
final Map<Long, Task> toRemove = blockedTasks
|
|
||||||
.stream()
|
|
||||||
.map(TaskDependency::getBlockedTask)
|
|
||||||
.collect(Collectors.toMap(Task::getTaskId,
|
|
||||||
dependency -> dependency));
|
|
||||||
|
|
||||||
Long selectedId;
|
|
||||||
Object addedTask;
|
|
||||||
if (selectedDependencies != null) {
|
|
||||||
for (String selectedDependency : selectedDependencies) {
|
|
||||||
selectedId = Long.parseLong(selectedDependency);
|
|
||||||
addedTask = toRemove.remove(selectedId);
|
|
||||||
if (addedTask == null) {
|
|
||||||
toAdd.put(selectedId, taskRepo.findById(selectedId).get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Task taskToRemove : toRemove.values()) {
|
|
||||||
taskManager.removeDependentTask(task, taskToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Task taskToAdd : toAdd.values()) {
|
|
||||||
try {
|
|
||||||
taskManager.addDependentTask(task, taskToAdd);
|
|
||||||
} catch (CircularTaskDependencyException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<TaskDependency> getBlockedTasks(final Task task) {
|
|
||||||
|
|
||||||
final Task theTask = taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Task with ID %d in the database. Where did that ID come from?",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
return new ArrayList<>(theTask.getBlockedTasks());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
TaskTableModelData getTaskTableModelData(final Workflow workflow) {
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final Map<Task, String> dependencies = new HashMap<>();
|
|
||||||
|
|
||||||
final Iterator<Task> tasksIter = getTasksForWorkflow(workflow)
|
|
||||||
.iterator();
|
|
||||||
final GraphSet graphSet = new GraphSet();
|
|
||||||
|
|
||||||
while (tasksIter.hasNext()) {
|
|
||||||
Task task = tasksIter.next();
|
|
||||||
final Iterator<TaskDependency> deps = task
|
|
||||||
.getBlockingTasks()
|
|
||||||
.iterator();
|
|
||||||
final StringBuffer buffer = new StringBuffer();
|
|
||||||
while (deps.hasNext()) {
|
|
||||||
Task dep = deps.next().getBlockingTask();
|
|
||||||
graphSet.addEdge(task, dep, null);
|
|
||||||
buffer
|
|
||||||
.append(dep.getLabel().getValue(defaultLocale))
|
|
||||||
.append(", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
final int len = buffer.length();
|
|
||||||
if (len >= 2) {
|
|
||||||
buffer.setLength(len - 2);
|
|
||||||
} else {
|
|
||||||
graphSet.addNode(task);
|
|
||||||
}
|
|
||||||
dependencies.put(task, buffer.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Task> tasks = new ArrayList<>();
|
|
||||||
outer:
|
|
||||||
while (graphSet.nodeCount() > 0) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final List<Task> list = Graphs.getSinkNodes(graphSet);
|
|
||||||
for (final Iterator<Task> it = list.iterator(); it.hasNext();) {
|
|
||||||
final Task currentTask = it.next();
|
|
||||||
tasks.add(currentTask);
|
|
||||||
graphSet.removeNode(currentTask);
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
// break loop if no nodes removed
|
|
||||||
LOGGER.error("found possible loop in tasks for " + workflow);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//final Iterator<Task> taskIterator = tasks.iterator();
|
|
||||||
final Iterator<Task> taskIterator = getTasksForWorkflow(workflow)
|
|
||||||
.iterator();
|
|
||||||
|
|
||||||
return new TaskTableModelData(taskIterator, dependencies);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<Role> findAssignees(final CmsTask task) {
|
|
||||||
final CmsTask theTask = (CmsTask) taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Task with ID %d in the database. Where did that ID come from?",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
return theTask
|
|
||||||
.getAssignments()
|
|
||||||
.stream()
|
|
||||||
.map(assignment -> assignment.getRole())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<Role> findRoles(final ContentSection section) {
|
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
|
||||||
.findById(section.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No ContentSection with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
section.getObjectId())));
|
|
||||||
|
|
||||||
return new ArrayList<>(contentSection.getRoles());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void assignTask(final Task task, final String[] roleIds) {
|
|
||||||
|
|
||||||
final CmsTask theTask = (CmsTask) taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Task with ID %d in the database. Where did that ID come from?",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
theTask.getAssignments()
|
|
||||||
.forEach(assignment -> assignableTaskManager
|
|
||||||
.retractTask(theTask, assignment.getRole()));
|
|
||||||
|
|
||||||
if (roleIds != null) {
|
|
||||||
final List<Role> roles = Arrays
|
|
||||||
.stream(roleIds)
|
|
||||||
.map(roleId -> Long.parseLong(roleId))
|
|
||||||
.map(roleId -> roleRepo.findById(roleId).orElseThrow(
|
|
||||||
() -> new IllegalArgumentException(String.format(
|
|
||||||
"No role with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?", roleId))))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
roles.forEach(role -> assignableTaskManager
|
|
||||||
.assignTask(theTask, role));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void removeAssignment(final Task task, final String roleId) {
|
|
||||||
|
|
||||||
final Role role = roleRepo
|
|
||||||
.findById(Long.parseLong(roleId))
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Role with ID %s in the database. Where did that ID come from?",
|
|
||||||
roleId)));
|
|
||||||
|
|
||||||
final CmsTask theTask = (CmsTask) taskRepo
|
|
||||||
.findById(task.getTaskId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No Task with ID %d in the database. Where did that ID come from?",
|
|
||||||
task.getTaskId())));
|
|
||||||
|
|
||||||
assignableTaskManager.retractTask(theTask, role);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.libreccm.workflow.WorkflowRepository;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @version $Id: WorkflowDeleteForm.java 287 2005-02-22 00:29:02Z sskracic $
|
|
||||||
*/
|
|
||||||
|
|
||||||
class WorkflowDeleteForm extends BaseDeleteForm {
|
|
||||||
|
|
||||||
final WorkflowRequestLocal m_workflow;
|
|
||||||
|
|
||||||
WorkflowDeleteForm(final WorkflowRequestLocal workflow) {
|
|
||||||
super(new Label(gz("cms.ui.workflow.delete_prompt")));
|
|
||||||
|
|
||||||
m_workflow = workflow;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final Workflow workflow = m_workflow.getWorkflow(event.getPageState());
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowRepository workflowRepo = cdiUtil.findBean(WorkflowRepository.class);
|
|
||||||
workflowRepo.delete(workflow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.FormInitListener;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.libreccm.workflow.WorkflowRepository;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Uday Mathur
|
|
||||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class WorkflowEditForm extends BaseWorkflowForm {
|
|
||||||
|
|
||||||
private final WorkflowRequestLocal m_workflow;
|
|
||||||
|
|
||||||
WorkflowEditForm(final WorkflowRequestLocal workflow) {
|
|
||||||
super("workflow", gz("cms.ui.workflow.edit"));
|
|
||||||
|
|
||||||
m_workflow = workflow;
|
|
||||||
|
|
||||||
addInitListener(new InitListener());
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final Workflow workflow = m_workflow.getWorkflow(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowRepository workflowRepo = cdiUtil.findBean(
|
|
||||||
WorkflowRepository.class);
|
|
||||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
|
||||||
ConfigurationManager.class);
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
workflow.getName().putValue(defaultLocale,
|
|
||||||
(String) m_title.getValue(state));
|
|
||||||
workflow.getDescription().putValue(
|
|
||||||
defaultLocale,
|
|
||||||
(String) m_description.getValue(state));
|
|
||||||
|
|
||||||
workflowRepo.save(workflow);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InitListener implements FormInitListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void init(final FormSectionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final Workflow workflow = m_workflow.getWorkflow(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
|
||||||
ConfigurationManager.class);
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
m_title.setValue(state, workflow.getName().getValue(defaultLocale));
|
|
||||||
m_description.setValue(state, workflow.getDescription().getValue(
|
|
||||||
defaultLocale));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.List;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.list.AbstractListModelBuilder;
|
|
||||||
import com.arsdigita.bebop.list.ListModel;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a list of workflow templates registered to the current content
|
|
||||||
* section.
|
|
||||||
*
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class WorkflowListModelBuilder extends AbstractListModelBuilder {
|
|
||||||
|
|
||||||
protected static final String WORKFLOW_TEMPLATE_ID = "workflowTemplateId";
|
|
||||||
|
|
||||||
protected static final String WORKFLOW_TEMPLATE_NAME
|
|
||||||
= "workflowTemplateName";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final ListModel makeModel(final List list, final PageState state) {
|
|
||||||
return new Model();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Model implements ListModel {
|
|
||||||
|
|
||||||
private final Iterator<Map<String, String>> templates;
|
|
||||||
|
|
||||||
private Map<String, String> currentTemplate;
|
|
||||||
|
|
||||||
public Model() {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowAdminPaneController controller = cdiUtil.findBean(
|
|
||||||
WorkflowAdminPaneController.class);
|
|
||||||
|
|
||||||
templates = controller
|
|
||||||
.listWorkflowTemplates(CMS.getContext().getContentSection())
|
|
||||||
.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
if (templates.hasNext()) {
|
|
||||||
currentTemplate = templates.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return currentTemplate.get(WORKFLOW_TEMPLATE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKey() {
|
|
||||||
return currentTemplate.get(WORKFLOW_TEMPLATE_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public abstract class WorkflowRequestLocal extends RequestLocal {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public final Workflow getWorkflow(final PageState state) {
|
|
||||||
final Object object = get(state);
|
|
||||||
|
|
||||||
if (object instanceof Optional) {
|
|
||||||
return ((Optional<Workflow>) object).get();
|
|
||||||
} else {
|
|
||||||
return (Workflow) object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.cms.ui.workflow;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.PrintEvent;
|
|
||||||
import com.arsdigita.bebop.event.PrintListener;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.OptionGroup;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a list of workflow templates registered to the current content
|
|
||||||
* section.
|
|
||||||
*
|
|
||||||
* @author Uday Mathur (umathur@arsdigita.com)
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class WorkflowsOptionPrintListener implements PrintListener {
|
|
||||||
|
|
||||||
protected List<Workflow> getCollection(final PageState state) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final WorkflowsOptionPrintListenerController controller = cdiUtil
|
|
||||||
.findBean(WorkflowsOptionPrintListenerController.class);
|
|
||||||
|
|
||||||
return controller.getWorkflowTemplates(getContentSection(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ContentSection getContentSection(final PageState state) {
|
|
||||||
return CMS.getContext().getContentSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void prepare(final PrintEvent event) {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final OptionGroup target = (OptionGroup) event.getTarget();
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
final List<Workflow> templates = getCollection(state);
|
|
||||||
|
|
||||||
for (final Workflow template : templates) {
|
|
||||||
target.addOption(new Option(
|
|
||||||
Long.toString(template.getWorkflowId()),
|
|
||||||
template.getName().getValue(KernelConfig
|
|
||||||
.getConfig()
|
|
||||||
.getDefaultLocale())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 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.cms.ui.workflow;
|
|
||||||
|
|
||||||
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
import org.librecms.contentsection.ContentSectionRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RequestScoped
|
|
||||||
class WorkflowsOptionPrintListenerController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentSectionRepository sectionRepo;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<Workflow> getWorkflowTemplates(
|
|
||||||
final ContentSection section) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(section);
|
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
|
||||||
.findById(section.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No ContentSection with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
section.getObjectId())));
|
|
||||||
|
|
||||||
return contentSection.getWorkflowTemplates();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue