diff --git a/dev.properties b/dev.properties index 4e06fe56..b983f35a 100644 --- a/dev.properties +++ b/dev.properties @@ -1,6 +1,4 @@ dockerImage=615645230945.dkr.ecr.ap-southeast-2.amazonaws.com/javaduck:latest geoserver=http://geoserver-123.aodn.org.au/geoserver/imos/ows -s3LambdaCodeFilename=request-handler.zip -s3LambdaCodeURL=https://s3-ap-southeast-2.amazonaws.com/wps-lambda/request-handler-0.01-lambda-package.zip templatesURL=https://raw.githubusercontent.com/aodn/aws-wps/master/wps-common/src/main/resources/config/templates.xml -administratorEmail=developers@emii.org.au +geonetworkCatalogueURL=http://catalogue-sandbox.aodn.org.au/geonetwork diff --git a/request-handler/src/main/java/au/org/aodn/aws/wps/lambda/WpsLambdaRequestHandler.java b/request-handler/src/main/java/au/org/aodn/aws/wps/lambda/WpsLambdaRequestHandler.java index 8fd489ca..5db7cb21 100644 --- a/request-handler/src/main/java/au/org/aodn/aws/wps/lambda/WpsLambdaRequestHandler.java +++ b/request-handler/src/main/java/au/org/aodn/aws/wps/lambda/WpsLambdaRequestHandler.java @@ -6,6 +6,7 @@ import au.org.aodn.aws.wps.AwsApiResponse.ResponseBuilder; import au.org.aodn.aws.wps.RequestParser; import au.org.aodn.aws.wps.RequestParserFactory; +import au.org.aodn.aws.wps.exception.ValidationException; import au.org.aodn.aws.util.JobFileUtil; import au.org.aodn.aws.wps.operation.Operation; import com.amazonaws.services.lambda.runtime.Context; @@ -79,6 +80,11 @@ public AwsApiResponse handleRequest(AwsApiRequest request, Context context) { String exceptionReportString = JobFileUtil.getExceptionReportString(oe.getExceptionText(), oe.getExceptionCode(), oe.getLocator()); responseBuilder.body(exceptionReportString); + } catch (ValidationException ve) { + LOGGER.error("Error in request parameters " + ve.getMessage(), ve); + responseBuilder.statusCode(500); + String exceptionReportString = JobFileUtil.getExceptionReportString(ve.getMessage(), "ValidationError"); + responseBuilder.body(exceptionReportString); } catch (Exception e) { LOGGER.error("Exception : " + e.getMessage(), e); responseBuilder.statusCode(500); diff --git a/request-handler/src/main/java/au/org/aodn/aws/wps/operation/ExecuteOperation.java b/request-handler/src/main/java/au/org/aodn/aws/wps/operation/ExecuteOperation.java index cd5e98c9..4b8826dc 100644 --- a/request-handler/src/main/java/au/org/aodn/aws/wps/operation/ExecuteOperation.java +++ b/request-handler/src/main/java/au/org/aodn/aws/wps/operation/ExecuteOperation.java @@ -3,6 +3,7 @@ import au.org.aodn.aws.util.EmailService; import au.org.aodn.aws.util.JobFileUtil; import au.org.aodn.aws.wps.request.ExecuteRequestHelper; +import au.org.aodn.aws.wps.exception.ValidationException; import au.org.aodn.aws.wps.status.*; import com.amazonaws.services.batch.AWSBatch; import com.amazonaws.services.batch.AWSBatchClientBuilder; @@ -30,7 +31,7 @@ public ExecuteOperation(Execute executeRequest) { @Override - public String execute() { + public String execute() throws ValidationException { // Config items: // queue names @@ -54,6 +55,7 @@ public String execute() { LOGGER.info("awsRegion: " + awsRegion); ExecuteRequestHelper helper = new ExecuteRequestHelper(executeRequest); + helper.validateInputs(); String email = helper.getEmail(); String processIdentifier = executeRequest.getIdentifier().getValue(); // code spaces not supported for the moment diff --git a/request-handler/src/main/java/au/org/aodn/aws/wps/operation/Operation.java b/request-handler/src/main/java/au/org/aodn/aws/wps/operation/Operation.java index 71ddb35f..ed416dfc 100644 --- a/request-handler/src/main/java/au/org/aodn/aws/wps/operation/Operation.java +++ b/request-handler/src/main/java/au/org/aodn/aws/wps/operation/Operation.java @@ -1,7 +1,8 @@ package au.org.aodn.aws.wps.operation; import au.org.aodn.aws.exception.OGCException; +import au.org.aodn.aws.wps.exception.ValidationException; public interface Operation { - String execute() throws OGCException; + String execute() throws OGCException, ValidationException; } diff --git a/wps-common/src/main/java/au/org/aodn/aws/wps/exception/ValidationException.java b/wps-common/src/main/java/au/org/aodn/aws/wps/exception/ValidationException.java new file mode 100644 index 00000000..e24b582a --- /dev/null +++ b/wps-common/src/main/java/au/org/aodn/aws/wps/exception/ValidationException.java @@ -0,0 +1,24 @@ +package au.org.aodn.aws.wps.exception; + +public class ValidationException extends Exception { + + public ValidationException() + { + super(); + } + + public ValidationException(String message) + { + super(message); + } + + public ValidationException(String message, Throwable ex) + { + super(message, ex); + } + + public ValidationException(Throwable ex) + { + super(ex); + } +} \ No newline at end of file diff --git a/wps-common/src/main/java/au/org/aodn/aws/wps/request/ExecuteRequestHelper.java b/wps-common/src/main/java/au/org/aodn/aws/wps/request/ExecuteRequestHelper.java index edba8415..c8e1cf94 100644 --- a/wps-common/src/main/java/au/org/aodn/aws/wps/request/ExecuteRequestHelper.java +++ b/wps-common/src/main/java/au/org/aodn/aws/wps/request/ExecuteRequestHelper.java @@ -5,6 +5,10 @@ import net.opengis.wps.v_1_0_0.InputType; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import au.org.aodn.aws.wps.exception.ValidationException; public class ExecuteRequestHelper { private final Execute request; @@ -34,6 +38,36 @@ public boolean hasRequestedOutput(String identifier) { return false; } + public void validateInputs() throws ValidationException { + String layerName = getLiteralInputValue("layer"); + String subset = getLiteralInputValue("subset"); + String email = getEmail(); + + if (layerName == null) { + throw new ValidationException("Request must have a layer name"); + } + + if (subset == null) { + throw new ValidationException("Request must have a subset"); + } else { + int latLonCount = 0; + Pattern latLonPattern = Pattern.compile("([+-]?\\d+\\.?\\d+)\\s*,\\s*([+-]?\\d+\\.?\\d+)"); + Matcher matcher = latLonPattern.matcher(subset); + + while (matcher.find()) { + latLonCount++; + } + + if (latLonCount != 2) { + throw new ValidationException(String.format("Invalid latitude/longitude format for subset: %s", subset)); + } + } + + if (email == null) { + throw new ValidationException("Request must have a callback email"); + } + } + public String getRequestedMimeType(String identifier) { for (DocumentOutputDefinitionType output: getResponseFormOutputs()) { if (output.getIdentifier().getValue().equals(identifier)) {