Skip to content

Commit

Permalink
Mars receipt, null pointer exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedram-A-Keyvani committed Nov 12, 2024
1 parent 72aa346 commit 62597cd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public String performSubmissionToBioSamplesAndEna(
@RequestBody final String submissionPayload,
@RequestParam(value = "webinjwt") String webinJwt) {
try {
String webinToken;
if (webinJwt != null) {
webinToken = webinJwt;
} else {
if (webinJwt == null || webinJwt.isEmpty()) {
throw new RuntimeException("Webin Authentication Token is not provided");
}

Expand All @@ -62,7 +59,7 @@ public String performSubmissionToBioSamplesAndEna(
final IsaJson isaJson = this.objectMapper.readValue(submissionPayload, IsaJson.class);
final List<Study> studies = getStudies(isaJson);

final BiosampleAccessionsMap accessionsMap = this.bioSamplesSubmitter.createBioSamples(studies, webinToken);
final BiosampleAccessionsMap accessionsMap = this.bioSamplesSubmitter.createBioSamples(studies, webinJwt);
marsReceiptService.convertReceiptToMars(accessionsMap, isaJson);

return marsReceiptService.convertMarsReceiptToJson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String convertMarsReceiptToJson() {
}

public void setMarsReceiptErrors(String... errors) {
super.setMarsReceiptErrors(MarsErrorType.INTERNAL_SERVER_ERROR, errors);
super.setMarsReceiptErrors(MarsErrorType.INVALID_METADATA, errors);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String convertMarsReceiptToJson() {
}

public void setMarsReceiptErrors(String... errors) {
super.setMarsReceiptErrors(MarsErrorType.INTERNAL_SERVER_ERROR, errors);
super.setMarsReceiptErrors(MarsErrorType.INVALID_METADATA, errors);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ protected void buildMarsReceipt(
final List<String> info,
final List<String> errors,
final IsaJson isaJson) {
setMarsReceiptErrors(MarsErrorType.INVALID_METADATA, errors.toArray(String[]::new));
setMarsReceiptInfo(info.toArray(String[]::new));
final String[] errorArray = Optional.ofNullable(errors).orElse(new ArrayList<>()).toArray(String[]::new);
final String[] infoArray = Optional.ofNullable(info).orElse(new ArrayList<>()).toArray(String[]::new);

setMarsReceiptErrors(MarsErrorType.INVALID_METADATA, errorArray);
setMarsReceiptInfo(infoArray);
setMarsAccessions(
studiesAccessionsMap,
samplesAccessionsMap,
Expand Down Expand Up @@ -122,7 +125,7 @@ protected void setMarsAccessions(
if (studyAccessionMap.accession != null) {
marsAccessions.add(getStudyMarsAccession(studyAccessionMap));
}
if (samplesAccessionsMap != null) {
if (samplesAccessionsMap != null && study.materials != null) {
Optional.ofNullable(study.materials.samples)
.orElse(new ArrayList<>())
.forEach(
Expand All @@ -134,7 +137,7 @@ protected void setMarsAccessions(
}
});
}
if (sourcesAccessionsMap != null) {
if (sourcesAccessionsMap != null && study.materials != null) {
Optional.ofNullable(study.materials.sources)
.orElse(new ArrayList<>())
.forEach(
Expand All @@ -151,7 +154,7 @@ protected void setMarsAccessions(
.orElse(new ArrayList<>())
.forEach(
assay -> {
if (otherMaterialsAccessionsMap != null) {
if (otherMaterialsAccessionsMap != null && assay.materials != null) {
Optional.ofNullable(assay.materials.otherMaterials)
.orElse(new ArrayList<>())
.forEach(
Expand All @@ -167,8 +170,7 @@ protected void setMarsAccessions(
});
}
if (dataFilesAccessionsMap != null) {
Optional.ofNullable(
assay.dataFiles)
Optional.ofNullable(assay.dataFiles)
.orElse(new ArrayList<>())
.forEach(
dataFile -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

public enum MarsErrorType {
INVALID_METADATA,
INVALID_DATA,
INTERNAL_SERVER_ERROR;
INVALID_DATA;
}

0 comments on commit 62597cd

Please sign in to comment.