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..5c78d3f 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java @@ -28,6 +28,8 @@ 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; @@ -41,6 +43,7 @@ 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; @@ -154,6 +157,61 @@ public class RESTResource { 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 // */ 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..2e180a2 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,46 @@ 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: *
    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..65de75b --- /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..91c21e2 --- /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 + +}