Skip to content

Commit

Permalink
Use stac-migrate to update STAC Items and Collections to the latest v…
Browse files Browse the repository at this point in the history
…ersion #42
  • Loading branch information
m-mohr committed Mar 11, 2021
1 parent c309a9d commit ae642b4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added new method `listCollectionItems` for searching and retrieving Items from `GET /collections/{collectionId}/items`.

### Changed

- Methods returning STAC (e.g. `listCollections`, `describeCollection`, `getResultAsStac`, `listCollectionItems`) always return the data compliant to the latest STAC version (currently 1.0.0-rc.1).

## [1.1.0] - 2021-02-18

### Added
Expand Down
10 changes: 10 additions & 0 deletions openeo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ declare module OpenEO {
stopJob(): Promise<Job>;
/**
* Retrieves the STAC Item produced for the job results.
*
* The Item returned always complies to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @returns {Promise<object.<string, *>>} The JSON-based response compatible to the API specification, but also including a `costs` property if present in the headers.
Expand All @@ -840,6 +842,8 @@ declare module OpenEO {
getResultsAsItem(): Promise<any>;
/**
* Retrieves the STAC Item or Collection produced for the job results.
*
* The Item or Collection returned always complies to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @returns {Promise<object.<string, *>>} The JSON-based response compatible to the API specification, but also including a `costs` property if present in the headers.
Expand Down Expand Up @@ -1696,6 +1700,8 @@ declare module OpenEO {
listUdfRuntimes(): Promise<any>;
/**
* List all collections available on the back-end.
*
* The collections returned always comply to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @returns {Promise<Collections>} A response compatible to the API specification.
Expand All @@ -1704,6 +1710,8 @@ declare module OpenEO {
listCollections(): Promise<Collections>;
/**
* Get further information about a single collection.
*
* The collection returned always complies to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @param {string} collectionId - Collection ID to request further metadata for.
Expand All @@ -1714,6 +1722,8 @@ declare module OpenEO {
/**
* Loads items for a specific image collection.
* May not be available for all collections.
*
* The items returned always comply to the latest STAC version (currently 1.0.0-rc.1).
*
* This is an experimental API and is subject to change.
*
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
},
"dependencies": {
"@openeo/js-commons": "^1.2.0",
"@radiantearth/stac-migrate": "^1.0.0-rc.1",
"axios": "^0.21.1",
"oidc-client": "^1.11.5"
},
Expand Down
15 changes: 14 additions & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Environment = require('./env');
const Utils = require('@openeo/js-commons/src/utils');
const axios = require('axios').default;
const StacMigrate = require('@radiantearth/stac-migrate');

const AuthProvider = require('./authprovider');
const BasicProvider = require('./basicprovider');
Expand Down Expand Up @@ -115,32 +116,41 @@ class Connection {
/**
* List all collections available on the back-end.
*
* The collections returned always comply to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @returns {Promise<Collections>} A response compatible to the API specification.
* @throws {Error}
*/
async listCollections() {
let response = await this._get('/collections');
if (Utils.isObject(response.data) && Array.isArray(response.data.collections)) {
response.data.collections = response.data.collections.map(collection => StacMigrate.collection(collection));
}
return response.data;
}

/**
* Get further information about a single collection.
*
* The collection returned always complies to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @param {string} collectionId - Collection ID to request further metadata for.
* @returns {Promise<Collection>} - A response compatible to the API specification.
* @throws {Error}
*/
async describeCollection(collectionId) {
let response = await this._get('/collections/' + collectionId);
return response.data;
return StacMigrate.collection(response.data);
}

/**
* Loads items for a specific image collection.
* May not be available for all collections.
*
* The items returned always comply to the latest STAC version (currently 1.0.0-rc.1).
*
* This is an experimental API and is subject to change.
*
* @async
Expand Down Expand Up @@ -186,6 +196,9 @@ class Connection {
}

let response = await this._get(nextUrl, params);
if (Utils.isObject(response.data) && Array.isArray(response.data.features)) {
response.data.features = response.data.features.map(item => StacMigrate.item(item));
}
yield response.data;

page++;
Expand Down
12 changes: 7 additions & 5 deletions src/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Environment = require('./env');
const BaseEntity = require('./baseentity');
const Logs = require('./logs');
const Utils = require('@openeo/js-commons/src/utils');
const StacMigrate = require('@radiantearth/stac-migrate');

const STOP_STATUS = ['finished', 'canceled', 'error'];

Expand Down Expand Up @@ -256,6 +257,8 @@ class Job extends BaseEntity {
/**
* Retrieves the STAC Item produced for the job results.
*
* The Item returned always complies to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @returns {Promise<object.<string, *>>} The JSON-based response compatible to the API specification, but also including a `costs` property if present in the headers.
* @throws {Error}
Expand All @@ -282,27 +285,26 @@ class Job extends BaseEntity {
item.properties.datetime = temp[0] || temp[1];
}
}
return item;
return StacMigrate.item(item);
}
}

/**
* Retrieves the STAC Item or Collection produced for the job results.
*
* The Item or Collection returned always complies to the latest STAC version (currently 1.0.0-rc.1).
*
* @async
* @returns {Promise<object.<string, *>>} The JSON-based response compatible to the API specification, but also including a `costs` property if present in the headers.
* @throws {Error}
*/
async getResultsAsStac() {
let response = await this.connection._get('/jobs/' + this.id + '/results');
let data = response.data;
let data = StacMigrate.stac(response.data);
if (!Utils.isObject(data.assets)) {
data.assets = {};
}
if (data.type === 'Feature') { // Item
if (!Utils.isObject(data.properties)) {
data.properties = {};
}
if (typeof response.headers['openeo-costs'] === 'number') {
data.properties.costs = response.headers['openeo-costs'];
}
Expand Down
3 changes: 2 additions & 1 deletion tests/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
// TESTBACKEND: 'http://127.0.0.1:8080'
TESTBACKEND: 'https://earthengine.openeo.org'
TESTBACKEND: 'https://earthengine.openeo.org',
STAC_MIGRATE_VERSION: '1.0.0-rc.1'
};
8 changes: 4 additions & 4 deletions tests/earthengine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var timeout = 2*60*1000;
jest.setTimeout(timeout); // Give Google some time to process data

describe('With earth-engine-driver', () => {
const { TESTBACKEND } = require('./config.js');
const { TESTBACKEND, STAC_MIGRATE_VERSION } = require('./config.js');
const TESTBACKENDDIRECT = TESTBACKEND + '/v1.0';
const TESTUSERNAME = 'group5';
const TESTPASSWORD = 'test123';
Expand Down Expand Up @@ -183,8 +183,8 @@ describe('With earth-engine-driver', () => {

test('Collections in detail', async () => {
var coll = await con.describeCollection(TESTCOLLECTION.id);
expect(coll.stac_version).toBe(TESTCOLLECTION.stac_version);
expect(coll.stac_extensions).toEqual(TESTCOLLECTION.stac_extensions);
expect(coll.stac_version).toBe(STAC_MIGRATE_VERSION);
expect(coll.stac_extensions).toEqual([]);
expect(coll.id).toBe(TESTCOLLECTION.id);
expect(coll).toHaveProperty('description');
expect(coll.license).toBe(TESTCOLLECTION.license);
Expand Down Expand Up @@ -500,7 +500,7 @@ describe('With earth-engine-driver', () => {
// Get STAC
var res = await job.getResultsAsStac();
expect(res).not.toBeNull();
expect(res).toHaveProperty("stac_version");
expect(res.stac_version).toBe(STAC_MIGRATE_VERSION);
expect(res).toHaveProperty("assets");
expect(Utils.size(res)).toBeGreaterThan(0);
expect(res).toHaveProperty("links");
Expand Down

0 comments on commit ae642b4

Please sign in to comment.