From 97659d3646243778cf549e7412072b2765092b20 Mon Sep 17 00:00:00 2001 From: cdeac Date: Wed, 31 Jan 2024 11:26:49 +0200 Subject: [PATCH 1/3] NUM-2160 upgrade to spring boot 3.2.2 and some cleanup --- pom.xml | 10 +++---- .../de/vitagroup/num/domain/dto/AqlDto.java | 7 +++-- .../num/domain/dto/ParameterOptionsDto.java | 1 + .../vitagroup/num/domain/dto/ProjectDto.java | 1 + .../num/domain/model/Organization.java | 1 + .../num/domain/model/admin/User.java | 1 - .../num/domain/model/admin/UserDetails.java | 1 + .../de/vitagroup/num/service/AqlService.java | 7 ++--- .../num/service/SetupHealthiness.java | 14 +++------- .../exception/CustomizedExceptionHandler.java | 28 ++++++++++++++++++- .../num/service/policy/EhrPolicy.java | 10 +++---- .../service/policy/EuropeanConsentPolicy.java | 1 - .../num/service/policy/TemplatesPolicy.java | 1 - .../num/web/controller/AqlController.java | 6 ++-- .../num/web/controller/CohortController.java | 9 +++--- .../controller/NumAttachmentController.java | 6 ++-- .../controller/OrganizationController.java | 10 +++---- .../num/web/controller/ProjectController.java | 20 ++++++------- .../num/TestNumPortalApplication.java | 3 -- .../service/AttachmentServiceTest.java | 14 ++-------- .../tests/IntegrationTest.java | 4 +-- .../num/service/EhrBaseServiceTest.java | 1 - .../num/service/ProjectServiceTest.java | 7 ----- .../notification/NotificationServiceTest.java | 14 +++++----- 24 files changed, 87 insertions(+), 90 deletions(-) diff --git a/pom.xml b/pom.xml index 6fa8c33ac..f9b96f3ea 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.8 + 3.2.2 @@ -21,7 +21,7 @@ 2.15.1 2.6.0 - 1.0.4 + 1.0.5-rc1 7.4 3.2.0 2.3.0 @@ -29,8 +29,8 @@ 1.10.0 0.8.11 9.0.8 - 3.2.2 - 3.2.2 + 3.2.5 + 3.2.5 3.10.8 4.9.10 false @@ -41,7 +41,7 @@ 3.2.0 1.19.3 false - 2022.0.3 + 2023.0.0 diff --git a/src/main/java/de/vitagroup/num/domain/dto/AqlDto.java b/src/main/java/de/vitagroup/num/domain/dto/AqlDto.java index 8bdb46250..4700a670f 100644 --- a/src/main/java/de/vitagroup/num/domain/dto/AqlDto.java +++ b/src/main/java/de/vitagroup/num/domain/dto/AqlDto.java @@ -18,7 +18,7 @@ @NoArgsConstructor public class AqlDto { - @Schema(description = "The unique identifier", example = "1") + @Schema(description = "The unique identifier", example = "1", accessMode = Schema.AccessMode.READ_ONLY) private Long id; @Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "The name of the aql") @@ -56,6 +56,7 @@ public class AqlDto { private String query; @Schema(description = "Flag marking aql as being public") + @Builder.Default private boolean publicAql = true; @Schema(description = "The owner of the aql", hidden = true) @@ -67,9 +68,9 @@ public class AqlDto { @Schema(description = "to for category data", hidden = true) private AqlCategoryDto category; - @Schema + @Schema(accessMode = Schema.AccessMode.READ_ONLY) private OffsetDateTime createDate; - @Schema + @Schema(accessMode = Schema.AccessMode.READ_ONLY) private OffsetDateTime modifiedDate; } diff --git a/src/main/java/de/vitagroup/num/domain/dto/ParameterOptionsDto.java b/src/main/java/de/vitagroup/num/domain/dto/ParameterOptionsDto.java index cf327daa0..4ac632ff0 100644 --- a/src/main/java/de/vitagroup/num/domain/dto/ParameterOptionsDto.java +++ b/src/main/java/de/vitagroup/num/domain/dto/ParameterOptionsDto.java @@ -16,6 +16,7 @@ @AllArgsConstructor public class ParameterOptionsDto { + @Builder.Default private Map options = new LinkedHashMap<>(); private String aqlPath; private String archetypeId; diff --git a/src/main/java/de/vitagroup/num/domain/dto/ProjectDto.java b/src/main/java/de/vitagroup/num/domain/dto/ProjectDto.java index 897174f8c..831138c55 100644 --- a/src/main/java/de/vitagroup/num/domain/dto/ProjectDto.java +++ b/src/main/java/de/vitagroup/num/domain/dto/ProjectDto.java @@ -27,6 +27,7 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class ProjectDto { + @Schema(accessMode = Schema.AccessMode.READ_ONLY) private Long id; @NotNull(message = "Project name cannot be null") diff --git a/src/main/java/de/vitagroup/num/domain/model/Organization.java b/src/main/java/de/vitagroup/num/domain/model/Organization.java index db2a35c1e..dd48d3d61 100644 --- a/src/main/java/de/vitagroup/num/domain/model/Organization.java +++ b/src/main/java/de/vitagroup/num/domain/model/Organization.java @@ -34,5 +34,6 @@ public class Organization implements Serializable { private Set domains = new HashSet<>(); @Column(nullable = false, columnDefinition = "BOOLEAN DEFAULT TRUE") + @Builder.Default private Boolean active = Boolean.TRUE; } diff --git a/src/main/java/de/vitagroup/num/domain/model/admin/User.java b/src/main/java/de/vitagroup/num/domain/model/admin/User.java index bb0865c61..9145c85a3 100644 --- a/src/main/java/de/vitagroup/num/domain/model/admin/User.java +++ b/src/main/java/de/vitagroup/num/domain/model/admin/User.java @@ -49,7 +49,6 @@ public class User { private String email; @NotNull - @NotEmpty @Schema(description = "The timestamp of user registration") private Long createdTimestamp; diff --git a/src/main/java/de/vitagroup/num/domain/model/admin/UserDetails.java b/src/main/java/de/vitagroup/num/domain/model/admin/UserDetails.java index 67b7e7638..1131a9661 100644 --- a/src/main/java/de/vitagroup/num/domain/model/admin/UserDetails.java +++ b/src/main/java/de/vitagroup/num/domain/model/admin/UserDetails.java @@ -26,6 +26,7 @@ public class UserDetails implements Serializable { @JoinColumn(name = "organization_id") private Organization organization; + @Builder.Default private boolean approved = false; private LocalDateTime createdDate; diff --git a/src/main/java/de/vitagroup/num/service/AqlService.java b/src/main/java/de/vitagroup/num/service/AqlService.java index 5e94b172f..ff05b4203 100644 --- a/src/main/java/de/vitagroup/num/service/AqlService.java +++ b/src/main/java/de/vitagroup/num/service/AqlService.java @@ -2,14 +2,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import de.vitagroup.num.domain.dto.Language; +import de.vitagroup.num.domain.dto.SearchCriteria; +import de.vitagroup.num.domain.dto.SlimAqlDto; import de.vitagroup.num.domain.model.Aql; import de.vitagroup.num.domain.model.AqlCategory; import de.vitagroup.num.domain.model.Roles; import de.vitagroup.num.domain.model.admin.User; import de.vitagroup.num.domain.model.admin.UserDetails; -import de.vitagroup.num.domain.dto.Language; -import de.vitagroup.num.domain.dto.SearchCriteria; -import de.vitagroup.num.domain.dto.SlimAqlDto; import de.vitagroup.num.domain.repository.AqlCategoryRepository; import de.vitagroup.num.domain.repository.AqlRepository; import de.vitagroup.num.domain.specification.AqlSpecification; @@ -26,7 +26,6 @@ import org.ehrbase.aqleditor.dto.aql.Result; import org.ehrbase.aqleditor.service.AqlEditorAqlService; import org.ehrbase.openehr.sdk.aql.parser.AqlParseException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.domain.*; import org.springframework.data.jpa.domain.JpaSort; diff --git a/src/main/java/de/vitagroup/num/service/SetupHealthiness.java b/src/main/java/de/vitagroup/num/service/SetupHealthiness.java index 58033081b..d26d52036 100644 --- a/src/main/java/de/vitagroup/num/service/SetupHealthiness.java +++ b/src/main/java/de/vitagroup/num/service/SetupHealthiness.java @@ -11,22 +11,16 @@ import org.springframework.stereotype.Service; import java.io.IOException; -import java.net.*; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; +import java.net.HttpURLConnection; +import java.net.URISyntaxException; +import java.net.URL; import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.time.temporal.TemporalAmount; -import java.time.temporal.TemporalUnit; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.ANNOUNCEMENT_IN_PLACE; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.EXCEPTION_HAPPENED_IN_CLASS_FOR_ENVIRONMENT; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.EXCEPTION_IN_PARSING_PAGE; +import static de.vitagroup.num.domain.templates.ExceptionsTemplate.*; @Slf4j @Service diff --git a/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java b/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java index 9ce886acb..bc275150d 100644 --- a/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java +++ b/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java @@ -8,10 +8,11 @@ import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.security.access.AccessDeniedException; -import org.springframework.validation.BindException; +import org.springframework.validation.method.ParameterErrors; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; +import org.springframework.web.method.annotation.HandlerMethodValidationException; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import java.util.*; @@ -314,4 +315,29 @@ protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotV .build(); return ResponseEntity.status( HttpStatus.BAD_REQUEST ).body( errorDetails ); } + + @Override + protected ResponseEntity handleHandlerMethodValidationException(HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { + Map errors = new HashMap<>(); + for (final var validation : ex.getAllValidationResults()) { + if (validation instanceof ParameterErrors) { + ParameterErrors parameterErrors = (ParameterErrors) validation; + parameterErrors.getFieldErrors().forEach(fieldError -> { + errors.put(fieldError.getField(), fieldError.getDefaultMessage()); + }); + } else { + final String parameterName = validation.getMethodParameter().getParameterName(); + validation + .getResolvableErrors() + .forEach( + error -> errors.put(parameterName, error.getDefaultMessage())); + } + } + ErrorDetails errorDetails = ErrorDetails + .builder() + .message("Validation failed") + .details(errors) + .build(); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorDetails); + } } diff --git a/src/main/java/de/vitagroup/num/service/policy/EhrPolicy.java b/src/main/java/de/vitagroup/num/service/policy/EhrPolicy.java index 35dce83fe..a661e51c4 100644 --- a/src/main/java/de/vitagroup/num/service/policy/EhrPolicy.java +++ b/src/main/java/de/vitagroup/num/service/policy/EhrPolicy.java @@ -1,11 +1,6 @@ package de.vitagroup.num.service.policy; import de.vitagroup.num.service.exception.SystemException; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - import de.vitagroup.num.service.util.AqlQueryConstants; import lombok.Builder; import lombok.extern.slf4j.Slf4j; @@ -15,7 +10,10 @@ import org.ehrbase.openehr.sdk.aql.dto.operand.IdentifiedPath; import org.ehrbase.openehr.sdk.aql.dto.path.AqlObjectPath; import org.ehrbase.openehr.sdk.aql.dto.select.SelectExpression; -import org.ehrbase.openehr.sdk.aql.render.AqlRenderer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; import static de.vitagroup.num.domain.templates.ExceptionsTemplate.COHORT_SIZE_CANNOT_BE_0; import static de.vitagroup.num.domain.templates.ExceptionsTemplate.INVALID_AQL; diff --git a/src/main/java/de/vitagroup/num/service/policy/EuropeanConsentPolicy.java b/src/main/java/de/vitagroup/num/service/policy/EuropeanConsentPolicy.java index 03cc125a5..3d19ee82b 100644 --- a/src/main/java/de/vitagroup/num/service/policy/EuropeanConsentPolicy.java +++ b/src/main/java/de/vitagroup/num/service/policy/EuropeanConsentPolicy.java @@ -5,7 +5,6 @@ import lombok.extern.slf4j.Slf4j; import org.ehrbase.openehr.sdk.aql.dto.AqlQuery; import org.ehrbase.openehr.sdk.aql.dto.operand.Primitive; -import org.ehrbase.openehr.sdk.aql.render.AqlRenderer; import java.util.List; diff --git a/src/main/java/de/vitagroup/num/service/policy/TemplatesPolicy.java b/src/main/java/de/vitagroup/num/service/policy/TemplatesPolicy.java index 5744f2872..6cca17977 100644 --- a/src/main/java/de/vitagroup/num/service/policy/TemplatesPolicy.java +++ b/src/main/java/de/vitagroup/num/service/policy/TemplatesPolicy.java @@ -6,7 +6,6 @@ import org.apache.commons.collections.MapUtils; import org.ehrbase.openehr.sdk.aql.dto.AqlQuery; import org.ehrbase.openehr.sdk.aql.dto.operand.Primitive; -import org.ehrbase.openehr.sdk.aql.render.AqlRenderer; import java.util.List; import java.util.Map; diff --git a/src/main/java/de/vitagroup/num/web/controller/AqlController.java b/src/main/java/de/vitagroup/num/web/controller/AqlController.java index cd0f7d22a..ad91ab837 100644 --- a/src/main/java/de/vitagroup/num/web/controller/AqlController.java +++ b/src/main/java/de/vitagroup/num/web/controller/AqlController.java @@ -46,7 +46,7 @@ public class AqlController extends CustomizedExceptionHandler { @Operation(description = "Retrieves public or owned aql query by id.") @PreAuthorize(Role.MANAGER_OR_STUDY_COORDINATOR_OR_RESEARCHER_OR_CRITERIA_EDITOR) public ResponseEntity getAqlById( - @AuthenticationPrincipal @NotNull Jwt principal, @NotNull @NotEmpty @PathVariable Long id) { + @AuthenticationPrincipal @NotNull Jwt principal, @NotNull @PathVariable Long id) { return ResponseEntity.ok( mapper.convertToDto(aqlService.getAqlById(id, principal.getSubject()))); } @@ -68,7 +68,7 @@ public ResponseEntity createAql( @PreAuthorize(Role.CRITERIA_EDITOR) public ResponseEntity updateAql( @AuthenticationPrincipal @NotNull Jwt principal, - @PathVariable("id") Long aqlId, + @NotNull @PathVariable("id") Long aqlId, @Valid @NotNull @RequestBody AqlDto aqlDto) { var aql = aqlService.updateAql(mapper.convertToEntity(aqlDto), aqlId, principal.getSubject(), aqlDto.getCategoryId()); @@ -79,7 +79,7 @@ public ResponseEntity updateAql( @DeleteMapping("/{id}") @Operation(description = "Delete AQL criteria") @PreAuthorize(Role.CRITERIA_EDITOR_OR_SUPER_ADMIN) - public void deleteAql(@AuthenticationPrincipal @NotNull Jwt principal, @PathVariable Long id) { + public void deleteAql(@AuthenticationPrincipal @NotNull Jwt principal, @NotNull @PathVariable Long id) { aqlService.deleteById(id, principal.getSubject(), Roles.extractRoles(principal)); } diff --git a/src/main/java/de/vitagroup/num/web/controller/CohortController.java b/src/main/java/de/vitagroup/num/web/controller/CohortController.java index 685563b06..f8ec96791 100644 --- a/src/main/java/de/vitagroup/num/web/controller/CohortController.java +++ b/src/main/java/de/vitagroup/num/web/controller/CohortController.java @@ -1,11 +1,11 @@ package de.vitagroup.num.web.controller; -import de.vitagroup.num.domain.model.Cohort; -import de.vitagroup.num.domain.model.Roles; import de.vitagroup.num.domain.dto.CohortDto; import de.vitagroup.num.domain.dto.CohortGroupDto; import de.vitagroup.num.domain.dto.CohortSizeDto; import de.vitagroup.num.domain.dto.TemplateSizeRequestDto; +import de.vitagroup.num.domain.model.Cohort; +import de.vitagroup.num.domain.model.Roles; import de.vitagroup.num.mapper.CohortMapper; import de.vitagroup.num.service.CohortService; import de.vitagroup.num.service.exception.CustomizedExceptionHandler; @@ -14,10 +14,11 @@ import de.vitagroup.num.web.config.Role; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; @@ -27,8 +28,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.WebRequest; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Collectors; diff --git a/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java b/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java index 2c9ab7d96..e819ac130 100644 --- a/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java +++ b/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java @@ -52,7 +52,7 @@ public ResponseEntity createAttachment(@AuthenticationPrincipal @NotNull @PreAuthorize(Role.STUDY_COORDINATOR) @PostMapping(path = "/{projectId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity createMultipleAttachments(@AuthenticationPrincipal @NotNull Jwt principal, - @NotNull @NotEmpty @PathVariable Long projectId, + @NotNull @PathVariable Long projectId, @ModelAttribute @Valid LightAttachmentDto lightDto) throws IOException { attachmentService.saveAttachments(projectId, principal.getSubject(), lightDto, false); return ResponseEntity.ok("ok"); @@ -61,7 +61,7 @@ public ResponseEntity createMultipleAttachments(@AuthenticationPrincipal @AuditLog(description = "Get a list of all attachments for one project (by projectId)") @Operation(description = "Get a list of all attachments for one project (by projectId)") @GetMapping("/project/{projectId}") - public ResponseEntity> listAllAttachments(@NotNull @NotEmpty @PathVariable Long projectId) { + public ResponseEntity> listAllAttachments(@NotNull @PathVariable Long projectId) { return ResponseEntity.ok(attachmentService.getAttachmentsBy(projectId).stream() .map(attachment -> modelMapper.map(attachment, AttachmentDto.class)) .collect(Collectors.toList())); @@ -89,7 +89,7 @@ public void deleteAql(@AuthenticationPrincipal @NotNull Jwt principal, @PathVari @AuditLog(description = "Download attachment") @Operation(description = "Download attachment with given id") @GetMapping("/{attachmentId}") - public ResponseEntity downloadAttachment(@NotNull @NotEmpty @PathVariable Long attachmentId) { + public ResponseEntity downloadAttachment(@NotNull @PathVariable Long attachmentId) { Attachment attachment = attachmentService.getAttachmentById(attachmentId); HttpHeaders header = new HttpHeaders(); header.setContentDisposition(ContentDisposition.builder("attachment").filename(attachment.getName()).build()); diff --git a/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java b/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java index 617dbea48..b13f90c72 100644 --- a/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java +++ b/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java @@ -47,8 +47,7 @@ public ResponseEntity> getAllMailDomainsForActiveOrganizations() { @AuditLog @GetMapping("/{id}") @Operation(description = "Retrieves an organization by external id") - public ResponseEntity getOrganizationById( - @NotNull @NotEmpty @PathVariable Long id) { + public ResponseEntity getOrganizationById(@NotNull @PathVariable Long id) { return ResponseEntity.ok(mapper.convertToDto(organizationService.getOrganizationById(id))); } @@ -102,9 +101,8 @@ public ResponseEntity createOrganization( @PutMapping(value = "/{id}") @Operation(description = "Updates an organization") @PreAuthorize(Role.SUPER_ADMIN_OR_ORGANIZATION_ADMIN) - public ResponseEntity updateOrganization( - @AuthenticationPrincipal @NotNull Jwt principal, - @PathVariable("id") Long organizationId, + public ResponseEntity updateOrganization(@AuthenticationPrincipal @NotNull Jwt principal, + @NotNull @PathVariable("id") Long organizationId, @Valid @NotNull @RequestBody OrganizationDto organizationDto) { return ResponseEntity.ok( mapper.convertToDto( @@ -120,7 +118,7 @@ public ResponseEntity updateOrganization( @DeleteMapping(value = "/{id}") @PreAuthorize(Role.SUPER_ADMIN) public void deleteOrganization(@AuthenticationPrincipal @NotNull Jwt principal, - @PathVariable("id") Long organizationId) { + @NotNull @PathVariable("id") Long organizationId) { organizationService.deleteOrganization(organizationId, principal.getSubject()); } } diff --git a/src/main/java/de/vitagroup/num/web/controller/ProjectController.java b/src/main/java/de/vitagroup/num/web/controller/ProjectController.java index 853e62527..88ca18168 100644 --- a/src/main/java/de/vitagroup/num/web/controller/ProjectController.java +++ b/src/main/java/de/vitagroup/num/web/controller/ProjectController.java @@ -76,7 +76,7 @@ public ResponseEntity> getProjects(@AuthenticationPrincipal @Operation(description = "Retrieves a project by id") @PreAuthorize(Role.STUDY_COORDINATOR_OR_RESEARCHER_OR_APPROVER) public ResponseEntity getProjectById(@AuthenticationPrincipal @NotNull Jwt principal, - @NotNull @NotEmpty @PathVariable Long id) { + @NotNull @PathVariable Long id) { Optional project = projectService.getProjectById(principal.getSubject(), id); if (project.isEmpty()) { @@ -161,7 +161,7 @@ public ResponseEntity updateMultipartProject( public ResponseEntity executeAql( @AuthenticationPrincipal @NotNull Jwt principal, @RequestBody @Valid RawQueryDto query, - @NotNull @NotEmpty @PathVariable Long projectId, + @NotNull @PathVariable Long projectId, @RequestParam(required = false) Boolean defaultConfiguration) { return ResponseEntity.ok( projectService.retrieveData( @@ -190,7 +190,7 @@ public ResponseEntity executeManagerProject( public ResponseEntity exportResults( @AuthenticationPrincipal @NotNull Jwt principal, @RequestBody @Valid RawQueryDto query, - @NotNull @NotEmpty @PathVariable Long projectId, + @NotNull @PathVariable Long projectId, @RequestParam(required = false) Boolean defaultConfiguration, @RequestParam(required = false) @Parameter( description = "A string defining the output format. Valid values are 'csv' and 'json'. Default is csv.") @@ -228,7 +228,7 @@ public ResponseEntity exportManagerResults( @PreAuthorize(Role.STUDY_COORDINATOR_OR_RESEARCHER_OR_APPROVER) public ResponseEntity> getComments( @AuthenticationPrincipal @NotNull Jwt principal, - @NotNull @NotEmpty @PathVariable Long projectId) { + @NotNull @PathVariable Long projectId) { return ResponseEntity.ok( commentService.getComments(projectId, principal.getSubject()).stream() .map(commentMapper::convertToDto) @@ -241,8 +241,8 @@ public ResponseEntity> getComments( @PreAuthorize(Role.STUDY_COORDINATOR_OR_RESEARCHER_OR_APPROVER) public ResponseEntity addComment( @AuthenticationPrincipal @NotNull Jwt principal, - @NotNull @NotEmpty @PathVariable Long projectId, - @Valid @NotNull @RequestBody CommentDto commentDto) { + @NotNull @PathVariable Long projectId, + @Valid @RequestBody CommentDto commentDto) { Comment comment = commentService.createComment( @@ -257,8 +257,8 @@ public ResponseEntity addComment( @PreAuthorize(Role.STUDY_COORDINATOR_OR_RESEARCHER_OR_APPROVER) public ResponseEntity updateComment( @AuthenticationPrincipal @NotNull Jwt principal, - @NotNull @NotEmpty @PathVariable Long projectId, - @NotNull @NotEmpty @PathVariable Long commentId, + @NotNull @PathVariable Long projectId, + @NotNull @PathVariable Long commentId, @Valid @NotNull @RequestBody CommentDto commentDto) { Comment comment = @@ -276,8 +276,8 @@ public ResponseEntity updateComment( @PreAuthorize(Role.STUDY_COORDINATOR_OR_RESEARCHER_OR_APPROVER) public void deleteComment( @AuthenticationPrincipal @NotNull Jwt principal, - @NotNull @NotEmpty @PathVariable Long projectId, - @NotNull @NotEmpty @PathVariable Long commentId) { + @NotNull @PathVariable Long projectId, + @NotNull @PathVariable Long commentId) { commentService.deleteComment(commentId, projectId, principal.getSubject()); } diff --git a/src/test/java/de/vitagroup/num/TestNumPortalApplication.java b/src/test/java/de/vitagroup/num/TestNumPortalApplication.java index d284fa3b6..b147179cb 100644 --- a/src/test/java/de/vitagroup/num/TestNumPortalApplication.java +++ b/src/test/java/de/vitagroup/num/TestNumPortalApplication.java @@ -1,7 +1,5 @@ package de.vitagroup.num; -import de.vitagroup.num.config.database.NumAttachmentFlywayConfig; -import de.vitagroup.num.config.database.NumPortalAttachmentDatasourceConfiguration; import de.vitagroup.num.listeners.UserCacheInit; import de.vitagroup.num.service.atna.AtnaProperties; import org.springframework.boot.SpringApplication; @@ -9,7 +7,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableAsync; @SpringBootApplication diff --git a/src/test/java/de/vitagroup/num/attachment/service/AttachmentServiceTest.java b/src/test/java/de/vitagroup/num/attachment/service/AttachmentServiceTest.java index 981a14135..0290adcda 100644 --- a/src/test/java/de/vitagroup/num/attachment/service/AttachmentServiceTest.java +++ b/src/test/java/de/vitagroup/num/attachment/service/AttachmentServiceTest.java @@ -4,13 +4,12 @@ import de.vitagroup.num.attachment.domain.dto.AttachmentDto; import de.vitagroup.num.attachment.domain.dto.LightAttachmentDto; import de.vitagroup.num.attachment.domain.model.Attachment; -import de.vitagroup.num.service.exception.ForbiddenException; import de.vitagroup.num.domain.model.Project; import de.vitagroup.num.domain.model.ProjectStatus; import de.vitagroup.num.domain.model.admin.UserDetails; -import de.vitagroup.num.domain.repository.ProjectRepository; import de.vitagroup.num.service.ProjectService; import de.vitagroup.num.service.exception.BadRequestException; +import de.vitagroup.num.service.exception.ForbiddenException; import de.vitagroup.num.service.exception.ResourceNotFound; import org.junit.Assert; import org.junit.Before; @@ -25,19 +24,12 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; -import java.util.List; import java.util.LinkedHashSet; +import java.util.List; import java.util.Optional; import java.util.Set; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.ATTACHMENT_LIMIT_REACHED; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.DESCRIPTION_TOO_LONG; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.DOCUMENT_TYPE_MISMATCH; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.INVALID_FILE_MISSING_CONTENT; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.PDF_FILES_ARE_NOT_ATTACHED; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.PDF_FILE_SIZE_EXCEEDED; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.PROJECT_NOT_FOUND; -import static de.vitagroup.num.domain.templates.ExceptionsTemplate.WRONG_PROJECT_STATUS; +import static de.vitagroup.num.domain.templates.ExceptionsTemplate.*; @RunWith(MockitoJUnitRunner.class) public class AttachmentServiceTest { diff --git a/src/test/java/de/vitagroup/num/integrationtesting/tests/IntegrationTest.java b/src/test/java/de/vitagroup/num/integrationtesting/tests/IntegrationTest.java index f19c7bf13..d532fac68 100644 --- a/src/test/java/de/vitagroup/num/integrationtesting/tests/IntegrationTest.java +++ b/src/test/java/de/vitagroup/num/integrationtesting/tests/IntegrationTest.java @@ -42,10 +42,10 @@ public abstract class IntegrationTest { private static final String EHR_BASE_URL = "/ehrbase/rest/openehr/v1/definition/template/adl1.4/"; @ClassRule - public static PostgreSQLContainer postgreSQLContainer = NumPostgresqlContainer.getInstance("numportal"); + public static PostgreSQLContainer postgreSQLContainer = NumPostgresqlContainer.getInstance("numportal"); @ClassRule - public static PostgreSQLContainer attachmentPostgreSQLContainer = AttachmentPostgresqlContainer.getInstance("num-attachment"); + public static PostgreSQLContainer attachmentPostgreSQLContainer = AttachmentPostgresqlContainer.getInstance("num-attachment"); @Autowired public MockMvc mockMvc; @Rule public WireMockRule wireMockRule = new WireMockRule(8099); diff --git a/src/test/java/de/vitagroup/num/service/EhrBaseServiceTest.java b/src/test/java/de/vitagroup/num/service/EhrBaseServiceTest.java index 983ab7d48..35439ff21 100644 --- a/src/test/java/de/vitagroup/num/service/EhrBaseServiceTest.java +++ b/src/test/java/de/vitagroup/num/service/EhrBaseServiceTest.java @@ -9,7 +9,6 @@ import org.ehrbase.openehr.sdk.aql.parser.AqlParseException; import org.ehrbase.openehr.sdk.aql.parser.AqlQueryParser; import org.ehrbase.openehr.sdk.client.openehrclient.defaultrestclient.DefaultRestClient; -import org.ehrbase.openehr.sdk.generator.commons.aql.field.AqlFieldImp; import org.ehrbase.openehr.sdk.generator.commons.aql.query.NativeQuery; import org.ehrbase.openehr.sdk.generator.commons.aql.query.Query; import org.ehrbase.openehr.sdk.generator.commons.aql.record.Record; diff --git a/src/test/java/de/vitagroup/num/service/ProjectServiceTest.java b/src/test/java/de/vitagroup/num/service/ProjectServiceTest.java index b54b2c678..1d124572b 100644 --- a/src/test/java/de/vitagroup/num/service/ProjectServiceTest.java +++ b/src/test/java/de/vitagroup/num/service/ProjectServiceTest.java @@ -165,19 +165,12 @@ public void shouldCorrectlyValidateInvalidQuery() { } @Test - @Ignore( - value = "This should pass when https://github.com/ehrbase/openEHR_SDK/issues/216 is fixed") public void shouldCorrectlyGenerateAliases() { String query = "Select c0 as F1 from EHR e contains COMPOSITION c0[openEHR-EHR-COMPOSITION.report.v1]"; AqlQuery dto = AqlQueryParser.parse(query); -// SelectFieldDto selectFieldDto = new SelectFieldDto(); -// selectFieldDto.setAqlPath(EhrFields.EHR_ID().getPath()); -// selectFieldDto.setContainmentId(dto.getEhr().getContainmentId()); -// dto.getSelect().getStatement().add(0, selectFieldDto); - String editedQuery = AqlRenderer.render(dto); Matcher matcher = Pattern.compile("F1").matcher(editedQuery); diff --git a/src/test/java/de/vitagroup/num/service/notification/NotificationServiceTest.java b/src/test/java/de/vitagroup/num/service/notification/NotificationServiceTest.java index c0c234bac..977561cd3 100644 --- a/src/test/java/de/vitagroup/num/service/notification/NotificationServiceTest.java +++ b/src/test/java/de/vitagroup/num/service/notification/NotificationServiceTest.java @@ -12,8 +12,10 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import java.util.Arrays; @@ -38,15 +40,14 @@ public class NotificationServiceTest { @Before public void setUp() { - when((messageSource.getMessage(any()))).thenReturn("Any content"); + when((numProperties.getUrl())).thenReturn("https://dev.num-codex.de/home"); + when(messageSource.getMessage(any())).thenReturn("Any content"); when((messageSource.getMessage(anyString(), any()))).thenReturn("Any content"); when((messageSource.getMessage(any(), any(), any(), any(), any(), any(),any()))).thenReturn("Any content"); } @Test public void shouldSendOneEmailPerNotification() { - when((numProperties.getUrl())).thenReturn("Portal url"); - notificationService.send( List.of( AccountApprovalNotification.builder().recipientEmail("john.doe@vita.ag").build(), @@ -57,8 +58,7 @@ public void shouldSendOneEmailPerNotification() { @Test public void shouldSendEmailsPerNotification() { - when((numProperties.getUrl())).thenReturn("Portal url"); - + when(messageSource.getMessage(anyString(), any(Object[].class))).thenReturn("Another body content"); notificationService.send( List.of( ProjectStartNotification.builder().recipientEmail("john.doe@vita.ag").build(), @@ -100,8 +100,7 @@ public void shouldSendEmailsPerNotification() { @Test public void shouldNotSendEmailsWhenRecipientMissing() { - when((numProperties.getUrl())).thenReturn("Portal url"); - + when(messageSource.getMessage(Mockito.eq("mail.project-pending-approval.body"), any(Object[].class))).thenReturn("Any body content"); notificationService.send( List.of( ProjectStartNotification.builder().build(), @@ -109,6 +108,7 @@ public void shouldNotSendEmailsWhenRecipientMissing() { ProjectStatusChangeNotification.builder().build(), ProjectApprovalRequestNotification.builder() .recipientEmail("ann.doe@vita.ag") + .projectId(9L) .build())); verify(emailService, times(1)).sendEmail(anyString(), anyString(), anyString()); From e379400710b185eb41ca678816ed8c698eb142f0 Mon Sep 17 00:00:00 2001 From: cdeac Date: Wed, 31 Jan 2024 14:17:53 +0200 Subject: [PATCH 2/3] fix sonar complaints --- .../num/service/exception/CustomizedExceptionHandler.java | 4 +--- .../vitagroup/num/web/controller/NumAttachmentController.java | 1 - .../vitagroup/num/web/controller/OrganizationController.java | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java b/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java index bc275150d..6d9375653 100644 --- a/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java +++ b/src/main/java/de/vitagroup/num/service/exception/CustomizedExceptionHandler.java @@ -322,9 +322,7 @@ protected ResponseEntity handleHandlerMethodValidationException(HandlerM for (final var validation : ex.getAllValidationResults()) { if (validation instanceof ParameterErrors) { ParameterErrors parameterErrors = (ParameterErrors) validation; - parameterErrors.getFieldErrors().forEach(fieldError -> { - errors.put(fieldError.getField(), fieldError.getDefaultMessage()); - }); + parameterErrors.getFieldErrors().forEach(fieldError -> errors.put(fieldError.getField(), fieldError.getDefaultMessage())); } else { final String parameterName = validation.getMethodParameter().getParameterName(); validation diff --git a/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java b/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java index e819ac130..fa0c173f7 100644 --- a/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java +++ b/src/main/java/de/vitagroup/num/web/controller/NumAttachmentController.java @@ -21,7 +21,6 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import java.io.IOException; import java.util.List; diff --git a/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java b/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java index b13f90c72..756a417c5 100644 --- a/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java +++ b/src/main/java/de/vitagroup/num/web/controller/OrganizationController.java @@ -23,7 +23,6 @@ import org.springframework.web.bind.annotation.*; import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import java.util.List; import java.util.stream.Collectors; From b2e8b88c65da2e2c3b5e5b9f6d22ede58d6b721c Mon Sep 17 00:00:00 2001 From: cdeac Date: Wed, 31 Jan 2024 14:43:10 +0200 Subject: [PATCH 3/3] use latest num-aql-editor 1.0.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f9b96f3ea..8b91b9a3f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 2.15.1 2.6.0 - 1.0.5-rc1 + 1.0.5 7.4 3.2.0 2.3.0