Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra funtionality used by PDOK geoserver workspace builder #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ nb*.xml

./target
target

/.idea
*.iml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
import it.geosolutions.geoserver.rest.encoder.service.GSServiceSettingsEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager.ConfigureCoveragesOption;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStyleManager;
Expand Down Expand Up @@ -3145,4 +3146,130 @@ private static void checkString(String string) {

}

public boolean publishServiceLayer(final String workspace, final String servicetype, final GSServiceSettingsEncoder serviceEncoder) {

if (workspace == null) {
throw new IllegalArgumentException("Null argument");
}
// TODO: check this usecase, layer should always be defined
if (workspace.isEmpty()) {
throw new IllegalArgumentException("Empty argument");
}

// rest/services/w[mfc]s/workspaces/schelpdierwater/settings.xml
final String url = restURL + "/rest/services/" + servicetype + "/workspaces/" + workspace + "/settings.xml";

String settingsXml = serviceEncoder.toString();
LOGGER.debug("URL: " + url);
LOGGER.debug("BODY: " + settingsXml);

String sendResult = HTTPUtils.putXml(url, settingsXml, gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info( servicetype.toUpperCase() + "Service successfully configured: " + workspace);
}
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Error configuring " + servicetype.toUpperCase() + " Servic " + workspace + " (" + sendResult + ")");
}

return sendResult != null;
}

public boolean publishWmsServiceLayer(final String workspace, final GSServiceSettingsEncoder serviceEncoder) {

if (workspace == null) {
throw new IllegalArgumentException("Null argument");
}
// TODO: check this usecase, layer should always be defined
if (workspace.isEmpty()) {
throw new IllegalArgumentException("Empty argument");
}

// rest/services/wms/workspaces/schelpdierwater/settings.xml
final String url = restURL + "/rest/services/wms/workspaces/" + workspace + "/settings.xml";

String settingsXml = serviceEncoder.toString();
LOGGER.debug("URL: " + url);
LOGGER.debug("BODY: " + settingsXml);

String sendResult = HTTPUtils.putXml(url, settingsXml, gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("WMS Service successfully configured: " + workspace);
}
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Error configuring WMS Servic " + workspace + " (" + sendResult + ")");
}

return sendResult != null;
}

public boolean publishWfsServiceLayer(final String workspace, final GSServiceSettingsEncoder serviceEncoder) {

if (workspace == null) {
throw new IllegalArgumentException("Null argument");
}
// TODO: check this usecase, layer should always be defined
if (workspace.isEmpty()) {
throw new IllegalArgumentException("Empty argument");
}

// rest/services/wms/workspaces/schelpdierwater/settings.xml
final String url = restURL + "/rest/services/wfs/workspaces/" + workspace + "/settings.xml";

String settingsXml = serviceEncoder.toString();
LOGGER.debug("URL: " + url);
LOGGER.debug("BODY: " + settingsXml);

String sendResult = HTTPUtils.putXml(url, settingsXml, gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("WFS Service successfully configured: " + workspace);
}
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Error configuring WFS Service " + workspace + " (" + sendResult + ")");
}

return sendResult != null;
}
public boolean publishMosaicLayer(final String workspace, final String storename, final GSCoverageEncoder cove, final GSLayerEncoder layerEncoder) {
String ftypeXml = cove.toString();
StringBuilder postUrl = new StringBuilder(restURL).append("/rest/workspaces/").append(workspace).append("/coveragestores/").append(storename).append("/coverages.xml");

final String layername = cove.getNativeName();

LOGGER.info("URL: " + postUrl.toString());
LOGGER.info("BODY: " + ftypeXml);

String configuredResult = HTTPUtils.postXml(postUrl.toString(), ftypeXml, this.gsuser, this.gspass);
boolean published = configuredResult != null;
boolean configured = false;

if (!published) {
LOGGER.warn("Error in publishing (" + configuredResult + ") " + workspace + ":" + storename + "/" + layername);
} else {
LOGGER.info("Mosaic layer successfully added (layer:" + layername + ")");

if (layerEncoder == null) {
if (LOGGER.isErrorEnabled())
LOGGER.error("GSLayerEncoder is null: Unable to find the defaultStyle for this layer");
return false;
}

configured = configureLayer(workspace, layername, layerEncoder);

if (!configured) {
LOGGER.warn("Error in configuring (" + configuredResult + ") " + workspace + ":" + storename + "/" + layername);
} else {
LOGGER.info("DB layer successfully configured (layer:" + layername + ")");
}
}

return published && configured;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,22 @@ public RESTFeatureTypeList getFeatureTypes(String workspace) {
return RESTFeatureTypeList.build(load(url));
}

public RESTFeatureTypeList getFeatureTypes(String workspace, String list) {
String url = "/rest/workspaces/" + workspace + "/featuretypes.xml?list=" + list;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving featuretypes from " + url);
}
return RESTFeatureTypeList.build(load(url));
}

public RESTCoverageList getCoverageNames(String workspace, String coveragestorename, String list) {
String url = "/rest/workspaces/" + workspace + "/coveragestores/" + coveragestorename + "/coverages.xml?list=" + list;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving coveragenames from " + url);
}
return RESTCoverageList.build(load(url));
}

/**
* Get detailed info about a given Layer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@
* @author ETj (etj at geo-solutions.it)
*/
public class NameLinkElem {
private final Element elem;
private final Element elem;

public NameLinkElem(Element elem) {
public NameLinkElem(Element elem) {
this.elem = elem;
}

public String getName() {
return elem.getChildText("name");
}
public String getName() {
return elem.getChildText("name");
}

public String getValue() {

return elem.getContent(0).getValue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@ public void addStyle(String style) {
stylesEncoder.addContent(el);
}

/**
*
* @param styleName
* @param workspaceName
*/
public void addStyle(String styleName, String workspaceName) {
final Element el = new Element("style");

Element name = new Element("name");
Element workspace = new Element("workspace");

name.setText(styleName);
workspace.setText(workspaceName);

el.addContent(name);
el.addContent(workspace);

stylesEncoder.addContent(el);
}

/**
* delete a style from the list of available styles
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ public void addLayer(String layer, String styleName) {
style.addContent(elem("name", styleName));
}
}

public void addLayer(String layer, String styleName, String styleWorkspace) {
initPublishables("publishables");

publishablesElem.addContent(
new Element("published").setAttribute("type", "layer").addContent(
elem("name", layer)));

Element style = new Element("style");
stylesElem.addContent(style);
if (styleName != null) {
style.addContent(elem("name", styleName));
style.addContent(elem("workspace", styleWorkspace));
}
}

public void addLayerGroup(String group) {
initPublishables("publishables");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,26 @@ public String getNativeCoverageName() {
return null;
}

public void addRequestSRS(String[] requestsrslist) {

Element requestsrs = new Element("requestSRS");

for (String request : requestsrslist) {
new Element("requestSRS").addContent(new Element("string").setText(request));
}

addContent(requestsrs);
}

public void addResponseSRS(String[] responsesrslist) {

Element responsesrs = new Element("responseSRS");

for (String response : responsesrslist) {
responsesrs.addContent(new Element("string").setText(response));
}

addContent(responsesrs);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.datastore;

import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;

import java.net.URL;

/**
* Encoder for a {@value #TYPE} datastore.
*
* @author Peter van de Riet
*/
public class GSGeoTIFFDatastoreEncoder extends GSAbstractStoreEncoder {
static final String TYPE = "GeoTIFF";

public GSGeoTIFFDatastoreEncoder(String name) {
super(StoreType.COVERAGESTORES, name);
setName(name);

// Set mandatory parameter
setType(TYPE);
add("enabled", "true");
}

public void setUrl(URL url) {
add("url", url.toString());
}
/**
* @return {@value #TYPE}
*/
protected String getValidType() {
return TYPE;
}

public void setWorkspaceName(String workspaceName) {
GsWorkspaceElement workspaceXml = new GsWorkspaceElement(workspaceName);
addContent(workspaceXml.getRoot());
}

private class GsWorkspaceElement extends XmlElement {
public GsWorkspaceElement(String workspaceName) {
super("workspace");
add("name", workspaceName);
}
}
}
Loading