Search in sources :

Example 1 with RESTLayer

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

the class GeoServerClient method parseLayerList.

/**
 * Parses the layer list.
 *
 * @param reader the reader
 * @param existingWorkspaceList the existing workspace list
 * @param workspaceName the workspace name
 */
private void parseLayerList(GeoServerRESTReader reader, List<String> existingWorkspaceList, String workspaceName) {
    Thread t1 = new Thread(new Runnable() {

        public void run() {
            List<String> workspaceList = null;
            if (workspaceName == null) {
                workspaceList = existingWorkspaceList;
                // Add the default workspace last
                workspaceList.add(null);
            }
            Map<String, List<GeoServerLayer>> layerMap = new LinkedHashMap<String, List<GeoServerLayer>>();
            RESTLayerList layers = reader.getLayers();
            int count = 1;
            int total = layers.size();
            for (NameLinkElem featureTypeName : layers) {
                @SuppressWarnings("deprecation") RESTLayer layer = reader.getLayer(featureTypeName.getName());
                if (layer != null) {
                    String layerName = layer.getName();
                    String workspace = null;
                    for (String workspaceNameToTest : workspaceList) {
                        if (reader.existsLayer(workspaceNameToTest, layerName, true)) {
                            if (workspaceNameToTest == null) {
                                workspace = DEFAULT_WORKSPACE_NAME;
                            } else {
                                workspace = workspaceNameToTest;
                            }
                            break;
                        }
                    }
                    GeoServerLayer geoServerlayer = new GeoServerLayer();
                    geoServerlayer.setLayerWorkspace(workspace);
                    geoServerlayer.setLayerName(layerName);
                    geoServerlayer.setConnection(connection);
                    StyleWrapper styleWrapper = new StyleWrapper();
                    styleWrapper.setStyle(layer.getDefaultStyle());
                    String styleWorkspace = layer.getDefaultStyleWorkspace();
                    styleWrapper.setWorkspace((styleWorkspace == null) ? DEFAULT_WORKSPACE_NAME : styleWorkspace);
                    geoServerlayer.setStyle(styleWrapper);
                    List<GeoServerLayer> layerList = layerMap.get(workspace);
                    if (layerList == null) {
                        layerList = new ArrayList<GeoServerLayer>();
                        layerMap.put(workspace, layerList);
                    }
                    layerList.add(geoServerlayer);
                    if (parentObj != null) {
                        parentObj.readLayersProgress(connection, count, total);
                    }
                }
                count++;
            }
            if (parentObj != null) {
                parentObj.readLayersComplete(connection, layerMap);
            }
        }
    });
    t1.start();
}
Also used : GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) RESTLayer(it.geosolutions.geoserver.rest.decoder.RESTLayer) 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) RESTLayerList(it.geosolutions.geoserver.rest.decoder.RESTLayerList) NameLinkElem(it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 RESTLayer (it.geosolutions.geoserver.rest.decoder.RESTLayer)1 RESTLayerList (it.geosolutions.geoserver.rest.decoder.RESTLayerList)1 RESTStyleList (it.geosolutions.geoserver.rest.decoder.RESTStyleList)1 NameLinkElem (it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1