Skip to content

Lp/vodafone 2 #1046

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

Open
wants to merge 16 commits into
base: vodafone
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ dependencies {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}

testImplementation group:'org.springframework.batch', name: 'spring-batch-test', version: '5.2.2'
testImplementation group: 'com.h2database', name: 'h2', version: '2.3.232'

integrationTestImplementation sourceSets.main.runtimeClasspath
integrationTestImplementation sourceSets.test.runtimeClasspath
integrationTestImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.20.4'
Expand Down
1 change: 0 additions & 1 deletion charts/pre-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ description: A Helm chart for pre-api App
name: pre-api
home: https://github.com/hmcts/pre-api
version: 0.0.64

maintainers:
- name: HMCTS pre team
dependencies:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.reform.preapi.batch.application.processor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.preapi.batch.application.services.reporting.LoggingService;
Expand All @@ -14,6 +15,7 @@
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class DeltaProcessor {
private final LoggingService loggingService;
Expand All @@ -34,7 +36,8 @@ public void processDelta(String previousFile, String currentFile, String deltaFi
writeNewRecords(deltaFile, headers, newRecords);
loggingService.logInfo("New delta records written to: %s", deltaFile);
} catch (IOException e) {
e.printStackTrace();
// todo more informative message
log.error(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ private MigratedItemGroup processExemptionItem(CSVExemptionListData exemptionIte
loggingService.logDebug("Processing Exemption Item: %s", exemptionItem);

ExtractedMetadata extractedData = convertToExtractedMetadata(exemptionItem);
try {
if (extractedData == null) {
return null;
}
// todo- shouldn't be possible- remove this?
if (extractedData == null) {
return null;
}

try {
ProcessedRecording cleansedData = transformData(extractedData);
if (cleansedData == null) {
return null;
}
return migrationService.createMigratedItemGroup(extractedData, cleansedData);

} catch (Exception e) {
loggingService.logError(
"Error processing archive %s: %s",
Expand All @@ -109,8 +109,8 @@ private MigratedItemGroup processExemptionItem(CSVExemptionListData exemptionIte
e
);
handleError(extractedData, "Failed to create migrated item group: " + e.getMessage(), "Error");
return null;
}
return null;
}

private MigratedItemGroup processArchiveItem(CSVArchiveListData archiveItem) {
Expand Down Expand Up @@ -139,17 +139,16 @@ private MigratedItemGroup processArchiveItem(CSVArchiveListData archiveItem) {
if (!isValidated(cleansedData, archiveItem)) {
return null;
}
loggingService.incrementProgress();

loggingService.incrementProgress();
cacheService.dumpToFile();

return migrationService.createMigratedItemGroup(extractedData, cleansedData);
} catch (Exception e) {
loggingService.logError("Error processing archive %s: %s", archiveItem.getArchiveName(), e.getMessage(), e);
handleError(archiveItem, "Failed to create migrated item group: " + e.getMessage(), "Error");
return null;
}

return null;
}

// =========================
Expand Down Expand Up @@ -223,7 +222,7 @@ private boolean isMigrated(ProcessedRecording cleansedData, CSVArchiveListData a
String seenOriginal = (String) metadata.get("origVersionArchiveName");
String seenCopyName = (String) metadata.get("copyVersionArchiveName");

if ((isOrig && seenOrig && archiveName.equalsIgnoreCase(seenOriginal))
if ((isOrig && seenOrig && archiveName.equalsIgnoreCase(seenOriginal))
|| (isCopy && seenCopy && archiveName.equalsIgnoreCase(seenCopyName))) {

handleError(archiveItem, "Duplicate recording already seen", "Duplicate");
Expand Down Expand Up @@ -256,7 +255,7 @@ private boolean isMigrated(ProcessedRecording cleansedData, CSVArchiveListData a
//======================
// Helper Methods
//======================

private <T> boolean checkForError(ServiceResult<T> result, IArchiveData item) {
String errorMessage = result.getErrorMessage();
String category = result.getCategory();
Expand All @@ -268,17 +267,16 @@ private <T> boolean checkForError(ServiceResult<T> result, IArchiveData item) {
return false;
}

private MigratedItemGroup handleError(IArchiveData item, String message, String category) {
private void handleError(IArchiveData item, String message, String category) {
migrationTrackerService.addFailedItem(new FailedItem(item, message, category));
return null;
}

private MigratedItemGroup handleTest(TestItem testItem) {
private void handleTest(TestItem testItem) {
migrationTrackerService.addTestItem(testItem);
return null;
}

private ExtractedMetadata convertToExtractedMetadata(CSVExemptionListData exemptionItem) {
// todo - this shouldn't be possible, remove ?
if (exemptionItem == null) {
loggingService.logWarning("Received NULL exemption item for conversion!");
return null;
Expand Down Expand Up @@ -308,20 +306,20 @@ private ExtractedMetadata convertToExtractedMetadata(CSVExemptionListData exempt
private void checkAndCreateNotifyItem(ExtractedMetadata extractedData) {
String defendantLastName = extractedData.getDefendantLastName();
String witnessFirstName = extractedData.getWitnessFirstName();
// Double-barrelled name checks
// Double-barreled name checks
if (defendantLastName != null && defendantLastName.contains("-")) {
migrationTrackerService.addNotifyItem(new NotifyItem("Double-barelled defendant",extractedData));
migrationTrackerService.addNotifyItem(new NotifyItem("Double-barreled defendant", extractedData));
}

if (witnessFirstName != null && witnessFirstName.contains("-")) {
migrationTrackerService.addNotifyItem(new NotifyItem("Double-barelled witness",extractedData));
migrationTrackerService.addNotifyItem(new NotifyItem("Double-barreled witness", extractedData));
}

String urn = extractedData.getUrn();
String exhibitRef = extractedData.getExhibitReference();
// case ref checks
if (urn == null || urn.isEmpty()) {
migrationTrackerService.addNotifyItem(new NotifyItem("Missing URN",extractedData));
migrationTrackerService.addNotifyItem(new NotifyItem("Missing URN", extractedData));
} else if (urn.length() < 11) {
migrationTrackerService.addNotifyItem(new NotifyItem("URN - invalid length", extractedData));
}
Expand All @@ -332,6 +330,5 @@ private void checkAndCreateNotifyItem(ExtractedMetadata extractedData) {
migrationTrackerService.addNotifyItem(new NotifyItem("T-ref - invalid length", extractedData));
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public void processRecording(CSVArchiveListData archiveItem) {
ProcessedRecording cleansedData = result.getData();

String key = cacheService.generateCacheKey(
"recording", "version",
cleansedData.getUrn(),
"recording",
"version",
cleansedData.getUrn(),
cleansedData.getExhibitReference(),
cleansedData.getDefendantLastName(),
cleansedData.getWitnessFirstName()
Expand All @@ -69,7 +70,7 @@ public void processRecording(CSVArchiveListData archiveItem) {
if (existingMetadata == null) {
existingMetadata = new HashMap<>();
}

// Update versioning info for this recording
RecordingUtils.MetadataUpdateResult metadataResult = RecordingUtils.updateVersionMetadata(
cleansedData.getRecordingVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public Object process(Object item) {
// =========================================
private void processSitesData(CSVSitesData sitesItem) {
cacheService.saveSiteReference(sitesItem.getSiteReference(), sitesItem.getCourtName());

}

// ==================================================
Expand All @@ -69,5 +68,4 @@ private String[] createChannelUserEntry(CSVChannelData channelData) {
channelData.getChannelUserEmail()
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public BatchConfiguration(
this.stepUtils = stepUtils;
}


@Bean
public Step createDeltaProcessingStep() {
return new StepBuilder("deltaProcessingStep", jobRepository)
Expand All @@ -122,7 +121,7 @@ public Step createDeltaProcessingStep() {
@JobScope
public Step createExemptionListStep() {
return stepUtils.buildChunkStep(
"excemptionListDataStep",
"exemptionListDataStep",
new ClassPathResource(EXCEMPTIONS_LIST_CSV),
new String[] {
"archive_name","create_time","duration","court_reference","urn",
Expand All @@ -136,8 +135,6 @@ public Step createExemptionListStep() {
);
}



@Bean
public Step createPreProcessStep() {
return new StepBuilder("preProcessStep", jobRepository)
Expand Down Expand Up @@ -200,7 +197,6 @@ public Step createRobotUserSignInStep() {
.build();
}


// =========================
// Utility and Helper Functions
// =========================
Expand All @@ -209,7 +205,7 @@ public Step createRobotUserSignInStep() {
public JobExecutionDecider deltaProcessingDecider() {
return (jobExecution, stepExecution) -> {
var migrationType = MigrationType.fromString(
(String) Objects.requireNonNull(jobExecution.getJobParameters().getString("migrationType"))
Objects.requireNonNull(jobExecution.getJobParameters().getString("migrationType"))
);

if (migrationType.equals(MigrationType.DELTA)) {
Expand All @@ -231,5 +227,4 @@ public JobExecutionDecider fileAvailabilityDecider() {
: new FlowExecutionStatus("FAILED");
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class FailedItem {
private IArchiveData item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class TestItem {
private CSVArchiveListData archiveItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public VersionDetails processVersioning(
String versionType = Optional.ofNullable(recordingVersion)
.map(String::toUpperCase)
.filter(Constants.VALID_VERSION_TYPES::contains)
.orElseThrow(() -> new IllegalArgumentException(
"Invalid recording version: " + recordingVersion
));
.orElseThrow(() -> new IllegalArgumentException(
"Invalid recording version: " + recordingVersion
));
String validVersionNumber = getValidVersionNumber(versionNumberStr);
int versionNumber = getRecordingVersionNumber(versionType);
boolean isMostRecent = isMostRecentVersion(versionType, validVersionNumber, dataMap);
Expand Down Expand Up @@ -125,5 +125,4 @@ public MetadataUpdateResult updateVersionMetadata(
}
return new MetadataUpdateResult(updatedMetadata, updated);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public abstract class BaseTask extends RobotUserTask {
public BaseTask(UserService userService,
UserAuthenticationService userAuthenticationService,
@Value("${cron-user-email}") String cronUserEmail,
JobLauncher jobLauncher, LoggingService loggingService,
JobLauncher jobLauncher,
LoggingService loggingService,
@Value("${migration.debug}") boolean debug,
@Value("${migration.dry-run:false}") boolean dryRun) {

Expand Down
Loading