Skip to content

Commit

Permalink
WIP: Migrate to PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Mar 17, 2024
1 parent b62a88d commit 0772681
Show file tree
Hide file tree
Showing 335 changed files with 7,334 additions and 7,828 deletions.
37 changes: 25 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,29 @@ jobs:
test:
name: Test
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
# - windows-2022 (MongoDB issues in CI)
- macos-12
- ubuntu-22.04
# - windows-2022 (cannot use Docker for postgres)
# - macos-12 (cannot use Docker for postgres)
runs-on: ${{ matrix.os }}

services:
postgres:
image: postgres:16
env:
POSTGRES_DB: fdp_test
POSTGRES_USER: fdp
POSTGRES_PASSWORD: fdp
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 54321:5432

env:
JAVA_DISTRIBUTION: temurin
JAVA_VERSION: 21
Expand All @@ -25,15 +41,6 @@ jobs:
with:
fetch-depth: 0

- name: Set up MongoDB
uses: ankane/setup-mongodb@v1
with:
mongodb-version: '5.0'

- name: Check MongoDB
run: |
mongo --eval "db.version()"
- name: Setup Java
uses: actions/setup-java@v3
with:
Expand All @@ -48,6 +55,12 @@ jobs:
- name: Test
run: |
mvn -q -U -B test
env:
FDP_POSTGRES_HOST: localhost
FDP_POSTGRES_PORT: 54321
FDP_POSTGRES_DB: fdp_test
FDP_POSTGRES_USERNAME: fdp
FDP_POSTGRES_PASSWORD: fdp

- name: Package
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ target/

# Netbeans
nb-configuration\.xml
/nbproject/
/nbproject/
*.iml
59 changes: 20 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.5</version>
<version>3.2.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>nl.dtls</groupId>
Expand Down Expand Up @@ -52,16 +52,15 @@

<!-- Project related -->
<spring.rdf.migration.version>1.2.0.RELEASE</spring.rdf.migration.version>
<spring.security.acl.mongo.version>5.2.4.RELEASE</spring.security.acl.mongo.version>

<!-- Core -->
<springdoc.version>2.2.0</springdoc.version>
<mongock.version>5.3.5</mongock.version>
<mongodb.spring-data.version>4.1.5</mongodb.spring-data.version>
<postgresql.version>42.7.2</postgresql.version>
<rdf4j.version>4.3.8</rdf4j.version>
<jwt.version>0.12.3</jwt.version>
<lombok.version>1.18.30</lombok.version>
<rdf-resolver.version>0.1.2-SNAPSHOT</rdf-resolver.version>
<hypersistence.version>3.7.3</hypersistence.version>

<!-- Test -->
<httpclient5.version>5.2.2</httpclient5.version>
Expand Down Expand Up @@ -104,18 +103,6 @@
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-bom</artifactId>
<version>${mongock.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<!-- ////////////////// -->
Expand Down Expand Up @@ -154,7 +141,7 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
Expand All @@ -172,28 +159,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl-mongodb</artifactId>
<version>${spring.security.acl.mongo.version}</version>
</dependency>

<!-- ////////////////// -->
<!-- Mongock -->
<!-- ////////////////// -->
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-springboot</artifactId>
</dependency>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongodb-springdata-v4-driver</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${mongodb.spring-data.version}</version>
</dependency>

<!-- ////////////////// -->
<!-- Core -->
Expand Down Expand Up @@ -257,6 +222,22 @@
<artifactId>rdf-resource-resolver-api</artifactId>
<version>${rdf-resolver.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-63</artifactId>
<version>${hypersistence.version}</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>runtime</scope>
</dependency>

<!-- ////////////////// -->
<!-- Test -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,27 @@
package nl.dtls.fairdatapoint.api.controller.apikey;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import nl.dtls.fairdatapoint.api.dto.apikey.ApiKeyDTO;
import nl.dtls.fairdatapoint.entity.exception.ResourceNotFoundException;
import nl.dtls.fairdatapoint.service.apikey.ApiKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

import static java.lang.String.format;

@Tag(name = "Authentication and Authorization")
@RestController
@RequestMapping("/api-keys")
@RequiredArgsConstructor
public class ApiKeyController {

@Autowired
private ApiKeyService apiKeyService;
private final ApiKeyService apiKeyService;

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ApiKeyDTO>> getApiKeys() {
Expand All @@ -59,7 +60,7 @@ public ResponseEntity<ApiKeyDTO> createApiKey() {
@DeleteMapping("/{uuid}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public ResponseEntity<Void> deleteApiKey(
@PathVariable final String uuid
@PathVariable final UUID uuid
) throws ResourceNotFoundException {
final boolean result = apiKeyService.delete(uuid);
if (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
package nl.dtls.fairdatapoint.api.controller.config;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import nl.dtls.fairdatapoint.api.dto.config.BootstrapConfigDTO;
import nl.dtls.fairdatapoint.service.config.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -36,10 +36,10 @@
@Tag(name = "Client")
@RestController
@RequestMapping("/configs")
@RequiredArgsConstructor
public class ConfigController {

@Autowired
private ConfigService configService;
private final ConfigService configService;

@GetMapping(path = "/bootstrap", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<BootstrapConfigDTO> getBootstrapConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import nl.dtls.fairdatapoint.api.dto.dashboard.DashboardItemDTO;
import nl.dtls.fairdatapoint.service.dashboard.DashboardService;
import nl.dtls.fairdatapoint.service.metadata.exception.MetadataServiceException;
import org.eclipse.rdf4j.model.IRI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -46,14 +45,12 @@
@Tag(name = "Client")
@RestController
@RequestMapping("/dashboard")
@RequiredArgsConstructor
public class DashboardController {

@Autowired
@Qualifier("persistentUrl")
private String persistentUrl;
private final String persistentUrl;

@Autowired
private DashboardService dashboardService;
private final DashboardService dashboardService;

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<DashboardItemDTO>> getDashboard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class ExceptionControllerAdvice {
public ErrorDTO handleConstraintViolation(Exception exception) {
log.warn(exception.getMessage());
log.debug("Handling bad request (ConstraintViolation)", exception);
exception.printStackTrace();
return new ErrorDTO(HttpStatus.BAD_REQUEST, exception.getMessage());
}

Expand All @@ -95,6 +96,7 @@ public ErrorDTO handleConstraintViolation(Exception exception) {
public ErrorDTO handleValidationException(Exception exception) {
log.warn(exception.getMessage());
log.debug("Handling bad request (ValidationException)", exception);
exception.printStackTrace();
return new ErrorDTO(HttpStatus.BAD_REQUEST, exception.getMessage());
}

Expand All @@ -112,6 +114,7 @@ public ErrorDTO handleValidationException(Exception exception) {
public Model handleRdfValidationException(RdfValidationException exception) {
final Model validationReportModel = exception.getModel();
log.debug("Handling bad request (RdfValidationException)", exception);
exception.printStackTrace();

// Log number of errors
final IRI validationResultIri = i("http://www.w3.org/ns/shacl#ValidationResult");
Expand Down Expand Up @@ -140,6 +143,7 @@ public Model handleRdfValidationException(RdfValidationException exception) {
)
)
public ErrorDTO handleInvalidQuery(MalformedQueryException exception) {
exception.printStackTrace();
return handleInvalidSparqlQuery(exception);
}

Expand All @@ -155,6 +159,7 @@ public ErrorDTO handleInvalidQuery(MalformedQueryException exception) {
)
)
public ErrorDTO handleInvalidQuery(QueryEvaluationException exception) {
exception.printStackTrace();
return handleInvalidSparqlQuery(exception);
}

Expand All @@ -172,6 +177,7 @@ public ErrorDTO handleInvalidQuery(QueryEvaluationException exception) {
public ErrorDTO handleUnauthorized(Exception exception) {
log.error(exception.getMessage());
log.debug("Handling unauthorized", exception);
exception.printStackTrace();
return new ErrorDTO(HttpStatus.UNAUTHORIZED, exception.getMessage());
}

Expand All @@ -189,6 +195,7 @@ public ErrorDTO handleUnauthorized(Exception exception) {
public ErrorDTO handleForbidden(Exception exception) {
log.error(exception.getMessage());
log.debug("Handling forbidden", exception);
exception.printStackTrace();
return new ErrorDTO(HttpStatus.FORBIDDEN, exception.getMessage());
}

Expand All @@ -206,6 +213,7 @@ public ErrorDTO handleForbidden(Exception exception) {
public ErrorDTO handleResourceNotFound(ResourceNotFoundException exception) {
log.error(exception.getMessage());
log.debug("Handling resource not found", exception);
exception.printStackTrace();
return new ErrorDTO(HttpStatus.NOT_FOUND, exception.getMessage());
}

Expand All @@ -223,12 +231,14 @@ public ErrorDTO handleResourceNotFound(ResourceNotFoundException exception) {
public ErrorDTO handleInternalServerError(Exception exception) {
log.error(exception.getMessage());
log.debug("Handling internal server error (MetadataServiceException)", exception);
exception.printStackTrace();
return new ErrorDTO(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage());
}

@ExceptionHandler(AbstractIndexException.class)
public ResponseEntity<ErrorDTO> handleIndexException(AbstractIndexException exception) {
log.debug("Handling index exception", exception);
exception.printStackTrace();
return new ResponseEntity<>(exception.getErrorDTO(), exception.getStatus());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import nl.dtls.fairdatapoint.api.dto.form.FormAutocompleteItemDTO;
import nl.dtls.fairdatapoint.api.dto.form.FormAutocompleteRequestDTO;
import nl.dtls.fairdatapoint.service.form.autocomplete.FormsAutocompleteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -41,10 +41,10 @@
@Tag(name = "Client")
@RestController
@RequestMapping("/forms")
@RequiredArgsConstructor
public class FormAutocompleteController {

@Autowired
private FormsAutocompleteService autocompleteService;
private final FormsAutocompleteService autocompleteService;

@PostMapping(
path = "/autocomplete",
Expand Down
Loading

0 comments on commit 0772681

Please sign in to comment.