Skip to content

Commit

Permalink
Merge branch 'main' into xslt-escape-json-apache-commons-text
Browse files Browse the repository at this point in the history
  • Loading branch information
josegar74 authored Dec 6, 2023
2 parents 5304ff9 + c8eb905 commit 5cffdb5
Show file tree
Hide file tree
Showing 71 changed files with 935 additions and 708 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Thank you for contributing to GeoNetwork:

* Good housekeeping: Anytime you commit, try and clean the code around it to latest style guide. If you improve a function without comments: add comments. If you modify functionality that does not have tests: write a test. If you fix functionality without documentation: add documentation.

* History: Clean commit messages and history: avoid big commits with hundreds of files, break commits up into understandable chunks, longer verbose commit messages are encouraged. Beware of reformatting and needless whitespace changes.
* History: Clean commit messages and history: avoid big commits with hundreds of files, break commits up into understandable chunks, longer verbose commit messages are encouraged. Avoid reformatting and needless whitespace changes.

* Draft: Use pull request *Draft** (or even the text "WIP") to identify work in progress.

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GeoNetwork Open-source
# GeoNetwork opensource

## Build Health

Expand All @@ -11,13 +11,13 @@
* An interactive Web Map Viewer to combine Web Map Services from distributed servers around the world
* Online editing of metadata with a powerful template system
* Scheduled harvesting and synchronization of metadata between distributed catalogs
* Support for OGC-CSW 2.0.2 ISO Profile, OAI-PMH, SRU protocols
* Support for OGC-CSW 2.0.2, ISO 1911x and DCAT-AP metadata profiles, OAI-PMH, SRU protocols
* Fine-grained access control with group and user management
* Multi-lingual user interface

## Documentation

The Geonetwork Manual and Online Help are included in the `docs/manual` folder. This content is compiled into html pages during a release for a publishing on docs.geonetwork-opensource.org website.
The GeoNetwork Manual and Online Help are included in the `docs/manual` folder. This content is compiled into html pages during a release for a publishing on docs.geonetwork-opensource.org website.

* [docs.geonetwork-opensource.org](https://docs.geonetwork-opensource.org)

Expand All @@ -28,5 +28,5 @@ The online help is compiled into html pages during a release and is included in
Developer documentation located in ``README.md`` files in the code-base:

* General documentation for the project as a whole is in this [README.md](README.md)
* [Software Development Documentation](/software_development/) provides instructions for setting up a development environment, building Geonetwork, compiling user documentation, and making a releases.
* [Software Development Documentation](/software_development/) provides instructions for setting up a development environment, building GeoNetwork, compiling user documentation, and making a releases.
* Module specific documentation can be found in each module:
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@
<artifactId>gn-schema-iso19139</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.geonetwork-opensource.schemas</groupId>
<artifactId>gn-schema-iso19115-3.2018</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency> <!-- dummy API for ARC SDE stuff -->
<groupId>${project.groupId}</groupId>
<artifactId>gn-dummy-api</artifactId>
Expand Down
68 changes: 37 additions & 31 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 @@ -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)) {
Expand All @@ -56,7 +65,4 @@ public static boolean isGroupWithEnabledWorkflow(String groupName) {
return false;
}
}



}
54 changes: 52 additions & 2 deletions core/src/test/java/org/fao/geonet/AbstractCoreIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import jeeves.server.dispatchers.ServiceManager;
import jeeves.server.sources.ServiceRequest;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.domain.AbstractMetadata;
import org.fao.geonet.domain.ISODate;
import org.fao.geonet.domain.Metadata;
import org.fao.geonet.domain.MetadataType;
import org.fao.geonet.domain.Pair;
import org.fao.geonet.domain.Profile;
Expand All @@ -41,13 +43,19 @@
import org.fao.geonet.domain.User;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.GeonetworkDataDirectory;
import org.fao.geonet.kernel.SchemaManager;
import org.fao.geonet.kernel.UpdateDatestamp;
import org.fao.geonet.kernel.datamanager.IMetadataManager;
import org.fao.geonet.kernel.mef.Importer;
import org.fao.geonet.kernel.mef.MEFLib;
import org.fao.geonet.kernel.search.IndexingMode;
import org.fao.geonet.repository.AbstractSpringDataTest;
import org.fao.geonet.repository.GroupRepository;
import org.fao.geonet.repository.SourceRepository;
import org.fao.geonet.repository.UserGroupRepository;
import org.fao.geonet.repository.UserRepository;
import org.fao.geonet.schema.iso19115_3_2018.ISO19115_3_2018SchemaPlugin;
import org.fao.geonet.schema.iso19139.ISO19139SchemaPlugin;
import org.fao.geonet.utils.Log;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
Expand Down Expand Up @@ -79,6 +87,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static java.lang.Math.round;
Expand Down Expand Up @@ -109,6 +118,12 @@ public abstract class AbstractCoreIntegrationTest extends AbstractSpringDataTest
protected UserGroupRepository _userGroupRepo;
@Autowired
protected GroupRepository _groupRepo;
@Autowired
private SchemaManager schemaManager;
@Autowired
private IMetadataManager metadataManager;
@Autowired
private SourceRepository sourceRepository;

protected static Element createServiceConfigParam(String name, String value) {
return new Element("param")
Expand Down Expand Up @@ -293,8 +308,7 @@ public MockHttpSession loginAsAnonymous() {
return session;
}


private static Element getSample(String resource) throws IOException, JDOMException {
private Element getSample(String resource) throws IOException, JDOMException {
final URL resourceUrl = AbstractCoreIntegrationTest.class.getResource(resource);
return Xml.loadStream(resourceUrl.openStream());
}
Expand Down Expand Up @@ -371,4 +385,40 @@ protected void addTestSpecificData(GeonetworkDataDirectory geonetworkDataDirecto
public boolean resetLuceneIndex() {
return true;
}

protected AbstractMetadata injectMetadataInDbDoNotRefreshHeader(Element sampleMetadataXml, ServiceContext context) throws Exception {
return injectMetadataInDb(sampleMetadataXml, context, false);
}

protected AbstractMetadata injectMetadataInDb(Element sampleMetadataXml, ServiceContext context, boolean resfreshHeader) throws Exception {
String uuid = UUID.randomUUID().toString();
String schema = schemaManager.autodetectSchema(sampleMetadataXml);
Xml.selectElement(sampleMetadataXml,
"iso19139".equals(schema)
? "gmd:fileIdentifier/gco:CharacterString"
: "mdb:metadataIdentifier/*/mcc:code/*",
"iso19139".equals(schema)
? ISO19139SchemaPlugin.allNamespaces.asList()
: ISO19115_3_2018SchemaPlugin.allNamespaces.asList())
.setText(uuid);

String source = sourceRepository.findAll().get(0).getUuid();
final Metadata metadata = new Metadata();
metadata
.setDataAndFixCR(sampleMetadataXml)
.setUuid(uuid);
metadata.getDataInfo()
.setRoot(sampleMetadataXml.getQualifiedName())
.setSchemaId(schema)
.setType(MetadataType.METADATA)
.setPopularity(1000);
metadata.getSourceInfo()
.setOwner(1)
.setSourceId(source);
metadata.getHarvestInfo()
.setHarvested(false);

return metadataManager.insertMetadata(context, metadata, sampleMetadataXml, IndexingMode.none, false, UpdateDatestamp.NO,
false, resfreshHeader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;
import org.fao.geonet.AbstractCoreIntegrationTest;
import org.fao.geonet.constants.Geonet;
Expand All @@ -40,11 +39,9 @@
import org.fao.geonet.domain.Source;
import org.fao.geonet.domain.SourceType;
import org.fao.geonet.domain.User;
import org.fao.geonet.kernel.datamanager.IMetadataManager;
import org.fao.geonet.kernel.search.EsSearchManager;
import org.fao.geonet.kernel.search.IndexingMode;
import org.fao.geonet.repository.GroupRepository;
import org.fao.geonet.repository.MetadataCategoryRepository;
import org.fao.geonet.repository.SourceRepository;
import org.fao.geonet.repository.specification.MetadataSpecs;
import org.fao.geonet.utils.Xml;
Expand Down Expand Up @@ -76,24 +73,12 @@ public class DataManagerIntegrationTest extends AbstractDataManagerIntegrationTe
public void testDeleteMetadata() throws Exception {
ServiceContext serviceContext = createContextAndLogAsAdmin();
long count = metadataRepository.count();
String mdId = dataManager.insertMetadata(
serviceContext,
"iso19139",
new Element("MD_Metadata"),
"uuid",
serviceContext.getUserSession().getUserIdAsInt(),
"" + ReservedGroup.all.getId(),
"sourceid",
"n",
"doctype",
null,
new ISODate().getDateAndTime(),
new ISODate().getDateAndTime(),
false,
IndexingMode.none);

int mdId = injectMetadataInDbDoNotRefreshHeader(getSampleMetadataXml(), serviceContext).getId();

assertEquals(count + 1, metadataRepository.count());

metadataManager.deleteMetadata(serviceContext, mdId);
metadataManager.deleteMetadata(serviceContext, String.valueOf(mdId));

assertEquals(count, metadataRepository.count());
}
Expand Down
84 changes: 84 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,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"));
}
}
2 changes: 1 addition & 1 deletion domain/src/main/java/org/fao/geonet/domain/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public Group setId(int id) {
*
* @return group name
*/
@Column(nullable = false, length = 32)
@Column(nullable = false, length = 255)
public String getName() {
return _name;
}
Expand Down
Loading

0 comments on commit 5cffdb5

Please sign in to comment.