parent
a899315650
commit
31d4aae4a4
@ -29,6 +29,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
|||||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||||
|
|
||||||
@ -392,6 +393,7 @@ public class GeoServerRESTPublisher {
|
|||||||
GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
|
GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
|
||||||
coverageEncoder.addName(FilenameUtils.getBaseName(geotiff.getName()));
|
coverageEncoder.addName(FilenameUtils.getBaseName(geotiff.getName()));
|
||||||
coverageEncoder.addSRS(srs);
|
coverageEncoder.addSRS(srs);
|
||||||
|
coverageEncoder.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
|
||||||
configureCoverage(coverageEncoder, workspace, storeName, coverageName);
|
configureCoverage(coverageEncoder, workspace, storeName, coverageName);
|
||||||
|
|
||||||
// config layer props (style, ...)
|
// config layer props (style, ...)
|
||||||
|
|||||||
@ -27,6 +27,7 @@ package it.geosolutions.geoserver.rest.encoder;
|
|||||||
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureDimensionInfoEncoder;
|
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureDimensionInfoEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder;
|
import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||||
@ -35,9 +36,8 @@ import org.jdom.Element;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Encode a GeoServer resouce.
|
* Encode a GeoServer resouce. The <T> type regards the GDSDimensionInfoEncoder
|
||||||
* The <T> type regards the GDSDimensionInfoEncoder metadata Type which has
|
* metadata Type which has different specialization for Features.
|
||||||
* different specialization for Features.
|
|
||||||
*
|
*
|
||||||
* @see GSDimensionInfoEncoder
|
* @see GSDimensionInfoEncoder
|
||||||
* @see GSFeatureDimensionInfoEncoder
|
* @see GSFeatureDimensionInfoEncoder
|
||||||
@ -45,10 +45,12 @@ import org.jdom.Element;
|
|||||||
* @author ETj (etj at geo-solutions.it)
|
* @author ETj (etj at geo-solutions.it)
|
||||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
*/
|
*/
|
||||||
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extends PropertyXMLEncoder {
|
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
||||||
|
extends PropertyXMLEncoder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rootName Actually 'feature' or 'coverage'
|
* @param rootName
|
||||||
|
* Actually 'feature' or 'coverage'
|
||||||
* @see GSFeatureTypeEncoder
|
* @see GSFeatureTypeEncoder
|
||||||
* @see GSCoverageEncoder
|
* @see GSCoverageEncoder
|
||||||
*/
|
*/
|
||||||
@ -82,47 +84,146 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extend
|
|||||||
REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE
|
REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final static String PROJECTIONPOLICY="projectionPolicy";
|
||||||
|
/**
|
||||||
|
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||||
|
*
|
||||||
|
* @deprecated use the setProjectionPolicy. <br>
|
||||||
|
* This method will be set as private in the next release
|
||||||
|
*/
|
||||||
|
public void addProjectionPolicy(ProjectionPolicy policy) {
|
||||||
|
add(PROJECTIONPOLICY, policy.toString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||||
*/
|
*/
|
||||||
public void addProjectionPolicy(ProjectionPolicy policy) {
|
public void setProjectionPolicy(ProjectionPolicy policy) {
|
||||||
add("projectionPolicy", policy.toString());
|
set(PROJECTIONPOLICY, policy.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String NAME="name";
|
||||||
|
/**
|
||||||
|
* Add the 'name' node with a text value from 'name'
|
||||||
|
*
|
||||||
|
* @note REQUIRED to configure a resource
|
||||||
|
* @deprecated use the setName. <br>
|
||||||
|
* This method will be set as private in the next release
|
||||||
|
*/
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String TITLE="title";
|
||||||
|
/**
|
||||||
|
* Add the 'title' node with a text value from 'title'
|
||||||
|
*
|
||||||
|
* @deprecated use the setTitle. <br>
|
||||||
|
* This method will be set as private in the next release
|
||||||
|
*/
|
||||||
|
public void addTitle(final String title) {
|
||||||
|
add(TITLE, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the 'name' node with a text value from 'name'
|
* Set or modify the 'title' node with a text value from 'title'
|
||||||
* @note REQUIRED to configure a resource
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public void addName(final String name) {
|
public void setTitle(final String title) {
|
||||||
add("name", name);
|
set(TITLE, title);
|
||||||
}
|
|
||||||
|
|
||||||
public void addTitle(final String title) {
|
|
||||||
add("title", title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final static String SRS="srs";
|
||||||
|
/**
|
||||||
|
* Add the 'SRS' node with a text value from 'srs'
|
||||||
|
*
|
||||||
|
* @deprecated use the setSRS. <br>
|
||||||
|
* This method will be set as private in the next release
|
||||||
|
*/
|
||||||
public void addSRS(final String srs) {
|
public void addSRS(final String srs) {
|
||||||
add("srs", 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 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";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the setSRS. <br>
|
||||||
|
* This method will be set as private in the next release
|
||||||
|
*
|
||||||
|
* @param minx
|
||||||
|
* @param maxy
|
||||||
|
* @param maxx
|
||||||
|
* @param miny
|
||||||
|
* @param crs
|
||||||
|
*/
|
||||||
public void addLatLonBoundingBox(double minx, double maxy, double maxx,
|
public void addLatLonBoundingBox(double minx, double maxy, double maxx,
|
||||||
double miny, final String crs) {
|
double miny, final String crs) {
|
||||||
add("latLonBoundingBox/minx", String.valueOf(minx));
|
add(LATLONBBMINX, String.valueOf(minx));
|
||||||
add("latLonBoundingBox/maxy", String.valueOf(maxy));
|
add(LATLONBBMAXY, String.valueOf(maxy));
|
||||||
add("latLonBoundingBox/maxx", String.valueOf(maxx));
|
add(LATLONBBMAXX, String.valueOf(maxx));
|
||||||
add("latLonBoundingBox/miny", String.valueOf(miny));
|
add(LATLONBBMINY, String.valueOf(miny));
|
||||||
add("latLonBoundingBox/crs", crs);
|
add(LATLONBBCRS, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLatLonBoundingBox(double minx, double maxy, double maxx,
|
||||||
|
double miny, 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";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the setSRS. <br>
|
||||||
|
* This method will be set as private in the next release
|
||||||
|
*
|
||||||
|
* @param minx
|
||||||
|
* @param maxy
|
||||||
|
* @param maxx
|
||||||
|
* @param miny
|
||||||
|
* @param crs
|
||||||
|
*/
|
||||||
public void addNativeBoundingBox(double minx, double maxy, double maxx,
|
public void addNativeBoundingBox(double minx, double maxy, double maxx,
|
||||||
double miny, final String crs) {
|
double miny, final String crs) {
|
||||||
add("nativeBoundingBox/minx", String.valueOf(minx));
|
add(NATIVEBBMINX, String.valueOf(minx));
|
||||||
add("nativeBoundingBox/maxy", String.valueOf(maxy));
|
add(NATIVEBBMAXY, String.valueOf(maxy));
|
||||||
add("nativeBoundingBox/maxx", String.valueOf(maxx));
|
add(NATIVEBBMAXX, String.valueOf(maxx));
|
||||||
add("nativeBoundingBox/miny", String.valueOf(miny));
|
add(NATIVEBBMINY, String.valueOf(miny));
|
||||||
add("nativeBoundingBox/crs", crs);
|
add(NATIVEBBCRS, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNativeBoundingBox(double minx, double maxy, double maxx,
|
||||||
|
double miny, 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,12 +57,24 @@ public class PropertyXMLEncoder extends XmlElement {
|
|||||||
super(rootName);
|
super(rootName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void add(String key, String value) {
|
protected void add(final String key, final String value) {
|
||||||
if (key != null && value != null) {
|
if (key != null && value != null) {
|
||||||
add(this.getRoot(), key, value);
|
add(this.getRoot(), key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void set(final String key, final String value) {
|
||||||
|
if (key != null && value != null) {
|
||||||
|
Element pp = null;
|
||||||
|
if ((pp = contains(key)) == null)
|
||||||
|
add(key, value);
|
||||||
|
else {
|
||||||
|
remove(pp);
|
||||||
|
add(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void add(Element e, String key, String value) {
|
private void add(Element e, String key, String value) {
|
||||||
if (!key.contains("/")) {
|
if (!key.contains("/")) {
|
||||||
e.addContent(new Element(key).setText(value));
|
e.addContent(new Element(key).setText(value));
|
||||||
|
|||||||
@ -79,7 +79,5 @@ public class GSCoverageEncoderTest extends TestCase {
|
|||||||
Assert.assertNull(el4);
|
Assert.assertNull(el4);
|
||||||
if (el4==null)
|
if (el4==null)
|
||||||
LOGGER.info("REMOVED");
|
LOGGER.info("REMOVED");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
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.metadata.GSDimensionInfoEncoder;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class GSResourceEncoderTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test set or reset of reprojection
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testReprojection(){
|
||||||
|
GSResourceEncoder<GSDimensionInfoEncoder> re=new GSCoverageEncoder();
|
||||||
|
|
||||||
|
re.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
|
||||||
|
Assert.assertNotNull(re.contains("projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString()));
|
||||||
|
|
||||||
|
re.setProjectionPolicy(ProjectionPolicy.NONE);
|
||||||
|
Assert.assertNull(re.contains("projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString()));
|
||||||
|
Assert.assertNotNull(re.contains("projectionPolicy",ProjectionPolicy.NONE.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user