From 0bf39aae8ebab46b50ad28f0887ffa93151201f1 Mon Sep 17 00:00:00 2001 From: eblondel Date: Sat, 6 Apr 2013 14:28:47 +0200 Subject: [PATCH 1/4] MetadataLink support - add MetadataLinkInfo encoder --- .../GSMetadataLinkInfoEncoder.java | 107 ++++++++++++++++++ .../ResourceMetadataLinkInfo.java | 36 ++++++ 2 files changed, 143 insertions(+) create mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoder.java create mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/ResourceMetadataLinkInfo.java diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoder.java new file mode 100644 index 0000000..14d3994 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoder.java @@ -0,0 +1,107 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 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.metadatalink; + +import java.util.Map; +import java.util.Map.Entry; + +import org.jdom.Element; +import org.jdom.filter.Filter; + +import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; +import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; + +/** GSMetadataLinkEncoder + * + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org + * + */ +public class GSMetadataLinkInfoEncoder extends PropertyXMLEncoder { + + public static class filterByContent implements Filter { + + final private String key; + + public filterByContent(String content){ + this.key=content; + } + + private static final long serialVersionUID = 1L; + + public boolean matches(Object obj) { + Element el=((Element) obj).getChild(ResourceMetadataLinkInfo.content.toString()); + if (el!=null && el.getTextTrim().equals(key)) { + return true; + } + return false; + } + } + + public static Filter getFilterByContent(String content){ + return new filterByContent(content); + } + + + public GSMetadataLinkInfoEncoder() { + super("metadataLink"); + } + + /** quick MetadataLinkInfo set-up + * + * @param type + * @param metadataType + * @param content + */ + public void setup(String type, String metadataType, String content){ + set(ResourceMetadataLinkInfo.type.name(), type); + set(ResourceMetadataLinkInfo.metadataType.name(), metadataType); + set(ResourceMetadataLinkInfo.content.name(), content); + } + + public void setup(Map metadataLinkInfos){ + for (Entry mdLinkInfo:metadataLinkInfos.entrySet()){ + set(mdLinkInfo.getKey().toString(),mdLinkInfo.getValue()); + } + } + + public void setMetadataLinkInfoMember(ResourceMetadataLinkInfo type, String value){ + set(type.toString(),value); + } + + + public boolean delMetadataLinkInfoMember(ResourceMetadataLinkInfo type){ + return ElementUtils.remove(this.getRoot(), get(type.toString())); + } + + + public String getMetadataLinkInfoMember(ResourceMetadataLinkInfo type){ + Element el = get(type.toString()); + if (el!=null) + return el.getTextTrim(); + else + return null; + } + +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/ResourceMetadataLinkInfo.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/ResourceMetadataLinkInfo.java new file mode 100644 index 0000000..3fbb74b --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadatalink/ResourceMetadataLinkInfo.java @@ -0,0 +1,36 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 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.metadatalink; + +/** + * Enumeration of featureType metadataLink member + * + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org + * + */ +public enum ResourceMetadataLinkInfo { + type, metadataType, content + +} From 47282974b5ad7dc2ab49824791c67ad37a690a38 Mon Sep 17 00:00:00 2001 From: eblondel Date: Sat, 6 Apr 2013 14:31:58 +0200 Subject: [PATCH 2/4] MetadataLink support - GSResourceEncoder metadatalink methods --- .../rest/encoder/GSResourceEncoder.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java index 92cb5a7..c43954f 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java @@ -29,6 +29,7 @@ import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder; import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; @@ -46,15 +47,18 @@ import org.jdom.filter.Filter; * * @author ETj (etj at geo-solutions.it) * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org */ public abstract class GSResourceEncoder extends PropertyXMLEncoder { public final static String NAME = "name"; public final static String METADATA="metadata"; public final static String KEYWORDS="keywords"; + public final static String METADATALINKS="metadataLinks"; final private GSMetadataEncoder metadata = new GSMetadataEncoder(); final private Element keywordsListEncoder = new Element(KEYWORDS); + final private Element metadataLinksListEncoder = new Element(METADATALINKS); private class GSMetadataEncoder extends NestedElementEncoder{ public GSMetadataEncoder() { @@ -75,6 +79,7 @@ public abstract class GSResourceEncoder // Link members to the parent addContent(metadata.getRoot()); addContent(keywordsListEncoder); + addContent(metadataLinksListEncoder); } public void setEnabled(boolean enabled) { @@ -136,6 +141,45 @@ public abstract class GSResourceEncoder })).size() == 0 ? false : true; } + /** + * @param MetadataLink the metadataLink to add + * + * @author Emmanuel Blondel + */ + public void addMetadataLinkInfo(GSMetadataLinkInfoEncoder metadataLinkInfo) { + metadataLinksListEncoder.addContent(metadataLinkInfo.getRoot()); + } + + + /** Quick MetadataLinkInfo set-up + * + * @author Emmanuel Blondel + * + * @param type + * @param metadataType + * @param content + */ + public void addMetadataLinkInfo(String type, String metadataType, String content){ + final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder(); + mde.setup(type, metadataType, content); + metadataLinksListEncoder.addContent(mde.getRoot()); + } + + + /** + * delete a metadataLinkInfo from the list using the metadataURL (MetadataLinkInfo content) + * + * @author Emmanuel Blondel + * + * @param metadataURL + * @return true if something is removed, false otherwise + */ + public boolean delMetadataLinkInfo(final String metadataURL) { + return (metadataLinksListEncoder.removeContent(GSMetadataLinkInfoEncoder.getFilterByContent(metadataURL))).size() == 0 ? false + : true; + } + + /** * Reprojection policy for a published layer. One of: *
    From 8adef995c2a597a70fb84bab1d3e5515bfc90205 Mon Sep 17 00:00:00 2001 From: eblondel Date: Sat, 6 Apr 2013 14:35:10 +0200 Subject: [PATCH 3/4] MetadataLink support - RESTResource metadatalink decoder --- .../geoserver/rest/decoder/RESTResource.java | 448 ++++++++++-------- 1 file changed, 252 insertions(+), 196 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java index 9067b49..1997ff9 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java @@ -1,196 +1,252 @@ -/* - * GeoServer-Manager - Simple Manager Library for GeoServer - * - * Copyright (C) 2007,2011 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.decoder; - -import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; -import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute; -import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.jdom.Element; -import org.jdom.Namespace; - -/** - * Parse a resource (FeatureType or Coverage) returned as XML REST objects. - * - * @author etj - */ -public class RESTResource { - protected final Element rootElem; - - public static RESTResource build(String response) { - Element elem = JDOMBuilder.buildElement(response); - return elem == null ? null : new RESTCoverage(elem); - } - - public RESTResource(Element resource) { - this.rootElem = resource; - } - - public String getName() { - return rootElem.getChildText("name"); - } - - public String getTitle() { - return rootElem.getChildText("title"); - } - - public String getNativeName() { - return rootElem.getChildText("nativeName"); - } - - public String getAbstract() { - return rootElem.getChildText("abstract"); - } - - public String getNameSpace() { - return rootElem.getChild("namespace").getChildText("name"); - } - - public String getStoreName() { - return rootElem.getChild("store").getChildText("name"); - } - - public String getStoreType() { - return rootElem.getChild("store").getAttributeValue("class"); - } - - public String getStoreUrl() { - Element store = rootElem.getChild("store"); - Element atom = store.getChild("link", - Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom")); - return atom.getAttributeValue("href"); - } - - public String getCRS() { - Element elBBox = rootElem.getChild("latLonBoundingBox"); - return elBBox.getChildText("crs"); - } - - protected double getLatLonEdge(String edge) { - Element elBBox = rootElem.getChild("latLonBoundingBox"); - return Double.parseDouble(elBBox.getChildText(edge)); - } - - public double getMinX() { - return getLatLonEdge("minx"); - } - - public double getMaxX() { - return getLatLonEdge("maxx"); - } - - public double getMinY() { - return getLatLonEdge("miny"); - } - - public double getMaxY() { - return getLatLonEdge("maxy"); - } - - public List> getAttributeList() { - List> attrsList = null; - - final Element attrsRoot = rootElem.getChild("attributes"); - final List attrs = attrsRoot.getChildren(); - if (attrs != null) { - attrsList = new ArrayList>(attrs.size()); - for (Element attr : attrs) { - Map attrsMap = new HashMap(); - attrsList.add(attrsMap); - for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) { - String key = at.toString(); - attrsMap.put(at, attr.getChildText(key)); - } - } - } - return attrsList; - } - - public List getEncodedAttributeList() { - List attrsList = null; - - final Element attrsRoot = rootElem.getChild("attributes"); - final List attrs = attrsRoot.getChildren(); - if (attrs != null) { - attrsList = new ArrayList(attrs.size()); - for (Element attr : attrs) { - final GSAttributeEncoder attrEnc = new GSAttributeEncoder(); - for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) { - String key = at.toString(); - attrEnc.setAttribute(at, attr.getChildText(key)); - } - attrsList.add(attrEnc); - } - - } - return attrsList; - } - - // /** - // * @return the list of available attribute names - // */ - // public List getAttributeNames() { - // return getAttributes("name"); - // } - // - // /** - // * @return a list of object which are String representation of Classes - // */ - // public List getAttributeBinding() { - // return getAttributes("binding"); - // } - - // /** - // *
    - // * NATION
    - // * 0
    - // * 1
    - // * true
    - // * java.lang.Integer
    - // * 3
    - // *

    - // * - // * @param name - // * @return - // */ - // private List getAttributes(String name) { - // final Element attrsRoot = rootElem.getChild("attributes"); - // final List attrs = attrsRoot.getChildren(); - // List attrNames = null; - // if (attrs != null) { - // attrNames = new ArrayList(attrs.size()); - // for (Element attr : attrs) { - // attrNames.add(attr.getChildText(name)); - // } - // } - // return attrNames; - // } -} +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 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.decoder; + +import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; +import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute; +import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder; +import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jdom.Element; +import org.jdom.Namespace; + +/** + * Parse a resource (FeatureType or Coverage) returned as XML REST objects. + * + * @author etj + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org + */ +public class RESTResource { + protected final Element rootElem; + + public static RESTResource build(String response) { + Element elem = JDOMBuilder.buildElement(response); + return elem == null ? null : new RESTCoverage(elem); + } + + public RESTResource(Element resource) { + this.rootElem = resource; + } + + public String getName() { + return rootElem.getChildText("name"); + } + + public String getTitle() { + return rootElem.getChildText("title"); + } + + public String getNativeName() { + return rootElem.getChildText("nativeName"); + } + + public String getAbstract() { + return rootElem.getChildText("abstract"); + } + + public String getNameSpace() { + return rootElem.getChild("namespace").getChildText("name"); + } + + public String getStoreName() { + return rootElem.getChild("store").getChildText("name"); + } + + public String getStoreType() { + return rootElem.getChild("store").getAttributeValue("class"); + } + + public String getStoreUrl() { + Element store = rootElem.getChild("store"); + Element atom = store.getChild("link", + Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom")); + return atom.getAttributeValue("href"); + } + + public String getCRS() { + Element elBBox = rootElem.getChild("latLonBoundingBox"); + return elBBox.getChildText("crs"); + } + + protected double getLatLonEdge(String edge) { + Element elBBox = rootElem.getChild("latLonBoundingBox"); + return Double.parseDouble(elBBox.getChildText(edge)); + } + + public double getMinX() { + return getLatLonEdge("minx"); + } + + public double getMaxX() { + return getLatLonEdge("maxx"); + } + + public double getMinY() { + return getLatLonEdge("miny"); + } + + public double getMaxY() { + return getLatLonEdge("maxy"); + } + + public List> getAttributeList() { + List> attrsList = null; + + final Element attrsRoot = rootElem.getChild("attributes"); + final List attrs = attrsRoot.getChildren(); + if (attrs != null) { + attrsList = new ArrayList>(attrs.size()); + for (Element attr : attrs) { + Map attrsMap = new HashMap(); + attrsList.add(attrsMap); + for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) { + String key = at.toString(); + attrsMap.put(at, attr.getChildText(key)); + } + } + } + return attrsList; + } + + public List getEncodedAttributeList() { + List attrsList = null; + + final Element attrsRoot = rootElem.getChild("attributes"); + final List attrs = attrsRoot.getChildren(); + if (attrs != null) { + attrsList = new ArrayList(attrs.size()); + for (Element attr : attrs) { + final GSAttributeEncoder attrEnc = new GSAttributeEncoder(); + for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) { + String key = at.toString(); + attrEnc.setAttribute(at, attr.getChildText(key)); + } + attrsList.add(attrEnc); + } + + } + return attrsList; + } + + /** + * + * @author Emmanuel Blondel + * + * @return the list of metadataLinkInfo + */ + public List> getMetadataLinkInfoList() { + List> metaLinksList = null; + + final Element metaLinksRoot = rootElem.getChild("metadataLinks"); + final List metaLinks = metaLinksRoot.getChildren(); + if (metaLinks != null) { + metaLinksList = new ArrayList>(metaLinks.size()); + for (Element metaLink : metaLinks) { + Map metaLinkMap = new HashMap(); + metaLinksList.add(metaLinkMap); + for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo.values()) { + String key = rmd.toString(); + metaLinkMap.put(rmd, metaLink.getChildText(key)); + } + } + } + return metaLinksList; + } + + + /** + * + * @author Emmanuel Blondel + * + * @return the list of GSMetadataLinkEncoder + */ + public List getEncodedMetadataLinkInfoList() { + List metaLinksList = null; + + final Element metaLinksRoot = rootElem.getChild("metadataLinks"); + final List metaLinks = metaLinksRoot.getChildren(); + if (metaLinks != null) { + metaLinksList = new ArrayList(metaLinks.size()); + for (Element metaLink : metaLinks) { + final GSMetadataLinkInfoEncoder metaLinkEnc = new GSMetadataLinkInfoEncoder(); + for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo.values()) { + String key = rmd.toString(); + metaLinkEnc.setMetadataLinkInfoMember(rmd, metaLink.getChildText(key)); //change + } + metaLinksList.add(metaLinkEnc); + } + + } + return metaLinksList; + } + + + // /** + // * @return the list of available attribute names + // */ + // public List getAttributeNames() { + // return getAttributes("name"); + // } + // + // /** + // * @return a list of object which are String representation of Classes + // */ + // public List getAttributeBinding() { + // return getAttributes("binding"); + // } + + // /** + // *
    + // * NATION
    + // * 0
    + // * 1
    + // * true
    + // * java.lang.Integer
    + // * 3
    + // *

    + // * + // * @param name + // * @return + // */ + // private List getAttributes(String name) { + // final Element attrsRoot = rootElem.getChild("attributes"); + // final List attrs = attrsRoot.getChildren(); + // List attrNames = null; + // if (attrs != null) { + // attrNames = new ArrayList(attrs.size()); + // for (Element attr : attrs) { + // attrNames.add(attr.getChildText(name)); + // } + // } + // return attrNames; + // } +} From b388298afbe356c10af600ff6d14e1258b563abd Mon Sep 17 00:00:00 2001 From: eblondel Date: Sat, 6 Apr 2013 14:43:18 +0200 Subject: [PATCH 4/4] #62 fix MetadataLink support - adding tests --- .../decoder/MetadataDecoderTest.java | 166 ++++--- .../encoder/feature/GSFeatureEncoderTest.java | 448 +++++++++--------- .../GSMetadataLinkInfoEncoderTest.java | 53 +++ .../resources/testdata/coverageExample.xml | 204 ++++---- 4 files changed, 484 insertions(+), 387 deletions(-) create mode 100644 src/test/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoderTest.java diff --git a/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java b/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java index 39a46f2..a70e82a 100644 --- a/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java @@ -1,74 +1,92 @@ -/* - * GeoBatch - Open Source geospatial batch processing system - * https://github.com/nfms4redd/nfms-geobatch - * Copyright (C) 2007-2012 GeoSolutions S.A.S. - * http://www.geo-solutions.it - * - * GPLv3 + Classpath exception - * - * 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 3 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, see . - */ -package it.geosolutions.geoserver.decoder; - -import it.geosolutions.geoserver.rest.decoder.RESTCoverage; -import it.geosolutions.geoserver.rest.decoder.RESTDimensionInfo; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.core.io.ClassPathResource; - -/** - * @author DamianoG - * - */ -public class MetadataDecoderTest { - - - @Test - public void testMetadataDimensionInfo() throws IOException { - - File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile(); - String coverageString = FileUtils.readFileToString(coverageFile); - RESTCoverage coverage = RESTCoverage.build(coverageString); - List list = coverage.getDimensionInfo(); - - Assert.assertEquals(list.size(),2); - - - for (RESTDimensionInfo el : list){ - if(el.getKey().equals("time")){ - Assert.assertEquals(el.getResolution(),null); - Assert.assertEquals(el.getPresentation(),"LIST"); - Assert.assertEquals(el.getKey(),"time"); - Assert.assertEquals(el.isEnabled(),true); - } - if(el.getKey().equals("elevation")){ - Assert.assertEquals(el.getResolution(),"2"); - Assert.assertEquals(el.getPresentation(),"DISCRETE_INTERVAL"); - Assert.assertEquals(el.getKey(),"elevation"); - Assert.assertEquals(el.isEnabled(),true); - } - } - - - - - - } -} +/* + * GeoBatch - Open Source geospatial batch processing system + * https://github.com/nfms4redd/nfms-geobatch + * Copyright (C) 2007-2012 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * GPLv3 + Classpath exception + * + * 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 3 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, see . + */ +package it.geosolutions.geoserver.decoder; + +import it.geosolutions.geoserver.rest.decoder.RESTCoverage; +import it.geosolutions.geoserver.rest.decoder.RESTDimensionInfo; +import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.core.io.ClassPathResource; + +/** + * @author DamianoG + * @author eblondel + * + */ +public class MetadataDecoderTest { + + + @Test + public void testMetadataDimensionInfo() throws IOException { + + File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile(); + String coverageString = FileUtils.readFileToString(coverageFile); + RESTCoverage coverage = RESTCoverage.build(coverageString); + List list = coverage.getDimensionInfo(); + + Assert.assertEquals(list.size(),2); + + + for (RESTDimensionInfo el : list){ + if(el.getKey().equals("time")){ + Assert.assertEquals(el.getResolution(),null); + Assert.assertEquals(el.getPresentation(),"LIST"); + Assert.assertEquals(el.getKey(),"time"); + Assert.assertEquals(el.isEnabled(),true); + } + if(el.getKey().equals("elevation")){ + Assert.assertEquals(el.getResolution(),"2"); + Assert.assertEquals(el.getPresentation(),"DISCRETE_INTERVAL"); + Assert.assertEquals(el.getKey(),"elevation"); + Assert.assertEquals(el.isEnabled(),true); + } + } + } + + @Test + public void testMetadataLinkInfo() throws IOException{ + File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile(); + String coverageString = FileUtils.readFileToString(coverageFile); + RESTCoverage coverage = RESTCoverage.build(coverageString); + + List list = coverage.getEncodedMetadataLinkInfoList(); + + GSMetadataLinkInfoEncoder metadataLinkInfo1 = list.get(0); + Assert.assertEquals(metadataLinkInfo1.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.type),"text/xml"); + Assert.assertEquals(metadataLinkInfo1.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.metadataType),"ISO19115:2003"); + Assert.assertEquals(metadataLinkInfo1.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.content),"http://www.organization.org/metadata1"); + + GSMetadataLinkInfoEncoder metadataLinkInfo2 = list.get(1); + Assert.assertEquals(metadataLinkInfo2.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.type),"text/html"); + Assert.assertEquals(metadataLinkInfo2.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.metadataType),"ISO19115:2003"); + Assert.assertEquals(metadataLinkInfo2.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.content),"http://www.organization.org/metadata2"); + + } +} diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java index 9372f9e..24bd329 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java @@ -1,217 +1,231 @@ -/* - * Copyright (C) 2007 - 2011 GeoSolutions S.A.S. - * http://www.geo-solutions.it - * - * GPLv3 + Classpath exception - * - * 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 3 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, see . - */ -package it.geosolutions.geoserver.rest.encoder.feature; - -import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; -import it.geosolutions.geoserver.rest.decoder.RESTLayer; -import it.geosolutions.geoserver.rest.decoder.RESTResource; -import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; -import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; -import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; -import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation; -import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete; -import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder; -import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; -import it.geosolutions.geoserver.rest.publisher.GeoserverRESTPublisherTest; - -import java.io.File; -import java.io.IOException; -import java.math.BigDecimal; -import java.util.List; - -import org.jdom.Element; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.ClassPathResource; - -/** - * - * @author ETj (etj at geo-solutions.it) - * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it - */ -public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest { - protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class); - - @Test - public void testIntegration() throws IOException { - - if (!enabled()) - return; - deleteAll(); - - GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW); - - String storeName = "resttestshp"; - String layerName = "cities"; - - GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder(); - fte.setName(layerName + "_NEW"); - fte.setTitle("title"); - // fte.addKeyword("TODO"); - fte.setNativeCRS("EPSG:4326"); - fte.setDescription("desc"); - fte.setEnabled(true); - - GSLayerEncoder layerEncoder = new GSLayerEncoder(); - layerEncoder.setEnabled(true); - layerEncoder.setQueryable(true); - - layerEncoder.setDefaultStyle("point"); - - publisher.createWorkspace(DEFAULT_WS); - - File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); - - // test insert - boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile); - assertTrue("publish() failed", published); - assertTrue(existsLayer(layerName)); - - publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(), - "default_point.sld")); - - // optionally select the attributes to publish - RESTLayer layer = reader.getLayer(layerName); - RESTResource resource = reader.getResource(layer); - List attrs = resource.getEncodedAttributeList(); - assertNotNull(attrs); - for (GSAttributeEncoder enc : attrs) { - fte.setAttribute(enc); - } - - assertTrue(publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder)); - } - - @Test - public void testFeatureTypeEncoder() { - - GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder(); - encoder.addKeyword("KEYWORD_1"); - encoder.addKeyword("KEYWORD_2"); - encoder.addKeyword("..."); - encoder.addKeyword("KEYWORD_N"); - - encoder.setName("Layername"); - - encoder.setTitle("title"); - encoder.addKeyword("TODO"); - encoder.setNativeCRS("EPSG:4326"); - encoder.setDescription("desc"); - encoder.setEnabled(true); - - GSAttributeEncoder attribute = new GSAttributeEncoder(); - attribute.setAttribute(FeatureTypeAttribute.name, "NAME"); - attribute.setAttribute(FeatureTypeAttribute.binding, "java.lang.String"); - attribute.setAttribute(FeatureTypeAttribute.maxOccurs, "1"); - attribute.setAttribute(FeatureTypeAttribute.minOccurs, "0"); - attribute.setAttribute(FeatureTypeAttribute.nillable, "true"); - - encoder.setAttribute(attribute); - - encoder.delAttribute("NAME"); - - attribute.setAttribute(FeatureTypeAttribute.name, "NEW_NAME"); - - encoder.setAttribute(attribute); - - // TODO encoder.getAttribute("NAME"); - - GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder("ELE"); - - encoder.addMetadata("elevation", dim2); - dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(10)); - Element el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION); - Assert.assertNotNull(el); - - LOGGER.info("contains_key:" + el.toString()); - - dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(12)); - el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.RESOLUTION); - Assert.assertNotNull(el); - Assert.assertEquals("12", el.getText()); - - dim2.setPresentation(Presentation.CONTINUOUS_INTERVAL); - - encoder.setMetadata("time", new GSFeatureDimensionInfoEncoder("time")); - el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION); - Assert.assertNotNull(el); - el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.RESOLUTION); - Assert.assertNull(el); - - el = ElementUtils.contains(encoder.getRoot(), GSResourceEncoder.METADATA); - Assert.assertNotNull(el); - LOGGER.info("contains_key:" + el.toString()); - - final boolean removed = ElementUtils.remove(encoder.getRoot(), el); - LOGGER.info("remove:" + removed); - Assert.assertTrue(removed); - - el = ElementUtils.contains(encoder.getRoot(), "metadata"); - Assert.assertNull(el); - if (el == null) - LOGGER.info("REMOVED"); - - if (LOGGER.isInfoEnabled()) - LOGGER.info(encoder.toString()); - - assertEquals(encoder.getName(),"Layername"); - } - - @Test - public void testModifyFeature() { - GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder(); - encoder.addKeyword("KEYWORD_1"); - encoder.addKeyword("KEYWORD_2"); - encoder.addKeyword("..."); - encoder.addKeyword("KEYWORD_N"); - - Assert.assertTrue(encoder.delKeyword("KEYWORD_2")); - Assert.assertFalse(encoder.delKeyword("KEYWORD_M")); - - final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder( - "elevation_field"); - - // if (LOGGER.isInfoEnabled()) - // LOGGER.info(encoder.toString()); - - final String metadata = "elevation"; - encoder.setMetadata(metadata, elevationDimension); - - elevationDimension.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, - BigDecimal.valueOf(10)); - - if (LOGGER.isInfoEnabled()) - LOGGER.info(encoder.toString()); - - Assert.assertTrue(encoder.delMetadata(metadata)); - - if (LOGGER.isInfoEnabled()) - LOGGER.info(encoder.toString()); - - final Element el = ElementUtils.contains(encoder.getRoot(), - GSDimensionInfoEncoder.DIMENSIONINFO); - Assert.assertNull(el); - if (el == null) - LOGGER.info("REMOVED"); - - } -} +/* + * Copyright (C) 2007 - 2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * GPLv3 + Classpath exception + * + * 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 3 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, see . + */ +package it.geosolutions.geoserver.rest.encoder.feature; + +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; +import it.geosolutions.geoserver.rest.decoder.RESTLayer; +import it.geosolutions.geoserver.rest.decoder.RESTResource; +import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; +import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; +import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation; +import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete; +import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; +import it.geosolutions.geoserver.rest.publisher.GeoserverRESTPublisherTest; + +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.List; + +import org.jdom.Element; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.ClassPathResource; + +/** + * + * @author ETj (etj at geo-solutions.it) + * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it + */ +public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest { + protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class); + + @Test + public void testIntegration() throws IOException { + + if (!enabled()) + return; + deleteAll(); + + GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW); + + String storeName = "resttestshp"; + String layerName = "cities"; + + GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder(); + fte.setName(layerName + "_NEW"); + fte.setTitle("title"); + // fte.addKeyword("TODO"); + fte.setNativeCRS("EPSG:4326"); + fte.setDescription("desc"); + fte.setEnabled(true); + + //metadataLink + GSMetadataLinkInfoEncoder metadatalink = new GSMetadataLinkInfoEncoder(); + metadatalink.setup("text/xml", "ISO19115:2003","http://www.organization.org/metadata1"); + fte.addMetadataLinkInfo(metadatalink); + + GSLayerEncoder layerEncoder = new GSLayerEncoder(); + layerEncoder.setEnabled(true); + layerEncoder.setQueryable(true); + + layerEncoder.setDefaultStyle("point"); + + publisher.createWorkspace(DEFAULT_WS); + + File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); + + // test insert + boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile); + assertTrue("publish() failed", published); + assertTrue(existsLayer(layerName)); + + publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(), + "default_point.sld")); + + // optionally select the attributes to publish + RESTLayer layer = reader.getLayer(layerName); + RESTResource resource = reader.getResource(layer); + List attrs = resource.getEncodedAttributeList(); + assertNotNull(attrs); + for (GSAttributeEncoder enc : attrs) { + fte.setAttribute(enc); + } + + assertTrue(publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder)); + } + + @Test + public void testFeatureTypeEncoder() { + + GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder(); + encoder.addKeyword("KEYWORD_1"); + encoder.addKeyword("KEYWORD_2"); + encoder.addKeyword("..."); + encoder.addKeyword("KEYWORD_N"); + + encoder.setName("Layername"); + + encoder.setTitle("title"); + encoder.addKeyword("TODO"); + encoder.setNativeCRS("EPSG:4326"); + encoder.setDescription("desc"); + encoder.setEnabled(true); + + GSAttributeEncoder attribute = new GSAttributeEncoder(); + attribute.setAttribute(FeatureTypeAttribute.name, "NAME"); + attribute.setAttribute(FeatureTypeAttribute.binding, "java.lang.String"); + attribute.setAttribute(FeatureTypeAttribute.maxOccurs, "1"); + attribute.setAttribute(FeatureTypeAttribute.minOccurs, "0"); + attribute.setAttribute(FeatureTypeAttribute.nillable, "true"); + + encoder.setAttribute(attribute); + + encoder.delAttribute("NAME"); + + attribute.setAttribute(FeatureTypeAttribute.name, "NEW_NAME"); + + encoder.setAttribute(attribute); + + // TODO encoder.getAttribute("NAME"); + + GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder("ELE"); + + encoder.addMetadata("elevation", dim2); + dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(10)); + Element el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION); + Assert.assertNotNull(el); + + LOGGER.info("contains_key:" + el.toString()); + + dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(12)); + el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.RESOLUTION); + Assert.assertNotNull(el); + Assert.assertEquals("12", el.getText()); + + dim2.setPresentation(Presentation.CONTINUOUS_INTERVAL); + + encoder.setMetadata("time", new GSFeatureDimensionInfoEncoder("time")); + el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION); + Assert.assertNotNull(el); + el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.RESOLUTION); + Assert.assertNull(el); + + el = ElementUtils.contains(encoder.getRoot(), GSResourceEncoder.METADATA); + Assert.assertNotNull(el); + LOGGER.info("contains_key:" + el.toString()); + + final boolean removed = ElementUtils.remove(encoder.getRoot(), el); + LOGGER.info("remove:" + removed); + Assert.assertTrue(removed); + + el = ElementUtils.contains(encoder.getRoot(), "metadata"); + Assert.assertNull(el); + if (el == null) + LOGGER.info("REMOVED"); + + if (LOGGER.isInfoEnabled()) + LOGGER.info(encoder.toString()); + + assertEquals(encoder.getName(),"Layername"); + } + + @Test + public void testModifyFeature() { + GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder(); + encoder.addKeyword("KEYWORD_1"); + encoder.addKeyword("KEYWORD_2"); + encoder.addKeyword("..."); + encoder.addKeyword("KEYWORD_N"); + + Assert.assertTrue(encoder.delKeyword("KEYWORD_2")); + Assert.assertFalse(encoder.delKeyword("KEYWORD_M")); + + //metadataLinkInfo + encoder.addMetadataLinkInfo("text/xml", "ISO19115:2003","http://www.organization.org/metadata1"); + encoder.addMetadataLinkInfo("text/html", "ISO19115:2003","http://www.organization.org/metadata2"); + + Assert.assertTrue(encoder.delMetadataLinkInfo("http://www.organization.org/metadata2")); + Assert.assertFalse(encoder.delMetadataLinkInfo("http://www.organization.org/metadata3")); + + //dimensions + final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder( + "elevation_field"); + + // if (LOGGER.isInfoEnabled()) + // LOGGER.info(encoder.toString()); + + final String metadata = "elevation"; + encoder.setMetadata(metadata, elevationDimension); + + elevationDimension.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, + BigDecimal.valueOf(10)); + + if (LOGGER.isInfoEnabled()) + LOGGER.info(encoder.toString()); + + Assert.assertTrue(encoder.delMetadata(metadata)); + + if (LOGGER.isInfoEnabled()) + LOGGER.info(encoder.toString()); + + final Element el = ElementUtils.contains(encoder.getRoot(), + GSDimensionInfoEncoder.DIMENSIONINFO); + Assert.assertNull(el); + if (el == null) + LOGGER.info("REMOVED"); + + } +} diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoderTest.java new file mode 100644 index 0000000..c0159ff --- /dev/null +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/metadatalink/GSMetadataLinkInfoEncoderTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007 - 2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * GPLv3 + Classpath exception + * + * 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 3 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, see . + */ +package it.geosolutions.geoserver.rest.encoder.metadatalink; + +import junit.framework.Assert; + +import org.junit.Test; + +/** +* +* @author eblondel +* +*/ +public class GSMetadataLinkInfoEncoderTest { + + @Test + public void metadataLinkInfoTest(){ + GSMetadataLinkInfoEncoder encoder = new GSMetadataLinkInfoEncoder(); + encoder.setup("text/xml", "ISO19115:2003","http://www.organization.org/metadata1"); + + Assert.assertEquals("text/xml", encoder.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.type)); + Assert.assertEquals("ISO19115:2003", encoder.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.metadataType)); + Assert.assertEquals("http://www.organization.org/metadata1", encoder.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.content)); + + Assert.assertTrue(encoder.delMetadataLinkInfoMember(ResourceMetadataLinkInfo.content)); + Assert.assertNull(encoder.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.content)); + + encoder.setMetadataLinkInfoMember(ResourceMetadataLinkInfo.type, "text/html"); + encoder.setMetadataLinkInfoMember(ResourceMetadataLinkInfo.metadataType, "FGDC"); + encoder.setMetadataLinkInfoMember(ResourceMetadataLinkInfo.content, "http://www.organization.org/metadata2"); + Assert.assertEquals("text/html", encoder.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.type)); + Assert.assertEquals("FGDC", encoder.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.metadataType)); + Assert.assertEquals("http://www.organization.org/metadata2", encoder.getMetadataLinkInfoMember(ResourceMetadataLinkInfo.content)); + + } +} \ No newline at end of file diff --git a/src/test/resources/testdata/coverageExample.xml b/src/test/resources/testdata/coverageExample.xml index 1e41f79..4047347 100644 --- a/src/test/resources/testdata/coverageExample.xml +++ b/src/test/resources/testdata/coverageExample.xml @@ -1,97 +1,109 @@ - - - granuleTestMosaic - granuleTestMosaic - - topp - - - granuleTestMosaic - GEOGCS["WGS 84", - DATUM["World Geodetic System 1984", - SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], - AUTHORITY["EPSG","6326"]], - PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], - UNIT["degree", 0.017453292519943295], - AXIS["Geodetic longitude", EAST], - AXIS["Geodetic latitude", NORTH], - AUTHORITY["EPSG","4326"]] - EPSG:4326 - - -180.0 - 180.0 - -90.0 - 90.0 - EPSG:4326 - - - -180.0 - 180.0 - -90.0 - 90.0 - EPSG:4326 - - NONE - true - true - - - - true - LIST - - - - - true - DISCRETE_INTERVAL - 2 - - - - - granuleTestMosaic - - - - - 0 0 - 540 270 - - - 0.6666666666666666 - -0.6666666666666666 - 0.0 - 0.0 - -179.66666666666666 - 89.66666666666667 - - EPSG:4326 - - - - AllowMultithreading - false - - - MaxAllowedTiles - 2147483647 - - - InputTransparentColor - - - - SUGGESTED_TILE_SIZE - 256,256 - - - USE_JAI_IMAGEREAD - false - - - BackgroundValues - -1.0 - - + + + granuleTestMosaic + granuleTestMosaic + + topp + + + granuleTestMosaic + + + text/xml + ISO19115:2003 + http://www.organization.org/metadata1 + + + text/html + ISO19115:2003 + http://www.organization.org/metadata2 + + + GEOGCS["WGS 84", + DATUM["World Geodetic System 1984", + SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], + AUTHORITY["EPSG","6326"]], + PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], + UNIT["degree", 0.017453292519943295], + AXIS["Geodetic longitude", EAST], + AXIS["Geodetic latitude", NORTH], + AUTHORITY["EPSG","4326"]] + EPSG:4326 + + -180.0 + 180.0 + -90.0 + 90.0 + EPSG:4326 + + + -180.0 + 180.0 + -90.0 + 90.0 + EPSG:4326 + + NONE + true + true + + + + true + LIST + + + + + true + DISCRETE_INTERVAL + 2 + + + + + granuleTestMosaic + + + + + 0 0 + 540 270 + + + 0.6666666666666666 + -0.6666666666666666 + 0.0 + 0.0 + -179.66666666666666 + 89.66666666666667 + + EPSG:4326 + + + + AllowMultithreading + false + + + MaxAllowedTiles + 2147483647 + + + InputTransparentColor + + + + SUGGESTED_TILE_SIZE + 256,256 + + + USE_JAI_IMAGEREAD + false + + + BackgroundValues + -1.0 + + \ No newline at end of file