From e76103aa0ddd74663ae12b394aaccda9bd01f1ef Mon Sep 17 00:00:00 2001 From: Bruno Pacheco Date: Mon, 19 Aug 2024 23:50:40 +0200 Subject: [PATCH] chore: simplify error messages --- .../daam/api/AcceptTermsExceptionMapper.java | 2 +- .../daam/exceptions/AcceptTermsException.java | 6 +++--- .../exceptions/ApplicationNotFoundException.java | 8 ++++---- .../ApplicationNotInCorrectStateException.java | 8 ++++---- .../exceptions/ApplicationSubmissionException.java | 6 +++--- .../exceptions/AttachmentTooLargeException.java | 6 ++---- .../daam/exceptions/UserNotApplicantException.java | 8 ++++---- .../daam/gateways/RemsApiQueryGateway.java | 13 ++++++------- .../daam/services/AcceptTermsService.java | 2 +- .../daam/services/SubmitApplicationService.java | 2 +- .../daam/api/AcceptTermsTest.java | 4 ++-- .../daam/api/SubmitApplicationTest.java | 2 +- 12 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsExceptionMapper.java b/src/main/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsExceptionMapper.java index 2a19bb0..eb40991 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsExceptionMapper.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsExceptionMapper.java @@ -19,7 +19,7 @@ public class AcceptTermsExceptionMapper implements ExceptionMapper warnings; - public AcceptTermsException(Long applicationId, List warnings) { - super(String.format(MESSAGE, applicationId)); + public AcceptTermsException(List warnings) { + super(MESSAGE); this.warnings = ofNullable(warnings).orElseGet(List::of); } } diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotFoundException.java b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotFoundException.java index 83ed589..23095f0 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotFoundException.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotFoundException.java @@ -5,9 +5,9 @@ public class ApplicationNotFoundException extends RuntimeException { - private static final String MESSAGE = "Application %s not found."; + private static final String MESSAGE = "The application was not found."; - public ApplicationNotFoundException(Long applicationId) { - super(MESSAGE.formatted(applicationId)); + public ApplicationNotFoundException() { + super(MESSAGE); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotInCorrectStateException.java b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotInCorrectStateException.java index 44ddc9c..3996db6 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotInCorrectStateException.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationNotInCorrectStateException.java @@ -5,9 +5,9 @@ public class ApplicationNotInCorrectStateException extends RuntimeException { - private static final String MESSAGE = "Application %s is not in correct state: %s."; + private static final String MESSAGE = "The application is not in correct state: %s."; - public ApplicationNotInCorrectStateException(Long id, String state) { - super(MESSAGE.formatted(id, state)); + public ApplicationNotInCorrectStateException(String state) { + super(MESSAGE.formatted(state)); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationSubmissionException.java b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationSubmissionException.java index 39ad93e..f56fd32 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationSubmissionException.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/ApplicationSubmissionException.java @@ -13,11 +13,11 @@ @Getter public class ApplicationSubmissionException extends RuntimeException { - private static final String MESSAGE = "Application %s could not be submitted."; + private static final String MESSAGE = "The application could not be submitted."; private final transient List warnings; - public ApplicationSubmissionException(Long applicationId, List warnings) { - super(String.format(MESSAGE, applicationId)); + public ApplicationSubmissionException(List warnings) { + super(MESSAGE); this.warnings = ofNullable(warnings).orElseGet(List::of); } } diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/AttachmentTooLargeException.java b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/AttachmentTooLargeException.java index 52ca35e..dbbb64a 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/AttachmentTooLargeException.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/AttachmentTooLargeException.java @@ -4,13 +4,11 @@ package io.github.genomicdatainfrastructure.daam.exceptions; -import static java.lang.String.format; - public class AttachmentTooLargeException extends RuntimeException { - private static final String MESSAGE = "File %s is too big."; + private static final String MESSAGE = "The file %s is too big."; public AttachmentTooLargeException(String filename) { - super(format(MESSAGE, filename)); + super(MESSAGE.formatted(filename)); } } diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/UserNotApplicantException.java b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/UserNotApplicantException.java index 1a1e108..36c8b60 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/UserNotApplicantException.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/exceptions/UserNotApplicantException.java @@ -5,9 +5,9 @@ public class UserNotApplicantException extends RuntimeException { - private static final String MESSAGE = "User %s is not an applicant for application %s"; + private static final String MESSAGE = "The user %s is not an applicant."; - public UserNotApplicantException(Long applicationId, String userId) { - super(MESSAGE.formatted(userId, applicationId)); + public UserNotApplicantException(String userId) { + super(MESSAGE.formatted(userId)); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/gateways/RemsApiQueryGateway.java b/src/main/java/io/github/genomicdatainfrastructure/daam/gateways/RemsApiQueryGateway.java index 1156a85..edd5fc3 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/gateways/RemsApiQueryGateway.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/gateways/RemsApiQueryGateway.java @@ -4,19 +4,16 @@ package io.github.genomicdatainfrastructure.daam.gateways; -import static java.util.Comparator.comparing; -import static java.util.Optional.ofNullable; - import io.github.genomicdatainfrastructure.daam.exceptions.ApplicationNotFoundException; import io.github.genomicdatainfrastructure.daam.exceptions.ApplicationNotInCorrectStateException; import io.github.genomicdatainfrastructure.daam.exceptions.UserNotApplicantException; import io.github.genomicdatainfrastructure.daam.remote.rems.api.RemsApplicationQueryApi; import io.github.genomicdatainfrastructure.daam.remote.rems.api.RemsCatalogueItemQueryApi; import io.github.genomicdatainfrastructure.daam.remote.rems.model.Application; -import io.github.genomicdatainfrastructure.daam.remote.rems.model.Entitlement; import io.github.genomicdatainfrastructure.daam.remote.rems.model.Application.ApplicationStateEnum; import io.github.genomicdatainfrastructure.daam.remote.rems.model.ApplicationOverview; import io.github.genomicdatainfrastructure.daam.remote.rems.model.CatalogueItem; +import io.github.genomicdatainfrastructure.daam.remote.rems.model.Entitlement; import jakarta.enterprise.context.ApplicationScoped; import jakarta.ws.rs.WebApplicationException; import org.eclipse.microprofile.config.inject.ConfigProperty; @@ -25,6 +22,9 @@ import java.util.List; import java.util.Set; +import static java.util.Comparator.comparing; +import static java.util.Optional.ofNullable; + @ApplicationScoped public class RemsApiQueryGateway { @@ -54,7 +54,7 @@ public Application retrieveApplication(Long applicationId, String userId) { ); } catch (WebApplicationException e) { if (e.getResponse().getStatus() == 404) { - throw new ApplicationNotFoundException(applicationId); + throw new ApplicationNotFoundException(); } throw e; } @@ -73,12 +73,11 @@ public void checkIfApplicationIsEditableByUser(Long id, String userId) { var application = retrieveApplication(id, userId); if (!application.getApplicationApplicant().getUserid().equals(userId)) { - throw new UserNotApplicantException(id, userId); + throw new UserNotApplicantException(userId); } if (!EDITABLE_STATES.contains(application.getApplicationState())) { throw new ApplicationNotInCorrectStateException( - id, application.getApplicationState().value() ); } diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/services/AcceptTermsService.java b/src/main/java/io/github/genomicdatainfrastructure/daam/services/AcceptTermsService.java index f009977..31bec52 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/services/AcceptTermsService.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/services/AcceptTermsService.java @@ -70,7 +70,7 @@ public void acceptTerms(Long id, String userId, AcceptTermsCommand acceptTermsCo .build()) .toList(); - throw new AcceptTermsException(id, warnings); + throw new AcceptTermsException(warnings); } } } diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/services/SubmitApplicationService.java b/src/main/java/io/github/genomicdatainfrastructure/daam/services/SubmitApplicationService.java index 8a7a414..b722c50 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/services/SubmitApplicationService.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/services/SubmitApplicationService.java @@ -68,7 +68,7 @@ public void submitApplication(Long id, String userId) { .build()) .toList(); - throw new ApplicationSubmissionException(id, warnings); + throw new ApplicationSubmissionException(warnings); } } } diff --git a/src/test/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsTest.java b/src/test/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsTest.java index 6783b1b..ce602ab 100644 --- a/src/test/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsTest.java +++ b/src/test/java/io/github/genomicdatainfrastructure/daam/api/AcceptTermsTest.java @@ -87,8 +87,8 @@ void cannot_accept_terms_when_success_false() { var expected = ErrorResponse.builder() .status(400) - .title("Could not accept terms") - .detail("Terms and Licenses of application 44 could not be accepted.") + .title("Terms and Licenses could not be accepted") + .detail("Terms and Licenses could not be accepted.") .validationWarnings(List.of( ValidationWarning.builder() .key("dummy-error") diff --git a/src/test/java/io/github/genomicdatainfrastructure/daam/api/SubmitApplicationTest.java b/src/test/java/io/github/genomicdatainfrastructure/daam/api/SubmitApplicationTest.java index b4b8529..ba92205 100644 --- a/src/test/java/io/github/genomicdatainfrastructure/daam/api/SubmitApplicationTest.java +++ b/src/test/java/io/github/genomicdatainfrastructure/daam/api/SubmitApplicationTest.java @@ -83,7 +83,7 @@ void cannot_submit_application_due_to_submission_errors() { var expected = ErrorResponse.builder() .status(400) .title("Application could not be submitted") - .detail("Application 44 could not be submitted.") + .detail("The application could not be submitted.") .validationWarnings(List.of( ValidationWarning.builder() .key("Missing")