Skip to content

Commit

Permalink
Fix check to verify if a group has enabled the workflow, checking if …
Browse files Browse the repository at this point in the history
…the workflow is also enabled
  • Loading branch information
josegar74 committed Dec 5, 2023
1 parent d7c60e3 commit 886ea73
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 30 deletions.
60 changes: 30 additions & 30 deletions core/src/main/java/org/fao/geonet/util/WorkflowUtil.java
Original file line number Diff line number Diff line change
@@ -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: [email protected]
//=============================================================================
/*
* 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: [email protected]
*/

package org.fao.geonet.util;

Expand All @@ -37,15 +33,22 @@

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
*/
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)) {
Expand All @@ -56,7 +59,4 @@ public static boolean isGroupWithEnabledWorkflow(String groupName) {
return false;
}
}



}
44 changes: 44 additions & 0 deletions core/src/test/java/org/fao/geonet/util/WorkflowUtilTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit 886ea73

Please sign in to comment.