Search in sources :

Example 1 with GeoServerLayer

use of com.sldeditor.common.data.GeoServerLayer 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)

Example 2 with GeoServerLayer

use of com.sldeditor.common.data.GeoServerLayer in project sldeditor by robward-scisys.

the class GeoServerLayerUpdateTool method extractWorkspaceLayers.

private void extractWorkspaceLayers(GeoServerWorkspaceNode workspaceNode) {
    for (int layerIndex = 0; layerIndex < workspaceNode.getChildCount(); layerIndex++) {
        TreeNode childTreeNode = workspaceNode.getChildAt(layerIndex);
        if (childTreeNode instanceof GeoServerLayerNode) {
            GeoServerLayerNode layerNode = (GeoServerLayerNode) childTreeNode;
            GeoServerLayer layer = layerNode.getLayer();
            layerList.add(layer);
        }
    }
}
Also used : GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) TreeNode(javax.swing.tree.TreeNode) GeoServerLayerNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerLayerNode)

Example 3 with GeoServerLayer

use of com.sldeditor.common.data.GeoServerLayer in project sldeditor by robward-scisys.

the class GeoServerLayerTest method testGetStyle.

/**
 * Test method for {@link com.sldeditor.common.data.GeoServerLayer#getStyle()}.
 * Test method for {@link com.sldeditor.common.data.GeoServerLayer#setStyle(com.sldeditor.common.data.StyleWrapper)}.
 */
@Test
public void testGetStyle() {
    StyleWrapper styleWrapper = new StyleWrapper();
    styleWrapper.setStyle("style");
    styleWrapper.setStyle("workspace");
    GeoServerLayer layer = new GeoServerLayer();
    layer.setStyle(styleWrapper);
    assertEquals(styleWrapper, layer.getStyle());
}
Also used : GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Test(org.junit.Test)

Example 4 with GeoServerLayer

use of com.sldeditor.common.data.GeoServerLayer in project sldeditor by robward-scisys.

the class GeoServerInputTest method testGetStyleMap.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerInput#getStyleMap(com.sldeditor.common.data.GeoServerConnection)}.
 */
@Test
public void testGetStyleMap() {
    GeoServerInput input = new GeoServerInput(null);
    GeoServerInput.overrideGeoServerClientClass(DummyGeoServerClient.class);
    // Add some GeoServer connections
    GeoServerConnection connection1 = new GeoServerConnection();
    connection1.setConnectionName("test connection 1");
    input.addNewConnection(connection1);
    GeoServerConnection connection2 = new GeoServerConnection();
    connection2.setConnectionName("test connection 2");
    input.addNewConnection(connection2);
    // Try a null objects
    Map<String, List<StyleWrapper>> actualStyleMap = input.getStyleMap(null);
    assertNull(actualStyleMap);
    actualStyleMap = input.getStyleMap(connection2);
    assertNull(actualStyleMap);
    Map<String, List<StyleWrapper>> expectedStyleMap = new HashMap<String, List<StyleWrapper>>();
    // CHECKSTYLE:OFF
    StyleWrapper[] styleWrappers = { new StyleWrapper("workspace", "style1"), new StyleWrapper("workspace", "style2") };
    // CHECKSTYLE:ON
    expectedStyleMap.put("style1", Arrays.asList(styleWrappers));
    Map<String, List<GeoServerLayer>> expectedLayerMap = new HashMap<String, List<GeoServerLayer>>();
    // CHECKSTYLE:OFF
    GeoServerLayer[] geoServerLayers = { new GeoServerLayer("workspace", "style1"), new GeoServerLayer("workspace", "style2") };
    // CHECKSTYLE:ON
    expectedLayerMap.put("style1", Arrays.asList(geoServerLayers));
    input.populateComplete(connection1, expectedStyleMap, expectedLayerMap);
    actualStyleMap = input.getStyleMap(connection1);
    assertEquals(expectedStyleMap, actualStyleMap);
}
Also used : GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) HashMap(java.util.HashMap) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ArrayList(java.util.ArrayList) List(java.util.List) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 5 with GeoServerLayer

use of com.sldeditor.common.data.GeoServerLayer in project sldeditor by robward-scisys.

the class GeoServerReadProgressTest method testGeoServerReadProgress.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgress#GeoServerReadProgress(com.sldeditor.common.filesystem.FileSystemInterface, com.sldeditor.extension.filesystem.geoserver.GeoServerParseCompleteInterface)}.
 */
@Test
public void testGeoServerReadProgress() {
    DummyProgressComplete complete = new DummyProgressComplete();
    GeoServerReadProgress progress = new GeoServerReadProgress(null, complete);
    GeoServerOverallNode geoServerRootNode = new GeoServerOverallNode(null);
    GeoServerConnection connection = new GeoServerConnection();
    connection.setConnectionName("test connection 1");
    GeoServerNode node = new GeoServerNode(null, connection);
    geoServerRootNode.add(node);
    progress.addNewConnectionNode(connection, node);
    progress.startPopulating(null);
    progress.startPopulating(connection);
    progress.readLayersProgress(null, 0, 0);
    assertFalse(complete.completed);
    progress.readLayersProgress(connection, 0, 5);
    progress.readLayersProgress(connection, 1, 5);
    progress.readLayersProgress(connection, 2, 5);
    progress.readLayersProgress(connection, 3, 5);
    progress.readLayersProgress(connection, 4, 5);
    progress.readLayersProgress(connection, 5, 5);
    assertFalse(complete.completed);
    progress.readLayersProgress(connection, 6, 5);
    assertFalse(complete.completed);
    progress.readStylesProgress(null, 0, 0);
    progress.readStylesProgress(connection, 0, 3);
    progress.readStylesProgress(connection, 1, 3);
    progress.readStylesProgress(connection, 2, 3);
    progress.readStylesProgress(connection, 3, 3);
    progress.readStylesProgress(connection, 4, 3);
    assertFalse(complete.completed);
    Map<String, List<GeoServerLayer>> completedLayersMap = new HashMap<String, List<GeoServerLayer>>();
    Map<String, List<StyleWrapper>> completedStyleMap = new HashMap<String, List<StyleWrapper>>();
    progress.readLayersComplete(connection, completedLayersMap);
    progress.readStylesComplete(connection, completedStyleMap, false);
    assertTrue(complete.completed);
}
Also used : GeoServerOverallNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerOverallNode) GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) HashMap(java.util.HashMap) StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerNode) List(java.util.List) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) GeoServerReadProgress(com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgress) Test(org.junit.Test)

Aggregations

GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)18 Test (org.junit.Test)11 StyleWrapper (com.sldeditor.common.data.StyleWrapper)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)5 List (java.util.List)5 GeoServerLayerNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerLayerNode)4 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)3 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 GeoServerLayerHeadingNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerLayerHeadingNode)2 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)2 TreeNode (javax.swing.tree.TreeNode)2 NodeInterface (com.sldeditor.common.NodeInterface)1 FileSystemInterface (com.sldeditor.common.filesystem.FileSystemInterface)1 GeoServerNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerNode)1 GeoServerOverallNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerOverallNode)1 GeoServerReadProgress (com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgress)1 RESTLayer (it.geosolutions.geoserver.rest.decoder.RESTLayer)1 RESTLayerList (it.geosolutions.geoserver.rest.decoder.RESTLayerList)1