changes implementing fix to the defects #14 and #15

This commit is contained in:
ccancellieri 2011-09-13 22:58:46 +02:00
parent 05838a75df
commit 2d928874a0
5 changed files with 182 additions and 43 deletions

View File

@ -29,6 +29,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
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.feature.GSFeatureTypeEncoder;
@ -392,6 +393,7 @@ public class GeoServerRESTPublisher {
GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
coverageEncoder.addName(FilenameUtils.getBaseName(geotiff.getName()));
coverageEncoder.addSRS(srs);
coverageEncoder.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
configureCoverage(coverageEncoder, workspace, storeName, coverageName);
// config layer props (style, ...)

View File

@ -27,6 +27,7 @@ package it.geosolutions.geoserver.rest.encoder;
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
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.GSMetadataEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
@ -35,20 +36,21 @@ import org.jdom.Element;
/**
*
* Encode a GeoServer resouce.
* The <T> type regards the GDSDimensionInfoEncoder metadata Type which has
* different specialization for Features.
* Encode a GeoServer resouce. The <T> type regards the GDSDimensionInfoEncoder
* metadata Type which has different specialization for Features.
*
* @see GSDimensionInfoEncoder
* @see GSFeatureDimensionInfoEncoder
* @see GSDimensionInfoEncoder
* @see GSFeatureDimensionInfoEncoder
*
* @author ETj (etj at 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 GSCoverageEncoder
*/
@ -56,21 +58,21 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extend
super(rootName);
add("enabled", "true");
// Link members to the parent
// Link members to the parent
addContent(metadata.getRoot());
addContent(keywordsListEncoder);
}
final private GSMetadataEncoder<T> metadata=new GSMetadataEncoder<T>();
final private GSMetadataEncoder<T> metadata = new GSMetadataEncoder<T>();
public void addMetadata(String key, T dimensionInfo) {
metadata.add(key, dimensionInfo.getRoot());
}
final private Element keywordsListEncoder = new Element("keywords");
public void addKeyword(String keyword) {
final Element el=new Element("string");
final Element el = new Element("string");
el.setText(keyword);
keywordsListEncoder.addContent(el);
}
@ -82,47 +84,146 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extend
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
*/
public void addProjectionPolicy(ProjectionPolicy policy) {
add("projectionPolicy", policy.toString());
public void setProjectionPolicy(ProjectionPolicy policy) {
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'
* @note REQUIRED to configure a resource
*
* Set or modify the 'title' node with a text value from 'title'
*/
public void addName(final String name) {
add("name", name);
}
public void addTitle(final String title) {
add("title", title);
}
public void addSRS(final String srs) {
add("srs", srs);
public void setTitle(final String title) {
set(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) {
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,
double miny, final String crs) {
add("latLonBoundingBox/minx", String.valueOf(minx));
add("latLonBoundingBox/maxy", String.valueOf(maxy));
add("latLonBoundingBox/maxx", String.valueOf(maxx));
add("latLonBoundingBox/miny", String.valueOf(miny));
add("latLonBoundingBox/crs", crs);
add(LATLONBBMINX, String.valueOf(minx));
add(LATLONBBMAXY, String.valueOf(maxy));
add(LATLONBBMAXX, String.valueOf(maxx));
add(LATLONBBMINY, String.valueOf(miny));
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,
double miny, final String crs) {
add("nativeBoundingBox/minx", String.valueOf(minx));
add("nativeBoundingBox/maxy", String.valueOf(maxy));
add("nativeBoundingBox/maxx", String.valueOf(maxx));
add("nativeBoundingBox/miny", String.valueOf(miny));
add("nativeBoundingBox/crs", 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 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);
}
}

View File

@ -57,11 +57,23 @@ public class PropertyXMLEncoder extends XmlElement {
super(rootName);
}
protected void add(String key, String value) {
protected void add(final String key, final String value) {
if (key != null && value != null) {
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) {
if (!key.contains("/")) {

View File

@ -79,7 +79,5 @@ public class GSCoverageEncoderTest extends TestCase {
Assert.assertNull(el4);
if (el4==null)
LOGGER.info("REMOVED");
}
}

View File

@ -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()));
}
}