Added publish db improvemets to solve issue #13

This commit is contained in:
ccancellieri 2011-11-14 16:46:06 +01:00
parent 10c6fcbb1f
commit ffa19fefba
2 changed files with 67 additions and 13 deletions

11
pom.xml
View File

@ -62,6 +62,17 @@
</roles> </roles>
<timezone>+1</timezone> <timezone>+1</timezone>
</developer> </developer>
<developer>
<id>ccancellieri</id>
<name>Carlo Cancellieri</name>
<email>carlo.cancellieri AT geosolutions.it</email>
<organization>GeoSolutions</organization>
<organizationUrl>http://www.geo-solutions.it</organizationUrl>
<roles>
<role>developer</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers> </developers>
<licenses> <licenses>

View File

@ -340,6 +340,30 @@ public class GeoServerRESTPublisher {
} }
/** /**
* @deprecated use {@link publishDBLayer(final String workspace, final
* String storename, final GSFeatureTypeEncoder fte, final
* GSLayerEncoder layerEncoder)}
* @param workspace
* @param storename
* @param layername
* @param srs
* @param defaultStyle
* @return
*/
public boolean publishDBLayer(String workspace, String storename,
String layername, String srs, String defaultStyle) {
final GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
fte.addName(layername);
fte.addSRS(srs); // srs=null?"EPSG:4326":srs);
final GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.addDefaultStyle(defaultStyle);
return publishDBLayer(workspace, storename, fte, layerEncoder);
}
/**
*
* Publish a table in a PostGis store as a new layer. * Publish a table in a PostGis store as a new layer.
* *
* <P> * <P>
@ -353,20 +377,31 @@ public class GeoServerRESTPublisher {
* </PRE> * </PRE>
* *
* and a PUT to <BR> * and a PUT to <BR>
* restURL + "/rest/layers/" + layerName * restURL + "/rest/layers/" workspace + : + layerName
*
* @param workspace
* @param storename
* @param fte
* GSFeatureTypeEncoder encoding creating FeatureType
* @return true if layer is successfully created
*
* *
*/ */
public boolean publishDBLayer(String workspace, String storename, public boolean publishDBLayer(final String workspace,
String layername, String srs, String defaultStyle) { final String storename, final GSFeatureTypeEncoder fte,
final GSLayerEncoder layerEncoder) {
String ftypeXml = fte.toString();
StringBuilder postUrl = new StringBuilder(restURL) StringBuilder postUrl = new StringBuilder(restURL)
.append("/rest/workspaces/").append(workspace) .append("/rest/workspaces/").append(workspace)
.append("/datastores/").append(storename) .append("/datastores/").append(storename)
.append("/featuretypes"); .append("/featuretypes");
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder(); final String layername = fte.getName();
fte.addName(layername); if (layername == null || layername.isEmpty()) {
fte.addSRS(srs); // srs=null?"EPSG:4326":srs); if (LOGGER.isEnabledFor(Level.ERROR))
String ftypeXml = fte.toString(); LOGGER.error("GSFeatureTypeEncoder has no valid name associated, try using GSFeatureTypeEncoder.setName(String)");
return false;
}
String configuredResult = HTTPUtils.postXml(postUrl.toString(), String configuredResult = HTTPUtils.postXml(postUrl.toString(),
ftypeXml, this.gsuser, this.gspass); ftypeXml, this.gsuser, this.gspass);
@ -379,8 +414,12 @@ public class GeoServerRESTPublisher {
} else { } else {
LOGGER.info("DB layer successfully added (layer:" + layername + ")"); LOGGER.info("DB layer successfully added (layer:" + layername + ")");
GSLayerEncoder layerEncoder = new GSLayerEncoder(); if (layerEncoder == null) {
layerEncoder.addDefaultStyle(defaultStyle); if (LOGGER.isEnabledFor(Level.ERROR))
LOGGER.error("GSLayerEncoder is null: Unable to find the defauldStyle for this layer");
return false;
}
configured = configureLayer(workspace, layername, layerEncoder); configured = configureLayer(workspace, layername, layerEncoder);
if (!configured) { if (!configured) {
@ -407,6 +446,10 @@ public class GeoServerRESTPublisher {
public static enum ParameterConfigure { public static enum ParameterConfigure {
FIRST, NONE, ALL; FIRST, NONE, ALL;
/**
* Overrides the default toString method printing a toLowerCase
* representation of this Parameter which is suitable to build parameter in the rest URL
*/
@Override @Override
public String toString() { public String toString() {
return this.name().toLowerCase(); return this.name().toLowerCase();
@ -612,10 +655,10 @@ public class GeoServerRESTPublisher {
public RESTCoverageStore publishExternalMosaic(String workspace, public RESTCoverageStore publishExternalMosaic(String workspace,
String storeName, File mosaicDir, String srs, String defaultStyle) String storeName, File mosaicDir, String srs, String defaultStyle)
throws FileNotFoundException { throws FileNotFoundException {
GSCoverageEncoder coverageEncoder = new GSCoverageEncoder(); final GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
coverageEncoder.addSRS(srs); coverageEncoder.addSRS(srs);
coverageEncoder.addName(FilenameUtils.getBaseName(mosaicDir.getName())); coverageEncoder.addName(FilenameUtils.getBaseName(mosaicDir.getName()));
GSLayerEncoder layerEncoder = new GSLayerEncoder(); final GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.addDefaultStyle(defaultStyle); layerEncoder.addDefaultStyle(defaultStyle);
return publishExternalMosaic(workspace, storeName, mosaicDir, return publishExternalMosaic(workspace, storeName, mosaicDir,
@ -1271,7 +1314,6 @@ public class GeoServerRESTPublisher {
/** /**
* Create a new coverage in a given workspace and coverage store * Create a new coverage in a given workspace and coverage store
* *
* @deprecated to be tested
* @param ce * @param ce
* contains the coverage name to create and the configuration to * contains the coverage name to create and the configuration to
* apply * apply
@ -1325,7 +1367,8 @@ public class GeoServerRESTPublisher {
* coverage name (if != null will override the CoverageEncoder * coverage name (if != null will override the CoverageEncoder
* name) * name)
* @return true if success * @return true if success
* @deprecated * @deprecated use {@link configureCoverage(final GSCoverageEncoder ce,
final String wsname, final String csname)}
*/ */
protected boolean configureCoverage(final GSCoverageEncoder ce, protected boolean configureCoverage(final GSCoverageEncoder ce,
final String wsname, final String csname, String cname) { final String wsname, final String csname, String cname) {