Skip to content

Commit

Permalink
Tests, notes for WCS 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdinando Villa committed May 16, 2023
1 parent 74fcb73 commit 9c0769f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public void setArguments(Map<String, Object> arguments) {
}
}

/*
* In addition to processing steps, it should have the fields for parameters, title, etc.
*/
public static class Process extends LinkedHashMap<String, ProcessNode> {
private static final long serialVersionUID = -7734440696956959927L;
}
Expand Down Expand Up @@ -115,9 +118,10 @@ public boolean validateProcess(Process process) {

public static void main(String[] args) {

Authorization authorization = new Authorization(Authentication.INSTANCE.getCredentials("https://openeo.vito.be"));
Authorization authorization = new Authorization(
Authentication.INSTANCE.getCredentials("https://openeo.vito.be/openeo/1.1.0"), "oidc/terrascope");

OpenEO openEO = new OpenEO("https://openeo.vito.be", authorization);
OpenEO openEO = new OpenEO("https://openeo.vito.be/openeo/1.1.0", authorization);
String processDefinition = "{\r\n" + " \"zumba\": {\r\n" + " \"process_id\": \"add\",\r\n"
+ " \"arguments\": {\"x\": 3, \"y\": 5},\r\n" + " \"result\": true\r\n" + " }\r\n" + "}";
Process process = JsonUtils.parseObject(processDefinition, Process.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,22 @@ public String getMessage() {
}
}

public static void main(String[] args) {

/*
* TODO: for 1.0, just get the layer names from the capabilities, then use describeCoverage
* on all at the beginning.
*/
WCSService service = new WCSService("https://www.geo.euskadi.eus/WCS_KARTOGRAFIA", Version.create("1.0.0"));
for (WCSLayer layer : service.getLayers()) {
System.out.println(layer);
// this fuck wants
// https://www.geo.euskadi.eus/geoeuskadi/services/U11/WCS_KARTOGRAFIA/MapServer/WCSServer?SERVICE=WCS&VERSION=1.0.0&REQUEST=DescribeCoverage&COVERAGE=1
layer.describeCoverage();
System.out.println(layer);
}
}

@SuppressWarnings("unchecked")
public WCSService(String serviceUrl, Version version) {

Expand All @@ -500,8 +516,14 @@ public WCSService(String serviceUrl, Version version) {

if (db == null) {

File dpath = Configuration.INSTANCE
.getDataPath("ogc/wcs/" + Klab.INSTANCE.getRootIdentity().getIdentityType().name().toLowerCase());
/*
* anonymous is for testing only
*/
String identity = Klab.INSTANCE.getRootIdentity() == null
? "anonymous"
: Klab.INSTANCE.getRootIdentity().getIdentityType().name().toLowerCase();

File dpath = Configuration.INSTANCE.getDataPath("ogc/wcs/" + identity);
dpath.mkdirs();

db = DBMaker.fileDB(new File(dpath + File.separator + "wcscache.dat")).closeOnJvmShutdown().transactionEnable()
Expand Down Expand Up @@ -554,38 +576,49 @@ public WCSService(String serviceUrl, Version version) {
String content = IOUtils.toString(input, StandardCharsets.UTF_8);
Map<?, ?> capabilitiesType = (Map<?, ?>) U.fromXmlMap(content);

// JXPathContext context = JXPathContext.newContext(capabilitiesType);
// System.out.println(MapUtils.dump(capabilitiesType) + "");
for (Object o : MapUtils.get(capabilitiesType, "wcs:Capabilities/wcs:Contents/wcs:CoverageSummary",
Collection.class)) {
Map<String, Object> item = (Map<String, Object>) o;
Object name = item.get(version.getMajor() >= 2 ? COVERAGE_ID : IDENTIFIER);
if (name != null) {
identifiers.add(name.toString());
if (version.getMajor() == 1) {

/*
* TODO get the POS array at CoverageOfferingBrief, then use describeCoverage on
* each new layer. ArcShit will have NUMBERS as layer IDs, with just labels and
* envelope (projection in srsName).
*/

} else {

// JXPathContext context = JXPathContext.newContext(capabilitiesType);
// System.out.println(MapUtils.dump(capabilitiesType) + "");
for (Object o : MapUtils.get(capabilitiesType, "wcs:Capabilities/wcs:Contents/wcs:CoverageSummary",
Collection.class)) {
Map<String, Object> item = (Map<String, Object>) o;
Object name = item.get(version.getMajor() >= 2 ? COVERAGE_ID : IDENTIFIER);
if (name != null) {
identifiers.add(name.toString());
}
}
}

for (Object o : MapUtils.get(capabilitiesType, "wcs:Capabilities/wcs:Contents/wcs:CoverageSummary",
Collection.class)) {
for (Object o : MapUtils.get(capabilitiesType, "wcs:Capabilities/wcs:Contents/wcs:CoverageSummary",
Collection.class)) {

Map<String, Object> item = (Map<String, Object>) o;
Map<String, Object> item = (Map<String, Object>) o;

Object name = item.get(version.getMajor() >= 2 ? COVERAGE_ID : IDENTIFIER);
Object bbox = item.get(WGS84_BOUNDING_BOX);
Object name = item.get(version.getMajor() >= 2 ? COVERAGE_ID : IDENTIFIER);
Object bbox = item.get(WGS84_BOUNDING_BOX);

if (name instanceof String && bbox instanceof Map) {
if (name instanceof String && bbox instanceof Map) {

WCSLayer layer = new WCSLayer(skipRefresh);
WCSLayer layer = new WCSLayer(skipRefresh);

layer.name = name.toString();
double[] upperCorner = NumberUtils.doubleArrayFromString(((Map<?, ?>) bbox).get(UPPER_CORNER).toString(),
"\\s+");
double[] lowerCorner = NumberUtils.doubleArrayFromString(((Map<?, ?>) bbox).get(LOWER_CORNER).toString(),
"\\s+");
layer.wgs84envelope = Envelope.create(lowerCorner[0], upperCorner[0], lowerCorner[1], upperCorner[1],
Projection.getLatLon());
layer.name = name.toString();
double[] upperCorner = NumberUtils
.doubleArrayFromString(((Map<?, ?>) bbox).get(UPPER_CORNER).toString(), "\\s+");
double[] lowerCorner = NumberUtils
.doubleArrayFromString(((Map<?, ?>) bbox).get(LOWER_CORNER).toString(), "\\s+");
layer.wgs84envelope = Envelope.create(lowerCorner[0], upperCorner[0], lowerCorner[1], upperCorner[1],
Projection.getLatLon());

layers.put(layer.name, layer);
layers.put(layer.name, layer);
}
}
}
} catch (IOException e) {
Expand Down Expand Up @@ -648,9 +681,7 @@ public URL buildRetrieveUrl(WCSLayer layer, Version version, IGeometry geometry,

s = serviceUrl + "?service=WCS&version=" + version + "&request=GetCoverage&coverage="
+ layer.getRequestIdentifier() + "&bbox=" + west + "," + south + "," + east + "," + north + "&crs="
+ crs.getSimpleSRS()
+ "&responseCRS=" + crs.getSimpleSRS()
+ "&width=" + xc + "&height=" + yc
+ crs.getSimpleSRS() + "&responseCRS=" + crs.getSimpleSRS() + "&width=" + xc + "&height=" + yc
+ "&format=" + "GeoTIFF";

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.integratedmodelling.klab.Authentication;
import org.integratedmodelling.klab.exceptions.KlabAuthorizationException;
import org.integratedmodelling.klab.exceptions.KlabIOException;
import org.integratedmodelling.klab.exceptions.KlabIllegalArgumentException;
import org.integratedmodelling.klab.rest.ExternalAuthenticationCredentials;

import kong.unirest.HttpResponse;
Expand All @@ -31,13 +32,30 @@ public class Authorization {
private String prefix;
private String tokenType;

/**
* Create a new authorization. {@link #isOnline()} should be called after creation.
*
* @param credentials
* @param prefix prepended to the auth token returned by {@link #getAuthorization()}. Normally
* used for OpenID providers that need the authentication method and the provider (e.g.
* oidc/provider).
*/
public Authorization(ExternalAuthenticationCredentials credentials, String prefix) {
this(credentials);
this.prefix = prefix;
}

/**
* Create a new authorization. {@link #isOnline()} should be called after creation.
*
* @param credentials
*/
public Authorization(ExternalAuthenticationCredentials credentials) {

if (credentials == null) {
throw new KlabIllegalArgumentException("attempted authorization with null credentials");
}

this.credentials = credentials;

if ("basic".equals(credentials.getScheme())) {
Expand All @@ -50,7 +68,17 @@ public Authorization(ExternalAuthenticationCredentials credentials) {
}
}

/**
* Check if the last authentication attempt went well.
*
* @return
*/
public boolean isOnline() {
return token != null;
}

private void refreshToken() {

/*
* authenticate and get the first token. Credentials should contain: 0. Auth endpoint 1.
* grant type 2. client ID 3. client secret 4. scope
Expand Down Expand Up @@ -87,7 +115,18 @@ private void refreshToken() {
}

/**
* Return the authorization token for the Authorization: header.
* The raw authorization token with no auth method or prefix. May be null if {@link #isOnline()}
* returns false.
*
* @return
*/
public String getToken() {
return this.token;
}

/**
* Return the authorization token for the Authorization: header. Includes the auth method (e.g.
* Basic, Bearer) and any prefix passed at construction.
*
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package org.integratedmodelling.klab.cli.commands;

import java.util.List;

import org.integratedmodelling.kim.api.IKimConcept;
import org.integratedmodelling.kim.api.IServiceCall;
import org.integratedmodelling.klab.Klab;
import org.integratedmodelling.klab.api.auth.IIdentity;
import org.integratedmodelling.klab.api.cli.ICommand;
import org.integratedmodelling.klab.api.data.general.IExpression.CompilerScope;
import org.integratedmodelling.klab.api.runtime.ISession;
import org.integratedmodelling.klab.engine.runtime.code.ExpressionScope;
import org.integratedmodelling.klab.engine.runtime.expressions.GroovyProcessor;
import org.integratedmodelling.klab.utils.Parameters;
import org.integratedmodelling.klab.utils.StringUtils;

public class Test implements ICommand {

Expand Down

0 comments on commit 9c0769f

Please sign in to comment.