Skip to content
Snippets Groups Projects
Commit 4c550b5d authored by Jesper Zedlitz's avatar Jesper Zedlitz
Browse files

Möglichkeiten zum Begrenzen und Ausschließen von Eintrags-Typen eingebaut

parent bae89e6d
No related branches found
No related tags found
1 merge request!18Resolve "Typen von Einträgen einschließen und ausschließen"
Pipeline #490 passed
...@@ -29,7 +29,8 @@ Jede Brücke benötigt mindestens zwei Informationen: ...@@ -29,7 +29,8 @@ Jede Brücke benötigt mindestens zwei Informationen:
| `BRIDGE_x_IRI` | pro Brücke | Präfix, mit dem die IRI der Datensätze gebildet werden | | `BRIDGE_x_IRI` | pro Brücke | Präfix, mit dem die IRI der Datensätze gebildet werden |
| `BRIDGE_x_CONTRIBUTOR` | pro Brücke | [DCAT-AP.de contributorId](https://www.dcat-ap.de/def/dcatde/2.0/spec/#datensatz-datenbereitsteller-id), die für die Datensätze gesetzt wird | | `BRIDGE_x_CONTRIBUTOR` | pro Brücke | [DCAT-AP.de contributorId](https://www.dcat-ap.de/def/dcatde/2.0/spec/#datensatz-datenbereitsteller-id), die für die Datensätze gesetzt wird |
| `BRIDGE_x_DISTRIBUTED` | pro Brücke | ist hier eine 1 gesetzt, wird eine [verteilte CSW-Suche (DistributedSearch)](https://docs.opengeospatial.org/is/12-176r7/12-176r7.html#85) durchgeführt | | `BRIDGE_x_DISTRIBUTED` | pro Brücke | ist hier eine 1 gesetzt, wird eine [verteilte CSW-Suche (DistributedSearch)](https://docs.opengeospatial.org/is/12-176r7/12-176r7.html#85) durchgeführt |
| `BRIDGE_x_EXCLUDE_TILES` | pro Brücke | gibt an, ob die Suche auf Einträge vom Typ `dataset`, `datasetCollection` und `series` eingeschränkt werden soll | | `BRIDGE_x_TYPE_EXCLUDE` | pro Brücke | schließe Einträge vom hier angegeben Typ aus, mehrere Einträge können mit Komma getrennt werden, ein Beispiel: `appplication,tile` |
| `BRIDGE_x_TYPE_INCLUDE` | pro Brücke | beschränke die Suche auf die hier angegebenen Typen, mehrere Einträge können mit Komma getrennt werden, ein Beispiel: `dataset,datasetCollection,series` |
| `BRIDGE_x_REMOVE_KEYWORDS` | pro Brücke | optionale Komma-getrennte Liste von Schlüsselwörtern, die entfernt werden sollen | | `BRIDGE_x_REMOVE_KEYWORDS` | pro Brücke | optionale Komma-getrennte Liste von Schlüsselwörtern, die entfernt werden sollen |
| `BRIDGE_x_FIND_WMS_IN_INFO` | pro Brücke | gibt an, ob in den `transferOptions` from Typ `information` nach WMS gesucht werden soll. Mehr dazu bei den [Details der Konfigurationsoptionen](konfigurationsdetails.md#BRIDGE_FIND_WMS_IN_INFO) | | `BRIDGE_x_FIND_WMS_IN_INFO` | pro Brücke | gibt an, ob in den `transferOptions` from Typ `information` nach WMS gesucht werden soll. Mehr dazu bei den [Details der Konfigurationsoptionen](konfigurationsdetails.md#BRIDGE_FIND_WMS_IN_INFO) |
| `BRIDGE_x_FIX_MISSING_TEMPORAL` | pro Brücke | ist hier eine 1 gesetzt, wird bei fehlender zeitlicher Coverage das Veröffentlichungsdatum als Startdatum verwendet | | `BRIDGE_x_FIX_MISSING_TEMPORAL` | pro Brücke | ist hier eine 1 gesetzt, wird bei fehlender zeitlicher Coverage das Veröffentlichungsdatum als Startdatum verwendet |
......
...@@ -17,7 +17,16 @@ public class BridgeSettings { ...@@ -17,7 +17,16 @@ public class BridgeSettings {
String contributorId = "https://www.gdi-sh.de"; String contributorId = "https://www.gdi-sh.de";
boolean distributedSearch = false; boolean distributedSearch = false;
boolean excludeTiles = true; /**
* List of item types (i.e. dataset, datasetCollection, series, application, tile, service) that should <b>not</b> be searched.
*/
String[] typeExclude;
/**
* List of item types (i.e. dataset, datasetCollection, series, application, tile, service) that should be searched.
* If not set all item types will be searched.
*/
String[] typeInclude;
boolean findWMSinInfo = false; boolean findWMSinInfo = false;
......
...@@ -30,22 +30,24 @@ public class CswInterface { ...@@ -30,22 +30,24 @@ public class CswInterface {
private static final Logger log = LoggerFactory.getLogger(CswInterface.class); private static final Logger log = LoggerFactory.getLogger(CswInterface.class);
private final SAXReader saxReader = new SAXReader(); private final SAXReader saxReader = new SAXReader();
private final String url; private final String url;
/**
* List of item types (i.e. dataset, datasetCollection, series, application, tile, service) that should <b>not</b> be searched.
*/
private String[] typeExclude;
/**
* List of item types (i.e. dataset, datasetCollection, series, application, tile, service) that should be searched.
* If not set all item types will be searched.
*/
private String[] typeInclude;
private CloseableHttpClient httpClient = HttpClients.createMinimal(); private CloseableHttpClient httpClient = HttpClients.createMinimal();
private String dumpCswResponse = null; private String dumpCswResponse = null;
private boolean distributedSearch = false; private boolean distributedSearch = false;
private boolean filterOpendata = false; private boolean filterOpendata = false;
/**
* If <code>true</code> limit the results to datasets, dataset collections and series.
*/
private boolean excludeTiles = false;
/** /**
* Ask the CSW server in the GetRecords operation to sort the results by Identifier * Ask the CSW server in the GetRecords operation to sort the results by Identifier
*/ */
private boolean sortResults = true; private boolean sortResults = true;
private String authorization = null; private String authorization = null;
public CswInterface(String url) { public CswInterface(String url) {
this.url = url; this.url = url;
} }
...@@ -53,10 +55,35 @@ public class CswInterface { ...@@ -53,10 +55,35 @@ public class CswInterface {
public CswInterface(BridgeSettings settings) { public CswInterface(BridgeSettings settings) {
this.url = settings.cswURL; this.url = settings.cswURL;
setDistributedSearch(settings.distributedSearch); setDistributedSearch(settings.distributedSearch);
setExcludeTiles(settings.excludeTiles);
filterOpendata = settings.filterOpenData; filterOpendata = settings.filterOpenData;
authorization = settings.authorization; authorization = settings.authorization;
sortResults = settings.sortResults; sortResults = settings.sortResults;
typeExclude = settings.typeExclude;
typeInclude = settings.typeInclude;
}
public void setTypeExclude(String[] typeExclude) {
this.typeExclude = typeExclude;
}
public void setTypeInclude(String[] typeInclude) {
this.typeInclude = typeInclude;
}
public void setSortResults(boolean sortResults) {
this.sortResults = sortResults;
}
boolean hasTypeInclude() {
return typeInclude != null && typeInclude.length > 0;
}
boolean hasTypeExclude() {
return typeExclude != null && typeExclude.length > 0;
}
boolean hasMultipleTypeExclude() {
return typeExclude != null && typeExclude.length > 1;
} }
void setHttpClient(CloseableHttpClient httpClient) { void setHttpClient(CloseableHttpClient httpClient) {
...@@ -83,10 +110,6 @@ public class CswInterface { ...@@ -83,10 +110,6 @@ public class CswInterface {
this.dumpCswResponse = s; this.dumpCswResponse = s;
} }
public void setExcludeTiles(boolean excludeTiles) {
this.excludeTiles = excludeTiles;
}
/** /**
* @param startPosition number of the first requested record. Used for paging. Will be sent to the WFS server as * @param startPosition number of the first requested record. Used for paging. Will be sent to the WFS server as
* <code>startPosition</code> First record is 1. * <code>startPosition</code> First record is 1.
...@@ -138,6 +161,10 @@ public class CswInterface { ...@@ -138,6 +161,10 @@ public class CswInterface {
} }
request.setEntity(new StringEntity(xmlRequest.toString(), StandardCharsets.UTF_8)); request.setEntity(new StringEntity(xmlRequest.toString(), StandardCharsets.UTF_8));
{ FileWriter fw = new FileWriter("/tmp/request.xml");
fw.write(xmlRequest.toString());
fw.close();}
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
try (CloseableHttpResponse response = httpClient.execute(request)) { try (CloseableHttpResponse response = httpClient.execute(request)) {
if (response.getCode() == 200) { if (response.getCode() == 200) {
...@@ -186,12 +213,15 @@ public class CswInterface { ...@@ -186,12 +213,15 @@ public class CswInterface {
} }
} }
if (!filters.isEmpty()) { // Do we have multiple CQL filter queries and therefore need a surrounding And element?
xmlRequest.append("<ogc:And xmlns:ogc=\"http://www.opengis.net/ogc\">"); final boolean needsAndElement = !filters.isEmpty() || hasMultipleTypeExclude() || hasTypeInclude();
if (needsAndElement) {
xmlRequest.append("<ogc:And>");
for (String propertyName : filters.keySet()) { for (String propertyName : filters.keySet()) {
Set<String> values = filters.get(propertyName); Set<String> values = filters.get(propertyName);
for (String value : values) { for (String value : values) {
xmlRequest.append("<ogc:PropertyIsEqualTo><ogc:PropertyName xmlns:apiso=\"http://www.opengis.net/cat/apiso/1.0\">apiso:") xmlRequest.append("<ogc:PropertyIsEqualTo><ogc:PropertyName>apiso:")
.append(propertyName) .append(propertyName)
.append("</ogc:PropertyName>") .append("</ogc:PropertyName>")
.append("<ogc:Literal>") .append("<ogc:Literal>")
...@@ -202,25 +232,32 @@ public class CswInterface { ...@@ -202,25 +232,32 @@ public class CswInterface {
} }
} }
if (excludeTiles) { if (hasTypeInclude()) {
// limit the results to datasets, dataset collections and series. xmlRequest.append("<ogc:Or>");
xmlRequest.append("<ogc:Or>\n" +
" <ogc:PropertyIsEqualTo>\n" + for (String type : typeInclude) {
" <ogc:PropertyName xmlns:apiso=\"http://www.opengis.net/cat/apiso/1.0\">apiso:Type</ogc:PropertyName>\n" + xmlRequest.append("<ogc:PropertyIsEqualTo>"
" <ogc:Literal>dataset</ogc:Literal>\n" + + "<ogc:PropertyName>apiso:Type</ogc:PropertyName>"
" </ogc:PropertyIsEqualTo>\n" + + "<ogc:Literal>")
" <ogc:PropertyIsEqualTo>\n" + .append(type)
" <ogc:PropertyName xmlns:apiso=\"http://www.opengis.net/cat/apiso/1.0\">apiso:Type</ogc:PropertyName>\n" + .append("</ogc:Literal></ogc:PropertyIsEqualTo>");
" <ogc:Literal>datasetCollection</ogc:Literal>\n" + }
" </ogc:PropertyIsEqualTo>\n" +
" <ogc:PropertyIsEqualTo>\n" + xmlRequest.append("</ogc:Or>");
" <ogc:PropertyName xmlns:apiso=\"http://www.opengis.net/cat/apiso/1.0\">apiso:Type</ogc:PropertyName>\n" + }
" <ogc:Literal>series</ogc:Literal>\n" +
" </ogc:PropertyIsEqualTo>\n" + if (hasTypeExclude()) {
" </ogc:Or>"); for (String type : typeExclude) {
xmlRequest.append("<ogc:Not><ogc:PropertyIsEqualTo>"
+ "<ogc:PropertyName>apiso:Type</ogc:PropertyName>"
+ "<ogc:Literal>")
.append(type)
.append("</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Not>");
} }
}
if (!filters.isEmpty()) { if (needsAndElement) {
xmlRequest.append("</ogc:And>"); xmlRequest.append("</ogc:And>");
} }
...@@ -252,6 +289,7 @@ public class CswInterface { ...@@ -252,6 +289,7 @@ public class CswInterface {
final String xmlRequest = "<csw:GetRecords xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" xmlns:ogc=\"http://www.opengis.net/ogc\"\n" + final String xmlRequest = "<csw:GetRecords xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" xmlns:ogc=\"http://www.opengis.net/ogc\"\n" +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ows=\"http://www.opengis.net/ows\"\n" + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ows=\"http://www.opengis.net/ows\"\n" +
"xmlns:apiso=\"http://www.opengis.net/cat/apiso/1.0\" "+
"outputSchema=\"http://www.isotc211.org/2005/gmd\" outputFormat=\"application/xml\" version=\"2.0.2\" service=\"CSW\" resultType=\"results\"\n" + "outputSchema=\"http://www.isotc211.org/2005/gmd\" outputFormat=\"application/xml\" version=\"2.0.2\" service=\"CSW\" resultType=\"results\"\n" +
"maxRecords=\"999\" xsi:schemaLocation=\"http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd\">\n" + "maxRecords=\"999\" xsi:schemaLocation=\"http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd\">\n" +
" <csw:Query typeNames=\"csw:Record\">\n" + " <csw:Query typeNames=\"csw:Record\">\n" +
......
...@@ -7,11 +7,15 @@ import io.undertow.server.HttpServerExchange; ...@@ -7,11 +7,15 @@ import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers; import io.undertow.util.Headers;
import io.undertow.util.HttpString; import io.undertow.util.HttpString;
import io.undertow.util.Methods; import io.undertow.util.Methods;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.HttpStatus;
import org.apache.jena.rdf.model.*; import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.DCAT; import org.apache.jena.vocabulary.DCAT;
import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDF;
import org.dom4j.Element; import org.dom4j.Element;
...@@ -19,9 +23,7 @@ import org.slf4j.Logger; ...@@ -19,9 +23,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
...@@ -60,7 +62,21 @@ public class Server implements HttpHandler { ...@@ -60,7 +62,21 @@ public class Server implements HttpHandler {
settings.contributorId = StringUtils.defaultString(bridgeContributor, "https://example.org/contributor"); settings.contributorId = StringUtils.defaultString(bridgeContributor, "https://example.org/contributor");
settings.distributedSearch = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_DISTRIBUTED")); settings.distributedSearch = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_DISTRIBUTED"));
settings.excludeTiles = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_EXCLUDE_TILES")); if (System.getenv("BRIDGE" + prefix + "_TYPE_EXCLUDE") != null) {
String value = System.getenv("BRIDGE" + prefix + "_TYPE_EXCLUDE").replaceAll(" ", StringUtils.EMPTY);
settings.typeExclude = value.split(",");
}
if (BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_EXCLUDE_TILES"))) {
if (settings.typeExclude == null) {
settings.typeExclude = new String[]{"tile"};
} else {
settings.typeExclude = ArrayUtils.add(settings.typeExclude, "tile");
}
}
if (System.getenv("BRIDGE" + prefix + "_TYPE_INCLUDE") != null) {
String value = System.getenv("BRIDGE" + prefix + "_TYPE_INCLUDE").replaceAll(" ", StringUtils.EMPTY);
settings.typeInclude = value.split(",");
}
settings.findWMSinInfo = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_FIND_WMS_IN_INFO")); settings.findWMSinInfo = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_FIND_WMS_IN_INFO"));
settings.addMissingTemporalStart = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_FIX_MISSING_TEMPORAL")); settings.addMissingTemporalStart = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_FIX_MISSING_TEMPORAL"));
settings.filterOpenData = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_FILTER_OPENDATA")); settings.filterOpenData = BooleanUtils.toBoolean(System.getenv("BRIDGE" + prefix + "_FILTER_OPENDATA"));
...@@ -193,8 +209,6 @@ public class Server implements HttpHandler { ...@@ -193,8 +209,6 @@ public class Server implements HttpHandler {
} }
/** /**
* Handle CSW -> DCAT request * Handle CSW -> DCAT request
*/ */
......
...@@ -52,6 +52,12 @@ class CswInterfaceTest { ...@@ -52,6 +52,12 @@ class CswInterfaceTest {
} }
} }
private static String wrapXML(String result) {
return "<xml" +
" xmlns:ogc=\"http://www.opengis.net/ogc\"" +
" xmlns:apiso=\"http://www.opengis.net/cat/apiso/1.0\">" + result + "</xml>";
}
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
...@@ -98,8 +104,7 @@ class CswInterfaceTest { ...@@ -98,8 +104,7 @@ class CswInterfaceTest {
String result = cswInterface.buildFilterQuery(filters); String result = cswInterface.buildFilterQuery(filters);
Element filter = saxReader.read(new StringReader(result)).getRootElement(); Element filter = saxReader.read(new StringReader(wrapXML(result))).getRootElement().element("And");
assertEquals("And", filter.getName());
List<Element> properties = filter.elements("PropertyIsEqualTo"); List<Element> properties = filter.elements("PropertyIsEqualTo");
assertEquals(3, properties.size()); assertEquals(3, properties.size());
...@@ -123,8 +128,7 @@ class CswInterfaceTest { ...@@ -123,8 +128,7 @@ class CswInterfaceTest {
cswInterface.setFilterOpendata(true); cswInterface.setFilterOpendata(true);
String result = cswInterface.buildFilterQuery(filters); String result = cswInterface.buildFilterQuery(filters);
Element filter = saxReader.read(new StringReader(result)).getRootElement(); Element filter = saxReader.read(new StringReader(wrapXML(result))).getRootElement().element("And");
assertEquals("And", filter.getName());
List<Element> properties = filter.elements("PropertyIsEqualTo"); List<Element> properties = filter.elements("PropertyIsEqualTo");
assertEquals(4, properties.size()); assertEquals(4, properties.size());
...@@ -144,8 +148,7 @@ class CswInterfaceTest { ...@@ -144,8 +148,7 @@ class CswInterfaceTest {
cswInterface.setFilterOpendata(true); cswInterface.setFilterOpendata(true);
String result = cswInterface.buildFilterQuery(new HashMap<>()); String result = cswInterface.buildFilterQuery(new HashMap<>());
Element filter = saxReader.read(new StringReader(result)).getRootElement(); Element filter = saxReader.read(new StringReader(wrapXML(result))).getRootElement().element("And");
assertEquals("And", filter.getName());
Element property = filter.element("PropertyIsEqualTo"); Element property = filter.element("PropertyIsEqualTo");
assertNotNull(property); assertNotNull(property);
assertEquals("apiso:Subject", property.elementText("PropertyName")); assertEquals("apiso:Subject", property.elementText("PropertyName"));
...@@ -226,4 +229,33 @@ class CswInterfaceTest { ...@@ -226,4 +229,33 @@ class CswInterfaceTest {
assertEquals("apiso:Subject", elementAnd.element("PropertyIsEqualTo").elementText("PropertyName")); assertEquals("apiso:Subject", elementAnd.element("PropertyIsEqualTo").elementText("PropertyName"));
assertEquals("opendata", elementAnd.element("PropertyIsEqualTo").elementText("Literal")); assertEquals("opendata", elementAnd.element("PropertyIsEqualTo").elementText("Literal"));
} }
@Test
void buildFilterQuery_TypeExclude_One() throws DocumentException {
cswInterface.setTypeExclude(new String[]{"tile"});
String result = cswInterface.buildFilterQuery(new HashMap<>());
Element xml = saxReader.read(new StringReader(wrapXML(result))).getRootElement();
Element elementNot = xml.element("Not");
assertNotNull(elementNot);
assertEquals("apiso:Type", elementNot.element("PropertyIsEqualTo").elementText("PropertyName"));
assertEquals("tile", elementNot.element("PropertyIsEqualTo").elementText("Literal"));
}
@Test
void buildFilterQuery_TypeExclude_Multiple() throws DocumentException {
cswInterface.setTypeExclude(new String[]{"tile", "application"});
String result = cswInterface.buildFilterQuery(new HashMap<>());
Element xml = saxReader.read(new StringReader(wrapXML(result))).getRootElement();
Element andElement = xml.element("And");
assertNotNull(andElement);
List<Element> notElements = andElement.elements("Not");
assertEquals("apiso:Type", notElements.get(0).element("PropertyIsEqualTo").elementText("PropertyName"));
assertEquals("tile", notElements.get(0).element("PropertyIsEqualTo").elementText("Literal"));
assertEquals("apiso:Type", notElements.get(1).element("PropertyIsEqualTo").elementText("PropertyName"));
assertEquals("application", notElements.get(1).element("PropertyIsEqualTo").elementText("Literal"));
}
} }
...@@ -10,8 +10,6 @@ import org.junit.jupiter.api.BeforeAll; ...@@ -10,8 +10,6 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockingDetails;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockserver.client.MockServerClient; import org.mockserver.client.MockServerClient;
import org.mockserver.integration.ClientAndServer; import org.mockserver.integration.ClientAndServer;
...@@ -23,7 +21,7 @@ import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; ...@@ -23,7 +21,7 @@ import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -60,11 +58,14 @@ public class ServerTests { ...@@ -60,11 +58,14 @@ public class ServerTests {
public void readEnvironmentVariables_single() { public void readEnvironmentVariables_single() {
environmentVariables.set("BRIDGE_URL", "http://localhost:8081/csw"); environmentVariables.set("BRIDGE_URL", "http://localhost:8081/csw");
environmentVariables.set("BRIDGE_FIND_WMS_IN_INFO", "true"); environmentVariables.set("BRIDGE_FIND_WMS_IN_INFO", "true");
environmentVariables.set("BRIDGE_TYPE_EXCLUDE", "application,tile");
Server.readEnvironmentVariables(); Server.readEnvironmentVariables();
assertEquals(1, Server.bridgeSettings.size()); assertEquals(1, Server.bridgeSettings.size());
assertEquals("http://localhost:8081/csw", Server.bridgeSettings.get(0).cswURL); assertEquals("http://localhost:8081/csw", Server.bridgeSettings.get(0).cswURL);
assertTrue(Server.bridgeSettings.get(0).findWMSinInfo); assertTrue(Server.bridgeSettings.get(0).findWMSinInfo);
assertEquals("[application, tile]", Arrays.toString(Server.bridgeSettings.get(0).typeExclude));
} }
@Test @Test
...@@ -99,27 +100,43 @@ public class ServerTests { ...@@ -99,27 +100,43 @@ public class ServerTests {
environmentVariables.set("BRIDGE_1_FIND_WMS_IN_INFO", "true"); environmentVariables.set("BRIDGE_1_FIND_WMS_IN_INFO", "true");
environmentVariables.set("BRIDGE_1_REMOVE_KEYWORDS", "opendata"); environmentVariables.set("BRIDGE_1_REMOVE_KEYWORDS", "opendata");
environmentVariables.set("BRIDGE_1_FIX_MISSING_TEMPORAL", "1"); environmentVariables.set("BRIDGE_1_FIX_MISSING_TEMPORAL", "1");
environmentVariables.set("BRIDGE_1_TYPE_EXCLUDE", "application, tile,service");
environmentVariables.set("BRIDGE_2_URL", "http://localhost:8082/csw"); environmentVariables.set("BRIDGE_2_URL", "http://localhost:8082/csw");
environmentVariables.set("BRIDGE_2_FIND_WMS_IN_INFO", "false"); environmentVariables.set("BRIDGE_2_FIND_WMS_IN_INFO", "false");
environmentVariables.set("BRIDGE_2_FILTER_OPENDATA", "true"); environmentVariables.set("BRIDGE_2_FILTER_OPENDATA", "true");
environmentVariables.set("BRIDGE_2_SORT_RESULTS", "false"); environmentVariables.set("BRIDGE_2_SORT_RESULTS", "false");
environmentVariables.set("BRIDGE_2_TYPE_INCLUDE", "dataset,series");
environmentVariables.set("BRIDGE_3_URL", "http://localhost:8083/csw"); environmentVariables.set("BRIDGE_3_URL", "http://localhost:8083/csw");
environmentVariables.set("BRIDGE_2_SORT_RESULTS", "1"); environmentVariables.set("BRIDGE_3_SORT_RESULTS", "1");
Server.readEnvironmentVariables(); Server.readEnvironmentVariables();
BridgeSettings settings1 = Server.bridgeSettings.get(0);
BridgeSettings settings2 = Server.bridgeSettings.get(1);
BridgeSettings settings3 = Server.bridgeSettings.get(2);
assertEquals(3, Server.bridgeSettings.size()); assertEquals(3, Server.bridgeSettings.size());
assertEquals("http://localhost:8081/csw", Server.bridgeSettings.get(0).cswURL); assertEquals("http://localhost:8081/csw", settings1.cswURL);
assertEquals("http://localhost:8082/csw", Server.bridgeSettings.get(1).cswURL); assertEquals("http://localhost:8082/csw", settings2.cswURL);
assertEquals("http://localhost:8083/csw", Server.bridgeSettings.get(2).cswURL); assertEquals("http://localhost:8083/csw", settings3.cswURL);
assertTrue(Server.bridgeSettings.get(0).findWMSinInfo); assertTrue(settings1.findWMSinInfo);
assertFalse(Server.bridgeSettings.get(1).findWMSinInfo); assertFalse(settings2.findWMSinInfo);
assertTrue(Server.bridgeSettings.get(0).keywordRemove.contains("opendata")); assertTrue(settings1.keywordRemove.contains("opendata"));
assertTrue(Server.bridgeSettings.get(0).addMissingTemporalStart); assertTrue(settings1.addMissingTemporalStart);
assertFalse(Server.bridgeSettings.get(1).addMissingTemporalStart); assertFalse(settings2.addMissingTemporalStart);
assertTrue(Server.bridgeSettings.get(1).filterOpenData); assertTrue(settings2.filterOpenData);
assertTrue(Server.bridgeSettings.get(0).sortResults); assertTrue(settings1.sortResults);
assertTrue(Server.bridgeSettings.get(1).sortResults); assertFalse(settings2.sortResults);
assertTrue(Server.bridgeSettings.get(2).sortResults); assertTrue(settings3.sortResults);
assertNotNull(settings1.typeExclude);
assertEquals(3, settings1.typeExclude.length);
assertEquals("[application, tile, service]", Arrays.toString(settings1.typeExclude));
assertNotNull(settings2.typeInclude);
assertEquals(2, settings2.typeInclude.length);
assertEquals("[dataset, series]", Arrays.toString(settings2.typeInclude));
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment