Skip to content

Commit

Permalink
Merge branch 'geonetwork:main' into 44-libupdates-20240627
Browse files Browse the repository at this point in the history
  • Loading branch information
josegar74 authored Oct 17, 2024
2 parents 312405e + 5b01f64 commit b1d8f1b
Show file tree
Hide file tree
Showing 368 changed files with 45,386 additions and 2,870 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ web/src/main/webapp/META-INF/MANIFEST.MF
web/src/main/webapp/WEB-INF/data/0*
web/src/main/webapp/WEB-INF/data/config/encryptor.properties
web/src/main/webapp/WEB-INF/data/config/index/records.json
web/src/main/webapp/WEB-INF/data/config/schema_plugins/*/schematron/schematron*.xsl
web/src/main/webapp/WEB-INF/data/config/schema_plugins/csw-record
web/src/main/webapp/WEB-INF/data/config/schema_plugins/dublin-core
web/src/main/webapp/WEB-INF/data/config/schema_plugins/iso19*
web/src/main/webapp/WEB-INF/data/config/schema_plugins/schemaplugin-uri-catalog.xml
web/src/main/webapp/WEB-INF/data/config/schema_plugins/*
web/src/main/webapp/WEB-INF/data/config/schemaplugin-uri-catalog.xml
web/src/main/webapp/WEB-INF/data/data/backup
web/src/main/webapp/WEB-INF/data/data/metadata_data
Expand Down
88 changes: 88 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: GeoNetwork opensource
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: François
family-names: Prunayre
affiliation: Titellus
- given-names: Jose
family-names: García
affiliation: GeoCat BV
- given-names: Jeroen
family-names: Ticheler
affiliation: GeoCat BV
orcid: 'https://orcid.org/0009-0003-3896-0437'
email: [email protected]
- given-names: Florent
family-names: Gravin
affiliation: CamptoCamp
- given-names: Simon
family-names: Pigot
affiliation: CSIRO Australia
- name: GeoCat BV
address: Veenderweg 13
city: Bennekom
country: NL
post-code: 6721 WD
tel: +31 (0) 318 416 664
website: 'https://www.geocat.net/'
email: [email protected]
- name: Titellus
address: 321 Route de la Mollière
city: Saint Pierre de Genebroz
country: FR
post-code: 73360
website: 'https://titellus.net/'
email: [email protected]
- name: CamptoCamp
address: QG Center Rte de la Chaux 4
city: Bussigny
country: CH
post-code: 1030
tel: +41 (21) 619 10 10
website: 'https://camptocamp.com/'
email: [email protected]
- name: Open Source Geospatial Foundation - OSGeo
address: '9450 SW Gemini Dr. #42523'
location: Beaverton
region: Oregon
post-code: '97008'
country: US
email: [email protected]
website: 'https://www.osgeo.org/'
repository-code: 'http://github.com/geonetwork/core-geonetwork'
url: 'https://geonetwork-opensource.org'
repository-artifact: >-
https://sourceforge.net/projects/geonetwork/files/GeoNetwork_opensource/
abstract: >-
GeoNetwork is a catalog application to manage spatial and
non-spatial resources. It is compliant with critical
international standards from ISO, OGC and INSPIRE. It
provides powerful metadata editing and search functions as
well as an interactive web map viewer.
keywords:
- catalog
- gis
- sdi
- spatial data infrastructure
- dataspace
- search
- open data
- standards
- spatial
- CSW
- OGCAPI Records
- DCAT
- GeoDCAT-AP
- Catalog Service
- OGC
- open geospatial consortium
- osgeo
- open source geospatial foundation
license: GPL-2.0
10 changes: 5 additions & 5 deletions add-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ then
${insertLine} a\\
\ <dependency>\\
\ <groupId>org.geonetwork-opensource.schemas</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <artifactId>gn-schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ </dependency>
SED_SCRIPT
Expand All @@ -103,7 +103,7 @@ SED_SCRIPT
\ <dependencies>\\
\ <dependency>\\
\ <groupId>org.geonetwork-opensource.schemas</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <artifactId>gn-schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ </dependency>\\
\ </dependencies>\\
Expand All @@ -121,7 +121,7 @@ SED_SCRIPT
\ <artifactItems>\\
\ <artifactItem>\\
\ <groupId>org.geonetwork-opensource.schemas</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <artifactId>gn-schema-${schema}</artifactId>\\
\ <type>zip</type>\\
\ <overWrite>false</overWrite>\\
\ <outputDirectory>\$\{schema-plugins.dir\}</outputDirectory>\\
Expand All @@ -138,7 +138,7 @@ SED_SCRIPT
fi

# Add schema resources in service/pom.xml with test scope for unit tests
line=$(grep -n "<artifactId>schema-${schema}</artifactId>" services/pom.xml | cut -d: -f1)
line=$(grep -n "<artifactId>gn-schema-${schema}</artifactId>" services/pom.xml | cut -d: -f1)

if [ ! $line ]
then
Expand All @@ -154,7 +154,7 @@ then
${finalLine} a\\
\ <dependency>\\
\ <groupId>${projectGroupId}</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <artifactId>gn-schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ <scope>test</scope>\\
\ </dependency>
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/org/fao/geonet/utils/XmlRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2016 Food and Agriculture Organization of the
* Copyright (C) 2001-2024 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
Expand Down Expand Up @@ -124,13 +124,13 @@ protected final Element executeAndReadResponse(HttpRequestBase httpMethod) throw
" -- Response Code: " + httpResponse.getRawStatusCode());
}

byte[] data = null;
byte[] data;

try {
data = IOUtils.toByteArray(httpResponse.getBody());
return Xml.loadStream(new ByteArrayInputStream(data));
} catch (JDOMException e) {
throw new BadXmlResponseEx("Response: '" + new String(data, "UTF8") + "' (from URI " + httpMethod.getURI() + ")");
throw new BadXmlResponseEx("Invalid XML document from URI: " + httpMethod.getURI());
} finally {
httpMethod.releaseConnection();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* =============================================================================
* === Copyright (C) 2019 Food and Agriculture Organization of the
* === Copyright (C) 2024 Food and Agriculture Organization of the
* === United Nations (FAO-UN), United Nations World Food Programme (WFP)
* === and United Nations Environment Programme (UNEP)
* ===
Expand Down Expand Up @@ -44,12 +44,16 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public abstract class AbstractStore implements Store {
protected static final String RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_SEPARATOR = ":";
protected static final String RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_ESCAPED_SEPARATOR = "\\:";

@Override
public final List<MetadataResource> getResources(final ServiceContext context, final String metadataUuid, final Sort sort,
final String filter) throws Exception {
Expand Down Expand Up @@ -279,4 +283,28 @@ public String toString() {
}
};
}

private String escapeResourceManagementExternalProperties(String value) {
return value.replace(RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_SEPARATOR, RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_ESCAPED_SEPARATOR);
}

/**
* Create an encoded base 64 object id contains the following fields to uniquely identify the resource
* The fields are separated by a colon ":"
* @param type to identify type of storage - document/folder
* @param visibility of the resource public/private
* @param metadataId internal metadata id
* @param version identifier which can be used to directly get this version.
* @param resourceId or filename of the resource
* @return based 64 object id
*/
protected String getResourceManagementExternalPropertiesObjectId(final String type, final MetadataResourceVisibility visibility, final Integer metadataId, final String version,
final String resourceId) {
return Base64.getEncoder().encodeToString(
((type + RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_SEPARATOR +
escapeResourceManagementExternalProperties(visibility == null ? "" : visibility.toString().toLowerCase()) + RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_SEPARATOR +
metadataId + RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_SEPARATOR +
escapeResourceManagementExternalProperties(version == null ? "" : version) + RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_SEPARATOR +
escapeResourceManagementExternalProperties(resourceId)).getBytes()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,34 +232,45 @@ private Path getPath(ServiceContext context, int metadataId, MetadataResourceVis
public String delResources(ServiceContext context, int metadataId) throws Exception {
Path metadataDir = Lib.resource.getMetadataDir(getDataDirectory(context), metadataId);
try {
Log.info(Geonet.RESOURCES, String.format("Deleting all files from metadataId '%d'", metadataId));
IO.deleteFileOrDirectory(metadataDir, true);
return String.format("Metadata '%s' directory removed.", metadataId);
Log.info(Geonet.RESOURCES,
String.format("Metadata '%d' directory removed.", metadataId));
return String.format("Metadata '%d' directory removed.", metadataId);
} catch (Exception e) {
return String.format("Unable to remove metadata '%s' directory.", metadataId);
return String.format("Unable to remove metadata '%d' directory.", metadataId);
}
}

@Override
public String delResource(ServiceContext context, String metadataUuid, String resourceId, Boolean approved) throws Exception {
canEdit(context, metadataUuid, approved);
int metadataId = canEdit(context, metadataUuid, approved);

try (ResourceHolder filePath = getResource(context, metadataUuid, resourceId, approved)) {
Files.deleteIfExists(filePath.getPath());
return String.format("MetadataResource '%s' removed.", resourceId);
Log.info(Geonet.RESOURCES,
String.format("Resource '%s' removed for metadata %d (%s).", resourceId, metadataId, metadataUuid));
return String.format("Metadata resource '%s' removed.", resourceId);
} catch (IOException e) {
Log.warning(Geonet.RESOURCES,
String.format("Unable to remove resource '%s' for metadata %d (%s). %s", resourceId, metadataId, metadataUuid, e.getMessage()));
return String.format("Unable to remove resource '%s'.", resourceId);
}
}

@Override
public String delResource(final ServiceContext context, final String metadataUuid, final MetadataResourceVisibility visibility,
final String resourceId, Boolean approved) throws Exception {
canEdit(context, metadataUuid, approved);
int metadataId = canEdit(context, metadataUuid, approved);

try (ResourceHolder filePath = getResource(context, metadataUuid, visibility, resourceId, approved)) {
Files.deleteIfExists(filePath.getPath());
return String.format("MetadataResource '%s' removed.", resourceId);
Log.info(Geonet.RESOURCES,
String.format("Resource '%s' removed for metadata %d (%s).", resourceId, metadataId, metadataUuid));
return String.format("Metadata resource '%s' removed.", resourceId);
} catch (IOException e) {
Log.warning(Geonet.RESOURCES,
String.format("Unable to remove resource '%s' for metadata %d (%s). %s", resourceId, metadataId, metadataUuid, e.getMessage()));
return String.format("Unable to remove resource '%s'.", resourceId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import jeeves.server.sources.http.JeevesServlet;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.exceptions.BadParameterEx;
import org.fao.geonet.utils.FilePathChecker;
import org.fao.geonet.utils.IO;
import org.fao.geonet.utils.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ConfigurableApplicationContext;
Expand Down Expand Up @@ -63,6 +66,9 @@ public class GeonetworkDataDirectory {
*/
public static final String GEONETWORK_BEAN_KEY = "GeonetworkDataDirectory";

@Autowired
SchemaManager schemaManager;

private Path webappDir;
private Path systemDataDir;
private Path indexConfigDir;
Expand Down Expand Up @@ -797,11 +803,18 @@ public Path getXsltConversion(String conversionId) {
if (conversionId.startsWith(IMPORT_STYLESHEETS_SCHEMA_PREFIX)) {
String[] pathToken = conversionId.split(":");
if (pathToken.length == 3) {
String schema = pathToken[1];
if (!schemaManager.existsSchema(schema)) {
throw new BadParameterEx(String.format(
"Conversion not found. Schema '%s' is not registered in this catalog.", schema));
}
FilePathChecker.verify(pathToken[2]);
return this.getSchemaPluginsDir()
.resolve(pathToken[1])
.resolve(pathToken[2] + ".xsl");
}
} else {
FilePathChecker.verify(conversionId);
return this.getWebappDir().resolve(Geonet.Path.IMPORT_STYLESHEETS).
resolve(conversionId + ".xsl");
}
Expand Down
21 changes: 12 additions & 9 deletions core/src/main/java/org/fao/geonet/kernel/SchemaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Class that handles all functions relating to metadata schemas. This includes
Expand Down Expand Up @@ -106,6 +107,7 @@ public class SchemaManager {
private static int activeWriters = 0;
private Map<String, Schema> hmSchemas = new HashMap<>();
private Map<String, Namespace> hmSchemasTypenames = new HashMap<>();
private Map<String, String> cswOutputSchemas = new HashMap<>();
private String[] fnames = {"labels.xml", "codelists.xml", "strings.xml"};
private Path schemaPluginsDir;
private Path schemaPluginsCat;
Expand Down Expand Up @@ -958,6 +960,7 @@ private void addSchema(ApplicationContext applicationContext, Path schemaDir, El

if (mds.getSchemaPlugin() != null && mds.getSchemaPlugin().getCswTypeNames() != null) {
hmSchemasTypenames.putAll(mds.getSchemaPlugin().getCswTypeNames());
cswOutputSchemas.putAll(mds.getSchemaPlugin().getOutputSchemas());
}

// -- add cached xml files (schema codelists and label files)
Expand Down Expand Up @@ -1925,17 +1928,17 @@ public Map<String, Namespace> getHmSchemasTypenames() {
}

/**
* Return the list of namespace URI of all typenames declared in all schema plugins.
* Return the list of outputSchema declared in all schema plugins.
*/
public Map<String, String> getOutputSchemas() {
return cswOutputSchemas;
}

/**
* Return the list of namespace URI of all outputSchema declared in all schema plugins.
*/
public List<String> getListOfOutputSchemaURI() {
Iterator<String> iterator = hmSchemasTypenames.keySet().iterator();
List<String> listOfSchemaURI = new ArrayList<>();
while (iterator.hasNext()) {
String typeLocalName = iterator.next();
Namespace ns = hmSchemasTypenames.get(typeLocalName);
listOfSchemaURI.add(ns.getURI());
}
return listOfSchemaURI;
return new ArrayList<>(cswOutputSchemas.values());
}

/**
Expand Down
Loading

0 comments on commit b1d8f1b

Please sign in to comment.