diff --git a/core/src/main/java/org/geonetwork/map/wms/SLDUtil.java b/core/src/main/java/org/geonetwork/map/wms/SLDUtil.java index ce162c35b57b..92908d7abc10 100644 --- a/core/src/main/java/org/geonetwork/map/wms/SLDUtil.java +++ b/core/src/main/java/org/geonetwork/map/wms/SLDUtil.java @@ -1,127 +1,48 @@ +/* + * Copyright (C) 2001-2026 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: geonetwork@osgeo.org + */ + package org.geonetwork.map.wms; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.impl.client.DefaultHttpClient; import org.fao.geonet.constants.Geonet; -import org.fao.geonet.utils.Xml; import org.geotools.factory.CommonFactoryFinder; import org.geotools.filter.v1_1.OGCConfiguration; -import org.geotools.ows.ServiceException; import org.geotools.xsd.Configuration; import org.geotools.xsd.Encoder; -import org.jdom.Content; -import org.jdom.Element; -import org.jdom.JDOMException; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.geotools.api.filter.Filter; import org.geotools.api.filter.FilterFactory; -import javax.mail.internet.ContentType; -import javax.mail.internet.ParseException; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.net.URI; -import java.net.URISyntaxException; import java.util.*; public class SLDUtil { public static final String LOGGER = Geonet.GEONETWORK + ".util.sld"; - /** - * Issue a GetStyle query on specified server for specified layers, parse XML result and return - * the SLD as a String. - * - * @param url base url of WMS server with no parameter. ex: http://demo.boundlessgeo.com/geoserver/wms - * @param layers comma separated list of layers - * @return String the sld of the layers from the server url - * @throws IOException if there is an error communicating with the server - * @throws ServiceException if the server responds with an error - * @throws ParseException if unable to parse content type header from server - */ - public static Map parseSLD(URI url, String layers) throws URISyntaxException, IOException, ParseException { - Map hash = new HashMap(); - - String requestUrl = SLDUtil.getGetStyleRequest(url, layers); - - HttpGet httpGet = new HttpGet(requestUrl); - HttpClient client = new DefaultHttpClient(); - final HttpResponse httpResponse = client.execute(httpGet); - - // Set encoding of response from HTTP content-type header - ContentType contentType = new ContentType(httpResponse.getEntity().getContentType().getValue()); - String charset = contentType.getParameter("charset"); - hash.put("charset", charset); - hash.put("content", IOUtils.toString(httpResponse.getEntity().getContent(), charset).trim()); - - return hash; - } - - - public static String getGetStyleRequest(URI uri, String layers) throws URISyntaxException { - URIBuilder builder = new URIBuilder(uri); - builder.addParameter("service", "WMS"); - builder.addParameter("request", "GetStyles"); - builder.addParameter("version", "1.1.1"); - builder.addParameter("layers", layers); - - return builder.build().toString(); - } - - /** - * Insert a new filter in all rules of the sld document. For each rule, - * the ogc:Filter ellement is added if not exist, or merge with an ogc:And - * tag with the giver filter. - * - * @param doc Xml docuement representing the SLD - * @param filter the new filter to insert - * @throws JDOMException - * @throws IOException - */ - public static void insertFilter(Element doc, Filter filter) throws JDOMException, IOException { - - String sFilter = SLDUtil.encodeFilter(filter); - Element newFilterElt = Xml.loadString(sFilter, false); - List newFilterChildren = (List) ((Element)newFilterElt.clone()).getChildren(); - - if(newFilterChildren.size() > 0) { - Content newFilterContent = newFilterChildren.get(0).detach(); - - // Check rules in both se and sld namespaces - List rules = (List) Xml.selectNodes(doc, "*//sld:Rule", Arrays.asList(Geonet.Namespaces.SLD)); - if(rules.size() == 0) { - rules = (List) Xml.selectNodes(doc, "*//se:Rule", Arrays.asList(Geonet.Namespaces.SE)); - } - - for (Element rule : rules) { - List filters = (List) Xml.selectNodes(rule, "ogc:Filter", Arrays.asList(Geonet.Namespaces.OGC)); - if(filters.size() == 0) { - rule.addContent((Element)newFilterElt.clone()); - } - else if (filters.size() == 1) { - Element sldFilterElt = filters.get(0); - Element filterContent = (Element)sldFilterElt.getChildren().get(0); - filterContent.detach(); - sldFilterElt.removeContent(); - Element andElt = new Element("And", Geonet.Namespaces.OGC); - andElt.addContent(filterContent); - andElt.addContent((Content)newFilterContent.clone()); - sldFilterElt.addContent(andElt); - } - else { - throw new JDOMException("A rule must have maximum one ogc:filter element"); - } - } - } - } - /** * Encode into a string the given OGC Filter * @@ -171,7 +92,7 @@ public static Filter generateCustomFilter(JSONObject userFilters) throws JSONExc FilterFactory ff2 = CommonFactoryFinder.getFilterFactory(); JSONArray filters = userFilters.getJSONArray("filters"); - List res = new LinkedList(); + List res = new LinkedList<>(); for(int i=0;i res = new LinkedList(); + List res = new LinkedList<>(); JSONArray filters = jsonObject.getJSONArray("filter"); for(int i=0;i hash = SLDUtil.parseSLD(new URL(url), layers); -// assertNotNull(hash.get("content")); -// assertEquals(hash.get("charset"), "UTF-8"); -// } - - private void testInsertFilter(final String filePattern, final String rulePattern) throws Exception { - - ClassLoader classloader = Thread.currentThread().getContextClassLoader(); - Filter customFilter = SLDUtil.generateCustomFilter(new JSONObject(this.getRessourceAsString("sld/test-sld-" + rulePattern + ".json"))); - - Element root = Xml.loadFile(classloader.getResource("sld/sxt-" + filePattern + "-sld.xml")); - SLDUtil.insertFilter(root, customFilter); - - XMLOutputter outputter = new XMLOutputter(); - Document doc = new Document(root); - - String sldDoc = outputter.outputString(doc); - - org.xmlunit.diff.Diff diff = DiffBuilder - .compare(Input.fromString(sldDoc)) - .withTest(Input.fromString( - this.getRessourceAsString("sld/sxt-" + filePattern + "-sld-merged.xml") - )) - .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)) - .ignoreWhitespace() - .checkForSimilar() - .build(); - - assertFalse( - "Process does not alter the document.", - diff.hasDifferences()); + @Test(expected = JSONException.class) + public void testGenerateCustomFilterInvalidParamCount() throws JSONException { + JSONObject json = new JSONObject(); + JSONArray filters = new JSONArray(); + JSONObject filter1 = new JSONObject(); + filter1.put("field_name", "name"); + JSONArray filterArray = new JSONArray(); + JSONObject filterDetails = new JSONObject(); + filterDetails.put("filter_type", "PropertyIsEqualTo"); + JSONArray params = new JSONArray(); // Empty params, should fail + filterDetails.put("params", params); + filterArray.put(filterDetails); + filter1.put("filter", filterArray); + filters.put(filter1); + json.put("filters", filters); + + SLDUtil.generateCustomFilter(json); + } + + @Test(expected = JSONException.class) + public void testGenerateCustomFilterUnknownType() throws JSONException { + JSONObject json = new JSONObject(); + JSONArray filters = new JSONArray(); + JSONObject filter1 = new JSONObject(); + filter1.put("field_name", "name"); + JSONArray filterArray = new JSONArray(); + JSONObject filterDetails = new JSONObject(); + filterDetails.put("filter_type", "UnknownType"); + JSONArray params = new JSONArray(); + params.put("val"); + filterDetails.put("params", params); + filterArray.put(filterDetails); + filter1.put("filter", filterArray); + filters.put(filter1); + json.put("filters", filters); + + SLDUtil.generateCustomFilter(json); } - private String getRessourceAsString(String name) throws IOException { - ClassLoader classloader = Thread.currentThread().getContextClassLoader(); - BufferedReader buffer = new BufferedReader(new InputStreamReader(classloader.getResourceAsStream(name))); - String line = ""; - StringBuilder res = new StringBuilder(); - while ((line = buffer.readLine()) != null) - res.append(line); + @Test + public void testGenerateCustomFilterPropertyIsBetweenExclusive() throws JSONException { + JSONObject json = new JSONObject(); + JSONArray filters = new JSONArray(); + JSONObject filter1 = new JSONObject(); + filter1.put("field_name", "age"); + JSONArray filterArray = new JSONArray(); + JSONObject filterDetails = new JSONObject(); + filterDetails.put("filter_type", "PropertyIsBetweenExclusive"); + JSONArray params = new JSONArray(); + params.put(10); + params.put(20); + filterDetails.put("params", params); + filterArray.put(filterDetails); + filter1.put("filter", filterArray); + filters.put(filter1); + json.put("filters", filters); - return res.toString(); + Filter filter = SLDUtil.generateCustomFilter(json); + assertNotNull(filter); + String filterStr = filter.toString(); + assertTrue(filterStr.contains("age") && filterStr.contains("10") && filterStr.contains("20")); } + @Test + public void testGenerateCustomFilterPropertyIsNull() throws JSONException { + JSONObject json = new JSONObject(); + JSONArray filters = new JSONArray(); + JSONObject filter1 = new JSONObject(); + filter1.put("field_name", "name"); + JSONArray filterArray = new JSONArray(); + JSONObject filterDetails = new JSONObject(); + filterDetails.put("filter_type", "PropertyIsNull"); + JSONArray params = new JSONArray(); // No params needed + filterDetails.put("params", params); + filterArray.put(filterDetails); + filter1.put("filter", filterArray); + filters.put(filter1); + json.put("filters", filters); + + Filter filter = SLDUtil.generateCustomFilter(json); + assertNotNull(filter); + String filterStr = filter.toString(); + assertTrue(filterStr.contains("name") && (filterStr.contains("null") || filterStr.contains("NULL") || filterStr.contains("is null"))); + } } diff --git a/docs/manual/docs/user-guide/analyzing/data.md b/docs/manual/docs/user-guide/analyzing/data.md index 05860381bc4b..4fd8faf5c92b 100644 --- a/docs/manual/docs/user-guide/analyzing/data.md +++ b/docs/manual/docs/user-guide/analyzing/data.md @@ -18,7 +18,7 @@ Once indexed, all users can access the filtering menu providing: - a control to display or not the heatmap - facets on all fields (computing automatically range facet for numbers) - table action display all values -- filter action apply the filters to the WMS layers using SLD +- filter action apply the filters to the WMS layers via the WMS `FILTER` parameter ![](img/filtering.png) diff --git a/domain/src/main/java/org/fao/geonet/domain/TextFile.java b/domain/src/main/java/org/fao/geonet/domain/TextFile.java deleted file mode 100644 index 0b70a8a73539..000000000000 --- a/domain/src/main/java/org/fao/geonet/domain/TextFile.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.fao.geonet.domain; - -import javax.persistence.*; - -/** - * An entity representing a text file with mime type. - * - */ - -@Entity -@Table(name = "files") -@SequenceGenerator(name= TextFile.ID_SEQ_NAME, initialValue=1, allocationSize=1) -public class TextFile extends GeonetEntity { - - static final String ID_SEQ_NAME = "files_id_seq"; - - private int _id; - private String _content; - private String _mimeType; - - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = TextFile.ID_SEQ_NAME) - @Column(nullable = false) - public int getId() { - return this._id; - } - - @Column(nullable = false) - @Lob - public String getContent() { - return this._content; - } - - @Column(nullable = false) - public String getMimeType() { - return this._mimeType; - } - - public TextFile setId(int id) { - this._id = id; - return this; - } - - public TextFile setMimeType(String mimeType) { - this._mimeType = mimeType; - return this; - } - - public TextFile setContent(String content) { - this._content = content; - return this; - } - - @Override - public int hashCode() { - final int prime = 31; - int hash = 1; - hash = prime * hash + this._id; - return hash; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - TextFile other = (TextFile) obj; - return this._id == other._id; - } - -} diff --git a/domain/src/main/java/org/fao/geonet/repository/TextFileRepository.java b/domain/src/main/java/org/fao/geonet/repository/TextFileRepository.java deleted file mode 100644 index b4b093548e60..000000000000 --- a/domain/src/main/java/org/fao/geonet/repository/TextFileRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.fao.geonet.repository; - -import org.fao.geonet.domain.TextFile; - -/** - * Data Access object for the {@link TextFile} entities. - */ -public interface TextFileRepository extends GeonetRepository {} diff --git a/services/src/main/java/org/fao/geonet/api/sld/SldApi.java b/services/src/main/java/org/fao/geonet/api/sld/SldApi.java index fc8cd2dfc475..8ee346ff340c 100644 --- a/services/src/main/java/org/fao/geonet/api/sld/SldApi.java +++ b/services/src/main/java/org/fao/geonet/api/sld/SldApi.java @@ -1,3 +1,26 @@ +/* + * Copyright (C) 2001-2026 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: geonetwork@osgeo.org + */ + package org.fao.geonet.api.sld; import static org.fao.geonet.api.ApiParams.API_CLASS_TOOLS_OPS; @@ -5,191 +28,28 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import jeeves.transaction.TransactionManager; -import jeeves.transaction.TransactionTask; -import org.apache.commons.lang3.StringUtils; -import org.fao.geonet.ApplicationContextHolder; -import org.fao.geonet.api.exception.ResourceNotFoundException; import org.fao.geonet.constants.Geonet; -import org.fao.geonet.domain.TextFile; -import org.fao.geonet.kernel.setting.SettingManager; -import org.fao.geonet.repository.TextFileRepository; -import org.fao.geonet.utils.Xml; import org.geonetwork.map.wms.SLDUtil; -import org.geotools.ows.ServiceException; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; import org.json.JSONException; import org.json.JSONObject; import org.geotools.api.filter.Filter; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.stereotype.Service; -import org.springframework.transaction.TransactionStatus; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import javax.mail.internet.ParseException; -import javax.servlet.http.HttpServletResponse; -import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -@Service @RequestMapping(value = { "/{portal}/api/tools/ogc" }) @Tag(name = API_CLASS_TOOLS_TAG, description = API_CLASS_TOOLS_OPS) +@Controller("tools") public class SldApi { public static final String LOGGER = Geonet.GEONETWORK + ".api.sld"; - @Autowired - TextFileRepository fileRepository; - @Autowired - SettingManager settingManager; - - @io.swagger.v3.oas.annotations.Operation(summary = "Test form", hidden = true) - @GetMapping(value = "/sldform") - @ResponseBody - @ResponseStatus(value = HttpStatus.OK) - public String getSLDTestingForm() { - - return "" + - "
" + - "Server URL : " + - "
" + - "Layers :" + - "
" + - "JSON Custom filters : " + - "
" + - "" + - "
" + - ""; - } - - @io.swagger.v3.oas.annotations.Operation(summary = "Get the list of SLD available") - @GetMapping(value = "/sld", - produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - @ResponseStatus(value = HttpStatus.OK) - public List getSLD() { - List files = fileRepository.findAll(); - List response = new ArrayList<>(files.size()); - for (TextFile file : files) { - response.add( - settingManager.getNodeURL() + "api/tools/ogc/sld/" + file.getId() + ".xml"); - } - return response; - - } - - @io.swagger.v3.oas.annotations.Operation(summary = "Remove all SLD files", - description = "Clean all SLD generated previously") - @DeleteMapping(value = "/sld", - produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - @ResponseStatus(value = HttpStatus.OK) - public void deteleSLD() { - fileRepository.deleteAll(); - } - - - @io.swagger.v3.oas.annotations.Operation(summary = "Generate a SLD with a new filter", - description = "Get the current SLD for the requested layers, add new filters in, save the SLD and return the new SLD URL.") - @PostMapping(value = "/sld", - consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, - produces = MediaType.TEXT_PLAIN_VALUE) - @ResponseStatus(value = HttpStatus.CREATED) - public - @ResponseBody - String buildSLD( - @Parameter(description = "The WMS server URL", - required = true) - @RequestParam("url") String serverURL, - @Parameter(description = "The layers", - required = true) - @RequestParam("layers") String layers, - @Parameter(description = "The filters in JSON", - required = true) - @RequestParam("filters") String filters) throws ServiceException, JSONException, ParseException, IOException, JDOMException, URISyntaxException { - - Map hash = SLDUtil.parseSLD(new URI(serverURL), layers); - - Element root = Xml.loadString(hash.get("content"), false); - - if (root.getName().equals("ServiceExceptionReport")) { - throw new ServiceException("The WMS GetStyle request failed."); - } - Filter customFilter = SLDUtil.generateCustomFilter(new JSONObject(filters)); - SLDUtil.insertFilter(root, customFilter); - - String charset = hash.get("charset"); - Format format = Format.getPrettyFormat(); - if (StringUtils.isNoneEmpty(charset)) { - format.setEncoding(charset); - } - XMLOutputter outputter = new XMLOutputter(format); - Document doc = new Document(root); - String sldDoc = outputter.outputString(doc); - - TextFile sld = new TextFile(); - sld.setContent(sldDoc); - sld.setMimeType("application/xml"); - - TransactionManager.runInTransaction("sldApi", ApplicationContextHolder.get(), - TransactionManager.TransactionRequirement.CREATE_NEW, - TransactionManager.CommitBehavior.ALWAYS_COMMIT, - false, new TransactionTask() { - @Override - public Void doInTransaction(TransactionStatus transaction) throws Throwable { - fileRepository.saveAndFlush(sld); - return null; - } - } - ); - - return settingManager.getNodeURL() + "api/tools/ogc/sld/" + sld.getId() + ".xml"; - } - @io.swagger.v3.oas.annotations.Operation(summary = "Generate an OGC filter", description = "From a JSON filter, return an OGC filter expression.") @PostMapping(value = "/filter", @@ -206,43 +66,4 @@ String buildFilter( Filter customFilter = SLDUtil.generateCustomFilter(new JSONObject(filters)); return SLDUtil.encodeFilter(customFilter); } - - @io.swagger.v3.oas.annotations.Operation(summary = "Download a SLD", - description = "") - @GetMapping(value = "/sld/{id:\\d+}.{extension}", - produces = MediaType.APPLICATION_XML_VALUE) - @ResponseStatus(value = HttpStatus.OK) - public void downloadSLD( - @Parameter(description = "The SLD identifier", - required = true) - @PathVariable("id") int id, - @PathVariable("extension") String extension, - HttpServletResponse response) throws ResourceNotFoundException { - try { - Optional file = fileRepository.findById(id); - // Validate that the file id found matches the extension - if (file.isPresent() && !StringUtils.isEmpty(extension)) { - Path path = new File(id + "." + extension).toPath(); - String extensionMimeType = Files.probeContentType(path); - if (!file.get().getMimeType().equals(extensionMimeType)) { - throw new ResourceNotFoundException(String.format( - "SLD '%s' with extension '%s' not found. ", - id, extension)); - } - - response.setContentType(file.get().getMimeType() + "; charset=utf-8"); - PrintWriter writer = response.getWriter(); - writer.write(file.get().getContent()); - writer.flush(); - } else { - throw new ResourceNotFoundException(String.format( - "SLD '%s' not found. ", - id)); - } - } catch (Exception e) { - throw new ResourceNotFoundException(String.format( - "SLD '%s' not found. ", - id)); - } - } } diff --git a/services/src/test/java/org/fao/geonet/api/sld/TextFileTest.java b/services/src/test/java/org/fao/geonet/api/sld/TextFileTest.java deleted file mode 100644 index 0de528d602a7..000000000000 --- a/services/src/test/java/org/fao/geonet/api/sld/TextFileTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.fao.geonet.api.sld; - -import org.fao.geonet.domain.TextFile; -import org.fao.geonet.repository.AbstractSpringDataTest; -import org.fao.geonet.repository.TextFileRepository; -import org.fao.geonet.services.AbstractServiceIntegrationTest; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Test File service - */ -public class TextFileTest extends AbstractServiceIntegrationTest { - - @Autowired - private TextFileRepository textFileRepository; - - @Test - public void testStoreLoadFile() throws IOException { - - TextFile sld = new TextFile(); - sld.setContent(this.getRessourceAsString("test-sld-merged.xml")); - sld.setMimeType("application/xml"); - textFileRepository.save(sld); - int id = sld.getId(); - assertTrue(id > 0); - - TextFile file = textFileRepository.findById(id).get(); - file.getContent(); - - assertEquals(this.getRessourceAsString("test-sld-merged.xml"),file.getContent()); - - } - - private String getRessourceAsString(String name) throws IOException { - ClassLoader classloader = Thread.currentThread().getContextClassLoader(); - BufferedReader buffer = new BufferedReader(new InputStreamReader(classloader.getResourceAsStream(name))); - String line = ""; - StringBuilder res = new StringBuilder(); - while ((line = buffer.readLine()) != null) - res.append(line); - - return res.toString(); - } - -} diff --git a/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterDirective.js b/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterDirective.js index a76fa85ea0fd..f14f9f45700b 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterDirective.js +++ b/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterDirective.js @@ -97,16 +97,7 @@ var module = angular.module("gn_wfsfilter_directive", []); - module.constant("gnWfsFilterConfig", { - // Define how WMS filter features - // * Inject filter in SLD - // filterStrategy: "SLD" - // * Same but using SLD_BODY parameter (Do not activate it, - // Usually return 414 Request-URI Too Large) - // filterStrategy: "SLD_BODY" - // * Using FILTER parameter (recommended) - filterStrategy: "FILTER" - }); + module.constant("gnWfsFilterConfig", {}); /** * @ngdoc directive @@ -1037,7 +1028,6 @@ ); } if (sldConfig.filters.length > 0) { - var isSld = gnWfsFilterConfig.filterStrategy.indexOf("SLD") === 0; wfsFilterService .getFilter(sldConfig, layer.get("directUrl") || layer.get("url"), ftName) .then( diff --git a/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterService.js b/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterService.js index 14f42fa6fcee..9f5b49e9ce66 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterService.js +++ b/web-ui/src/main/resources/catalog/components/viewer/wfsfilter/WfsFilterService.js @@ -34,7 +34,6 @@ "$http", "$q", "$translate", - "gnWfsFilterConfig", function ( gnIndexRequestManager, gnHttp, @@ -42,8 +41,7 @@ gnGlobalSettings, $http, $q, - $translate, - gnWfsFilterConfig + $translate ) { var indexProxyUrl = gnHttp.getService("featureindexproxy"); @@ -421,140 +419,57 @@ }; /** - * Call generateSLD service to create the SLD and get an url to reach it. + * Call the OGC filter service and return the filter expression. * - * @param {boolean} isSld Request a SLD URL or a OGC FILTER - * @param {Object} rulesObj structure of the SLD rules to apply - * @param {string} wmsUrl url of the WMS service - * @param {string} featureTypeName of the featuretype - * @return {HttpPromise} promise + * @param {Object} rulesObj structure of the filter rules to apply + * @param {string} wmsUrl url of the WMS service (unused, kept for API compatibility) + * @param {string} featureTypeName of the featuretype (unused, kept for API compatibility) + * @return {HttpPromise} promise resolving to an OGC filter string */ this.getFilter = function (rulesObj, wmsUrl, featureTypeName) { - var isSld = gnWfsFilterConfig.filterStrategy.indexOf("SLD") === 0, - params = { - filters: JSON.stringify(rulesObj), - url: wmsUrl, - layers: featureTypeName - }; + var params = { + filters: JSON.stringify(rulesObj) + }; return $http({ method: "POST", - url: "../api/tools/ogc/" + (isSld ? "sld" : "filter"), + url: "../api/tools/ogc/filter", data: $.param(params), headers: { "Content-Type": "application/x-www-form-urlencoded" } - }).then( - function (response) { - if (isSld) { - var url = response.data; - return this.pollSldUrl(url); - } else { - var defer = $q.defer(); - defer.resolve( - response.data.replace('', "") - ); - return defer.promise; - } - }.bind(this) - ); + }).then(function (response) { + var defer = $q.defer(); + defer.resolve( + response.data.replace('', "") + ); + return defer.promise; + }); }; /** - * Apply FILTER or SLD parameter to a layer depending on configuration. + * Apply FILTER parameter to a WMS layer. * - * @param {boolean} layer Map layer - * @param {Object} filterOrSldUrl OGC filter or SLD url or SLD body retrieved from getFilter. + * @param {Object} layer Map layer + * @param {string} filter OGC filter expression retrieved from getFilter. */ - this.applyFilter = function (layer, filterOrSldUrl) { - var isSld = gnWfsFilterConfig.filterStrategy.indexOf("SLD") === 0; - if (isSld) { - var useSldBody = gnWfsFilterConfig.filterStrategy === "SLD_BODY"; - if (useSldBody) { - $http.get(filterOrSldUrl).then(function (response) { - layer.getSource().updateParams({ - SLD_BODY: response.data - }); - }); - } else { - layer.getSource().updateParams({ - SLD: filterOrSldUrl - }); - } - } else { - var layers = layer.getSource().getParams().LAYERS, - isGroupOfNLayers = layers.split(",").length; + this.applyFilter = function (layer, filter) { + var layers = layer.getSource().getParams().LAYERS, + isGroupOfNLayers = layers.split(",").length; - function buildFilterForEachLayers(nbOfLayers, filter) { - if (filter == null) { - return filter; - } - var listOfFilters = ""; - for (var i = 0; i < nbOfLayers; i++) { - listOfFilters += "(" + filter + ")"; - } - return listOfFilters; + function buildFilterForEachLayers(nbOfLayers, f) { + if (f == null) { + return f; } - layer.getSource().updateParams({ - FILTER: isGroupOfNLayers - ? buildFilterForEachLayers(isGroupOfNLayers, filterOrSldUrl) - : filterOrSldUrl - }); + var listOfFilters = ""; + for (var i = 0; i < nbOfLayers; i++) { + listOfFilters += "(" + f + ")"; + } + return listOfFilters; } - }; - - this.pollSldUrl = function (url) { - var defer = $q.defer(); - var pollingTimeout = 100; - var pollingAttempts = 0; - var pollingMaxAttemps = 25; - - var poller = function () { - pollingAttempts++; - $http({ - method: "GET", - url: url - }).then( - function () { - defer.resolve(url); - }, - function (error) { - if (pollingAttempts < pollingMaxAttemps) { - $timeout(poller, pollingTimeout); - } else { - defer.reject(error); - } - } - ); - }; - poller(); - return defer.promise; - }; - - this.pollSldUrl = function (url) { - var defer = $q.defer(); - var pollingTimeout = 100; - var pollingAttempts = 0; - var pollingMaxAttempts = 25; - - var poller = function () { - pollingAttempts++; - $http({ - method: "GET", - url: url - }).then( - function () { - defer.resolve(url); - }, - function (error) { - if (pollingAttempts < pollingMaxAttempts) { - $timeout(poller, pollingTimeout); - } else { - defer.reject(error); - } - } - ); - }; - poller(); - return defer.promise; + layer.getSource().updateParams({ + FILTER: isGroupOfNLayers + ? buildFilterForEachLayers(isGroupOfNLayers, filter) + : filter + }); }; /** diff --git a/web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v4412/migrate-default.sql b/web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v4412/migrate-default.sql index 96914ab80c76..359852783823 100644 --- a/web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v4412/migrate-default.sql +++ b/web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v4412/migrate-default.sql @@ -2,3 +2,6 @@ INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system UPDATE Settings SET value='4.4.12' WHERE name='system/platform/version'; UPDATE Settings SET value='SNAPSHOT' WHERE name='system/platform/subVersion'; + +DROP SEQUENCE IF EXISTS files_id_seq; +DROP TABLE IF EXISTS files; diff --git a/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml b/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml index 960884e6952c..18995416b8c4 100644 --- a/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml +++ b/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml @@ -249,11 +249,6 @@ - - - -