Removed depcrecated package com.arsdigita.cms.ui.lifecycle from ccm-cms
parent
9d16918052
commit
db0f16f21b
|
|
@ -45,7 +45,6 @@ import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
||||||
import com.arsdigita.cms.ui.item.CustomizedPreviewLink;
|
import com.arsdigita.cms.ui.item.CustomizedPreviewLink;
|
||||||
import com.arsdigita.cms.ui.item.ItemLanguages;
|
import com.arsdigita.cms.ui.item.ItemLanguages;
|
||||||
import com.arsdigita.cms.ui.item.Summary;
|
import com.arsdigita.cms.ui.item.Summary;
|
||||||
import com.arsdigita.cms.ui.lifecycle.ItemLifecycleAdminPane;
|
|
||||||
import com.arsdigita.cms.ui.workflow.ItemWorkflowAdminPane;
|
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;
|
||||||
|
|
@ -167,8 +166,6 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
|
|
||||||
private final ItemWorkflowAdminPane workflowPane;
|
private final ItemWorkflowAdminPane workflowPane;
|
||||||
|
|
||||||
private final ItemLifecycleAdminPane lifecyclePane;
|
|
||||||
|
|
||||||
private final WizardSelector wizardPane;
|
private final WizardSelector wizardPane;
|
||||||
|
|
||||||
private final ItemLanguages languagesPane;
|
private final ItemLanguages languagesPane;
|
||||||
|
|
@ -294,7 +291,6 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
// selectedLanguageModel,
|
// selectedLanguageModel,
|
||||||
selectedLanguageParam);
|
selectedLanguageParam);
|
||||||
workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX
|
workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX
|
||||||
lifecyclePane = new ItemLifecycleAdminPane(itemRequestLocal);
|
|
||||||
|
|
||||||
// Create tabbed pane.
|
// Create tabbed pane.
|
||||||
tabbedPane = new TabbedPane();
|
tabbedPane = new TabbedPane();
|
||||||
|
|
@ -309,8 +305,6 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
languagesPane);
|
languagesPane);
|
||||||
tabbedPane.addTab(new Label(gz("cms.ui.item.workflow")),
|
tabbedPane.addTab(new Label(gz("cms.ui.item.workflow")),
|
||||||
workflowPane);
|
workflowPane);
|
||||||
tabbedPane.addTab(new Label(gz("cms.ui.item.lifecycles")),
|
|
||||||
lifecyclePane);
|
|
||||||
|
|
||||||
tabbedPane.addActionListener(new ActionListener() {
|
tabbedPane.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ package com.arsdigita.cms.ui;
|
||||||
import com.arsdigita.bebop.Component;
|
import com.arsdigita.bebop.Component;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.SimpleComponent;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
import com.arsdigita.bebop.SimpleContainer;
|
||||||
import com.arsdigita.bebop.TabbedPane;
|
import com.arsdigita.bebop.TabbedPane;
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
import com.arsdigita.bebop.event.ActionEvent;
|
||||||
|
|
@ -37,10 +36,8 @@ import org.librecms.contentsection.ContentSection;
|
||||||
import com.arsdigita.cms.dispatcher.CMSPage;
|
import com.arsdigita.cms.dispatcher.CMSPage;
|
||||||
import com.arsdigita.cms.ui.category.CategoryAdminPane;
|
import com.arsdigita.cms.ui.category.CategoryAdminPane;
|
||||||
import com.arsdigita.cms.ui.folder.FolderAdminPane;
|
import com.arsdigita.cms.ui.folder.FolderAdminPane;
|
||||||
import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane;
|
|
||||||
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
|
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
@ -134,8 +131,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
|
|
||||||
private WorkflowAdminPane m_workflowPane;
|
private WorkflowAdminPane m_workflowPane;
|
||||||
|
|
||||||
private LifecycleAdminPane m_lifecyclePane;
|
|
||||||
|
|
||||||
private CategoryAdminPane m_categoryPane;
|
private CategoryAdminPane m_categoryPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -155,7 +150,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
m_browsePane = getBrowsePane();
|
m_browsePane = getBrowsePane();
|
||||||
m_searchPane = getSearchPane();
|
m_searchPane = getSearchPane();
|
||||||
m_workflowPane = getWorkflowAdminPane();
|
m_workflowPane = getWorkflowAdminPane();
|
||||||
m_lifecyclePane = getLifecycleAdminPane();
|
|
||||||
m_categoryPane = getCategoryAdminPane();
|
m_categoryPane = getCategoryAdminPane();
|
||||||
|
|
||||||
// The panes
|
// The panes
|
||||||
|
|
@ -191,11 +185,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
m_categoryPane,
|
m_categoryPane,
|
||||||
permissionChecker.isPermitted(
|
permissionChecker.isPermitted(
|
||||||
AdminPrivileges.ADMINISTER_CATEGORIES));
|
AdminPrivileges.ADMINISTER_CATEGORIES));
|
||||||
m_tabbedPane.setTabVisible(
|
|
||||||
state,
|
|
||||||
m_lifecyclePane,
|
|
||||||
permissionChecker.isPermitted(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -256,17 +245,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
return m_workflowPane;
|
return m_workflowPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates, and then caches, the lifecycle administration pane. Overriding
|
|
||||||
* this method to return null will prevent this tab from appearing.
|
|
||||||
*/
|
|
||||||
protected LifecycleAdminPane getLifecycleAdminPane() {
|
|
||||||
if (m_lifecyclePane == null) {
|
|
||||||
m_lifecyclePane = new LifecycleAdminPane();
|
|
||||||
}
|
|
||||||
return m_lifecyclePane;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates, and then caches, the category administration pane. Overriding
|
* Creates, and then caches, the category administration pane. Overriding
|
||||||
* this method to return null will prevent this tab from appearing.
|
* this method to return null will prevent this tab from appearing.
|
||||||
|
|
@ -322,7 +301,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
tab(pane, "cms.ui.browse", getBrowsePane());
|
tab(pane, "cms.ui.browse", getBrowsePane());
|
||||||
tab(pane, "cms.ui.search", getSearchPane());
|
tab(pane, "cms.ui.search", getSearchPane());
|
||||||
tab(pane, "cms.ui.workflows", getWorkflowAdminPane());
|
tab(pane, "cms.ui.workflows", getWorkflowAdminPane());
|
||||||
tab(pane, "cms.ui.lifecycles", getLifecycleAdminPane());
|
|
||||||
tab(pane, "cms.ui.categories", getCategoryAdminPane());
|
tab(pane, "cms.ui.categories", getCategoryAdminPane());
|
||||||
|
|
||||||
return pane;
|
return pane;
|
||||||
|
|
@ -368,8 +346,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
// m_rolePane.reset(state);
|
// m_rolePane.reset(state);
|
||||||
} else if (pane == m_workflowPane) {
|
} else if (pane == m_workflowPane) {
|
||||||
m_workflowPane.reset(state);
|
m_workflowPane.reset(state);
|
||||||
} else if (pane == m_lifecyclePane) {
|
|
||||||
m_lifecyclePane.reset(state);
|
|
||||||
} else if (pane == m_categoryPane) {
|
} else if (pane == m_categoryPane) {
|
||||||
m_categoryPane.reset(state);
|
m_categoryPane.reset(state);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,362 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ColumnPanel;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
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.event.FormValidationListener;
|
|
||||||
import com.arsdigita.bebop.form.FormErrorDisplay;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.IntegerParameter;
|
|
||||||
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.NumberInRangeValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.StringLengthValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
import org.librecms.lifecycle.PhaseDefinition;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.CMSForm;
|
|
||||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains a form component to add a lifecycle phase definition.
|
|
||||||
*
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author Xixi D'Moon
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class AddPhaseForm extends CMSForm {
|
|
||||||
|
|
||||||
private final static String LABEL = "label";
|
|
||||||
private final static String DESCRIPTION = "description";
|
|
||||||
private final static String DELAY_DAYS = "delay_days";
|
|
||||||
private final static String DELAY_HOURS = "delay_hours";
|
|
||||||
private final static String DELAY_MINUTES = "delay_minutes";
|
|
||||||
private final static String DURATION_DAYS = "duration_days";
|
|
||||||
private final static String DURATION_HOURS = "duration_hours";
|
|
||||||
private final static String DURATION_MINUTES = "duration_minutes";
|
|
||||||
private final static String SUBMIT = "submit";
|
|
||||||
private final static String CANCEL = "cancel";
|
|
||||||
|
|
||||||
private final LifecycleDefinitionRequestLocal selectedLifecycle;
|
|
||||||
|
|
||||||
private final TextField phaseLabel;
|
|
||||||
private final TextArea phaseDescription;
|
|
||||||
private final TextField delayDays;
|
|
||||||
private final TextField delayHours;
|
|
||||||
private final TextField delayMinutes;
|
|
||||||
private final TextField durationDays;
|
|
||||||
private final TextField durationHours;
|
|
||||||
private final TextField durationMinutes;
|
|
||||||
private final Submit submit;
|
|
||||||
private final Submit cancel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param cycles The cycle selection model. This is to tell the form which
|
|
||||||
* cycle definition is selected since phase definitions are
|
|
||||||
* associated to cycle definitions
|
|
||||||
*/
|
|
||||||
public AddPhaseForm(final LifecycleDefinitionRequestLocal selectedLifecycle) {
|
|
||||||
super("LifecyclePhaseDefinition");
|
|
||||||
|
|
||||||
this.selectedLifecycle = selectedLifecycle;
|
|
||||||
|
|
||||||
final Label heading = new Label(gz("cms.ui.lifecycle.phase_add"));
|
|
||||||
heading.setFontWeight(Label.BOLD);
|
|
||||||
add(heading, ColumnPanel.FULL_WIDTH);
|
|
||||||
add(new FormErrorDisplay(this), ColumnPanel.FULL_WIDTH);
|
|
||||||
|
|
||||||
add(new Label(gz("cms.ui.lifecycle.phase.name")));
|
|
||||||
phaseLabel = new TextField(new TrimmedStringParameter(LABEL));
|
|
||||||
phaseLabel.addValidationListener(new NotEmptyValidationListener());
|
|
||||||
phaseLabel.setSize(40);
|
|
||||||
phaseLabel.setMaxLength(1000);
|
|
||||||
add(phaseLabel);
|
|
||||||
|
|
||||||
add(new Label(gz("cms.ui.lifecycle.phase.description")));
|
|
||||||
phaseDescription = new TextArea(new TrimmedStringParameter(DESCRIPTION));
|
|
||||||
phaseDescription.addValidationListener(
|
|
||||||
new StringLengthValidationListener(
|
|
||||||
4000));
|
|
||||||
phaseDescription.setCols(40);
|
|
||||||
phaseDescription.setRows(5);
|
|
||||||
phaseDescription.setWrap(TextArea.SOFT);
|
|
||||||
add(phaseDescription);
|
|
||||||
|
|
||||||
// phase delay
|
|
||||||
add(new Label(gz("cms.ui.lifecycle.phase_start_delay")));
|
|
||||||
delayDays = new TextField(new IntegerParameter(DELAY_DAYS));
|
|
||||||
delayHours = new TextField(new IntegerParameter(DELAY_HOURS));
|
|
||||||
delayMinutes = new TextField(new IntegerParameter(DELAY_MINUTES));
|
|
||||||
|
|
||||||
//max value: days: 60 years, hours: 7 days, minutes: 1 day
|
|
||||||
delayDays.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 21900));
|
|
||||||
delayHours.addValidationListener(new NumberInRangeValidationListener(
|
|
||||||
0, 168));
|
|
||||||
delayMinutes.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 1440));
|
|
||||||
delayDays.setSize(7);
|
|
||||||
delayHours.setSize(7);
|
|
||||||
delayMinutes.setSize(7);
|
|
||||||
delayDays.setClassAttr("DaysField");
|
|
||||||
delayHours.setClassAttr("HoursField");
|
|
||||||
delayMinutes.setClassAttr("MinutesField");
|
|
||||||
|
|
||||||
final SimpleContainer delayContainer = new SimpleContainer();
|
|
||||||
delayContainer.add(new Label(gz("cms.ui.lifecycle.phase_days")));
|
|
||||||
delayContainer.add(delayDays);
|
|
||||||
delayContainer.add(new Label(gz("cms.ui.lifecycle.phase_hours")));
|
|
||||||
delayContainer.add(delayHours);
|
|
||||||
delayContainer.add(new Label(gz("cms.ui.lifecycle.phase_minutes")));
|
|
||||||
delayContainer.add(delayMinutes);
|
|
||||||
add(delayContainer);
|
|
||||||
|
|
||||||
// phase duration
|
|
||||||
add(new Label(gz("cms.ui.lifecycle.phase_duration")));
|
|
||||||
durationDays = new TextField(new IntegerParameter(DURATION_DAYS));
|
|
||||||
durationHours = new TextField(new IntegerParameter(DURATION_HOURS));
|
|
||||||
durationMinutes = new TextField(
|
|
||||||
new IntegerParameter(DURATION_MINUTES));
|
|
||||||
|
|
||||||
//max value: days: 60 years, hours: 7 days, minutes: 1 day
|
|
||||||
durationDays.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 21900));
|
|
||||||
durationHours.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 168));
|
|
||||||
durationMinutes.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 1440));
|
|
||||||
durationDays.setSize(7);
|
|
||||||
durationHours.setSize(7);
|
|
||||||
durationMinutes.setSize(7);
|
|
||||||
durationDays.setClassAttr("DaysField");
|
|
||||||
durationHours.setClassAttr("HoursField");
|
|
||||||
durationMinutes.setClassAttr("MinutesField");
|
|
||||||
|
|
||||||
final SimpleContainer durationContainer = new SimpleContainer();
|
|
||||||
durationContainer.add(new Label(gz("cms.ui.lifecycle.phase_days")));
|
|
||||||
durationContainer.add(durationDays);
|
|
||||||
durationContainer.add(new Label(gz("cms.ui.lifecycle.phase_hours")));
|
|
||||||
durationContainer.add(durationHours);
|
|
||||||
durationContainer.add(new Label(gz("cms.ui.lifecycle.phase_minutes")));
|
|
||||||
durationContainer.add(durationMinutes);
|
|
||||||
add(durationContainer);
|
|
||||||
|
|
||||||
final SimpleContainer submitCancel = new SimpleContainer();
|
|
||||||
submit = new Submit(SUBMIT, gz("cms.ui.lifecycle.phase.add_submit"));
|
|
||||||
submitCancel.add(submit);
|
|
||||||
cancel = new Submit(CANCEL, gz("cms.ui.lifecycle.phase.add_cancel"));
|
|
||||||
submitCancel.add(cancel);
|
|
||||||
add(submitCancel, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
|
|
||||||
|
|
||||||
addSubmissionListener(new FormSecurityListener(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES));
|
|
||||||
|
|
||||||
addValidationListener(new FormValidationListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void validate(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
validateDuration(state);
|
|
||||||
validateUniqueName(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(new FormProcessListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
addPhase(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this form was cancelled.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @return True if the form was cancelled, false otherwise
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled(final PageState state) {
|
|
||||||
return cancel.isSelected(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new phase using data from the form.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
protected void addPhase(final PageState state) throws FormProcessException {
|
|
||||||
final String label = (String) phaseLabel.getValue(state);
|
|
||||||
final String description = (String) phaseDescription.getValue(state);
|
|
||||||
final int delDays = (int) Optional
|
|
||||||
.ofNullable(delayDays.getValue(state))
|
|
||||||
.orElseGet(() -> 0);
|
|
||||||
final int delHours = (int) Optional
|
|
||||||
.ofNullable(delayHours.getValue(state))
|
|
||||||
.orElseGet(() -> 0);
|
|
||||||
final int delMinutes = (int) Optional
|
|
||||||
.ofNullable(delayMinutes.getValue(state))
|
|
||||||
.orElseGet(() -> 0);
|
|
||||||
final int durDays = (int) Optional
|
|
||||||
.ofNullable(durationDays.getValue(state))
|
|
||||||
.orElseGet(() -> 0);
|
|
||||||
final int durHours = (int) Optional
|
|
||||||
.ofNullable(durationHours.getValue(state))
|
|
||||||
.orElseGet(() -> 0);
|
|
||||||
final int durMinutes = (int) Optional
|
|
||||||
.ofNullable(durationMinutes.getValue(state))
|
|
||||||
.orElseGet(() -> 0);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
controller.addPhaseDefinition(
|
|
||||||
selectedLifecycle.getLifecycleDefinition(state),
|
|
||||||
label,
|
|
||||||
description,
|
|
||||||
delDays,
|
|
||||||
delHours,
|
|
||||||
delMinutes,
|
|
||||||
durDays,
|
|
||||||
durHours,
|
|
||||||
durMinutes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate name uniqueness.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
protected void validateUniqueName(final PageState state)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final String label = (String) phaseLabel.getValue(state);
|
|
||||||
|
|
||||||
final LifecycleDefinition cycleDef = selectedLifecycle
|
|
||||||
.getLifecycleDefinition(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
final List<PhaseDefinition> phaseDefs = controller
|
|
||||||
.getPhaseDefinitions(cycleDef);
|
|
||||||
|
|
||||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
|
||||||
ConfigurationManager.class);
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final boolean duplicateLabel = phaseDefs
|
|
||||||
.stream()
|
|
||||||
.map(phaseDef -> phaseDef.getLabel().getValue(defaultLocale))
|
|
||||||
.anyMatch(phaseDefLabel -> phaseDefLabel.equalsIgnoreCase(label));
|
|
||||||
|
|
||||||
if (duplicateLabel) {
|
|
||||||
throw new FormProcessException(new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.phase_name_not_unique",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the phase duration. The duration cannot be 0.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
protected void validateDuration(final PageState state)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final Integer durDays = (Integer) durationDays.getValue(state);
|
|
||||||
final Integer durHours = (Integer) durationHours.getValue(state);
|
|
||||||
final Integer durMinutes = (Integer) durationMinutes.getValue(state);
|
|
||||||
|
|
||||||
// Phase duration is infinite, so the duration is valid.
|
|
||||||
if (durDays == null && durHours == null && durMinutes == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int days, hours, minutes;
|
|
||||||
if (durDays != null) {
|
|
||||||
days = durDays;
|
|
||||||
} else {
|
|
||||||
days = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durHours != null) {
|
|
||||||
hours = durHours;
|
|
||||||
} else {
|
|
||||||
hours = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durMinutes != null) {
|
|
||||||
minutes = durMinutes;
|
|
||||||
} else {
|
|
||||||
minutes = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((days + hours + minutes) == 0) {
|
|
||||||
throw new FormProcessException(new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.phase_duration_negative",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GlobalizedMessage gz(final String key) {
|
|
||||||
return new GlobalizedMessage(key,
|
|
||||||
CmsConstants.CMS_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,77 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.StringLengthValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.BaseForm;
|
|
||||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class BaseLifecycleForm extends BaseForm {
|
|
||||||
|
|
||||||
private final TextField lifecycleName;
|
|
||||||
private final TextArea lifecycleDescription;
|
|
||||||
|
|
||||||
BaseLifecycleForm(final String key, final GlobalizedMessage message) {
|
|
||||||
super(key, message);
|
|
||||||
|
|
||||||
lifecycleName = new TextField(new TrimmedStringParameter("label"));
|
|
||||||
addField(gz("cms.ui.lifecycle.name"), lifecycleName);
|
|
||||||
|
|
||||||
lifecycleName.addValidationListener(new NotEmptyValidationListener());
|
|
||||||
lifecycleName.setSize(40);
|
|
||||||
lifecycleName.setMaxLength(1000);
|
|
||||||
|
|
||||||
lifecycleDescription = new TextArea(
|
|
||||||
new TrimmedStringParameter("description"));
|
|
||||||
addField(gz("cms.ui.lifecycle.description"), lifecycleDescription);
|
|
||||||
|
|
||||||
lifecycleDescription.addValidationListener(
|
|
||||||
new StringLengthValidationListener(4000));
|
|
||||||
lifecycleDescription.setCols(40);
|
|
||||||
lifecycleDescription.setRows(5);
|
|
||||||
lifecycleDescription.setWrap(TextArea.SOFT);
|
|
||||||
|
|
||||||
addAction(new Finish());
|
|
||||||
addAction(new Cancel());
|
|
||||||
|
|
||||||
addSubmissionListener(new FormSecurityListener(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TextField getLifecycleName() {
|
|
||||||
return lifecycleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TextArea getLifecycleDescription() {
|
|
||||||
return lifecycleDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,154 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.ColumnPanel;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
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.form.Hidden;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.parameters.LongParameter;
|
|
||||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.PhaseDefinition;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.CMSForm;
|
|
||||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
import org.librecms.lifecycle.PhaseDefinititionRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class handles the deleting of a phase definition.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:flattop@arsdigita.com">Jack Chung</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DeletePhaseForm extends CMSForm
|
|
||||||
implements FormProcessListener, FormInitListener {
|
|
||||||
|
|
||||||
private final PhaseRequestLocal selectedPhaseDef;
|
|
||||||
|
|
||||||
private final Hidden selectedPhaseDefId;
|
|
||||||
private final Submit deleteWidget;
|
|
||||||
private final Submit cancelWidget;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param m The phase selection model. This tells the form which phase
|
|
||||||
* definition is selected.
|
|
||||||
*/
|
|
||||||
public DeletePhaseForm(final PhaseRequestLocal selectedPhaseDef) {
|
|
||||||
super("PhaseDefinitionDelete");
|
|
||||||
|
|
||||||
this.selectedPhaseDef = selectedPhaseDef;
|
|
||||||
|
|
||||||
selectedPhaseDefId = new Hidden(new LongParameter("id"));
|
|
||||||
add(selectedPhaseDefId);
|
|
||||||
selectedPhaseDefId
|
|
||||||
.addValidationListener(new NotNullValidationListener());
|
|
||||||
|
|
||||||
final BoxPanel buttons = new BoxPanel(BoxPanel.HORIZONTAL);
|
|
||||||
deleteWidget = new Submit("delete",
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.phase.delete_submit",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
deleteWidget.setClassAttr("deletePhase");
|
|
||||||
buttons.add(deleteWidget);
|
|
||||||
|
|
||||||
cancelWidget = new Submit("cancel",
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.phase.delete_cancel",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
cancelWidget.setClassAttr("canceldeletePhase");
|
|
||||||
buttons.add(cancelWidget);
|
|
||||||
|
|
||||||
add(buttons, ColumnPanel.CENTER | ColumnPanel.FULL_WIDTH);
|
|
||||||
|
|
||||||
addInitListener(this);
|
|
||||||
|
|
||||||
addSubmissionListener(new FormSecurityListener(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES));
|
|
||||||
|
|
||||||
addProcessListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this form was cancelled.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @return true if the form was cancelled, false otherwise
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled(final PageState state) {
|
|
||||||
return cancelWidget.isSelected(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form process listener. Deletes a phase definition
|
|
||||||
*
|
|
||||||
* @param event The form process event
|
|
||||||
*
|
|
||||||
* @exception FormProcessException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final FormData data = event.getFormData();
|
|
||||||
final Long key = (Long) data.get(selectedPhaseDefId.getName());
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PhaseDefinititionRepository phaseDefRepo = cdiUtil.findBean(
|
|
||||||
PhaseDefinititionRepository.class);
|
|
||||||
|
|
||||||
// Check if the object is already deleted for double click
|
|
||||||
// protection.
|
|
||||||
final PhaseDefinition phaseDef = phaseDefRepo.findById(key).get();
|
|
||||||
if (phaseDef != null) {
|
|
||||||
phaseDefRepo.delete(phaseDef);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Init listener. gets the id of the selected phase definition
|
|
||||||
*
|
|
||||||
* @param event The form init event
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public final void init(final FormSectionEvent event) {
|
|
||||||
final FormData data = event.getFormData();
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final Long phaseDefId = selectedPhaseDef.getPhase(state)
|
|
||||||
.getDefinitionId();
|
|
||||||
|
|
||||||
data.put(selectedPhaseDefId.getName(), phaseDefId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,435 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ColumnPanel;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
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.FormValidationListener;
|
|
||||||
import com.arsdigita.bebop.form.FormErrorDisplay;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.IntegerParameter;
|
|
||||||
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.NumberInRangeValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.StringLengthValidationListener;
|
|
||||||
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
|
||||||
import com.arsdigita.cms.lifecycle.Duration;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.PhaseDefinition;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.CMSForm;
|
|
||||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains a form component to edit a lifecycle phase definition.
|
|
||||||
*
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author Xixi D'Moon
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class EditPhaseForm extends CMSForm {
|
|
||||||
|
|
||||||
private final static String LABEL = "label";
|
|
||||||
private final static String DESCRIPTION = "description";
|
|
||||||
private final static String DELAY_DAYS = "delay_days";
|
|
||||||
private final static String DELAY_HOURS = "delay_hours";
|
|
||||||
private final static String DELAY_MINUTES = "delay_minutes";
|
|
||||||
private final static String DURATION_DAYS = "duration_days";
|
|
||||||
private final static String DURATION_HOURS = "duration_hours";
|
|
||||||
private final static String DURATION_MINUTES = "duration_minutes";
|
|
||||||
private final static String SUBMIT = "submit";
|
|
||||||
private final static String CANCEL = "cancel";
|
|
||||||
|
|
||||||
private final LifecycleDefinitionRequestLocal selectedLifecycle;
|
|
||||||
private final PhaseRequestLocal selectedPhase;
|
|
||||||
|
|
||||||
private final TextField phaseLabel;
|
|
||||||
private final TextArea phaseDescription;
|
|
||||||
private final TextField delayDays;
|
|
||||||
private final TextField delayHours;
|
|
||||||
private final TextField delayMinutes;
|
|
||||||
private final TextField durationDays;
|
|
||||||
private final TextField durationHours;
|
|
||||||
private final TextField durationMinutes;
|
|
||||||
private final Submit submit;
|
|
||||||
private final Submit cancel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param m A single selection model for phase definitions. This is to tell
|
|
||||||
* the form which phase definition is selected for editing.
|
|
||||||
*
|
|
||||||
* @pre phases != null
|
|
||||||
*/
|
|
||||||
public EditPhaseForm(
|
|
||||||
final LifecycleDefinitionRequestLocal selectedLifecycle,
|
|
||||||
final PhaseRequestLocal selectedPhase) {
|
|
||||||
|
|
||||||
super("EditPhaseDefinition");
|
|
||||||
|
|
||||||
this.selectedLifecycle = selectedLifecycle;
|
|
||||||
this.selectedPhase = selectedPhase;
|
|
||||||
|
|
||||||
add(new Label());
|
|
||||||
add(new FormErrorDisplay(this));
|
|
||||||
|
|
||||||
add(new Label(gz("cms.ui.lifecycle.phase.name")));
|
|
||||||
phaseLabel = new TextField(new TrimmedStringParameter(LABEL));
|
|
||||||
phaseLabel.addValidationListener(new NotEmptyValidationListener());
|
|
||||||
phaseLabel.setSize(40);
|
|
||||||
phaseLabel.setMaxLength(1000);
|
|
||||||
add(phaseLabel);
|
|
||||||
|
|
||||||
add(new Label(gz("cms.ui.lifecycle.phase.description")));
|
|
||||||
phaseDescription = new TextArea(new TrimmedStringParameter(DESCRIPTION));
|
|
||||||
phaseDescription.addValidationListener(
|
|
||||||
new StringLengthValidationListener(
|
|
||||||
4000));
|
|
||||||
phaseDescription.setCols(40);
|
|
||||||
phaseDescription.setRows(5);
|
|
||||||
phaseDescription.setWrap(TextArea.SOFT);
|
|
||||||
add(phaseDescription);
|
|
||||||
|
|
||||||
// Phase duration
|
|
||||||
// Max value: days: 60 years, hours: 7 days, minutes: 1 day
|
|
||||||
delayDays = new TextField(new IntegerParameter(DELAY_DAYS));
|
|
||||||
delayDays.addValidationListener(new NumberInRangeValidationListener(0,
|
|
||||||
21900));
|
|
||||||
delayDays.setSize(7);
|
|
||||||
delayDays.setClassAttr("DaysField");
|
|
||||||
|
|
||||||
delayHours = new TextField(new IntegerParameter(DELAY_HOURS));
|
|
||||||
delayHours.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 168));
|
|
||||||
delayHours.setClassAttr("HoursField");
|
|
||||||
delayHours.setSize(7);
|
|
||||||
|
|
||||||
delayMinutes = new TextField(new IntegerParameter(DELAY_MINUTES));
|
|
||||||
delayMinutes.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 1440));
|
|
||||||
delayMinutes.setSize(7);
|
|
||||||
delayMinutes.setClassAttr("MinutesField");
|
|
||||||
|
|
||||||
add(new Label(
|
|
||||||
new GlobalizedMessage("cms.ui.lifecycle.phase_start_delay",
|
|
||||||
CmsConstants.CMS_BUNDLE)));
|
|
||||||
final SimpleContainer delayContainer = new SimpleContainer();
|
|
||||||
delayContainer.add(new Label(gz("cms.ui.lifecycle.phase_days")));
|
|
||||||
delayContainer.add(delayDays);
|
|
||||||
delayContainer.add(new Label(gz("cms.ui.lifecycle.phase_hours")));
|
|
||||||
delayContainer.add(delayHours);
|
|
||||||
delayContainer.add(new Label(gz("cms.ui.lifecycle.phase_minutes")));
|
|
||||||
delayContainer.add(delayMinutes);
|
|
||||||
add(delayContainer);
|
|
||||||
|
|
||||||
// Phase duration
|
|
||||||
// Max value: days: 60 years, hours: 7 days, minutes: 1 day
|
|
||||||
durationDays = new TextField(new IntegerParameter(DURATION_DAYS));
|
|
||||||
durationDays.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0,
|
|
||||||
21900));
|
|
||||||
durationDays.setSize(7);
|
|
||||||
durationDays.setClassAttr("DaysField");
|
|
||||||
|
|
||||||
durationHours = new TextField(new IntegerParameter(DURATION_HOURS));
|
|
||||||
durationHours.addValidationListener(new NumberInRangeValidationListener(
|
|
||||||
0,
|
|
||||||
168));
|
|
||||||
durationHours.setSize(7);
|
|
||||||
durationHours.setClassAttr("HoursField");
|
|
||||||
|
|
||||||
durationMinutes = new TextField(new IntegerParameter(DURATION_MINUTES));
|
|
||||||
durationMinutes.addValidationListener(
|
|
||||||
new NumberInRangeValidationListener(0, 1440));
|
|
||||||
durationMinutes.setSize(7);
|
|
||||||
durationMinutes.setClassAttr("MinutesField");
|
|
||||||
|
|
||||||
add(new Label(gz("cms.ui.lifecycle.phase_duration")));
|
|
||||||
final SimpleContainer durationContainer = new SimpleContainer();
|
|
||||||
durationContainer.add(new Label(gz("cms.ui.lifecycle.phase_days")));
|
|
||||||
durationContainer.add(durationDays);
|
|
||||||
durationContainer.add(new Label(gz("cms.ui.lifecycle.phase_hours")));
|
|
||||||
durationContainer.add(durationHours);
|
|
||||||
durationContainer.add(new Label(gz("cms.ui.lifecycle.phase_minutes")));
|
|
||||||
durationContainer.add(durationMinutes);
|
|
||||||
add(durationContainer);
|
|
||||||
|
|
||||||
// Submit and cancel buttons
|
|
||||||
final SimpleContainer submitCancelContainer = new SimpleContainer();
|
|
||||||
submit = new Submit(SUBMIT, gz("cms.ui.lifecycle.phase.edit_submit"));
|
|
||||||
submitCancelContainer.add(submit);
|
|
||||||
cancel = new Submit(CANCEL, gz("cms.ui.lifecycle.phase.edit_cancel"));
|
|
||||||
submitCancelContainer.add(cancel);
|
|
||||||
add(submitCancelContainer, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
|
|
||||||
|
|
||||||
// Add form listeners.
|
|
||||||
addInitListener(new FormInitListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void init(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
initializePhaseDefinition(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addSubmissionListener(new FormSecurityListener(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES));
|
|
||||||
|
|
||||||
addValidationListener(new FormValidationListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void validate(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
validateDuration(state);
|
|
||||||
validateUniqueName(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(new FormProcessListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
updatePhaseDefinition(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this form was cancelled.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @return True if the form was cancelled, false otherwise
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled(final PageState state) {
|
|
||||||
return cancel.isSelected(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the form fields with the current phase definition attribute
|
|
||||||
* values.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
private void initializePhaseDefinition(final PageState state)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final Locale defaultLocale = KernelConfig.getConfig().getDefaultLocale();
|
|
||||||
|
|
||||||
final PhaseDefinition phaseDef = selectedPhase.getPhase(state);
|
|
||||||
phaseLabel.setValue(state, phaseDef.getLabel().getValue(defaultLocale));
|
|
||||||
phaseDescription.setValue(state,
|
|
||||||
phaseDef
|
|
||||||
.getDescription()
|
|
||||||
.getValue(defaultLocale));
|
|
||||||
|
|
||||||
final long[] delay = Duration.formatDHM(phaseDef.getDefaultDelay());
|
|
||||||
delayDays.setValue(state, delay[0]);
|
|
||||||
delayHours.setValue(state, delay[1]);
|
|
||||||
delayMinutes.setValue(state, delay[2]);
|
|
||||||
|
|
||||||
final Long duration = phaseDef.getDefaultDuration();
|
|
||||||
if (duration != 0) {
|
|
||||||
final Long[] dhm = Duration.formatDHM(duration);
|
|
||||||
durationDays.setValue(state, dhm[0]);
|
|
||||||
durationHours.setValue(state, dhm[1]);
|
|
||||||
durationMinutes.setValue(state, dhm[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the phase definition with values from the form.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
private void updatePhaseDefinition(final PageState state)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final String label = (String) phaseLabel.getValue(state);
|
|
||||||
final String description = (String) phaseDescription.getValue(state);
|
|
||||||
final int delDays = (int) Optional
|
|
||||||
.ofNullable(delayDays.getValue(state))
|
|
||||||
.orElseGet(() -> 0);
|
|
||||||
final int delHours = (int) Optional
|
|
||||||
.ofNullable(delayHours.getValue(state))
|
|
||||||
.orElseGet(() -> 0);;
|
|
||||||
final int delMinutes = (int) Optional
|
|
||||||
.ofNullable(delayMinutes.getValue(state))
|
|
||||||
.orElseGet(() -> 0);;
|
|
||||||
final int durDays = (int) Optional
|
|
||||||
.ofNullable(durationDays.getValue(state))
|
|
||||||
.orElseGet(() -> 0);;
|
|
||||||
final int durHours = (int) Optional
|
|
||||||
.ofNullable(durationHours.getValue(state))
|
|
||||||
.orElseGet(() -> 0);;
|
|
||||||
final int durMinutes = (int) Optional
|
|
||||||
.ofNullable(durationMinutes.getValue(state))
|
|
||||||
.orElseGet(() -> 0);;
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
|
|
||||||
controller.updatePhaseDefinition(selectedPhase.getPhase(state),
|
|
||||||
label,
|
|
||||||
description,
|
|
||||||
delDays,
|
|
||||||
delHours,
|
|
||||||
delMinutes,
|
|
||||||
durDays,
|
|
||||||
durHours,
|
|
||||||
durMinutes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensures that the new name (if it has changed) is unique within the
|
|
||||||
* lifecycle definition.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @pre state != null
|
|
||||||
*/
|
|
||||||
private void validateUniqueName(final PageState state)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
|
||||||
ConfigurationManager.class);
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final String oldLabel = selectedPhase
|
|
||||||
.getPhase(state)
|
|
||||||
.getLabel()
|
|
||||||
.getValue(defaultLocale);
|
|
||||||
final String newLabel = (String) phaseLabel.getValue(state);
|
|
||||||
|
|
||||||
if (oldLabel.equals(newLabel)) {
|
|
||||||
//Label has node changed, no validation required.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final LifecycleDefinition cycleDef = selectedLifecycle
|
|
||||||
.getLifecycleDefinition(state);
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
final List<PhaseDefinition> phaseDefs = controller
|
|
||||||
.getPhaseDefinitions(cycleDef);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final boolean duplicateLabel = phaseDefs
|
|
||||||
.stream()
|
|
||||||
.map(phaseDef -> phaseDef.getLabel().getValue(defaultLocale))
|
|
||||||
.anyMatch(phaseDefLabel -> {
|
|
||||||
return phaseDefLabel.equalsIgnoreCase(newLabel);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (duplicateLabel) {
|
|
||||||
throw new FormProcessException(new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.phase_name_not_unique",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the phase duration. The duration cannot be 0.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void validateDuration(final PageState state)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final Integer durDays = (Integer) durationDays.getValue(state);
|
|
||||||
final Integer durHours = (Integer) durationHours.getValue(state);
|
|
||||||
final Integer durMinutes = (Integer) durationMinutes.getValue(state);
|
|
||||||
|
|
||||||
// Phase duration is infinite, so the duration is valid.
|
|
||||||
if (durDays == null && durHours == null && durMinutes == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int days, hours, minutes;
|
|
||||||
if (durDays == null) {
|
|
||||||
days = 0;
|
|
||||||
} else {
|
|
||||||
days = durDays;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durHours == null) {
|
|
||||||
hours = 0;
|
|
||||||
} else {
|
|
||||||
hours = durHours;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durMinutes == null) {
|
|
||||||
minutes = 0;
|
|
||||||
} else {
|
|
||||||
minutes = durMinutes;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((days + hours + minutes) == 0) {
|
|
||||||
throw new FormProcessException(new GlobalizedMessage(
|
|
||||||
"cms.ui.phase.duration_negative",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GlobalizedMessage gz(final String key) {
|
|
||||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,350 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.librecms.CMSConfig;
|
|
||||||
import org.libreccm.categorization.Categorization;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.TaskManager;
|
|
||||||
import org.libreccm.workflow.TaskState;
|
|
||||||
import org.libreccm.workflow.Workflow;
|
|
||||||
import org.libreccm.workflow.WorkflowManager;
|
|
||||||
import org.libreccm.workflow.WorkflowRepository;
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contentsection.ContentItemManager;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
import org.librecms.contentsection.ContentSectionRepository;
|
|
||||||
import org.librecms.lifecycle.Lifecycle;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinitionRepository;
|
|
||||||
import org.librecms.lifecycle.LifecycleManager;
|
|
||||||
import org.librecms.lifecycle.LifecycleRepository;
|
|
||||||
import org.librecms.lifecycle.Phase;
|
|
||||||
import org.librecms.lifecycle.PhaseDefinition;
|
|
||||||
import org.librecms.lifecycle.PhaseRepository;
|
|
||||||
import org.librecms.workflow.CmsTask;
|
|
||||||
import org.librecms.workflow.CmsTaskType;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
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
|
|
||||||
class ItemLifecycleAdminController implements Serializable {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager
|
|
||||||
.getLogger(ItemLifecycleAdminController.class);
|
|
||||||
private static final long serialVersionUID = -6482423583933975632L;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ConfigurationManager confManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private GlobalizationHelper globalizationHelper;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentItemRepository itemRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentItemManager itemManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LifecycleDefinitionRepository lifecycleDefRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LifecycleManager lifecycleManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LifecycleRepository lifecycleRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private PhaseRepository phaseRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentSectionRepository sectionRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TaskManager taskManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private WorkflowManager workflowManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private WorkflowRepository workflowRepo;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public boolean isAssignedToAbstractCategory(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())));
|
|
||||||
|
|
||||||
final long count = contentItem
|
|
||||||
.getCategories()
|
|
||||||
.stream()
|
|
||||||
.map(Categorization::getCategory)
|
|
||||||
.filter(Category::isAbstractCategory)
|
|
||||||
.count();
|
|
||||||
|
|
||||||
return count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<LifecycleDefinition> getLifecycleDefinitions(
|
|
||||||
final ContentSection section) {
|
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
|
||||||
.findById(section.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No ContentSection with ID %d in the database.",
|
|
||||||
section.getObjectId())));
|
|
||||||
|
|
||||||
return contentSection
|
|
||||||
.getLifecycleDefinitions()
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public Optional<LifecycleDefinition> getDefaultLifecycle(
|
|
||||||
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())));
|
|
||||||
|
|
||||||
final LifecycleDefinition definition = contentItem
|
|
||||||
.getContentType()
|
|
||||||
.getDefaultLifecycle();
|
|
||||||
|
|
||||||
if (definition == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
} else {
|
|
||||||
return Optional
|
|
||||||
.of(lifecycleDefRepo
|
|
||||||
.findById(definition.getDefinitionId())
|
|
||||||
.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public LifecycleDefinition getDefinitionOfLifecycle(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())));
|
|
||||||
final ContentItem liveItem = itemManager
|
|
||||||
.getLiveVersion(item, ContentItem.class)
|
|
||||||
.get();
|
|
||||||
|
|
||||||
return liveItem.getLifecycle().getDefinition();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<ItemPhaseTableRow> findPhasesOfLifecycle(
|
|
||||||
final Lifecycle lifecycle) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(lifecycle);
|
|
||||||
|
|
||||||
final Lifecycle ofLifecycle = lifecycleRepo
|
|
||||||
.findById(lifecycle.getLifecycleId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Lifecycle with ID %d in the database.",
|
|
||||||
lifecycle.getLifecycleId())));
|
|
||||||
|
|
||||||
return ofLifecycle
|
|
||||||
.getPhases()
|
|
||||||
.stream()
|
|
||||||
.map(this::buildItemPhaseTableRow)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemPhaseTableRow buildItemPhaseTableRow(final Phase phase) {
|
|
||||||
|
|
||||||
final PhaseDefinition definition = phase.getDefinition();
|
|
||||||
|
|
||||||
final ItemPhaseTableRow row = new ItemPhaseTableRow();
|
|
||||||
row.setName(globalizationHelper
|
|
||||||
.getValueFromLocalizedString(definition.getLabel()));
|
|
||||||
row.setDescription(globalizationHelper
|
|
||||||
.getValueFromLocalizedString(definition.getDescription()));
|
|
||||||
row.setStartDate(phase.getStartDateTime());
|
|
||||||
row.setEndDate(phase.getEndDateTime());
|
|
||||||
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public String getPublishingTabUrl(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void repulish(final ContentItem item) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(item);
|
|
||||||
|
|
||||||
final Optional<ContentItem> liveItem = itemManager
|
|
||||||
.getLiveVersion(item, ContentItem.class);
|
|
||||||
if (liveItem.isPresent()) {
|
|
||||||
final ContentItem contentItem = itemRepo
|
|
||||||
.findById(item.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No ContentItem with Id %d in the database.",
|
|
||||||
item.getObjectId())));
|
|
||||||
itemManager.publish(contentItem);
|
|
||||||
final Workflow workflow = contentItem.getWorkflow();
|
|
||||||
if (workflow != null
|
|
||||||
&& workflow.isActive()
|
|
||||||
&& workflow.getTasksState() == TaskState.ENABLED) {
|
|
||||||
|
|
||||||
workflowManager.finish(contentItem.getWorkflow());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void publish(final String itemUuid,
|
|
||||||
final long cycleDefId,
|
|
||||||
final Date endDate,
|
|
||||||
final String workflowUuid,
|
|
||||||
final User user) {
|
|
||||||
|
|
||||||
final ContentItem contentItem = itemRepo
|
|
||||||
.findByUuid(itemUuid)
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No ContentItem with UUID %s in the database.",
|
|
||||||
itemUuid)));
|
|
||||||
|
|
||||||
final LifecycleDefinition cycleDef = lifecycleDefRepo
|
|
||||||
.findById(cycleDefId)
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No LifecycleDefinition with ID %d in the database.",
|
|
||||||
cycleDefId)));
|
|
||||||
|
|
||||||
if (itemManager.isLive(contentItem)) {
|
|
||||||
contentItem.setLifecycle(null);
|
|
||||||
itemRepo.save(contentItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
final ContentItem pending = itemManager.publish(contentItem, cycleDef);
|
|
||||||
final Lifecycle lifecycle = pending.getLifecycle();
|
|
||||||
|
|
||||||
if (endDate != null) {
|
|
||||||
|
|
||||||
// update individual phases
|
|
||||||
final List<Phase> phases = lifecycle.getPhases();
|
|
||||||
|
|
||||||
for (final Phase phase : phases) {
|
|
||||||
final Date thisStart = phase.getStartDateTime();
|
|
||||||
if (thisStart.compareTo(endDate) > 0) {
|
|
||||||
phase.setStartDateTime(endDate);
|
|
||||||
phaseRepo.save(phase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lifecycleManager.startLifecycle(lifecycle);
|
|
||||||
|
|
||||||
if (workflowUuid != null) {
|
|
||||||
final Workflow workflow = workflowRepo
|
|
||||||
.findByUuid(workflowUuid)
|
|
||||||
.get();
|
|
||||||
finish(workflow, contentItem, user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void finish(final Workflow workflow,
|
|
||||||
final ContentItem item,
|
|
||||||
final User user) {
|
|
||||||
|
|
||||||
if (workflow != null && user != null) {
|
|
||||||
|
|
||||||
final List<Task> enabledTasks = workflowManager
|
|
||||||
.findEnabledTasks(workflow);
|
|
||||||
for (final Task task : enabledTasks) {
|
|
||||||
LOGGER.debug("Task is {}.", task.getUuid());
|
|
||||||
if (task instanceof CmsTask) {
|
|
||||||
final CmsTask cmsTask = (CmsTask) task;
|
|
||||||
|
|
||||||
if (cmsTask.getTaskType() == CmsTaskType.DEPLOY) {
|
|
||||||
LOGGER.debug("Found DEPLOY task.");
|
|
||||||
taskManager.finish(cmsTask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final CMSConfig cmsConfig = confManager
|
|
||||||
.findConfiguration(CMSConfig.class);
|
|
||||||
|
|
||||||
if (cmsConfig.isDeleteWorkflowAfterPublication()) {
|
|
||||||
workflowRepo.delete(workflow);
|
|
||||||
} else {
|
|
||||||
// restart the workflow by recreating it
|
|
||||||
// from the same workflow template
|
|
||||||
final Workflow template = workflow.getTemplate();
|
|
||||||
if (template == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
workflowRepo.delete(workflow);
|
|
||||||
final Workflow restarted = workflowManager.createWorkflow(
|
|
||||||
template, item);
|
|
||||||
// Startring the workflow will probably do the wrong thing, because most of the time
|
|
||||||
// the current user would be a publisher, not an author
|
|
||||||
workflowRepo.save(restarted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,236 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
|
||||||
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import com.arsdigita.web.RedirectSignal;
|
|
||||||
import com.arsdigita.web.URL;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.librecms.contentsection.ContentItemManager;
|
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@goolemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ItemLifecycleAdminPane extends BaseItemPane {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
ItemLifecycleAdminPane.class);
|
|
||||||
private final ContentItemRequestLocal selectedItem;
|
|
||||||
private final LifecycleRequestLocal selectedLifecycle;
|
|
||||||
private final LayoutPanel introPane;
|
|
||||||
private final LayoutPanel detailPane;
|
|
||||||
private final LayoutPanel selectPane;
|
|
||||||
private final LayoutPanel lockedPane;
|
|
||||||
private final LayoutPanel errorPane;
|
|
||||||
private final LayoutPanel cantPublishPane;
|
|
||||||
|
|
||||||
public ItemLifecycleAdminPane(final ContentItemRequestLocal selectedItem) {
|
|
||||||
this.selectedItem = selectedItem;
|
|
||||||
selectedLifecycle = new ItemLifecycleRequestLocal();
|
|
||||||
|
|
||||||
introPane = new LayoutPanel();
|
|
||||||
add(introPane);
|
|
||||||
|
|
||||||
final Label message = new Label(gz("cms.ui.item.lifecycle.intro"));
|
|
||||||
introPane.setBody(message);
|
|
||||||
|
|
||||||
detailPane = new LayoutPanel();
|
|
||||||
add(detailPane);
|
|
||||||
|
|
||||||
final ItemLifecycleItemPane itemPane = new ItemLifecycleItemPane(
|
|
||||||
selectedItem, selectedLifecycle);
|
|
||||||
detailPane.setBody(itemPane);
|
|
||||||
|
|
||||||
selectPane = new LayoutPanel();
|
|
||||||
add(selectPane);
|
|
||||||
|
|
||||||
final ItemLifecycleSelectForm selectForm = new ItemLifecycleSelectForm(
|
|
||||||
selectedItem);
|
|
||||||
selectPane.setBody(selectForm);
|
|
||||||
|
|
||||||
lockedPane = new LayoutPanel();
|
|
||||||
add(lockedPane);
|
|
||||||
|
|
||||||
final Label lockedMsg = new Label(gz(
|
|
||||||
"cms.ui.item.lifecycle.publish_locked"));
|
|
||||||
lockedPane.setBody(lockedMsg);
|
|
||||||
final ControlLink lockedUpdateLink = new ControlLink(new Label(gz(
|
|
||||||
"cms.ui.item.lifecycle.publish_locked.update")));
|
|
||||||
lockedUpdateLink.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(final ActionEvent event) {
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.getDispatcherPath()
|
|
||||||
+ ContentItemPage.getItemURL(
|
|
||||||
selectedItem.getContentItem(event.getPageState()),
|
|
||||||
ContentItemPage.PUBLISHING_TAB),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
lockedPane.setBottom(lockedUpdateLink);
|
|
||||||
|
|
||||||
errorPane = new LayoutPanel();
|
|
||||||
add(errorPane);
|
|
||||||
|
|
||||||
final Label errorMsg = new Label(gz("cms.ui.lifecycle.publish.error"));
|
|
||||||
errorPane.setBody(errorMsg);
|
|
||||||
|
|
||||||
cantPublishPane = new LayoutPanel();
|
|
||||||
add(cantPublishPane);
|
|
||||||
|
|
||||||
final Label cantPublish = new Label(gz(
|
|
||||||
"cms.ui.lifecycle.publish.not_possible_abstract_category"));
|
|
||||||
cantPublishPane.setBody(cantPublish);
|
|
||||||
|
|
||||||
connect(selectForm, detailPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ItemLifecycleRequestLocal extends LifecycleRequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemManager itemManager = cdiUtil
|
|
||||||
.findBean(ContentItemManager.class);
|
|
||||||
final Optional<ContentItem> liveItem = itemManager
|
|
||||||
.getLiveVersion(item, ContentItem.class);
|
|
||||||
if (liveItem.isPresent()) {
|
|
||||||
|
|
||||||
final Lifecycle lifecycle = liveItem.get().getLifecycle();
|
|
||||||
LOGGER.debug("Returning lifecycle {}",
|
|
||||||
Objects.toString(lifecycle));
|
|
||||||
return lifecycle;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addActionListener(new VisibilityListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class VisibilityListener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
LOGGER.debug("Determining which pane to show");
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
// if (CMSConfig.getConfig().isThreadPublishing()
|
|
||||||
// && PublishLock.getInstance().isLocked(m_item.getContentItem(
|
|
||||||
// state))) {
|
|
||||||
// if (PublishLock.getInstance().hasError(m_item.getContentItem(
|
|
||||||
// state))) {
|
|
||||||
// push(state, m_errorPane);
|
|
||||||
// } else {
|
|
||||||
// push(state, m_lockedPane);
|
|
||||||
// state.getResponse().addIntHeader("Refresh", 5);
|
|
||||||
// }
|
|
||||||
// } else
|
|
||||||
if (isAssignedToAbstractCategory(selectedItem.getContentItem(state))) {
|
|
||||||
push(state, cantPublishPane);
|
|
||||||
} else {
|
|
||||||
if (state.isVisibleOnPage(ItemLifecycleAdminPane.this)) {
|
|
||||||
if (selectedLifecycle.getLifecycle(state) == null) {
|
|
||||||
if (hasPermission(state)) {
|
|
||||||
push(state, selectPane);
|
|
||||||
} else {
|
|
||||||
push(state, introPane);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
push(state, detailPane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasPermission(final PageState state) {
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
return permissionChecker.isPermitted(ItemPrivileges.PUBLISH, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the item is assigned to an abstract category.
|
|
||||||
*
|
|
||||||
* A category is abstract if not items can assigned to it.
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
*
|
|
||||||
* @return {@code true} if assigned to a abstract category, {@code false} if
|
|
||||||
* not.
|
|
||||||
*/
|
|
||||||
private boolean isAssignedToAbstractCategory(final ContentItem item) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ItemLifecycleAdminController controller = cdiUtil
|
|
||||||
.findBean(ItemLifecycleAdminController.class);
|
|
||||||
|
|
||||||
return controller.isAssignedToAbstractCategory(item);
|
|
||||||
|
|
||||||
// final long count = item.getCategories().stream()
|
|
||||||
// .filter(categorization -> {
|
|
||||||
// return categorization.getCategory().isAbstractCategory();
|
|
||||||
// })
|
|
||||||
// .count();
|
|
||||||
//
|
|
||||||
// return count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,956 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
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.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.SingleSelect;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
|
||||||
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.mail.Mail;
|
|
||||||
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.UncheckedWrapperException;
|
|
||||||
import com.arsdigita.web.RedirectSignal;
|
|
||||||
import com.arsdigita.web.URL;
|
|
||||||
import com.arsdigita.xml.Element;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.librecms.CMSConfig;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.libreccm.security.Shiro;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contentsection.ContentItemManager;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
|
||||||
import org.librecms.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains the component which displays the information for a
|
|
||||||
* particular lifecycle, with the ability to edit and delete. This information
|
|
||||||
* also includes the associated phases for this lifecycle, also with the ability
|
|
||||||
* to add, edit, and delete.
|
|
||||||
*
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author Xixi D'Moon
|
|
||||||
* @author Justin Ross
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class ItemLifecycleItemPane extends BaseItemPane {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
ItemLifecycleItemPane.class);
|
|
||||||
private final ContentItemRequestLocal selectedItem;
|
|
||||||
private final LifecycleRequestLocal selectedLifecycle;
|
|
||||||
private final SimpleContainer detailPane;
|
|
||||||
|
|
||||||
public ItemLifecycleItemPane(final ContentItemRequestLocal selectedItem,
|
|
||||||
final LifecycleRequestLocal selectedLifecycle) {
|
|
||||||
this.selectedItem = selectedItem;
|
|
||||||
this.selectedLifecycle = selectedLifecycle;
|
|
||||||
|
|
||||||
detailPane = new SimpleContainer();
|
|
||||||
add(detailPane);
|
|
||||||
setDefault(detailPane);
|
|
||||||
|
|
||||||
detailPane.add(new SummarySection());
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
final ContentItemManager itemManager = cdiUtil.findBean(
|
|
||||||
ContentItemManager.class);
|
|
||||||
final GlobalizationHelper globalizationHelper = cdiUtil.findBean(
|
|
||||||
GlobalizationHelper.class);
|
|
||||||
|
|
||||||
final Label lastPublishedLabel = new Label();
|
|
||||||
lastPublishedLabel.addPrintListener(new PrintListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void prepare(final PrintEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final Optional<ContentItem> item = itemManager.getLiveVersion(
|
|
||||||
selectedItem.getContentItem(state), ContentItem.class);
|
|
||||||
final Label label = (Label) event.getTarget();
|
|
||||||
final String dateStr;
|
|
||||||
if (item.isPresent()) {
|
|
||||||
final Date lastModifiedDate = itemRepo
|
|
||||||
.retrieveCurrentRevision(item.get(),
|
|
||||||
item.get().getObjectId())
|
|
||||||
.getRevisionDate();
|
|
||||||
dateStr = DateFormat.getDateTimeInstance(
|
|
||||||
DateFormat.LONG,
|
|
||||||
DateFormat.SHORT,
|
|
||||||
globalizationHelper.getNegotiatedLocale())
|
|
||||||
.format(lastModifiedDate);
|
|
||||||
} else {
|
|
||||||
dateStr = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
label.setLabel(new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.details.last_published",
|
|
||||||
CmsConstants.CMS_BUNDLE,
|
|
||||||
new Object[]{dateStr}));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
detailPane.add(lastPublishedLabel);
|
|
||||||
|
|
||||||
detailPane.add(
|
|
||||||
new PhaseSection());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SummarySection extends Section {
|
|
||||||
|
|
||||||
public SummarySection() {
|
|
||||||
setHeading(new Label(gz("cms.ui.lifecycle.details")));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
if (CMSConfig.getConfig().isUseOldStyleItemLifecycleItemPane()) {
|
|
||||||
group.setSubject(new Properties());
|
|
||||||
group.addAction(new UnpublishLink());
|
|
||||||
group.addAction(new RepublishLink());
|
|
||||||
group.addAction(new RepublishAndResetLink());
|
|
||||||
} else {
|
|
||||||
group.addAction(new ActionForm());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Properties extends PropertyList {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final List<Property> properties(final PageState state) {
|
|
||||||
final List<Property> props = super.properties(state);
|
|
||||||
final Lifecycle cycle = selectedLifecycle.getLifecycle(state);
|
|
||||||
|
|
||||||
final DateFormat format = DateFormat.getDateTimeInstance(
|
|
||||||
DateFormat.FULL,
|
|
||||||
DateFormat.FULL);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
|
||||||
.findBean(GlobalizationHelper.class);
|
|
||||||
final Locale language = globalizationHelper
|
|
||||||
.getNegotiatedLocale();
|
|
||||||
|
|
||||||
props.add(new Property(
|
|
||||||
gz("cms.ui.name"),
|
|
||||||
cycle.getDefinition().getLabel().getValue(language)));
|
|
||||||
props.add(new Property(
|
|
||||||
gz("cms.ui.item.lifecycle.start_date"),
|
|
||||||
format.format(cycle.getStartDateTime())));
|
|
||||||
|
|
||||||
final java.util.Date endDate = cycle.getEndDateTime();
|
|
||||||
|
|
||||||
if (endDate == null) {
|
|
||||||
props.add(new Property(gz("cms.ui.item.lifecycle.end_date"),
|
|
||||||
lz("cms.ui.none")));
|
|
||||||
} else {
|
|
||||||
props.add(new Property(gz("cms.ui.item.lifecycle.end_date"),
|
|
||||||
format.format(endDate)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PublishLink extends ActionLink {
|
|
||||||
|
|
||||||
private final RequestLocal canPublishRequestLocal = new RequestLocal();
|
|
||||||
|
|
||||||
PublishLink(final Component component) {
|
|
||||||
super(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateXML(final PageState state, final Element parent) {
|
|
||||||
Boolean canPublish = (Boolean) canPublishRequestLocal.get(state);
|
|
||||||
if (null == canPublish) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
if (permissionChecker.isPermitted(ItemPrivileges.PUBLISH, item)) {
|
|
||||||
canPublish = true;
|
|
||||||
} else {
|
|
||||||
canPublish = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
canPublishRequestLocal.set(state, canPublish);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canPublish) {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
LOGGER.debug("User can publish {}" + item.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
super.generateXML(state, parent);
|
|
||||||
} else if (LOGGER.isDebugEnabled()) {
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
LOGGER.debug("User cannot publish {}", item.getUuid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UnpublishLink extends PublishLink {
|
|
||||||
|
|
||||||
UnpublishLink() {
|
|
||||||
super(new Label(gz("cms.ui.item.lifecycle.unpublish")));
|
|
||||||
|
|
||||||
super.addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemManager itemManager = cdiUtil.findBean(
|
|
||||||
ContentItemManager.class);
|
|
||||||
|
|
||||||
itemManager.unpublish(item);
|
|
||||||
|
|
||||||
final String target = String.join(
|
|
||||||
"",
|
|
||||||
URL.getDispatcherPath(),
|
|
||||||
ContentItemPage.getItemURL(item,
|
|
||||||
ContentItemPage.AUTHORING_TAB));
|
|
||||||
|
|
||||||
throw new RedirectSignal(target, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void republish(final ContentItem item,
|
|
||||||
final boolean reset,
|
|
||||||
final User user) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ItemLifecycleAdminController controller = cdiUtil
|
|
||||||
.findBean(ItemLifecycleAdminController.class);
|
|
||||||
|
|
||||||
controller.repulish(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RepublishLink extends PublishLink {
|
|
||||||
|
|
||||||
RepublishLink() {
|
|
||||||
super(new Label(gz("cms.ui.item.lifecycle.republish")));
|
|
||||||
|
|
||||||
super.addActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
final User user = shiro.getUser().get();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* jensp 2011-12-14: Check is threaded publishing is active.
|
|
||||||
* If yes, execute publishing in a thread.
|
|
||||||
*/
|
|
||||||
if (CMSConfig.getConfig().isThreadPublishing()) {
|
|
||||||
final Republisher republisher = new Republisher(item, user);
|
|
||||||
final Thread thread = new Thread(republisher);
|
|
||||||
thread.setUncaughtExceptionHandler(
|
|
||||||
new Thread.UncaughtExceptionHandler() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(final Thread thread,
|
|
||||||
final Throwable ex) {
|
|
||||||
final StringWriter strWriter = new StringWriter();
|
|
||||||
final PrintWriter writer
|
|
||||||
= new PrintWriter(strWriter);
|
|
||||||
ex.printStackTrace(writer);
|
|
||||||
|
|
||||||
// PublishLock.getInstance().setError(item, strWriter
|
|
||||||
// .toString());
|
|
||||||
LOGGER.error(String.format(
|
|
||||||
"An error occurred while "
|
|
||||||
+ "publishing the item '%s': ",
|
|
||||||
item.getUuid()), ex);
|
|
||||||
|
|
||||||
if ((CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureSender()
|
|
||||||
== null)
|
|
||||||
&& (CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureReceiver()
|
|
||||||
== null)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UserRepository userRepo = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
final User receiver = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureReceiver()).get();
|
|
||||||
final User sender = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureSender()).get();
|
|
||||||
|
|
||||||
if ((sender != null) && (receiver != null)) {
|
|
||||||
final Writer traceWriter = new StringWriter();
|
|
||||||
final PrintWriter printWriter = new PrintWriter(
|
|
||||||
traceWriter);
|
|
||||||
ex.printStackTrace(printWriter);
|
|
||||||
|
|
||||||
final Mail notification = new Mail(
|
|
||||||
receiver.getPrimaryEmailAddress()
|
|
||||||
.getAddress(),
|
|
||||||
sender.getPrimaryEmailAddress().getAddress(),
|
|
||||||
String.format(
|
|
||||||
"Failed to publish item '%s'",
|
|
||||||
item.getUuid()));
|
|
||||||
notification.setBody(String.format(
|
|
||||||
"Publishing item '%s' failed "
|
|
||||||
+ "with error message: %s.\n\n"
|
|
||||||
+ "Stacktrace:\n%s",
|
|
||||||
item.getUuid(),
|
|
||||||
ex.getMessage(),
|
|
||||||
traceWriter.toString()));
|
|
||||||
try {
|
|
||||||
notification.send();
|
|
||||||
} catch (MessagingException msgex) {
|
|
||||||
throw new UncheckedWrapperException(msgex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.getDispatcherPath()
|
|
||||||
+ ContentItemPage.getItemURL(item,
|
|
||||||
ContentItemPage.PUBLISHING_TAB),
|
|
||||||
true);
|
|
||||||
/*
|
|
||||||
* jensp 2011-12-14 end
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
republish(item, false, user);
|
|
||||||
// if (CMSConfig.getConfig().isUseStreamlinedCreation()) {
|
|
||||||
// throw new RedirectSignal(
|
|
||||||
// URL.there(state.getRequest(),
|
|
||||||
// CmsConstants.CONTENT_CENTER_URL),
|
|
||||||
// true);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jens Pelzetter
|
|
||||||
*/
|
|
||||||
private class Republisher implements Runnable {
|
|
||||||
|
|
||||||
private final String itemUuid;
|
|
||||||
private final User user;
|
|
||||||
|
|
||||||
private Republisher(final ContentItem item, User user) {
|
|
||||||
itemUuid = item.getUuid();
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
final ContentItem item = itemRepo.findByUuid(itemUuid).get();
|
|
||||||
|
|
||||||
// PublishLock.getInstance().lock(item);
|
|
||||||
republish(item, false, user);
|
|
||||||
// PublishLock.getInstance().unlock(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RepublishAndResetLink extends PublishLink {
|
|
||||||
|
|
||||||
RepublishAndResetLink() {
|
|
||||||
super(new Label(gz("cms.ui.item.lifecycle.republish_and_reset")));
|
|
||||||
|
|
||||||
super.addActionListener(new Listener());
|
|
||||||
// warning gets a bit annoying, and link should be descriptive
|
|
||||||
// enough that it is not required
|
|
||||||
// setConfirmation("This will reset all your publication dates, are
|
|
||||||
// you sure you want to continue?");
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements ActionListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent e) {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
final User user = shiro.getUser().get();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* jensp 2011-12-14: Execute is a thread if threaded publishing
|
|
||||||
* is active.
|
|
||||||
*/
|
|
||||||
if (CMSConfig.getConfig().isThreadPublishing()) {
|
|
||||||
final Republisher republisher = new Republisher(item, user);
|
|
||||||
final Thread thread = new Thread(republisher);
|
|
||||||
thread.setUncaughtExceptionHandler(
|
|
||||||
new Thread.UncaughtExceptionHandler() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(final Thread thread,
|
|
||||||
final Throwable ex) {
|
|
||||||
final StringWriter strWriter = new StringWriter();
|
|
||||||
final PrintWriter writer
|
|
||||||
= new PrintWriter(strWriter);
|
|
||||||
ex.printStackTrace(writer);
|
|
||||||
|
|
||||||
// PublishLock.getInstance().setError(item, strWriter
|
|
||||||
// .toString());
|
|
||||||
LOGGER.error(String.format(
|
|
||||||
"An error occurred while "
|
|
||||||
+ "publishing the item '%s': ",
|
|
||||||
item.getUuid()), ex);
|
|
||||||
|
|
||||||
if ((CMSConfig.getConfig().
|
|
||||||
getPublishingFailureSender() == null)
|
|
||||||
&& (CMSConfig.getConfig().
|
|
||||||
getPublishingFailureReceiver()
|
|
||||||
== null)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UserRepository userRepo = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
final User receiver = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureReceiver()).get();
|
|
||||||
final User sender = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureSender()).get();
|
|
||||||
|
|
||||||
if ((sender != null) && (receiver != null)) {
|
|
||||||
final Writer traceWriter = new StringWriter();
|
|
||||||
final PrintWriter printWriter = new PrintWriter(
|
|
||||||
traceWriter);
|
|
||||||
ex.printStackTrace(printWriter);
|
|
||||||
|
|
||||||
final Mail notification = new Mail(
|
|
||||||
receiver.getPrimaryEmailAddress()
|
|
||||||
.getAddress(),
|
|
||||||
sender.getPrimaryEmailAddress().getAddress(),
|
|
||||||
String.format(
|
|
||||||
"Failed to publish item '%s'",
|
|
||||||
item.getUuid()));
|
|
||||||
notification.setBody(String.format(
|
|
||||||
"Publishing item '%s' failed "
|
|
||||||
+ "with error message: %s.\n\n"
|
|
||||||
+ "Stacktrace:\n%s",
|
|
||||||
item.getUuid(),
|
|
||||||
ex.getMessage(),
|
|
||||||
traceWriter.toString()));
|
|
||||||
try {
|
|
||||||
notification.send();
|
|
||||||
} catch (MessagingException msgex) {
|
|
||||||
throw new UncheckedWrapperException(msgex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.getDispatcherPath()
|
|
||||||
+ ContentItemPage.getItemURL(item,
|
|
||||||
ContentItemPage.PUBLISHING_TAB),
|
|
||||||
true);
|
|
||||||
} else {
|
|
||||||
/**
|
|
||||||
* jensp 2011-12-14 end
|
|
||||||
*/
|
|
||||||
republish(item, true, user);
|
|
||||||
// if (CMSConfig.getConfig().isUseStreamlinedCreation()) {
|
|
||||||
// throw new RedirectSignal(
|
|
||||||
// URL.there(state.getRequest(),
|
|
||||||
// CmsConstants.CONTENT_CENTER_URL),
|
|
||||||
// true);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jens Pelzetter
|
|
||||||
*/
|
|
||||||
private class Republisher implements Runnable {
|
|
||||||
|
|
||||||
private final String itemUuid;
|
|
||||||
private final User user;
|
|
||||||
|
|
||||||
private Republisher(final ContentItem item, User user) {
|
|
||||||
itemUuid = item.getUuid();
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
final ContentItem item = itemRepo.findByUuid(itemUuid).get();
|
|
||||||
// PublishLock.getInstance().lock(item);
|
|
||||||
republish(item, true, user);
|
|
||||||
// PublishLock.getInstance().unlock(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PhaseSection extends Section {
|
|
||||||
|
|
||||||
PhaseSection() {
|
|
||||||
super(gz("cms.ui.lifecycle.phases"));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(new PhaseTable());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PhaseTable extends Table {
|
|
||||||
|
|
||||||
PhaseTable() {
|
|
||||||
super(new ItemPhaseTableModelBuilder(selectedLifecycle),
|
|
||||||
new String[]{
|
|
||||||
lz("cms.ui.name"),
|
|
||||||
lz("cms.ui.description"),
|
|
||||||
lz("cms.ui.item.lifecycle.start_date"),
|
|
||||||
lz("cms.ui.item.lifecycle.end_date")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New style pane. Uses a select box for the action to avoid wrong clicks on
|
|
||||||
* unpublish.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter
|
|
||||||
*/
|
|
||||||
private class ActionForm
|
|
||||||
extends Form
|
|
||||||
implements FormProcessListener,
|
|
||||||
FormInitListener {
|
|
||||||
|
|
||||||
private static final String LIFECYCLE_ACTION
|
|
||||||
= "itemLifecycleItemPaneActionSelect";
|
|
||||||
private static final String REPUBLISH = "republish";
|
|
||||||
private static final String UNPUBLISH = "unpublish";
|
|
||||||
private static final String REPUBLISH_AND_RESET = "republishAndReset";
|
|
||||||
private final Submit submit;
|
|
||||||
private final Label notAuthorized;
|
|
||||||
|
|
||||||
public ActionForm() {
|
|
||||||
super("itemLifecycleItemPaneActionForm");
|
|
||||||
|
|
||||||
final BoxPanel actionPanel = new BoxPanel(BoxPanel.HORIZONTAL);
|
|
||||||
final SingleSelect actionSelect = new SingleSelect(
|
|
||||||
LIFECYCLE_ACTION);
|
|
||||||
|
|
||||||
actionSelect.addOption(new Option(
|
|
||||||
REPUBLISH,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"cms.ui.item.lifecycle.republish",
|
|
||||||
CmsConstants.CMS_BUNDLE))));
|
|
||||||
if (!CMSConfig.getConfig().isHideResetLifecycleLink()) {
|
|
||||||
actionSelect.addOption(new Option(
|
|
||||||
REPUBLISH_AND_RESET,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"cms.ui.item.lifecycle.republish_and_reset",
|
|
||||||
CmsConstants.CMS_BUNDLE))));
|
|
||||||
}
|
|
||||||
actionSelect.addOption(new Option(
|
|
||||||
UNPUBLISH,
|
|
||||||
new Label(gz("cms.ui.item.lifecycle.unpublish"))));
|
|
||||||
|
|
||||||
submit = new Submit(gz("cms.ui.item.lifecycle.do"));
|
|
||||||
notAuthorized = new Label(gz(
|
|
||||||
"cms.ui.item.lifecycle.do.not_authorized"));
|
|
||||||
|
|
||||||
actionPanel.add(actionSelect);
|
|
||||||
actionPanel.add(submit);
|
|
||||||
actionPanel.add(notAuthorized);
|
|
||||||
add(actionPanel);
|
|
||||||
|
|
||||||
addInitListener(this);
|
|
||||||
addProcessListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
if (permissionChecker.isPermitted(ItemPrivileges.PUBLISH, item)) {
|
|
||||||
submit.setVisible(state, true);
|
|
||||||
notAuthorized.setVisible(state, false);
|
|
||||||
} else {
|
|
||||||
submit.setVisible(state, false);
|
|
||||||
notAuthorized.setVisible(state, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final FormData data = event.getFormData();
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
|
||||||
final User user = shiro.getUser().get();
|
|
||||||
|
|
||||||
String selected = (String) data.get(LIFECYCLE_ACTION);
|
|
||||||
final ContentItem item = selectedItem.getContentItem(state);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Republish/Republish and Reset are executed in the thread if
|
|
||||||
* threaded publishing is active.
|
|
||||||
*/
|
|
||||||
if (REPUBLISH.equals(selected)) {
|
|
||||||
if (CMSConfig.getConfig().isThreadPublishing()) {
|
|
||||||
final RepublishRunner runner = new RepublishRunner(item,
|
|
||||||
user);
|
|
||||||
final Thread thread = new Thread(runner);
|
|
||||||
thread.setUncaughtExceptionHandler(
|
|
||||||
new Thread.UncaughtExceptionHandler() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(final Thread thread,
|
|
||||||
final Throwable ex) {
|
|
||||||
final StringWriter strWriter = new StringWriter();
|
|
||||||
final PrintWriter writer
|
|
||||||
= new PrintWriter(strWriter);
|
|
||||||
ex.printStackTrace(writer);
|
|
||||||
|
|
||||||
// PublishLock.getInstance().setError(item, strWriter
|
|
||||||
// .toString());
|
|
||||||
LOGGER.error(String.format(
|
|
||||||
"An error occurred while "
|
|
||||||
+ "publishing the item '%s': ",
|
|
||||||
item.getUuid()), ex);
|
|
||||||
|
|
||||||
if ((CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureSender()
|
|
||||||
== null)
|
|
||||||
&& (CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureReceiver()
|
|
||||||
== null)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UserRepository userRepo = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
final User receiver = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureReceiver()).get();
|
|
||||||
final User sender = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureSender()).get();
|
|
||||||
|
|
||||||
if ((sender != null) && (receiver != null)) {
|
|
||||||
final Writer traceWriter = new StringWriter();
|
|
||||||
final PrintWriter printWriter = new PrintWriter(
|
|
||||||
traceWriter);
|
|
||||||
ex.printStackTrace(printWriter);
|
|
||||||
|
|
||||||
final Mail notification = new Mail(
|
|
||||||
receiver.getPrimaryEmailAddress()
|
|
||||||
.getAddress(),
|
|
||||||
sender.getPrimaryEmailAddress().getAddress(),
|
|
||||||
String.format(
|
|
||||||
"Failed to publish item '%s'",
|
|
||||||
item.getUuid()));
|
|
||||||
notification.setBody(String.format(
|
|
||||||
"Publishing item '%s' failed "
|
|
||||||
+ "with error message: %s.\n\n"
|
|
||||||
+ "Stacktrace:\n%s",
|
|
||||||
item.getUuid(),
|
|
||||||
ex.getMessage(),
|
|
||||||
traceWriter.toString()));
|
|
||||||
try {
|
|
||||||
notification.send();
|
|
||||||
} catch (MessagingException msgex) {
|
|
||||||
throw new UncheckedWrapperException(msgex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.getDispatcherPath()
|
|
||||||
+ ContentItemPage.getItemURL(item,
|
|
||||||
ContentItemPage.PUBLISHING_TAB),
|
|
||||||
true);
|
|
||||||
} else {
|
|
||||||
republish(item, false, user);
|
|
||||||
|
|
||||||
// if (CMSConfig.getConfig().isUseStreamlinedCreation()) {
|
|
||||||
// throw new RedirectSignal(
|
|
||||||
// URL.there(state.getRequest(),
|
|
||||||
// CmsConstants.CONTENT_CENTER_URL), true);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
} else if (REPUBLISH_AND_RESET.equals(selected)) {
|
|
||||||
if (CMSConfig.getConfig().isThreadPublishing()) {
|
|
||||||
final RepublishAndResetRunner runner
|
|
||||||
= new RepublishAndResetRunner(
|
|
||||||
item, user);
|
|
||||||
final Thread thread = new Thread(runner);
|
|
||||||
thread.setUncaughtExceptionHandler(
|
|
||||||
new Thread.UncaughtExceptionHandler() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(final Thread thread,
|
|
||||||
final Throwable ex) {
|
|
||||||
final StringWriter strWriter = new StringWriter();
|
|
||||||
final PrintWriter writer
|
|
||||||
= new PrintWriter(strWriter);
|
|
||||||
ex.printStackTrace(writer);
|
|
||||||
|
|
||||||
// PublishLock.getInstance().setError(item, strWriter
|
|
||||||
// .toString());
|
|
||||||
LOGGER.error(String.format(
|
|
||||||
"An error occurred while "
|
|
||||||
+ "publishing the item '%s': ",
|
|
||||||
item.getUuid()), ex);
|
|
||||||
|
|
||||||
if ((CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureSender()
|
|
||||||
== null)
|
|
||||||
&& (CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureReceiver()
|
|
||||||
== null)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UserRepository userRepo = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
final User receiver = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureReceiver()).get();
|
|
||||||
final User sender = userRepo.findByEmailAddress(
|
|
||||||
CMSConfig.getConfig()
|
|
||||||
.getPublishingFailureSender()).get();
|
|
||||||
|
|
||||||
if ((sender != null) && (receiver != null)) {
|
|
||||||
final Writer traceWriter = new StringWriter();
|
|
||||||
final PrintWriter printWriter = new PrintWriter(
|
|
||||||
traceWriter);
|
|
||||||
ex.printStackTrace(printWriter);
|
|
||||||
|
|
||||||
final Mail notification = new Mail(
|
|
||||||
receiver.getPrimaryEmailAddress()
|
|
||||||
.getAddress(),
|
|
||||||
sender.getPrimaryEmailAddress().getAddress(),
|
|
||||||
String.format(
|
|
||||||
"Failed to publish item '%s'",
|
|
||||||
item.getUuid()));
|
|
||||||
notification.setBody(String.format(
|
|
||||||
"Publishing item '%s' failed "
|
|
||||||
+ "with error message: %s.\n\n"
|
|
||||||
+ "Stacktrace:\n%s",
|
|
||||||
item.getUuid(),
|
|
||||||
ex.getMessage(),
|
|
||||||
traceWriter.toString()));
|
|
||||||
try {
|
|
||||||
notification.send();
|
|
||||||
} catch (MessagingException msgex) {
|
|
||||||
throw new UncheckedWrapperException(msgex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.getDispatcherPath()
|
|
||||||
+ ContentItemPage.getItemURL(item,
|
|
||||||
ContentItemPage.PUBLISHING_TAB),
|
|
||||||
true);
|
|
||||||
} else {
|
|
||||||
republish(item, true, user);
|
|
||||||
|
|
||||||
// if (CMSConfig.getConfig().isUseStreamlinedCreation()) {
|
|
||||||
// throw new RedirectSignal(
|
|
||||||
// URL.there(state.getRequest(),
|
|
||||||
// CmsConstants.CONTENT_CENTER_URL), true);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
} else if (UNPUBLISH.equals(selected)) {
|
|
||||||
final ContentItemManager itemManager = cdiUtil.findBean(
|
|
||||||
ContentItemManager.class);
|
|
||||||
itemManager.unpublish(item);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Illegal selection");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RepublishRunner implements Runnable {
|
|
||||||
|
|
||||||
private final String itemUuid;
|
|
||||||
private final User user;
|
|
||||||
|
|
||||||
private RepublishRunner(final ContentItem item,
|
|
||||||
final User user) {
|
|
||||||
itemUuid = item.getUuid();
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doRepublish() {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
final ContentItem item = itemRepo.findByUuid(itemUuid).get();
|
|
||||||
republish(item, false, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// PublishLock.getInstance().lock(item);
|
|
||||||
doRepublish();
|
|
||||||
// PublishLock.getInstance().unlock(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RepublishAndResetRunner implements Runnable {
|
|
||||||
|
|
||||||
private final String itemUuid;
|
|
||||||
private final User user;
|
|
||||||
|
|
||||||
private RepublishAndResetRunner(final ContentItem item,
|
|
||||||
final User user) {
|
|
||||||
itemUuid = item.getUuid();
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doRepublishAndReset() {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
final ContentItem item = itemRepo.findByUuid(itemUuid).get();
|
|
||||||
republish(item, true, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
final ContentItem item = itemRepo.findByUuid(itemUuid).get();
|
|
||||||
// PublishLock.getInstance().lock(item);
|
|
||||||
doRepublishAndReset();
|
|
||||||
// PublishLock.getInstance().unlock(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,110 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.librecms.CMSConfig;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class ItemPhaseTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Iterator<ItemPhaseTableRow> iterator;
|
|
||||||
private ItemPhaseTableRow currentRow;
|
|
||||||
|
|
||||||
public ItemPhaseTableModel(final List<ItemPhaseTableRow> rows) {
|
|
||||||
iterator = rows.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
currentRow = iterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
|
||||||
.findBean(GlobalizationHelper.class);
|
|
||||||
final Locale locale = globalizationHelper.getNegotiatedLocale();
|
|
||||||
final DateFormat format;
|
|
||||||
if (CMSConfig.getConfig().isHideTimezone()) {
|
|
||||||
format = DateFormat.getDateTimeInstance(
|
|
||||||
DateFormat.FULL, DateFormat.SHORT, locale);
|
|
||||||
} else {
|
|
||||||
format = DateFormat.getDateTimeInstance(
|
|
||||||
DateFormat.FULL, DateFormat.FULL, locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (columnIndex) {
|
|
||||||
case 0:
|
|
||||||
return currentRow.getName();
|
|
||||||
case 1:
|
|
||||||
return currentRow.getDescription();
|
|
||||||
case 2:
|
|
||||||
if (currentRow.getStartDate() == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return format.format(currentRow.getStartDate());
|
|
||||||
}
|
|
||||||
case 3:
|
|
||||||
if (currentRow.getEndDate() == null) {
|
|
||||||
return new GlobalizedMessage("cms.ui.lifecycle.forever",
|
|
||||||
CmsConstants.CMS_BUNDLE)
|
|
||||||
.localize();
|
|
||||||
} else {
|
|
||||||
return currentRow.getEndDate();
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Illegal Column Index");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
|
|
||||||
return currentRow.getPhaseId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Xixi D'Moon <xdmoon@arsdigita.com>
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class ItemPhaseTableModelBuilder extends AbstractTableModelBuilder {
|
|
||||||
|
|
||||||
private final LifecycleRequestLocal lifecycle;
|
|
||||||
|
|
||||||
public ItemPhaseTableModelBuilder(final LifecycleRequestLocal lifecycle) {
|
|
||||||
this.lifecycle = lifecycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ItemLifecycleAdminController controller = cdiUtil
|
|
||||||
.findBean(ItemLifecycleAdminController.class);
|
|
||||||
|
|
||||||
final List<ItemPhaseTableRow> rows = controller
|
|
||||||
.findPhasesOfLifecycle(lifecycle.getLifecycle(state));
|
|
||||||
|
|
||||||
return new ItemPhaseTableModel(rows);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,94 +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.lifecycle;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class ItemPhaseTableRow implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8947185134493863779L;
|
|
||||||
|
|
||||||
private long phaseId;
|
|
||||||
private String name;
|
|
||||||
private String description;
|
|
||||||
private Date startDate;
|
|
||||||
private Date endDate;
|
|
||||||
|
|
||||||
public long getPhaseId() {
|
|
||||||
return phaseId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPhaseId(final long phaseId) {
|
|
||||||
this.phaseId = phaseId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(final String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(final String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getStartDate() {
|
|
||||||
if (startDate == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return new Date(startDate.getTime());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartDate(final Date startDate) {
|
|
||||||
if (startDate == null) {
|
|
||||||
this.startDate = startDate;
|
|
||||||
} else {
|
|
||||||
this.startDate = new Date(startDate.getTime());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getEndDate() {
|
|
||||||
if (endDate == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return new Date(endDate.getTime());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndDate(final Date endDate) {
|
|
||||||
if (endDate == null) {
|
|
||||||
this.endDate = endDate;
|
|
||||||
} else {
|
|
||||||
this.endDate = new Date(endDate.getTime());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,76 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author <a href="mailto:xdmoon@redhat.com">Xixi D'Moon</a>
|
|
||||||
* @author <a href="jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class LifecycleAddForm extends BaseLifecycleForm {
|
|
||||||
|
|
||||||
private final SingleSelectionModel<Long> selectedLifecycle;
|
|
||||||
|
|
||||||
LifecycleAddForm(final SingleSelectionModel<Long> selectedLifecycle) {
|
|
||||||
super("LifecycleDefinition", gz("cms.ui.lifecycle.add"));
|
|
||||||
|
|
||||||
this.selectedLifecycle = selectedLifecycle;
|
|
||||||
|
|
||||||
getLifecycleName().addValidationListener(
|
|
||||||
new LifecycleNameUniqueListener(this));
|
|
||||||
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
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 LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
|
|
||||||
final LifecycleDefinition definition = controller
|
|
||||||
.createLifecycleDefinition(
|
|
||||||
CMS.getContext().getContentSection(),
|
|
||||||
(String) getLifecycleName().getValue(state),
|
|
||||||
(String) getLifecycleDescription().getValue(state));
|
|
||||||
|
|
||||||
selectedLifecycle.setSelectedKey(state,
|
|
||||||
definition.getDefinitionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,74 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
|
|
||||||
import org.libreccm.security.Party;
|
|
||||||
|
|
||||||
import com.arsdigita.toolbox.ui.SecurityContainer;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Security container that wraps the canAdministerLifecycles access check around
|
|
||||||
* its components.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:pihman@arsdigita.com">Michael Pih</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class LifecycleAdminContainer extends SecurityContainer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This default constructor should be followed by calls to <code>add</code>.
|
|
||||||
*/
|
|
||||||
public LifecycleAdminContainer() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a <code>SecurityContainer</code> around a child component.
|
|
||||||
*
|
|
||||||
* @param component The child component
|
|
||||||
*/
|
|
||||||
public LifecycleAdminContainer(final Component component) {
|
|
||||||
super(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the current user can access the child component.
|
|
||||||
*
|
|
||||||
* @param state The page state
|
|
||||||
*
|
|
||||||
* @return true if the access checks pass, false otherwise
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected boolean canAccess(final Party party, final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
return permissionChecker.isPermitted(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,121 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.BaseAdminPane;
|
|
||||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
|
||||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinitionRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains the split pane for the lifecycle administration
|
|
||||||
* interface.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class LifecycleAdminPane extends BaseAdminPane {
|
|
||||||
|
|
||||||
private final SingleSelectionModel selectionModel;
|
|
||||||
private final LifecycleDefinitionRequestLocal selectionLifecycleDefinition;
|
|
||||||
|
|
||||||
public LifecycleAdminPane() {
|
|
||||||
super(new Label(gz("cms.ui.lifecycles")),
|
|
||||||
new LifecycleListModelBuilder());
|
|
||||||
|
|
||||||
selectionModel = getSelectionModel();
|
|
||||||
selectionLifecycleDefinition = new SelectionRequestLocal();
|
|
||||||
|
|
||||||
// XXX secvis
|
|
||||||
//add(new LifecycleAdminContainer(m_addLink));
|
|
||||||
setAdd(gz("cms.ui.lifecycle.add"),
|
|
||||||
new LifecycleAddForm(selectionModel));
|
|
||||||
setEdit(gz("cms.ui.lifecycle.edit"),
|
|
||||||
new LifecycleEditForm(selectionLifecycleDefinition));
|
|
||||||
setDelete(gz("cms.ui.lifecycle.delete"), new DeleteForm());
|
|
||||||
|
|
||||||
setIntroPane(new Label(gz("cms.ui.lifecycle.intro")));
|
|
||||||
setItemPane(new LifecycleItemPane(selectionLifecycleDefinition,
|
|
||||||
getEditLink(),
|
|
||||||
getDeleteLink()));
|
|
||||||
|
|
||||||
addAction(new LifecycleAdminContainer(getAddLink()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SelectionRequestLocal
|
|
||||||
extends LifecycleDefinitionRequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
final String id = selectionModel.getSelectedKey(state).toString();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleDefinitionRepository lifecycleDefRepo = cdiUtil
|
|
||||||
.findBean(LifecycleDefinitionRepository.class);
|
|
||||||
|
|
||||||
return lifecycleDefRepo.findById(Long.parseLong(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class DeleteForm extends BaseDeleteForm {
|
|
||||||
|
|
||||||
DeleteForm() {
|
|
||||||
super(new Label(gz("cms.ui.lifecycle.delete_prompt")));
|
|
||||||
|
|
||||||
addSubmissionListener(new FormSecurityListener(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
|
||||||
final LifecycleDefinition definition = selectionLifecycleDefinition
|
|
||||||
.getLifecycleDefinition(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
controller.deleteLifecycleDefinition(definition, section);
|
|
||||||
|
|
||||||
selectionModel.clearSelection(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,407 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
import com.arsdigita.toolbox.ui.Property;
|
|
||||||
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
import org.librecms.contentsection.ContentSectionManager;
|
|
||||||
import org.librecms.contentsection.ContentSectionRepository;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinitionRepository;
|
|
||||||
import org.librecms.lifecycle.PhaseDefinition;
|
|
||||||
import org.librecms.lifecycle.PhaseDefinititionRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
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
|
|
||||||
class LifecycleAdminPaneController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ConfigurationManager confManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentSectionRepository sectionRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentSectionManager sectionManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LifecycleDefinitionRepository lifecycleDefRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private PhaseDefinititionRepository phaseDefRepo;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<LifecycleDefinition> getLifecyclesForContentSection(
|
|
||||||
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.getLifecycleDefinitions());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public List<Map<String, String>> listLifecyclesForContentSection(
|
|
||||||
final ContentSection section
|
|
||||||
) {
|
|
||||||
return getLifecyclesForContentSection(section)
|
|
||||||
.stream()
|
|
||||||
.map(this::buildLifecycleListItem)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> buildLifecycleListItem(
|
|
||||||
final LifecycleDefinition lifecycleDefinition) {
|
|
||||||
final Map<String, String> item = new HashMap<>();
|
|
||||||
item.put(
|
|
||||||
LifecycleListModelBuilder.LIFECYCLE_DEF_ID,
|
|
||||||
Long.toString(lifecycleDefinition.getDefinitionId())
|
|
||||||
);
|
|
||||||
item.put(
|
|
||||||
LifecycleListModelBuilder.LIFECYCLE_DEF_LABEL,
|
|
||||||
lifecycleDefinition
|
|
||||||
.getLabel()
|
|
||||||
.getValue(KernelConfig.getConfig().getDefaultLocale())
|
|
||||||
);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<Property> getLifecycleProperties(
|
|
||||||
final LifecycleDefinition ofLifecycleDefinition
|
|
||||||
) {
|
|
||||||
final LifecycleDefinition definition = lifecycleDefRepo
|
|
||||||
.findById(ofLifecycleDefinition.getDefinitionId())
|
|
||||||
.orElseThrow(
|
|
||||||
() -> new IllegalArgumentException(
|
|
||||||
String.format(
|
|
||||||
"No LifecycleDefinition with ID %d found.",
|
|
||||||
ofLifecycleDefinition.getDefinitionId()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
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.lifecycle.name",
|
|
||||||
CmsConstants.CMS_BUNDLE
|
|
||||||
),
|
|
||||||
definition.getLabel().getValue(defaultLocale)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
properties.add(
|
|
||||||
new Property(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.description",
|
|
||||||
CmsConstants.CMS_BUNDLE
|
|
||||||
),
|
|
||||||
definition.getDescription().getValue(defaultLocale)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new lifecycle definition
|
|
||||||
*
|
|
||||||
* @param section The content section which the
|
|
||||||
* {@link LifecycleDefinition} is created.
|
|
||||||
* @param name The name of the new lifecycle definition.
|
|
||||||
* @param description The description of the new lifecycle definition.
|
|
||||||
*/
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public LifecycleDefinition createLifecycleDefinition(
|
|
||||||
final ContentSection section,
|
|
||||||
final String name,
|
|
||||||
final String description) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(section, "ContentSection can't be null.");
|
|
||||||
Objects.requireNonNull(name, "Name can't be null");
|
|
||||||
if (name.trim().isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Name can't be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
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 LifecycleDefinition definition = new LifecycleDefinition();
|
|
||||||
|
|
||||||
definition.getLabel().putValue(defaultLocale, name);
|
|
||||||
definition.getDescription().putValue(defaultLocale, description);
|
|
||||||
lifecycleDefRepo.save(definition);
|
|
||||||
|
|
||||||
sectionManager.addLifecycleDefinitionToContentSection(definition,
|
|
||||||
contentSection);
|
|
||||||
|
|
||||||
return definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the name and/or description of a {@link LifecycleDefinition}.
|
|
||||||
*
|
|
||||||
* @param definition The definition to update.
|
|
||||||
* @param name The new name.
|
|
||||||
* @param description The new description.
|
|
||||||
*/
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void updateLifecycleDefinition(final LifecycleDefinition definition,
|
|
||||||
final String name,
|
|
||||||
final String description) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(definition, "definition can't be null.");
|
|
||||||
Objects.requireNonNull(name, "name can't be null");
|
|
||||||
if (name.trim().isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Name can't be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefRepo
|
|
||||||
.findById(definition.getDefinitionId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No LifecycleDefinition with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
definition.getDefinitionId())));
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
if (!lifecycleDefinition.getLabel().getValue(defaultLocale).equals(name)) {
|
|
||||||
lifecycleDefinition.getLabel().putValue(defaultLocale, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lifecycleDefinition.getDescription().getValue(defaultLocale)
|
|
||||||
.equals(description)) {
|
|
||||||
lifecycleDefinition.getDescription().putValue(defaultLocale,
|
|
||||||
description);
|
|
||||||
}
|
|
||||||
|
|
||||||
lifecycleDefRepo.save(lifecycleDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void deleteLifecycleDefinition(
|
|
||||||
final LifecycleDefinition definition,
|
|
||||||
final ContentSection section) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(definition, "definition can't be null.");
|
|
||||||
|
|
||||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefRepo
|
|
||||||
.findById(definition.getDefinitionId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No LifecycleDefinition with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
definition.getDefinitionId())));
|
|
||||||
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())));
|
|
||||||
|
|
||||||
sectionManager.removeLifecycleDefinitionFromContentSection(
|
|
||||||
lifecycleDefinition,
|
|
||||||
contentSection);
|
|
||||||
lifecycleDefRepo.delete(lifecycleDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public List<PhaseDefinition> getPhaseDefinitions(
|
|
||||||
final LifecycleDefinition definition) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(definition);
|
|
||||||
|
|
||||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefRepo
|
|
||||||
.findById(definition.getDefinitionId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No LifecycleDefinition with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
definition.getDefinitionId())));
|
|
||||||
|
|
||||||
return new ArrayList<>(lifecycleDefinition.getPhaseDefinitions());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void addPhaseDefinition(final LifecycleDefinition definition,
|
|
||||||
final String label,
|
|
||||||
final String description,
|
|
||||||
final int delayDays,
|
|
||||||
final int delayHours,
|
|
||||||
final int delayMinutes,
|
|
||||||
final int durationDays,
|
|
||||||
final int durationHours,
|
|
||||||
final int durationMinutes) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(definition, "definition can't be null");
|
|
||||||
Objects.requireNonNull(label, "label can't be null");
|
|
||||||
if (label.trim().isEmpty()) {
|
|
||||||
throw new IllegalArgumentException(String.format(
|
|
||||||
"label can't be empty."));
|
|
||||||
}
|
|
||||||
|
|
||||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefRepo
|
|
||||||
.findById(definition.getDefinitionId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No LifecycleDefinition with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
definition.getDefinitionId())));
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final PhaseDefinition phaseDefinition = new PhaseDefinition();
|
|
||||||
lifecycleDefinition.addPhaseDefinition(phaseDefinition);
|
|
||||||
|
|
||||||
phaseDefinition.getLabel().putValue(defaultLocale, label);
|
|
||||||
phaseDefinition.getDescription().putValue(defaultLocale, description);
|
|
||||||
int delay = delayDays * 24 * 60 * 60;
|
|
||||||
delay += delayHours * 60 * 60;
|
|
||||||
delay += delayMinutes * 60;
|
|
||||||
phaseDefinition.setDefaultDelay(delay);
|
|
||||||
int duration = durationDays * 24 * 60 * 60;
|
|
||||||
duration += durationHours * 60 * 60;
|
|
||||||
duration += durationMinutes * 60;
|
|
||||||
phaseDefinition.setDefaultDuration(duration);
|
|
||||||
|
|
||||||
phaseDefRepo.save(phaseDefinition);
|
|
||||||
lifecycleDefRepo.save(lifecycleDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public void updatePhaseDefinition(final PhaseDefinition definition,
|
|
||||||
final String label,
|
|
||||||
final String description,
|
|
||||||
final int delayDays,
|
|
||||||
final int delayHours,
|
|
||||||
final int delayMinutes,
|
|
||||||
final int durationDays,
|
|
||||||
final int durationHours,
|
|
||||||
final int durationMinutes) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(definition, "definition can't be null");
|
|
||||||
Objects.requireNonNull(label, "label can't be null");
|
|
||||||
if (label.trim().isEmpty()) {
|
|
||||||
throw new IllegalArgumentException(String.format(
|
|
||||||
"label can't be empty."));
|
|
||||||
}
|
|
||||||
|
|
||||||
final PhaseDefinition phaseDefinition = phaseDefRepo
|
|
||||||
.findById(definition.getDefinitionId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No PhaseDefinition with ID %d in the database. "
|
|
||||||
+ "Where did that ID come from?",
|
|
||||||
definition.getDefinitionId())));
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
phaseDefinition.getLabel().putValue(defaultLocale, label);
|
|
||||||
phaseDefinition.getDescription().putValue(defaultLocale, description);
|
|
||||||
int delay = delayDays * 24 * 60 * 60;
|
|
||||||
delay += delayHours * 60 * 60;
|
|
||||||
delay += delayMinutes * 60;
|
|
||||||
phaseDefinition.setDefaultDelay(delay);
|
|
||||||
int duration = durationDays * 24 * 60 * 60;
|
|
||||||
duration += durationHours * 60 * 60;
|
|
||||||
duration += durationMinutes * 60;
|
|
||||||
phaseDefinition.setDefaultDuration(duration);
|
|
||||||
|
|
||||||
phaseDefRepo.save(phaseDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public String getLifecycleDefinitionName(
|
|
||||||
final LifecycleDefinition ofCycle
|
|
||||||
) {
|
|
||||||
final LifecycleDefinition cycle = lifecycleDefRepo.findById(
|
|
||||||
Objects.requireNonNull(ofCycle).getDefinitionId()
|
|
||||||
).orElseThrow(
|
|
||||||
() -> new IllegalArgumentException(
|
|
||||||
String.format(
|
|
||||||
"No LifecycleDefinition with ID %d available",
|
|
||||||
ofCycle.getDefinitionId()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class
|
|
||||||
);
|
|
||||||
return cycle.getLabel().getValue(kernelConfig.getDefaultLocale());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public String getLifecycleDefinitionDescription(
|
|
||||||
final LifecycleDefinition ofCycle
|
|
||||||
) {
|
|
||||||
final LifecycleDefinition cycle = lifecycleDefRepo.findById(
|
|
||||||
Objects.requireNonNull(ofCycle).getDefinitionId()
|
|
||||||
).orElseThrow(
|
|
||||||
() -> new IllegalArgumentException(
|
|
||||||
String.format(
|
|
||||||
"No LifecycleDefinition with ID %d available",
|
|
||||||
ofCycle.getDefinitionId()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class
|
|
||||||
);
|
|
||||||
return cycle.getDescription().getValue(kernelConfig.getDefaultLocale());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public abstract class LifecycleDefinitionRequestLocal extends RequestLocal {
|
|
||||||
|
|
||||||
public final LifecycleDefinition getLifecycleDefinition(
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final Optional<LifecycleDefinition> definition
|
|
||||||
= (Optional<LifecycleDefinition>) get(
|
|
||||||
state);
|
|
||||||
|
|
||||||
return definition.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,98 +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.lifecycle;
|
|
||||||
|
|
||||||
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 org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains a form component to edit a lifecycle definition.
|
|
||||||
*
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author Xixi D'Moon <xdmoon@redhat.com>
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class LifecycleEditForm extends BaseLifecycleForm {
|
|
||||||
|
|
||||||
private final LifecycleDefinitionRequestLocal selectedDefinition;
|
|
||||||
|
|
||||||
LifecycleEditForm(final LifecycleDefinitionRequestLocal selectedDefinition) {
|
|
||||||
super("LifecycleEdit", gz("cms.ui.lifecycle.edit"));
|
|
||||||
|
|
||||||
this.selectedDefinition = selectedDefinition;
|
|
||||||
|
|
||||||
getLifecycleName().addValidationListener(
|
|
||||||
new LifecycleNameUniqueListener(this, selectedDefinition));
|
|
||||||
|
|
||||||
addInitListener(new InitListener());
|
|
||||||
addProcessListener(new ProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InitListener implements FormInitListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void init(final FormSectionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final LifecycleDefinition cycle = selectedDefinition
|
|
||||||
.getLifecycleDefinition(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil.findBean(
|
|
||||||
LifecycleAdminPaneController.class
|
|
||||||
);
|
|
||||||
|
|
||||||
getLifecycleName().setValue(
|
|
||||||
state, controller.getLifecycleDefinitionName(cycle)
|
|
||||||
);
|
|
||||||
getLifecycleDescription().setValue(
|
|
||||||
state, controller.getLifecycleDefinitionDescription(cycle)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final LifecycleDefinition definition = selectedDefinition
|
|
||||||
.getLifecycleDefinition(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
|
|
||||||
controller.updateLifecycleDefinition(
|
|
||||||
definition,
|
|
||||||
(String) getLifecycleName().getValue(state),
|
|
||||||
(String) getLifecycleDescription().getValue(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,252 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Container;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
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.table.DefaultTableCellRenderer;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
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.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
import org.librecms.lifecycle.PhaseDefinititionRepository;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains the component which displays the information for a
|
|
||||||
* particular lifecycle, with the ability to edit and delete. This information
|
|
||||||
* also includes the associated phases for this lifecycle, also with the ability
|
|
||||||
* to add, edit, and delete.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
* @author Michael Pih
|
|
||||||
* @author Jack Chung
|
|
||||||
* @author <a href="mailto:xdmoon@redhat.com">Xixi D'Moon</a>
|
|
||||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
|
||||||
*/
|
|
||||||
class LifecycleItemPane extends BaseItemPane {
|
|
||||||
|
|
||||||
private final LifecycleDefinitionRequestLocal selectedLifecycle;
|
|
||||||
|
|
||||||
private final PhaseRequestLocal selectedPhase;
|
|
||||||
|
|
||||||
private final Container detailPane;
|
|
||||||
|
|
||||||
private final Table phasesTable;
|
|
||||||
|
|
||||||
public LifecycleItemPane(
|
|
||||||
final LifecycleDefinitionRequestLocal selectedLifecycle,
|
|
||||||
final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
|
|
||||||
this.selectedLifecycle = selectedLifecycle;
|
|
||||||
selectedPhase = new SelectionRequestLocal();
|
|
||||||
|
|
||||||
phasesTable = new PhaseTable();
|
|
||||||
|
|
||||||
detailPane = new SimpleContainer();
|
|
||||||
add(detailPane);
|
|
||||||
setDefault(detailPane);
|
|
||||||
|
|
||||||
detailPane.add(new SummarySection(editLink, deleteLink));
|
|
||||||
|
|
||||||
final ActionLink phaseAddLink = new ActionLink(new Label(gz(
|
|
||||||
"cms.ui.lifecycle.phase_add")));
|
|
||||||
|
|
||||||
detailPane.add(new PhaseSection(phaseAddLink));
|
|
||||||
|
|
||||||
final AddPhaseForm phaseAddForm = new AddPhaseForm(selectedLifecycle);
|
|
||||||
final EditPhaseForm phaseEditForm = new EditPhaseForm(selectedLifecycle,
|
|
||||||
selectedPhase);
|
|
||||||
final DeletePhaseForm phaseDeleteForm = new DeletePhaseForm(
|
|
||||||
selectedPhase);
|
|
||||||
|
|
||||||
add(phaseAddForm);
|
|
||||||
add(phaseEditForm);
|
|
||||||
add(phaseDeleteForm);
|
|
||||||
|
|
||||||
connect(phaseAddLink, phaseAddForm);
|
|
||||||
connect(phaseAddForm);
|
|
||||||
connect(phasesTable, 4, phaseEditForm);
|
|
||||||
connect(phaseEditForm, phasesTable.getRowSelectionModel());
|
|
||||||
connect(phasesTable, 5, phaseDeleteForm);
|
|
||||||
connect(phaseDeleteForm, phasesTable.getRowSelectionModel());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SelectionRequestLocal extends PhaseRequestLocal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final Object initialValue(final PageState state) {
|
|
||||||
final String id = phasesTable.getRowSelectionModel().getSelectedKey(
|
|
||||||
state).toString();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PhaseDefinititionRepository phaseDefRepo = cdiUtil.findBean(
|
|
||||||
PhaseDefinititionRepository.class);
|
|
||||||
|
|
||||||
return phaseDefRepo.findById(Long.parseLong(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SummarySection extends Section {
|
|
||||||
|
|
||||||
public SummarySection(final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
setHeading(new Label(gz("cms.ui.lifecycle.details")));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(new Properties());
|
|
||||||
group.addAction(new LifecycleAdminContainer(editLink),
|
|
||||||
ActionGroup.EDIT);
|
|
||||||
group.addAction(new LifecycleAdminContainer(deleteLink),
|
|
||||||
ActionGroup.DELETE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Properties extends PropertyList {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final java.util.List<Property> properties(
|
|
||||||
final PageState 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();
|
|
||||||
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
|
|
||||||
final java.util.List<Property> props = super.properties(state);
|
|
||||||
final LifecycleDefinition cycle = selectedLifecycle
|
|
||||||
.getLifecycleDefinition(state);
|
|
||||||
|
|
||||||
props.addAll(controller.getLifecycleProperties(cycle));
|
|
||||||
|
|
||||||
// props.add(new Property(
|
|
||||||
// gz("cms.ui.lifecycle.name"),
|
|
||||||
// cycle.getLabel().getValue(defaultLocale)));
|
|
||||||
// props.add(new Property(
|
|
||||||
// gz("cms.ui.lifecycle.description"),
|
|
||||||
// cycle.getDescription().getValue(defaultLocale)));
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PhaseSection extends Section {
|
|
||||||
|
|
||||||
public PhaseSection(final ActionLink addLink) {
|
|
||||||
setHeading(new Label(gz("cms.ui.lifecycle.phases")));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(phasesTable);
|
|
||||||
group.addAction(new LifecycleAdminContainer(addLink),
|
|
||||||
ActionGroup.ADD);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX fix this
|
|
||||||
private static final String[] HEADERS = {
|
|
||||||
lz("cms.ui.lifecycle.phase.name"),
|
|
||||||
lz("cms.ui.lifecycle.phase.description"),
|
|
||||||
lz("cms.ui.lifecycle.phase_delay"),
|
|
||||||
lz("cms.ui.lifecycle.phase_duration"),
|
|
||||||
"",
|
|
||||||
""
|
|
||||||
};
|
|
||||||
|
|
||||||
private class PhaseTable extends Table {
|
|
||||||
|
|
||||||
public PhaseTable() {
|
|
||||||
super(new PhaseTableModelBuilder(selectedLifecycle), HEADERS);
|
|
||||||
|
|
||||||
setEmptyView(new Label(gz("cms.ui.lifecycle.phase_none")));
|
|
||||||
|
|
||||||
getColumn(4).setCellRenderer(new DefaultTableCellRenderer(true));
|
|
||||||
|
|
||||||
getColumn(5).setCellRenderer(new DefaultTableCellRenderer(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
// Hide the action columns if the user does not have
|
|
||||||
// proper access.
|
|
||||||
page.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void actionPerformed(final ActionEvent e) {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final boolean hasLifecycleAdmin = hasAdmin(state);
|
|
||||||
getColumn(4).setVisible(state, hasLifecycleAdmin);
|
|
||||||
getColumn(5).setVisible(state, hasLifecycleAdmin);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasAdmin(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
return permissionChecker.isPermitted(
|
|
||||||
AdminPrivileges.ADMINISTER_LIFECYLES);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void reset(final PageState state) {
|
|
||||||
super.reset(state);
|
|
||||||
|
|
||||||
phasesTable.clearSelection(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,100 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.list.ListModel;
|
|
||||||
import com.arsdigita.bebop.list.ListModelBuilder;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
|
||||||
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads all the current lifecycles from the database so that they may be
|
|
||||||
* displayed in a list.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:pihman@arsdigita.com">Michael Pih</a>
|
|
||||||
* @author <a href="mailto:flattop@arsdigita.com">Jack Chung</a>
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public final class LifecycleListModelBuilder extends LockableImpl
|
|
||||||
implements ListModelBuilder {
|
|
||||||
|
|
||||||
protected static final String LIFECYCLE_DEF_ID = "lifecycleDefId";
|
|
||||||
|
|
||||||
protected static final String LIFECYCLE_DEF_LABEL = "lifecycleDefLabel";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final ListModel makeModel(final com.arsdigita.bebop.List list,
|
|
||||||
final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
|
||||||
return new Model(controller.listLifecyclesForContentSection(section));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Model implements ListModel {
|
|
||||||
|
|
||||||
private final Iterator<Map<String, String>> iterator;
|
|
||||||
|
|
||||||
private Map<String, String> currentLifecycleDef;
|
|
||||||
|
|
||||||
public Model(final List<Map<String, String>> lifecycles) {
|
|
||||||
iterator = lifecycles.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() throws NoSuchElementException {
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
currentLifecycleDef = iterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return currentLifecycleDef.get(LIFECYCLE_DEF_LABEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKey() {
|
|
||||||
return currentLifecycleDef.get(LIFECYCLE_DEF_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,89 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.event.ParameterEvent;
|
|
||||||
import com.arsdigita.bebop.event.ParameterListener;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class LifecycleNameUniqueListener implements ParameterListener {
|
|
||||||
|
|
||||||
private final BaseLifecycleForm form;
|
|
||||||
private final LifecycleDefinitionRequestLocal selectedDefinition;
|
|
||||||
|
|
||||||
protected LifecycleNameUniqueListener(final BaseLifecycleForm form) {
|
|
||||||
this.form = form;
|
|
||||||
selectedDefinition = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected LifecycleNameUniqueListener(
|
|
||||||
final BaseLifecycleForm form,
|
|
||||||
final LifecycleDefinitionRequestLocal selectedDefinition) {
|
|
||||||
|
|
||||||
this.form = form;
|
|
||||||
this.selectedDefinition = selectedDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void validate(final ParameterEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ConfigurationManager confManager = cdiUtil
|
|
||||||
.findBean(ConfigurationManager.class);
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
final String label = (String) form.getLifecycleName().getValue(state);
|
|
||||||
|
|
||||||
final java.util.List<LifecycleDefinition> definitions = controller
|
|
||||||
.getLifecyclesForContentSection(CMS.getContext().getContentSection());
|
|
||||||
|
|
||||||
for (final LifecycleDefinition definition : definitions) {
|
|
||||||
if (definition.getLabel().getValue(defaultLocale)
|
|
||||||
.equalsIgnoreCase(label)
|
|
||||||
&& (selectedDefinition == null
|
|
||||||
|| !selectedDefinition.getLifecycleDefinition(state)
|
|
||||||
.equals(definition))) {
|
|
||||||
throw new FormProcessException(new GlobalizedMessage(
|
|
||||||
"cms.ui.lifecycle.name_not_unique",
|
|
||||||
CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
public abstract class LifecycleRequestLocal extends RequestLocal {
|
|
||||||
|
|
||||||
public final Lifecycle getLifecycle(final PageState state) {
|
|
||||||
return (Lifecycle) get(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.PhaseDefinition;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public abstract class PhaseRequestLocal extends RequestLocal {
|
|
||||||
|
|
||||||
|
|
||||||
public final PhaseDefinition getPhase(final PageState state) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final Optional<PhaseDefinition> phaseDef = (Optional<PhaseDefinition>) get(state);
|
|
||||||
return phaseDef.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,138 +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.lifecycle;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.cms.lifecycle.Duration;
|
|
||||||
|
|
||||||
import org.librecms.lifecycle.LifecycleDefinition;
|
|
||||||
import org.librecms.lifecycle.PhaseDefinition;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
class PhaseTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final LifecycleDefinitionRequestLocal selectedLifecycle;
|
|
||||||
|
|
||||||
public PhaseTableModelBuilder(
|
|
||||||
final LifecycleDefinitionRequestLocal selectedLifecycle) {
|
|
||||||
this.selectedLifecycle = selectedLifecycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
|
||||||
final LifecycleDefinition definition = selectedLifecycle
|
|
||||||
.getLifecycleDefinition(state);
|
|
||||||
|
|
||||||
return new PhaseTableModel(controller.getPhaseDefinitions(definition));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class PhaseTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Iterator<PhaseDefinition> iterator;
|
|
||||||
private PhaseDefinition currentPhaseDef;
|
|
||||||
|
|
||||||
public PhaseTableModel(final List<PhaseDefinition> phaseDefinitions) {
|
|
||||||
iterator = phaseDefinitions.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int getColumnCount() {
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean nextRow() {
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
currentPhaseDef = iterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Object getElementAt(final int column) {
|
|
||||||
|
|
||||||
switch (column) {
|
|
||||||
case 0:
|
|
||||||
return currentPhaseDef
|
|
||||||
.getLabel()
|
|
||||||
.getValue(KernelConfig.getConfig().getDefaultLocale());
|
|
||||||
case 1:
|
|
||||||
return currentPhaseDef
|
|
||||||
.getDescription()
|
|
||||||
.getValue(KernelConfig.getConfig().getDefaultLocale());
|
|
||||||
case 2:
|
|
||||||
return Duration.formatDuration(currentPhaseDef
|
|
||||||
.getDefaultDelay());
|
|
||||||
case 3:
|
|
||||||
final Long duration = currentPhaseDef.getDefaultDuration();
|
|
||||||
|
|
||||||
if (duration == 0) {
|
|
||||||
return lz("cms.ui.lifecycle.forever");
|
|
||||||
} else {
|
|
||||||
return Duration.formatDuration(duration);
|
|
||||||
}
|
|
||||||
case 4:
|
|
||||||
return lz("cms.ui.lifecycle.phase_edit");
|
|
||||||
case 5:
|
|
||||||
return lz("cms.ui.lifecycle.phase_delete");
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
if (currentPhaseDef == null) {
|
|
||||||
throw new IllegalStateException();
|
|
||||||
} else {
|
|
||||||
return currentPhaseDef.getDefinitionId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue