Search in sources :

Example 36 with StyleWrapper

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

Example 37 with StyleWrapper

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

the class GeoServerClient method parseStyleInWorkspace.

/**
 * Parses the style in workspace.
 *
 * @param reader the reader
 * @param styleMap the style map
 * @param count the count
 * @param workspaceName the workspace name
 * @return the int
 */
private int parseStyleInWorkspace(GeoServerRESTReader reader, Map<String, List<StyleWrapper>> styleMap, int count, String workspaceName) {
    List<StyleWrapper> styleList;
    if (workspaceName != null) {
        RESTStyleList geoServerWorkspaceStyleList = reader.getStyles(workspaceName);
        styleList = new ArrayList<StyleWrapper>();
        for (String style : geoServerWorkspaceStyleList.getNames()) {
            StyleWrapper newStyleWrapper = new StyleWrapper(workspaceName, style);
            styleList.add(newStyleWrapper);
            if (parentObj != null) {
                parentObj.readStylesProgress(connection, count, count);
            }
            count++;
        }
        styleMap.put(workspaceName, styleList);
    }
    return count;
}
Also used : StyleWrapper(com.sldeditor.common.data.StyleWrapper) RESTStyleList(it.geosolutions.geoserver.rest.decoder.RESTStyleList)

Example 38 with StyleWrapper

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

the class GeoServerInput method copyNodes.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#drop(com.sldeditor.extension.input.NodeInterface, java.util.Map)
     */
@Override
public boolean copyNodes(NodeInterface destinationTreeNode, Map<NodeInterface, List<SLDDataInterface>> droppedDataMap) {
    if (droppedDataMap == null) {
        return false;
    }
    if (destinationTreeNode instanceof GeoServerWorkspaceNode) {
        GeoServerWorkspaceNode workspaceNode = (GeoServerWorkspaceNode) destinationTreeNode;
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(workspaceNode.getConnection());
        if (client == null) {
            return false;
        } else {
            for (NodeInterface key : droppedDataMap.keySet()) {
                for (SLDDataInterface sldData : droppedDataMap.get(key)) {
                    StyleWrapper styleWrapper = sldData.getStyle();
                    removeStyleFileExtension(styleWrapper);
                    styleWrapper.setWorkspace(workspaceNode.getWorkspaceName());
                    client.uploadSLD(styleWrapper, sldData.getSld());
                }
            }
            client.refreshWorkspace(workspaceNode.getWorkspaceName());
        }
        return true;
    }
    return false;
}
Also used : GeoServerClientInterface(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClientInterface) GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) NodeInterface(com.sldeditor.common.NodeInterface)

Example 39 with StyleWrapper

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

the class StyleWrapperTest method test.

@Test
public void test() {
    StyleWrapper styleWrapper = new StyleWrapper();
    assertNull(styleWrapper.getStyle());
    assertNull(styleWrapper.getWorkspace());
    String expectedStyle = "test style";
    styleWrapper.setStyle(expectedStyle);
    assertEquals(styleWrapper.getStyle().compareTo(expectedStyle), 0);
    String expectedWorkspace = "test workspace";
    styleWrapper.setWorkspace(expectedWorkspace);
    assertEquals(styleWrapper.getWorkspace().compareTo(expectedWorkspace), 0);
    // Clone
    StyleWrapper clone = styleWrapper.clone();
    assertTrue(styleWrapper.compareTo(null) != 0);
    assertTrue(styleWrapper.compareTo(clone) == 0);
}
Also used : StyleWrapper(com.sldeditor.common.data.StyleWrapper) Test(org.junit.Test)

Example 40 with StyleWrapper

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

the class GeoServerLayerTest method testGetStyleString.

/**
 * Test method for {@link com.sldeditor.common.data.GeoServerLayer#getStyleString()}.
 * Test method for {@link com.sldeditor.common.data.GeoServerLayer#setDefaultWorkspaceName(java.lang.String)}.
 */
@Test
public void testGetStyleString() {
    GeoServerLayer.setDefaultWorkspaceName(null);
    StyleWrapper styleWrapper = new StyleWrapper();
    String style = "style";
    styleWrapper.setStyle(style);
    String workspace = "workspace";
    styleWrapper.setWorkspace(workspace);
    GeoServerLayer layer = new GeoServerLayer();
    layer.setStyle(styleWrapper);
    String styleString = layer.getStyleString();
    assertTrue(style.compareTo(styleString) == 0);
    String defaultWorkspaceName = "Default workspace";
    styleWrapper.setWorkspace(defaultWorkspaceName);
    layer.setStyle(styleWrapper);
    GeoServerLayer.setDefaultWorkspaceName(defaultWorkspaceName);
    String styleString2 = layer.getStyleString();
    assertTrue(style.compareTo(styleString2) == 0);
    styleWrapper.setWorkspace(workspace);
    layer.setStyle(styleWrapper);
    String styleString3 = layer.getStyleString();
    assertEquals(styleString3.compareTo(workspace + ":" + style), 0);
}
Also used : GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Test(org.junit.Test)

Aggregations

StyleWrapper (com.sldeditor.common.data.StyleWrapper)59 SLDData (com.sldeditor.common.data.SLDData)35 Test (org.junit.Test)31 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)15 File (java.io.File)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 ArrayList (java.util.ArrayList)12 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)10 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)9 List (java.util.List)9 GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)8 IOException (java.io.IOException)8 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)7 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 GeoServerStyleNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5 HashMap (java.util.HashMap)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)4 NamedLayer (org.geotools.styling.NamedLayer)4