Skip to content
Open
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 @@ -13,6 +13,7 @@ public class ZippedManifestData {
private final String subType;
private final String caseType;
private String errorDescription;
private final String comment;

public String getDocumentName() {
return this.caseNumber + "_" + this.docType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class FeatureToggleService {
private static final String UNSUBMITTED_APPLICATION_TOGGLE = "probate-cron-unsubmitted-application";
private static final String DECLARATION_NOT_SIGNED_TOGGLE = "probate-cron-declaration-not-signed";
private static final String NFI_DATA_EXTRACT_TOGGLE = "probate-nfi-data-extract";
private static final String SMEE_AND_FORD_COMMENT_FIELD_TOGGLE = "probate-smee-ford-comment-field";

@Autowired
public FeatureToggleService(LDClient ldClient, @Value("${ld.user.key}") String ldUserKey,
Expand Down Expand Up @@ -110,4 +111,9 @@ public boolean isNfiDataExtractFeatureToggleOn() {
return this.isFeatureToggleOn(
NFI_DATA_EXTRACT_TOGGLE, false);
}

public boolean isSmeeAndFordCommentFieldFeatureToggleOn() {
return this.isFeatureToggleOn(
SMEE_AND_FORD_COMMENT_FIELD_TOGGLE, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uk.gov.hmcts.probate.exception.ClientException;
import uk.gov.hmcts.probate.model.ccd.raw.request.ReturnedCaseDetails;
import uk.gov.hmcts.probate.service.CaseQueryService;
import uk.gov.hmcts.probate.service.FeatureToggleService;
import uk.gov.hmcts.probate.service.NotificationService;
import uk.gov.hmcts.probate.service.zip.ZipFileService;
import uk.gov.service.notify.NotificationClientException;
Expand All @@ -26,10 +27,12 @@ public class SmeeAndFordDataExtractService {
private final CaseQueryService caseQueryService;
private final NotificationService notificationService;
private final ZipFileService zipFileService;
private final SmeeAndFordDataExtractStrategy smeeAndFOrdDataExtractStrategy;
private final SmeeAndFordDataExtractStrategy smeeAndFordDataExtractStrategy;
private final FeatureToggleService featureToggleService;
@Value("${feature.blobstorage.smeeandford.enabled}")
public boolean featureBlobStorageSmeeAndFord;


public void performSmeeAndFordExtractForDateRange(String fromDate, String toDate) {
if (fromDate.equals(toDate)) {
performSmeeAndFordExtractForDate(fromDate);
Expand All @@ -56,11 +59,19 @@ private void sendSmeeAndFordEmail(List<ReturnedCaseDetails> cases, String fromDa
if (!cases.isEmpty()) {
try {
log.info("FeatureBlobStorageSmeeAndFord flag enabled is {}", featureBlobStorageSmeeAndFord);
log.info("isSmeeAndFordCommentFieldFeatureToggleOn flag enabled is {}",
featureToggleService.isSmeeAndFordCommentFieldFeatureToggleOn());
if (featureBlobStorageSmeeAndFord) {
File tempFile = zipFileService.createTempZipFile("Probate_Docs_" + fromDate);
zipFileService.generateAndUploadZipFile(cases, tempFile, fromDate, smeeAndFOrdDataExtractStrategy);
log.info("Zip file uploaded on blob store");
Files.deleteIfExists(tempFile.toPath());
if (featureToggleService.isSmeeAndFordCommentFieldFeatureToggleOn()) {
log.info("Feature toggle FirstStopReminderFeatureToggle is on, commencing task");
File tempFile = zipFileService.createTempZipFile("Probate_Docs_" + fromDate);
zipFileService.generateAndUploadZipFile(cases, tempFile, fromDate,
smeeAndFordDataExtractStrategy);
log.info("Zip file uploaded on blob store");
Files.deleteIfExists(tempFile.toPath());
} else {
log.info("Feature toggle FirstStopReminderFeatureToggle is off, skipping task");
}
}
notificationService.sendSmeeAndFordEmail(cases, fromDate, toDate);
} catch (NotificationClientException e) {
Expand Down
34 changes: 22 additions & 12 deletions src/main/java/uk/gov/hmcts/probate/service/zip/ZipFileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class ZipFileService {
ADMON_WILL_GRANT_REISSUE, AD_COLLIGENDA_BONA_GRANT_REISSUE, WELSH_DIGITAL_GRANT_REISSUE,
WELSH_INTESTACY_GRANT_REISSUE, WELSH_ADMON_WILL_GRANT_REISSUE, WELSH_AD_COLLIGENDA_BONA_GRANT_REISSUE};
private static final String HEADER_ROW_FILE = "templates/dataExtracts/ManifestFileHeaderRow.csv";
private static final String ERROR_MASSAGE = "Exception occurred while generating zip file ";
private static final String ERROR_MESSAGE = "Exception occurred while generating zip file ";

public File generateZipFile(List<ReturnedCaseDetails> cases, File tempFile, String date, DataExtractType type) {
log.info("{} generateZipFile for {} cases", type, cases.size());
Expand All @@ -85,7 +85,7 @@ public File generateZipFile(List<ReturnedCaseDetails> cases, File tempFile, Stri
zipOut.closeEntry();
return tempFile;
} catch (Exception e) {
log.error(ERROR_MASSAGE, e);
log.error(ERROR_MESSAGE, e);
throw new ZipFileException(e.getMessage());
}
}
Expand All @@ -112,7 +112,7 @@ public void generateAndUploadZipFile(List<ReturnedCaseDetails> cases,
fos.close();
strategy.uploadToBlobStorage(tempFile);
} catch (Exception e) {
log.error(ERROR_MASSAGE, e);
log.error(ERROR_MESSAGE, e);
throw new ZipFileException(e.getMessage());
}
}
Expand Down Expand Up @@ -148,8 +148,9 @@ private void getScannedDocuments(final ZipOutputStream zos,
final String binaryUrl = doc.getValue().getUrl().getDocumentBinaryUrl();
final String documentTypeName = "scanned_" + WILL.getTemplateName()
+ "_" + scannedDocIndex.getAndIncrement();
fetchAndUploadDocument(zos, binaryUrl, caseDetails, documentTypeName, PDF,
manifestDataList);
final String documentSubType = doc.getValue().getSubtype();
fetchAndUploadDocument(zos, binaryUrl, caseDetails, documentTypeName, PDF, documentSubType,
manifestDataList, null);
});
}
}
Expand All @@ -166,8 +167,9 @@ private void getUploadedWillDocuments(ZipOutputStream zos,
final String binaryUrl = doc.getValue().getDocumentLink().getDocumentBinaryUrl();
final String documentTypeName = "uploaded_" + WILL.getTemplateName()
+ "_" + uploadedDocIndex.getAndIncrement();
fetchAndUploadDocument(zos, binaryUrl, caseDetails, documentTypeName, PDF,
manifestDataList);
final String documentComment = doc.getValue().getComment();
fetchAndUploadDocument(zos, binaryUrl, caseDetails, documentTypeName, PDF, null,
manifestDataList, documentComment);
});
}
}
Expand All @@ -182,7 +184,7 @@ private void getGrantDocuments(ZipOutputStream zos,
.forEach(doc -> {
final String binaryUrl = doc.getValue().getDocumentLink().getDocumentBinaryUrl();
fetchAndUploadDocument(zos, binaryUrl, caseDetails,
doc.getValue().getDocumentType().getTemplateName(), PDF, manifestDataList);
doc.getValue().getDocumentType().getTemplateName(), PDF, null, manifestDataList, null);
});
}

Expand All @@ -198,7 +200,8 @@ private void getReIssueGrantDocuments(ZipOutputStream zos,
final String binaryUrl = doc.getValue().getDocumentLink().getDocumentBinaryUrl();
final String documentTypeName = doc.getValue().getDocumentType().getTemplateName()
+ "_" + reIssueGrantDocIndex.getAndIncrement();
fetchAndUploadDocument(zos, binaryUrl, caseDetails, documentTypeName, PDF, manifestDataList);
fetchAndUploadDocument(zos, binaryUrl, caseDetails, documentTypeName, PDF, null,
manifestDataList, null);
});

}
Expand All @@ -208,7 +211,9 @@ private void fetchAndUploadDocument(ZipOutputStream zos,
ReturnedCaseDetails caseDetails,
String documentTypeName,
String docType,
List<ZippedManifestData> manifestDataList) {
String documentSubType,
List<ZippedManifestData> manifestDataList,
String documentComment) {
final String documentId = binaryUrl.substring(binaryUrl
.indexOf("/documents/") + 11, binaryUrl.lastIndexOf("/"));
String errorDescription = "";
Expand All @@ -217,8 +222,11 @@ private void fetchAndUploadDocument(ZipOutputStream zos,
.documentId(documentId)
.docType(documentTypeName)
.docFileType(docType)
.subType(caseDetails.getData().getCaseType())
.errorDescription(errorDescription).build();
.subType(documentSubType)
.caseType(caseDetails.getData().getCaseType())
.errorDescription(errorDescription)
.comment(documentComment)
.build();

try {
ByteArrayResource byteArrayResource =
Expand Down Expand Up @@ -305,6 +313,8 @@ private void generateManifestFile(ZipOutputStream zos, List<ZippedManifestData>
data.append(zippedManifestData.getDocumentName());
data.append(DELIMITER);
data.append(zippedManifestData.getErrorDescription());
data.append(DELIMITER);
data.append(zippedManifestData.getComment());
data.append(NEW_LINE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Case reference number|Document id|Document type|Document sub type|Case type|Document file name|Error description
Case reference number|Document id|Document type|Document sub type|Case type|Document file name|Error description|Comment
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uk.gov.hmcts.probate.model.ccd.raw.request.CaseData;
import uk.gov.hmcts.probate.model.ccd.raw.request.ReturnedCaseDetails;
import uk.gov.hmcts.probate.service.CaseQueryService;
import uk.gov.hmcts.probate.service.FeatureToggleService;
import uk.gov.hmcts.probate.service.NotificationService;
import uk.gov.hmcts.probate.service.zip.ZipFileService;
import uk.gov.service.notify.NotificationClientException;
Expand Down Expand Up @@ -48,6 +49,8 @@ class SmeeAndFordDataExtractServiceTest {
private BlobUpload blobUpload;
@Mock
private SmeeAndFordDataExtractStrategy smeeAndFOrdDataExtractStrategy;
@Mock
private FeatureToggleService featureToggleService;

private static final LocalDateTime LAST_MODIFIED = LocalDateTime.now(ZoneOffset.UTC).minusYears(2);

Expand All @@ -60,6 +63,7 @@ class SmeeAndFordDataExtractServiceTest {
public void setup() {
MockitoAnnotations.openMocks(this);
smeeAndFordDataExtractService.featureBlobStorageSmeeAndFord = false;
when(featureToggleService.isSmeeAndFordCommentFieldFeatureToggleOn()).thenReturn(true);
CollectionMember<ScannedDocument> scannedDocument = new CollectionMember<>(new ScannedDocument("1",
"test", "other", "will", LocalDateTime.now(), DocumentLink.builder().build(),
"test", LocalDateTime.now()));
Expand Down
Loading