diff --git a/core/src/main/java/org/fao/geonet/util/WorkflowUtil.java b/core/src/main/java/org/fao/geonet/util/WorkflowUtil.java index 123b455919b8..10f61f28a7db 100644 --- a/core/src/main/java/org/fao/geonet/util/WorkflowUtil.java +++ b/core/src/main/java/org/fao/geonet/util/WorkflowUtil.java @@ -1,29 +1,25 @@ -//============================================================================= -//=== -//=== ThreadUtils -//=== -//============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the -//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) -//=== and United Nations Environment Programme (UNEP) -//=== -//=== This program is free software; you can redistribute it and/or modify -//=== it under the terms of the GNU General Public License as published by -//=== the Free Software Foundation; either version 2 of the License, or (at -//=== your option) any later version. -//=== -//=== This program 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 -//=== General Public License for more details. -//=== -//=== You should have received a copy of the GNU General Public License -//=== along with this program; if not, write to the Free Software -//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -//=== -//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, -//=== Rome - Italy. email: geonetwork@osgeo.org -//============================================================================= +/* + * Copyright (C) 2001-2023 Food and Agriculture Organization of the + * United Nations (FAO-UN), United Nations World Food Programme (WFP) + * and United Nations Environment Programme (UNEP) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, + * Rome - Italy. email: geonetwork@osgeo.org + */ package org.fao.geonet.util; @@ -37,8 +33,12 @@ public class WorkflowUtil { + private WorkflowUtil() { + + } + /** - * Checks if a group has the workflow enabled. + * Checks if the workflow is enabled and a group has the workflow enabled. * * @param groupName Group name * @return @@ -46,6 +46,9 @@ public class WorkflowUtil { public static boolean isGroupWithEnabledWorkflow(String groupName) { SettingManager settingManager = ApplicationContextHolder.get().getBean(SettingManager.class); + boolean isWorkflowEnabled = settingManager.getValueAsBool(Settings.METADATA_WORKFLOW_ENABLE); + if (!isWorkflowEnabled) return false; + String groupMatchingRegex = settingManager.getValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP); if (!StringUtils.isEmpty(groupMatchingRegex)) { @@ -56,7 +59,4 @@ public static boolean isGroupWithEnabledWorkflow(String groupName) { return false; } } - - - } diff --git a/core/src/test/java/org/fao/geonet/util/WorkflowUtilTest.java b/core/src/test/java/org/fao/geonet/util/WorkflowUtilTest.java new file mode 100644 index 000000000000..8e45936e4866 --- /dev/null +++ b/core/src/test/java/org/fao/geonet/util/WorkflowUtilTest.java @@ -0,0 +1,44 @@ +package org.fao.geonet.util; + +import org.fao.geonet.AbstractCoreIntegrationTest; +import org.fao.geonet.kernel.setting.SettingManager; +import org.fao.geonet.kernel.setting.Settings; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.Assert.assertEquals; + +public class WorkflowUtilTest extends AbstractCoreIntegrationTest { + @Autowired + SettingManager settingManager; + + @Test + public void testWorkflowDisabled() { + settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, false); + assertEquals(false, WorkflowUtil.isGroupWithEnabledWorkflow("sample")); + } + + @Test + public void testWorkflowEnabledAllGroups() { + settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, true); + settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, ".*"); + assertEquals(true, WorkflowUtil.isGroupWithEnabledWorkflow("sample")); + } + + @Test + public void testWorkflowEnabledInGroupList() { + settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, true); + settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, "sample|test"); + assertEquals(true, WorkflowUtil.isGroupWithEnabledWorkflow("sample")); + + settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, "sam*|test"); + assertEquals(true, WorkflowUtil.isGroupWithEnabledWorkflow("sample")); + } + + @Test + public void testWorkflowEnabledNotInGroupList() { + settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, true); + settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, "test"); + assertEquals(false, WorkflowUtil.isGroupWithEnabledWorkflow("sample")); + } +}