-
Notifications
You must be signed in to change notification settings - Fork 40
Feature/diagnostic document sync #195
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
Changes from all commits
03da110
0782c44
ad2ccaa
b0ca63f
e9ddd75
2c957c9
d0438c1
6eb9221
af58fa0
c4a4142
0e957e3
48c98e8
4c11d31
e267058
7dc70ef
5442526
1b65b93
a4c35a9
ae5a424
2fedd6d
ddf96cd
f1c5078
8009ccc
df18a20
3fc6583
f757174
4c62154
80304ef
24ae8ec
5d1182a
e6e770c
0747e05
98e3c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.iemr.mmu.config; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
| import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
| import software.amazon.awssdk.regions.Region; | ||
| import software.amazon.awssdk.services.s3.S3Client; | ||
| import software.amazon.awssdk.services.s3.presigner.S3Presigner; | ||
|
|
||
| /*** | ||
| * @purpose S3 client beans used to store diagnostic documents pushed from a van. Built | ||
| * once and shared, rather than re-built per request. | ||
| */ | ||
| @Configuration | ||
| public class S3ClientConfig { | ||
|
|
||
| @Value("${aws.s3.access-key}") | ||
| private String accessKey; | ||
|
|
||
| @Value("${aws.s3.secret-key}") | ||
| private String secretKey; | ||
|
|
||
| @Value("${aws.s3.region}") | ||
| private String region; | ||
|
|
||
| private StaticCredentialsProvider credentialsProvider() { | ||
| return StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)); | ||
| } | ||
|
|
||
| @Bean | ||
| public S3Client diagnosticDocumentS3Client() { | ||
| return S3Client.builder().region(Region.of(region)).credentialsProvider(credentialsProvider()).build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public S3Presigner diagnosticDocumentS3Presigner() { | ||
| return S3Presigner.builder().region(Region.of(region)).credentialsProvider(credentialsProvider()).build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.iemr.mmu.service.dataSyncLayerCentral; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import software.amazon.awssdk.services.s3.model.GetObjectRequest; | ||
| import software.amazon.awssdk.services.s3.presigner.S3Presigner; | ||
| import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest; | ||
|
|
||
| /*** | ||
| * @purpose Hands back a short-lived presigned URL for the latest successfully-pushed | ||
| * diagnostic document matching a beneficiary+documentType, generated on demand from | ||
| * the object's S3 key (s3_path) - the bucket is private, so no permanent URL is | ||
| * ever persisted or handed out. | ||
| */ | ||
| @Service | ||
| public class DiagnosticDocumentFetchService { | ||
|
|
||
| private static final Duration URL_VALIDITY = Duration.ofMinutes(15); | ||
|
|
||
| @Value("${diagnostic.documents.s3.bucket}") | ||
| private String bucket; | ||
|
|
||
| @Autowired | ||
|
Check warning on line 28 in src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DiagnosticDocumentFetchService.java
|
||
| private DiagnosticDocumentRepository diagnosticDocumentRepository; | ||
|
|
||
| @Autowired | ||
|
Check warning on line 31 in src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DiagnosticDocumentFetchService.java
|
||
| private S3Presigner s3Presigner; | ||
|
|
||
| /*** | ||
| * @return null if no successfully-pushed document matches, otherwise the download details | ||
| * (documentType, orderType, externalOrderId, contentType, lastModDate, downloadUrl, | ||
| * urlExpiresInSeconds) | ||
| */ | ||
| public Map<String, Object> getLatestDocumentDownload(Long beneficiaryId, String documentType) { | ||
| Map<String, Object> row = diagnosticDocumentRepository.findLatestDocument(beneficiaryId, documentType); | ||
| if (row == null) { | ||
| return null; | ||
|
Check warning on line 42 in src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DiagnosticDocumentFetchService.java
|
||
| } | ||
|
|
||
| String s3Key = (String) row.get("s3_path"); | ||
| GetObjectRequest getObjectRequest = GetObjectRequest.builder().bucket(bucket).key(s3Key).build(); | ||
| GetObjectPresignRequest presignRequest = GetObjectPresignRequest.builder().signatureDuration(URL_VALIDITY) | ||
| .getObjectRequest(getObjectRequest).build(); | ||
|
Check warning on line 48 in src/main/java/com/iemr/mmu/service/dataSyncLayerCentral/DiagnosticDocumentFetchService.java
|
||
| String downloadUrl = s3Presigner.presignGetObject(presignRequest).url().toString(); | ||
|
|
||
| Map<String, Object> result = new java.util.HashMap<>(); | ||
| result.put("externalOrderId", row.get("external_order_id")); | ||
| result.put("orderType", row.get("order_type")); | ||
| result.put("documentType", row.get("document_type")); | ||
| result.put("contentType", row.get("content_type")); | ||
| result.put("originalFileName", row.get("original_file_name")); | ||
| result.put("lastModDate", String.valueOf(row.get("last_mod_date"))); | ||
| result.put("downloadUrl", downloadUrl); | ||
| result.put("urlExpiresInSeconds", URL_VALIDITY.getSeconds()); | ||
| return result; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.