#44 add getMetadataList and getDimensionInfo methods to RESTCoverage.java

This commit is contained in:
Damiano 2012-10-09 19:43:55 +02:00
parent 3a05e405bd
commit f8765d6287
5 changed files with 412 additions and 1 deletions

View File

@ -25,6 +25,10 @@
package it.geosolutions.geoserver.rest.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Element;
/**
@ -187,7 +191,20 @@ public class RESTCoverage extends RESTResource {
public String getSRS() {
return rootElem.getChildText("srs");
}
public RESTMetadataList getMetadataList() {
return new RESTMetadataList(rootElem.getChild("metadata"));
}
public List<RESTDimensionInfo> getDimensionInfo() {
List<RESTDimensionInfo> listDim = new ArrayList<RESTDimensionInfo>();
for (RESTMetadataList.RESTMetadataElement el : getMetadataList()){
if(el.getKey().equals("time") || el.getKey().equals("elevation")){
listDim.add(new RESTDimensionInfo(el.getMetadataElem()));
}
}
return listDim;
}
// public String getStoreName() {
// return rootElem.getChild("store").getChildText("name");

View File

@ -0,0 +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 <http://www.gnu.org/licenses/>.
*/
package it.geosolutions.geoserver.rest.decoder;
import org.jdom.Element;
/**
* @author DamianoG
*
*/
public class RESTDimensionInfo extends RESTMetadataList.RESTMetadataElement{
private boolean enabled;
private String presentation;
private String resolution;
/**
* @param elem
*/
public RESTDimensionInfo(Element elem) {
super(elem);
if(elem.getChild("dimensionInfo")!=null){
enabled = Boolean.parseBoolean(elem.getChild("dimensionInfo").getChildText("enabled"));
presentation = elem.getChild("dimensionInfo").getChildText("presentation");
resolution = elem.getChild("dimensionInfo").getChildText("resolution");
}
}
/**
* @return the enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* @return the presentation
*/
public String getPresentation() {
return presentation;
}
/**
* @param presentation the presentation to set
*/
public void setPresentation(String presentation) {
this.presentation = presentation;
}
/**
* @return the resolution
*/
public String getResolution() {
return resolution;
}
/**
* @param resolution the resolution to set
*/
public void setResolution(String resolution) {
this.resolution = resolution;
}
}

View File

@ -0,0 +1,131 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package it.geosolutions.geoserver.rest.decoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;
/**
* @author DamianoG
*
*/
public class RESTMetadataList implements Iterable<RESTMetadataList.RESTMetadataElement> {
private final List<Element> metadataList;
/**
* @param list
*/
protected RESTMetadataList(Element list) {
List<Element> tmpList = new ArrayList<Element>();
for(Element el : (List<Element>)list.getChildren("entry")){
tmpList.add(el);
}
metadataList = Collections.unmodifiableList(tmpList);
}
public int size() {
return metadataList.size();
}
public boolean isEmpty() {
return metadataList.isEmpty();
}
public RESTMetadataElement get(int index) {
return new RESTMetadataElement(metadataList.get(index));
}
/* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<RESTMetadataElement> iterator() {
return new RESTMetadataIterator(metadataList);
}
private static class RESTMetadataIterator implements Iterator<RESTMetadataElement>{
private final Iterator<Element> iter;
/**
* @param iter
*/
public RESTMetadataIterator(List<Element> orig) {
this.iter = orig.iterator();
}
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
@Override
public boolean hasNext() {
return iter.hasNext();
}
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
@Override
public RESTMetadataElement next() {
return new RESTMetadataElement(iter.next());
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported.");
}
}
/**
* Generic metadata Object
*
* @author DamianoG
*
*/
public static class RESTMetadataElement {
protected final Element metadataElem;
public RESTMetadataElement(Element elem) {
this.metadataElem = elem;
}
public String getKey() {
return metadataElem.getAttributeValue("key");
}
public Element getMetadataElem() {
return metadataElem;
}
}
}

View File

@ -0,0 +1,74 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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<RESTDimensionInfo> 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);
}
}
}
}

View File

@ -0,0 +1,97 @@
<coverage>
<name>granuleTestMosaic</name>
<nativeName>granuleTestMosaic</nativeName>
<namespace>
<name>topp</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/namespaces/topp.xml" type="application/xml"/>
</namespace>
<title>granuleTestMosaic</title>
<nativeCRS>GEOGCS[&quot;WGS 84&quot;, &#xd;
DATUM[&quot;World Geodetic System 1984&quot;, &#xd;
SPHEROID[&quot;WGS 84&quot;, 6378137.0, 298.257223563, AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]], &#xd;
AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]], &#xd;
PRIMEM[&quot;Greenwich&quot;, 0.0, AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]], &#xd;
UNIT[&quot;degree&quot;, 0.017453292519943295], &#xd;
AXIS[&quot;Geodetic longitude&quot;, EAST], &#xd;
AXIS[&quot;Geodetic latitude&quot;, NORTH], &#xd;
AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]</nativeCRS>
<srs>EPSG:4326</srs>
<nativeBoundingBox>
<minx>-180.0</minx>
<maxx>180.0</maxx>
<miny>-90.0</miny>
<maxy>90.0</maxy>
<crs>EPSG:4326</crs>
</nativeBoundingBox>
<latLonBoundingBox>
<minx>-180.0</minx>
<maxx>180.0</maxx>
<miny>-90.0</miny>
<maxy>90.0</maxy>
<crs>EPSG:4326</crs>
</latLonBoundingBox>
<projectionPolicy>NONE</projectionPolicy>
<enabled>true</enabled>
<advertised>true</advertised>
<metadata>
<entry key="time">
<dimensionInfo>
<enabled>true</enabled>
<presentation>LIST</presentation>
</dimensionInfo>
</entry>
<entry key="elevation">
<dimensionInfo>
<enabled>true</enabled>
<presentation>DISCRETE_INTERVAL</presentation>
<resolution>2</resolution>
</dimensionInfo>
</entry>
</metadata>
<store class="coverageStore">
<name>granuleTestMosaic</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/coveragestores/granuleTestMosaic.xml" type="application/xml"/>
</store>
<grid dimension="2">
<range>
<low>0 0</low>
<high>540 270</high>
</range>
<transform>
<scaleX>0.6666666666666666</scaleX>
<scaleY>-0.6666666666666666</scaleY>
<shearX>0.0</shearX>
<shearY>0.0</shearY>
<translateX>-179.66666666666666</translateX>
<translateY>89.66666666666667</translateY>
</transform>
<crs>EPSG:4326</crs>
</grid>
<parameters>
<entry>
<string>AllowMultithreading</string>
<string>false</string>
</entry>
<entry>
<string>MaxAllowedTiles</string>
<string>2147483647</string>
</entry>
<entry>
<string>InputTransparentColor</string>
<string></string>
</entry>
<entry>
<string>SUGGESTED_TILE_SIZE</string>
<string>256,256</string>
</entry>
<entry>
<string>USE_JAI_IMAGEREAD</string>
<string>false</string>
</entry>
<entry>
<string>BackgroundValues</string>
<string>-1.0</string>
</entry>
</parameters>
</coverage>