From aca14864505441377a1ac1b706245a6084ca0c83 Mon Sep 17 00:00:00 2001 From: Raymond Kroon Date: Thu, 2 Jun 2016 14:41:40 +0200 Subject: [PATCH] extra funtionality used by PDOK geoserver workspace builder --- .gitignore | 3 + .../rest/GeoServerRESTPublisher.java | 127 ++++++++++++ .../geoserver/rest/GeoServerRESTReader.java | 16 ++ .../rest/decoder/utils/NameLinkElem.java | 15 +- .../rest/encoder/GSLayerEncoder.java | 20 ++ .../rest/encoder/GSLayerGroupEncoder23.java | 15 ++ .../encoder/coverage/GSCoverageEncoder.java | 22 ++ .../datastore/GSGeoTIFFDatastoreEncoder.java | 71 +++++++ .../datastore/GSMosaicDatastoreEncoder.java | 73 +++++++ .../service/GSServiceSettingsEncoder.java | 192 ++++++++++++++++++ .../encoder/utils/PropertyXMLEncoder.java | 7 + 11 files changed, 556 insertions(+), 5 deletions(-) create mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSGeoTIFFDatastoreEncoder.java create mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSMosaicDatastoreEncoder.java create mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/service/GSServiceSettingsEncoder.java diff --git a/.gitignore b/.gitignore index 79dd63f8..bb132e77 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ nb*.xml ./target target + +/.idea +*.iml diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 17a85ba9..8146b907 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -39,6 +39,7 @@ import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder; import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; +import it.geosolutions.geoserver.rest.encoder.service.GSServiceSettingsEncoder; import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager; import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager.ConfigureCoveragesOption; import it.geosolutions.geoserver.rest.manager.GeoServerRESTStyleManager; @@ -3145,4 +3146,130 @@ private static void checkString(String string) { } + public boolean publishServiceLayer(final String workspace, final String servicetype, final GSServiceSettingsEncoder serviceEncoder) { + + if (workspace == null) { + throw new IllegalArgumentException("Null argument"); + } + // TODO: check this usecase, layer should always be defined + if (workspace.isEmpty()) { + throw new IllegalArgumentException("Empty argument"); + } + + // rest/services/w[mfc]s/workspaces/schelpdierwater/settings.xml + final String url = restURL + "/rest/services/" + servicetype + "/workspaces/" + workspace + "/settings.xml"; + + String settingsXml = serviceEncoder.toString(); + LOGGER.debug("URL: " + url); + LOGGER.debug("BODY: " + settingsXml); + + String sendResult = HTTPUtils.putXml(url, settingsXml, gsuser, gspass); + if (sendResult != null) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info( servicetype.toUpperCase() + "Service successfully configured: " + workspace); + } + } else { + if (LOGGER.isWarnEnabled()) + LOGGER.warn("Error configuring " + servicetype.toUpperCase() + " Servic " + workspace + " (" + sendResult + ")"); + } + + return sendResult != null; + } + + public boolean publishWmsServiceLayer(final String workspace, final GSServiceSettingsEncoder serviceEncoder) { + + if (workspace == null) { + throw new IllegalArgumentException("Null argument"); + } + // TODO: check this usecase, layer should always be defined + if (workspace.isEmpty()) { + throw new IllegalArgumentException("Empty argument"); + } + + // rest/services/wms/workspaces/schelpdierwater/settings.xml + final String url = restURL + "/rest/services/wms/workspaces/" + workspace + "/settings.xml"; + + String settingsXml = serviceEncoder.toString(); + LOGGER.debug("URL: " + url); + LOGGER.debug("BODY: " + settingsXml); + + String sendResult = HTTPUtils.putXml(url, settingsXml, gsuser, gspass); + if (sendResult != null) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("WMS Service successfully configured: " + workspace); + } + } else { + if (LOGGER.isWarnEnabled()) + LOGGER.warn("Error configuring WMS Servic " + workspace + " (" + sendResult + ")"); + } + + return sendResult != null; + } + + public boolean publishWfsServiceLayer(final String workspace, final GSServiceSettingsEncoder serviceEncoder) { + + if (workspace == null) { + throw new IllegalArgumentException("Null argument"); + } + // TODO: check this usecase, layer should always be defined + if (workspace.isEmpty()) { + throw new IllegalArgumentException("Empty argument"); + } + + // rest/services/wms/workspaces/schelpdierwater/settings.xml + final String url = restURL + "/rest/services/wfs/workspaces/" + workspace + "/settings.xml"; + + String settingsXml = serviceEncoder.toString(); + LOGGER.debug("URL: " + url); + LOGGER.debug("BODY: " + settingsXml); + + String sendResult = HTTPUtils.putXml(url, settingsXml, gsuser, gspass); + if (sendResult != null) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("WFS Service successfully configured: " + workspace); + } + } else { + if (LOGGER.isWarnEnabled()) + LOGGER.warn("Error configuring WFS Service " + workspace + " (" + sendResult + ")"); + } + + return sendResult != null; + } + public boolean publishMosaicLayer(final String workspace, final String storename, final GSCoverageEncoder cove, final GSLayerEncoder layerEncoder) { + String ftypeXml = cove.toString(); + StringBuilder postUrl = new StringBuilder(restURL).append("/rest/workspaces/").append(workspace).append("/coveragestores/").append(storename).append("/coverages.xml"); + + final String layername = cove.getNativeName(); + + LOGGER.info("URL: " + postUrl.toString()); + LOGGER.info("BODY: " + ftypeXml); + + String configuredResult = HTTPUtils.postXml(postUrl.toString(), ftypeXml, this.gsuser, this.gspass); + boolean published = configuredResult != null; + boolean configured = false; + + if (!published) { + LOGGER.warn("Error in publishing (" + configuredResult + ") " + workspace + ":" + storename + "/" + layername); + } else { + LOGGER.info("Mosaic layer successfully added (layer:" + layername + ")"); + + if (layerEncoder == null) { + if (LOGGER.isErrorEnabled()) + LOGGER.error("GSLayerEncoder is null: Unable to find the defaultStyle for this layer"); + return false; + } + + configured = configureLayer(workspace, layername, layerEncoder); + + if (!configured) { + LOGGER.warn("Error in configuring (" + configuredResult + ") " + workspace + ":" + storename + "/" + layername); + } else { + LOGGER.info("DB layer successfully configured (layer:" + layername + ")"); + } + } + + return published && configured; + } + + } diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java index 5aa06eff..4343a15d 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java @@ -833,6 +833,22 @@ public RESTFeatureTypeList getFeatureTypes(String workspace) { return RESTFeatureTypeList.build(load(url)); } + public RESTFeatureTypeList getFeatureTypes(String workspace, String list) { + String url = "/rest/workspaces/" + workspace + "/featuretypes.xml?list=" + list; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("### Retrieving featuretypes from " + url); + } + return RESTFeatureTypeList.build(load(url)); + } + + public RESTCoverageList getCoverageNames(String workspace, String coveragestorename, String list) { + String url = "/rest/workspaces/" + workspace + "/coveragestores/" + coveragestorename + "/coverages.xml?list=" + list; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("### Retrieving coveragenames from " + url); + } + return RESTCoverageList.build(load(url)); + } + /** * Get detailed info about a given Layer. * diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/NameLinkElem.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/NameLinkElem.java index 0c773932..93fdbaab 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/NameLinkElem.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/utils/NameLinkElem.java @@ -32,14 +32,19 @@ * @author ETj (etj at geo-solutions.it) */ public class NameLinkElem { - private final Element elem; + private final Element elem; - public NameLinkElem(Element elem) { + public NameLinkElem(Element elem) { this.elem = elem; } - public String getName() { - return elem.getChildText("name"); - } + public String getName() { + return elem.getChildText("name"); + } + + public String getValue() { + + return elem.getContent(0).getValue(); + } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java index e022c2dc..a1acbfb1 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java @@ -211,6 +211,26 @@ public void addStyle(String style) { stylesEncoder.addContent(el); } + /** + * + * @param styleName + * @param workspaceName + */ + public void addStyle(String styleName, String workspaceName) { + final Element el = new Element("style"); + + Element name = new Element("name"); + Element workspace = new Element("workspace"); + + name.setText(styleName); + workspace.setText(workspaceName); + + el.addContent(name); + el.addContent(workspace); + + stylesEncoder.addContent(el); + } + /** * delete a style from the list of available styles * diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder23.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder23.java index 248ca302..e7c3ffd3 100755 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder23.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoder23.java @@ -91,6 +91,21 @@ public void addLayer(String layer, String styleName) { style.addContent(elem("name", styleName)); } } + + public void addLayer(String layer, String styleName, String styleWorkspace) { + initPublishables("publishables"); + + publishablesElem.addContent( + new Element("published").setAttribute("type", "layer").addContent( + elem("name", layer))); + + Element style = new Element("style"); + stylesElem.addContent(style); + if (styleName != null) { + style.addContent(elem("name", styleName)); + style.addContent(elem("workspace", styleWorkspace)); + } + } public void addLayerGroup(String group) { initPublishables("publishables"); diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java index 4b506e17..bb7b2e37 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java @@ -182,4 +182,26 @@ public String getNativeCoverageName() { return null; } + public void addRequestSRS(String[] requestsrslist) { + + Element requestsrs = new Element("requestSRS"); + + for (String request : requestsrslist) { + new Element("requestSRS").addContent(new Element("string").setText(request)); + } + + addContent(requestsrs); + } + + public void addResponseSRS(String[] responsesrslist) { + + Element responsesrs = new Element("responseSRS"); + + for (String response : responsesrslist) { + responsesrs.addContent(new Element("string").setText(response)); + } + + addContent(responsesrs); + } + } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSGeoTIFFDatastoreEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSGeoTIFFDatastoreEncoder.java new file mode 100644 index 00000000..be41d5d6 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSGeoTIFFDatastoreEncoder.java @@ -0,0 +1,71 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2012 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package it.geosolutions.geoserver.rest.encoder.datastore; + +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; +import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder; +import it.geosolutions.geoserver.rest.encoder.utils.XmlElement; + +import java.net.URL; + +/** + * Encoder for a {@value #TYPE} datastore. + * + * @author Peter van de Riet + */ +public class GSGeoTIFFDatastoreEncoder extends GSAbstractStoreEncoder { + static final String TYPE = "GeoTIFF"; + + public GSGeoTIFFDatastoreEncoder(String name) { + super(StoreType.COVERAGESTORES, name); + setName(name); + + // Set mandatory parameter + setType(TYPE); + add("enabled", "true"); + } + + public void setUrl(URL url) { + add("url", url.toString()); + } + /** + * @return {@value #TYPE} + */ + protected String getValidType() { + return TYPE; + } + + public void setWorkspaceName(String workspaceName) { + GsWorkspaceElement workspaceXml = new GsWorkspaceElement(workspaceName); + addContent(workspaceXml.getRoot()); + } + + private class GsWorkspaceElement extends XmlElement { + public GsWorkspaceElement(String workspaceName) { + super("workspace"); + add("name", workspaceName); + } + } +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSMosaicDatastoreEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSMosaicDatastoreEncoder.java new file mode 100644 index 00000000..27f49c2d --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/datastore/GSMosaicDatastoreEncoder.java @@ -0,0 +1,73 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2012 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package it.geosolutions.geoserver.rest.encoder.datastore; + +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; +import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder; +import it.geosolutions.geoserver.rest.encoder.utils.XmlElement; + +import java.net.URL; + +/** + * Encoder for a {@value #TYPE} datastore. + * + * @author Peter van de Riet + */ +public class GSMosaicDatastoreEncoder extends GSAbstractStoreEncoder { + static final String TYPE = "ImageMosaic"; + + public GSMosaicDatastoreEncoder(String name) { + super(StoreType.COVERAGESTORES, name); +// super(name); + setName(name); + + // Set mandatory parameter + setType(TYPE); + add("enabled", "true"); + } + + public void setUrl(URL url) { + add("url", url.toString()); + } + + /** + * @return {@value #TYPE} + */ + protected String getValidType() { + return TYPE; + } + + public void setWorkspaceName(String workspaceName) { + GsWorkspaceElement workspaceXml = new GsWorkspaceElement(workspaceName); + addContent(workspaceXml.getRoot()); + } + + private class GsWorkspaceElement extends XmlElement { + public GsWorkspaceElement(String workspaceName) { + super("workspace"); + add("name", workspaceName); + } + } +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/service/GSServiceSettingsEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/service/GSServiceSettingsEncoder.java new file mode 100644 index 00000000..f8d72268 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/service/GSServiceSettingsEncoder.java @@ -0,0 +1,192 @@ +package it.geosolutions.geoserver.rest.encoder.service; + +import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; +import org.jdom.Element; + +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: nijhur + * Date: 9-10-14 + * Time: 8:46 + */ +public class GSServiceSettingsEncoder extends PropertyXMLEncoder { + + public final static String WORKSPACESTRING = "workspace"; + public final static String NAMESTRING = "name"; + public final static String KEYWORDS = "keywords"; + public final static String METADATA = "metadata"; + + + private final static String MAINTAINER = "http://www.geonovum.nl/dossiers/pdok"; + private final static String SCHEMABASEURL = "http://schemas.opengis.net"; + + final private Element workspaceElement = new Element(WORKSPACESTRING); + final private Element nameElement = new Element(NAMESTRING); + final private Element keywordsElement = new Element(KEYWORDS); + final private Element metadata = new Element(METADATA); + + + + public GSServiceSettingsEncoder(String type, String serviceMetadataId) { + super(type.toLowerCase()); + addEnabled(); + addContent(workspaceElement); + nameElement.setText(type.toUpperCase()); + addContent(nameElement); + addContent(keywordsElement); + addContent(metadata); + if ( "WMS".equals(type.toUpperCase())){ + addWmsMetadata(serviceMetadataId); + addWmsDefaultFields(); + + } else if ("WFS".equals(type.toUpperCase())){ + addWfsMetadata(serviceMetadataId); + addWfsDefaultFields(); + } + } + + public void addWfsGmlSettings(){ + String[][] data = new String[][] { { "V_11", "URN", "false" }, {"V_20", "URN2", "false"}, {"V_10", "XML", "true"} }; + Element root = new Element("gml"); + for(String[] entryData : data ){ + Element entry = new Element("entry"); + + Element version = new Element("version"); + version.setText(entryData[0]); + entry.addContent(version); + + Element gml = new Element("gml"); + + Element style = new Element("srsNameStyle"); + style.setText(entryData[1]); + gml.addContent(style); + + Element override = new Element("overrideGMLAttributes"); + override.setText(entryData[2]); + gml.addContent(override); + + entry.addContent(gml); + + root.addContent(entry); + } + + addContent(root); + + } + + + private void addWmsMetadata(String wmsMetadataId){ + String ENTRY = "entry"; + String KEY = "key"; + metadata.addContent( createElementWithAttribute(ENTRY, "20", KEY, "jpegCompression")); + metadata.addContent( createElementWithAttribute(ENTRY, "100", KEY, "pngCompression")); + metadata.addContent( createElementWithAttribute(ENTRY, "auto", KEY, "kmlSuperoverlayMode")); + metadata.addContent( createElementWithAttribute(ENTRY, "1000", KEY, "framesDelay")); + metadata.addContent( createElementWithAttribute(ENTRY, "refresh", KEY, "kmlReflectorMode")); + metadata.addContent( createElementWithAttribute(ENTRY, "", KEY, "inspire.spatialDatasetIdentifier")); + metadata.addContent( createElementWithAttribute(ENTRY, "dut", KEY, "inspire.language")); + metadata.addContent( createElementWithAttribute(ENTRY, "40", KEY, "kmlKmscore")); + metadata.addContent( createElementWithAttribute(ENTRY, "true", KEY, "svgAntiAlias")); + metadata.addContent( createElementWithAttribute(ENTRY, "http://www.nationaalgeoregister.nl/geonetwork/srv/eng/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=" + wmsMetadataId, KEY, "inspire.metadataURL")); + metadata.addContent( createElementWithAttribute(ENTRY, "false", KEY, "kmlPlacemark")); + metadata.addContent( createElementWithAttribute(ENTRY, "true", KEY, "kmlAttr")); + metadata.addContent( createElementWithAttribute(ENTRY, "2147483647", KEY, "maxAllowedFrames")); + metadata.addContent( createElementWithAttribute(ENTRY, "[{'name': 'PDOK', 'href' : 'http://www.pdok.nl", KEY, "authorityURLs'")); + metadata.addContent( createElementWithAttribute(ENTRY, "application/vnd.ogc.csw.GetRecordByIdResponse_xml", KEY, "inspire.metadataURLType")); + metadata.addContent( createElementWithAttribute(ENTRY, "false", KEY, "loopContinuously")); + metadata.addContent( createElementWithAttribute(ENTRY, "Batik", KEY, "svgRenderer")); + } + + private void addWfsMetadata(String wfsMetadataId){ + String ENTRY = "entry"; + String KEY = "key"; + metadata.addContent( createElementWithAttribute(ENTRY, "false", KEY, "SHAPE-ZIP_DEFAULT_PRJ_IS_ESRI")); + metadata.addContent( createElementWithAttribute(ENTRY, wfsMetadataId, KEY, "inspire.spatialDatasetIdentifier")); + metadata.addContent( createElementWithAttribute(ENTRY, "application/vnd.ogc.csw.GetRecordByIdResponse_xml", KEY, "inspire.metadataURLType")); + metadata.addContent( createElementWithAttribute(ENTRY, "http://www.nationaalgeoregister.nl/geonetwork/srv/eng/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=" + wfsMetadataId, KEY, "inspire.metadataURL")); + } + + private void addWmsDefaultFields(){ + add("maintainer", MAINTAINER); + add("schemaBaseURL", "http://schemas.opengis.net"); + add("bboxForEachCRS", "true"); + //addWatermark(); + add("maxBuffer", "25"); + add("maxRequestMemory", "270336"); + add("maxRenderingTime", "60"); + add("maxRenderingErrors", "1000"); + } + + private void addWfsDefaultFields(){ + add("schemaBaseURL", SCHEMABASEURL); + add("serviceLevel", "BASIC"); + add("maxFeatures", "15000"); + add("featureBounding", "false"); + add("canonicalSchemaLocation", "false"); + add("encodeFeatureMember", "false"); + addWfsGmlSettings(); + } + + public void setWorkspace(String workspaceName){ + final Element name = new Element(NAMESTRING); + name.setText(workspaceName); + workspaceElement.addContent(name); + } + + private void addWatermark(){ + Element watermark = new Element("watermark"); + + Element enabled = new Element("enabled"); + enabled.setText("false"); + watermark.addContent(enabled); + + Element position = new Element("position"); + enabled.setText("BOT_RIGHT"); + watermark.addContent(position); + + Element transparency = new Element("transparency"); + enabled.setText("0"); + watermark.addContent(transparency); + + addContent(watermark); + } + + protected void addEnabled(){ + add("enabled","true"); + } + + public void setTitle(String title){ + add("title", title); + } + + public void setAbstract(String abstractText){ + add("abstrct", abstractText); + } + + public void setAccessConstraints(String accessConstraints){ + add("accessConstraints", accessConstraints); + } + + public void setFees(String fees){ + add("fees", fees); + } + + public void setSrs(List values){ + Element srs = new Element("srs"); + for (String value : values){ + Element valueElement = new Element("string"); + valueElement.setText(value); + srs.addContent(valueElement); + } + addContent(srs); + } + + public void addKeyword(String keyword){ + Element valueElement = new Element("string"); + valueElement.setText(keyword); + keywordsElement.addContent(valueElement); + } + +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java index ec03cc98..bf460317 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java @@ -134,6 +134,13 @@ private void add(Element e, String key, String value) { } + protected Element createElementWithAttribute(String elementName, String elementValue, String attributeName, String attributeValue){ + Element result = new Element(elementName); + result.setAttribute(attributeName, attributeValue); + result.setText(elementValue); + return result; + } + // public void set(final String key, final String value) { // if (key != null && value != null) { // set(getRoot(), key, value);