#17 Create a method to update the default style of a given layer
This commit is contained in:
parent
fa22471878
commit
bbd13b3aa9
@ -730,7 +730,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* Allows to configure some layer attributes such as WmsPath and DefaultStyle
|
* Allows to configure some layer attributes such as WmsPath and DefaultStyle
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected boolean configureLayer(final GSLayerEncoder layer, final String layerName) {
|
public boolean configureLayer(final GSLayerEncoder layer, final String layerName) {
|
||||||
|
|
||||||
if (layer.isEmpty()) {
|
if (layer.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -27,6 +27,8 @@ package it.geosolutions.geoserver.rest;
|
|||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -34,6 +36,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.Namespace;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,7 +88,21 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
|
|||||||
|
|
||||||
String sld = reader.getSLD(styleName);
|
String sld = reader.getSLD(styleName);
|
||||||
assertNotNull(sld);
|
assertNotNull(sld);
|
||||||
assertEquals(1475, sld.length());
|
|
||||||
|
Element styleEl = JDOMBuilder.buildElement(sld);
|
||||||
|
assertNotNull(styleEl);
|
||||||
|
|
||||||
|
Namespace SLDNS = Namespace.getNamespace("sld", "http://www.opengis.net/sld");
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
assertEquals(styleName, styleEl.getChild("NamedLayer", SLDNS).getChild("Name",SLDNS).getText());
|
||||||
|
assertEquals("STYLE FOR TESTING PURPOSES", styleEl.getChild("NamedLayer", SLDNS).getChild("UserStyle", SLDNS).getChild("Title", SLDNS).getText());
|
||||||
|
} catch(NullPointerException npe) {
|
||||||
|
fail("Error in SLD");
|
||||||
|
}
|
||||||
|
|
||||||
|
// assertEquals(1475, sld.length());
|
||||||
|
|
||||||
assertEquals(1, reader.getStyles().size());
|
assertEquals(1, reader.getStyles().size());
|
||||||
}
|
}
|
||||||
@ -320,6 +338,70 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
|
|||||||
assertFalse("removed not existing datastore", ok);
|
assertFalse("removed not existing datastore", ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testUpdateDefaultStyle() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ns = "it.geosolutions";
|
||||||
|
String storeName = "resttestshp";
|
||||||
|
String layerName = "cities";
|
||||||
|
|
||||||
|
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
{
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
cleanupTestStyle(styleName);
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String styleName2 = "restteststyle2";
|
||||||
|
{
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile();
|
||||||
|
cleanupTestStyle(styleName2);
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
cleanupTestFT(layerName, ns, storeName);
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(ns, storeName, layerName, zipFile, "EPSG:4326", styleName);
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
|
||||||
|
{
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals(styleName, layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
GSLayerEncoder le = new GSLayerEncoder();
|
||||||
|
le.addDefaultStyle(styleName2);
|
||||||
|
publisher.configureLayer(le, layerName);
|
||||||
|
|
||||||
|
{
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals(styleName2, layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// remove layer and datastore
|
||||||
|
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
|
||||||
|
assertFalse(existsLayer(layerName));
|
||||||
|
boolean dsRemoved = publisher.removeDatastore(ns, storeName);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
}
|
||||||
|
|
||||||
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
||||||
// String wsName = "this_ws_does_not_exist";
|
// String wsName = "this_ws_does_not_exist";
|
||||||
// String storeName = "this_store_does_not_exist";
|
// String storeName = "this_store_does_not_exist";
|
||||||
|
|||||||
35
src/test/resources/testdata/restteststyle2.sld
vendored
Normal file
35
src/test/resources/testdata/restteststyle2.sld
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
|
||||||
|
<sld:NamedLayer>
|
||||||
|
<sld:Name>country</sld:Name>
|
||||||
|
<sld:UserStyle>
|
||||||
|
<sld:Name>restteststyle2</sld:Name>
|
||||||
|
<sld:Title>STYLE2 FOR TESTING PURPOSES</sld:Title>
|
||||||
|
<sld:Abstract>A sample style that just draws out a solid gray interior with a black 1px outline</sld:Abstract>
|
||||||
|
<sld:FeatureTypeStyle>
|
||||||
|
<sld:Name>name2</sld:Name>
|
||||||
|
<sld:FeatureTypeName>Feature</sld:FeatureTypeName>
|
||||||
|
<sld:SemanticTypeIdentifier>SemanticType[ANY]</sld:SemanticTypeIdentifier>
|
||||||
|
<sld:Rule>
|
||||||
|
<sld:Title>Polygon</sld:Title>
|
||||||
|
<sld:PolygonSymbolizer>
|
||||||
|
<sld:Fill>
|
||||||
|
<sld:CssParameter name="fill">
|
||||||
|
<ogc:Literal>#C8B679</ogc:Literal>
|
||||||
|
</sld:CssParameter>
|
||||||
|
<sld:CssParameter name="fill-opacity">
|
||||||
|
<ogc:Literal>1.0</ogc:Literal>
|
||||||
|
</sld:CssParameter>
|
||||||
|
</sld:Fill>
|
||||||
|
<sld:Stroke>
|
||||||
|
<sld:CssParameter name="stroke">
|
||||||
|
<ogc:Literal>#000000</ogc:Literal>
|
||||||
|
</sld:CssParameter>
|
||||||
|
</sld:Stroke>
|
||||||
|
</sld:PolygonSymbolizer>
|
||||||
|
</sld:Rule>
|
||||||
|
</sld:FeatureTypeStyle>
|
||||||
|
</sld:UserStyle>
|
||||||
|
</sld:NamedLayer>
|
||||||
|
</sld:StyledLayerDescriptor>
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user