Search in sources :

Example 6 with GeoServerRESTManager

use of it.geosolutions.geoserver.rest.GeoServerRESTManager in project sldeditor by robward-scisys.

the class GeoServerClient method updateLayerStyles.

/**
 * Update layer styles.
 *
 * @param layer the original layer
 * @return true, if successful
 */
@Override
public boolean updateLayerStyles(GeoServerLayer layer) {
    if (layer == null) {
        return false;
    }
    StyleWrapper updatedStyle = layer.getStyle();
    boolean ok = false;
    GeoServerRESTManager manager = GeoServerRESTManagerFactory.getManager(connection);
    GeoServerRESTPublisher publisher = manager.getPublisher();
    if (publisher != null) {
        GSLayerEncoder layerEncoder = new GSLayerEncoder();
        String defaultStyle;
        if (isDefaultWorkspace(updatedStyle.getWorkspace())) {
            defaultStyle = updatedStyle.getStyle();
        } else {
            defaultStyle = updatedStyle.getWorkspace() + ":" + updatedStyle.getStyle();
        }
        layerEncoder.setDefaultStyle(defaultStyle);
        ok = publisher.configureLayer(layer.getLayerWorkspace(), layer.getLayerName(), layerEncoder);
    }
    return ok;
}
Also used : StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerRESTPublisher(it.geosolutions.geoserver.rest.GeoServerRESTPublisher) GSLayerEncoder(it.geosolutions.geoserver.rest.encoder.GSLayerEncoder) GeoServerRESTManager(it.geosolutions.geoserver.rest.GeoServerRESTManager)

Example 7 with GeoServerRESTManager

use of it.geosolutions.geoserver.rest.GeoServerRESTManager in project sldeditor by robward-scisys.

the class GeoServerClient method retrieveData.

/**
 * Retrieve data from GeoServer.
 */
@Override
public void retrieveData() {
    GeoServerRESTManager manager = GeoServerRESTManagerFactory.getManager(connection);
    if (manager != null) {
        GeoServerRESTReader reader = manager.getReader();
        if (reader != null) {
            if (parentObj != null) {
                parentObj.startPopulating(connection);
            }
            List<String> workspaceList = getWorkspaceList();
            parseStyleList(reader, workspaceList);
            parseLayerList(reader, workspaceList, null);
        }
    }
}
Also used : GeoServerRESTReader(it.geosolutions.geoserver.rest.GeoServerRESTReader) GeoServerRESTManager(it.geosolutions.geoserver.rest.GeoServerRESTManager)

Example 8 with GeoServerRESTManager

use of it.geosolutions.geoserver.rest.GeoServerRESTManager in project sldeditor by robward-scisys.

the class GeoServerClient method uploadSLD.

/**
 * Upload sld.
 *
 * @param styleWrapper the style wrapper
 * @param sldBody the sld body
 * @return true, if successful
 */
@Override
public boolean uploadSLD(StyleWrapper styleWrapper, String sldBody) {
    String workspaceName = styleWrapper.getWorkspace();
    String styleName = styleWrapper.getStyle();
    if (!workspaceValid(workspaceName)) {
        return false;
    }
    boolean result = false;
    GeoServerRESTManager manager = GeoServerRESTManagerFactory.getManager(connection);
    GeoServerRESTPublisher publisher = manager.getPublisher();
    if (publisher != null) {
        if (styleExists(workspaceName, styleName)) {
            if (isDefaultWorkspace(workspaceName)) {
                result = publisher.updateStyle(sldBody, styleName, true);
            } else {
                result = publisher.updateStyleInWorkspace(workspaceName, sldBody, styleName);
            }
        } else {
            if (isDefaultWorkspace(workspaceName)) {
                result = publisher.publishStyle(sldBody, styleName, true);
            } else {
                GeoServerRESTReader reader = manager.getReader();
                if (reader != null) {
                    if (!reader.existsWorkspace(workspaceName)) {
                        if (!publisher.createWorkspace(workspaceName)) {
                            ConsoleManager.getInstance().error(this, Localisation.getField(GeoServerClient.class, "GeoServerClient.failedToCreateWorkspace") + workspaceName);
                            return false;
                        }
                    }
                } else {
                    return false;
                }
                result = publisher.publishStyleInWorkspace(workspaceName, sldBody, styleName);
            }
        }
    }
    if (result) {
        ConsoleManager.getInstance().information(this, String.format("%s : %s %s/%s", Localisation.getString(GeoServerClient.class, "GeoServerClient.styleUploaded"), connection.getConnectionName(), workspaceName, styleName));
    }
    return result;
}
Also used : GeoServerRESTReader(it.geosolutions.geoserver.rest.GeoServerRESTReader) GeoServerRESTPublisher(it.geosolutions.geoserver.rest.GeoServerRESTPublisher) GeoServerRESTManager(it.geosolutions.geoserver.rest.GeoServerRESTManager)

Example 9 with GeoServerRESTManager

use of it.geosolutions.geoserver.rest.GeoServerRESTManager in project sldeditor by robward-scisys.

the class GeoServerClient method refreshWorkspace.

/**
 * Refresh workspace.
 *
 * @param workspaceName the workspace name
 */
@Override
public void refreshWorkspace(String workspaceName) {
    GeoServerRESTManager manager = GeoServerRESTManagerFactory.getManager(connection);
    if (manager != null) {
        GeoServerRESTReader reader = manager.getReader();
        if (reader != null) {
            Map<String, List<StyleWrapper>> styleMap = new LinkedHashMap<String, List<StyleWrapper>>();
            int count = 1;
            List<StyleWrapper> styleList = new ArrayList<StyleWrapper>();
            if (workspaceName.compareTo(DEFAULT_WORKSPACE_NAME) == 0) {
                count = parseStyleInDefaultWorkspace(reader, count, styleList);
                styleMap.put(DEFAULT_WORKSPACE_NAME, styleList);
            } else {
                // Read styles from workspace
                count = parseStyleInWorkspace(reader, styleMap, count, workspaceName);
            }
            if (parentObj != null) {
                parentObj.readStylesComplete(connection, styleMap, true);
            }
        }
    }
}
Also used : GeoServerRESTReader(it.geosolutions.geoserver.rest.GeoServerRESTReader) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ArrayList(java.util.ArrayList) RESTStyleList(it.geosolutions.geoserver.rest.decoder.RESTStyleList) ArrayList(java.util.ArrayList) List(java.util.List) RESTLayerList(it.geosolutions.geoserver.rest.decoder.RESTLayerList) GeoServerRESTManager(it.geosolutions.geoserver.rest.GeoServerRESTManager) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

GeoServerRESTManager (it.geosolutions.geoserver.rest.GeoServerRESTManager)9 GeoServerRESTReader (it.geosolutions.geoserver.rest.GeoServerRESTReader)5 GeoServerRESTPublisher (it.geosolutions.geoserver.rest.GeoServerRESTPublisher)4 StyleWrapper (com.sldeditor.common.data.StyleWrapper)2 RESTLayerList (it.geosolutions.geoserver.rest.decoder.RESTLayerList)1 RESTStyleList (it.geosolutions.geoserver.rest.decoder.RESTStyleList)1 GSLayerEncoder (it.geosolutions.geoserver.rest.encoder.GSLayerEncoder)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1