Enum fields to UPPERCASE. Closes #24

This commit is contained in:
Oscar Fonts 2012-06-26 09:24:06 +02:00
parent 49543f609b
commit 68e8056a1b
6 changed files with 49 additions and 49 deletions

View File

@ -546,7 +546,7 @@ public class GeoServerRESTPublisher {
UploadMethod method, DataStoreExtension extension, String mimeType, UploadMethod method, DataStoreExtension extension, String mimeType,
URI uri, ParameterConfigure configure, NameValuePair... params) URI uri, ParameterConfigure configure, NameValuePair... params)
throws FileNotFoundException, IllegalArgumentException { throws FileNotFoundException, IllegalArgumentException {
return createStore(workspace, DataStoreType.datastores, storeName, return createStore(workspace, DataStoreType.DATASTORES, storeName,
method, extension, mimeType, uri, configure, params); method, extension, mimeType, uri, configure, params);
} }
@ -555,7 +555,7 @@ public class GeoServerRESTPublisher {
String mimeType, URI uri, ParameterConfigure configure, String mimeType, URI uri, ParameterConfigure configure,
NameValuePair... params) throws FileNotFoundException, NameValuePair... params) throws FileNotFoundException,
IllegalArgumentException { IllegalArgumentException {
return createStore(workspace, DataStoreType.coveragestores, storeName, return createStore(workspace, DataStoreType.COVERAGESTORES, storeName,
method, extension, mimeType, uri, configure, params); method, extension, mimeType, uri, configure, params);
} }
@ -601,17 +601,17 @@ public class GeoServerRESTPublisher {
String sentResult = null; String sentResult = null;
if (method.equals(UploadMethod.file)) { if (method.equals(UploadMethod.FILE)) {
final File file = new File(uri); final File file = new File(uri);
if (!file.exists()) if (!file.exists())
throw new FileNotFoundException("unable to locate file: " throw new FileNotFoundException("unable to locate file: "
+ file); + file);
sentResult = HTTPUtils.put(sbUrl.toString(), file, mimeType, sentResult = HTTPUtils.put(sbUrl.toString(), file, mimeType,
gsuser, gspass); gsuser, gspass);
} else if (method.equals(UploadMethod.external)) { } else if (method.equals(UploadMethod.EXTERNAL)) {
sentResult = HTTPUtils.put(sbUrl.toString(), uri.toString(), sentResult = HTTPUtils.put(sbUrl.toString(), uri.toString(),
mimeType, gsuser, gspass); mimeType, gsuser, gspass);
} else if (method.equals(UploadMethod.url)) { } else if (method.equals(UploadMethod.URL)) {
// TODO check // TODO check
sentResult = HTTPUtils.put(sbUrl.toString(), uri.toString(), sentResult = HTTPUtils.put(sbUrl.toString(), uri.toString(),
mimeType, gsuser, gspass); mimeType, gsuser, gspass);
@ -640,13 +640,13 @@ public class GeoServerRESTPublisher {
* *
*/ */
public enum DataStoreType { public enum DataStoreType {
coveragestores, datastores; COVERAGESTORES, DATASTORES;
public static String getTypeName(DataStoreType type) { public static String getTypeName(DataStoreType type) {
switch (type) { switch (type) {
case coveragestores: case COVERAGESTORES:
return "coverages.xml"; // Format return "coverages.xml"; // Format
case datastores: case DATASTORES:
return "featuretypes.xml"; return "featuretypes.xml";
default: default:
return "coverages.xml"; return "coverages.xml";
@ -673,7 +673,7 @@ public class GeoServerRESTPublisher {
* *
*/ */
public enum UploadMethod { public enum UploadMethod {
file, url, external FILE, URL, EXTERNAL
} }
// ========================================================================== // ==========================================================================
@ -724,7 +724,7 @@ public class GeoServerRESTPublisher {
*/ */
public boolean publishShp(String workspace, String storename, public boolean publishShp(String workspace, String storename,
String datasetname, File zipFile) throws FileNotFoundException, IllegalArgumentException { String datasetname, File zipFile) throws FileNotFoundException, IllegalArgumentException {
return publishShp(workspace, storename, new NameValuePair[0], datasetname,UploadMethod.file, zipFile.toURI(), "EPSG:4326", ProjectionPolicy.NONE,null); return publishShp(workspace, storename, new NameValuePair[0], datasetname,UploadMethod.FILE, zipFile.toURI(), "EPSG:4326", ProjectionPolicy.NONE,null);
} }
/** /**
@ -774,11 +774,11 @@ public class GeoServerRESTPublisher {
// //
final String mimeType; final String mimeType;
switch (method){ switch (method){
case external: case EXTERNAL:
mimeType="text/plain"; mimeType="text/plain";
break; break;
case url: // TODO check which mime-type should be used case URL: // TODO check which mime-type should be used
case file: case FILE:
mimeType="application/zip"; mimeType="application/zip";
break; break;
default: default:
@ -786,7 +786,7 @@ public class GeoServerRESTPublisher {
} }
if (!createDataStore(workspace, if (!createDataStore(workspace,
(storeName != null) ? storeName : FilenameUtils.getBaseName(shapefile.toString()), (storeName != null) ? storeName : FilenameUtils.getBaseName(shapefile.toString()),
method, DataStoreExtension.shp, mimeType, method, DataStoreExtension.SHP, mimeType,
shapefile, ParameterConfigure.NONE, storeParams)) { shapefile, ParameterConfigure.NONE, storeParams)) {
LOGGER.error("Unable to create data store for shapefile: " LOGGER.error("Unable to create data store for shapefile: "
+ shapefile); + shapefile);
@ -799,7 +799,7 @@ public class GeoServerRESTPublisher {
featureTypeEncoder.setSRS(srs); featureTypeEncoder.setSRS(srs);
featureTypeEncoder.setProjectionPolicy(policy); featureTypeEncoder.setProjectionPolicy(policy);
if (!createResource(workspace, DataStoreType.datastores, storeName, if (!createResource(workspace, DataStoreType.DATASTORES, storeName,
featureTypeEncoder)) { featureTypeEncoder)) {
LOGGER.error("Unable to create a coverage store for coverage: " LOGGER.error("Unable to create a coverage store for coverage: "
+ shapefile); + shapefile);
@ -832,7 +832,7 @@ public class GeoServerRESTPublisher {
String layerName, File zipFile, String nativeCrs, String layerName, File zipFile, String nativeCrs,
String defaultStyle) throws FileNotFoundException, IllegalArgumentException { String defaultStyle) throws FileNotFoundException, IllegalArgumentException {
return publishShp(workspace, storename, (NameValuePair[])null, layerName, UploadMethod.file, zipFile.toURI(), nativeCrs, ProjectionPolicy.NONE,defaultStyle); return publishShp(workspace, storename, (NameValuePair[])null, layerName, UploadMethod.FILE, zipFile.toURI(), nativeCrs, ProjectionPolicy.NONE,defaultStyle);
} }
/** /**
@ -860,7 +860,7 @@ public class GeoServerRESTPublisher {
public boolean publishShp(String workspace, String storename, public boolean publishShp(String workspace, String storename,
String layername, File zipFile, String srs) String layername, File zipFile, String srs)
throws FileNotFoundException { throws FileNotFoundException {
return publishShp(workspace, storename, (NameValuePair[])null, layername, UploadMethod.file, zipFile.toURI(), srs, ProjectionPolicy.NONE,null); return publishShp(workspace, storename, (NameValuePair[])null, layername, UploadMethod.FILE, zipFile.toURI(), srs, ProjectionPolicy.NONE,null);
} }
/** /**
@ -896,7 +896,7 @@ public class GeoServerRESTPublisher {
String layername, File zipFile, String srs, NameValuePair... params) String layername, File zipFile, String srs, NameValuePair... params)
throws FileNotFoundException, IllegalArgumentException { throws FileNotFoundException, IllegalArgumentException {
return publishShp(workspace, storename, params, layername, UploadMethod.file, zipFile.toURI(), srs, ProjectionPolicy.NONE,null); return publishShp(workspace, storename, params, layername, UploadMethod.FILE, zipFile.toURI(), srs, ProjectionPolicy.NONE,null);
} }
@ -923,16 +923,16 @@ public class GeoServerRESTPublisher {
if (resource.getScheme().equals("file") || resource.isAbsolute() == false) { if (resource.getScheme().equals("file") || resource.isAbsolute() == false) {
File f = new File(resource); File f = new File(resource);
if (f.exists() && f.isFile() && f.toString().endsWith(".zip")) { if (f.exists() && f.isFile() && f.toString().endsWith(".zip")) {
method = UploadMethod.file; method = UploadMethod.FILE;
mime = "application/zip"; mime = "application/zip";
} else if (f.isDirectory()) { } else if (f.isDirectory()) {
method = UploadMethod.external; method = UploadMethod.EXTERNAL;
mime = "text/plain"; mime = "text/plain";
} }
} else { } else {
try { try {
if(resource.toURL() != null) { if(resource.toURL() != null) {
method = UploadMethod.url; method = UploadMethod.URL;
mime = "text/plain"; mime = "text/plain";
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
@ -942,9 +942,9 @@ public class GeoServerRESTPublisher {
// Create store, upload data, and publish layers // Create store, upload data, and publish layers
return createStore( return createStore(
workspace, DataStoreType.datastores, workspace, DataStoreType.DATASTORES,
storeName, method, storeName, method,
DataStoreExtension.shp, DataStoreExtension.SHP,
mime, resource, mime, resource,
ParameterConfigure.ALL, ParameterConfigure.ALL,
new NameValuePair[0]); new NameValuePair[0]);
@ -1132,7 +1132,7 @@ public class GeoServerRESTPublisher {
CoverageStoreExtension extension, String mimeType, File file, CoverageStoreExtension extension, String mimeType, File file,
ParameterConfigure configure, NameValuePair... params) ParameterConfigure configure, NameValuePair... params)
throws FileNotFoundException { throws FileNotFoundException {
return createCoverageStore(workspace, coveragestore, UploadMethod.file, return createCoverageStore(workspace, coveragestore, UploadMethod.FILE,
extension, mimeType, file.toURI(), configure, params); extension, mimeType, file.toURI(), configure, params);
} }
@ -1194,7 +1194,7 @@ public class GeoServerRESTPublisher {
* *
*/ */
public enum CoverageStoreExtension { public enum CoverageStoreExtension {
geotiff, imagemosaic, worldimage GEOTIFF, IMAGEMOSAIC, WORLDIMAGE
} }
/** /**
@ -1212,7 +1212,7 @@ public class GeoServerRESTPublisher {
* *
*/ */
public enum DataStoreExtension { public enum DataStoreExtension {
shp, properties, h2, spatialite SHP, PROPERTIES, H2, SPATIALITE
} }
/** /**
@ -1255,7 +1255,7 @@ public class GeoServerRESTPublisher {
ParameterUpdate update) throws FileNotFoundException, ParameterUpdate update) throws FileNotFoundException,
IllegalArgumentException { IllegalArgumentException {
return createCoverageStore(workspace, coveragestore, return createCoverageStore(workspace, coveragestore,
UploadMethod.external, extension, mimeType, file.toURI(), UploadMethod.EXTERNAL, extension, mimeType, file.toURI(),
configure, configure,
(update != null) ? new NameValuePair[] { new NameValuePair( (update != null) ? new NameValuePair[] { new NameValuePair(
"update", update.toString()) } : (NameValuePair[]) null); "update", update.toString()) } : (NameValuePair[]) null);
@ -1271,7 +1271,7 @@ public class GeoServerRESTPublisher {
public boolean publishGeoTIFF(String workspace, String storeName, public boolean publishGeoTIFF(String workspace, String storeName,
File geotiff) throws FileNotFoundException { File geotiff) throws FileNotFoundException {
return publishCoverage(workspace, storeName, return publishCoverage(workspace, storeName,
CoverageStoreExtension.geotiff, "image/geotiff", geotiff, CoverageStoreExtension.GEOTIFF, "image/geotiff", geotiff,
ParameterConfigure.FIRST, (NameValuePair[]) null); ParameterConfigure.FIRST, (NameValuePair[]) null);
} }
@ -1314,7 +1314,7 @@ public class GeoServerRESTPublisher {
workspace, workspace,
(storeName != null) ? storeName : FilenameUtils (storeName != null) ? storeName : FilenameUtils
.getBaseName(geotiff.getAbsolutePath()), .getBaseName(geotiff.getAbsolutePath()),
CoverageStoreExtension.geotiff, CoverageStoreExtension.GEOTIFF,
"image/geotiff", "image/geotiff",
geotiff, geotiff,
ParameterConfigure.FIRST, ParameterConfigure.FIRST,
@ -1361,7 +1361,7 @@ public class GeoServerRESTPublisher {
if (!createCoverageStore(workspace, (storeName != null) ? storeName if (!createCoverageStore(workspace, (storeName != null) ? storeName
: FilenameUtils.getBaseName(geotiff.getAbsolutePath()), : FilenameUtils.getBaseName(geotiff.getAbsolutePath()),
UploadMethod.file, CoverageStoreExtension.geotiff, UploadMethod.FILE, CoverageStoreExtension.GEOTIFF,
"image/geotiff", geotiff.toURI(), ParameterConfigure.NONE, "image/geotiff", geotiff.toURI(), ParameterConfigure.NONE,
(NameValuePair[]) null)) { (NameValuePair[]) null)) {
LOGGER.error("Unable to create coverage store for coverage: " LOGGER.error("Unable to create coverage store for coverage: "
@ -1466,7 +1466,7 @@ public class GeoServerRESTPublisher {
// create store // create store
final boolean store = publishExternalCoverage(workspace, storeName, final boolean store = publishExternalCoverage(workspace, storeName,
CoverageStoreExtension.geotiff, "text/plain", geotiff, CoverageStoreExtension.GEOTIFF, "text/plain", geotiff,
ParameterConfigure.NONE, ParameterUpdate.OVERWRITE); ParameterConfigure.NONE, ParameterUpdate.OVERWRITE);
if (!store) { if (!store) {
return null; return null;
@ -1546,7 +1546,7 @@ public class GeoServerRESTPublisher {
File zipFile, ParameterConfigure configure, NameValuePair... params) File zipFile, ParameterConfigure configure, NameValuePair... params)
throws FileNotFoundException { throws FileNotFoundException {
return publishCoverage(workspace, coveragestore, return publishCoverage(workspace, coveragestore,
CoverageStoreExtension.worldimage, "application/zip", zipFile, CoverageStoreExtension.WORLDIMAGE, "application/zip", zipFile,
configure, params); configure, params);
} }
@ -1562,7 +1562,7 @@ public class GeoServerRESTPublisher {
public boolean publishImageMosaic(String workspace, String storeName, public boolean publishImageMosaic(String workspace, String storeName,
File zipFile) throws FileNotFoundException { File zipFile) throws FileNotFoundException {
return publishCoverage(workspace, storeName, return publishCoverage(workspace, storeName,
CoverageStoreExtension.imagemosaic, "application/zip", zipFile, CoverageStoreExtension.IMAGEMOSAIC, "application/zip", zipFile,
ParameterConfigure.FIRST, (NameValuePair[]) null); ParameterConfigure.FIRST, (NameValuePair[]) null);
} }
@ -1575,7 +1575,7 @@ public class GeoServerRESTPublisher {
File zipFile, ParameterConfigure configure, NameValuePair... params) File zipFile, ParameterConfigure configure, NameValuePair... params)
throws FileNotFoundException { throws FileNotFoundException {
return publishCoverage(workspace, storeName, return publishCoverage(workspace, storeName,
CoverageStoreExtension.imagemosaic, "application/zip", zipFile, CoverageStoreExtension.IMAGEMOSAIC, "application/zip", zipFile,
configure, params); configure, params);
} }
@ -2332,7 +2332,7 @@ public class GeoServerRESTPublisher {
*/ */
public boolean createCoverage(final String wsname, final String storeName, public boolean createCoverage(final String wsname, final String storeName,
final GSCoverageEncoder ce) throws IllegalArgumentException { final GSCoverageEncoder ce) throws IllegalArgumentException {
return createResource(wsname, DataStoreType.coveragestores, storeName, return createResource(wsname, DataStoreType.COVERAGESTORES, storeName,
ce); ce);
} }

View File

@ -268,7 +268,7 @@ public class GeoServerRESTReader {
*/ */
public RESTFeatureType getFeatureType(RESTLayer layer) { public RESTFeatureType getFeatureType(RESTLayer layer) {
if(layer.getType() != RESTLayer.TYPE.VECTOR) if(layer.getType() != RESTLayer.Type.VECTOR)
throw new RuntimeException("Bad layer type for layer " + layer.getName()); throw new RuntimeException("Bad layer type for layer " + layer.getName());
String response = loadFullURL(layer.getResourceUrl()); String response = loadFullURL(layer.getResourceUrl());
@ -368,7 +368,7 @@ public class GeoServerRESTReader {
* @return Coverage details as a {@link RESTCoverage} * @return Coverage details as a {@link RESTCoverage}
*/ */
public RESTCoverage getCoverage(RESTLayer layer) { public RESTCoverage getCoverage(RESTLayer layer) {
if(layer.getType() != RESTLayer.TYPE.RASTER) if(layer.getType() != RESTLayer.Type.RASTER)
throw new RuntimeException("Bad layer type for layer " + layer.getName()); throw new RuntimeException("Bad layer type for layer " + layer.getName());
String response = loadFullURL(layer.getResourceUrl()); String response = loadFullURL(layer.getResourceUrl());

View File

@ -59,19 +59,19 @@ import org.jdom.Namespace;
public class RESTLayer { public class RESTLayer {
private final Element layerElem; private final Element layerElem;
public enum TYPE { public enum Type {
VECTOR("VECTOR"), VECTOR("VECTOR"),
RASTER("RASTER"), RASTER("RASTER"),
UNKNOWN(null); UNKNOWN(null);
private final String restName; private final String restName;
private TYPE(String restName) { private Type(String restName) {
this.restName = restName; this.restName = restName;
} }
public static TYPE get(String restName) { public static Type get(String restName) {
for (TYPE type : values()) { for (Type type : values()) {
if(type == UNKNOWN) if(type == UNKNOWN)
continue; continue;
if(type.restName.equals(restName)) if(type.restName.equals(restName))
@ -104,8 +104,8 @@ public class RESTLayer {
return layerElem.getChildText("type"); return layerElem.getChildText("type");
} }
public TYPE getType() { public Type getType() {
return TYPE.get(getTypeString()); return Type.get(getTypeString());
} }
public String getDefaultStyle() { public String getDefaultStyle() {

View File

@ -174,9 +174,9 @@ public abstract class GeoserverRESTTest extends TestCase {
List<String> layers = reader.getLayers().getNames(); List<String> layers = reader.getLayers().getNames();
for (String layerName : layers) { for (String layerName : layers) {
RESTLayer layer = reader.getLayer(layerName); RESTLayer layer = reader.getLayer(layerName);
if(layer.getType() == RESTLayer.TYPE.VECTOR) if(layer.getType() == RESTLayer.Type.VECTOR)
deleteFeatureType(layer); deleteFeatureType(layer);
else if(layer.getType() == RESTLayer.TYPE.RASTER) else if(layer.getType() == RESTLayer.Type.RASTER)
deleteCoverage(layer); deleteCoverage(layer);
else else
LOGGER.error("Unknown layer type " + layer.getType()); LOGGER.error("Unknown layer type " + layer.getType());

View File

@ -105,7 +105,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
File zipFile = new ClassPathResource("testdata/shapefile/cities.shp").getFile(); File zipFile = new ClassPathResource("testdata/shapefile/cities.shp").getFile();
// test insert // test insert
boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.external, zipFile.toURI(), "EPSG:4326",ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon"); boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.EXTERNAL, zipFile.toURI(), "EPSG:4326",ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon");
assertTrue("publish() failed", published); assertTrue("publish() failed", published);
assertTrue(existsLayer(datasetName)); assertTrue(existsLayer(datasetName));
@ -138,7 +138,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
// test insert // test insert
boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.file, zipFile.toURI(), "EPSG:4326",ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon"); boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.FILE, zipFile.toURI(), "EPSG:4326",ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon");
assertTrue("publish() failed", published); assertTrue("publish() failed", published);
assertTrue(existsLayer(datasetName)); assertTrue(existsLayer(datasetName));