Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public enum Parameter {
TYPE("type"),
FIELDS("fields"),
LAYER_NAME("layer_name"),
COLLECTION_TITLE("collection_title"),
FULL_METADATA_LINK("full_metadata_link"),
SUGGESTED_CITATION("suggested_citation"),
;

private final String value;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ public ResponseEntity<InlineResponse200> execute(
var endDate = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.END_DATE.getValue());
var multiPolygon = body.getInputs().get(DatasetDownloadEnums.Parameter.MULTI_POLYGON.getValue());
var recipient = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.RECIPIENT.getValue());
var collectionTitle = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.COLLECTION_TITLE.getValue());
var fullMetadataLink = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.FULL_METADATA_LINK.getValue());
var suggestedCitation = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.SUGGESTED_CITATION.getValue());

// move the notify user email from data-access-service to here to make the first email faster
restServices.notifyUser(recipient, uuid, startDate, endDate, multiPolygon);
restServices.notifyUser(recipient, uuid, startDate, endDate, multiPolygon, collectionTitle, fullMetadataLink, suggestedCitation);

var response = restServices.downloadData(uuid, startDate, endDate, multiPolygon, recipient);
var response = restServices.downloadData(uuid, startDate, endDate, multiPolygon, recipient, collectionTitle, fullMetadataLink, suggestedCitation);

var value = new InlineValue(response.getBody());
var status = new InlineValue(Integer.toString(HttpStatus.OK.value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public RestServices(BatchClient batchClient, ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public void notifyUser(String recipient, String uuid, String startDate, String endDate, Object multiPolygon) {
public void notifyUser(String recipient, String uuid, String startDate, String endDate, Object multiPolygon, String collectionTitle,
String fullMetadataLink,
String suggestedCitation) {

String aodnInfoSender = "no.reply@aodn.org.au";

try (SesClient ses = SesClient.builder().build()) {
var subject = Content.builder().data("Start processing data file whose uuid is: " + uuid).build();
var content = Content.builder().data(generateStartedEmailContent(uuid, startDate, endDate, multiPolygon)).build();
var content = Content.builder().data(generateStartedEmailContent(uuid, startDate, endDate, multiPolygon, collectionTitle, fullMetadataLink, suggestedCitation)).build();
var destination = Destination.builder().toAddresses(recipient).build();

var body = Body.builder().html(content).build();
Expand All @@ -74,14 +76,20 @@ public ResponseEntity<String> downloadData(
String startDate,
String endDate,
Object polygons,
String recipient
String recipient,
String collectionTitle,
String fullMetadataLink,
String suggestedCitation
) throws JsonProcessingException {

Map<String, String> parameters = new HashMap<>();
parameters.put(DatasetDownloadEnums.Parameter.UUID.getValue(), id);
parameters.put(DatasetDownloadEnums.Parameter.START_DATE.getValue(), startDate);
parameters.put(DatasetDownloadEnums.Parameter.END_DATE.getValue(), endDate);
parameters.put(DatasetDownloadEnums.Parameter.RECIPIENT.getValue(), recipient);
parameters.put(DatasetDownloadEnums.Parameter.COLLECTION_TITLE.getValue(), collectionTitle);
parameters.put(DatasetDownloadEnums.Parameter.FULL_METADATA_LINK.getValue(), fullMetadataLink);
parameters.put(DatasetDownloadEnums.Parameter.SUGGESTED_CITATION.getValue(), suggestedCitation);
if (polygons == null || polygons.toString().isEmpty()) {
throw new IllegalArgumentException("Polygons parameter should now be null. If users didn't specify polygons, a 'non-specified' should be sent.");

Expand Down Expand Up @@ -119,7 +127,15 @@ private String submitJob(String jobName, String jobQueue, String jobDefinition,
return submitJobResponse.jobId();
}

private String generateStartedEmailContent(String uuid, String startDate, String endDate, Object multipolygon) {
private String generateStartedEmailContent(
String uuid,
String startDate,
String endDate,
Object multipolygon,
String collectionTitle,
String fullMetadataLink,
String suggestedCitation
) {
try (InputStream inputStream = getClass().getResourceAsStream("/job-started-email.html")) {

if (inputStream == null) {
Expand All @@ -129,19 +145,21 @@ private String generateStartedEmailContent(String uuid, String startDate, String

String template = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);

// Handle dates - only show if not "non-specified"
String displayStartDate = (startDate != null && !startDate.equals(DatetimeUtils.NON_SPECIFIED_DATE)) ? startDate.replace("-", "/") : "";
String displayEndDate = (endDate != null && !endDate.equals(DatetimeUtils.NON_SPECIFIED_DATE)) ? endDate.replace("-", "/") : "";

// Generate dynamic bbox HTML
String bboxHtml = EmailUtils.generateBboxHtml(multipolygon, objectMapper);
// Generate subsetting section (returns empty string if no subsetting)
String subsettingSection = EmailUtils.generateSubsettingSection(
startDate,
endDate,
multipolygon,
objectMapper
);

// Replace all variables in one chain
return template
.replace("{{uuid}}", uuid)
.replace("{{startDate}}", displayStartDate)
.replace("{{endDate}}", displayEndDate)
.replace("{{bboxContent}}", bboxHtml)
.replace("{{collectionTitle}}", collectionTitle != null ? collectionTitle : "")
.replace("{{fullMetadataLink}}", fullMetadataLink != null ? fullMetadataLink : "")
.replace("{{suggestedCitation}}", suggestedCitation != null ? suggestedCitation : "")
.replace("{{subsettingSection}}", subsettingSection)
.replace("{{HEADER_IMG}}", EmailUtils.readBase64Image("header.txt"))
.replace("{{DOWNLOAD_ICON}}", EmailUtils.readBase64Image("download.txt"))
.replace("{{BBOX_IMG}}", EmailUtils.readBase64Image("bbox.txt"))
Expand Down
Loading