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

Feature/stac 1.1.0 #103

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
179 changes: 96 additions & 83 deletions src/main/java/org/openeo/spring/api/CollectionsApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public class CollectionsApiController implements CollectionsApi {
@Autowired
private JobsApiController jobsApiController;

@Autowired
private ResultApiController resultApiController;

/** Whether to run both inter- and intra-catalogue parallelized loading. */
@Value("${org.openeo.parallelizedHarvest}")
private boolean parallelizedHarvest;
Expand Down Expand Up @@ -496,6 +499,8 @@ else if (headerValue.contains(TIFF)) {
// if ((bboxList.isPresent() || temporalString.isPresent()) && (subsetList.isPresent())) {
// return ApiUtil.errorResponse(HttpStatus.FORBIDDEN,"Please provide either bbox and datetime parameters, or subset. Can't parse both at the same time!");
// }
// coverage = 'coverage?subset=Lat(46.45:46.50),Lon(11.30:11.35),time("2019-05-01/2019-06-01")'

if (subsetList.isPresent()) {
return ApiUtil.errorResponse(
HttpStatus.NOT_IMPLEMENTED,
Expand Down Expand Up @@ -578,7 +583,9 @@ else if (headerValue.contains(TIFF)) {
List<?> collTInt = collection.getExtent().getTemporal().getInterval();
OffsetDateTime collT0 = collection.getExtent().getTemporal().getInterval().get(0).get(0);
OffsetDateTime collT1 = collection.getExtent().getTemporal().getInterval().get(0).get(1);

if (collT1==null) {
collT1 = OffsetDateTime.now();
}
final String DATETIME_OPEN = "..";
if (DATETIME_OPEN == temporalExtent[0] && DATETIME_OPEN == temporalExtent[1]) {
return ApiUtil.errorResponse(
Expand Down Expand Up @@ -657,92 +664,98 @@ else if (headerValue.contains(TIFF)) {
Job job = new Job();
BatchJobResult jobResult = BatchJobResult.ofType(AssetType.FEATURE);
job.setProcess(process);
job.setTitle(String.format("OGC-Coverage-%s-%s", fileFormat, OffsetDateTime.now()));
ResponseEntity<?> response = jobsApiController.createJob(job, principal);

ResponseEntity<?> response = resultApiController.computeResult(job, principal);
return response;
}
}
//
// job.setTitle(String.format("OGC-Coverage-%s-%s", fileFormat, OffsetDateTime.now()));
// ResponseEntity<?> response2 = jobsApiController.createJob(job, principal);

/*
* PROBLEM
* Information in the logs cannot be saved in the Job obj and gets lost
* for the client.
*/
job = (Job) response.getBody();
response = jobsApiController.startJob(job.getId().toString());
// response = jobsApiController.downloadResult(job.getId().toString(), filePath); ?
boolean jobFinishedSuccessfully = false;
for (int i = 0; i < 150; i++) { // FIXME ??
try {
Thread.sleep(2000); // FIXME ?
ResponseEntity<?> jobDescription = jobsApiController.describeJob(job.getId().toString());
job = (Job) jobDescription.getBody();
log.debug("Job status: {}", job.getStatus());

if (job.getStatus() == JobStates.FINISHED) {
jobFinishedSuccessfully = true;
break;
}
else if (job.getStatus() == JobStates.ERROR) {
jobFinishedSuccessfully = false;
break;
}
} catch (InterruptedException e) {
log.error("Request interrupted!");
Thread.currentThread().interrupt();
}
}
if (!jobFinishedSuccessfully) {
// FIXME
return ApiUtil.errorResponse(
HttpStatus.INTERNAL_SERVER_ERROR,
"The request did not finished within the timeout limit, or failed.");
}

ResponseEntity<?> jobListResults = jobsApiController.listResults(job.getId().toString());
jobResult = (BatchJobResult) jobListResults.getBody();
Map<String, Asset> resultAssets = jobResult.getAssets();
String resultKey = new String();
for (Map.Entry<String, Asset> entry : resultAssets.entrySet()) {
log.trace("{} : {}", entry.getKey(), entry.getValue());
if (entry.getKey().contains("result")){
resultKey = entry.getKey();
}
}
Asset outputAsset = resultAssets.get(resultKey);
String outputFilePath = outputAsset.getHref();
try {
log.debug("Result path: '{}'", outputFilePath);
File outputFile = new File(outputFilePath);
String mime = URLConnection.guessContentTypeFromName(outputFile.getName());
if (mime == null) {
try {
mime = ConvenienceHelper.getMimeFromFilename(outputFile.getName());
}
catch (Exception e){
log.warn("Could not derive MIME type from file name.", e);
}
}
log.debug("Guessed MIME type: {}", mime);

URL url = new URL(outputFilePath);
InputStream is = null;
byte[] outputFileBytes = null;
is = url.openStream();
outputFileBytes = IOUtils.toByteArray(is);
if (is != null) {
is.close();
}
if (mime == null) {
mime = "application/octet-stream";
}
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(mime))
.body(outputFileBytes);
}
catch (IOException e) {
log.error("Result file not found", e);
return ApiUtil.errorResponse(
HttpStatus.INTERNAL_SERVER_ERROR,
"Result file not found.");
}
// job = (Job) response.getBody();
// response = jobsApiController.startJob(job.getId().toString());
//// response = jobsApiController.downloadResult(job.getId().toString(), filePath); ?
// boolean jobFinishedSuccessfully = false;
// for (int i = 0; i < 150; i++) { // FIXME ??
// try {
// Thread.sleep(2000); // FIXME ?
// ResponseEntity<?> jobDescription = jobsApiController.describeJob(job.getId().toString());
// job = (Job) jobDescription.getBody();
// log.debug("Job status: {}", job.getStatus());
//
// if (job.getStatus() == JobStates.FINISHED) {
// jobFinishedSuccessfully = true;
// break;
// }
// else if (job.getStatus() == JobStates.ERROR) {
// jobFinishedSuccessfully = false;
// break;
// }
// } catch (InterruptedException e) {
// log.error("Request interrupted!");
// Thread.currentThread().interrupt();
// }
// }
// if (!jobFinishedSuccessfully) {
// // FIXME
// return ApiUtil.errorResponse(
// HttpStatus.INTERNAL_SERVER_ERROR,
// "The request did not finished within the timeout limit, or failed.");
// }
//
// ResponseEntity<?> jobListResults = jobsApiController.listResults(job.getId().toString());
// jobResult = (BatchJobResult) jobListResults.getBody();
// Map<String, Asset> resultAssets = jobResult.getAssets();
// String resultKey = new String();
// for (Map.Entry<String, Asset> entry : resultAssets.entrySet()) {
// log.trace("{} : {}", entry.getKey(), entry.getValue());
// if (entry.getKey().contains("result")){
// resultKey = entry.getKey();
// }
// }
// Asset outputAsset = resultAssets.get(resultKey);
// String outputFilePath = outputAsset.getHref();
// try {
// log.debug("Result path: '{}'", outputFilePath);
// File outputFile = new File(outputFilePath);
// String mime = URLConnection.guessContentTypeFromName(outputFile.getName());
// if (mime == null) {
// try {
// mime = ConvenienceHelper.getMimeFromFilename(outputFile.getName());
// }
// catch (Exception e){
// log.warn("Could not derive MIME type from file name.", e);
// }
// }
// log.debug("Guessed MIME type: {}", mime);
//
// URL url = new URL(outputFilePath);
// InputStream is = null;
// byte[] outputFileBytes = null;
// is = url.openStream();
// outputFileBytes = IOUtils.toByteArray(is);
// if (is != null) {
// is.close();
// }
// if (mime == null) {
// mime = "application/octet-stream";
// }
// return ResponseEntity.ok()
// .contentType(MediaType.parseMediaType(mime))
// .body(outputFileBytes);
// }
// catch (IOException e) {
// log.error("Result file not found", e);
// return ApiUtil.errorResponse(
// HttpStatus.INTERNAL_SERVER_ERROR,
// "Result file not found.");
// }

// {
// "process_graph": {
Expand All @@ -768,5 +781,5 @@ else if (job.getStatus() == JobStates.ERROR) {
// },
// "parameters": []
// }
}
}
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ static Collection parseCollection(String coverageID, InputStream stream,
dim.setType(TypeEnum.SPATIAL); // FIXME this should be implicit

// int gridDim = Integer.parseInt(gridDims[index]) + 1;
int epsgCode = axisLabel2EpsgCode.get(label);
String epsgCode = axisLabel2EpsgCode.get(label).toString();
dim.setReferenceSystem(epsgCode);

// axis type: easting/northing/z ?
Expand Down Expand Up @@ -1359,7 +1359,7 @@ else if (TEMPORAL_AXIS_LABELS.contains(label)) {
if (null != bandWave) {
try {
double w = Double.parseDouble(bandWave);
bandsSummary.setCenterwavelength(w);
bandsSummary.setCenterWavelength(w);
} catch (NumberFormatException e) {
log.warn("Error in parsing band wave-lenght:" + e.getMessage());
}
Expand Down
71 changes: 47 additions & 24 deletions src/main/java/org/openeo/spring/model/BandSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ public class BandSummary {
private String description;

@JsonProperty(value="center_wavelength", required=false)
private Double centerwavelength;

private Double centerWavelength;

@JsonProperty(value="full_width_half_max", required=false)
private Double fullWidthHalfMax;

@JsonProperty(value="gsd", required=false)
private Double gsd;

public BandSummary name(String name) {
this.name = name;
return this;
}

/**
* Relationship between the current document and the linked document. SHOULD be a [registered link relation type](https://www.iana.org/assignments/link-relations/link-relations.xml) whenever feasible.
* @return rel
Expand All @@ -54,11 +52,6 @@ public void setName(String name) {
this.name = name;
}

public BandSummary commonname(String commonname) {
this.commonname = commonname;
return this;
}

/**
* The value MUST be a valid URL.
* @return href
Expand All @@ -82,22 +75,51 @@ public void setDescription(String description) {
this.description = description;
}

public BandSummary centerwavelength(double centerwavelength) {
this.centerwavelength = centerwavelength;
return this;
}

/**
* The value MUST be a string that hints at the format used to represent data at the provided URI, preferably a media (MIME) type.
* @return type
*/
@ApiModelProperty(example = "0.773", value = "The value MUST be a value that hints at the format used to represent data at the provided URI, preferably a media (MIME) type.")
public Double getCenterwavelength() {
return centerwavelength;
public Double getCenterWwavelength() {
return centerWavelength;
}

public void setCenterwavelength(Double centerwavelength) {
this.centerwavelength = centerwavelength;
public void setCenterWavelength(Double centerwavelength) {
this.centerWavelength = centerwavelength;
}

@ApiModelProperty
public Double getFullWidthHalfMax() {
return fullWidthHalfMax;
}

public void setFullWidthHalfMax(Double fullWidthHalfMax) {
this.fullWidthHalfMax = fullWidthHalfMax;
}

/*
* constructor builder helpers
*/

public BandSummary name(String name) {
this.name = name;
return this;
}

public BandSummary commonName(String commonname) {
this.commonname = commonname;
return this;
}

public BandSummary centerWavelength(double centerWavelength) {
this.centerWavelength = centerWavelength;
return this;
}

public BandSummary fullWidthHalfMax(double fullWidthHalfMax) {
this.fullWidthHalfMax = fullWidthHalfMax;
return this;
}

public BandSummary gsd(Double gsd) {
Expand Down Expand Up @@ -130,13 +152,14 @@ public boolean equals(java.lang.Object o) {
return Objects.equals(this.name, bandsummary.name) &&
Objects.equals(this.commonname, bandsummary.commonname) &&
Objects.equals(this.description, bandsummary.description) &&
Objects.equals(this.centerwavelength, bandsummary.centerwavelength) &&
Objects.equals(this.centerWavelength, bandsummary.centerWavelength) &&
Objects.equals(this.fullWidthHalfMax, bandsummary.fullWidthHalfMax) &&
Objects.equals(this.gsd, bandsummary.gsd);
}

@Override
public int hashCode() {
return Objects.hash(name, commonname, description, centerwavelength, gsd);
return Objects.hash(name, commonname, description, centerWavelength, fullWidthHalfMax, gsd);
}

@Override
Expand All @@ -147,7 +170,8 @@ public String toString() {
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" common_name: ").append(toIndentedString(commonname)).append("\n");
sb.append(" description: ").append(toIndentedString(description)).append("\n");
sb.append(" center_wavelength: ").append(toIndentedString(centerwavelength)).append("\n");
sb.append(" center_wavelength: ").append(toIndentedString(centerWavelength)).append("\n");
sb.append(" full_width_half_max: ").append(toIndentedString(fullWidthHalfMax)).append("\n");
sb.append(" gsd: ").append(toIndentedString(gsd)).append("\n");
sb.append("}");
return sb.toString();
Expand All @@ -164,4 +188,3 @@ private String toIndentedString(java.lang.Object o) {
return o.toString().replace("\n", "\n ");
}
}

12 changes: 5 additions & 7 deletions src/main/java/org/openeo/spring/model/DimensionSpatial.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static AxisEnum fromValue(String value) {
private String unit = null;

@JsonProperty("reference_system")
private Integer referenceSystem = null;
private String referenceSystem = null;

public DimensionSpatial axis(AxisEnum axis) {
this.axis = axis;
Expand Down Expand Up @@ -195,7 +195,7 @@ public void setUnit(String unit) {
this.unit = unit;
}

public DimensionSpatial referenceSystem(Integer referenceSystem) {
public DimensionSpatial referenceSystem(String referenceSystem) {
this.referenceSystem = referenceSystem;
return this;
}
Expand All @@ -204,15 +204,13 @@ public DimensionSpatial referenceSystem(Integer referenceSystem) {
* The spatial reference system for the data, specified as [EPSG code](http://www.epsg-registry.org/), [WKT2 (ISO 19162) string](http://docs.opengeospatial.org/is/18-010r7/18-010r7.html) or [PROJ definition (deprecated)](https://proj.org/usage/quickstart.html). Defaults to EPSG code 4326.
* @return referenceSystem
*/
@ApiModelProperty(value = "The spatial reference system for the data, specified as [EPSG code](http://www.epsg-registry.org/), [WKT2 (ISO 19162) string](http://docs.opengeospatial.org/is/18-010r7/18-010r7.html) or [PROJ definition (deprecated)](https://proj.org/usage/quickstart.html). Defaults to EPSG code 4326.")

@ApiModelProperty(value = "The spatial reference system for the data, specified as [EPSG code](http://www.epsg-registry.org/), [WKT2 (ISO 19162) string](http://docs.opengeospatial.org/is/18-010r7/18-010r7.html) or [PROJ definition (deprecated)](https://proj.org/usage/quickstart.html). Defaults to EPSG code '4326'.")
@Valid

public Integer getReferenceSystem() {
public String getReferenceSystem() {
return referenceSystem;
}

public void setReferenceSystem(Integer referenceSystem) {
public void setReferenceSystem(String referenceSystem) {
this.referenceSystem = referenceSystem;
}

Expand Down
Loading
Loading