diff --git a/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/openeo/OpenEO.java b/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/openeo/OpenEO.java index ab3087ea9c..b1abb85059 100644 --- a/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/openeo/OpenEO.java +++ b/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/openeo/OpenEO.java @@ -59,6 +59,9 @@ public void setArguments(Map arguments) { } } + /* + * In addition to processing steps, it should have the fields for parameters, title, etc. + */ public static class Process extends LinkedHashMap { private static final long serialVersionUID = -7734440696956959927L; } @@ -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); diff --git a/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/raster/wcs/WCSService.java b/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/raster/wcs/WCSService.java index 8d3da8a98f..dd3cc263a9 100644 --- a/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/raster/wcs/WCSService.java +++ b/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/raster/wcs/WCSService.java @@ -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) { @@ -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() @@ -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 item = (Map) 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 item = (Map) 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 item = (Map) o; + Map item = (Map) 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) { @@ -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 { diff --git a/klab.engine/src/main/java/org/integratedmodelling/klab/auth/Authorization.java b/klab.engine/src/main/java/org/integratedmodelling/klab/auth/Authorization.java index 42990ad974..54d392b329 100644 --- a/klab.engine/src/main/java/org/integratedmodelling/klab/auth/Authorization.java +++ b/klab.engine/src/main/java/org/integratedmodelling/klab/auth/Authorization.java @@ -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; @@ -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())) { @@ -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 @@ -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 */ diff --git a/klab.engine/src/main/java/org/integratedmodelling/klab/cli/commands/Test.java b/klab.engine/src/main/java/org/integratedmodelling/klab/cli/commands/Test.java index e446c96bb8..945bab84bf 100644 --- a/klab.engine/src/main/java/org/integratedmodelling/klab/cli/commands/Test.java +++ b/klab.engine/src/main/java/org/integratedmodelling/klab/cli/commands/Test.java @@ -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 {