#102 - 1.5.x - support for AuthorityURL/Identifier/advertise + tests
This commit is contained in:
parent
cb6fc418f2
commit
9d72c4665d
@ -34,6 +34,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList;
|
|||||||
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
|
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTFeatureTypeList;
|
import it.geosolutions.geoserver.rest.decoder.RESTFeatureTypeList;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer21;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroupList;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroupList;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
|
||||||
@ -536,7 +537,15 @@ public class GeoServerRESTReader {
|
|||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("### Retrieving layer from " + url);
|
LOGGER.debug("### Retrieving layer from " + url);
|
||||||
}
|
}
|
||||||
return RESTLayer.build(load(url));
|
|
||||||
|
RESTLayer layer = null;
|
||||||
|
if (this.getGeoserverVersion().getVersion()
|
||||||
|
.equals(GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
||||||
|
layer = RESTLayer21.build(load(url));
|
||||||
|
} else {
|
||||||
|
layer = RESTLayer.build(load(url));
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|||||||
@ -25,7 +25,15 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.Namespace;
|
import org.jdom.Namespace;
|
||||||
|
|
||||||
@ -48,16 +56,31 @@ import org.jdom.Namespace;
|
|||||||
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
|
||||||
</resource>
|
</resource>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
|
<queryable>true</queryable>
|
||||||
|
<advertised>true</advertised>
|
||||||
<attribution>
|
<attribution>
|
||||||
<logoWidth>0</logoWidth>
|
<logoWidth>0</logoWidth>
|
||||||
<logoHeight>0</logoHeight>
|
<logoHeight>0</logoHeight>
|
||||||
</attribution>
|
</attribution>
|
||||||
|
<authorityURLs>
|
||||||
|
<AuthorityURL>
|
||||||
|
<name>authority1</name>
|
||||||
|
<href>http://www.authority1.org</href>
|
||||||
|
</AuthorityURL>
|
||||||
|
</authorityURLs>
|
||||||
|
<identifiers>
|
||||||
|
<Identifier>
|
||||||
|
<authority>authority1</authority>
|
||||||
|
<identifier>identifier1</identifier>
|
||||||
|
</Identifier>
|
||||||
|
</identifiers>
|
||||||
</layer>
|
</layer>
|
||||||
* }</PRE>
|
* }</PRE>
|
||||||
* @author etj
|
* @author etj
|
||||||
|
* @author eblondel
|
||||||
*/
|
*/
|
||||||
public class RESTLayer {
|
public class RESTLayer {
|
||||||
private final Element layerElem;
|
protected final Element layerElem;
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
VECTOR("VECTOR"),
|
VECTOR("VECTOR"),
|
||||||
@ -96,6 +119,18 @@ public class RESTLayer {
|
|||||||
this.layerElem = layerElem;
|
this.layerElem = layerElem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getEnabled() {
|
||||||
|
return Boolean.parseBoolean(layerElem.getChildText("enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getQueryable() {
|
||||||
|
return Boolean.parseBoolean(layerElem.getChildText("queryable"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAdvertised() {
|
||||||
|
return Boolean.parseBoolean(layerElem.getChildText("advertised"));
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return layerElem.getChildText("name");
|
return layerElem.getChildText("name");
|
||||||
}
|
}
|
||||||
@ -167,6 +202,60 @@ public class RESTLayer {
|
|||||||
return atom.getAttributeValue("href");
|
return atom.getAttributeValue("href");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of AuthorityURLInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of GSAuthorityURLInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSAuthorityURLInfoEncoder> getEncodedAuthorityURLInfoList() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLList = null;
|
||||||
|
|
||||||
|
final Element authorityURLsRoot = layerElem.getChild("authorityURLs");
|
||||||
|
if (authorityURLsRoot != null) {
|
||||||
|
final List<Element> authorityURLs = authorityURLsRoot.getChildren();
|
||||||
|
if (authorityURLs != null) {
|
||||||
|
authorityURLList = new ArrayList<GSAuthorityURLInfoEncoder>(
|
||||||
|
authorityURLs.size());
|
||||||
|
for (Element authorityURL : authorityURLs) {
|
||||||
|
final GSAuthorityURLInfoEncoder authEnc = new GSAuthorityURLInfoEncoder();
|
||||||
|
authEnc.setName(authorityURL
|
||||||
|
.getChildText(AuthorityURLInfo.name.name()));
|
||||||
|
authEnc.setHref(authorityURL
|
||||||
|
.getChildText(AuthorityURLInfo.href.name()));
|
||||||
|
authorityURLList.add(authEnc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return authorityURLList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of IdentifierInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of IdentifierInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSIdentifierInfoEncoder> getEncodedIdentifierInfoList() {
|
||||||
|
List<GSIdentifierInfoEncoder> idList = null;
|
||||||
|
|
||||||
|
final Element idRoot = layerElem.getChild("identifiers");
|
||||||
|
if (idRoot != null) {
|
||||||
|
final List<Element> identifiers = idRoot.getChildren();
|
||||||
|
if (identifiers != null) {
|
||||||
|
idList = new ArrayList<GSIdentifierInfoEncoder>(
|
||||||
|
identifiers.size());
|
||||||
|
for (Element identifier : identifiers) {
|
||||||
|
final GSIdentifierInfoEncoder idEnc = new GSIdentifierInfoEncoder();
|
||||||
|
idEnc.setAuthority(identifier
|
||||||
|
.getChildText(IdentifierInfo.authority.name()));
|
||||||
|
idEnc.setIdentifier(identifier
|
||||||
|
.getChildText(IdentifierInfo.identifier.name()));
|
||||||
|
idList.add(idEnc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return idList;
|
||||||
|
}
|
||||||
|
|
||||||
// protected double getLatLonEdge(String edge) {
|
// protected double getLatLonEdge(String edge) {
|
||||||
// Element resource = layerElem.getChild("resource");
|
// Element resource = layerElem.getChild("resource");
|
||||||
// Element elBBox = resource.getChild("latLonBoundingBox");
|
// Element elBBox = resource.getChild("latLonBoundingBox");
|
||||||
|
|||||||
@ -0,0 +1,175 @@
|
|||||||
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse <TT>Layer</TT>s returned as XML REST objects. Applicable to GS 2.1 for
|
||||||
|
* decoding: - AuthorityURLs - Identifiers - advertised property value
|
||||||
|
*
|
||||||
|
* <P>
|
||||||
|
* This is the XML REST representation:
|
||||||
|
*
|
||||||
|
* <PRE>
|
||||||
|
* {@code
|
||||||
|
* <layer>
|
||||||
|
* <name>tasmania_cities</name>
|
||||||
|
* <path>/</path>
|
||||||
|
* <type>VECTOR</type>
|
||||||
|
* <defaultStyle>
|
||||||
|
* <name>capitals</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml"/>
|
||||||
|
* </defaultStyle>
|
||||||
|
* <resource class="featureType">
|
||||||
|
* <name>tasmania_cities</name>
|
||||||
|
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
|
||||||
|
* </resource>
|
||||||
|
* <enabled>true</enabled>
|
||||||
|
* <queryable>true</queryable>
|
||||||
|
* <advertised>true</advertised>
|
||||||
|
* <attribution>
|
||||||
|
* <logoWidth>0</logoWidth>
|
||||||
|
* <logoHeight>0</logoHeight>
|
||||||
|
* </attribution>
|
||||||
|
* <metadata>
|
||||||
|
* <entry key="identifiers">
|
||||||
|
* [{"authority":"authority1","identifier":"identifier1"},]
|
||||||
|
* </entry>
|
||||||
|
* <entry key="authorityURLs">
|
||||||
|
* [{"name":"authority1","href":"http://www.authority1.org"},]
|
||||||
|
* </entry>
|
||||||
|
* <entry key="advertised">true</entry>
|
||||||
|
* </metadata>
|
||||||
|
* </layer>
|
||||||
|
* }
|
||||||
|
* </PRE>
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*/
|
||||||
|
public class RESTLayer21 extends RESTLayer {
|
||||||
|
|
||||||
|
public RESTLayer21(Element layerElem) {
|
||||||
|
super(layerElem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RESTLayer21 build(String response) {
|
||||||
|
if (response == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Element pb = JDOMBuilder.buildElement(response);
|
||||||
|
if (pb != null)
|
||||||
|
return new RESTLayer21(pb);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the advertised property from the Geoserver Layer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public boolean getAdvertised() {
|
||||||
|
boolean advertised = true;
|
||||||
|
|
||||||
|
final Element metadataRoot = layerElem.getChild("metadata");
|
||||||
|
if (metadataRoot != null) {
|
||||||
|
final List<Element> metaElements = metadataRoot.getChildren();
|
||||||
|
if (metaElements != null) {
|
||||||
|
for (Element el : metaElements) {
|
||||||
|
String key = el.getAttributeValue("key");
|
||||||
|
if (key.matches("advertised")) {
|
||||||
|
advertised = Boolean.parseBoolean(el.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return advertised;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of AuthorityURLInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of GSAuthorityURLInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSAuthorityURLInfoEncoder> getEncodedAuthorityURLInfoList() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLList = null;
|
||||||
|
|
||||||
|
final Element metadataRoot = layerElem.getChild("metadata");
|
||||||
|
if (metadataRoot != null) {
|
||||||
|
final List<Element> metaElements = metadataRoot.getChildren();
|
||||||
|
if (metaElements != null) {
|
||||||
|
for (Element element : metaElements) {
|
||||||
|
String key = element.getAttributeValue("key");
|
||||||
|
if (key.matches("authorityURLs")) {
|
||||||
|
|
||||||
|
String jsonStr = element.getValue();
|
||||||
|
jsonStr = jsonStr.substring(2);
|
||||||
|
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
|
||||||
|
|
||||||
|
String[] items = jsonStr.split("\\}(,)\\{");
|
||||||
|
authorityURLList = new ArrayList<GSAuthorityURLInfoEncoder>(
|
||||||
|
items.length);
|
||||||
|
for (String item : items) {
|
||||||
|
String[] props = item.split(",");
|
||||||
|
|
||||||
|
String[] kvp1 = props[0].split("\":");
|
||||||
|
String name = kvp1[1].replace("\"", "");
|
||||||
|
String[] kvp2 = props[1].split("\":");
|
||||||
|
String href = kvp2[1].replace("\"", "");
|
||||||
|
|
||||||
|
authorityURLList.add(new GSAuthorityURLInfoEncoder(
|
||||||
|
name, href));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return authorityURLList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the list of IdentifierInfo from the GeoServer Layer
|
||||||
|
*
|
||||||
|
* @return the list of IdentifierInfoEncoder
|
||||||
|
*/
|
||||||
|
public List<GSIdentifierInfoEncoder> getEncodedIdentifierInfoList() {
|
||||||
|
List<GSIdentifierInfoEncoder> identifierList = null;
|
||||||
|
|
||||||
|
final Element metadataRoot = layerElem.getChild("metadata");
|
||||||
|
if (metadataRoot != null) {
|
||||||
|
final List<Element> metaElements = metadataRoot.getChildren();
|
||||||
|
if (metaElements != null) {
|
||||||
|
for (Element element : metaElements) {
|
||||||
|
String key = element.getAttributeValue("key");
|
||||||
|
if (key.matches("identifiers")) {
|
||||||
|
|
||||||
|
String jsonStr = element.getValue();
|
||||||
|
jsonStr = jsonStr.substring(2);
|
||||||
|
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
|
||||||
|
|
||||||
|
String[] items = jsonStr.split("\\}(,)\\{");
|
||||||
|
identifierList = new ArrayList<GSIdentifierInfoEncoder>(
|
||||||
|
items.length);
|
||||||
|
for (String item : items) {
|
||||||
|
String[] props = item.split(",");
|
||||||
|
|
||||||
|
String[] kvp1 = props[0].split("\":");
|
||||||
|
String authority = kvp1[1].replace("\"", "");
|
||||||
|
String[] kvp2 = props[1].split("\":");
|
||||||
|
String identifier = kvp2[1].replace("\"", "");
|
||||||
|
|
||||||
|
identifierList.add(new GSIdentifierInfoEncoder(
|
||||||
|
authority, identifier));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return identifierList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -28,12 +28,17 @@ package it.geosolutions.geoserver.rest.encoder;
|
|||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.filter.Filter;
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Layer encoder for Geoserver >= 2.2
|
||||||
*
|
*
|
||||||
* @author ETj (etj at geo-solutions.it)
|
* @author ETj (etj at geo-solutions.it)
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
*
|
*
|
||||||
* The layer encoder is enabled by default
|
* The layer encoder is enabled by default
|
||||||
*
|
*
|
||||||
@ -41,12 +46,19 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
|||||||
public class GSLayerEncoder extends PropertyXMLEncoder {
|
public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||||
|
|
||||||
public final static String STYLES = "styles";
|
public final static String STYLES = "styles";
|
||||||
|
public final static String AUTHORITY_URLS="authorityURLs";
|
||||||
|
public final static String IDENTIFIERS="identifiers";
|
||||||
|
|
||||||
final private Element stylesEncoder = new Element(STYLES);
|
final private Element stylesEncoder = new Element(STYLES);
|
||||||
|
final private Element authorityURLListEncoder = new Element(AUTHORITY_URLS);
|
||||||
|
final private Element identifierListEncoder = new Element(IDENTIFIERS);
|
||||||
|
|
||||||
public GSLayerEncoder() {
|
public GSLayerEncoder() {
|
||||||
super("layer");
|
super("layer");
|
||||||
addEnabled();
|
addEnabled();
|
||||||
addContent(stylesEncoder);
|
addContent(stylesEncoder);
|
||||||
|
addContent(authorityURLListEncoder);
|
||||||
|
addContent(identifierListEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,4 +179,58 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
|||||||
}
|
}
|
||||||
})).size() == 0 ? false : true;
|
})).size() == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param advertised
|
||||||
|
* true if the layer should be advertised
|
||||||
|
*/
|
||||||
|
public void setAdvertised(boolean advertised) {
|
||||||
|
if (advertised)
|
||||||
|
set("advertised", "true");
|
||||||
|
else
|
||||||
|
set("advertised", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an authorityURLInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param authorityURLInfo
|
||||||
|
*/
|
||||||
|
public void addAuthorityURL(GSAuthorityURLInfoEncoder authorityURLInfo) {
|
||||||
|
authorityURLListEncoder.addContent(authorityURLInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a AuthorityURLInfo from the list using the authorityURL
|
||||||
|
* (AuthorityURLInfo href)
|
||||||
|
*
|
||||||
|
* @param authorityURL
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delAuthorityURL(final String authorityURL) {
|
||||||
|
return (authorityURLListEncoder.removeContent(GSAuthorityURLInfoEncoder
|
||||||
|
.getFilterByHref(authorityURL))).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an identifierInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param identifierInfo
|
||||||
|
*/
|
||||||
|
public void addIdentifier(GSIdentifierInfoEncoder identifierInfo) {
|
||||||
|
identifierListEncoder.addContent(identifierInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a IdentifierInfo from the list using the authority name
|
||||||
|
* (IdentifierInfo authority)
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delIdentifier(final String authority) {
|
||||||
|
return (identifierListEncoder.removeContent(GSIdentifierInfoEncoder
|
||||||
|
.getFilterByHref(authority))).size() == 0 ? false : true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,188 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layer encoder for Geoserver = 2.1
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com
|
||||||
|
*
|
||||||
|
* The layer encoder is enabled by default
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSLayerEncoder21 extends GSLayerEncoder {
|
||||||
|
|
||||||
|
public final static String METADATA = "metadata";
|
||||||
|
final private GSMetadataEncoder metadata = new GSMetadataEncoder();
|
||||||
|
public Map<String, String> authorityURLList;
|
||||||
|
public Map<String, String> identifierList;
|
||||||
|
|
||||||
|
private class GSMetadataEncoder extends NestedElementEncoder {
|
||||||
|
public GSMetadataEncoder() {
|
||||||
|
super(METADATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GSLayerEncoder21() {
|
||||||
|
super();
|
||||||
|
addContent(metadata.getRoot());
|
||||||
|
addAdvertised();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key
|
||||||
|
* @param dimensionInfo
|
||||||
|
*/
|
||||||
|
protected void addMetadata(String key, XmlElement dimensionInfo) {
|
||||||
|
metadata.add(key, dimensionInfo.getRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* advertise the layer
|
||||||
|
*/
|
||||||
|
protected void addAdvertised() {
|
||||||
|
metadata.add("advertised", "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param advertised
|
||||||
|
* true if the layer should be advertised
|
||||||
|
*/
|
||||||
|
public void setAdvertised(boolean advertised) {
|
||||||
|
if (advertised) {
|
||||||
|
metadata.add("advertised", "true");
|
||||||
|
} else {
|
||||||
|
metadata.add("advertised", "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an authorityURLInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param authorityURLInfo
|
||||||
|
*/
|
||||||
|
public void addAuthorityURL(GSAuthorityURLInfoEncoder authorityURLInfo) {
|
||||||
|
if (authorityURLList == null) {
|
||||||
|
authorityURLList = new HashMap<String, String>();
|
||||||
|
}
|
||||||
|
authorityURLList.put(authorityURLInfo.getHref(),
|
||||||
|
authorityURLInfo.getName());
|
||||||
|
String jsonStr = "";
|
||||||
|
for (Entry<String, String> entry : authorityURLList.entrySet()) {
|
||||||
|
jsonStr += "{" + "\"" + AuthorityURLInfo.name.name() + "\":\""
|
||||||
|
+ entry.getValue() + "\"," + "\""
|
||||||
|
+ AuthorityURLInfo.href.name() + "\":\"" + entry.getKey()
|
||||||
|
+ "\"" + "},";
|
||||||
|
}
|
||||||
|
metadata.set("authorityURLs", "[" + jsonStr + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a AuthorityURLInfo from the list using the authorityURL
|
||||||
|
* (AuthorityURLInfo href)
|
||||||
|
*
|
||||||
|
* @param authorityURL
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delAuthorityURL(final String authorityURL) {
|
||||||
|
boolean delete = false;
|
||||||
|
if (!(authorityURLList == null || authorityURLList.isEmpty())) {
|
||||||
|
if (authorityURLList.containsKey(authorityURL)) {
|
||||||
|
identifierList.remove(authorityURL);
|
||||||
|
String jsonStr = "";
|
||||||
|
for (Entry<String, String> entry : identifierList.entrySet()) {
|
||||||
|
jsonStr += "{" + "\"" + AuthorityURLInfo.name.name()
|
||||||
|
+ "\":\"" + entry.getValue() + "\"," + "\""
|
||||||
|
+ AuthorityURLInfo.href.name() + "\":\""
|
||||||
|
+ entry.getKey() + "\"" + "},";
|
||||||
|
}
|
||||||
|
metadata.set("identifiers", "[" + jsonStr + "]");
|
||||||
|
delete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an identifierInfo to the GeoServer layer
|
||||||
|
*
|
||||||
|
* @param identifierInfo
|
||||||
|
*/
|
||||||
|
public void addIdentifier(GSIdentifierInfoEncoder identifierInfo) {
|
||||||
|
if (identifierList == null) {
|
||||||
|
identifierList = new HashMap<String, String>();
|
||||||
|
}
|
||||||
|
identifierList.put(identifierInfo.getAuthority(),
|
||||||
|
identifierInfo.getIdentifier());
|
||||||
|
String jsonStr = "";
|
||||||
|
for (Entry<String, String> entry : identifierList.entrySet()) {
|
||||||
|
jsonStr += "{" + "\"" + IdentifierInfo.authority.name() + "\":\""
|
||||||
|
+ entry.getKey() + "\"," + "\""
|
||||||
|
+ IdentifierInfo.identifier.name() + "\":\""
|
||||||
|
+ entry.getValue() + "\"" + "},";
|
||||||
|
}
|
||||||
|
metadata.set("identifiers", "[" + jsonStr + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a IdentifierInfo from the list using the authority name
|
||||||
|
* (IdentifierInfo authority)
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @return true if something is removed, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean delIdentifier(final String authority) {
|
||||||
|
boolean delete = false;
|
||||||
|
if (!(identifierList == null || identifierList.isEmpty())) {
|
||||||
|
if (identifierList.containsKey(authority)) {
|
||||||
|
identifierList.remove(authority);
|
||||||
|
String jsonStr = "";
|
||||||
|
for (Entry<String, String> entry : identifierList.entrySet()) {
|
||||||
|
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
|
||||||
|
+ "\":\"" + entry.getKey() + "\"," + "\""
|
||||||
|
+ IdentifierInfo.identifier.name() + "\":\""
|
||||||
|
+ entry.getValue() + "\"" + "},";
|
||||||
|
}
|
||||||
|
metadata.set("identifiers", "[" + jsonStr + "]");
|
||||||
|
delete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delete;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.authorityurl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of layer authorityURL members
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum AuthorityURLInfo {
|
||||||
|
|
||||||
|
name, href;
|
||||||
|
}
|
||||||
@ -0,0 +1,219 @@
|
|||||||
|
/*
|
||||||
|
* 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.authorityurl;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSAuthorityURLInfoEncoder - encodes an authorityURL for a given GeoServer
|
||||||
|
* layer as follows:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {
|
||||||
|
* @code
|
||||||
|
* final GSAuthorityURLInfoEncoder ae = new GSAuthorityURLInfoEncoder();
|
||||||
|
* ae.setName("an authority");
|
||||||
|
* ae.setHref("http://www.organization.org");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* For this example, the XML output is:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <AuthorityURL>
|
||||||
|
* <name>an authority</name>
|
||||||
|
* <href>http://www.organization.org</href>
|
||||||
|
* </AuthorityURL>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSAuthorityURLInfoEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to filter the AuthorityURL by href
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByHref implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByHref(String href) {
|
||||||
|
this.key = href;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj).getChild(AuthorityURLInfo.href
|
||||||
|
.toString());
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the AuthorityURLInfo href (authorityURL)
|
||||||
|
*
|
||||||
|
* @param href
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByHref(String href) {
|
||||||
|
return new filterByHref(href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new GSAuthorityURLInfoEncoder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GSAuthorityURLInfoEncoder() {
|
||||||
|
super("AuthorityURL");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly an AuthorityURL info
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* (required)
|
||||||
|
* @param href
|
||||||
|
* (required)
|
||||||
|
*/
|
||||||
|
public GSAuthorityURLInfoEncoder(String name, String href) {
|
||||||
|
super("AuthorityURL");
|
||||||
|
this.setup(name, href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly an AuthorityURL info
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param href
|
||||||
|
*/
|
||||||
|
protected void setup(String name, String href) {
|
||||||
|
set(AuthorityURLInfo.name.name(), name);
|
||||||
|
set(AuthorityURLInfo.href.name(), href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an AuthorityURLInfo member (name, href)
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void setMember(AuthorityURLInfo type, String value) {
|
||||||
|
set(type.toString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the name
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.setMember(AuthorityURLInfo.name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the href
|
||||||
|
*
|
||||||
|
* @param href
|
||||||
|
*/
|
||||||
|
public void setHref(String href) {
|
||||||
|
this.setMember(AuthorityURLInfo.href, href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an AuthorityURLInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if the AuthorityURLInfo member is removed
|
||||||
|
*/
|
||||||
|
protected boolean delMember(AuthorityURLInfo type) {
|
||||||
|
return ElementUtils.remove(this.getRoot(),
|
||||||
|
this.getRoot().getChild(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the authority name
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delName() {
|
||||||
|
return this.delMember(AuthorityURLInfo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the href
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delHref() {
|
||||||
|
return this.delMember(AuthorityURLInfo.href);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the AuthorityURLInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return the value of the AuthorityURLInfo member
|
||||||
|
*/
|
||||||
|
protected String getMember(AuthorityURLInfo type) {
|
||||||
|
Element el = this.getRoot().getChild(type.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return this.getMember(AuthorityURLInfo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the href
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getHref() {
|
||||||
|
return this.getMember(AuthorityURLInfo.href);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,219 @@
|
|||||||
|
/*
|
||||||
|
* 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.identifier;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.filter.Filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSIdentifierInfoEncoder - encodes an Identifier for a given GeoServer layer
|
||||||
|
* as follows:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {
|
||||||
|
* @code
|
||||||
|
* final GSIdentifierInfoEncoder ie = new GSIdentifierInfoEncoder();
|
||||||
|
* ie.setAuthority("an authority");
|
||||||
|
* ie.setIdentifier("an identifier");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* For this example, the XML output is:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <Identifier>
|
||||||
|
* <authority>an authority</authority>
|
||||||
|
* <identifier>an identifier</identifier>
|
||||||
|
* </Identifier>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSIdentifierInfoEncoder extends XmlElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to filter the Idenfiers by authority
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static class filterByAuthority implements Filter {
|
||||||
|
|
||||||
|
final private String key;
|
||||||
|
|
||||||
|
public filterByAuthority(String authority) {
|
||||||
|
this.key = authority;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public boolean matches(Object obj) {
|
||||||
|
Element el = ((Element) obj).getChild(IdentifierInfo.authority
|
||||||
|
.toString());
|
||||||
|
if (el != null && el.getTextTrim().equals(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Filter using the IdentifierInfo authority
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @return the filter
|
||||||
|
*/
|
||||||
|
public static Filter getFilterByHref(String authority) {
|
||||||
|
return new filterByAuthority(authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new GSIdentifierInfoEncoder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GSIdentifierInfoEncoder() {
|
||||||
|
super("Identifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs quickly an Identifier info
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* (required)
|
||||||
|
* @param identifier
|
||||||
|
* (required)
|
||||||
|
*/
|
||||||
|
public GSIdentifierInfoEncoder(String authority, String identifier) {
|
||||||
|
super("Identifier");
|
||||||
|
this.setup(authority, identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set-up quickly an Identifier info
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
* @param identifier
|
||||||
|
*/
|
||||||
|
protected void setup(String authority, String identifier) {
|
||||||
|
set(IdentifierInfo.authority.name(), authority);
|
||||||
|
set(IdentifierInfo.identifier.name(), identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an IdentifierInfo member (authority, identifier)
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void setMember(IdentifierInfo type, String value) {
|
||||||
|
set(type.toString(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the authority
|
||||||
|
*
|
||||||
|
* @param authority
|
||||||
|
*/
|
||||||
|
public void setAuthority(String authority) {
|
||||||
|
this.setMember(IdentifierInfo.authority, authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the identifier
|
||||||
|
*
|
||||||
|
* @param identifier
|
||||||
|
*/
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.setMember(IdentifierInfo.identifier, identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an IdentifierInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return true if the IdentifierInfo member is removed
|
||||||
|
*/
|
||||||
|
protected boolean delMember(IdentifierInfo type) {
|
||||||
|
return ElementUtils.remove(this.getRoot(),
|
||||||
|
this.getRoot().getChild(type.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the authority
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delAuthority() {
|
||||||
|
return this.delMember(IdentifierInfo.authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the identifier
|
||||||
|
*
|
||||||
|
* @return true if removed
|
||||||
|
*/
|
||||||
|
public boolean delIdentifier() {
|
||||||
|
return this.delMember(IdentifierInfo.identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the IdentifierInfo member
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return the value of the IdentifierInfo member
|
||||||
|
*/
|
||||||
|
protected String getMember(IdentifierInfo type) {
|
||||||
|
Element el = this.getRoot().getChild(type.toString());
|
||||||
|
if (el != null)
|
||||||
|
return el.getTextTrim();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the authority
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getAuthority() {
|
||||||
|
return this.getMember(IdentifierInfo.authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the identifier
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getIdentifier() {
|
||||||
|
return this.getMember(IdentifierInfo.identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of layer authorityURL members
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum IdentifierInfo {
|
||||||
|
|
||||||
|
authority, identifier;
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer21;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Apply Layer decoder tests on a GS 2.1 layer REST config
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LayerDecoder21Test {
|
||||||
|
|
||||||
|
RESTLayer21 layer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws IOException {
|
||||||
|
File layerFile = new ClassPathResource("testdata/layerExample21.xml")
|
||||||
|
.getFile();
|
||||||
|
String layerString = FileUtils.readFileToString(layerFile);
|
||||||
|
layer = (RESTLayer21) RESTLayer21.build(layerString);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvertised() {
|
||||||
|
Assert.assertEquals(true, layer.getAdvertised());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAuthorityURLs() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedAuthorityURLInfoList();
|
||||||
|
System.out.println(authorityURLs.size());
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getName());
|
||||||
|
Assert.assertEquals("http://www.authority1.org", authorityURLs.get(0)
|
||||||
|
.getHref());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getName());
|
||||||
|
Assert.assertEquals("http://www.authority2.org", authorityURLs.get(1)
|
||||||
|
.getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIdentifiers() {
|
||||||
|
List<GSIdentifierInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedIdentifierInfoList();
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getAuthority());
|
||||||
|
Assert.assertEquals("identifier1", authorityURLs.get(0).getIdentifier());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getAuthority());
|
||||||
|
Assert.assertEquals("identifier2", authorityURLs.get(1).getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,99 @@
|
|||||||
|
package it.geosolutions.geoserver.decoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LayerDecoderTest {
|
||||||
|
|
||||||
|
RESTLayer layer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws IOException {
|
||||||
|
File layerFile = new ClassPathResource("testdata/layerExample.xml")
|
||||||
|
.getFile();
|
||||||
|
String layerString = FileUtils.readFileToString(layerFile);
|
||||||
|
layer = RESTLayer.build(layerString);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnabled() {
|
||||||
|
Assert.assertEquals(true, layer.getEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQueryable() {
|
||||||
|
Assert.assertEquals(true, layer.getQueryable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvertised() {
|
||||||
|
Assert.assertEquals(true, layer.getAdvertised());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testName() {
|
||||||
|
Assert.assertEquals("tasmania_cities", layer.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypeString() {
|
||||||
|
Assert.assertEquals("VECTOR", layer.getTypeString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testType() {
|
||||||
|
Assert.assertEquals(RESTLayer.Type.VECTOR, layer.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultStyle() {
|
||||||
|
Assert.assertEquals("capitals", layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResourceUrl() {
|
||||||
|
Assert.assertEquals(
|
||||||
|
"http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml",
|
||||||
|
layer.getResourceUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAuthorityURLs() {
|
||||||
|
List<GSAuthorityURLInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedAuthorityURLInfoList();
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getName());
|
||||||
|
Assert.assertEquals("http://www.authority1.org", authorityURLs.get(0)
|
||||||
|
.getHref());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getName());
|
||||||
|
Assert.assertEquals("http://www.authority2.org", authorityURLs.get(1)
|
||||||
|
.getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIdentifiers() {
|
||||||
|
List<GSIdentifierInfoEncoder> authorityURLs = layer
|
||||||
|
.getEncodedIdentifierInfoList();
|
||||||
|
Assert.assertEquals("authority1", authorityURLs.get(0).getAuthority());
|
||||||
|
Assert.assertEquals("identifier1", authorityURLs.get(0).getIdentifier());
|
||||||
|
Assert.assertEquals("authority2", authorityURLs.get(1).getAuthority());
|
||||||
|
Assert.assertEquals("identifier2", authorityURLs.get(1).getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GSLayerEncoder21Test
|
||||||
|
*
|
||||||
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||||
|
* emmanuel.blondel@fao.org
|
||||||
|
*/
|
||||||
|
public class GSLayerEncoder21Test {
|
||||||
|
|
||||||
|
GSLayerEncoder21 layerEncoder;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
layerEncoder = new GSLayerEncoder21();
|
||||||
|
layerEncoder.setAdvertised(true);
|
||||||
|
layerEncoder.addAuthorityURL(new GSAuthorityURLInfoEncoder(
|
||||||
|
"authority1", "http://www.authority1.org"));
|
||||||
|
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority1",
|
||||||
|
"identifier1"));
|
||||||
|
layerEncoder.addAuthorityURL(new GSAuthorityURLInfoEncoder(
|
||||||
|
"authority2", "http://www.authority2.org"));
|
||||||
|
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
|
||||||
|
"identifier2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetadata() {
|
||||||
|
List<Element> metaElements = layerEncoder.getRoot()
|
||||||
|
.getChild("metadata").getChildren();
|
||||||
|
for (Element el : metaElements) {
|
||||||
|
String key = el.getAttributeValue("key");
|
||||||
|
|
||||||
|
if (key.matches("advertised")) {
|
||||||
|
Assert.assertEquals(true, Boolean.parseBoolean(el.getValue()));
|
||||||
|
|
||||||
|
} else if (key.matches("authorityURLs")) {
|
||||||
|
String jsonStr = el.getValue();
|
||||||
|
jsonStr = jsonStr.substring(2);
|
||||||
|
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
|
||||||
|
|
||||||
|
String[] items = jsonStr.split("\\}(,)\\{");
|
||||||
|
|
||||||
|
String[] props1 = items[0].split(",");
|
||||||
|
String[] kvp1_1 = props1[0].split("\":");
|
||||||
|
String[] kvp1_2 = props1[1].split("\":");
|
||||||
|
Assert.assertEquals(AuthorityURLInfo.name.name(),
|
||||||
|
kvp1_1[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("authority1", kvp1_1[1].replace("\"", ""));
|
||||||
|
Assert.assertEquals(AuthorityURLInfo.href.name(),
|
||||||
|
kvp1_2[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("http://www.authority1.org",
|
||||||
|
kvp1_2[1].replace("\"", ""));
|
||||||
|
|
||||||
|
String[] props2 = items[1].split(",");
|
||||||
|
String[] kvp2_1 = props2[0].split("\":");
|
||||||
|
String[] kvp2_2 = props2[1].split("\":");
|
||||||
|
Assert.assertEquals(AuthorityURLInfo.name.name(),
|
||||||
|
kvp2_1[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("authority2", kvp2_1[1].replace("\"", ""));
|
||||||
|
Assert.assertEquals(AuthorityURLInfo.href.name(),
|
||||||
|
kvp2_2[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("http://www.authority2.org",
|
||||||
|
kvp2_2[1].replace("\"", ""));
|
||||||
|
|
||||||
|
} else if (key.matches("identifiers")) {
|
||||||
|
String jsonStr = el.getValue();
|
||||||
|
jsonStr = jsonStr.substring(2);
|
||||||
|
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
|
||||||
|
|
||||||
|
String[] items = jsonStr.split("\\}(,)\\{");
|
||||||
|
|
||||||
|
String[] props1 = items[0].split(",");
|
||||||
|
String[] kvp1_1 = props1[0].split("\":");
|
||||||
|
String[] kvp1_2 = props1[1].split("\":");
|
||||||
|
Assert.assertEquals(IdentifierInfo.authority.name(),
|
||||||
|
kvp1_1[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("authority2", kvp1_1[1].replace("\"", ""));
|
||||||
|
Assert.assertEquals(IdentifierInfo.identifier.name(),
|
||||||
|
kvp1_2[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("identifier2", kvp1_2[1].replace("\"", ""));
|
||||||
|
|
||||||
|
String[] props2 = items[1].split(",");
|
||||||
|
String[] kvp2_1 = props2[0].split("\":");
|
||||||
|
String[] kvp2_2 = props2[1].split("\":");
|
||||||
|
Assert.assertEquals(IdentifierInfo.authority.name(),
|
||||||
|
kvp2_1[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("authority1", kvp2_1[1].replace("\"", ""));
|
||||||
|
Assert.assertEquals(IdentifierInfo.identifier.name(),
|
||||||
|
kvp2_2[0].replace("\"", ""));
|
||||||
|
Assert.assertEquals("identifier1", kvp2_2[1].replace("\"", ""));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,6 +19,8 @@
|
|||||||
*/
|
*/
|
||||||
package it.geosolutions.geoserver.rest.encoder;
|
package it.geosolutions.geoserver.rest.encoder;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
@ -40,9 +42,17 @@ public class GSLayerEncoderTest {
|
|||||||
layerEncoder = new GSLayerEncoder();
|
layerEncoder = new GSLayerEncoder();
|
||||||
layerEncoder.setEnabled(true);
|
layerEncoder.setEnabled(true);
|
||||||
layerEncoder.setQueryable(true);
|
layerEncoder.setQueryable(true);
|
||||||
|
layerEncoder.setAdvertised(true);
|
||||||
|
|
||||||
layerEncoder.setDefaultStyle("point");
|
layerEncoder.setDefaultStyle("point");
|
||||||
layerEncoder.addStyle("additional_style1");
|
layerEncoder.addStyle("additional_style1");
|
||||||
layerEncoder.addStyle("additional_style2");
|
layerEncoder.addStyle("additional_style2");
|
||||||
|
|
||||||
|
layerEncoder.addAuthorityURL(new GSAuthorityURLInfoEncoder(
|
||||||
|
"authority1", "http://www.authority1.org"));
|
||||||
|
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority1",
|
||||||
|
"identifier1"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -55,6 +65,10 @@ public class GSLayerEncoderTest {
|
|||||||
true,
|
true,
|
||||||
Boolean.parseBoolean(layerEncoder.getRoot()
|
Boolean.parseBoolean(layerEncoder.getRoot()
|
||||||
.getChild("queryable").getValue()));
|
.getChild("queryable").getValue()));
|
||||||
|
Assert.assertEquals(
|
||||||
|
true,
|
||||||
|
Boolean.parseBoolean(layerEncoder.getRoot()
|
||||||
|
.getChild("advertised").getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -82,4 +96,21 @@ public class GSLayerEncoderTest {
|
|||||||
.getRoot().getChild("styles").getChildren().get(0)).getText());
|
.getRoot().getChild("styles").getChildren().get(0)).getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAuthorityURL() {
|
||||||
|
Element el = (Element) layerEncoder.getRoot().getChild("authorityURLs")
|
||||||
|
.getChildren().get(0);
|
||||||
|
Assert.assertEquals("authority1", el.getChild("name").getValue());
|
||||||
|
Assert.assertEquals("http://www.authority1.org", el.getChild("href")
|
||||||
|
.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIdentifier() {
|
||||||
|
Element el = (Element) layerEncoder.getRoot().getChild("identifiers")
|
||||||
|
.getChildren().get(0);
|
||||||
|
Assert.assertEquals("authority1", el.getChild("authority").getValue());
|
||||||
|
Assert.assertEquals("identifier1", el.getChild("identifier").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.authorityurl;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSAuthorityURLInfoEncoderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void authorityURLInfoTest() {
|
||||||
|
GSAuthorityURLInfoEncoder encoder = new GSAuthorityURLInfoEncoder();
|
||||||
|
encoder.setup("authority1", "http://www.authority1.org");
|
||||||
|
|
||||||
|
Assert.assertEquals("authority1", encoder.getName());
|
||||||
|
Assert.assertEquals("http://www.authority1.org", encoder.getHref());
|
||||||
|
|
||||||
|
Assert.assertTrue(encoder.delHref());
|
||||||
|
Assert.assertNull(encoder.getHref());
|
||||||
|
|
||||||
|
encoder.setName("authority2");
|
||||||
|
encoder.setHref("http://www.authority2.org");
|
||||||
|
Assert.assertEquals("authority2", encoder.getName());
|
||||||
|
Assert.assertEquals("http://www.authority2.org", encoder.getHref());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,8 +22,12 @@ package it.geosolutions.geoserver.rest.encoder.feature;
|
|||||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTResource;
|
import it.geosolutions.geoserver.rest.decoder.RESTResource;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder21;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
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.Presentation;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
|
||||||
@ -73,6 +77,7 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
|
|||||||
String layerName = "cities";
|
String layerName = "cities";
|
||||||
|
|
||||||
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
|
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
|
||||||
|
fte.setNativeName(layerName);
|
||||||
fte.setName(layerName + "_NEW");
|
fte.setName(layerName + "_NEW");
|
||||||
fte.setTitle("title");
|
fte.setTitle("title");
|
||||||
// fte.addKeyword("TODO");
|
// fte.addKeyword("TODO");
|
||||||
@ -86,14 +91,32 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
|
|||||||
"http://www.organization.org/metadata1");
|
"http://www.organization.org/metadata1");
|
||||||
fte.addMetadataLinkInfo(metadatalink);
|
fte.addMetadataLinkInfo(metadatalink);
|
||||||
|
|
||||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
GSLayerEncoder layerEncoder = null;
|
||||||
|
if (!GSVersionDecoder.VERSION.getVersion(VERSION).equals(
|
||||||
|
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
||||||
|
layerEncoder = new GSLayerEncoder();
|
||||||
|
} else if (GSVersionDecoder.VERSION.getVersion(VERSION).equals(
|
||||||
|
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
|
||||||
|
layerEncoder = new GSLayerEncoder21();
|
||||||
|
}
|
||||||
layerEncoder.setEnabled(true);
|
layerEncoder.setEnabled(true);
|
||||||
layerEncoder.setQueryable(true);
|
layerEncoder.setQueryable(true);
|
||||||
|
layerEncoder.setAdvertised(true);
|
||||||
|
|
||||||
layerEncoder.setDefaultStyle("point");
|
layerEncoder.setDefaultStyle("point");
|
||||||
layerEncoder.addStyle("point2");
|
layerEncoder.addStyle("point2");
|
||||||
layerEncoder.addStyle("point3");
|
layerEncoder.addStyle("point3");
|
||||||
|
|
||||||
|
// authorityURL
|
||||||
|
GSAuthorityURLInfoEncoder authorityURL = new GSAuthorityURLInfoEncoder(
|
||||||
|
"authority1", "http://www.authority1.org");
|
||||||
|
layerEncoder.addAuthorityURL(authorityURL);
|
||||||
|
|
||||||
|
// identifier
|
||||||
|
GSIdentifierInfoEncoder identifier = new GSIdentifierInfoEncoder(
|
||||||
|
"authority1", "identifier1");
|
||||||
|
layerEncoder.addIdentifier(identifier);
|
||||||
|
|
||||||
publisher.createWorkspace(DEFAULT_WS);
|
publisher.createWorkspace(DEFAULT_WS);
|
||||||
|
|
||||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
|||||||
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package it.geosolutions.geoserver.rest.encoder.identifier;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author eblondel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GSIdentifierInfoEncoderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void identifierInfoTest() {
|
||||||
|
GSIdentifierInfoEncoder encoder = new GSIdentifierInfoEncoder();
|
||||||
|
encoder.setup("authority1", "identifier1");
|
||||||
|
|
||||||
|
Assert.assertEquals("authority1", encoder.getAuthority());
|
||||||
|
Assert.assertEquals("identifier1", encoder.getIdentifier());
|
||||||
|
|
||||||
|
Assert.assertTrue(encoder.delIdentifier());
|
||||||
|
Assert.assertNull(encoder.getIdentifier());
|
||||||
|
|
||||||
|
encoder.setAuthority("authority2");
|
||||||
|
encoder.setIdentifier("identifier2");
|
||||||
|
Assert.assertEquals("authority2", encoder.getAuthority());
|
||||||
|
Assert.assertEquals("identifier2", encoder.getIdentifier());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/test/resources/testdata/layerExample.xml
vendored
Normal file
44
src/test/resources/testdata/layerExample.xml
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<layer>
|
||||||
|
<name>tasmania_cities</name>
|
||||||
|
<path>/</path>
|
||||||
|
<type>VECTOR</type>
|
||||||
|
<defaultStyle>
|
||||||
|
<name>capitals</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
|
||||||
|
href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml" />
|
||||||
|
</defaultStyle>
|
||||||
|
<resource class="featureType">
|
||||||
|
<name>tasmania_cities</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
|
||||||
|
href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml"
|
||||||
|
type="application/xml" />
|
||||||
|
</resource>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<queryable>true</queryable>
|
||||||
|
<advertised>true</advertised>
|
||||||
|
<attribution>
|
||||||
|
<logoWidth>0</logoWidth>
|
||||||
|
<logoHeight>0</logoHeight>
|
||||||
|
</attribution>
|
||||||
|
<authorityURLs>
|
||||||
|
<AuthorityURL>
|
||||||
|
<name>authority1</name>
|
||||||
|
<href>http://www.authority1.org</href>
|
||||||
|
</AuthorityURL>
|
||||||
|
<AuthorityURL>
|
||||||
|
<name>authority2</name>
|
||||||
|
<href>http://www.authority2.org</href>
|
||||||
|
</AuthorityURL>
|
||||||
|
</authorityURLs>
|
||||||
|
<identifiers>
|
||||||
|
<Identifier>
|
||||||
|
<authority>authority1</authority>
|
||||||
|
<identifier>identifier1</identifier>
|
||||||
|
</Identifier>
|
||||||
|
<Identifier>
|
||||||
|
<authority>authority2</authority>
|
||||||
|
<identifier>identifier2</identifier>
|
||||||
|
</Identifier>
|
||||||
|
</identifiers>
|
||||||
|
</layer>
|
||||||
|
|
||||||
29
src/test/resources/testdata/layerExample21.xml
vendored
Normal file
29
src/test/resources/testdata/layerExample21.xml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<layer>
|
||||||
|
<name>tasmania_cities</name>
|
||||||
|
<path>/</path>
|
||||||
|
<type>VECTOR</type>
|
||||||
|
<defaultStyle>
|
||||||
|
<name>capitals</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
|
||||||
|
href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml" />
|
||||||
|
</defaultStyle>
|
||||||
|
<resource class="featureType">
|
||||||
|
<name>tasmania_cities</name>
|
||||||
|
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
|
||||||
|
href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml"
|
||||||
|
type="application/xml" />
|
||||||
|
</resource>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<queryable>true</queryable>
|
||||||
|
<advertised>true</advertised>
|
||||||
|
<attribution>
|
||||||
|
<logoWidth>0</logoWidth>
|
||||||
|
<logoHeight>0</logoHeight>
|
||||||
|
</attribution>
|
||||||
|
<metadata>
|
||||||
|
<entry key="identifiers">[{"authority":"authority1","identifier":"identifier1"},{"authority":"authority2","identifier":"identifier2"},]</entry>
|
||||||
|
<entry key="authorityURLs">[{"name":"authority1","href":"http://www.authority1.org"},{"name":"authority2","href":"http://www.authority2.org"},]</entry>
|
||||||
|
<entry key="advertised">true</entry>
|
||||||
|
</metadata>
|
||||||
|
</layer>
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user