Skip to content

Commit

Permalink
Merge branch 'develop' of [email protected]:integratedmodelling/klab.git…
Browse files Browse the repository at this point in the history
… into develop
  • Loading branch information
euskalhenriko committed Jan 24, 2025
2 parents ad80919 + 4d59d26 commit 484f55c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
26 changes: 16 additions & 10 deletions adapters/klab.ogc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@
</exclusions>
</dependency>
<!--- AWS dependencies-->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<artifactId>apache-client</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>${aws.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>protocol-core</artifactId>
<version>${aws.version}</version>
</dependency>

<!-- <dependency> <groupId>org.geotools.xsd</groupId> <artifactId>gt-xsd-core</artifactId>
<version>${geotools.version}</version> </dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

public class STACAssetParser {
// https://github.com/radiantearth/stac-spec/blob/master/best-practices.md#common-media-types-in-stac
final private static Set<String> SUPPORTED_MEDIA_TYPE = Set.of("image/tiff;application=geotiff;profile=cloud-optimized","image/vnd.stac.geotiff;profile=cloud-optimized");
final private static Set<String> SUPPORTED_MEDIA_TYPE = Set.of("image/tiff;application=geotiff", "image/vnd.stac.geotiff",
"image/tiff;application=geotiff;profile=cloud-optimized", "image/vnd.stac.geotiff;profile=cloud-optimized",
"image/vnd.stac.geotiff;cloud-optimized=true", "application/geo+json");

/**
* Check if the MIME value is supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public static JSONObject readAssetsFromCollection(String collectionUrl, JSONObje
// item_assets is a shortcut for obtaining information about the assets
// https://github.com/stac-extensions/item-assets
if (collection.has("item_assets")) {
return STACCollectionParser.readItemAssets(collection);
if (!collection.getJSONObject("item_assets").isEmpty()) {
return STACCollectionParser.readItemAssets(collection);
}
}

// TODO Move the query to another place.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import kong.unirest.apache.ApacheClient;
import kong.unirest.json.JSONObject;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

public class STACEncoder implements IResourceEncoder {

Expand Down Expand Up @@ -160,24 +163,19 @@ private void sortByDate(List<HMStacItem> items, IMonitor monitor) {
"Ordered STAC items. First: [" + items.get(0).getTimestamp() + "]; Last [" + items.get(items.size() - 1).getTimestamp() + "]");
}

private AmazonS3 buildS3Client(String bucketRegion) throws IOException {
private S3Client buildS3Client(String bucketRegion) throws IOException {
ExternalAuthenticationCredentials awsCredentials = Authentication.INSTANCE.getCredentials(S3URLUtils.AWS_ENDPOINT);
BasicAWSCredentials awsCreds = null;
AwsCredentials credentials = null;
try {
awsCreds = new BasicAWSCredentials(awsCredentials.getCredentials().get(0), awsCredentials.getCredentials().get(1));
credentials = AwsBasicCredentials.create(awsCredentials.getCredentials().get(0), awsCredentials.getCredentials().get(1));
} catch (Exception e) {
throw new KlabIOException("Error defining AWS credenetials. " + e.getMessage());
}
AmazonS3 s3Client = null;
try {
s3Client = AmazonS3Client.builder()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(bucketRegion)
.build();
} catch (Exception e) {
throw new KlabIOException("Error building S3 client. " + e.getMessage());
}
return s3Client;
return S3Client.builder()
.httpClientBuilder(ApacheHttpClient.builder())
.region(Region.of(bucketRegion))
.credentialsProvider(StaticCredentialsProvider.create(credentials))
.build();
}

@Override
Expand Down Expand Up @@ -239,7 +237,8 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters
.findFirst().orElseThrow();
Time resourceTime = (Time) Scale.create(resource.getGeometry()).getDimension(Type.TIME);

if (resourceTime.getStart() != null && resourceTime.getEnd() != null && resourceTime.getCoveredExtent() > 0) {
if (resourceTime != null &&
resourceTime.getStart() != null && resourceTime.getEnd() != null && resourceTime.getCoveredExtent() > 0) {
time = validateTemporalDimension(time, resourceTime);
}
ITimeInstant start = time.getStart();
Expand Down Expand Up @@ -277,9 +276,8 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters

if (resource.getParameters().contains("s3BucketRegion")) {
String bucketRegion = resource.getParameters().get("s3BucketRegion", String.class);
AmazonS3 s3Client = buildS3Client(bucketRegion);
// TODO waiting until the library version is updated
// collection.setS3Client(s3Client);
S3Client s3Client = buildS3Client(bucketRegion);
collection.setS3Client(s3Client);
}

// Allow transform ensures the process to finish, but I would not bet on the resulting
Expand Down
3 changes: 3 additions & 0 deletions adapters/klab.ogc/src/main/resources/ogc/prototypes/stac.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
optional text 'asset'
"The asset that is going to be retrieved from the items."

optional text 's3BucketRegion'
"The Region for S3 elements."

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<!-- Careful here: geotools must be right for hortonmachine to work; JTS
should be the same one that geotools and HM needs. -->
<geotools.version>28.0</geotools.version>
<hortonmachine.version>0.10.9-SNAPSHOT</hortonmachine.version>
<hortonmachine.version>0.10.9-S3-SDK-2.0-SNAPSHOT</hortonmachine.version>
<jts.version>1.20.0</jts.version>
<h2gis.version>1.5.0</h2gis.version>
<maven.compiler.source>11</maven.compiler.source>
Expand Down Expand Up @@ -143,7 +143,7 @@
<mockito.version>5.6.0</mockito.version>
<hamcrest.version>2.2</hamcrest.version>
<powermock.version>2.0.9</powermock.version>
<aws.version>1.12.767</aws.version>
<aws.version>2.29.14</aws.version>
</properties>

<build>
Expand Down

0 comments on commit 484f55c

Please sign in to comment.