forked from geonetwork/core-geonetwork
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into xslt-escape-json-apache-commons-text
- Loading branch information
Showing
71 changed files
with
935 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
@@ -38,14 +34,27 @@ | |
public class WorkflowUtil { | ||
|
||
/** | ||
* Checks if a group has the workflow enabled. | ||
* Avoid creation of new instances of this utility class making its constructor private. | ||
*/ | ||
private WorkflowUtil() { | ||
|
||
} | ||
|
||
/** | ||
* Checks if the workflow is enabled and a group has the workflow enabled. | ||
* | ||
* @param groupName Group name | ||
* @return | ||
* @return {@code true} if the workflow is enabled and it has been enabled for all groups or the group name matches | ||
* the regular expression in {@link Settings#METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP}. False otherwise. | ||
*/ | ||
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 +65,4 @@ public static boolean isGroupWithEnabledWorkflow(String groupName) { | |
return false; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
core/src/test/java/org/fao/geonet/util/WorkflowUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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; | ||
|
||
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.*; | ||
|
||
public class WorkflowUtilTest extends AbstractCoreIntegrationTest { | ||
@Autowired | ||
SettingManager settingManager; | ||
|
||
@Test | ||
public void testWorkflowDisabled() { | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, false); | ||
assertFalse(WorkflowUtil.isGroupWithEnabledWorkflow("sample")); | ||
} | ||
|
||
@Test | ||
public void testWorkflowDisabledAndEnabledAllGroups() { | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, false); | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, ".*"); | ||
assertFalse(WorkflowUtil.isGroupWithEnabledWorkflow("sample")); | ||
} | ||
|
||
@Test | ||
public void testWorkflowDisabledAndEnabledInGroupList() { | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, false); | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, "sample|test"); | ||
assertFalse(WorkflowUtil.isGroupWithEnabledWorkflow("sample")); | ||
|
||
settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, "sam*|test"); | ||
assertFalse(WorkflowUtil.isGroupWithEnabledWorkflow("sample")); | ||
} | ||
|
||
@Test | ||
public void testWorkflowEnabledAllGroups() { | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, true); | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, ".*"); | ||
assertTrue(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"); | ||
assertTrue(WorkflowUtil.isGroupWithEnabledWorkflow("sample")); | ||
|
||
settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, "sam*|test"); | ||
assertTrue(WorkflowUtil.isGroupWithEnabledWorkflow("sample")); | ||
} | ||
|
||
@Test | ||
public void testWorkflowEnabledNotInGroupList() { | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_ENABLE, true); | ||
settingManager.setValue(Settings.METADATA_WORKFLOW_DRAFT_WHEN_IN_GROUP, "test"); | ||
assertFalse(WorkflowUtil.isGroupWithEnabledWorkflow("sample")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.