#87, Add support for Mosaic Creation by Zip Upload

This commit is contained in:
Simone Giannecchini 2013-07-16 20:37:55 +02:00
parent 205cd75285
commit 4dac450327
20 changed files with 404 additions and 197 deletions

View File

@ -39,15 +39,18 @@ import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager.ConfigureCoveragesOption;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.zip.ZipFile;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.io.FilenameUtils;
@ -2640,12 +2643,12 @@ public class GeoServerRESTPublisher {
*
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
*/
public boolean createOrHarvestExternal(String workspace, String coverageStore, String format,
public boolean harvestExternal(String workspace, String coverageStore, String format,
String path) {
try {
GeoServerRESTStructuredGridCoverageReaderManager manager = new GeoServerRESTStructuredGridCoverageReaderManager(
new URL(restURL), gsuser, gspass);
return manager.createOrHarvestExternal(workspace, coverageStore, format, path);
return manager.harvestExternal(workspace, coverageStore, format, path);
} catch (IllegalArgumentException e) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(e.getLocalizedMessage(), e);
@ -2658,6 +2661,84 @@ public class GeoServerRESTPublisher {
return false;
}
/**
* Create a new ImageMosaic with the provided configuration provided as a zip file.
*
* <p>
* This call configures all the coverages contained in the ImageMosaic.
*
* @param workspace the GeoServer workspace
* @param coverageStore the GeoServer coverageStore
* @param the absolute path to the file to upload
*
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
* @since geoserver-2.4.0, geoserver-mng-1.6.0
*/
public boolean createImageMosaic(String workspace, String coverageStore, String path) {
return createImageMosaic(workspace, coverageStore, path, ConfigureCoveragesOption.ALL);
}
/**
* Create a new ImageMosaic with the provided configuration provided as a zip file.
*
* <p>
* With the options configure we can decide whether or not to configure or not the coverages contained in the ImageMosaic.
*
* @param workspace the GeoServer workspace
* @param coverageStore the GeoServer coverageStore
* @param the absolute path to the file to upload
* @param configureOpt tells GeoServer whether to configure all coverages in this mosaic (ALL) or none of them (NONE).
*
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
* @since geoserver-2.4.0, geoserver-mng-1.6.0
*/
public boolean createImageMosaic(String workspace, String coverageStore, String path, ConfigureCoveragesOption configureOpt) {
// checks
checkString(workspace);
checkString(coverageStore);
checkString(path);
final File zipFile= new File(path);
if(!zipFile.exists()||!zipFile.isFile()||!zipFile.canRead()){
throw new IllegalArgumentException("The provided pathname does not point to a valide zip file: "+path);
}
// is it a zip?
ZipFile zip=null;
try{
zip= new ZipFile(zipFile);
zip.getName();
}catch (Exception e) {
LOGGER.trace(e.getLocalizedMessage(),e.getStackTrace());
throw new IllegalArgumentException("The provided pathname does not point to a valide zip file: "+path);
}finally{
if(zip!=null){
try {
zip.close();
} catch (IOException e) {
// swallow
LOGGER.trace(e.getLocalizedMessage(),e.getStackTrace());
}
}
}
// create URL
StringBuilder ss=HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/",
coverageStore, "/", UploadMethod.EXTERNAL.toString(), ".imagemosaic");
switch(configureOpt){
case ALL:
break;
case NONE:
ss.append("?configure=none");
break;
default:
throw new IllegalArgumentException("Unrecognized COnfigureOption: "+configureOpt);
}
String sUrl = ss.toString();
// POST request
String result = HTTPUtils.put(sUrl, zipFile, "application/zip", gsuser, gspass);
return result != null;
}
/**
* Remove a granule from a structured coverage by id.
*
@ -2721,4 +2802,22 @@ public class GeoServerRESTPublisher {
}
/**
* Check the provided string for not being null or empty.
*
* <p>
* It throws an exception in case the string is either null or empty.
*
* @param string the {@link String} to be checked
*/
private static void checkString(String string) {
if (string == null) {
throw new NullPointerException("Provided string is is null!");
}
if (string.length() <= 0) {
throw new IllegalArgumentException("Provided string is is empty!");
}
}
}

View File

@ -227,4 +227,23 @@ public class RESTStructuredCoverageGranulesList implements Iterable<RESTStructur
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("RESTStructuredCoverageGranulesList [");
if (bbox != null) {
builder.append("bbox=");
builder.append(bbox);
}
if (granulesList != null) {
builder.append("granulesList={");
for(RESTStructuredCoverageGranule granule:granulesList){
builder.append(granule);
}
builder.append("}, ");
}
builder.append("]");
return builder.toString();
}
}

View File

@ -32,14 +32,20 @@ import java.math.BigDecimal;
/**
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
* @author Simone Giannecchini, GeoSolutions
*
*/
public class GSDimensionInfoEncoder extends XmlElement{
public final static String DIMENSIONINFO="dimensionInfo";
public final static String RESOLUTION="resolution";
public final static String PRESENTATION="presentation";
public final static String UNITS="units";
public final static String UNIT_SYMBOL="unitSymbol";
private boolean enabled;
/**
@ -116,4 +122,36 @@ public class GSDimensionInfoEncoder extends XmlElement{
}
/**
* Set UoM for this dimension.
*
* <code>null</code> is acceptable and leave this UoM blank.
*
* @param unit UoM for this dimension.
*/
public void setUnit(final String unit){
if(unit==null||unit.length()<=0){
return;
}
if (enabled){
set(UNITS,unit);
}
}
/**
* Set UoM for this dimension.
*
* <code>null</code> is acceptable and leave this UoM blank.
*
* @param unit UoM for this dimension.
*/
public void setUnitSymbol(final String unitSymbol){
if(unitSymbol==null||unitSymbol.length()<=0){
return;
}
if (enabled){
set(UNIT_SYMBOL,unitSymbol);
}
}
}

View File

@ -29,10 +29,13 @@ import it.geosolutions.geoserver.rest.HTTPUtils;
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList;
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageIndexSchema;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.zip.ZipFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,6 +47,21 @@ import org.slf4j.LoggerFactory;
* @author Simone Giannecchini, GeoSolutions
*/
public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerRESTAbstractManager {
/**
* Option that tells GeoServer whether or not to configure all the coverages for a certain ImageMosaic.
*
* @author Simone Giannecchini, GeoSolutions
*
*/
public enum ConfigureCoveragesOption{
NONE,
ALL;
public static ConfigureCoveragesOption getDefault() {
return ALL;
}
}
/**
* Default logger
@ -63,19 +81,97 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
String password) throws IllegalArgumentException, MalformedURLException {
super(restURL, username, password);
}
/**
* Create a new ImageMosaic with the provided configuration provided as a zip file.
*
* <p>
* This call configures all the coverages contained in the ImageMosaic.
*
* @param workspace the GeoServer workspace
* @param coverageStore the GeoServer coverageStore
* @param the absolute path to the file to upload
*
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
* @since geoserver-2.4.0, geoserver-mng-1.6.0
*/
public boolean create(String workspace, String coverageStore, String path) {
return create(workspace, coverageStore, path, ConfigureCoveragesOption.ALL);
}
/**
* Create a new ImageMosaic with the provided configuration provided as a zip file.
*
* <p>
* With the options configure we can decide whether or not to configure or not the coverages contained in the ImageMosaic.
*
* @param workspace the GeoServer workspace
* @param coverageStore the GeoServer coverageStore
* @param the absolute path to the file to upload
* @param configureOpt tells GeoServer whether to configure all coverages in this mosaic (ALL) or none of them (NONE).
*
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
* @since geoserver-2.4.0, geoserver-mng-1.6.0
*/
public boolean create(String workspace, String coverageStore, String path, ConfigureCoveragesOption configureOpt) {
// checks
checkString(workspace);
checkString(coverageStore);
checkString(path);
final File zipFile= new File(path);
if(!zipFile.exists()||!zipFile.isFile()||!zipFile.canRead()){
throw new IllegalArgumentException("The provided pathname does not point to a valide zip file: "+path);
}
// is it a zip?
ZipFile zip=null;
try{
zip= new ZipFile(zipFile);
zip.getName();
}catch (Exception e) {
LOGGER.trace(e.getLocalizedMessage(),e.getStackTrace());
throw new IllegalArgumentException("The provided pathname does not point to a valide zip file: "+path);
}finally{
if(zip!=null){
try {
zip.close();
} catch (IOException e) {
// swallow
LOGGER.trace(e.getLocalizedMessage(),e.getStackTrace());
}
}
}
// create URL
StringBuilder ss=HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/",
coverageStore, "/file.imagemosaic");
switch(configureOpt){
case ALL:
break;
case NONE:
ss.append("?configure=none");
break;
default:
throw new IllegalArgumentException("Unrecognized COnfigureOption: "+configureOpt);
}
String sUrl = ss.toString();
// POST request
String result = HTTPUtils.put(sUrl, zipFile, "application/zip", gsuser, gspass);
return result != null;
}
/**
* Create a store or harvest the coverage from the provided <b>external</b> path.
*
* @param workspace the GeoServer workspace
* @param coverageStore the GeoServer coverageStore
* @param format the format of the file to upload
* @param the absolut path to the file to upload
* @param the absolute path to the file to upload
*
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
* @since geoserver-2.4.0, geoserver-mng-1.6.0
*/
public boolean createOrHarvestExternal(String workspace, String coverageStore, String format,
public boolean harvestExternal(String workspace, String coverageStore, String format,
String path) {
// checks
checkString(workspace);

View File

@ -24,7 +24,6 @@ package it.geosolutions.geoserver.decoder;
import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
import it.geosolutions.geoserver.rest.decoder.RESTDimensionInfo;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo;
import java.io.File;
import java.io.IOException;

View File

@ -24,12 +24,11 @@
*/
package it.geosolutions.geoserver.rest.datastore;
import java.net.MalformedURLException;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import java.net.MalformedURLException;
/**
* Testcase for creating arcsde-based resources on geoserver.

View File

@ -24,16 +24,11 @@
*/
package it.geosolutions.geoserver.rest.datastore;
import java.net.MalformedURLException;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.MalformedURLException;
/**
* Testcase for creating OracleNG-based resources on geoserver.

View File

@ -24,18 +24,16 @@
*/
package it.geosolutions.geoserver.rest.datastore;
import java.net.MalformedURLException;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import org.junit.Before;
import java.net.MalformedURLException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -56,14 +54,14 @@ import org.slf4j.LoggerFactory;
*/
public abstract class StoreIntegrationTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(StoreIntegrationTest.class);
private final GeoServerRESTStoreManager storeManager;
protected final GeoServerRESTStoreManager storeManager;
/**
* ignore integration tests
*/
private final boolean ignore;
protected final boolean ignore;
private final static Logger LOGGER = LoggerFactory.getLogger(StoreIntegrationTest.class);
public boolean isIgnore() {
return ignore;
@ -84,64 +82,64 @@ public abstract class StoreIntegrationTest extends GeoserverRESTTest {
public abstract GSAbstractStoreEncoder getStoreEncoderTest();
@Test
public void testCreateDeleteDatastore() throws IllegalArgumentException, MalformedURLException {
if (!enabled()) {
return;
public void testCreateDeleteDatastore() throws IllegalArgumentException, MalformedURLException {
if (!enabled()) {
return;
}
deleteAll();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
// creation test
GSAbstractStoreEncoder storeEncoder=getStoreEncoderTest();
String storeName = storeEncoder.getName();
// String description = storeEncoder.getDescription();
boolean created = storeManager.create(DEFAULT_WS, storeEncoder);
if( ! ignore )
assertTrue("Datastore not created", created);
else if( ! created)
LOGGER.error("*** store " + storeName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(DEFAULT_WS, storeName);
assertNotNull(datastore);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
//check if the datastore is properly configured in GS for publishing layers
String layername = "states";
if(storeEncoder instanceof GSOracleNGDatastoreEncoder)
layername = layername.toUpperCase();
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.setName(layername);
fte.setTitle(layername);
fte.setNativeCRS("EPSG:4326");
fte.setDescription("desc");
fte.setEnabled(true);
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setDefaultStyle("polygon");
boolean published = publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder);
if(!ignore){
assertTrue("Test layer not published", published);
}else if(!published){
LOGGER.error("*** Test layer "
+ layername
+ " has not been published. Problem in datastore configuration");
}
// removing test
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
if( ! ignore )
assertTrue("Datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + storeName + " has not been removed.");
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
}
deleteAll();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
// creation test
GSAbstractStoreEncoder storeEncoder=getStoreEncoderTest();
String storeName = storeEncoder.getName();
// String description = storeEncoder.getDescription();
boolean created = storeManager.create(DEFAULT_WS, storeEncoder);
if( ! ignore )
assertTrue("Datastore not created", created);
else if( ! created)
LOGGER.error("*** store " + storeName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(DEFAULT_WS, storeName);
assertNotNull(datastore);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
//check if the datastore is properly configured in GS for publishing layers
String layername = "states";
if(storeEncoder instanceof GSOracleNGDatastoreEncoder)
layername = layername.toUpperCase();
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.setName(layername);
fte.setTitle(layername);
fte.setNativeCRS("EPSG:4326");
fte.setDescription("desc");
fte.setEnabled(true);
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setDefaultStyle("polygon");
boolean published = publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder);
if(!ignore){
assertTrue("Test layer not published", published);
}else if(!published){
LOGGER.error("*** Test layer "
+ layername
+ " has not been published. Problem in datastore configuration");
}
// removing test
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
if( ! ignore )
assertTrue("Datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + storeName + " has not been removed.");
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
}
}

View File

@ -24,8 +24,11 @@
*/
package it.geosolutions.geoserver.rest.encoder;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.net.URI;
import org.junit.Test;
/**

View File

@ -1,9 +1,9 @@
package it.geosolutions.geoserver.rest.encoder.feature;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import java.math.BigDecimal;

View File

@ -27,10 +27,10 @@ import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTGeometryEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTParameterEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.publisher.GeoserverRESTPublisherTest;

View File

@ -1,14 +1,10 @@
package it.geosolutions.geoserver.rest.encoder.feature;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTGeometryEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTParameterEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTGeometry;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTGeometryEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTParameter;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
import java.util.Arrays;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTParameterEncoder;
import junit.framework.Assert;
import org.jdom.Element;

View File

@ -16,26 +16,26 @@
*/
package it.geosolutions.geoserver.rest.manager;
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
import it.geosolutions.geoserver.rest.datastore.StoreIntegrationTest;
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList;
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList.RESTStructuredCoverageGranule;
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageIndexSchema;
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageIndexSchema.RESTStructuredCoverageIndexAttribute;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
import it.geosolutions.geoserver.rest.encoder.coverage.GSImageMosaicEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Iterator;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import sun.management.counter.Units;
/**
* In order to test that class, make sure to configure a geoserver with a "mosaic" store.
@ -52,42 +52,30 @@ import org.slf4j.LoggerFactory;
* @author Daniele Romagnoli, GeoSolutions SAS
*
*/
public class GeoServerRESTImageMosaicManagerTest extends StoreIntegrationTest {
public class GeoServerRESTImageMosaicManagerTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTImageMosaicManagerTest.class);
/**
* @param ignore
* @throws IllegalArgumentException
* @throws MalformedURLException
*/
public GeoServerRESTImageMosaicManagerTest()
throws IllegalArgumentException, MalformedURLException {
super(true);
}
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
return null;
}
@Test
public void createAndDelete() throws IllegalArgumentException, MalformedURLException, UnsupportedEncodingException{
public void createAndDelete() throws Exception{
if (!enabled()) {
return;
}
GeoServerRESTStructuredGridCoverageReaderManager manager =
new GeoServerRESTStructuredGridCoverageReaderManager(new URL(RESTURL), RESTUSER, RESTPW);
GeoServerRESTReader reader = new GeoServerRESTReader(new URL(RESTURL), RESTUSER, RESTPW);
// create mosaic
boolean create=manager.create("it.geosolutions", "mosaic",new ClassPathResource("testdata/granules/mosaic.zip").getFile().getAbsolutePath());
assertTrue(create);
// enable dimension
fixDimensions("it.geosolutions", "mosaic", "mosaic");
// check index format
RESTStructuredCoverageIndexSchema indexFormat = manager.getGranuleIndexSchema("it.geosolutions", "mosaic","mosaic");
if (indexFormat == null) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("sample coverage hasn't been found. Make sure to configure the layer before running this test");
return;
}
}
assertTrue(create);
assertNotNull(indexFormat);
assertFalse(indexFormat.isEmpty());
assertEquals(5, indexFormat.size());
@ -104,7 +92,7 @@ public class GeoServerRESTImageMosaicManagerTest extends StoreIntegrationTest {
assertEquals("0", element.getMinOccurs());
assertEquals("1", element.getMaxOccurs());
assertEquals("true", element.getNillable());
assertEquals("java.sql.Timestamp", element.getBinding());
assertEquals("java.util.Date", element.getBinding());
} else if (elementName.equals("date")) {
assertEquals("0", element.getMinOccurs());
assertEquals("1", element.getMaxOccurs());
@ -180,14 +168,8 @@ public class GeoServerRESTImageMosaicManagerTest extends StoreIntegrationTest {
assertNotNull(granule);
// Readding that granule
RESTCoverageStore store = reader.getCoverageStore("it.geosolutions", "mosaic");
final String urlString = store.getURL();
final URL url = new URL(urlString);
final File file = urlToFile(url);
final String filePath = file.getAbsolutePath();
// use reflection to get the store URL since coveragestore only returns name and workspace
result = manager.createOrHarvestExternal("it.geosolutions", "mosaic", "imagemosaic", filePath + File.separatorChar + fileLocation );
result = manager.harvestExternal("it.geosolutions", "mosaic", "imagemosaic", new ClassPathResource("testdata/granules/NCOM_wattemp_100_20081101T0000000_12.tiff").getFile().getAbsolutePath() );
Assert.assertTrue(result);
granulesList = manager.getGranules("it.geosolutions", "mosaic", "mosaic", null, null, null);
@ -201,64 +183,57 @@ public class GeoServerRESTImageMosaicManagerTest extends StoreIntegrationTest {
/**
* This method has been copied from org.geotools.data.DataUtilities
* This method enables the various dimensions for the coverage autocreated for this test.
*
* Takes a URL and converts it to a File. The attempts to deal with Windows UNC format specific
* problems, specifically files located on network shares and different drives.
*
* If the URL.getAuthority() returns null or is empty, then only the url's path property is used
* to construct the file. Otherwise, the authority is prefixed before the path.
*
* It is assumed that url.getProtocol returns "file".
*
* Authority is the drive or network share the file is located on. Such as "C:", "E:",
* "\\fooServer"
*
* @param url
* a URL object that uses protocol "file"
* @return a File that corresponds to the URL's location
* @param wsName the workspace
* @param coverageStoreName the coverage store name
* @param csname the coverage name
*/
private static File urlToFile(URL url) {
if (!"file".equals(url.getProtocol())) {
return null; // not a File URL
}
String string = url.toExternalForm();
if (string.contains("+")) {
// this represents an invalid URL created using either
// file.toURL(); or
// file.toURI().toURL() on a specific version of Java 5 on Mac
string = string.replace("+", "%2B");
}
try {
string = URLDecoder.decode(string, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Could not decode the URL to UTF-8 format", e);
}
private void fixDimensions(String wsName, String coverageStoreName, String csname) {
String path3;
String simplePrefix = "file:/";
String standardPrefix = "file://";
String os = System.getProperty("os.name");
if (os.toUpperCase().contains("WINDOWS") && string.startsWith(standardPrefix)) {
// win32: host/share reference
path3 = string.substring(standardPrefix.length() - 2);
} else if (string.startsWith(standardPrefix)) {
path3 = string.substring(standardPrefix.length());
} else if (string.startsWith(simplePrefix)) {
path3 = string.substring(simplePrefix.length() - 1);
} else {
String auth = url.getAuthority();
String path2 = url.getPath().replace("%20", " ");
if (auth != null && !auth.equals("")) {
path3 = "//" + auth + path2;
} else {
path3 = path2;
}
}
return new File(path3);
final GSImageMosaicEncoder coverageEncoder = new GSImageMosaicEncoder();
/*
* unused in mosaic creation
* this is only useful if you want to modify an existing coverage:
* publisher.configureCoverage(ce, wsname, csname);
* or create a new one from an existing store:
* publisher.createCoverage(ce, wsname, csname);
*/
coverageEncoder.setName("mosaic");
coverageEncoder.setAllowMultithreading(true);
coverageEncoder.setBackgroundValues("");
coverageEncoder.setFilter("");
coverageEncoder.setInputTransparentColor("");
coverageEncoder.setLatLonBoundingBox(-180, -90, 180, 90, "EPSG:4326");
coverageEncoder.setMaxAllowedTiles(11);
coverageEncoder.setNativeBoundingBox(-180, -90, 180, 90, "EPSG:4326");
coverageEncoder.setProjectionPolicy(ProjectionPolicy.NONE);
coverageEncoder.setSRS("EPSG:4326");
// activate time
final GSDimensionInfoEncoder time=new GSDimensionInfoEncoder(true);
time.setUnit("Seconds");
time.setUnitSymbol("s");
time.setPresentation(Presentation.LIST);
coverageEncoder.setMetadataDimension("time", time);
// activate date
final GSDimensionInfoEncoder date=new GSDimensionInfoEncoder(true);
date.setPresentation(Presentation.LIST);
coverageEncoder.setMetadataDimension("custom_dimension_DATE", date);
// activate depth
final GSDimensionInfoEncoder depth=new GSDimensionInfoEncoder(true);
depth.setPresentation(Presentation.LIST);
depth.setUnit("Meters");
depth.setUnitSymbol("m");
coverageEncoder.setMetadataDimension("custom_dimension_DEPTH", depth);
boolean config=publisher.configureCoverage(coverageEncoder, wsName, csname);
assertTrue(config);
}
}

View File

@ -25,8 +25,8 @@
package it.geosolutions.geoserver.rest.publisher;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
@ -34,8 +34,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -24,13 +24,13 @@
*/
package it.geosolutions.geoserver.rest.publisher;
import org.junit.Test;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTNamespace;
import java.net.URI;
import org.junit.Test;
/**
* Testcase for namespace management.
*

View File

@ -30,13 +30,9 @@ import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.datastore.StoreIntegrationTest;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import java.net.MalformedURLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Testcase for creating postgis-based resources on geoserver.
* <P>

View File

@ -31,7 +31,6 @@ 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 it.geosolutions.geoserver.rest.encoder.feature.GSFeatureEncoderTest;
import java.io.File;
import java.io.FileNotFoundException;
@ -39,8 +38,6 @@ import java.io.IOException;
import org.apache.commons.httpclient.NameValuePair;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Binary file not shown.

View File

@ -1 +0,0 @@
regex=[a-z]{5,5}