diff --git a/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/GetFileFromWFDMAPI.java b/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/GetFileFromWFDMAPI.java index ecee0dd..eb99306 100644 --- a/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/GetFileFromWFDMAPI.java +++ b/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/GetFileFromWFDMAPI.java @@ -91,6 +91,34 @@ public static boolean setVirusScanMetadata(String accessToken, String fileId, St return metaUpdateResponse.getStatus() == 200; } +public static void setImageConversionMetadata(String accessToken, String fileId, String versionNumber, + JSONObject fileDetails, String conversionStatus) throws UnirestException { +JSONArray metaArray = fileDetails.getJSONArray("metadata"); +// Locate any existing scan meta and remove +for (int i = 0; i < metaArray.length(); i++) { + String metadataName = metaArray.getJSONObject(i).getString("metadataName"); + if (metadataName.equalsIgnoreCase("WFDMConversionStatus-" + versionNumber)) { + metaArray.remove(i); + break; + } +} + +// inject scan meta +JSONObject meta = new JSONObject(); +meta.put("@type", "http://resources.wfdm.nrs.gov.bc.ca/fileMetadataResource"); +meta.put("metadataName", "WFDMConversionStatus-" + versionNumber); +meta.put("metadataValue", conversionStatus); +metaArray.put(meta); + +// PUT the changes +HttpResponse metaUpdateResponse = Unirest.put(System.getenv("WFDM_DOCUMENT_API_URL").trim() + fileId) + .header("Content-Type", "application/json") + .header("Authorization", "Bearer " + accessToken) + .body(fileDetails.toString()) + .asString(); + +} + /** * Fetch the bytes for a WFDM File resource. This will return a * BufferedInputStream diff --git a/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/ProcessSQSMessage.java b/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/ProcessSQSMessage.java index f10a983..e520b58 100644 --- a/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/ProcessSQSMessage.java +++ b/wfdm-file-index-initializer/src/main/java/ca/bc/gov/nrs/wfdm/wfdm_file_index_initializer/ProcessSQSMessage.java @@ -127,9 +127,22 @@ public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) { fileExtension = ""; } + Integer fileSize; + boolean fileTooLargeToConvert = false; + if (fileDetailsJson.has("fileSize")) { + fileSize = Integer.parseInt(fileDetailsJson.get("fileSize").toString()); + if (fileSize > 10000000) { + fileTooLargeToConvert = true; + GetFileFromWFDMAPI.setImageConversionMetadata(wfdmToken, fileId, versionNumber, + fileDetailsJson, "Image Conversion aborted due to file size"); + } + } + // if a file has a heic or heif mimetype it needs to be converted by the image // conversion lambda rather than processed - if (fileExtension.equals("HEIC") || fileExtension.equals("HEIF") ) { + if ((fileExtension.equals("HEIC") || fileExtension.equals("HEIF")) && !fileTooLargeToConvert) { + GetFileFromWFDMAPI.setImageConversionMetadata(wfdmToken, fileId, versionNumber, + fileDetailsJson, "Image Conversion attempted"); logger.log("\nInfo: File with mimeType of " + mimeType + " calling image conversion lambda"); AWSLambda client = AWSLambdaAsyncClient.builder().withRegion(region).build(); InvokeRequest request = new InvokeRequest();