Index: main/src/main/java/org/geoserver/catalog/CatalogBuilder.java =================================================================== --- main/src/main/java/org/geoserver/catalog/CatalogBuilder.java (revision 16153) +++ main/src/main/java/org/geoserver/catalog/CatalogBuilder.java (working copy) @@ -531,18 +531,28 @@ } /** + * Initializes basic resource info. + */ + private void initResourceInfo(ResourceInfo resInfo) throws Exception { + // set the name + if (resInfo.getNativeName() == null && resInfo.getName() != null) { + resInfo.setNativeName(resInfo.getName()); + } + if (resInfo.getNativeName() != null && resInfo.getName() == null) { + resInfo.setName(resInfo.getNativeName()); + } + } + + /** * Initializes a feature type object setting any info that has not been set. */ public void initFeatureType(FeatureTypeInfo featureType) throws Exception { if (featureType.getCatalog() == null) { featureType.setCatalog(catalog); } - if (featureType.getNativeName() == null && featureType.getName() != null) { - featureType.setNativeName(featureType.getName()); - } - if (featureType.getNativeName() != null && featureType.getName() == null) { - featureType.setName(featureType.getNativeName()); - } + + initResourceInfo(featureType); + // setup the srs if missing if (featureType.getSRS() == null) { lookupSRS(featureType, true); @@ -572,15 +582,9 @@ */ public void initWMSLayer(WMSLayerInfo wmsLayer) throws Exception { wmsLayer.setCatalog(catalog); + + initResourceInfo(wmsLayer); - // set the name - if (wmsLayer.getNativeName() == null && wmsLayer.getName() != null) { - wmsLayer.setNativeName(wmsLayer.getName()); - } - if (wmsLayer.getNativeName() != null && wmsLayer.getName() == null) { - wmsLayer.setName(wmsLayer.getNativeName()); - } - // get a fully initialized version we can copy from WMSLayerInfo full = buildWMSLayer(wmsLayer.getNativeName()); @@ -609,6 +613,53 @@ } /** + * Initialize a coverage object and set any unset info. + */ + public void initCoverage(CoverageInfo cinfo) throws Exception { + CoverageStoreInfo csinfo = (CoverageStoreInfo) store; + AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) catalog + .getResourcePool().getGridCoverageReader(csinfo, GeoTools.getDefaultHints()); + + initResourceInfo(cinfo); + + if (reader == null) + throw new Exception("Unable to acquire a reader for this coverage with format: " + + csinfo.getFormat().getName()); + + if (cinfo.getNativeCRS() == null) { + cinfo.setNativeCRS(reader.getCrs()); + } + + CoordinateReferenceSystem nativeCRS = cinfo.getNativeCRS(); + + if (cinfo.getSRS() == null) { + cinfo.setSRS(nativeCRS.getIdentifiers().toArray()[0].toString()); + } + + if (cinfo.getProjectionPolicy() == null) { + if (nativeCRS != null && !nativeCRS.getIdentifiers().isEmpty()) { + cinfo.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); + } + if (nativeCRS == null) { + cinfo.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); + } + } + + if (cinfo.getLatLonBoundingBox() == null + && cinfo.getNativeBoundingBox() == null) { + GeneralEnvelope envelope = reader.getOriginalEnvelope(); + + cinfo.setNativeBoundingBox(new ReferencedEnvelope(envelope)); + cinfo.setLatLonBoundingBox(new ReferencedEnvelope(CoverageStoreUtils.getWGS84LonLatEnvelope(envelope))); + } else if (cinfo.getLatLonBoundingBox() == null) { + setupBounds(cinfo); + } else if (cinfo.getNativeBoundingBox() == null && cinfo.getNativeCRS() != null) { + ReferencedEnvelope boundsLatLon = cinfo.getLatLonBoundingBox(); + cinfo.setNativeBoundingBox(boundsLatLon.transform(cinfo.getNativeCRS(), true)); + } + } + + /** * Builds the default coverage contained in the current store * * @return Index: restconfig/src/test/java/org/geoserver/catalog/rest/CoverageTest.java =================================================================== --- restconfig/src/test/java/org/geoserver/catalog/rest/CoverageTest.java (revision 16153) +++ restconfig/src/test/java/org/geoserver/catalog/rest/CoverageTest.java (working copy) @@ -102,8 +102,8 @@ "usa"+ "usa is a A raster file accompanied by a spatial data file" + "Generated from WorldImage" + - "EPSG:4326" + - ""+ + "EPSG:4326" + + /*""+ "-130.85168"+ "-62.0054"+ "20.7052"+ @@ -115,7 +115,7 @@ "20.7052"+ "54.1141"+ "EPSG:4326"+ - ""+ + ""+*/ ""+ ""+ "0 0"+ @@ -150,11 +150,14 @@ assertEquals( 201, response.getStatusCode() ); assertNotNull( response.getHeader( "Location") ); assertTrue( response.getHeader("Location").endsWith( "/workspaces/gs/coveragestores/usaWorldImage/coverages/usa" ) ); - + dom = getAsDOM( req ); assertEquals( "wcs:Coverages", dom.getDocumentElement().getNodeName() ); + + dom = getAsDOM("/rest/workspaces/gs/coveragestores/usaWorldImage/coverages/usa.xml"); + assertXpathEvaluatesTo("-130.85168", "/coverage/latLonBoundingBox/minx", dom); } - + // public void testPostAsJSON() throws Exception { // Document dom = getAsDOM( "wfs?request=getfeature&typename=wcs:pdsa"); // assertEquals( "ows:ExceptionReport", dom.getDocumentElement().getNodeName()); Index: restconfig/src/main/java/org/geoserver/catalog/rest/CoverageResource.java =================================================================== --- restconfig/src/main/java/org/geoserver/catalog/rest/CoverageResource.java (revision 16153) +++ restconfig/src/main/java/org/geoserver/catalog/rest/CoverageResource.java (working copy) @@ -74,7 +74,11 @@ CoverageStoreInfo ds = catalog.getCoverageStoreByName( workspace, coveragestore ); coverage.setStore( ds ); } - + + CatalogBuilder builder = new CatalogBuilder(catalog); + builder.setStore(coverage.getStore()); + builder.initCoverage(coverage); + NamespaceInfo ns = coverage.getNamespace(); if ( ns != null && !ns.getPrefix().equals( workspace ) ) { //TODO: change this once the two can be different and we untie namespace @@ -93,7 +97,7 @@ catalog.add( coverage ); //create a layer for the coverage - catalog.add(new CatalogBuilder(catalog).buildLayer(coverage)); + catalog.add(builder.buildLayer(coverage)); LOGGER.info( "POST coverage " + coveragestore + "," + coverage.getName() ); return coverage.getName();