-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ia-case-documents-api-dlrm-fc
# Conflicts: # src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java # src/main/resources/application.yaml # src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/EventTest.java
- Loading branch information
Showing
29 changed files
with
1,034 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/StoredNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities; | ||
|
||
import lombok.*; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document; | ||
|
||
@EqualsAndHashCode | ||
@ToString | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class StoredNotification { | ||
@NonNull private String notificationId; | ||
@NonNull private String notificationDateSent; | ||
@NonNull private String notificationSentTo; | ||
@NonNull private String notificationBody; | ||
@Setter private Document notificationDocument; | ||
@NonNull private String notificationMethod; | ||
@NonNull private String notificationStatus; | ||
@NonNull private String notificationReference; | ||
@NonNull private String notificationSubject; | ||
private String notificationErrorMessage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...ov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/field/PreviousDecisionDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PreviousDecisionDetails { | ||
|
||
private String decisionDetailsDate; | ||
private String recordDecisionType; | ||
private Document uploadSignedDecisionNoticeDocument; | ||
} |
80 changes: 80 additions & 0 deletions
80
...s/reform/iacasedocumentsapi/domain/handlers/presubmit/SaveNotificationsToDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit; | ||
|
||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.StoredNotification; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackResponse; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackStage; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.IdValue; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.PreSubmitCallbackHandler; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.SaveNotificationsToDataPdfService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static java.util.Objects.requireNonNull; | ||
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.NOTIFICATIONS; | ||
|
||
@Component | ||
public class SaveNotificationsToDataHandler implements PreSubmitCallbackHandler<AsylumCase> { | ||
|
||
private final SaveNotificationsToDataPdfService saveNotificationsToDataPdfService; | ||
|
||
public SaveNotificationsToDataHandler( | ||
SaveNotificationsToDataPdfService saveNotificationsToDataPdfService | ||
) { | ||
this.saveNotificationsToDataPdfService = saveNotificationsToDataPdfService; | ||
} | ||
|
||
public boolean canHandle( | ||
PreSubmitCallbackStage callbackStage, | ||
Callback<AsylumCase> callback | ||
) { | ||
requireNonNull(callbackStage, "callbackStage must not be null"); | ||
requireNonNull(callback, "callback must not be null"); | ||
|
||
return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT | ||
&& callback.getEvent() == Event.SAVE_NOTIFICATIONS_TO_DATA; | ||
} | ||
|
||
public PreSubmitCallbackResponse<AsylumCase> handle( | ||
PreSubmitCallbackStage callbackStage, | ||
Callback<AsylumCase> callback | ||
) { | ||
if (!canHandle(callbackStage, callback)) { | ||
throw new IllegalStateException("Cannot handle callback"); | ||
} | ||
|
||
final CaseDetails<AsylumCase> caseDetails = callback.getCaseDetails(); | ||
final AsylumCase asylumCase = caseDetails.getCaseData(); | ||
|
||
Optional<List<IdValue<StoredNotification>>> maybeExistingNotifications = | ||
asylumCase.read(NOTIFICATIONS); | ||
|
||
ArrayList<IdValue<StoredNotification>> newNotifications = new ArrayList<>(); | ||
List<String> invalidNotificationStatuses = List.of("Cancelled", "Failed", "Technical-failure", | ||
"Temporary-failure", "Permanent-failure", "Validation-failed", "Virus-scan-failed"); | ||
for (IdValue<StoredNotification> notification : maybeExistingNotifications.orElse(emptyList())) { | ||
StoredNotification storedNotification = notification.getValue(); | ||
if (storedNotification.getNotificationDocument() == null | ||
&& !invalidNotificationStatuses.contains(storedNotification.getNotificationStatus())) { | ||
String notificationBody = storedNotification.getNotificationBody(); | ||
String notificationReference = storedNotification.getNotificationReference(); | ||
Document notificationPdf = | ||
saveNotificationsToDataPdfService.createPdf(notificationBody, notificationReference); | ||
storedNotification.setNotificationDocument(notificationPdf); | ||
notification = new IdValue<>(notification.getId(), storedNotification); | ||
} | ||
newNotifications.add(notification); | ||
} | ||
asylumCase.write(NOTIFICATIONS, newNotifications); | ||
|
||
return new PreSubmitCallbackResponse<>(asylumCase); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...gov/hmcts/reform/iacasedocumentsapi/domain/service/SaveNotificationsToDataPdfService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.service; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.springframework.core.io.ByteArrayResource; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
@Service | ||
public class SaveNotificationsToDataPdfService { | ||
|
||
private static final String PDF_CONTENT_TYPE = "application/pdf"; | ||
|
||
private final DocumentToPdfConverter documentToPdfConverter; | ||
private final DocumentUploader documentUploader; | ||
|
||
public SaveNotificationsToDataPdfService( | ||
DocumentUploader documentUploader, | ||
DocumentToPdfConverter documentToPdfConverter | ||
) { | ||
this.documentUploader = documentUploader; | ||
this.documentToPdfConverter = documentToPdfConverter; | ||
} | ||
|
||
public Document createPdf(String notificationBody, String notificationReference) { | ||
|
||
byte[] byteArray = notificationBody.getBytes(); | ||
Resource resource = new ByteArrayResource(byteArray); | ||
|
||
File notificationPdf = | ||
documentToPdfConverter.convertHtmlDocResourceToPdf(resource); | ||
|
||
ByteArrayResource byteArrayResource = getByteArrayResource( | ||
notificationPdf, | ||
notificationReference + ".PDF" | ||
); | ||
|
||
return documentUploader.upload(byteArrayResource, PDF_CONTENT_TYPE); | ||
} | ||
|
||
private ByteArrayResource getByteArrayResource(File notificationPdf, String filename) { | ||
|
||
byte[] byteArray; | ||
|
||
try { | ||
byteArray = FileUtils.readFileToByteArray(notificationPdf); | ||
|
||
} catch (IOException e) { | ||
throw new IllegalStateException("Error reading converted pdf"); | ||
} | ||
|
||
return new ByteArrayResource(byteArray) { | ||
@Override | ||
public String getFilename() { | ||
return filename; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.