Skip to content

Commit

Permalink
Fixed silent error due to url case-sensitivity. Adjusted request body…
Browse files Browse the repository at this point in the history
… accordingly. geosolutions-it#199
  • Loading branch information
cschroedl-gov committed Sep 20, 2016
1 parent c9ef31f commit ce3ee33
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3212,13 +3212,6 @@ public void postImport(int i) throws Exception {
* @author Carl Schroedl - [email protected]
*/
public enum BBoxRecalculationMode {
/**
* Do not calculate any fields, regardless of the projection, projection
* policy, etc. This might be useful to avoid slow recalculation when
* operating against large datasets.
*/
NONE(""),

/**
* Recalculate the native bounding box, but do not recalculate the
* lat/long bounding box.
Expand All @@ -3229,7 +3222,14 @@ public enum BBoxRecalculationMode {
* Recalculate both the native bounding box and the lat/long bounding
* box.
*/
NATIVE_AND_LAT_LON_BBOX("nativebbox,latlonbbox")
NATIVE_AND_LAT_LON_BBOX("nativebbox,latlonbbox"),

/**
* Do not calculate any fields, regardless of the projection, projection
* policy, etc. This might be useful to avoid slow recalculation when
* operating against large datasets.
*/
NONE(""),
;

private final String paramValue;
Expand All @@ -3256,24 +3256,36 @@ public String getParamValue(){
* Recalculate the bounding box for a feature type or a coverage
*
* @param type
* @param xmlElementName - either featureType or coverage
* @param workspace
* @param storeName
* @param layerName
* @param calculationMode
* @return true if recalculation succeeded, false otherwise.
*/
private boolean recalculateBBox(StoreType type, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){
private boolean recalculateBBox(StoreType type, String xmlElementName, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){

String sUrl = restURL + "/rest/workspaces/" + workspace + "/" +
type.getType() +"s/" + storeName + "/" +
type.getTypeName() + "/" +
layerName + "." + Format.XML.toString() + "?recalculate=" +
calculationMode.getParamValue();
String baseUrl = restURL + "/rest/workspaces/" + workspace + "/" +
type.getType().toLowerCase() +"s/" + storeName + "/" +
type.getTypeName().toLowerCase() + "/" +
layerName + "." + Format.XML.toString();


// LOGGER.debug("Retrieving current state of item from "+ baseUrl);
// String getResult = HTTPUtils.get(baseUrl, gsuser, gspass);

// LOGGER.debug("Current state of item is:\n" + getResult);

String sUrl = baseUrl + "?recalculate=" + calculationMode.getParamValue();
LOGGER.debug("Constructed the following url for bounding box recalculation: " + sUrl);

// String body = getResult
// GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace);

String sendResult = HTTPUtils.put(sUrl, "", "text/plain", gsuser,
gspass);
// String body = wsenc.toString();
String body = "<" + xmlElementName +"><name>" + layerName + "</name>" +
"<enabled>" + enabled + "</enabled></" + xmlElementName + ">";
String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass);
boolean success = sendResult != null;
return success;
}
Expand All @@ -3284,10 +3296,10 @@ private boolean recalculateBBox(StoreType type, String workspace, String storeNa
* @param storeName
* @param layerName
* @param calculationMode
* @return
* @return true if successful, false otherwise
*/
public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){
return recalculateBBox(StoreType.DATASTORES, workspace, storeName, layerName, calculationMode);
public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){
return recalculateBBox(StoreType.DATASTORES, "featureType", workspace, storeName, layerName, calculationMode, enabled);
}

/**
Expand All @@ -3296,9 +3308,9 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St
* @param storeName
* @param layerName
* @param calculationMode
* @return
* @return true if successful, false otherwise
*/
public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){
return recalculateBBox(StoreType.COVERAGESTORES, workspace, storeName, layerName, calculationMode);
public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){
return recalculateBBox(StoreType.COVERAGESTORES, "coverage", workspace, storeName, layerName, calculationMode, enabled);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package it.geosolutions.geoserver.rest.publisher;

import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.UploadMethod;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoderTest;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.httpclient.NameValuePair;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

/**
* Testcase for publishing layers on geoserver.
* We need a running GeoServer to properly run the tests.
* If such geoserver instance cannot be contacted, tests will be skipped.
*
* @author Carl Schroedl - [email protected]
*/
public class GeoserverRESTRecalculateTest extends GeoserverRESTTest {

private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTRecalculateTest.class);

@Before
@Override
public void before(){
super.before();
deleteAll();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
}

@After
public void cleanUp(){
deleteAll();
}

@Test
public void testRecalculateFeatureTypeBBox() throws FileNotFoundException, IOException {
if (!enabled())
return;

String storeName = "resttestshp";
String layerName = "cities";

File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
assertTrue(publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile));

for(GeoServerRESTPublisher.BBoxRecalculationMode recalcMode : GeoServerRESTPublisher.BBoxRecalculationMode.values()){
boolean recalculated = publisher.recalculateFeatureTypeBBox(DEFAULT_WS,storeName, layerName, recalcMode, true);
assertTrue("recalculateBBox failed with recalculation mode '" +recalcMode.toString() + "'.", recalculated);
}
}

@Test
public void testRecalculateCoverageBBox() throws FileNotFoundException, IOException {
if (!enabled())
return;

String storeName = "testRESTStoreArcGrid";
String layerName = "resttestdem";

File arcgrid = new ClassPathResource("testdata/resttestdem.asc").getFile();

assertTrue(publisher.publishArcGrid(DEFAULT_WS, storeName, layerName, arcgrid));

for(GeoServerRESTPublisher.BBoxRecalculationMode recalcMode : GeoServerRESTPublisher.BBoxRecalculationMode.values()){
boolean recalculated = publisher.recalculateCoverageBBox(DEFAULT_WS,storeName, layerName, recalcMode, true);
assertTrue("recalculateBBox failed with recalculation mode '" +recalcMode.toString() + "'.", recalculated);
}
}
}

0 comments on commit ce3ee33

Please sign in to comment.