Java Code Examples for it.geosolutions.geoserver.rest.GeoServerRESTReader#getLayers()

The following examples show how to use it.geosolutions.geoserver.rest.GeoServerRESTReader#getLayers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoServerClient.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses the layer list worker.
 *
 * @param reader the reader
 * @param existingWorkspaceList the existing workspace list
 * @param workspaceName the workspace name
 */
private void parseLayerListWorker(
        GeoServerRESTReader reader, List<String> existingWorkspaceList, String workspaceName) {
    List<String> localWorkspaceList = null;

    if (workspaceName == null) {
        localWorkspaceList = existingWorkspaceList;
        localWorkspaceList.add(null); // Add the default workspace last
    }

    Map<String, List<GeoServerLayer>> layerMap = new LinkedHashMap<>();
    RESTLayerList layers = reader.getLayers();

    parseLayer(reader, localWorkspaceList, layerMap, layers);

    if (parentObj != null) {
        parentObj.readLayersComplete(connection, layerMap);
    }
}
 
Example 2
Source File: LayerCommands.java    From geoserver-shell with MIT License 5 votes vote down vote up
@CliCommand(value = "layer list", help = "List layers.")
public String list() throws Exception {
    GeoServerRESTReader reader = new GeoServerRESTReader(geoserver.getUrl(), geoserver.getUser(), geoserver.getPassword());
    RESTLayerList layers = reader.getLayers();
    List<String> names = layers.getNames();
    Collections.sort(names);
    StringBuilder builder = new StringBuilder();
    for (String name : names) {
        builder.append(name + OsUtils.LINE_SEPARATOR);
    }
    return builder.toString();
}
 
Example 3
Source File: WorkspacesManagerServiceImpl.java    From geofence with GNU General Public License v2.0 4 votes vote down vote up
public PagingLoadResult<Layer> getLayers(int offset, int limit, String baseURL,
        GSInstanceModel gsInstance, String workspace, String service) throws ApplicationException
    {

        List<Layer> layersListDTO = new ArrayList<Layer>();
        layersListDTO.add(new Layer("*"));

        if ((baseURL != null) &&
                !baseURL.equals("*") &&
                !baseURL.contains("?") &&
                (workspace != null) &&
                (workspace.length() > 0))
        {
            try
            {
                GeoServerRESTReader gsreader = new GeoServerRESTReader(baseURL, gsInstance.getUsername(), gsInstance.getPassword());

                if (workspace.equals("*") && workspaceConfigOpts.isShowDefaultGroups() && service.equals("WMS"))
                {
                    RESTAbstractList<NameLinkElem> layerGroups = gsreader.getLayerGroups();

                    if ((layerGroups != null)) {
                        for (NameLinkElem lg : layerGroups) {
//                            RESTLayerGroup group = gsreader.getLayerGroup(lg.getName());
//                            if (group != null)
//                            {
//                                layersListDTO.add(new Layer(group.getName()));
//                            }
                            layersListDTO.add(new Layer(lg.getName()));
                        }
                    }
                }
                else
                {
                    SortedSet<String> sortedLayerNames = new TreeSet<String>();

                    if (workspace.equals("*")) { // load all layers
                        RESTAbstractList<NameLinkElem> layers = gsreader.getLayers();
                    	if (layers != null)
                    		for (NameLinkElem layerLink : layers) {
                    			sortedLayerNames.add(layerLink.getName());
                    		}
                    } else {

                        if(StringUtils.isBlank(workspace))
                            throw new ApplicationException("A workspace name is needed");

                        sortedLayerNames = getWorkspaceLayers(gsreader, workspace);
                    }
                    // return the sorted layers list
                    for (String layerName : sortedLayerNames) {
                        layersListDTO.add(new Layer(layerName));
                    }
                }
            } catch (MalformedURLException e) {
                logger.error(e.getLocalizedMessage(), e);
                throw new ApplicationException(e.getLocalizedMessage(), e);
            }
        }

        return new RpcPageLoadResult<Layer>(layersListDTO, 0, layersListDTO.size());
    }