diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTCoverage.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTCoverage.java index f5a343e..d0609d4 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTCoverage.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTCoverage.java @@ -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 getDimensionInfo() { + List listDim = new ArrayList(); + 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"); diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTDimensionInfo.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTDimensionInfo.java new file mode 100644 index 0000000..9ee01f4 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTDimensionInfo.java @@ -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 . + */ +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; + } + + + +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTMetadataList.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTMetadataList.java new file mode 100644 index 0000000..bc56953 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTMetadataList.java @@ -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 . + */ +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 { + + private final List metadataList; + + /** + * @param list + */ + protected RESTMetadataList(Element list) { + List tmpList = new ArrayList(); + for(Element el : (List)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 iterator() { + return new RESTMetadataIterator(metadataList); + } + + private static class RESTMetadataIterator implements Iterator{ + + private final Iterator iter; + + /** + * @param iter + */ + public RESTMetadataIterator(List 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; + } + + } + +} diff --git a/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java b/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java new file mode 100644 index 0000000..39a46f2 --- /dev/null +++ b/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java @@ -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 . + */ +package it.geosolutions.geoserver.decoder; + +import it.geosolutions.geoserver.rest.decoder.RESTCoverage; +import it.geosolutions.geoserver.rest.decoder.RESTDimensionInfo; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.core.io.ClassPathResource; + +/** + * @author DamianoG + * + */ +public class MetadataDecoderTest { + + + @Test + public void testMetadataDimensionInfo() throws IOException { + + File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile(); + String coverageString = FileUtils.readFileToString(coverageFile); + RESTCoverage coverage = RESTCoverage.build(coverageString); + List list = coverage.getDimensionInfo(); + + Assert.assertEquals(list.size(),2); + + + for (RESTDimensionInfo el : list){ + if(el.getKey().equals("time")){ + Assert.assertEquals(el.getResolution(),null); + Assert.assertEquals(el.getPresentation(),"LIST"); + Assert.assertEquals(el.getKey(),"time"); + Assert.assertEquals(el.isEnabled(),true); + } + if(el.getKey().equals("elevation")){ + Assert.assertEquals(el.getResolution(),"2"); + Assert.assertEquals(el.getPresentation(),"DISCRETE_INTERVAL"); + Assert.assertEquals(el.getKey(),"elevation"); + Assert.assertEquals(el.isEnabled(),true); + } + } + + + + + + } +} diff --git a/src/test/resources/testdata/coverageExample.xml b/src/test/resources/testdata/coverageExample.xml new file mode 100644 index 0000000..1e41f79 --- /dev/null +++ b/src/test/resources/testdata/coverageExample.xml @@ -0,0 +1,97 @@ + + + granuleTestMosaic + granuleTestMosaic + + topp + + + granuleTestMosaic + GEOGCS["WGS 84", + DATUM["World Geodetic System 1984", + SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], + AUTHORITY["EPSG","6326"]], + PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], + UNIT["degree", 0.017453292519943295], + AXIS["Geodetic longitude", EAST], + AXIS["Geodetic latitude", NORTH], + AUTHORITY["EPSG","4326"]] + EPSG:4326 + + -180.0 + 180.0 + -90.0 + 90.0 + EPSG:4326 + + + -180.0 + 180.0 + -90.0 + 90.0 + EPSG:4326 + + NONE + true + true + + + + true + LIST + + + + + true + DISCRETE_INTERVAL + 2 + + + + + granuleTestMosaic + + + + + 0 0 + 540 270 + + + 0.6666666666666666 + -0.6666666666666666 + 0.0 + 0.0 + -179.66666666666666 + 89.66666666666667 + + EPSG:4326 + + + + AllowMultithreading + false + + + MaxAllowedTiles + 2147483647 + + + InputTransparentColor + + + + SUGGESTED_TILE_SIZE + 256,256 + + + USE_JAI_IMAGEREAD + false + + + BackgroundValues + -1.0 + + + \ No newline at end of file