Search in sources :

Example 1 with IGPGeoserverStyle

use of org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle in project geo-platform by geosdi.

the class GeoserverConnectorLayersTest method i_updateLayer.

@Ignore(value = "Layer poi_vito may be not present")
@Test
public void i_updateLayer() throws Exception {
    GeoserverLayer geoserverLayer = this.geoserverConnectorStore.loadWorkspaceLayerRequest().withWorkspaceName("tiger").withLayerName("poi_vito").getResponse();
    logger.info("##################LAYER {}\n", geoserverLayer);
    GeoserverLayerStyle layerStyle = geoserverLayer.getLayerStyle() != null ? geoserverLayer.getLayerStyle() : new GeoserverLayerStyle();
    List<IGPGeoserverStyle> styles = layerStyle.getStyles() != null ? geoserverLayer.getLayerStyle().getStyles() : Lists.newArrayList();
    GPGeoserverStyle gpGeoserverStyle = new GPGeoserverStyle();
    gpGeoserverStyle.setName("burg");
    styles.add(gpGeoserverStyle);
    layerStyle.setStyles(styles);
    geoserverLayer.setLayerStyle(layerStyle);
    logger.info("##################RESPONSE {}\n", this.geoserverConnectorStore.updateLayerRequest().withWorkspaceName("tiger").withLayerBody(geoserverLayer).withLayerName("poi_vito").getResponse());
    logger.info("##################UPDATED_LAYER {}\n", this.geoserverConnectorStore.loadWorkspaceLayerRequest().withWorkspaceName("tiger").withLayerName("poi_vito").getResponse());
}
Also used : GeoserverLayerStyle(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayerStyle) GeoserverLayer(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayer) IGPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle) GPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.GPGeoserverStyle) IGPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle) Ignore(org.junit.Ignore) GeoserverConnectorTest(org.geosdi.geoplatform.geoserver.GeoserverConnectorTest) Test(org.junit.Test)

Example 2 with IGPGeoserverStyle

use of org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle in project geo-platform by geosdi.

the class GPPublisherBasicServiceImpl method updateLayerStyle.

@Override
public Boolean updateLayerStyle(String workspace, String layerName, String styleToPublish, String styleName, boolean isDefault, boolean override) throws ResourceNotFoundFault {
    GeoserverLayer geoserverLayer = null;
    if (!this.checkIfExsistLayerInWorkspace(layerName, workspace)) {
        throw new ResourceNotFoundFault("The layer: " + layerName + " with workspace: " + workspace + " does not exists");
    }
    try {
        geoserverLayer = this.geoserverConnectorStore.loadWorkspaceLayerRequest().withLayerName(layerName).withWorkspaceName(workspace).getResponse();
    } catch (Exception e) {
        final String error = "Error to load layer with workspace name: " + workspace + " and layer name:" + layerName + " " + e;
        logger.error(error);
        throw new IllegalArgumentException(error, e.getCause());
    }
    try {
        if (override) {
            this.geoserverConnectorStore.updateStyleSLDV100Request().withStringStyleBody(styleToPublish).withRaw(FALSE).withStyleName(styleName).getResponse();
        } else {
            this.geoserverConnectorStore.createStyleSLDV100Request().withRaw(TRUE).withStyleName(styleName).withStringStyleBody(styleToPublish).getResponse();
        }
    } catch (Exception e) {
        throw new IllegalParameterFault("The Style with name " + styleName + " is not published.");
    }
    GeoserverLayerStyle layerStyle = geoserverLayer.getLayerStyle() != null ? geoserverLayer.getLayerStyle() : new GeoserverLayerStyle();
    List<IGPGeoserverStyle> styles = layerStyle.getStyles() != null ? geoserverLayer.getLayerStyle().getStyles() : Lists.newArrayList();
    GPGeoserverStyle gpGeoserverStyle = new GPGeoserverStyle();
    gpGeoserverStyle.setName(styleName);
    if (isDefault) {
        geoserverLayer.setDefaultStyle(gpGeoserverStyle);
    } else {
        styles.add(gpGeoserverStyle);
    }
    layerStyle.setStyles(styles);
    geoserverLayer.setLayerStyle(layerStyle);
    try {
        this.geoserverConnectorStore.updateLayerRequest().withWorkspaceName(workspace).withLayerBody(geoserverLayer).withLayerName(layerName).getResponse();
    } catch (Exception e) {
        final String error = "Error to update layer with workspace name: " + e;
        logger.error(error);
        return FALSE;
    }
    return TRUE;
}
Also used : GeoserverLayerStyle(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayerStyle) GeoserverLayer(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayer) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) IGPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle) GPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.GPGeoserverStyle) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) FactoryException(org.opengis.referencing.FactoryException) DataSourceException(org.geotools.data.DataSourceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IGPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle)

Aggregations

GeoserverLayer (org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayer)2 GeoserverLayerStyle (org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayerStyle)2 GPGeoserverStyle (org.geosdi.geoplatform.connector.geoserver.model.styles.GPGeoserverStyle)2 IGPGeoserverStyle (org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)1 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)1 GeoserverConnectorTest (org.geosdi.geoplatform.geoserver.GeoserverConnectorTest)1 DataSourceException (org.geotools.data.DataSourceException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 FactoryException (org.opengis.referencing.FactoryException)1