Skip to content

Commit

Permalink
Merge pull request #957 from Shreeja-dev/745-csv-error-scenarios
Browse files Browse the repository at this point in the history
fix: modified error message for invalid file prefix #745
  • Loading branch information
ratheesh-kr authored Dec 30, 2024
2 parents 121f806 + 4734c38 commit 5f9edd6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion hub-prime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>org.techbd</groupId>
<artifactId>hub-prime</artifactId>
<version>0.407.0</version>
<version>0.408.0</version>
<packaging>war</packaging>
<name>Tech by Design Hub (Prime)</name>
<description>Tech by Design Hub (Primary)</description>
Expand Down
12 changes: 10 additions & 2 deletions hub-prime/src/main/java/org/techbd/model/csv/FileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ public static FileType fromFilename(final String filename) {
if (filename == null) {
throw new IllegalArgumentException("Filename cannot be null");
}

String upperCaseFilename = filename.toUpperCase();
for (final FileType type : values()) {
if (upperCaseFilename.startsWith(type.name().toUpperCase())) {
return type;
}
}
throw new IllegalArgumentException("Unknown file type in filename: " + filename);
StringBuilder errorMessage = new StringBuilder("Invalid file prefix: ")
.append(filename)
.append(". Filenames must start with one of the following prefixes: ");
for (FileType type : values()) {
errorMessage.append(type.name()).append(", ");
}
errorMessage.setLength(errorMessage.length() - 2);
throw new IllegalArgumentException(errorMessage.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public List<OrchestrationSession> getSessions() {
return Collections.unmodifiableList(sessions);
}

public synchronized void orchestrate(@NotNull final OrchestrationSession... sessions) {
public synchronized void orchestrate(@NotNull final OrchestrationSession... sessions) throws Exception {
for (final OrchestrationSession session : sessions) {
this.sessions.add(session);
session.validate();
Expand Down Expand Up @@ -247,10 +247,9 @@ public Map<String, PayloadAndValidationOutcome> getPayloadAndValidationOutcomes(
return payloadAndValidationOutcomes;
}

public void validate() {
public void validate() throws IOException {
log.info("CsvOrchestrationEngine : validate - file : {} BEGIN for interaction id : {}",
file.getOriginalFilename(), masterInteractionId);
try {
final Instant intiatedAt = Instant.now();
final String originalFilename = file.getOriginalFilename();
final String uniqueFilename = masterInteractionId + "_"
Expand All @@ -265,17 +264,7 @@ public void validate() {
// Trigger CSV processing and validation
this.validationResults = processScreenings(masterInteractionId, intiatedAt, originalFilename, tenantId);
saveCombinedValidationResults(validationResults, masterInteractionId);
} catch (final IllegalArgumentException e) {
log.error("Validation Error", e);
this.validationResults = Map.of(
"status", "Error",
"message", "Validation Error: " + e.getMessage());
} catch (final Exception e) {
log.error("Unexpected system error", e);
this.validationResults = Map.of(
"status", "Error",
"message", "An unexpected system error occurred: " + e.getMessage());
}

}

private void saveScreeningGroup(final String groupInteractionId, final HttpServletRequest request,
Expand Down
7 changes: 0 additions & 7 deletions hub-prime/src/main/java/org/techbd/service/CsvService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@ public Object validateCsvFile(final MultipartFile file, final HttpServletRequest
.build();
engine.orchestrate(session);
return session.getValidationResults();
} catch (final Exception ex) {
LOG.error("Exception while processing file : {} ", file.getOriginalFilename(), ex);
} finally {
if (null == session) {
engine.clear(session);
}
}
return null;
}

private String getBundleInteractionId(final HttpServletRequest request) {
Expand Down Expand Up @@ -149,15 +146,11 @@ public List<Object> processZipFile(final MultipartFile file,final HttpServletReq
return csvBundleProcessorService.processPayload(masterInteractionId,
session.getPayloadAndValidationOutcomes(), request,
response,tenantId);
} catch (final Exception ex) {
LOG.error("Exception while processing file : {} ", file.getOriginalFilename(), ex);
} finally {
if (null == session) {
engine.clear(session);
}
}
return null;

}

}

0 comments on commit 5f9edd6

Please sign in to comment.