#102-AuthorityURL/Identifier/advertised decoders +fix/add other methods
This commit is contained in:
parent
e5033df000
commit
8d47a02e03
@ -25,7 +25,16 @@
|
||||
|
||||
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.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.metadatalink.GSMetadataLinkInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jdom.Namespace;
|
||||
@ -97,6 +106,18 @@ public class RESTLayer {
|
||||
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() {
|
||||
return layerElem.getChildText("name");
|
||||
}
|
||||
@ -164,6 +185,62 @@ public class RESTLayer {
|
||||
Element atom = resource.getChild("link", Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
||||
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) {
|
||||
// Element resource = layerElem.getChild("resource");
|
||||
|
||||
@ -0,0 +1,98 @@
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
40
src/test/resources/testdata/layerExample.xml
vendored
Normal file
40
src/test/resources/testdata/layerExample.xml
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
<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>
|
||||
Loading…
Reference in New Issue
Block a user