diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java index 96a2b68..9840c17 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java @@ -43,8 +43,9 @@ import org.jdom.Namespace; * Parse a resource (FeatureType or Coverage) returned as XML REST objects. * * @author etj - * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | - * emmanuel.blondel@fao.org + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org + * @author Henry Rotzoll + * */ public class RESTResource { protected final Element rootElem; @@ -74,23 +75,22 @@ public class RESTResource { return rootElem.getChildText("abstract"); } - public List getKeywords(){ - List kwdsList = null; - - final Element keywordsRoot = rootElem.getChild("keywords"); - if(keywordsRoot != null){ - final List keywords = keywordsRoot.getChildren(); - if(keywords != null){ - kwdsList = new ArrayList(keywords.size()); - for(Element keyword : keywords){ - kwdsList.add(keyword.getValue()); - } - } - } - return kwdsList; + public List getKeywords() { + List kwdsList = null; + + final Element keywordsRoot = rootElem.getChild("keywords"); + if (keywordsRoot != null) { + final List keywords = keywordsRoot.getChildren(); + if (keywords != null) { + kwdsList = new ArrayList(keywords.size()); + for (Element keyword : keywords) { + kwdsList.add(keyword.getValue()); + } + } + } + return kwdsList; } - - + public String getNameSpace() { return rootElem.getChild("namespace").getChildText("name"); } @@ -154,79 +154,77 @@ public class RESTResource { throw new UnsupportedOperationException("This method is specific for RESTFeatureType"); } - /** - * Decodes the list of MetadataLinkInfo from the GeoServer Resource - * - * @author Emmanuel Blondel - * - * @return the list of GSMetadataLinkEncoder - */ - public List getEncodedMetadataLinkInfoList() { - List metaLinksList = null; + /** + * Decodes the list of MetadataLinkInfo from the GeoServer Resource + * + * @since gs-2.4.x + * + * @return the list of GSMetadataLinkEncoder + */ + public List getEncodedMetadataLinkInfoList() { + List metaLinksList = null; - final Element metaLinksRoot = rootElem.getChild("metadataLinks"); - if(metaLinksRoot!=null){ - final List metaLinks = metaLinksRoot.getChildren(); - if (metaLinks != null) { - metaLinksList = new ArrayList( - metaLinks.size()); - for (Element metaLink : metaLinks) { - final GSMetadataLinkInfoEncoder metaLinkEnc = new GSMetadataLinkInfoEncoder(); - metaLinkEnc.setType(metaLink.getChildText(ResourceMetadataLinkInfo.type.name())); - metaLinkEnc.setMetadataType(metaLink.getChildText(ResourceMetadataLinkInfo.metadataType.name())); - metaLinkEnc.setContent(metaLink.getChildText(ResourceMetadataLinkInfo.content.name())); - metaLinksList.add(metaLinkEnc); - } - - } - } - return metaLinksList; - } - - /** - * Decodes the list of GSCoverageDimensionEncoder from the GeoServer Resource - * - * @author Henry Rotzoll - * - * @return the list of GSCoverageDimensionEncoder - */ - public List getEncodedDimensionsInfoList() - { - List dimensionList = null; - final Element dimensionsRoot = rootElem.getChild("dimensions"); - - if(dimensionsRoot!=null) - { - final List dimensions = dimensionsRoot.getChildren(); - if (dimensions != null) - { - dimensionList = new ArrayList(dimensions.size()); - for (Element coverageDimension : dimensions) - { - final String name = coverageDimension.getChildText("name"); - final String description = coverageDimension.getChildText("description"); - String rangeMin = null; - String rangeMax = null; - final Element rangeElement = coverageDimension.getChild("range"); - if(rangeElement != null) - { - rangeMin = rangeElement.getChildText("min"); - rangeMax = rangeElement.getChildText("max"); - } - final String unit = coverageDimension.getChildText("unit"); - String dimensionTypeName = null; - final Element dimensionTypeElement = coverageDimension.getChild("dimensionType"); - if(dimensionTypeElement != null) - { - dimensionTypeName = dimensionTypeElement.getChildText("name"); - } - final GSCoverageDimensionEncoder coverageDimensionEncoder = new GSCoverageDimensionEncoder(name, description, rangeMin, rangeMax, unit, dimensionTypeName); - dimensionList.add(coverageDimensionEncoder); - } - - } + final Element metaLinksRoot = rootElem.getChild("metadataLinks"); + if (metaLinksRoot != null) { + final List metaLinks = metaLinksRoot.getChildren(); + if (metaLinks != null) { + metaLinksList = new ArrayList(metaLinks.size()); + for (Element metaLink : metaLinks) { + final GSMetadataLinkInfoEncoder metaLinkEnc = new GSMetadataLinkInfoEncoder(); + metaLinkEnc + .setType(metaLink.getChildText(ResourceMetadataLinkInfo.type.name())); + metaLinkEnc.setMetadataType(metaLink + .getChildText(ResourceMetadataLinkInfo.metadataType.name())); + metaLinkEnc.setContent(metaLink.getChildText(ResourceMetadataLinkInfo.content + .name())); + metaLinksList.add(metaLinkEnc); + } + + } } - - return dimensionList; - } + return metaLinksList; + } + + /** + * Decodes the list of GSCoverageDimensionEncoder from the GeoServer Resource + * + * @since gs-2.4.x + * + * @return the list of GSCoverageDimensionEncoder + */ + public List getEncodedDimensionsInfoList() { + List dimensionList = null; + final Element dimensionsRoot = rootElem.getChild("dimensions"); + + if (dimensionsRoot != null) { + final List dimensions = dimensionsRoot.getChildren(); + if (dimensions != null) { + dimensionList = new ArrayList(dimensions.size()); + for (Element coverageDimension : dimensions) { + final String name = coverageDimension.getChildText("name"); + final String description = coverageDimension.getChildText("description"); + String rangeMin = null; + String rangeMax = null; + final Element rangeElement = coverageDimension.getChild("range"); + if (rangeElement != null) { + rangeMin = rangeElement.getChildText("min"); + rangeMax = rangeElement.getChildText("max"); + } + final String unit = coverageDimension.getChildText("unit"); + String dimensionTypeName = null; + final Element dimensionTypeElement = coverageDimension + .getChild("dimensionType"); + if (dimensionTypeElement != null) { + dimensionTypeName = dimensionTypeElement.getChildText("name"); + } + final GSCoverageDimensionEncoder coverageDimensionEncoder = new GSCoverageDimensionEncoder( + name, description, rangeMin, rangeMax, unit, dimensionTypeName); + dimensionList.add(coverageDimensionEncoder); + } + + } + } + + return dimensionList; + } } \ No newline at end of file diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java index e36309b..7208762 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java @@ -26,7 +26,6 @@ package it.geosolutions.geoserver.rest.encoder; import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder; -import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder; @@ -48,57 +47,58 @@ import org.jdom.filter.Filter; * * @author ETj (etj at geo-solutions.it) * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it - * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | - * emmanuel.blondel@fao.org + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org + * @author Henry Rotzoll */ -public abstract class GSResourceEncoder - extends PropertyXMLEncoder { - public final static String NAME = "name"; - public final static String NATIVENAME = "nativeName"; - public final static String METADATA="metadata"; - public final static String KEYWORDS="keywords"; - public final static String METADATALINKS="metadataLinks"; - public final static String DIMENSIONS="dimensions"; +public abstract class GSResourceEncoder extends PropertyXMLEncoder { + public final static String NAME = "name"; - final private GSMetadataEncoder metadata = new GSMetadataEncoder(); - final private Element keywordsListEncoder = new Element(KEYWORDS); - final private Element metadataLinksListEncoder = new Element(METADATALINKS); - final private Element dimensionsEncoder = new Element(DIMENSIONS); - - private class GSMetadataEncoder extends NestedElementEncoder{ - public GSMetadataEncoder() { - super(METADATA); - } - } + public final static String NATIVENAME = "nativeName"; - /** - * @param rootName - * Actually 'feature' or 'coverage' - * @see GSFeatureTypeEncoder - * @see GSCoverageEncoder - */ - protected GSResourceEncoder(final String rootName) { - super(rootName); - add("enabled", "true"); + public final static String METADATA = "metadata"; - // Link members to the parent - addContent(metadata.getRoot()); - addContent(keywordsListEncoder); - addContent(metadataLinksListEncoder); - } + public final static String KEYWORDS = "keywords"; - public void setEnabled(boolean enabled) { - set("enabled", (enabled) ? "true" : "false"); - } + public final static String METADATALINKS = "metadataLinks"; - - /** - * @param key - * @param dimensionInfo - */ - protected void addMetadata(String key, XmlElement dimensionInfo) { - metadata.add(key, dimensionInfo.getRoot()); - } + final private GSMetadataEncoder metadata = new GSMetadataEncoder(); + + final private Element keywordsListEncoder = new Element(KEYWORDS); + + final private Element metadataLinksListEncoder = new Element(METADATALINKS); + + private class GSMetadataEncoder extends NestedElementEncoder { + public GSMetadataEncoder() { + super(METADATA); + } + } + + /** + * @param rootName Actually 'feature' or 'coverage' + * @see GSFeatureTypeEncoder + * @see GSCoverageEncoder + */ + protected GSResourceEncoder(final String rootName) { + super(rootName); + add("enabled", "true"); + + // Link members to the parent + addContent(metadata.getRoot()); + addContent(keywordsListEncoder); + addContent(metadataLinksListEncoder); + } + + public void setEnabled(boolean enabled) { + set("enabled", (enabled) ? "true" : "false"); + } + + /** + * @param key + * @param dimensionInfo + */ + protected void addMetadata(String key, XmlElement dimensionInfo) { + metadata.add(key, dimensionInfo.getRoot()); + } /** * @deprecated Use {@link #setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be set as protected for internal use only @@ -108,7 +108,7 @@ public abstract class GSResourceEncoder public void setMetadata(String key, XmlElement dimensionInfo) { metadata.set(key, dimensionInfo.getRoot()); } - + /** * @param key * @param dimensionInfo @@ -116,7 +116,7 @@ public abstract class GSResourceEncoder protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) { addMetadataDimension(key, dimensionInfo, false); } - + /** * Add the metadata for a custom dimension. * @@ -124,21 +124,22 @@ public abstract class GSResourceEncoder * @param dimensionInfo {@link GSDimensionInfoEncoder} with additional information about the dimension * @param custom is the dimension custom or not? */ - protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo, boolean custom) { - if(custom){ - metadata.set("custom_dimension_"+key.toUpperCase(), dimensionInfo.getRoot()); - }else{ + protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo, + boolean custom) { + if (custom) { + metadata.set("custom_dimension_" + key.toUpperCase(), dimensionInfo.getRoot()); + } else { metadata.add(key, dimensionInfo.getRoot()); } } public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) { - setMetadataDimension(key, dimensionInfo, false); + setMetadataDimension(key, dimensionInfo, false); } public void setMetadataString(String key, String value) { - metadata.set(key, value); - } + metadata.set(key, value); + } /** * Set the metadata for a custom dimension. @@ -147,140 +148,85 @@ public abstract class GSResourceEncoder * @param dimensionInfo {@link GSDimensionInfoEncoder} with additional information about the dimension * @param custom is the dimension custom or not? */ - public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo, boolean custom) { - if(custom){ - metadata.set("custom_dimension_"+key.toUpperCase(), dimensionInfo.getRoot()); - }else{ + public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo, + boolean custom) { + if (custom) { + metadata.set("custom_dimension_" + key.toUpperCase(), dimensionInfo.getRoot()); + } else { metadata.set(key, dimensionInfo.getRoot()); } - } - /** - * @param key - * the name of the metadata to add (f.e.: elevation, time) - * @return true if something is removed, false otherwise - */ - public boolean delMetadata(String key) { - return metadata.remove(key); - } + } + /** + * @param key the name of the metadata to add (f.e.: elevation, time) + * @return true if something is removed, false otherwise + */ + public boolean delMetadata(String key) { + return metadata.remove(key); + } - public void addKeyword(String keyword) { - final Element el = new Element("string"); - el.setText(keyword); - keywordsListEncoder.addContent(el); - } + public void addKeyword(String keyword) { + final Element el = new Element("string"); + el.setText(keyword); + keywordsListEncoder.addContent(el); + } - /** - * delete a keyword from the list - * - * @param keyword - * @return true if something is removed, false otherwise - */ - public boolean delKeyword(final String keyword) { - final Element el = new Element("string"); - el.setText(keyword); - return (keywordsListEncoder.removeContent(new Filter() { - private static final long serialVersionUID = 1L; + /** + * delete a keyword from the list + * + * @param keyword + * @return true if something is removed, false otherwise + */ + public boolean delKeyword(final String keyword) { + final Element el = new Element("string"); + el.setText(keyword); + return (keywordsListEncoder.removeContent(new Filter() { + private static final long serialVersionUID = 1L; - public boolean matches(Object obj) { - if (((Element) obj).getText().equals(keyword)) { - return true; - } - return false; - } - })).size() == 0 ? false : true; - } + public boolean matches(Object obj) { + if (((Element) obj).getText().equals(keyword)) { + return true; + } + return false; + } + })).size() == 0 ? false : true; + } - /** - * Adds a MetadataLinkInfo to the GeoServer Resource - * - * @param MetadataLink - * - * @author Emmanuel Blondel - */ - public void addMetadataLinkInfo(GSMetadataLinkInfoEncoder metadataLinkInfo) { - metadataLinksListEncoder.addContent(metadataLinkInfo.getRoot()); - } + /** + * Adds a MetadataLinkInfo to the GeoServer Resource + * + * @param MetadataLink + * + */ + public void addMetadataLinkInfo(GSMetadataLinkInfoEncoder metadataLinkInfo) { + metadataLinksListEncoder.addContent(metadataLinkInfo.getRoot()); + } - /** - * Adds quickly a MetadataLinkInfo to the GeoServer Resource - * - * @author Emmanuel Blondel - * - * @param type - * @param metadataType - * @param content - */ - public void addMetadataLinkInfo(String type, String metadataType, - String content) { - final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder( - type, metadataType, content); - metadataLinksListEncoder.addContent(mde.getRoot()); - } + /** + * Adds quickly a MetadataLinkInfo to the GeoServer Resource + * + * + * @param type + * @param metadataType + * @param content + */ + public void addMetadataLinkInfo(String type, String metadataType, String content) { + final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder(type, metadataType, + content); + metadataLinksListEncoder.addContent(mde.getRoot()); + } - /** - * Deletes a metadataLinkInfo from the list using the metadataURL - * (MetadataLinkInfo content) - * - * @author Emmanuel Blondel - * - * @param metadataURL - * @return true if something is removed, false otherwise - */ - public boolean delMetadataLinkInfo(final String metadataURL) { - return (metadataLinksListEncoder - .removeContent(GSMetadataLinkInfoEncoder - .getFilterByContent(metadataURL))).size() == 0 ? false - : true; - } - - /** - * Adds a CoverageDimensionInfo to the GeoServer Resource - * - * @param coverageDimensionInfo - * - * @author Henry Rotzoll - */ - public void addCoverageDimensionInfo (GSCoverageDimensionEncoder coverageDimensionInfo) { - if(ElementUtils.contains(getRoot(), DIMENSIONS) == null)addContent(dimensionsEncoder); - dimensionsEncoder.addContent(coverageDimensionInfo.getRoot()); - } + /** + * Deletes a metadataLinkInfo from the list using the metadataURL (MetadataLinkInfo content) + * + * @param metadataURL + * @return true if something is removed, false otherwise + */ + public boolean delMetadataLinkInfo(final String metadataURL) { + return (metadataLinksListEncoder.removeContent(GSMetadataLinkInfoEncoder + .getFilterByContent(metadataURL))).size() == 0 ? false : true; + } - /** - * Adds quickly a CoverageDimensionInfo to the GeoServer Resource - * - * @author Henry Rotzoll - * - * @param name - * @param description - * @param rangeMin - * @param rangeMax - * @param unit - * @param dimensionType - */ - public void addCoverageDimensionInfo(String name, String description, String rangeMin, String rangeMax, String unit, String dimensionType) { - final GSCoverageDimensionEncoder coverageDimensionEncoder = new GSCoverageDimensionEncoder( - name, description, rangeMin, rangeMax, unit, dimensionType); - addCoverageDimensionInfo(coverageDimensionEncoder); - } - - /** - * Deletes a CoverageDimensionInfo from the list using the CoverageDimension Name - * (CoverageDimensionInfo content) - * - * @author Henry Rotzoll - * - * @param coverageDimensionName - * @return true if something is removed, false otherwise - */ - public boolean delCoverageDimensionInfo(final String coverageDimensionName) { - return (dimensionsEncoder - .removeContent(GSCoverageDimensionEncoder - .getFilterByContent(coverageDimensionName))).size() == 0 ? false - : true; - } - - /** * Reprojection policy for a published layer. One of: *
    @@ -289,95 +235,90 @@ public abstract class GSResourceEncoder *
  • {@link #NONE} No reprojection (use native CRS) *
*/ - public enum ProjectionPolicy { + public enum ProjectionPolicy { /** Reproject from native to declared CRS */ REPROJECT_TO_DECLARED, /** Use the declared CRS (ignore native) */ FORCE_DECLARED, /** Keep native */ NONE - } + } - private final static String PROJECTIONPOLICY = "projectionPolicy"; + private final static String PROJECTIONPOLICY = "projectionPolicy"; - /** - * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED - * - */ - protected void addProjectionPolicy(ProjectionPolicy policy) { - add(PROJECTIONPOLICY, policy.toString()); - } + /** + * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED + * + */ + protected void addProjectionPolicy(ProjectionPolicy policy) { + add(PROJECTIONPOLICY, policy.toString()); + } - /** - * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED - */ - public void setProjectionPolicy(ProjectionPolicy policy) { - set(PROJECTIONPOLICY, policy.toString()); - } + /** + * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED + */ + public void setProjectionPolicy(ProjectionPolicy policy) { + set(PROJECTIONPOLICY, policy.toString()); + } - /** - * Add the 'name' node with a text value from 'name' - * - * @note REQUIRED to configure a resource - */ - protected void addName(final String name) { - add(NAME, name); - } + /** + * Add the 'name' node with a text value from 'name' + * + * @note REQUIRED to configure a resource + */ + protected void addName(final String name) { + add(NAME, name); + } - /** - * Set or modify the 'name' node with a text value from 'name' - * - * @note REQUIRED to configure a resource - */ - public void setName(final String name) { - set(NAME, name); - } + /** + * Set or modify the 'name' node with a text value from 'name' + * + * @note REQUIRED to configure a resource + */ + public void setName(final String name) { + set(NAME, name); + } - public String getName() { - final Element nameNode = ElementUtils.contains(getRoot(), NAME, 1); - if (nameNode != null) - return nameNode.getText(); - else - return null; - } - - - /** - * Add the 'nativename' node with a text value from 'name' - * - * - */ - protected void addNativeName(final String nativename) { - add(NATIVENAME, nativename); - } + public String getName() { + final Element nameNode = ElementUtils.contains(getRoot(), NAME, 1); + if (nameNode != null) + return nameNode.getText(); + else + return null; + } - - /** - * Set or modify the 'nativename' node with a text value from 'name' - * - * @note if not specified, the nativeName will be set with the value of the - * 'name' node. - * - */ - public void setNativeName(final String nativename) { - set(NATIVENAME, nativename); - } + /** + * Add the 'nativename' node with a text value from 'name' + * + * + */ + protected void addNativeName(final String nativename) { + add(NATIVENAME, nativename); + } + + /** + * Set or modify the 'nativename' node with a text value from 'name' + * + * @note if not specified, the nativeName will be set with the value of the 'name' node. + * + */ + public void setNativeName(final String nativename) { + set(NATIVENAME, nativename); + } + + /** + * Get the nativeName + * + * @return + */ + public String getNativeName() { + final Element nameNode = ElementUtils.contains(getRoot(), NATIVENAME, 1); + if (nameNode != null) + return nameNode.getText(); + else + return null; + } - - /** - * Get the nativeName - * - * @return - */ - public String getNativeName() { - final Element nameNode = ElementUtils.contains(getRoot(), NATIVENAME, 1); - if (nameNode != null) - return nameNode.getText(); - else - return null; - } - - private final static String DESCRIPTION = "description"; /** @@ -394,8 +335,9 @@ public abstract class GSResourceEncoder public void setDescription(final String description) { set(DESCRIPTION, description); } - + private final static String ABSTRACT = "abstract"; + /** * Add the 'abstract' node with a text value from 'abstract' * @@ -403,6 +345,7 @@ public abstract class GSResourceEncoder protected void addAbstract(final String _abstract) { add(ABSTRACT, _abstract); } + /** * Set or modify the 'abstract' node with a text value from 'abstract' */ @@ -410,116 +353,124 @@ public abstract class GSResourceEncoder set(ABSTRACT, _abstract); } - private final static String TITLE = "title"; + private final static String TITLE = "title"; - /** - * Add the 'title' node with a text value from 'title' - * - */ - protected void addTitle(final String title) { - add(TITLE, title); - } + /** + * Add the 'title' node with a text value from 'title' + * + */ + protected void addTitle(final String title) { + add(TITLE, title); + } - /** - * Set or modify the 'title' node with a text value from 'title' - */ - public void setTitle(final String title) { - set(TITLE, title); - } + /** + * Set or modify the 'title' node with a text value from 'title' + */ + public void setTitle(final String title) { + set(TITLE, title); + } - private final static String SRS = "srs"; + private final static String SRS = "srs"; - /** - * Add the 'SRS' node with a text value from 'srs' - */ - protected void addSRS(final String srs) { - add(SRS, srs); - } + /** + * Add the 'SRS' node with a text value from 'srs' + */ + protected void addSRS(final String srs) { + add(SRS, srs); + } - /** - * Set or modify the 'SRS' node with a text value from 'srs' - */ - public void setSRS(final String srs) { - set(SRS, srs); - } - - private final static String NATIVECRS = "nativeCRS"; + /** + * Set or modify the 'SRS' node with a text value from 'srs' + */ + public void setSRS(final String srs) { + set(SRS, srs); + } - /** - * Add the 'nativeCRS' node with a text value from 'nativeCRS' - */ - protected void addNativeCRS(final String nativeCRS) { - add(NATIVECRS, nativeCRS); - } + private final static String NATIVECRS = "nativeCRS"; - /** - * Set or modify the 'nativeCRS' node with a text value from 'nativeCRS' - */ - public void setNativeCRS(final String nativeCRS) { - set(NATIVECRS, nativeCRS); - } + /** + * Add the 'nativeCRS' node with a text value from 'nativeCRS' + */ + protected void addNativeCRS(final String nativeCRS) { + add(NATIVECRS, nativeCRS); + } - private final static String LATLONBBMINX = "latLonBoundingBox/minx"; - private final static String LATLONBBMAXX = "latLonBoundingBox/maxx"; - private final static String LATLONBBMINY = "latLonBoundingBox/miny"; - private final static String LATLONBBMAXY = "latLonBoundingBox/maxy"; - private final static String LATLONBBCRS = "latLonBoundingBox/crs"; + /** + * Set or modify the 'nativeCRS' node with a text value from 'nativeCRS' + */ + public void setNativeCRS(final String nativeCRS) { + set(NATIVECRS, nativeCRS); + } - /** - * - * @param minx - * @param maxy - * @param maxx - * @param miny - * @param crs - */ - protected void addLatLonBoundingBox(double minx, double miny, double maxx, - double maxy, final String crs) { - add(LATLONBBMINX, String.valueOf(minx)); - add(LATLONBBMINY, String.valueOf(miny)); - add(LATLONBBMAXY, String.valueOf(maxy)); - add(LATLONBBMAXX, String.valueOf(maxx)); - add(LATLONBBCRS, crs); - } + private final static String LATLONBBMINX = "latLonBoundingBox/minx"; - public void setLatLonBoundingBox(double minx, double miny, double maxx, - double maxy, final String crs) { - set(LATLONBBMINX, String.valueOf(minx)); - set(LATLONBBMAXY, String.valueOf(maxy)); - set(LATLONBBMAXX, String.valueOf(maxx)); - set(LATLONBBMINY, String.valueOf(miny)); - set(LATLONBBCRS, crs); - } + private final static String LATLONBBMAXX = "latLonBoundingBox/maxx"; - private final static String NATIVEBBMINX = "nativeBoundingBox/minx"; - private final static String NATIVEBBMAXX = "nativeBoundingBox/maxx"; - private final static String NATIVEBBMINY = "nativeBoundingBox/miny"; - private final static String NATIVEBBMAXY = "nativeBoundingBox/maxy"; - private final static String NATIVEBBCRS = "nativeBoundingBox/crs"; + private final static String LATLONBBMINY = "latLonBoundingBox/miny"; - /** - * @param minx - * @param maxy - * @param maxx - * @param miny - * @param crs - */ - protected void addNativeBoundingBox(double minx, double miny, double maxx, - double maxy, final String crs) { - add(NATIVEBBMINX, String.valueOf(minx)); - add(NATIVEBBMAXY, String.valueOf(maxy)); - add(NATIVEBBMAXX, String.valueOf(maxx)); - add(NATIVEBBMINY, String.valueOf(miny)); - add(NATIVEBBCRS, crs); - } + private final static String LATLONBBMAXY = "latLonBoundingBox/maxy"; - public void setNativeBoundingBox(double minx, double miny, double maxx, - double maxy, final String crs) { - set(NATIVEBBMINX, String.valueOf(minx)); - set(NATIVEBBMAXY, String.valueOf(maxy)); - set(NATIVEBBMAXX, String.valueOf(maxx)); - set(NATIVEBBMINY, String.valueOf(miny)); - set(NATIVEBBCRS, crs); - } + private final static String LATLONBBCRS = "latLonBoundingBox/crs"; + + /** + * + * @param minx + * @param maxy + * @param maxx + * @param miny + * @param crs + */ + protected void addLatLonBoundingBox(double minx, double miny, double maxx, double maxy, + final String crs) { + add(LATLONBBMINX, String.valueOf(minx)); + add(LATLONBBMINY, String.valueOf(miny)); + add(LATLONBBMAXY, String.valueOf(maxy)); + add(LATLONBBMAXX, String.valueOf(maxx)); + add(LATLONBBCRS, crs); + } + + public void setLatLonBoundingBox(double minx, double miny, double maxx, double maxy, + final String crs) { + set(LATLONBBMINX, String.valueOf(minx)); + set(LATLONBBMAXY, String.valueOf(maxy)); + set(LATLONBBMAXX, String.valueOf(maxx)); + set(LATLONBBMINY, String.valueOf(miny)); + set(LATLONBBCRS, crs); + } + + private final static String NATIVEBBMINX = "nativeBoundingBox/minx"; + + private final static String NATIVEBBMAXX = "nativeBoundingBox/maxx"; + + private final static String NATIVEBBMINY = "nativeBoundingBox/miny"; + + private final static String NATIVEBBMAXY = "nativeBoundingBox/maxy"; + + private final static String NATIVEBBCRS = "nativeBoundingBox/crs"; + + /** + * @param minx + * @param maxy + * @param maxx + * @param miny + * @param crs + */ + protected void addNativeBoundingBox(double minx, double miny, double maxx, double maxy, + final String crs) { + add(NATIVEBBMINX, String.valueOf(minx)); + add(NATIVEBBMAXY, String.valueOf(maxy)); + add(NATIVEBBMAXX, String.valueOf(maxx)); + add(NATIVEBBMINY, String.valueOf(miny)); + add(NATIVEBBCRS, crs); + } + + public void setNativeBoundingBox(double minx, double miny, double maxx, double maxy, + final String crs) { + set(NATIVEBBMINX, String.valueOf(minx)); + set(NATIVEBBMAXY, String.valueOf(maxy)); + set(NATIVEBBMAXX, String.valueOf(maxx)); + set(NATIVEBBMINY, String.valueOf(miny)); + set(NATIVEBBCRS, crs); + } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java index f08c13a..d549005 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java @@ -25,38 +25,86 @@ package it.geosolutions.geoserver.rest.encoder.coverage; -import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; -import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; +import org.jdom.Element; +import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; +import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder; +import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; /** - * Creates an XML + * Creates an XML * * @author ETj (etj at geo-solutions.it) * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it * */ public class GSCoverageEncoder extends GSResourceEncoder { + + public final static String DIMENSIONS = "dimensions"; - public GSCoverageEncoder() { + final private Element dimensionsEncoder = new Element(DIMENSIONS); + + public GSCoverageEncoder() { super("coverage"); - } - + addContent(dimensionsEncoder); + } + /** * @param key * @param dimensionInfo * @deprecated Use {@link GSResourceEncoder#addMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon */ - protected void addMetadata(String key, GSDimensionInfoEncoder dimensionInfo) { - super.addMetadata(key, dimensionInfo); - } + protected void addMetadata(String key, GSDimensionInfoEncoder dimensionInfo) { + super.addMetadata(key, dimensionInfo); + } /** * @deprecated Use {@link GSResourceEncoder#setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon * @param key * @param dimensionInfo */ - public void setMetadata(String key, GSDimensionInfoEncoder dimensionInfo) { - super.setMetadata(key, dimensionInfo); - } + public void setMetadata(String key, GSDimensionInfoEncoder dimensionInfo) { + super.setMetadata(key, dimensionInfo); + } + + /** + * Adds a CoverageDimensionInfo to the GeoServer Resource + * + * @param coverageDimensionInfo + * + */ + public void addCoverageDimensionInfo(GSCoverageDimensionEncoder coverageDimensionInfo) { + if (ElementUtils.contains(getRoot(), DIMENSIONS) == null) + addContent(dimensionsEncoder); + dimensionsEncoder.addContent(coverageDimensionInfo.getRoot()); + } + + /** + * Adds quickly a CoverageDimensionInfo to the GeoServer Resource + * + * @param name + * @param description + * @param rangeMin + * @param rangeMax + * @param unit + * @param dimensionType + */ + public void addCoverageDimensionInfo(String name, String description, String rangeMin, + String rangeMax, String unit, String dimensionType) { + final GSCoverageDimensionEncoder coverageDimensionEncoder = new GSCoverageDimensionEncoder( + name, description, rangeMin, rangeMax, unit, dimensionType); + addCoverageDimensionInfo(coverageDimensionEncoder); + } + + /** + * Deletes a CoverageDimensionInfo from the list using the CoverageDimension Name (CoverageDimensionInfo content) + * + * @param coverageDimensionName + * @return true if something is removed, false otherwise + */ + public boolean delCoverageDimensionInfo(final String coverageDimensionName) { + return (dimensionsEncoder.removeContent(GSCoverageDimensionEncoder + .getFilterByContent(coverageDimensionName))).size() == 0 ? false : true; + } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoder.java index 5adbbf8..4f69fee 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoder.java @@ -31,30 +31,34 @@ import org.jdom.Element; import org.jdom.filter.Filter; /** - * GSCoverageDimension - encodes a CoverageDimension for a given GeoServer Resource - * (feature type /coverage), as follows: + * GSCoverageDimension - encodes a CoverageDimension for a given GeoServer Resource (feature type /coverage), as follows: + * *
  * {@code
- * final GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder("GRAY_INDEX", "GridSampleDimension[-2.147483648E9,-2.147483648E9]", String.valueOf(Integer.MIN_VALUE), String.valueOf(Integer.MAX_VALUE), "dobson units³", "REAL_32BITS");
+ * final GSCoverageDimensionEncoder gsCoverageDimensionEncoder = 
+ *      new GSCoverageDimensionEncoder("GRAY_INDEX", "GridSampleDimension[-2.147483648E9,-2.147483648E9]", 
+ *      String.valueOf(Integer.MIN_VALUE), String.valueOf(Integer.MAX_VALUE), "dobson units³", "REAL_32BITS");
  *  coverageEncoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder);
  * }
  * 
+ * * For this example, the XML output is: + * *
- * {@code
- *
- *	GRAY_INDEX
- *	GridSampleDimension[-2.147483648E9,2.147483648E9]
- *	
- *		-2.147483648E9
- *		2.147483647E9
- *	
- *	dobson units³
- *	
- * 		REAL_32BITS
- * 	
- *
- * }
+ *  {@code
+ * 
+ * 	GRAY_INDEX
+ * 	GridSampleDimension[-2.147483648E9,2.147483648E9]
+ * 	
+ * 		-2.147483648E9
+ * 		2.147483647E9
+ * 	
+ * 	dobson units³
+ * 	
+ *  		REAL_32BITS
+ *  	
+ * 
+ *  }
  * 
* * @author Henry Rotzoll (henry.rotzoll@dlr.de) @@ -62,333 +66,328 @@ import org.jdom.filter.Filter; */ public class GSCoverageDimensionEncoder extends XmlElement { - /** A class to filter the GSCoverageDimension by content - * - * - */ - private static class filterByContent implements Filter { + /** + * A class to filter the GSCoverageDimension by content + * + * + */ + private static class filterByContent implements Filter { - final private String key; + final private String key; - public filterByContent(String content) { - this.key = content; - } + public filterByContent(String content) { + this.key = content; + } - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public boolean matches(Object obj) { - Element el = ((Element) obj) - .getChild("name"); - if (el != null && el.getTextTrim().equals(key)) { - return true; - } - return false; - } - } + public boolean matches(Object obj) { + Element el = ((Element) obj).getChild("name"); + if (el != null && el.getTextTrim().equals(key)) { + return true; + } + return false; + } + } - /** - * Get a Filter using the GSCoverageDimensionEncoder content (GSCoverageDimensionEncoder name) - * - * @param content - * @return the filter - */ - public static Filter getFilterByContent(String content) { - return new filterByContent(content); - } + /** + * Get a Filter using the GSCoverageDimensionEncoder content (GSCoverageDimensionEncoder name) + * + * @param content + * @return the filter + */ + public static Filter getFilterByContent(String content) { + return new filterByContent(content); + } - /** - * Constructs a new GSCoverageDimensionEncoder - * - */ - public GSCoverageDimensionEncoder() { - super("coverageDimension"); - } + /** + * Constructs a new GSCoverageDimensionEncoder + * + */ + public GSCoverageDimensionEncoder() { + super("coverageDimension"); + } - /** - * Constructs quickly a GSCoverageDimensionEncoder info - * - * @param name - * @param description - * @param rangeMin - * @param rangeMax - * @param unit - * @param dimensionTypeName - */ - public GSCoverageDimensionEncoder(String name, String description, String rangeMin, String rangeMax, String unit, String dimensionTypeName) { - super("coverageDimension"); - this.setup(name, description, rangeMin, rangeMax, unit, dimensionTypeName); - } - - /** - * Set-up quickly a GSCoverageDimensionEncoder info - * - * @param name - * @param description - * @param rangeMin - * @param rangeMax - * @param unit - * @param dimensionTypeName - */ - protected void setup(String name, String description, String rangeMin, String rangeMax, String unit, String dimensionTypeName) - { - //name - setName(name); - - //description - setDescription(description); - - //range - setRange(rangeMin, rangeMax); - - //unit - setUnit(unit); - - //dimension Type - setDimensionType(dimensionTypeName); - } - - - /** - * Get the value of the GSCoverageDimensionEncoder member - * - * @param memberName - * @return the value of the GSCoverageDimensionEncoder member - */ - protected String getMember(String memberName) { - Element el = this.getRoot().getChild(memberName.toString()); - if (el != null) - return el.getTextTrim(); - else - return null; - } - - /** - * Deletes a GSCoverageDimensionEncoder member - * - * @param memberName - * @return true if the GSCoverageDimensionEncoder member is removed - */ - protected boolean delMemberIfExists(String memberName) { - if(ElementUtils.contains(getRoot(), memberName) != null) - { - return ElementUtils.remove(this.getRoot(), this.getRoot().getChild(memberName.toString())); - } - - return false; - } - - /** - * Set a GSCoverageDimensionEncoder member - * - * @param memberName - * @param memberValue - */ - protected void setMember(String memberName, String memberValue) { - if(memberName != null && !memberName.isEmpty() && memberValue != null && !memberValue.isEmpty()) - { - delMemberIfExists(memberName); //delete the element if it already exists - addMember(memberName.toString(), memberValue); - } - } - - /** - * adds a GSCoverageDimensionEncoder member - * - * @param memberName - * @param memberValue - */ - protected void addMember(String memberName, String memberValue) { - if(memberName != null && !memberName.isEmpty() && memberValue != null && ! memberValue.isEmpty()) - { - set(memberName.toString(), memberValue); - } - } - - /** - * Set the name - * - * @param name - */ - public void setName(String name){ - setMember("name", name); - } - - /** - * Deletes the name - * - * @param name - * @return true if removed - */ - public boolean delName(){ - return this.delMemberIfExists("name"); - } - - /** - * Get the description - * - * @return description - */ - public String getName(){ - return this.getMember("name"); - } - - /** - * Set the description - * - * @param description - */ - public void setDescription(String description){ - setMember("description", description); - } - - /** - * Deletes the description - * - * @param description - * @return true if removed - */ - public boolean delDescription(){ - return this.delMemberIfExists("description"); - } - - /** - * Get the description - * - * @return description - */ - public String getDescription(){ - return this.getMember("description"); - } - - /** - * Set the range - * - * @param range - */ - public void setRange(String rangeMin, String rangeMax){ - if(rangeMin != null && !rangeMin.isEmpty() && rangeMax != null && !rangeMax.isEmpty()) - { - remove("range"); - - final Element rangeElement = new Element("range"); - final Element rangeMinElement = new Element("min"); - rangeMinElement.setText(rangeMin); - final Element rangeMaxElement = new Element("max"); - rangeMaxElement.setText(rangeMax); - rangeElement.addContent(rangeMinElement); - rangeElement.addContent(rangeMaxElement); - addContent(rangeElement); - } - } - - /** - * Deletes the range - * - * @param range - * @return true if removed - */ - public boolean delRange(){ - return this.delMemberIfExists("range"); - } - - /** - * Get the range min - * - * @return range min - */ - public String getRangeMin(){ - final Element range = this.getRoot().getChild("range"); - if(range != null) - { - return range.getChildText("min"); - } - - return null; - } - - /** - * Get the range max - * - * @return range max - */ - public String getRangeMax(){ - final Element range = this.getRoot().getChild("range"); - if(range != null) - { - return range.getChildText("max"); - } - - return null; - } - - /** - * Set the unit - * - * @param unit - */ - public void setUnit(String unit){ - setMember("unit", unit); - } - - /** - * Deletes the type - * - * @param type - * @return true if removed - */ - public boolean delUnit(){ - return this.delMemberIfExists("unit"); - } - - /** - * Get the unit - * - * @return unit - */ - public String getUnit(){ - return this.getMember("unit"); - } - - /** - * Set the dimensionType - * - * @param dimensionType - */ - public void setDimensionType(String dimensionTypeName){ - if(dimensionTypeName != null && !dimensionTypeName.isEmpty()) - { - remove("dimensionType"); - - final Element dimensionTypeElement = new Element("dimensionType"); - final Element dimensionNameElement = new Element("name"); - dimensionNameElement.setText(dimensionTypeName); - dimensionTypeElement.addContent(dimensionNameElement); - addContent(dimensionTypeElement); - } - } - - /** - * Deletes the dimensionType - * - * @param dimensionType - * @return true if removed - */ - public boolean delDimensionType(){ - return this.delMemberIfExists("dimensionType"); - } - - /** - * Get the dimensionType name - * - * @return dimensionType name - */ - public String getDimensionTypeName(){ - final Element dimensionType = this.getRoot().getChild("dimensionType"); - if(dimensionType != null) - { - return dimensionType.getChildText("name"); - } - - return null; - } + /** + * Constructs quickly a GSCoverageDimensionEncoder info + * + * @param name + * @param description + * @param rangeMin + * @param rangeMax + * @param unit + * @param dimensionTypeName + */ + public GSCoverageDimensionEncoder(String name, String description, String rangeMin, + String rangeMax, String unit, String dimensionTypeName) { + super("coverageDimension"); + this.setup(name, description, rangeMin, rangeMax, unit, dimensionTypeName); + } + + /** + * Set-up quickly a GSCoverageDimensionEncoder info + * + * @param name + * @param description + * @param rangeMin + * @param rangeMax + * @param unit + * @param dimensionTypeName + */ + protected void setup(String name, String description, String rangeMin, String rangeMax, + String unit, String dimensionTypeName) { + // name + setName(name); + + // description + setDescription(description); + + // range + setRange(rangeMin, rangeMax); + + // unit + setUnit(unit); + + // dimension Type + setDimensionType(dimensionTypeName); + } + + /** + * Get the value of the GSCoverageDimensionEncoder member + * + * @param memberName + * @return the value of the GSCoverageDimensionEncoder member + */ + protected String getMember(String memberName) { + Element el = this.getRoot().getChild(memberName.toString()); + if (el != null) + return el.getTextTrim(); + else + return null; + } + + /** + * Deletes a GSCoverageDimensionEncoder member + * + * @param memberName + * @return true if the GSCoverageDimensionEncoder member is removed + */ + protected boolean delMemberIfExists(String memberName) { + if (ElementUtils.contains(getRoot(), memberName) != null) { + return ElementUtils.remove(this.getRoot(), + this.getRoot().getChild(memberName.toString())); + } + + return false; + } + + /** + * Set a GSCoverageDimensionEncoder member + * + * @param memberName + * @param memberValue + */ + protected void setMember(String memberName, String memberValue) { + if (memberName != null && !memberName.isEmpty() && memberValue != null + && !memberValue.isEmpty()) { + delMemberIfExists(memberName); // delete the element if it already exists + addMember(memberName.toString(), memberValue); + } + } + + /** + * adds a GSCoverageDimensionEncoder member + * + * @param memberName + * @param memberValue + */ + protected void addMember(String memberName, String memberValue) { + if (memberName != null && !memberName.isEmpty() && memberValue != null + && !memberValue.isEmpty()) { + set(memberName.toString(), memberValue); + } + } + + /** + * Set the name + * + * @param name + */ + public void setName(String name) { + setMember("name", name); + } + + /** + * Deletes the name + * + * @param name + * @return true if removed + */ + public boolean delName() { + return this.delMemberIfExists("name"); + } + + /** + * Get the description + * + * @return description + */ + public String getName() { + return this.getMember("name"); + } + + /** + * Set the description + * + * @param description + */ + public void setDescription(String description) { + setMember("description", description); + } + + /** + * Deletes the description + * + * @param description + * @return true if removed + */ + public boolean delDescription() { + return this.delMemberIfExists("description"); + } + + /** + * Get the description + * + * @return description + */ + public String getDescription() { + return this.getMember("description"); + } + + /** + * Set the range + * + * @param range + */ + public void setRange(String rangeMin, String rangeMax) { + if (rangeMin != null && !rangeMin.isEmpty() && rangeMax != null && !rangeMax.isEmpty()) { + remove("range"); + + final Element rangeElement = new Element("range"); + final Element rangeMinElement = new Element("min"); + rangeMinElement.setText(rangeMin); + final Element rangeMaxElement = new Element("max"); + rangeMaxElement.setText(rangeMax); + rangeElement.addContent(rangeMinElement); + rangeElement.addContent(rangeMaxElement); + addContent(rangeElement); + } + } + + /** + * Deletes the range + * + * @param range + * @return true if removed + */ + public boolean delRange() { + return this.delMemberIfExists("range"); + } + + /** + * Get the range min + * + * @return range min + */ + public String getRangeMin() { + final Element range = this.getRoot().getChild("range"); + if (range != null) { + return range.getChildText("min"); + } + + return null; + } + + /** + * Get the range max + * + * @return range max + */ + public String getRangeMax() { + final Element range = this.getRoot().getChild("range"); + if (range != null) { + return range.getChildText("max"); + } + + return null; + } + + /** + * Set the unit + * + * @param unit + */ + public void setUnit(String unit) { + setMember("unit", unit); + } + + /** + * Deletes the type + * + * @param type + * @return true if removed + */ + public boolean delUnit() { + return this.delMemberIfExists("unit"); + } + + /** + * Get the unit + * + * @return unit + */ + public String getUnit() { + return this.getMember("unit"); + } + + /** + * Set the dimensionType + * + * @param dimensionType + */ + public void setDimensionType(String dimensionTypeName) { + if (dimensionTypeName != null && !dimensionTypeName.isEmpty()) { + remove("dimensionType"); + + final Element dimensionTypeElement = new Element("dimensionType"); + final Element dimensionNameElement = new Element("name"); + dimensionNameElement.setText(dimensionTypeName); + dimensionTypeElement.addContent(dimensionNameElement); + addContent(dimensionTypeElement); + } + } + + /** + * Deletes the dimensionType + * + * @param dimensionType + * @return true if removed + */ + public boolean delDimensionType() { + return this.delMemberIfExists("dimensionType"); + } + + /** + * Get the dimensionType name + * + * @return dimensionType name + */ + public String getDimensionTypeName() { + final Element dimensionType = this.getRoot().getChild("dimensionType"); + if (dimensionType != null) { + return dimensionType.getChildText("name"); + } + + return null; + } } \ No newline at end of file diff --git a/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java b/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java index d06ca93..84f4be2 100644 --- a/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java @@ -19,112 +19,111 @@ import org.springframework.core.io.ClassPathResource; * * @author eblondel * @author Henry Rotzoll (henry.rotzoll@dlr.de) - * + * */ public class ResourceDecoderTest { - - - RESTCoverage coverage; - - @Before - public void setup() throws IOException{ - File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile(); - String coverageString = FileUtils.readFileToString(coverageFile); - coverage = RESTCoverage.build(coverageString); - } - - @Test - public void testName(){ - Assert.assertEquals(coverage.getName(),"granuleTestMosaic"); - } - - @Test - public void testNativeName(){ - Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic"); - } - - @Test - public void testTitle(){ - Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic"); - } - - @Test - public void testAbstract(){ - Assert.assertEquals(coverage.getAbstract(), "this is an abstract"); - } - - @Test - public void testKeywords(){ - List keywords = coverage.getKeywords(); - Assert.assertEquals(keywords.get(0), "keyword1"); - Assert.assertEquals(keywords.get(1), "keyword2"); - Assert.assertEquals(keywords.get(2), "keyword3"); - } - - @Test - public void testNameSpace(){ - Assert.assertEquals(coverage.getNameSpace(),"topp"); - } - - @Test - public void testStoreName(){ - Assert.assertEquals(coverage.getStoreName(), "granuleTestMosaic"); - } - - @Test - public void testStoreType(){ - Assert.assertEquals(coverage.getStoreType(), "coverageStore"); - } - - @Test - public void testStoreUrl(){ - Assert.assertEquals(coverage.getStoreUrl(), "http://localhost:8080/geoserver/rest/workspaces/topp/coveragestores/granuleTestMosaic.xml"); - } - - @Test - public void testCRS(){ - Assert.assertEquals(coverage.getCRS(), "EPSG:4326"); - } - - @Test - public void testBoundingBox(){ - Assert.assertEquals(coverage.getMinX(), -180.0, 0); - Assert.assertEquals(coverage.getMaxX(), 180.0, 0); - Assert.assertEquals(coverage.getMinY(), -90, 0); - Assert.assertEquals(coverage.getMaxY(), 90, 0); - } - - - @Test - public void testMetadataLinkInfo() throws IOException{ - + + RESTCoverage coverage; + + @Before + public void setup() throws IOException { + File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile(); + String coverageString = FileUtils.readFileToString(coverageFile); + coverage = RESTCoverage.build(coverageString); + } + + @Test + public void testName() { + Assert.assertEquals(coverage.getName(), "granuleTestMosaic"); + } + + @Test + public void testNativeName() { + Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic"); + } + + @Test + public void testTitle() { + Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic"); + } + + @Test + public void testAbstract() { + Assert.assertEquals(coverage.getAbstract(), "this is an abstract"); + } + + @Test + public void testKeywords() { + List keywords = coverage.getKeywords(); + Assert.assertEquals(keywords.get(0), "keyword1"); + Assert.assertEquals(keywords.get(1), "keyword2"); + Assert.assertEquals(keywords.get(2), "keyword3"); + } + + @Test + public void testNameSpace() { + Assert.assertEquals(coverage.getNameSpace(), "topp"); + } + + @Test + public void testStoreName() { + Assert.assertEquals(coverage.getStoreName(), "granuleTestMosaic"); + } + + @Test + public void testStoreType() { + Assert.assertEquals(coverage.getStoreType(), "coverageStore"); + } + + @Test + public void testStoreUrl() { + Assert.assertEquals(coverage.getStoreUrl(), + "http://localhost:8080/geoserver/rest/workspaces/topp/coveragestores/granuleTestMosaic.xml"); + } + + @Test + public void testCRS() { + Assert.assertEquals(coverage.getCRS(), "EPSG:4326"); + } + + @Test + public void testBoundingBox() { + Assert.assertEquals(coverage.getMinX(), -180.0, 0); + Assert.assertEquals(coverage.getMaxX(), 180.0, 0); + Assert.assertEquals(coverage.getMinY(), -90, 0); + Assert.assertEquals(coverage.getMaxY(), 90, 0); + } + + @Test + public void testMetadataLinkInfo() throws IOException { + List list = coverage.getEncodedMetadataLinkInfoList(); - + GSMetadataLinkInfoEncoder metadataLinkInfo1 = list.get(0); Assert.assertEquals("text/xml", metadataLinkInfo1.getType()); Assert.assertEquals("ISO19115:2003", metadataLinkInfo1.getMetadataType()); Assert.assertEquals("http://www.organization.org/metadata1", metadataLinkInfo1.getContent()); - + GSMetadataLinkInfoEncoder metadataLinkInfo2 = list.get(1); - Assert.assertEquals("text/html",metadataLinkInfo2.getType()); - Assert.assertEquals("ISO19115:2003",metadataLinkInfo2.getMetadataType()); - Assert.assertEquals("http://www.organization.org/metadata2",metadataLinkInfo2.getContent()); - - } - - @Test - public void testCoverageDimension() throws IOException{ - + Assert.assertEquals("text/html", metadataLinkInfo2.getType()); + Assert.assertEquals("ISO19115:2003", metadataLinkInfo2.getMetadataType()); + Assert.assertEquals("http://www.organization.org/metadata2", metadataLinkInfo2.getContent()); + + } + + @Test + public void testCoverageDimension() throws IOException { + List list = coverage.getEncodedDimensionsInfoList(); - + GSCoverageDimensionEncoder coverageDimension1 = list.get(0); Assert.assertEquals("GRAY_INDEX", coverageDimension1.getName()); - Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", coverageDimension1.getDescription()); + Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", + coverageDimension1.getDescription()); Assert.assertEquals("-inf", coverageDimension1.getRangeMin()); Assert.assertEquals("inf", coverageDimension1.getRangeMax()); Assert.assertEquals("dobson units³", coverageDimension1.getUnit()); Assert.assertEquals("REAL_32BITS", coverageDimension1.getDimensionTypeName()); - } - - + } + } diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java index 2803ca4..0c82101 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java @@ -21,6 +21,7 @@ package it.geosolutions.geoserver.rest.encoder.coverage; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; +import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation; import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; @@ -105,6 +106,8 @@ public class GSCoverageEncoderTest extends TestCase { encoder.addKeyword("..."); encoder.addKeyword("KEYWORD_N"); + + // Old style dimensions (into metadata) final GSDimensionInfoEncoder timeDimension=new GSDimensionInfoEncoder(true); timeDimension.setPresentation(Presentation.CONTINUOUS_INTERVAL); encoder.setMetadata("time", timeDimension); @@ -119,6 +122,12 @@ public class GSCoverageEncoderTest extends TestCase { final GSDimensionInfoEncoder elevationDimension=new GSDimensionInfoEncoder(true); elevationDimension.setPresentation(Presentation.LIST); encoder.setMetadata("elevation", elevationDimension); + + // New style dimensions (since gs-2.4.x) + GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder( + "GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", + "dobson units³", "REAL_32BITS"); + encoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder); if (LOGGER.isInfoEnabled()) LOGGER.info(encoder.toString()); diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoderTest.java index 1b90f8e..d6350a1 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/dimensions/GSCoverageDimensionEncoderTest.java @@ -19,52 +19,61 @@ */ package it.geosolutions.geoserver.rest.encoder.dimensions; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; + +import java.io.IOException; + import junit.framework.Assert; import org.junit.Test; /** -* -* @author Henry Rotzoll (henry.rotzoll@dlr.de) -* -*/ + * + * @author Henry Rotzoll (henry.rotzoll@dlr.de) + * + */ public class GSCoverageDimensionEncoderTest { - @Test - public void coverageDimensionTest(){ - GSCoverageDimensionEncoder encoder = new GSCoverageDimensionEncoder("GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units³", "REAL_32BITS"); + @Test + public void coverageDimensionTest() { + GSCoverageDimensionEncoder encoder = new GSCoverageDimensionEncoder("GRAY_INDEX", + "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units³", + "REAL_32BITS"); - Assert.assertEquals("GRAY_INDEX", encoder.getName()); - Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", encoder.getDescription()); - Assert.assertEquals("-inf", encoder.getRangeMin()); - Assert.assertEquals("inf", encoder.getRangeMax()); - Assert.assertEquals("dobson units³", encoder.getUnit()); - Assert.assertEquals("REAL_32BITS", encoder.getDimensionTypeName()); - - Assert.assertTrue(encoder.delName()); - Assert.assertTrue(encoder.delDescription()); - Assert.assertTrue(encoder.delRange()); - Assert.assertTrue(encoder.delUnit()); - Assert.assertTrue(encoder.delDimensionType()); - - Assert.assertNull( encoder.getName()); - Assert.assertNull(encoder.getDescription()); - Assert.assertNull(encoder.getRangeMin()); - Assert.assertNull(encoder.getRangeMax()); - Assert.assertNull(encoder.getUnit()); - Assert.assertNull(encoder.getDimensionTypeName()); - - encoder.setName("GRAY_INDEX"); - encoder.setDescription("GridSampleDimension[-Infinity,Infinity]"); - encoder.setRange("-inf", "inf"); - encoder.setUnit("dobson units³"); - encoder.setDimensionType("REAL_32BITS"); - - Assert.assertEquals("GRAY_INDEX", encoder.getName()); - Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", encoder.getDescription()); - Assert.assertEquals("-inf", encoder.getRangeMin()); - Assert.assertEquals("inf", encoder.getRangeMax()); - Assert.assertEquals("dobson units³", encoder.getUnit()); - Assert.assertEquals("REAL_32BITS", encoder.getDimensionTypeName()); - } + Assert.assertEquals("GRAY_INDEX", encoder.getName()); + Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", encoder.getDescription()); + Assert.assertEquals("-inf", encoder.getRangeMin()); + Assert.assertEquals("inf", encoder.getRangeMax()); + Assert.assertEquals("dobson units³", encoder.getUnit()); + Assert.assertEquals("REAL_32BITS", encoder.getDimensionTypeName()); + + Assert.assertTrue(encoder.delName()); + Assert.assertTrue(encoder.delDescription()); + Assert.assertTrue(encoder.delRange()); + Assert.assertTrue(encoder.delUnit()); + Assert.assertTrue(encoder.delDimensionType()); + + Assert.assertNull(encoder.getName()); + Assert.assertNull(encoder.getDescription()); + Assert.assertNull(encoder.getRangeMin()); + Assert.assertNull(encoder.getRangeMax()); + Assert.assertNull(encoder.getUnit()); + Assert.assertNull(encoder.getDimensionTypeName()); + + encoder.setName("GRAY_INDEX"); + encoder.setDescription("GridSampleDimension[-Infinity,Infinity]"); + encoder.setRange("-inf", "inf"); + encoder.setUnit("dobson units³"); + encoder.setDimensionType("REAL_32BITS"); + + Assert.assertEquals("GRAY_INDEX", encoder.getName()); + Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", encoder.getDescription()); + Assert.assertEquals("-inf", encoder.getRangeMin()); + Assert.assertEquals("inf", encoder.getRangeMax()); + Assert.assertEquals("dobson units³", encoder.getUnit()); + Assert.assertEquals("REAL_32BITS", encoder.getDimensionTypeName()); + } + } \ No newline at end of file diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java index 3465ab4..691b60b 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java @@ -53,15 +53,12 @@ import org.springframework.core.io.ClassPathResource; /** * - * Note on adding multiple available styles to the GSLayerEncoder: - to run the - * testIntegration(), 2 clones of the "point" style, named "point2" and "point3" - * have to be created. + * Note on adding multiple available styles to the GSLayerEncoder: - to run the testIntegration(), 2 clones of the "point" style, named "point2" and + * "point3" have to be created. * * @author ETj (etj at geo-solutions.it) * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it - * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | - * emmanuel.blondel@fao.org - * @author Henry Rotzoll (henry.rotzoll@dlr.de) + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org */ public class GSFeatureEncoderTest extends GeoserverRESTTest { protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class); @@ -87,91 +84,67 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { fte.setDescription("desc"); fte.setEnabled(true); - //metadataLink - GSMetadataLinkInfoEncoder metadatalink = new GSMetadataLinkInfoEncoder( - "text/xml", "ISO19115:2003", - "http://www.organization.org/metadata1"); + // metadataLink + GSMetadataLinkInfoEncoder metadatalink = new GSMetadataLinkInfoEncoder("text/xml", + "ISO19115:2003", "http://www.organization.org/metadata1"); fte.addMetadataLinkInfo(metadatalink); - - GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder("GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units³", "REAL_32BITS"); - fte.addCoverageDimensionInfo(gsCoverageDimensionEncoder); - - 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.setQueryable(true); - layerEncoder.setAdvertised(true); - layerEncoder.setDefaultStyle("point"); - layerEncoder.addStyle("point2"); - layerEncoder.addStyle("point3"); + 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.setQueryable(true); + layerEncoder.setAdvertised(true); - // authorityURL - GSAuthorityURLInfoEncoder authorityURL = new GSAuthorityURLInfoEncoder( - "authority1", "http://www.authority1.org"); - layerEncoder.addAuthorityURL(authorityURL); + layerEncoder.setDefaultStyle("point"); + layerEncoder.addStyle("point2"); + layerEncoder.addStyle("point3"); - // identifier - GSIdentifierInfoEncoder identifier1 = new GSIdentifierInfoEncoder( - "authority1", "identifier1"); - GSIdentifierInfoEncoder identifier2 = new GSIdentifierInfoEncoder( - "authority1", "another_identifier"); - layerEncoder.addIdentifier(identifier1); - layerEncoder.addIdentifier(identifier2); + // authorityURL + GSAuthorityURLInfoEncoder authorityURL = new GSAuthorityURLInfoEncoder("authority1", + "http://www.authority1.org"); + layerEncoder.addAuthorityURL(authorityURL); - publisher.createWorkspace(DEFAULT_WS); + // identifier + GSIdentifierInfoEncoder identifier1 = new GSIdentifierInfoEncoder("authority1", + "identifier1"); + GSIdentifierInfoEncoder identifier2 = new GSIdentifierInfoEncoder("authority1", + "another_identifier"); + layerEncoder.addIdentifier(identifier1); + layerEncoder.addIdentifier(identifier2); - File zipFile = new ClassPathResource("testdata/resttestshp.zip") - .getFile(); + publisher.createWorkspace(DEFAULT_WS); - // test insert - boolean published = publisher.publishShp(DEFAULT_WS, storeName, - layerName, zipFile); - assertTrue("publish() failed", published); - assertTrue(existsLayer(layerName)); + File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); - publisher.publishStyle(new File(new ClassPathResource("testdata") - .getFile(), "default_point.sld")); + // test insert + boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile); + assertTrue("publish() failed", published); + assertTrue(existsLayer(layerName)); - // optionally select the attributes to publish - RESTLayer layer = reader.getLayer(layerName); - RESTResource resource = reader.getResource(layer); - List attrs = resource.getEncodedAttributeList(); - assertNotNull(attrs); - for (GSAttributeEncoder enc : attrs) { - fte.setAttribute(enc); - } + publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(), + "default_point.sld")); - assertTrue(publisher.publishDBLayer(DEFAULT_WS, storeName, fte, - layerEncoder)); + // optionally select the attributes to publish + RESTLayer layer = reader.getLayer(layerName); + RESTResource resource = reader.getResource(layer); + List attrs = resource.getEncodedAttributeList(); + assertNotNull(attrs); + for (GSAttributeEncoder enc : attrs) { + fte.setAttribute(enc); + } + + assertTrue(publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder)); - } - - @Test - public void testCoverageDimension() throws IOException { - GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder(); - fte.setNativeName("testlayer"); - fte.setName("testlayer" + "_NEW"); - fte.setTitle("title"); - fte.setNativeCRS("EPSG:4326"); - fte.setDescription("desc"); - fte.setEnabled(true); - - assertFalse(fte.toString().contains("GRAY_INDEXGridSampleDimension[-Infinity,Infinity]-infinfdobson units³REAL_32BITS")); - - GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder("GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units³", "REAL_32BITS"); - fte.addCoverageDimensionInfo(gsCoverageDimensionEncoder); - LOGGER.debug("fte.toString() :" + fte.toString()); - assertTrue(fte.toString().contains("GRAY_INDEXGridSampleDimension[-Infinity,Infinity]-infinfdobson units³REAL_32BITS")); } + @Test public void testFeatureTypeEncoder() { @@ -180,9 +153,9 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { encoder.addKeyword("KEYWORD_2"); encoder.addKeyword("..."); encoder.addKeyword("KEYWORD_N"); - + encoder.setName("Layername"); - + encoder.setTitle("title"); encoder.addKeyword("TODO"); encoder.setNativeCRS("EPSG:4326"); @@ -195,24 +168,24 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { attribute.setAttribute(FeatureTypeAttribute.maxOccurs, "1"); attribute.setAttribute(FeatureTypeAttribute.minOccurs, "0"); attribute.setAttribute(FeatureTypeAttribute.nillable, "true"); - + encoder.setAttribute(attribute); - + encoder.delAttribute("NAME"); - + attribute.setAttribute(FeatureTypeAttribute.name, "NEW_NAME"); - + encoder.setAttribute(attribute); - + // TODO encoder.getAttribute("NAME"); - + GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder("ELE"); - + encoder.setMetadataDimension("elevation", dim2); dim2.setPresentation(Presentation.DISCRETE_INTERVAL, BigDecimal.valueOf(10)); Element el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION); assertNotNull(el); - + LOGGER.info("contains_key:" + el.toString()); dim2.setPresentation(Presentation.DISCRETE_INTERVAL, BigDecimal.valueOf(12)); @@ -221,7 +194,7 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { assertEquals("12", el.getText()); dim2.setPresentation(Presentation.CONTINUOUS_INTERVAL); - + encoder.setMetadataDimension("time", new GSFeatureDimensionInfoEncoder("time")); el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION); assertNotNull(el); @@ -240,11 +213,11 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { assertNull(el); if (el == null) LOGGER.info("REMOVED"); - + if (LOGGER.isInfoEnabled()) LOGGER.info(encoder.toString()); - assertEquals(encoder.getName(),"Layername"); + assertEquals(encoder.getName(), "Layername"); } @Test @@ -258,14 +231,16 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { assertTrue(encoder.delKeyword("KEYWORD_2")); assertFalse(encoder.delKeyword("KEYWORD_M")); - //metadataLinkInfo - encoder.addMetadataLinkInfo("text/xml", "ISO19115:2003","http://www.organization.org/metadata1"); - encoder.addMetadataLinkInfo("text/html", "ISO19115:2003","http://www.organization.org/metadata2"); - + // metadataLinkInfo + encoder.addMetadataLinkInfo("text/xml", "ISO19115:2003", + "http://www.organization.org/metadata1"); + encoder.addMetadataLinkInfo("text/html", "ISO19115:2003", + "http://www.organization.org/metadata2"); + assertTrue(encoder.delMetadataLinkInfo("http://www.organization.org/metadata2")); assertFalse(encoder.delMetadataLinkInfo("http://www.organization.org/metadata3")); - - //dimensions + + // dimensions final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder( "elevation_field"); @@ -275,8 +250,7 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { final String metadata = "elevation"; encoder.setMetadataDimension(metadata, elevationDimension); - elevationDimension.setPresentation(Presentation.DISCRETE_INTERVAL, - BigDecimal.valueOf(10)); + elevationDimension.setPresentation(Presentation.DISCRETE_INTERVAL, BigDecimal.valueOf(10)); if (LOGGER.isInfoEnabled()) LOGGER.info(encoder.toString()); @@ -293,28 +267,25 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { LOGGER.info("REMOVED"); } - + /** * Test method for virtual table encoding / SQL view layer integration * - * Settings information for integration tests - * - test is based on the data used in http://docs.geoserver.org/latest/en/user/data/database/sqlview.html#parameterizing-sql-views - * (states shapefile - available in testdata/states.zip) - * - create a postgis db - * - import the states shapefile (using shp2pgsql or Postgis shapefile uploader) - * - In Geoserver, create a postgis datastore for this DB, with the name "statesdb" + * Settings information for integration tests - test is based on the data used in + * http://docs.geoserver.org/latest/en/user/data/database/sqlview.html#parameterizing-sql-views (states shapefile - available in + * testdata/states.zip) - create a postgis db - import the states shapefile (using shp2pgsql or Postgis shapefile uploader) - In Geoserver, create + * a postgis datastore for this DB, with the name "statesdb" * */ @Test - public void testSQLViewIntegration(){ - - if (!enabled()) + public void testSQLViewIntegration() { + + if (!enabled()) return; deleteAll(); GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW); - - - String storeName = "statesdb"; //name of the datastore setup for tests + + String storeName = "statesdb"; // name of the datastore setup for tests String layerName = "my_sqlviewlayer"; String nativeName = "popstates"; @@ -322,51 +293,51 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest { fte.setName(layerName); fte.setNativeName(nativeName); fte.setTitle("title"); - + fte.addKeyword("keyword1"); fte.addKeyword("keyword2"); fte.setNativeCRS("EPSG:4326"); fte.setDescription("desc"); fte.setEnabled(true); - //virtual table - //------------- + // virtual table + // ------------- // Set-up the vtGeom final VTGeometryEncoder vtGeom = new VTGeometryEncoder("the_geom", "Point", "4326"); - + // Set-up 2 virtual table parameters final VTParameterEncoder vtParam1 = new VTParameterEncoder("high", "100000000", "^[\\d]+$"); final VTParameterEncoder vtParam2 = new VTParameterEncoder("low", "0", "^[\\d]+$"); - + // sql String sql = "select gid, state_name, the_geom from pgstates where persons between %low% and %high% and state_abbr = '%state%'"; - - //set-up the virtual table + + // set-up the virtual table final GSVirtualTableEncoder vte = new GSVirtualTableEncoder(); vte.setName(nativeName); vte.setSql(sql); vte.addVirtualTableGeometry(vtGeom); vte.addVirtualTableParameter(vtParam1); vte.addVirtualTableParameter(vtParam2); - fte.setMetadataVirtualTable(vte); //Set the virtual table - - //modif the vte + fte.setMetadataVirtualTable(vte); // Set the virtual table + + // modif the vte vte.delVirtualTableGeometry("the_geom"); vte.addVirtualTableGeometry("the_geom", "MultiPolygon", "4326"); - + final VTParameterEncoder vtParam3 = new VTParameterEncoder("state", "FL", "^[\\w\\d\\s]+$"); vte.addVirtualTableParameter(vtParam3); vte.addKeyColumn("gid"); - - //Layer encoder - //------------- + + // Layer encoder + // ------------- GSLayerEncoder layerEncoder = new GSLayerEncoder(); layerEncoder.setEnabled(true); layerEncoder.setQueryable(true); layerEncoder.setDefaultStyle("polygon"); // test insert - //------------ + // ------------ publisher.createWorkspace(DEFAULT_WS); boolean published = publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder); assertTrue("Publication unsuccessful", published); diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java index 491cfff..45a2baa 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java @@ -29,9 +29,11 @@ package it.geosolutions.geoserver.rest.publisher; import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.ParameterConfigure; import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore; +import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder; import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; import it.geosolutions.geoserver.rest.encoder.coverage.GSImageMosaicEncoder; +import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation; @@ -42,6 +44,7 @@ import java.io.IOException; import org.apache.commons.httpclient.NameValuePair; import org.junit.Test; import static org.junit.Assert.*; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -105,13 +108,26 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest { coverageEncoder.setSRS("EPSG:4326"); coverageEncoder.setSUGGESTED_TILE_SIZE("256,256"); coverageEncoder.setUSE_JAI_IMAGEREAD(true); - // activate time - final GSDimensionInfoEncoder time=new GSDimensionInfoEncoder(true); - time.setPresentation(Presentation.LIST); - // set time metadata - coverageEncoder.setMetadata("time", time); - // not active elevation - coverageEncoder.setMetadata("elevation", new GSDimensionInfoEncoder()); + + GSVersionDecoder v=reader.getGeoserverVersion(); + if (v.getVersion().equals(GSVersionDecoder.VERSION.getVersion(GSVersionDecoder.VERSION.v24.toString()))){ + // New style dimensions (since gs-2.4.x) + GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder( + "GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", + "dobson units³", "REAL_32BITS"); + coverageEncoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder); + } else { + // Old stile setting code + // activate time + final GSDimensionInfoEncoder time=new GSDimensionInfoEncoder(true); + time.setPresentation(Presentation.LIST); + // set time metadata + coverageEncoder.setMetadata("time", time); + // not active elevation + coverageEncoder.setMetadata("elevation", new GSDimensionInfoEncoder()); + } + + assertTrue(publisher.createWorkspace(wsName)); diff --git a/src/test/resources/testdata/coverageExample.xml b/src/test/resources/testdata/coverageExample.xml index ca83250..5a24090 100644 --- a/src/test/resources/testdata/coverageExample.xml +++ b/src/test/resources/testdata/coverageExample.xml @@ -1,4 +1,3 @@ - granuleTestMosaic granuleTestMosaic @@ -27,15 +26,18 @@ GEOGCS["WGS 84", - DATUM["World Geodetic System 1984", - SPHEROID["WGS 84", 6378137.0, 298.257223563, + 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], + AXIS["Geodetic + latitude", NORTH], AUTHORITY["EPSG","4326"]] EPSG:4326