From 02b61b7ddc7b013589f7a45cd2a67945a9f42a50 Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 2 Sep 2016 17:57:17 +0000 Subject: [PATCH] CCM NG: First part of migration of WorkflowAdminPane, as well as some smaller things in other classes. git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4251 8810af33-2d31-482b-a856-94f89814c4df --- .../cms/ui/ListOptionPrintListener.java | 60 +++ .../com/arsdigita/cms/ui/UserAddForm.java | 289 +++++++++++ .../com/arsdigita/cms/ui/UserSearchForm.java | 72 +++ .../arsdigita/cms/ui/VisibilityComponent.java | 56 +++ .../cms/ui/folder/FolderBrowser.java | 3 +- .../cms/ui/lifecycle/AddPhaseForm.java | 6 +- .../cms/ui/lifecycle/BaseLifecycleForm.java | 3 +- .../cms/ui/lifecycle/EditPhaseForm.java | 2 +- .../cms/ui/lifecycle/LifecycleAddForm.java | 3 +- .../cms/ui/lifecycle/LifecycleEditForm.java | 8 +- .../cms/ui/lifecycle/LifecycleItemPane.java | 3 +- .../AssignedTaskTableModelBuilder.java.off | 120 +++++ .../cms/ui/workflow/BaseWorkflowForm.java | 100 ++++ .../ui/workflow/BaseWorkflowItemPane.java.off | 253 ++++++++++ .../cms/ui/workflow/TaskAddRole.java | 206 ++++++++ .../cms/ui/workflow/TaskAddUser.java | 171 +++++++ .../cms/ui/workflow/TaskItemPane.java | 476 ++++++++++++++++++ .../cms/ui/workflow/TaskRequestLocal.java | 35 ++ .../cms/ui/workflow/WorkflowAddForm.java | 89 ++++ .../ui/workflow/WorkflowAdminPane.java.off | 31 +- .../cms/ui/workflow/WorkflowEditForm.java | 102 ++++ .../cms/ui/workflow/WorkflowItemPane.java.off | 30 ++ .../ui/workflow/WorkflowListModelBuilder.java | 80 +++ .../cms/ui/workflow/WorkflowRequestLocal.java | 30 ++ .../contentsection/ContentItemManager.java | 2 +- .../contentsection/ContentSectionManager.java | 40 +- .../com/arsdigita/kernel/KernelConfig.java | 5 + .../ApplicationInstanceTreeNode.java | 7 +- .../libreccm/l10n/GlobalizationHelper.java | 2 +- .../libreccm/security/ChallengeManager.java | 6 +- 30 files changed, 2230 insertions(+), 60 deletions(-) create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/ListOptionPrintListener.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/UserAddForm.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/UserSearchForm.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/VisibilityComponent.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/AssignedTaskTableModelBuilder.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowForm.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowItemPane.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddRole.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddUser.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskItemPane.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskRequestLocal.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAddForm.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowEditForm.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowItemPane.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowListModelBuilder.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowRequestLocal.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ListOptionPrintListener.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ListOptionPrintListener.java new file mode 100755 index 000000000..f82f39e84 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ListOptionPrintListener.java @@ -0,0 +1,60 @@ +/* + * 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; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.form.OptionGroup; + +import java.util.List; + +/** + * Migrated from the {@code DataQueryPrintListener} in the old system. Renamed + * and refactored to operate on a list. + * + * @author Jens Pelzetter + * @param Type of the objects in the list. + */ +public abstract class ListOptionPrintListener implements PrintListener { + + public ListOptionPrintListener() { + } + + protected abstract List getDataQuery(final PageState state); + + @Override + public void prepare(final PrintEvent event) { + final PageState state = event.getPageState(); + final OptionGroup target = (OptionGroup) event.getTarget(); + final List dataQuery = getDataQuery(state); + + dataQuery.forEach(item -> target.addOption( + new Option(getKey(item), + getValue(item)))); + } + + public abstract String getKey(final T object); + + public String getValue(final T object) { + return getKey(object); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/UserAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/UserAddForm.java new file mode 100755 index 000000000..3acf8d856 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/UserAddForm.java @@ -0,0 +1,289 @@ +/* + * 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; + +import com.arsdigita.bebop.ColumnPanel; +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.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.CheckboxGroup; +import com.arsdigita.bebop.form.Hidden; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.form.OptionGroup; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.form.Widget; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.xml.Element; + +import org.libreccm.security.User; +import org.librecms.CmsConstants; + +import java.math.BigDecimal; +import java.util.List; +import java.util.TooManyListenersException; + +/** + * Form for adding multiple users to a role. + * + * @author Jens Pelzetter + * @author Michael Pih + * @author Uday Mathur + */ +public abstract class UserAddForm extends SimpleContainer + implements FormProcessListener { + + private final static String SEARCH_QUERY = "searchQuery"; + private final static String USERS = "users"; + private final static String SUBMIT = "addSubmit"; + private final static String CANCEL = "addCancel"; + + private final static String DQ_USER_ID = "userId"; + private final static String DQ_NAME = "name"; + + private Widget m_search; + private RequestLocal m_query; + private String m_label; + private String m_submitText; + + private CMSContainer m_noMatches; + private CMSContainer m_matches; + + private Form m_form; + private Hidden m_searchQuery; + private CheckboxGroup m_users; + private Submit m_submit; + private Submit m_cancel; + + /** + * Constructor. + * + * @param search The widget on the search form that contains the value of + * the search string. + */ + public UserAddForm(final Widget search) { + this(search, "AddUsers"); + } + + public UserAddForm(final Widget search, final String name) { + this(search, name, + "Check the box next to the name of the person(s) to assign.", + "Add Members"); + } + + public UserAddForm(final Widget search, + final String name, + final String text, + final String submitText) { + m_label = text; + m_submitText = submitText; + m_search = search; + + m_query = new RequestLocal() { + + @Override + protected Object initialValue(final PageState state) { + return makeQuery(state); + } + + }; + + m_form = makeForm(name); + + Label title = new Label(new GlobalizedMessage("cms.ui.matches", + CmsConstants.CMS_BUNDLE)); + title.setFontWeight(Label.BOLD); + + Label label = new Label(new GlobalizedMessage( + "cms.ui.there_was_no_one_matching_the_search_criteria", + CmsConstants.CMS_BUNDLE)); + label.setFontWeight("em"); + + m_noMatches = new CMSContainer(); + m_noMatches.add(title); + m_noMatches.add(label); + add(m_noMatches); + + m_matches = new CMSContainer(); + m_matches.add(title); + m_matches.add(m_form); + add(m_matches); + } + + /** + * Build the form used to add users. + * + * @param name + * + * @return The form + */ + protected Form makeForm(final String name) { + final CMSForm form = new CMSForm(name) { + + public final boolean isCancelled(final PageState state) { + return m_cancel.isSelected(state); + } + + }; + + // This hidden field will store the search query. A hidden widget is + // used instead of a request local variable because the search query + // should only be updated when the search form is submitted. + m_searchQuery = new Hidden(SEARCH_QUERY); + form.add(m_searchQuery, ColumnPanel.FULL_WIDTH); + + Label l = new Label(m_label); + form.add(l, ColumnPanel.FULL_WIDTH); + + // Add the list of users that can be added. + m_users = new CheckboxGroup(USERS); + m_users.addValidationListener(new NotNullValidationListener()); + try { + m_users.addPrintListener(new PrintListener() { + + @Override + public void prepare(PrintEvent event) { + CheckboxGroup target = (CheckboxGroup) event.getTarget(); + PageState state = event.getPageState(); + // Ensures that the init listener gets fired before the + // print listeners. + FormData data = m_form.getFormData(state); + addUsers(state, target); + } + + }); + } catch (TooManyListenersException ex) { + throw new RuntimeException(ex); + } + form.add(m_users, ColumnPanel.FULL_WIDTH); + + // Submit and Cancel buttons. + SimpleContainer s = new SimpleContainer(); + m_submit = new Submit(SUBMIT, m_submitText); + s.add(m_submit); + m_cancel = new Submit(CANCEL, "Cancel"); + s.add(m_cancel); + form.add(s, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER); + + form.addProcessListener(this); + + return form; + } + + /** + * Fetches the form for adding users. + * + * @return The "add user" form + */ + public Form getForm() { + return m_form; + } + + /** + * Fetches the widget that contains the search string. + * + * @return The widget that contains the search string + */ + protected Widget getSearchWidget() { + return m_searchQuery; + } + + /** + * Return true if the form is cancelled, false otherwise. + * + * @param state The page state + * + * @return true if the form is cancelled, false otherwise. + * + * @pre ( state != null ) + */ + public boolean isCancelled(final PageState state) { + return m_cancel.isSelected(state); + } + + /** + * Adds users to the option group. + * + * @param state The page state + * @param target The option group + * + * @pre ( state != null && target != null ) + */ + protected void addUsers(final PageState state, final OptionGroup target) { + + @SuppressWarnings("unchecked") + final List users = (java.util.List) m_query.get(state); + + users.forEach(user -> target.addOption( + new Option(Long.toString(user.getPartyId()), + user.getName()))); + } + + /** + * Generates a {@link com.arsdigita.persistence.DataQuery} that encapsulates + * search results. + * + * @param state The page state + * + * @return + */ + protected abstract List makeQuery(final PageState state); + + /** + * Process listener for the "Add users" form. + * + * @param event The form event + * + * @throws com.arsdigita.bebop.FormProcessException + */ + @Override + public abstract void process(final FormSectionEvent event) + throws FormProcessException; + + /** + * Displays the appropriate frame. + * + * @param state The page state + * @param parent The parent DOM element + */ + @Override + public void generateXML(final PageState state, + final Element parent) { + + m_searchQuery.setValue(state, m_search.getValue(state)); + @SuppressWarnings("unchecked") + final List searchResults = (List) m_query.get(state); + + if (searchResults.size() > 0) { + m_matches.generateXML(state, parent); + } else { + m_noMatches.generateXML(state, parent); + } + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/UserSearchForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/UserSearchForm.java new file mode 100755 index 000000000..5192688c4 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/UserSearchForm.java @@ -0,0 +1,72 @@ +/* + * 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; + +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.librecms.CmsConstants; + +/** + * Form to search for users to be added to a staff group. + * + * + * @author Michael Pih + */ +public class UserSearchForm extends CMSForm { + + private final static String SEARCH_LABEL = "Search"; + + private TextField m_search; + + public UserSearchForm(String name) { + this(name, + new Label(new GlobalizedMessage( + "cms.ui.search_to_add_new_members", + CmsConstants.CMS_BUNDLE))); + + } + + public UserSearchForm(String name, Label heading) { + super(name, new ColumnPanel(3)); + heading.setFontWeight(Label.BOLD); + add(heading, ColumnPanel.FULL_WIDTH); + + add(new Label(new GlobalizedMessage( + "cms.ui.enter_first_name_last_name_andor_email_address", + CmsConstants.CMS_BUNDLE))); + + m_search = new TextField(new StringParameter("query")); + m_search.setSize(20); + add(m_search, ColumnPanel.RIGHT); + + Submit submit = new Submit("submit"); + submit.setButtonLabel(SEARCH_LABEL); + add(submit, ColumnPanel.LEFT); + } + + public TextField getSearchWidget() { + return m_search; + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/VisibilityComponent.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/VisibilityComponent.java new file mode 100755 index 000000000..5e834faff --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/VisibilityComponent.java @@ -0,0 +1,56 @@ +/* + * 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; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.PageState; +import com.arsdigita.toolbox.ui.ProxyComponent; +import com.arsdigita.util.Assert; + +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.security.PermissionChecker; + +/** + * @author Jens Pelzetter + * @author Justin Ross + */ +public class VisibilityComponent extends ProxyComponent { + + private final String m_action; + + public VisibilityComponent(final Component child, final String action) { + super(child); + + m_action = action; + } + + @Override + public boolean isVisible(final PageState state) { + return super.isVisible(state) && hasPermission(state); + } + + public boolean hasPermission(final PageState state) { + Assert.exists(m_action, String.class); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class); + + return permissionChecker.isPermitted(m_action); + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowser.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowser.java index 57999f3a6..78c987d01 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowser.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowser.java @@ -316,8 +316,7 @@ public class FolderBrowser extends Table { final List filters = new ArrayList<>(); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig. - getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); if (state.getValue(m_aToZfilter) != null) { filters.add(criteriaBuilder.like(criteriaBuilder.lower( root.get("Categorization.categorizedObject.displayName")), diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/AddPhaseForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/AddPhaseForm.java index d9d89a256..a6e91d878 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/AddPhaseForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/AddPhaseForm.java @@ -294,8 +294,7 @@ class AddPhaseForm extends CMSForm { ConfigurationManager.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); // Check if the object already exists for double click protection. final PhaseDefinition phaseDef = new PhaseDefinition(); @@ -331,8 +330,7 @@ class AddPhaseForm extends CMSForm { ConfigurationManager.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); for (final PhaseDefinition phaseDef : phaseDefs) { if (phaseDef.getLabel().getValue(defaultLocale).equalsIgnoreCase( diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/BaseLifecycleForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/BaseLifecycleForm.java index f0da704e2..80525f2e4 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/BaseLifecycleForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/BaseLifecycleForm.java @@ -98,8 +98,7 @@ class BaseLifecycleForm extends BaseForm { ConfigurationManager.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); final String label = (String) m_name.getValue(state); final java.util.List definitions = CMS diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/EditPhaseForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/EditPhaseForm.java index a81805e57..ce60792f2 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/EditPhaseForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/EditPhaseForm.java @@ -295,7 +295,7 @@ class EditPhaseForm extends CMSForm { PhaseDefinititionRepository.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig.getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); final PhaseDefinition phaseDefinition = m_phase.getPhase(state); phaseDefinition.getLabel().addValue(defaultLocale, label); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAddForm.java index 664665be0..6e2a8495e 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAddForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAddForm.java @@ -75,8 +75,7 @@ class LifecycleAddForm extends BaseLifecycleForm { ContentSectionManager.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); final LifecycleDefinition definition = new LifecycleDefinition(); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleEditForm.java index 6361585cc..ddd4f2a81 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleEditForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleEditForm.java @@ -75,9 +75,10 @@ class LifecycleEditForm extends BaseLifecycleForm { private class ProcessListener implements FormProcessListener { - public final void process(final FormSectionEvent e) + @Override + public final void process(final FormSectionEvent event) throws FormProcessException { - final PageState state = e.getPageState(); + final PageState state = event.getPageState(); final LifecycleDefinition definition = m_definition .getLifecycleDefinition(state); @@ -88,8 +89,7 @@ class LifecycleEditForm extends BaseLifecycleForm { .findBean(LifecycleDefinitionRepository.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); definition.getLabel().addValue(defaultLocale, (String) m_name.getValue(state)); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleItemPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleItemPane.java index 977dda79b..fef47e2d3 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleItemPane.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleItemPane.java @@ -150,8 +150,7 @@ class LifecycleItemPane extends BaseItemPane { ConfigurationManager.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); final java.util.List props = super.properties(state); final LifecycleDefinition cycle = m_cycle diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/AssignedTaskTableModelBuilder.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/AssignedTaskTableModelBuilder.java.off new file mode 100755 index 000000000..17a486dcc --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/AssignedTaskTableModelBuilder.java.off @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the CCM Public + * License (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the + * License at http://www.redhat.com/licenses/ccmpl.html. + * + * Software distributed under the License is distributed on an + * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express + * or implied. See the License for the specific language + * governing rights and limitations under the License. + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.table.AbstractTableModelBuilder; +import com.arsdigita.bebop.table.TableModel; + +import org.librecms.workflow.CmsTask; +import org.librecms.workflow.CmsTaskType; + +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.util.Assert; +import com.arsdigita.web.Web; + +import org.apache.logging.log4j.LogManager; +import org.libreccm.workflow.Workflow; + +import java.util.Collections; +import java.util.Iterator; + +import org.apache.logging.log4j.Logger; + +/** + * + * + */ +class AssignedTaskTableModelBuilder extends AbstractTableModelBuilder { + + private final WorkflowRequestLocal m_workflow; + + public AssignedTaskTableModelBuilder(final WorkflowRequestLocal workflow) { + m_workflow = workflow; + } + + @Override + public TableModel makeModel(final Table table, final PageState state) { + return new Model(m_workflow.getWorkflow(state)); + } + + private static class Model implements TableModel { + + private final Iterator m_iter; + private CmsTask m_task; + + Model(final Workflow workflow) { + Assert.exists(workflow, Workflow.class); + + if (workflow.getProcessState() == Workflow.STARTED) { + + final Engine engine = Engine.getInstance(CMSEngine.CMS_ENGINE_TYPE); + + Assert.exists(engine, Engine.class); + + m_iter = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow.getID()).iterator(); + } else { + m_iter = Collections.emptyList().iterator(); + } + + } + + @Override + public final int getColumnCount() { + return 3; + } + + @Override + public final boolean nextRow() { + if (m_iter.hasNext()) { + m_task = (CmsTask) m_iter.next(); + + return true; + } else { + return false; + } + } + + public final Object getKeyAt(final int column) { + return m_task.getID(); + } + + public final Object getElementAt(final int column) { + switch (column) { + case 0: + return m_task.getLabel(); + case 1: + // SF patch [ 1587168 ] Show locking user + return m_task.isLocked() ? m_task.getLockedUser() : null; + case 2: + return m_task.getTaskType().getID().equals(CmsTaskType.DEPLOY) + ? (Object) new Label("") : // null should work as well + (Object) lz("cms.ui.workflow.task.finish"); + default: + throw new IllegalStateException(); + } + } + } + + protected final static GlobalizedMessage gz(final String key) { + return GlobalizationUtil.globalize(key); + } + + protected final static String lz(final String key) { + return (String) gz(key).localize(); + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowForm.java new file mode 100755 index 000000000..50d72cbda --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowForm.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormValidationListener; +import com.arsdigita.cms.ui.BaseForm; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.librecms.CmsConstants; + +/** + * Jens Pelzetter + * + * @author Uday Mathur + * @author Michael Pih + * @author Justin Ross + */ +class BaseWorkflowForm extends BaseForm { + + final Name m_title; + final Description m_description; + + BaseWorkflowForm(final String key, final GlobalizedMessage message) { + super(key, message); + + m_title = new Name("name", 200, true); + addField(gz("cms.ui.name"), m_title); + + m_description = new Description("desc", 4000, true); + addField(gz("cms.ui.description"), m_description); + + addAction(new Finish()); + addAction(new Cancel()); + + addSecurityListener(CmsConstants.PRIVILEGE_ADMINISTER_WORKFLOW); + addValidationListener(new ValidationListener()); + } + + private class ValidationListener implements FormValidationListener { + + @Override + public final void validate(final FormSectionEvent event) + throws FormProcessException { + final String name = (String) m_title.getValue(event.getPageState()); + + // XXX do a dupe check here ala commented out code below + } + + } + + /* + protected void addValidationListener(Form f) { + f.addValidationListener(new DataQueryExistsListener(ERROR_MSG) { + private final String QUERY_NAME = + "com.arsdigita.workflow.simple.getProcessDefinitions"; + + + public void validate(FormSectionEvent event) + throws FormProcessException { + + String name = (String) m_title.getValue(event.getPageState()); + if ( name != null ) { + super.validate(event); + } else { + // Do nothing. The NotNullValidation listener should kick in. + } + } + + public DataQuery getDataQuery(FormSectionEvent e) { + PageState s = e.getPageState(); + Session session = SessionManager.getSession(); + DataQuery query = session.retrieveQuery(QUERY_NAME); + Filter listenerFilter = query.addFilter("lower(processDefinitionLabel) = lower(:label)"); + listenerFilter.set("label", ((String) m_title.getValue(s)).trim()); + Filter itemFilter = query.addNotEqualsFilter + ("processDefinitionId", m_id.getValue(s)); + return query; + } + }); + } + */ +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowItemPane.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowItemPane.java.off new file mode 100755 index 000000000..1a450337c --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/BaseWorkflowItemPane.java.off @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.ActionLink; +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.event.ActionEvent; +import com.arsdigita.bebop.event.ActionListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.table.DefaultTableCellRenderer; +import com.arsdigita.cms.ui.BaseDeleteForm; +import com.arsdigita.cms.ui.BaseItemPane; +import com.arsdigita.cms.ui.VisibilityComponent; +import org.librecms.workflow.CmsTask; +import org.libreccm.security.User; +import com.arsdigita.toolbox.ui.ActionGroup; +import com.arsdigita.toolbox.ui.PropertyList; +import com.arsdigita.toolbox.ui.Section; +import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.web.Web; +import org.libreccm.workflow.Workflow; + +import java.math.BigDecimal; + +abstract class BaseWorkflowItemPane extends BaseItemPane { + + final WorkflowRequestLocal m_workflow; + final TaskRequestLocal m_task; + + ActionGroup m_actionGroup; + final TaskTable m_tasks; + + final SimpleContainer m_detailPane; + final TaskItemPane m_taskPane; + final SummarySection m_summarySection; + + public BaseWorkflowItemPane(final WorkflowRequestLocal workflow, + final ActionLink editLink, + final ActionLink deleteLink) { + m_workflow = workflow; + + m_tasks = new TaskTable(); + m_task = new TaskSelectionRequestLocal(); + + m_detailPane = new SimpleContainer(); + + // Tasks + + final FinishLink taskFinishLink = new FinishLink(); + + final ActionLink taskAddLink = new ActionLink + (new Label(gz("cms.ui.workflow.task.add"))); + final TaskAddForm taskAddForm = new TaskAddForm + (m_workflow, m_tasks.getRowSelectionModel()); + + final ActionLink taskEditLink = new ActionLink + (new Label(gz("cms.ui.workflow.task.edit"))); + final TaskEditForm taskEditForm = new TaskEditForm(m_workflow, m_task); + + final ActionLink taskDeleteLink = new ActionLink + (new Label(gz("cms.ui.workflow.task.delete"))); + final TaskDeleteForm taskDeleteForm = new TaskDeleteForm(); + + final ActionLink backLink = new ActionLink + (new Label(gz("cms.ui.workflow.task.return"))); + backLink.addActionListener(new ResetListener()); + + m_taskPane = new TaskItemPane(m_workflow, m_task, + taskFinishLink, taskEditLink, + taskDeleteLink, backLink); + + m_summarySection = new SummarySection(editLink, deleteLink); + m_detailPane.add(m_summarySection); + m_detailPane.add(new TaskSection(taskAddLink)); + + add(m_detailPane); + setDefault(m_detailPane); + add(m_taskPane); + add(taskAddForm); + add(taskEditForm); + add(taskDeleteForm); + + connect(m_tasks, 0, m_taskPane); + + connect(taskAddLink, taskAddForm); + connect(taskAddForm, m_taskPane); + + connect(taskEditLink, taskEditForm); + connect(taskEditForm); + + connect(taskDeleteLink, taskDeleteForm); + connect(taskDeleteForm, m_detailPane); + } + + protected class AdminVisible extends VisibilityComponent { + public AdminVisible(final Component child) { + super(child, SecurityManager.WORKFLOW_ADMIN); + } + } + + private class FinishLink extends ActionLink { + FinishLink() { + super(new Label(gz("cms.ui.workflow.task.finish"))); + + addActionListener(new Listener()); + addActionListener(new ResetListener()); + } + + public final boolean isVisible(final PageState state) { + CmsTask task = m_task.getTask(state); + User lockingUser = task.getLockedUser(); + boolean visible = task.isEnabled() && + (lockingUser == null || + lockingUser.equals(Web.getWebContext().getUser())); + return visible; + } + + private class Listener implements ActionListener { + public final void actionPerformed(final ActionEvent e) { + final PageState state = e.getPageState(); + + try { + m_task.getTask(state).finish + (Web.getWebContext().getUser()); + } catch (TaskException te) { + throw new UncheckedWrapperException(te); + } + } + } + } + + public void reset(final PageState state) { + super.reset(state); + + m_tasks.getRowSelectionModel().clearSelection(state); + } + + private class TaskDeleteForm extends BaseDeleteForm { + TaskDeleteForm() { + super(new Label(gz("cms.ui.workflow.task.delete_prompt"))); + + addSecurityListener(SecurityManager.WORKFLOW_ADMIN); + } + + public final void process(final FormSectionEvent e) + throws FormProcessException { + final PageState state = e.getPageState(); + + m_task.getTask(state).delete(); + + m_tasks.getRowSelectionModel().clearSelection(state); + } + } + + private class TaskSelectionRequestLocal extends TaskRequestLocal { + protected final Object initialValue(final PageState state) { + final String id = m_tasks.getRowSelectionModel().getSelectedKey + (state).toString(); + + return new CmsTask(new BigDecimal(id)); + } + } + + class SummarySection extends Section { + SummarySection(final ActionLink editLink, + final ActionLink deleteLink) { + setHeading(new Label(gz("cms.ui.workflow.details"))); + + m_actionGroup = new ActionGroup(); + setBody(m_actionGroup); + + m_actionGroup.setSubject(new Properties()); + m_actionGroup.addAction(new AdminVisible(editLink), + ActionGroup.EDIT); + m_actionGroup.addAction(new AdminVisible(deleteLink), + ActionGroup.DELETE); +// m_actionGroup.addAction(new AdminVisible(new StartLink())); +// m_actionGroup.addAction(new AdminVisible(new StopLink())); + } + + private class Properties extends PropertyList { + protected final java.util.List properties(final PageState state) { + final java.util.List props = super.properties(state); + final Workflow flow = (Workflow) m_workflow.get(state); + + props.add(new Property(gz("cms.ui.name"), + flow.getLabel())); + props.add(new Property(gz("cms.ui.description"), + flow.getDescription())); + props.add(new Property(gz("cms.ui.workflow.current_state"), + flow.getStateString())); + props.add(new Property(gz("cms.ui.workflow.num_tasks"), + String.valueOf(flow.getTaskCount()))); + + return props; + } + } + + } + + class TaskSection extends Section { + TaskSection(final ActionLink taskAddLink) { + setHeading(new Label(gz("cms.ui.workflow.tasks"))); + + final ActionGroup group = new ActionGroup(); + setBody(group); + + group.setSubject(m_tasks); + group.addAction(new AdminVisible(taskAddLink), ActionGroup.ADD); + } + } + + // XXX Fix this. + private static final String[] s_columns = new String[] { + lz("cms.ui.name"), + lz("cms.ui.description"), + lz("cms.ui.workflow.task.dependencies"), + lz("cms.ui.workflow.task.state") + }; + + private class TaskTable extends Table { + public TaskTable() { + super(new TaskTableModelBuilder(m_workflow), s_columns); + + setEmptyView(new Label(gz("cms.ui.workflow.task.none"))); + + getColumn(0).setCellRenderer + (new DefaultTableCellRenderer(true)); + } + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddRole.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddRole.java new file mode 100755 index 000000000..488d9ee64 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddRole.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.GridPanel; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormSubmissionListener; +import com.arsdigita.bebop.form.CheckboxGroup; +import com.arsdigita.bebop.form.OptionGroup; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.CMS; + +import org.librecms.contentsection.ContentSection; + +import com.arsdigita.cms.ui.CMSForm; +import com.arsdigita.cms.ui.ListOptionPrintListener; + +import org.librecms.workflow.CmsTask; + +import com.arsdigita.globalization.GlobalizedMessage; + + +import com.arsdigita.util.UncheckedWrapperException; + +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.security.PermissionChecker; +import org.libreccm.security.Role; +import org.libreccm.security.RoleRepository; +import org.libreccm.workflow.TaskAssignment; +import org.libreccm.workflow.WorkflowManager; +import org.librecms.CmsConstants; + +import java.util.ArrayList; +import java.util.List; +import java.util.TooManyListenersException; + +class TaskAddRole extends CMSForm { + + private final TaskRequestLocal m_task; + private final OptionGroup m_roles; + private final Submit m_add; + private final Submit m_cancel; + + TaskAddRole(final TaskRequestLocal task) { + super("GroupAssignForm"); + + m_task = task; + + add(new Label(gz("cms.ui.workflow.task.roles")), ColumnPanel.TOP); + + m_roles = new CheckboxGroup("roles"); + add(m_roles); + + try { + m_roles.addPrintListener(new RoleOptionPrintListener()); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException("TooManyListeners: " + ex + .getMessage(), ex); + } + + final SimpleContainer submits = new SimpleContainer(); + add(submits, GridPanel.FULL_WIDTH | GridPanel.CENTER); + + m_add = new Submit("add", gz("cms.ui.finish")); + submits.add(m_add); + + m_cancel = new Submit("cancel", gz("cms.ui.cancel")); + submits.add(m_cancel); + + addInitListener(new InitListener()); + addSubmissionListener(new SubmissionListener()); + addProcessListener(new ProcessListener()); + } + + private class InitListener implements FormInitListener { + + @Override + public final void init(final FormSectionEvent event) + throws FormProcessException { + final PageState state = event.getPageState(); + final CmsTask task = m_task.getTask(state); + + final List assignments = task.getAssignments(); + final List roles = new ArrayList<>(); + + assignments.forEach(assignment -> roles.add(assignment.getRole())); + + m_roles.setValue(state, roles); + } + + } + + private class ProcessListener implements FormProcessListener { + + @Override + public final void process(final FormSectionEvent event) + throws FormProcessException { + final PageState state = event.getPageState(); + if (m_add.isSelected(state)) { + final CmsTask task = m_task.getTask(state); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowManager workflowManager = cdiUtil.findBean( + WorkflowManager.class); + final RoleRepository roleRepository = cdiUtil.findBean( + RoleRepository.class); + + task.getAssignments().forEach(assignment -> workflowManager + .retractTask(task, assignment.getRole())); + + final String[] roleIds = (String[]) m_roles.getValue(state); + + if (roleIds != null) { + for (final String roleId : roleIds) { + final Role role = roleRepository.findById(Long + .parseLong(roleId)); + workflowManager.assignTask(task, role); + } + } + } + } + + } + + private class SubmissionListener implements FormSubmissionListener { + + @Override + public final void submitted(final FormSectionEvent event) + throws FormProcessException { + final PageState state = event.getPageState(); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final PermissionChecker permissionChecker = cdiUtil.findBean( + PermissionChecker.class); + + if (!permissionChecker.isPermitted( + CmsConstants.PRIVILEGE_ADMINISTER_WORKFLOW)) { + throw new FormProcessException( + new GlobalizedMessage( + "cms.ui.workflow.insufficient_privileges", + CmsConstants.CMS_BUNDLE)); + } + } + + } + + private class RoleOptionPrintListener extends ListOptionPrintListener { + + public static final String QUERY_NAME + = "com.arsdigita.cms.getStaffRoles"; + + public RoleOptionPrintListener() { + super(); + } + + @Override + protected List getDataQuery(final PageState state) { + final ContentSection section = CMS.getContext().getContentSection(); + + return section.getRoles(); + } + + @Override + public String getKey(final Role role) { + return Long.toString(role.getRoleId()); + } + + @Override + public String getValue(final Role role) { + return role.getName(); + } + + } + + private static GlobalizedMessage gz(final String key) { + return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE); + } + + private static String lz(final String key) { + return (String) gz(key).localize(); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddUser.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddUser.java new file mode 100755 index 000000000..a670a6417 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskAddUser.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ui.UserAddForm; +import com.arsdigita.cms.ui.UserSearchForm; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.libreccm.security.User; +import org.libreccm.workflow.UserTask; + +import com.arsdigita.xml.Element; + +import org.apache.log4j.Logger; +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.security.UserRepository; +import org.libreccm.workflow.WorkflowManager; +import org.librecms.CmsConstants; + +import java.math.BigDecimal; +import java.util.List; + +/** + * Contains forms to search and add users as Task Assignees. + * + * @author Uday Mathur + * @author Michael Pih + * @version $Id$ + */ +class TaskAddUser extends SimpleContainer { + + private static final Logger s_log = Logger.getLogger(TaskAddUser.class); + + private final TaskRequestLocal m_task; + + private SearchForm m_search; + private AddForm m_add; + + public TaskAddUser(final TaskRequestLocal task) { + super(); + + m_task = task; + + m_search = new SearchForm(); + add(m_search); + + m_add = new AddForm(); + add(m_add); + } + + UserSearchForm getSearchForm() { + return m_search; + } + + UserAddForm getAddForm() { + return m_add; + } + + public final void generateXML(final PageState state, + final Element parent) { + if (isVisible(state)) { + final FormData one = m_search.getFormData(state); + final FormData two = m_add.getForm().getFormData(state); + + if (one != null && (one.isSubmission() || two.isSubmission())) { + m_search.generateXML(state, parent); + m_add.generateXML(state, parent); + } else { + m_search.generateXML(state, parent); + } + } + } + + private static class SearchForm extends UserSearchForm { + + private final Submit m_cancel; + + public SearchForm() { + super("user-search"); + + m_cancel = new Submit("cancel", gz("cms.ui.cancel")); + + add(m_cancel); + } + + } + + private class AddForm extends UserAddForm { + + public AddForm() { + super(m_search.getSearchWidget()); + } + + @Override + protected final List makeQuery(final PageState state) { + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final UserRepository userRepo = cdiUtil.findBean( + UserRepository.class); + + final String search = (String) getSearchWidget().getValue(state); + + return userRepo.filtered(search); + } + + @Override + public final void process(final FormSectionEvent event) + throws FormProcessException { + final FormData data = event.getFormData(); + final PageState state = event.getPageState(); + + final String[] users = (String[]) data.get("users"); + + if (users == null) { + throw new FormProcessException(new GlobalizedMessage( + "cms.ui.workflow.no_users_were_selected", + CmsConstants.CMS_BUNDLE)); + } else { + // Add each checked user to the task. + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowManager workflowManager = cdiUtil.findBean( + WorkflowManager.class); + final UserRepository userRepo = cdiUtil.findBean(UserRepository.class); + + final UserTask task = m_task.getTask(state); + User user; + + for (int i = 0; i < users.length; i++) { + user = userRepo.findById(Long.parseLong(users[i])); + + //ToDo + + } + } + } + + } + + private static GlobalizedMessage gz(final String key) { + return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE); + } + + private static String lz(final String key) { + return (String) gz(key).localize(); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskItemPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskItemPane.java new file mode 100755 index 000000000..9dd025e5e --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskItemPane.java @@ -0,0 +1,476 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the CCM Public + * License (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the + * License at http://www.redhat.com/licenses/ccmpl.html. + * + * Software distributed under the License is distributed on an + * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express + * or implied. See the License for the specific language + * governing rights and limitations under the License. + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.ActionLink; +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.Form; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.Page; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.RequestLocal; +import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.event.ActionEvent; +import com.arsdigita.bebop.event.ActionListener; +import com.arsdigita.bebop.event.TableActionAdapter; +import com.arsdigita.bebop.event.TableActionEvent; +import com.arsdigita.bebop.table.DefaultTableCellRenderer; +import com.arsdigita.bebop.table.TableColumn; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.bebop.table.TableModelBuilder; +import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ui.BaseItemPane; +import com.arsdigita.cms.ui.VisibilityComponent; +import com.arsdigita.kernel.KernelConfig; + +import org.librecms.workflow.CmsTask; +import org.libreccm.core.EmailAddress; +import org.libreccm.security.Group; +import org.libreccm.security.User; + +import com.arsdigita.toolbox.ui.ActionGroup; +import com.arsdigita.toolbox.ui.PropertyList; +import com.arsdigita.toolbox.ui.Section; +import com.arsdigita.util.LockableImpl; +import com.arsdigita.web.Web; + +import com.sun.javafx.scene.control.skin.VirtualFlow; +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.security.GroupRepository; +import org.libreccm.security.PermissionChecker; +import org.libreccm.security.Role; +import org.libreccm.security.RoleRepository; +import org.libreccm.security.Shiro; +import org.libreccm.workflow.Task; +import org.libreccm.workflow.UserTask; +import org.libreccm.workflow.Workflow; +import org.libreccm.workflow.WorkflowManager; +import org.librecms.CmsConstants; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.StringJoiner; + +/** + * @author Jens Pelzetter + * @author Justin Ross + */ +final class TaskItemPane extends BaseItemPane { + + private final WorkflowRequestLocal m_workflow; + private final TaskRequestLocal m_task; + + private final SimpleContainer m_detailPane; + + TaskItemPane(final WorkflowRequestLocal workflow, + final TaskRequestLocal task, + final ActionLink finishLink, + final ActionLink editLink, + final ActionLink deleteLink, + final ActionLink backLink) { + m_workflow = workflow; + m_task = task; + + m_detailPane = new SimpleContainer(); + m_detailPane.add(new Navigation(backLink)); + m_detailPane.add(new SummarySection(finishLink, editLink, deleteLink)); + + // Users + final ActionLink userAddLink = new ActionLink(new Label(gz( + "cms.ui.workflow.task.user.add"))); + + final TaskAddUser userAddPane = new TaskAddUser(m_task); + + final Form search = userAddPane.getSearchForm(); + final Form add = userAddPane.getAddForm().getForm(); + + // Roles + final ActionLink roleAddLink = new ActionLink(new Label(gz( + "cms.ui.workflow.task.role.add"))); + + final TaskAddRole roleAddForm = new TaskAddRole(m_task); + + m_detailPane.add(new RoleSection(roleAddLink)); + + add(m_detailPane); + setDefault(m_detailPane); + add(userAddPane); + add(roleAddForm); + + userAddLink.addActionListener(new NavigationListener(userAddPane)); + search.addSubmissionListener(new CancelListener(search)); + add.addSubmissionListener(new CancelListener(add)); + add.addProcessListener(new FormNavigationListener(m_detailPane)); + + connect(roleAddLink, roleAddForm); + resume(roleAddForm, m_detailPane); + } + + private boolean hasAdmin(final PageState state) { + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final PermissionChecker permissionChecker = cdiUtil.findBean( + PermissionChecker.class); + + return permissionChecker.isPermitted( + CmsConstants.PRIVILEGE_ADMINISTER_WORKFLOW); + } + + private class AdminVisible extends VisibilityComponent { + + public AdminVisible(final Component child) { + super(child, CmsConstants.PRIVILEGE_ADMINISTER_WORKFLOW); + } + + } + + private class AssigneeVisible extends AdminVisible { + + private final Component m_child; + private final Assigned m_assigned; + + public AssigneeVisible(final Component child) { + super(child); + + m_child = child; + m_assigned = new Assigned(); + } + + @Override + public final boolean isVisible(final PageState state) { + if (m_child.isVisible(state)) { + return m_assigned.isAssigned(state) || hasPermission(state); + } else { + return false; + } + } + + private class Assigned extends RequestLocal { + + @Override + protected final Object initialValue(final PageState state) { + if (assigned(state)) { + return Boolean.TRUE; + } else { + return Boolean.FALSE; + } + } + + private boolean assigned(final PageState state) { + final CmsTask task = m_task.getTask(state); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowManager workflowManager = cdiUtil.findBean( + WorkflowManager.class); + final Shiro shiro = cdiUtil.findBean(Shiro.class); + + final User user = shiro.getUser(); + + final List tasks = workflowManager.lockedBy(user); + + return tasks.contains(task); + } + + final boolean isAssigned(final PageState state) { + return ((Boolean) get(state)); + } + + } + + } + + private class VisibilityListener implements ActionListener { + + private final TableColumn m_column; + + VisibilityListener(final TableColumn column) { + m_column = column; + } + + @Override + public final void actionPerformed(final ActionEvent event) { + final PageState state = event.getPageState(); + + if (state.isVisibleOnPage(TaskItemPane.this) && !hasAdmin(state)) { + m_column.setVisible(state, false); + } + } + + } + + private class Navigation extends ActionGroup { + + Navigation(final ActionLink backLink) { + addAction(backLink, ActionGroup.RETURN); + } + + } + + private class SummarySection extends Section { + + SummarySection(final ActionLink finishLink, + final ActionLink editLink, + final ActionLink deleteLink) { + setHeading(new Label(gz("cms.ui.workflow.task.details"))); + + final ActionGroup group = new ActionGroup(); + setBody(group); + + group.setSubject(new Properties()); + group.addAction(new AssigneeVisible(new LockLink())); + group.addAction(new AssigneeVisible(new UnlockLink())); + group.addAction(new AssigneeVisible(finishLink)); + group.addAction(new AdminVisible(editLink), ActionGroup.EDIT); + group.addAction(new AdminVisible(deleteLink), ActionGroup.DELETE); + } + + private class LockLink extends ActionLink { + + LockLink() { + super(new Label(gz("cms.ui.workflow.task.lock"))); + + addActionListener(new Listener()); + } + + @Override + public final boolean isVisible(final PageState state) { + + final CmsTask task = m_task.getTask(state); + + return task.isActive() && !task.isLocked(); + } + + private class Listener implements ActionListener { + + @Override + public final void actionPerformed(final ActionEvent event) { + final PageState state = event.getPageState(); + + if (hasAdmin(state)) { + final CmsTask task = m_task.getTask(state); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowManager workflowManager = cdiUtil + .findBean(WorkflowManager.class); + workflowManager.lockTask(task); + } + } + + } + + } + + private class UnlockLink extends ActionLink { + + UnlockLink() { + super(new Label(gz("cms.ui.workflow.task.unlock"))); + + addActionListener(new Listener()); + } + + @Override + public final boolean isVisible(final PageState state) { + final CmsTask task = m_task.getTask(state); + + return task.isActive() && task.isLocked(); + } + + private class Listener implements ActionListener { + + @Override + public final void actionPerformed(final ActionEvent event) { + final PageState state = event.getPageState(); + + if (hasAdmin(state)) { + final CmsTask task = m_task.getTask(state); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowManager workflowManager = cdiUtil + .findBean(WorkflowManager.class); + workflowManager.unlockTask(task); + } + } + + } + + } + + private class Properties extends PropertyList { + + @Override + protected final List properties(final PageState state) { + @SuppressWarnings("unchecked") + final List props = super.properties(state); + final CmsTask task = m_task.getTask(state); + + final KernelConfig kernelConfig = KernelConfig.getConfig(); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); + + props.add(new Property(gz("cms.ui.name"), + task.getLabel().getValue(defaultLocale))); + props.add(new Property(gz("cms.ui.description"), + task.getDescription().getValue( + defaultLocale))); + props.add(new Property(gz("cms.ui.workflow.task.dependencies"), + deps(task))); + props.add(new Property(gz("cms.ui.workflow.task.state"), + task.getTaskState())); + props.add(new Property(gz("cms.ui.workflow.task.locked"), + task.isLocked() + ? lz("cms.ui.yes") : lz("cms.ui.no"))); + + return props; + } + + private String deps(final CmsTask task) { + final List deps = task.getDependsOn(); + final KernelConfig kernelConfig = KernelConfig.getConfig(); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); + final StringJoiner joiner = new StringJoiner(", "); + + deps.forEach(dep -> joiner.add(dep.getLabel().getValue( + defaultLocale))); + + return joiner.toString(); + } + + } + + } + + private class RoleSection extends Section { + + public RoleSection(final ActionLink roleAddLink) { + setHeading(new Label(gz("cms.ui.workflow.task.roles"))); + + final ActionGroup group = new ActionGroup(); + setBody(group); + + group.setSubject(new RoleTable()); + group.addAction(new AdminVisible(roleAddLink), ActionGroup.ADD); + } + + } + + private class RoleTable extends Table { + + public RoleTable() { + super(new RoleTableModelBuilder(m_task), + new String[]{ + lz("cms.ui.name"), // XXX globz + lz("cms.ui.workflow.task.role.delete") + }); + + setEmptyView(new Label(gz("cms.ui.workflow.task.role.none"))); + + getColumn(1).setCellRenderer(new DefaultTableCellRenderer(true)); + + addTableActionListener(new TableActionAdapter() { + + @Override + public final void cellSelected(final TableActionEvent event) { + final PageState state = event.getPageState(); + final int column = event.getColumn(); + + if (column == 1) { + if (hasAdmin(state)) { + final CmsTask task = m_task.getTask(state); + final Long roleId = Long.parseLong((String) event + .getRowKey()); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowManager workflowManager = cdiUtil + .findBean(WorkflowManager.class); + final RoleRepository roleRepo = cdiUtil.findBean( + RoleRepository.class); + + final Role role = roleRepo.findById(roleId); + workflowManager.retractTask(task, role); + } + } + } + + }); + } + + @Override + public final void register(final Page page) { + super.register(page); + + page.addActionListener(new VisibilityListener(getColumn(1))); + } + + } + + private static class RoleTableModelBuilder extends LockableImpl + implements TableModelBuilder { + + private final TaskRequestLocal m_task; + + public RoleTableModelBuilder(final TaskRequestLocal task) { + m_task = task; + } + + @Override + public final TableModel makeModel(final Table table, + final PageState state) { + return new Model(m_task.getTask(state)); + } + + private class Model implements TableModel { + + private final List roles = new ArrayList<>(); + private Role role; + private int index = -1; + + private Model(final CmsTask task) { + task.getAssignments().forEach(assignment -> roles.add( + assignment.getRole())); + } + + @Override + public final int getColumnCount() { + return 2; + } + + @Override + public final boolean nextRow() { + index++; + return index < roles.size(); + } + + @Override + public final Object getKeyAt(final int column) { + return Long.toString(role.getRoleId()); + } + + @Override + public final Object getElementAt(final int column) { + switch (column) { + case 0: + return role.getName(); + case 1: + return lz("cms.ui.workflow.task.role.delete"); + default: + throw new IllegalStateException(); + } + } + + } + + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskRequestLocal.java new file mode 100755 index 000000000..84e285504 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/TaskRequestLocal.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.RequestLocal; +import org.librecms.workflow.CmsTask; +import com.arsdigita.util.Assert; + +public abstract class TaskRequestLocal extends RequestLocal { + + public final CmsTask getTask(final PageState state) { + final CmsTask task = (CmsTask) get(state); + + Assert.exists(task, "CmsTask task"); + + return task; + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAddForm.java new file mode 100755 index 000000000..e88acc074 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAddForm.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SingleSelectionModel; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.cms.CMS; +import com.arsdigita.kernel.KernelConfig; + +import org.librecms.contentsection.ContentSection; +import org.libreccm.workflow.WorkflowTemplate; +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.configuration.ConfigurationManager; +import org.libreccm.workflow.WorkflowTemplateRepository; +import org.librecms.contentsection.ContentSectionManager; + +import java.util.Locale; + +/** + * @author Jens Pelzetter + * @author Uday Mathur + * @author Michael Pih + * @author Justin Ross + */ +class WorkflowAddForm extends BaseWorkflowForm { + + private final SingleSelectionModel m_model; + + WorkflowAddForm(final SingleSelectionModel model) { + super("workflow", gz("cms.ui.workflow.add")); + + m_model = model; + + addProcessListener(new ProcessListener()); + } + + private class ProcessListener implements FormProcessListener { + + @Override + public final void process(final FormSectionEvent event) + throws FormProcessException { + final PageState state = event.getPageState(); + + final String label = (String) m_title.getValue(state); + final String description = (String) m_description.getValue(state); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowTemplateRepository workflowTemplateRepository = cdiUtil.findBean( + WorkflowTemplateRepository.class); + final ContentSectionManager sectionManager = cdiUtil.findBean( + ContentSectionManager.class); + final ConfigurationManager confManager = cdiUtil.findBean(ConfigurationManager.class); + final KernelConfig kernelConfig = confManager.findConfiguration( + KernelConfig.class); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); + + final WorkflowTemplate workflow = new WorkflowTemplate(); + workflow.getName().addValue(defaultLocale, label); + workflow.getDescription().addValue(defaultLocale, description); + + workflowTemplateRepository.save(workflow); + + final ContentSection section = + CMS.getContext().getContentSection(); + sectionManager.addWorkflowTemplateToContentSection(workflow, section); + + m_model.setSelectedKey(state, workflow.getWorkflowId()); + } + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAdminPane.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAdminPane.java.off index cb251c487..c4d0d42c7 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAdminPane.java.off +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowAdminPane.java.off @@ -22,24 +22,21 @@ import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.ui.BaseAdminPane; import com.arsdigita.cms.ui.BaseDeleteForm; import com.arsdigita.cms.ui.VisibilityComponent; -import com.arsdigita.workflow.simple.WorkflowTemplate; -import org.apache.log4j.Logger; + +import org.libreccm.workflow.WorkflowTemplate; +import org.librecms.CmsConstants; import java.math.BigDecimal; /** - * @author Justin Ross <jross@redhat.com> - * @version $Id: WorkflowAdminPane.java 287 2005-02-22 00:29:02Z sskracic $ + * @author Jens Pelzetter + * @author Justin Ross */ public final class WorkflowAdminPane extends BaseAdminPane { - private static final Logger s_log = Logger.getLogger - (WorkflowAdminPane.class); - private final WorkflowRequestLocal m_workflow; public WorkflowAdminPane() { @@ -57,33 +54,39 @@ public final class WorkflowAdminPane extends BaseAdminPane { getEditLink(), getDeleteLink())); - addAction(new VisibilityComponent(getAddLink(), - SecurityManager.WORKFLOW_ADMIN)); + addAction(new VisibilityComponent( + getAddLink(), CmsConstants.PRIVILEGE_ADMINISTER_WORKFLOW)); } private class DeleteForm extends BaseDeleteForm { + DeleteForm() { super(gz("cms.ui.workflow.delete_prompt")); - addSecurityListener(SecurityManager.WORKFLOW_ADMIN); + addSecurityListener(CmsConstants.PRIVILEGE_ADMINISTER_WORKFLOW); } + @Override public final void process(final FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { final PageState state = e.getPageState(); m_workflow.getWorkflow(state).delete(); getSelectionModel().clearSelection(state); } + } private class SelectionRequestLocal extends WorkflowRequestLocal { + protected final Object initialValue(final PageState state) { - final String id = getSelectionModel().getSelectedKey - (state).toString(); + final String id = getSelectionModel().getSelectedKey(state) + .toString(); return new WorkflowTemplate(new BigDecimal(id)); } + } + } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowEditForm.java new file mode 100755 index 000000000..20b099a25 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowEditForm.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.kernel.KernelConfig; + +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.configuration.ConfigurationManager; +import org.libreccm.workflow.Workflow; +import org.libreccm.workflow.WorkflowRepository; + +import java.util.Locale; + +/** + * @author Jens Pelzetter + * @author Uday Mathur + * @author Justin Ross + */ +class WorkflowEditForm extends BaseWorkflowForm { + + private final WorkflowRequestLocal m_workflow; + + WorkflowEditForm(final WorkflowRequestLocal workflow) { + super("workflow", gz("cms.ui.workflow.edit")); + + m_workflow = workflow; + + addInitListener(new InitListener()); + addProcessListener(new ProcessListener()); + } + + private class ProcessListener implements FormProcessListener { + + @Override + public final void process(final FormSectionEvent event) + throws FormProcessException { + + final PageState state = event.getPageState(); + final Workflow workflow = m_workflow.getWorkflow(state); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final WorkflowRepository workflowRepo = cdiUtil.findBean( + WorkflowRepository.class); + final ConfigurationManager confManager = cdiUtil.findBean( + ConfigurationManager.class); + final KernelConfig kernelConfig = confManager.findConfiguration( + KernelConfig.class); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); + + workflow.getName().addValue(defaultLocale, + (String) m_title.getValue(state)); + workflow.getDescription().addValue( + defaultLocale, + (String) m_description.getValue(state)); + + workflowRepo.save(workflow); + } + + } + + private class InitListener implements FormInitListener { + + @Override + public final void init(final FormSectionEvent event) { + final PageState state = event.getPageState(); + final Workflow workflow = m_workflow.getWorkflow(state); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ConfigurationManager confManager = cdiUtil.findBean( + ConfigurationManager.class); + final KernelConfig kernelConfig = confManager.findConfiguration( + KernelConfig.class); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); + + m_title.setValue(state, workflow.getName().getValue(defaultLocale)); + m_description.setValue(state, workflow.getDescription()); + } + + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowItemPane.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowItemPane.java.off new file mode 100755 index 000000000..c21349ba0 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowItemPane.java.off @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.ActionLink; + +class WorkflowItemPane extends BaseWorkflowItemPane { + + public WorkflowItemPane(final WorkflowRequestLocal workflow, + final ActionLink editLink, + final ActionLink deleteLink) { + super(workflow, editLink, deleteLink); + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowListModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowListModelBuilder.java new file mode 100755 index 000000000..cdcd7b56b --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowListModelBuilder.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.List; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.list.AbstractListModelBuilder; +import com.arsdigita.bebop.list.ListModel; +import com.arsdigita.cms.CMS; +import com.arsdigita.kernel.KernelConfig; + +import org.librecms.contentsection.ContentSection; +import org.libreccm.workflow.WorkflowTemplate; +import org.libreccm.workflow.Task; + +import java.util.Locale; + +/** + * Builds a list of workflow templates registered to the current content + * section. + * + * @author Jens Pelzetter + * @author Michael Pih + * @author Justin Ross + */ +class WorkflowListModelBuilder extends AbstractListModelBuilder { + + @Override + public final ListModel makeModel(final List list, final PageState state) { + return new Model(); + } + + private class Model implements ListModel { + + private final java.util.List templates; + private int index = -1; + + public Model() { + final ContentSection section = CMS.getContext().getContentSection(); + + templates = section.getWorkflowTemplates(); + } + + @Override + public boolean next() { + index++; + return index < templates.size(); + } + + @Override + public Object getElement() { + final KernelConfig kernelConfig = KernelConfig.getConfig(); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); + return templates.get(index).getName().getValue(defaultLocale); + } + + @Override + public String getKey() { + return Long.toString(templates.get(index).getWorkflowId()); + } + + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowRequestLocal.java new file mode 100755 index 000000000..95f8faf5f --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/workflow/WorkflowRequestLocal.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.ui.workflow; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.RequestLocal; +import org.libreccm.workflow.Workflow; + +public abstract class WorkflowRequestLocal extends RequestLocal { + + public final Workflow getWorkflow(final PageState state) { + return (Workflow) get(state); + } +} diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java index 6de79ff27..a409c8c06 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java @@ -199,7 +199,7 @@ public class ContentItemManager { KernelConfig.class); item.setDisplayName(name); - item.getName().addValue(new Locale(kernelConfig.getDefaultLanguage()), + item.getName().addValue(kernelConfig.getDefaultLocale(), name); item.setLifecycle(lifecycle); item.setWorkflow(workflow); diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java index 86b72dae0..654ed059a 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java @@ -31,6 +31,7 @@ import org.libreccm.security.PermissionManager; import org.libreccm.security.RequiresPrivilege; import org.libreccm.security.Role; import org.libreccm.security.RoleRepository; +import org.libreccm.workflow.WorkflowTemplate; import java.util.List; import java.util.Locale; @@ -41,6 +42,7 @@ import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import javax.transaction.Transactional; + import org.librecms.lifecycle.LifecycleDefinition; import static org.librecms.CmsConstants.*; @@ -87,13 +89,12 @@ public class ContentSectionManager { public ContentSection createContentSection(final String name) { if (name == null || name.isEmpty()) { throw new IllegalArgumentException( - "The name of a ContentSection can't be blank."); + "The name of a ContentSection can't be blank."); } final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); - final Locale defautLocale - = new Locale(kernelConfig.getDefaultLanguage()); + KernelConfig.class); + final Locale defautLocale = kernelConfig.getDefaultLocale(); final ContentSection section = new ContentSection(); section.setLabel(name); @@ -233,12 +234,12 @@ public class ContentSectionManager { @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @Transactional(Transactional.TxType.REQUIRED) public void removeRoleFromContentSection( - final ContentSection contentSection, - final Role role) { + final ContentSection contentSection, + final Role role) { if (contentSection == null) { throw new IllegalArgumentException( - "Can't remove role from ContentSection null"); + "Can't remove role from ContentSection null"); } if (role == null) { @@ -249,8 +250,8 @@ public class ContentSectionManager { sectionRepo.save(contentSection); final TypedQuery query = entityManager - .createNamedQuery("ContentSection.findPermissions", - Permission.class); + .createNamedQuery("ContentSection.findPermissions", + Permission.class); query.setParameter("section", contentSection); query.setParameter("rootDocumentsFolder", contentSection.getRootDocumentsFolder()); @@ -280,8 +281,8 @@ public class ContentSectionManager { @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @Transactional(Transactional.TxType.REQUIRED) public void addLifecycleDefinitionToContentSection( - final LifecycleDefinition definition, - final ContentSection section) { + final LifecycleDefinition definition, + final ContentSection section) { throw new UnsupportedOperationException(); } @@ -289,8 +290,8 @@ public class ContentSectionManager { @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @Transactional(Transactional.TxType.REQUIRED) public void removeLifecycleDefinitionFromContentSection( - final LifecycleDefinition definition, - final ContentSection contentSection) { + final LifecycleDefinition definition, + final ContentSection contentSection) { throw new UnsupportedOperationException(); } @@ -298,8 +299,8 @@ public class ContentSectionManager { @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @Transactional(Transactional.TxType.REQUIRED) public void addWorkflowTemplateToContentSection( - final LifecycleDefinition definition, - final ContentSection section) { + final WorkflowTemplate definition, + final ContentSection section) { throw new UnsupportedOperationException(); } @@ -308,15 +309,16 @@ public class ContentSectionManager { @Transactional(Transactional.TxType.REQUIRED) public void removeWorkflowTemplateFromContentSection( - final LifecycleDefinition definition, - final ContentSection contentSection) { + final LifecycleDefinition definition, + final ContentSection contentSection) { throw new UnsupportedOperationException(); } public ItemResolver getItemResolver(final ContentSection section) { try { - final Class itemResolverClazz = (Class) Class. - forName(section.getItemResolverClass()); + final Class itemResolverClazz + = (Class) Class. + forName(section.getItemResolverClass()); return itemResolverClazz.newInstance(); } catch (ClassNotFoundException | IllegalAccessException | diff --git a/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java b/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java index 1b9b05e78..1e819ce46 100644 --- a/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java +++ b/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java @@ -29,6 +29,7 @@ import org.libreccm.configuration.Configuration; import org.libreccm.configuration.ConfigurationManager; import org.libreccm.configuration.Setting; +import java.util.Locale; import java.util.stream.Collectors; /** @@ -199,6 +200,10 @@ public final class KernelConfig { this.defaultLanguage = defaultLanguage; } + public Locale getDefaultLocale() { + return new Locale(getDefaultLanguage()); + } + public String getSystemEmailAddress() { return systemEmailAddress; } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInstanceTreeNode.java b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInstanceTreeNode.java index 05288a156..683ffe322 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInstanceTreeNode.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/admin/applications/ApplicationInstanceTreeNode.java @@ -35,7 +35,7 @@ import java.util.Locale; public class ApplicationInstanceTreeNode implements TreeNode { protected static final String INSTANCE_NODE_KEY_PREFIX = "appinstance_"; - + private final CcmApplication application; public ApplicationInstanceTreeNode(final CcmApplication application) { @@ -45,7 +45,7 @@ public class ApplicationInstanceTreeNode implements TreeNode { @Override public Object getKey() { return String.format("%s%d", - INSTANCE_NODE_KEY_PREFIX, + INSTANCE_NODE_KEY_PREFIX, application.getObjectId()); } @@ -57,8 +57,7 @@ public class ApplicationInstanceTreeNode implements TreeNode { .findBean(ConfigurationManager.class); final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); final String title; if (application.getTitle().hasValue(globalizationHelper diff --git a/ccm-core/src/main/java/org/libreccm/l10n/GlobalizationHelper.java b/ccm-core/src/main/java/org/libreccm/l10n/GlobalizationHelper.java index f216636dc..22c7b02aa 100644 --- a/ccm-core/src/main/java/org/libreccm/l10n/GlobalizationHelper.java +++ b/ccm-core/src/main/java/org/libreccm/l10n/GlobalizationHelper.java @@ -81,7 +81,7 @@ public class GlobalizationHelper { final KernelConfig kernelConfig = confManager.findConfiguration( KernelConfig.class); - Locale preferred = new Locale(kernelConfig.getDefaultLanguage()); + Locale preferred = kernelConfig.getDefaultLocale(); final Locale selectedLocale = getSelectedLocale(); if (selectedLocale == null || !kernelConfig.hasLanguage(selectedLocale diff --git a/ccm-core/src/main/java/org/libreccm/security/ChallengeManager.java b/ccm-core/src/main/java/org/libreccm/security/ChallengeManager.java index c458cee4a..81f82e6c2 100644 --- a/ccm-core/src/main/java/org/libreccm/security/ChallengeManager.java +++ b/ccm-core/src/main/java/org/libreccm/security/ChallengeManager.java @@ -401,8 +401,7 @@ public class ChallengeManager { } else { final KernelConfig kernelConfig = configurationManager .findConfiguration(KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale =kernelConfig.getDefaultLocale(); return localizedString.getValue(defaultLocale); } } @@ -444,8 +443,7 @@ public class ChallengeManager { } else { final KernelConfig kernelConfig = configurationManager .findConfiguration(KernelConfig.class); - final Locale defaultLocale = new Locale(kernelConfig - .getDefaultLanguage()); + final Locale defaultLocale = kernelConfig.getDefaultLocale(); return localizedString.getValue(defaultLocale); } }