From 62597cd32666a8bed4ab2b6920a8b54dceacdce7 Mon Sep 17 00:00:00 2001 From: "Pedram A. Keyvani" Date: Tue, 12 Nov 2024 15:37:28 +0100 Subject: [PATCH] Mars receipt, null pointer exception handling --- .../BioSampleSubmissionController.java | 7 ++----- .../biosamples/service/MarsReceiptService.java | 2 +- .../ISAToSRA/sra/service/MarsReceiptService.java | 2 +- .../ISAToSRA/receipt/MarsReceiptProvider.java | 16 +++++++++------- .../receipt/marsmodel/MarsErrorType.java | 3 +-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/controller/BioSampleSubmissionController.java b/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/controller/BioSampleSubmissionController.java index 1149a1b..baf4ec5 100644 --- a/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/controller/BioSampleSubmissionController.java +++ b/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/controller/BioSampleSubmissionController.java @@ -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"); } @@ -62,7 +59,7 @@ public String performSubmissionToBioSamplesAndEna( final IsaJson isaJson = this.objectMapper.readValue(submissionPayload, IsaJson.class); final List 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(); diff --git a/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/service/MarsReceiptService.java b/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/service/MarsReceiptService.java index af5377d..9403eca 100644 --- a/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/service/MarsReceiptService.java +++ b/repository-services/isajson-biosamples/src/main/java/com/elixir/biohackaton/ISAToSRA/biosamples/service/MarsReceiptService.java @@ -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); } /** diff --git a/repository-services/isajson-ena/src/main/java/com/elixir/biohackaton/ISAToSRA/sra/service/MarsReceiptService.java b/repository-services/isajson-ena/src/main/java/com/elixir/biohackaton/ISAToSRA/sra/service/MarsReceiptService.java index 773d576..89327c8 100644 --- a/repository-services/isajson-ena/src/main/java/com/elixir/biohackaton/ISAToSRA/sra/service/MarsReceiptService.java +++ b/repository-services/isajson-ena/src/main/java/com/elixir/biohackaton/ISAToSRA/sra/service/MarsReceiptService.java @@ -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); } /** diff --git a/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/MarsReceiptProvider.java b/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/MarsReceiptProvider.java index 2abd944..086caf1 100644 --- a/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/MarsReceiptProvider.java +++ b/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/MarsReceiptProvider.java @@ -69,8 +69,11 @@ protected void buildMarsReceipt( final List info, final List 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, @@ -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( @@ -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( @@ -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( @@ -167,8 +170,7 @@ protected void setMarsAccessions( }); } if (dataFilesAccessionsMap != null) { - Optional.ofNullable( - assay.dataFiles) + Optional.ofNullable(assay.dataFiles) .orElse(new ArrayList<>()) .forEach( dataFile -> { diff --git a/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/marsmodel/MarsErrorType.java b/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/marsmodel/MarsErrorType.java index 14ff43b..8b55fc3 100644 --- a/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/marsmodel/MarsErrorType.java +++ b/repository-services/receipt/src/main/java/com/elixir/biohackaton/ISAToSRA/receipt/marsmodel/MarsErrorType.java @@ -2,6 +2,5 @@ public enum MarsErrorType { INVALID_METADATA, - INVALID_DATA, - INTERNAL_SERVER_ERROR; + INVALID_DATA; }