Skip to content

Commit

Permalink
Merge pull request #458 from NUM-Forschungsdatenplattform/feature/NUM…
Browse files Browse the repository at this point in the history
…-2160-upgrade-to-spring-boot-3-2

NUM-2160 upgrade to spring boot 3.2.2 and some cleanup
  • Loading branch information
crisdelta authored Jan 31, 2024
2 parents 44daa5b + b2e8b88 commit 01e08aa
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 92 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.8</version>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -21,16 +21,16 @@
<commons-io.version>2.15.1</commons-io.version>
<ehr-sdk.version>2.6.0</ehr-sdk.version>
<!-- aql-editor-backend-starter repo was archived on August 2023 -->
<num-aql-editor-backend-starter.version>1.0.4</num-aql-editor-backend-starter.version>
<num-aql-editor-backend-starter.version>1.0.5</num-aql-editor-backend-starter.version>
<logstash-logback-encoder.version>7.4</logstash-logback-encoder.version>
<modelmapper.version>3.2.0</modelmapper.version>
<springdoc.version>2.3.0</springdoc.version>
<java.version>17</java.version>
<commons-csv.version>1.10.0</commons-csv.version>
<jacoco.version>0.8.11</jacoco.version>
<dependency-check.version>9.0.8</dependency-check.version>
<failsafe.version>3.2.2</failsafe.version>
<surefire.version>3.2.2</surefire.version>
<failsafe.version>3.2.5</failsafe.version>
<surefire.version>3.2.5</surefire.version>
<ehcache.version>3.10.8</ehcache.version>
<git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
<skip.integration.tests>false</skip.integration.tests>
Expand All @@ -41,7 +41,7 @@
<wiremock-standalone.version>3.2.0</wiremock-standalone.version>
<testcontainers.version>1.19.3</testcontainers.version>
<ossindexAnalyzerEnabled>false</ossindexAnalyzerEnabled>
<spring.cloud-version>2022.0.3</spring.cloud-version>
<spring.cloud-version>2023.0.0</spring.cloud-version>
</properties>

<repositories>
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/de/vitagroup/num/domain/dto/AqlDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@AllArgsConstructor
public class ParameterOptionsDto {

@Builder.Default
private Map<String, Object> options = new LinkedHashMap<>();
private String aqlPath;
private String archetypeId;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/vitagroup/num/domain/dto/ProjectDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ public class Organization implements Serializable {
private Set<MailDomain> domains = new HashSet<>();

@Column(nullable = false, columnDefinition = "BOOLEAN DEFAULT TRUE")
@Builder.Default
private Boolean active = Boolean.TRUE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class User {
private String email;

@NotNull
@NotEmpty
@Schema(description = "The timestamp of user registration")
private Long createdTimestamp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/de/vitagroup/num/service/AqlService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/de/vitagroup/num/service/SetupHealthiness.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -314,4 +315,27 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotV
.build();
return ResponseEntity.status( HttpStatus.BAD_REQUEST ).body( errorDetails );
}

@Override
protected ResponseEntity<Object> handleHandlerMethodValidationException(HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
Map<String, String> 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);
}
}
10 changes: 4 additions & 6 deletions src/main/java/de/vitagroup/num/service/policy/EhrPolicy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AqlDto> 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())));
}
Expand All @@ -68,7 +68,7 @@ public ResponseEntity<AqlDto> createAql(
@PreAuthorize(Role.CRITERIA_EDITOR)
public ResponseEntity<AqlDto> 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());

Expand All @@ -79,7 +79,7 @@ public ResponseEntity<AqlDto> 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));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +51,7 @@ public ResponseEntity<String> createAttachment(@AuthenticationPrincipal @NotNull
@PreAuthorize(Role.STUDY_COORDINATOR)
@PostMapping(path = "/{projectId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> 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");
Expand All @@ -61,7 +60,7 @@ public ResponseEntity<String> 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<List<AttachmentDto>> listAllAttachments(@NotNull @NotEmpty @PathVariable Long projectId) {
public ResponseEntity<List<AttachmentDto>> listAllAttachments(@NotNull @PathVariable Long projectId) {
return ResponseEntity.ok(attachmentService.getAttachmentsBy(projectId).stream()
.map(attachment -> modelMapper.map(attachment, AttachmentDto.class))
.collect(Collectors.toList()));
Expand Down Expand Up @@ -89,7 +88,7 @@ public void deleteAql(@AuthenticationPrincipal @NotNull Jwt principal, @PathVari
@AuditLog(description = "Download attachment")
@Operation(description = "Download attachment with given id")
@GetMapping("/{attachmentId}")
public ResponseEntity<StreamingResponseBody> downloadAttachment(@NotNull @NotEmpty @PathVariable Long attachmentId) {
public ResponseEntity<StreamingResponseBody> downloadAttachment(@NotNull @PathVariable Long attachmentId) {
Attachment attachment = attachmentService.getAttachmentById(attachmentId);
HttpHeaders header = new HttpHeaders();
header.setContentDisposition(ContentDisposition.builder("attachment").filename(attachment.getName()).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,8 +46,7 @@ public ResponseEntity<List<String>> getAllMailDomainsForActiveOrganizations() {
@AuditLog
@GetMapping("/{id}")
@Operation(description = "Retrieves an organization by external id")
public ResponseEntity<OrganizationDto> getOrganizationById(
@NotNull @NotEmpty @PathVariable Long id) {
public ResponseEntity<OrganizationDto> getOrganizationById(@NotNull @PathVariable Long id) {
return ResponseEntity.ok(mapper.convertToDto(organizationService.getOrganizationById(id)));
}

Expand Down Expand Up @@ -102,9 +100,8 @@ public ResponseEntity<OrganizationDto> createOrganization(
@PutMapping(value = "/{id}")
@Operation(description = "Updates an organization")
@PreAuthorize(Role.SUPER_ADMIN_OR_ORGANIZATION_ADMIN)
public ResponseEntity<OrganizationDto> updateOrganization(
@AuthenticationPrincipal @NotNull Jwt principal,
@PathVariable("id") Long organizationId,
public ResponseEntity<OrganizationDto> updateOrganization(@AuthenticationPrincipal @NotNull Jwt principal,
@NotNull @PathVariable("id") Long organizationId,
@Valid @NotNull @RequestBody OrganizationDto organizationDto) {
return ResponseEntity.ok(
mapper.convertToDto(
Expand All @@ -120,7 +117,7 @@ public ResponseEntity<OrganizationDto> 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());
}
}
Loading

0 comments on commit 01e08aa

Please sign in to comment.