-
-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend ElasticSearch proxy to filter out elements defined in the sche…
…ma filters configurations (#6869) (#8483) * Extend ElasticSearch proxy to filter out fields with the withheld information from the query response * Extend XmlSerializer to support 'authenticated' operation and filter out the xml elements * Fix ifNotOperation typo in enumeration element in schema-ident.xsd * MEF export - withheld elements in additional formats export * Search / Avoid NPE when filtering withheld elements. We always need the documentStandard field to check the schema config. * Indexing / Store nilReason attribute value instead of only withheld. Add nilReason for links (and not only contact). --------- Co-authored-by: Francois Prunayre <[email protected]>
- Loading branch information
1 parent
693d481
commit e6de61a
Showing
14 changed files
with
420 additions
and
182 deletions.
There are no files selected for viewing
199 changes: 105 additions & 94 deletions
199
core/src/main/java/org/fao/geonet/kernel/SchemaManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
//============================================================================== | ||
//=== | ||
//=== MetadataSchema | ||
//=== | ||
//============================================================================== | ||
//=== 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.kernel.schema; | ||
|
||
|
@@ -34,9 +30,9 @@ | |
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.fao.geonet.api.exception.ResourceNotFoundException; | ||
import org.fao.geonet.constants.Geonet; | ||
import org.fao.geonet.domain.Pair; | ||
import org.fao.geonet.domain.ReservedOperation; | ||
import org.fao.geonet.domain.Schematron; | ||
import org.fao.geonet.domain.SchematronCriteria; | ||
|
@@ -82,15 +78,15 @@ public class MetadataSchema { | |
private static final String XSL_FILE_EXTENSION = ".xsl"; | ||
private static final String SCH_FILE_EXTENSION = ".sch"; | ||
private static final String SCHEMATRON_RULE_FILE_PREFIX = "schematron-rules"; | ||
private Map<String, List<String>> hmElements = new HashMap<String, List<String>>(); | ||
private Map<String, List<List<String>>> hmRestric = new HashMap<String, List<List<String>>>(); | ||
private Map<String, MetadataType> hmTypes = new HashMap<String, MetadataType>(); | ||
private Map<String, List<String>> hmSubs = new HashMap<String, List<String>>(); | ||
private Map<String, String> hmSubsLink = new HashMap<String, String>(); | ||
private Map<String, Namespace> hmNameSpaces = new HashMap<String, Namespace>(); | ||
private Map<String, Namespace> hmPrefixes = new HashMap<String, Namespace>(); | ||
private Map<String, Pair<String, Element>> hmOperationFilters = | ||
new HashMap<String, Pair<String, Element>>(); | ||
private Map<String, List<String>> hmElements = new HashMap<>(); | ||
private Map<String, List<List<String>>> hmRestric = new HashMap<>(); | ||
private Map<String, MetadataType> hmTypes = new HashMap<>(); | ||
private Map<String, List<String>> hmSubs = new HashMap<>(); | ||
private Map<String, String> hmSubsLink = new HashMap<>(); | ||
private Map<String, Namespace> hmNameSpaces = new HashMap<>(); | ||
private Map<String, Namespace> hmPrefixes = new HashMap<>(); | ||
private Map<String, MetadataSchemaOperationFilter> hmOperationFilters = | ||
new HashMap<>(); | ||
private String schemaName; | ||
private Path schemaDir; | ||
private String standardUrl; | ||
|
@@ -294,8 +290,8 @@ void addElement(String name, String type, List<String> alValues, List<String> al | |
// first just add the subs - because these are for global elements we | ||
// never have a clash because global elements are all in the same scope | ||
// and are thus unique | ||
if (alSubs != null && alSubs.size() > 0) hmSubs.put(name, alSubs); | ||
if (subLink != null && subLink.length() > 0) hmSubsLink.put(name, subLink); | ||
if (alSubs != null && !alSubs.isEmpty()) hmSubs.put(name, alSubs); | ||
if (subLink != null && StringUtils.isNotBlank(subLink)) hmSubsLink.put(name, subLink); | ||
|
||
List<String> exType = hmElements.get(name); | ||
|
||
|
@@ -309,7 +305,8 @@ void addElement(String name, String type, List<String> alValues, List<String> al | |
|
||
// it's not there so add a new list | ||
} else { | ||
hmElements.put(name, exType = new ArrayList<String>()); | ||
exType = new ArrayList<>(); | ||
hmElements.put(name, exType); | ||
} | ||
exType.add(type); | ||
|
||
|
@@ -323,7 +320,8 @@ void addElement(String name, String type, List<String> alValues, List<String> al | |
|
||
// it's not there so add a new list of lists | ||
} else { | ||
hmRestric.put(restricName, exValues = new ArrayList<List<String>>()); | ||
exValues = new ArrayList<>(); | ||
hmRestric.put(restricName, exValues); | ||
} | ||
exValues.add(alValues); | ||
} | ||
|
@@ -361,7 +359,7 @@ public String getNS(String targetNSPrefix) { | |
*/ | ||
@JsonIgnore | ||
public List<Namespace> getNamespaces() { | ||
List<Namespace> list = new ArrayList<Namespace>(hmNameSpaces.size()); | ||
List<Namespace> list = new ArrayList<>(hmNameSpaces.size()); | ||
for (Namespace ns : hmNameSpaces.values()) { | ||
list.add(ns); | ||
} | ||
|
@@ -382,12 +380,12 @@ public String getPrefix(String theNSUri) { | |
//--------------------------------------------------------------------------- | ||
@JsonIgnore | ||
public List<Namespace> getSchemaNS() { | ||
return new ArrayList<Namespace>(hmPrefixes.values()); | ||
return new ArrayList<>(hmPrefixes.values()); | ||
} | ||
|
||
@JsonProperty(value = "namespaces") | ||
public Map<String, String> getSchemaNSWithPrefix() { | ||
Map<String, String> mapNs = new HashMap<String, String>(); | ||
Map<String, String> mapNs = new HashMap<>(); | ||
List<Namespace> schemaNsList = getSchemaNS(); | ||
|
||
for (Namespace ns : schemaNsList) { | ||
|
@@ -518,7 +516,7 @@ private void setSchematronPriorities() { | |
this.schemaRepo.saveAll(updated); | ||
} | ||
|
||
public void setOperationFilters(Map<String, Pair<String, Element>> operationFilters) { | ||
public void setOperationFilters(Map<String, MetadataSchemaOperationFilter> operationFilters) { | ||
this.hmOperationFilters = operationFilters; | ||
} | ||
|
||
|
@@ -527,10 +525,14 @@ public void setOperationFilters(Map<String, Pair<String, Element>> operationFilt | |
* | ||
* @return The XPath to select element to filter or null | ||
*/ | ||
public Pair<String, Element> getOperationFilter(ReservedOperation operation) { | ||
public MetadataSchemaOperationFilter getOperationFilter(ReservedOperation operation) { | ||
return hmOperationFilters.get(operation.name()); | ||
} | ||
|
||
public MetadataSchemaOperationFilter getOperationFilter(String operation) { | ||
return hmOperationFilters.get(operation); | ||
} | ||
|
||
@JsonIgnore | ||
public SchemaPlugin getSchemaPlugin() { | ||
return schemaPlugin; | ||
|
61 changes: 61 additions & 0 deletions
61
core/src/main/java/org/fao/geonet/kernel/schema/MetadataSchemaOperationFilter.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,61 @@ | ||
/* | ||
* 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.kernel.schema; | ||
|
||
import org.jdom.Element; | ||
|
||
public class MetadataSchemaOperationFilter { | ||
private String xpath; | ||
private String jsonpath; | ||
private String ifNotOperation; | ||
private Element markedElement; | ||
|
||
|
||
public MetadataSchemaOperationFilter(String xpath, String jsonpath, String ifNotOperation) { | ||
this(xpath, jsonpath, ifNotOperation, null); | ||
} | ||
|
||
public MetadataSchemaOperationFilter(String xpath, String jsonpath, String ifNotOperation, Element markedElement) { | ||
this.xpath = xpath; | ||
this.jsonpath = jsonpath; | ||
this.ifNotOperation = ifNotOperation; | ||
this.markedElement = markedElement; | ||
|
||
} | ||
|
||
public String getXpath() { | ||
return xpath; | ||
} | ||
|
||
public String getJsonpath() { | ||
return jsonpath; | ||
} | ||
|
||
public String getIfNotOperation() { | ||
return ifNotOperation; | ||
} | ||
|
||
public Element getMarkedElement() { | ||
return markedElement; | ||
} | ||
} |
Oops, something went wrong.