if ("yes".equalsIgnoreCase(form.getFirstValue("overviews")) ) {
/* TODO: Add overviews here */;
}
//create a builder to help build catalog objects
CatalogBuilder builder = new CatalogBuilder(catalog);
builder.setWorkspace( catalog.getWorkspaceByName( workspace ) );
//create the coverage store
CoverageStoreInfo info = catalog.getCoverageStoreByName(workspace, coveragestore);
boolean add = false;
if ( info == null ) {
//create a new coverage store
LOGGER.info("Auto-configuring coverage store: " + coveragestore);
info = builder.buildCoverageStore(coveragestore);
add = true;
}
else {
//use the existing
LOGGER.info("Using existing coverage store: " + coveragestore);
}
info.setType(coverageFormat.getName());
if (!isExternal) {
info.setURL("file:data/" + coveragestore + "/" + uploadedFile.getName() );
}
else {
try {
info.setURL( uploadedFile.toURL().toExternalForm());
} catch (MalformedURLException e) {
throw new RestletException( "url error", Status.SERVER_ERROR_INTERNAL, e );
}
}
//add or update the datastore info
if ( add ) {
catalog.add( info );
}
else {
catalog.save( info );
}
builder.setStore(info);
//check configure parameter, if set to none to not try to configure coverage
String configure = form.getFirstValue( "configure" );
if ( "none".equalsIgnoreCase( configure ) ) {
getResponse().setStatus( Status.SUCCESS_CREATED );
return;
}
String coverage = uploadedFile.getName();
if ( coverage.indexOf( '.') != -1 ) {
coverage = coverage.substring( 0, coverage.indexOf( '.') );
}
try {
AbstractGridCoverage2DReader reader =
(AbstractGridCoverage2DReader) ((AbstractGridFormat) coverageFormat).getReader(uploadedFile.toURL());
if ( reader == null ) {
throw new RestletException( "Could not aquire reader for coverage.", Status.SERVER_ERROR_INTERNAL );
}
CoverageInfo cinfo = builder.buildCoverage( reader );
//check if the name of the coverage was specified
String coverageName = form.getFirstValue("coverageName");
if ( coverageName != null ) {
cinfo.setName( coverageName );
}
if ( !add ) {
//update the existing
CoverageInfo existing = catalog.getCoverageByCoverageStore(info,
coverageName != null ? coverageName : coverage );
if ( existing == null ) {
//grab the first if there is only one
List<CoverageInfo> coverages = catalog.getCoveragesByCoverageStore( info);
if ( coverages.size() == 1 ) {
existing = coverages.get(0);
}
if ( coverages.size() == 0 ) {
//no coverages yet configured, change add flag and continue on
add = true;
}
else {
// multiple coverages, and one to configure not specified
throw new RestletException( "Unable to determine coverage to configure.", Status.SERVER_ERROR_INTERNAL);
}
}
if ( existing != null ) {
builder.updateCoverage(existing,cinfo);
catalog.save( existing );
cinfo = existing;
}
}
//do some post configuration, if srs is not known or unset, transform to 4326
if ("UNKNOWN".equals(cinfo.getSRS())) {
//CoordinateReferenceSystem sourceCRS = cinfo.getBoundingBox().getCoordinateReferenceSystem();
//CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326", true);
//ReferencedEnvelope re = cinfo.getBoundingBox().transform(targetCRS, true);
cinfo.setSRS( "EPSG:4326" );
//cinfo.setCRS( targetCRS );
//cinfo.setBoundingBox( re );
}
//add/save
if ( add ) {
catalog.add( cinfo );
LayerInfo layerInfo = builder.buildLayer( cinfo );
//JD: commenting this out, these sorts of edits should be handled
// with a second PUT request on the created coverage
/*
String styleName = form.getFirstValue("style");
if ( styleName != null ) {