From 42b8c5d75a8641c106855266f36647e2413eadea Mon Sep 17 00:00:00 2001 From: Xi Bai Date: Mon, 26 Apr 2021 15:33:59 +0100 Subject: [PATCH] make unit tests pass --- Dockerfile | 2 +- README.md | 4 +- build.gradle | 66 ++++++++++++------- gradle.properties | 14 ++-- gradle/docker.gradle | 2 +- gradle/profile_dev.gradle | 2 +- .../scala/ManagementPortalSimulation.scala | 7 +- src/gatling/scala/ProjectGatlingTest.scala | 2 +- src/gatling/scala/SensorDataGatlingTest.scala | 2 +- src/gatling/scala/SourceGatlingTest.scala | 4 +- src/gatling/scala/SourceTypeGatlingTest.scala | 2 +- src/gatling/scala/SubjectGatlingTest.scala | 2 +- .../management/ApplicationWebXml.java | 2 +- .../management/ManagementPortalApp.java | 5 +- .../management/ManagementPortalTestApp.java | 5 +- .../management/config/AsyncConfiguration.java | 3 +- .../config/DatabaseConfiguration.java | 5 +- .../config/MetricsConfiguration.java | 3 - .../management/config/WebConfigurer.java | 26 ++++---- .../config/audit/AuditEventConverter.java | 3 +- .../config/audit/CustomRevisionListener.java | 4 +- .../domain/audit/CustomRevisionMetadata.java | 31 ++++++--- .../support/AbstractEntityListener.java | 10 ++- .../CustomAuditEventRepository.java | 33 ++-------- .../security/SpringSecurityAuditorAware.java | 8 +-- .../management/service/AuditEventService.java | 2 +- .../management/service/MailService.java | 2 +- .../management/service/ProjectService.java | 4 +- .../management/service/RevisionService.java | 16 +++-- .../management/service/RoleService.java | 4 +- .../management/service/SourceDataService.java | 4 +- .../management/service/SourceService.java | 6 +- .../management/service/SourceTypeService.java | 4 +- .../management/service/SubjectService.java | 8 +-- .../management/service/UserService.java | 3 +- .../management/service/dto/RevisionDTO.java | 4 +- .../decorator/SourceMapperDecorator.java | 2 +- src/main/resources/config/application.yml | 5 ++ .../service/MetaTokenServiceTest.java | 2 +- .../service/UserServiceIntTest.java | 2 +- .../web/rest/AccountResourceIntTest.java | 2 +- .../web/rest/AuditResourceIntTest.java | 8 +-- .../web/rest/LogsResourceIntTest.java | 2 +- .../web/rest/ProfileInfoResourceIntTest.java | 6 +- .../web/rest/ProjectResourceIntTest.java | 6 +- .../web/rest/SourceDataResourceIntTest.java | 8 +-- .../web/rest/SourceResourceIntTest.java | 8 +-- .../web/rest/SourceTypeResourceIntTest.java | 8 +-- .../web/rest/SubjectResourceIntTest.java | 18 ++--- .../web/rest/UserResourceIntTest.java | 12 ++-- 50 files changed, 203 insertions(+), 190 deletions(-) diff --git a/Dockerfile b/Dockerfile index 18721ee21..cbe692409 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ RUN ./gradlew downloadDependencies :radar-auth:shadowJar # now we copy our application source code and build it COPY radar-auth radar-auth COPY src src -RUN ./gradlew -s bootRepackage +RUN ./gradlew -s bootWar # Run stage FROM openjdk:8-jre-alpine diff --git a/README.md b/README.md index 06ace06a5..d899edca6 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,7 @@ will generate few files: To optimize the ManagementPortal application for production, run: - ./gradlew -Pprod clean bootRepackage + ./gradlew -Pprod clean bootWar ### Hosting in production The latest Meta-QR code implementation requires REST resources on `api/meta-token/*` should definitely be rate-limited by upstream servers. @@ -319,7 +319,7 @@ To stop it and remove the container, run: You can also fully dockerize your application and all the services that it depends on. To achieve this, first build a docker image of your app by running: - ./gradlew bootRepackage -Pprod buildDocker + ./gradlew bootWar -Pprod buildDocker Then run: diff --git a/build.gradle b/build.gradle index 0d19a57fe..8d4c81a2e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,32 @@ import org.gradle.internal.os.OperatingSystem +buildscript { + repositories { + mavenCentral() + jcenter() + } + + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}") + } +} + plugins { - id 'org.springframework.boot' version '1.5.9.RELEASE' + id 'org.springframework.boot' version "${spring_boot_version}" id "com.moowork.node" version "1.2.0" id "io.spring.dependency-management" version "1.0.7.RELEASE" id 'de.undercouch.download' version '4.1.1' apply false - id("io.github.gradle-nexus.publish-plugin") version "1.0.0" + id "io.github.gradle-nexus.publish-plugin" version "1.0.0" +} + +apply plugin: 'org.springframework.boot' +apply plugin: 'war' +apply plugin: 'com.moowork.node' +apply plugin: 'io.spring.dependency-management' + +repositories { + mavenCentral() + jcenter() } allprojects { @@ -43,11 +64,6 @@ allprojects { description = 'MangementPortal application to manage studies and participants' -apply plugin: 'org.springframework.boot' -apply plugin: 'war' -apply plugin: 'com.moowork.node' -apply plugin: 'io.spring.dependency-management' - defaultTasks 'bootRun' configurations { @@ -55,13 +71,13 @@ configurations { } -bootRepackage { - mainClass = 'org.radarbase.management.ManagementPortalApp' +bootWar { + mainClassName = 'org.radarbase.management.ManagementPortalApp' + launchScript() +// buildInfo() } springBoot { - mainClass = 'org.radarbase.management.ManagementPortalApp' - executable = true buildInfo() } @@ -80,7 +96,7 @@ if (OperatingSystem.current().isWindows()) { } bootRun { - addResources = false + sourceResources sourceSets.main dependsOn pathingJar doFirst { classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", pathingJar.archivePath) @@ -88,7 +104,7 @@ if (OperatingSystem.current().isWindows()) { } } else { bootRun { - addResources = false + sourceResources sourceSets.main } } @@ -124,11 +140,6 @@ if (project.hasProperty('graphite')) { //ext.moduleDescription = 'Management Portal application' ext.findbugAnnotationVersion = '3.0.2' -repositories { - mavenCentral() - jcenter() -} - dependencies { compile "io.github.jhipster:jhipster:${jhipster_server_version}" compile "io.dropwizard.metrics:metrics-core:${dropwizard_metrics_version}" @@ -160,7 +171,7 @@ dependencies { compile group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1' compile group: 'com.google.code.findbugs', name: 'jsr305', version: findbugAnnotationVersion compile "org.hibernate:hibernate-envers:${hibernate_version}" - compile "org.hibernate:hibernate-validator" + compile "org.hibernate:hibernate-validator:${hibernate_version}" compile("org.liquibase:liquibase-core") compile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}" compile "org.springframework.boot:spring-boot-actuator" @@ -173,19 +184,28 @@ dependencies { exclude group: 'org.hibernate', module: 'hibernate-entitymanager' } compile "org.springframework.boot:spring-boot-starter-security" - compile "org.springframework.cloud:spring-cloud-starter-zuul:${zuul_proxy_version}" - compile("org.springframework.boot:spring-boot-starter-web") { + compile("org.springframework.cloud:spring-cloud-starter-netflix-zuul:${spring_cloud_version}") +// { +// exclude module: "spring-cloud-starter-netflix-ribbon" +// exclude module: "spring-cloud-starter-netflix-hystrix" +// } +// compile "org.springframework.cloud:spring-cloud-starter-netflix-hystrix:2.2.8.RELEASE" +// compile "org.springframework.cloud:spring-cloud-starter-netflix-ribbon:2.2.8.RELEASE" + compile "org.springframework.cloud:spring-cloud-context:${spring_cloud_version}" + compile "org.springframework.cloud:spring-cloud-commons:${spring_cloud_version}" + compile("org.springframework.boot:spring-boot-starter-web:${spring_boot_version}") { exclude module: 'spring-boot-starter-tomcat' } compile "org.springframework.boot:spring-boot-starter-undertow" compile "org.springframework.boot:spring-boot-starter-thymeleaf" compile("org.springframework:spring-context-support") + compile("org.springframework:spring-jdbc") compile "org.springframework.security:spring-security-config" compile "org.springframework.security:spring-security-data" compile ("org.springframework.security:spring-security-web"){ exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind' } - compile "org.springframework.security:spring-security-jwt" + compile "org.springframework.security:spring-security-jwt:${spring_security_jwt_versions}" compile "org.springframework.security.oauth:spring-security-oauth2:${spring_security_oauth2_version}" compile("io.springfox:springfox-swagger2:${springfox_version}") { exclude module: 'mapstruct' @@ -227,7 +247,7 @@ wrapper { gradleVersion '6.7.1' } -task stage(dependsOn: 'bootRepackage') { +task stage(dependsOn: 'bootWar') { } task ghPagesJavadoc(type: Copy, dependsOn: javadoc) { diff --git a/gradle.properties b/gradle.properties index 21a17db90..c7091d2ba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,11 +7,11 @@ commons_io_version=2.6 # Overridden to get metrics-jcache dropwizard_metrics_version=3.2.2 logstash_logback_encoder_version=4.9 -javax_transaction_version=1.2 +javax_transaction_version=3.9.1 json_path_version=0.9.1 jhipster_server_version=1.1.2 hazelcast_hibernate52_version=1.2 -hibernate_version=5.2.12.Final +hibernate_version=5.2.1.Final hikaricp_version=2.7.4 liquibase_slf4j_version=2.0.0 liquibase_hibernate5_version=3.6 @@ -20,15 +20,17 @@ node_version=6.10.0 npm_version=4.3.0 prometheus_simpleclient_version=0.0.20 postgresql_version=42.2.14 +spring_security_jwt_versions=1.1.1.RELEASE spring_security_oauth2_version=2.3.5.RELEASE springfox_version=2.6.1 -spring_boot_version=1.5.9.RELEASE -gatling_version=2.3.1 +spring_boot_version=2.3.10.RELEASE +spring_boot_devtools_version=2.4.5 +spring_cloud_version=2.2.8.RELEASE +gatling_version=3.3.1 mapstruct_version=1.1.0.Final undertow_version=1.4.10.Final yarn_version=0.21.3 -zuul_proxy_version=1.3.5.RELEASE -spring_data_envers_version=1.1.10.RELEASE +spring_data_envers_version=2.3.9.RELEASE jackson_version=2.9.10 jackson_dataformat_version=2.9.10 javaxXmlBindVersion=2.3.3 diff --git a/gradle/docker.gradle b/gradle/docker.gradle index f325f79d6..eefab18cf 100644 --- a/gradle/docker.gradle +++ b/gradle/docker.gradle @@ -1,6 +1,6 @@ import org.gradle.internal.os.OperatingSystem -task buildDocker(type: Exec, dependsOn: bootRepackage) { +task buildDocker(type: Exec, dependsOn: bootWar) { doFirst { copy { from "src/main/docker/" diff --git a/gradle/profile_dev.gradle b/gradle/profile_dev.gradle index 05da58afc..85e09bd35 100644 --- a/gradle/profile_dev.gradle +++ b/gradle/profile_dev.gradle @@ -4,7 +4,7 @@ apply plugin: 'com.moowork.node' ext.logbackLoglevel = 'DEBUG' dependencies { - compile "org.springframework.boot:spring-boot-devtools" + compile "org.springframework.boot:spring-boot-devtools:${spring_boot_devtools_version}" } def profiles = 'dev' diff --git a/src/gatling/scala/ManagementPortalSimulation.scala b/src/gatling/scala/ManagementPortalSimulation.scala index da1f1284b..59d02fba0 100644 --- a/src/gatling/scala/ManagementPortalSimulation.scala +++ b/src/gatling/scala/ManagementPortalSimulation.scala @@ -18,10 +18,9 @@ abstract class ManagementPortalSimulation extends Simulation { // Log failed HTTP requests //context.getLogger("io.gatling.http").setLevel(Level.valueOf("DEBUG")) - val baseURL: String = Option(System.getProperty("baseURL")) getOrElse """http://127.0.0.1:8080""" + val baseUrl: String = Option(System.getProperty("baseUrl")) getOrElse """http://127.0.0.1:8080""" - val httpConf: HttpProtocolBuilder = http - .baseURL(baseURL) + val httpConf: HttpProtocolBuilder = http.baseUrl(baseUrl) .inferHtmlResources() .acceptHeader("*/*") .acceptEncodingHeader("gzip, deflate") @@ -53,7 +52,7 @@ abstract class ManagementPortalSimulation extends Simulation { def run(): Unit = { val users = scenario("Users").exec(scn) setUp( - users.inject(rampUsers(100) over (1 minutes)) + users.inject(rampUsers(100) during (1 minutes)) ).protocols(httpConf) } } diff --git a/src/gatling/scala/ProjectGatlingTest.scala b/src/gatling/scala/ProjectGatlingTest.scala index e40b316b6..e5370ef71 100644 --- a/src/gatling/scala/ProjectGatlingTest.scala +++ b/src/gatling/scala/ProjectGatlingTest.scala @@ -42,7 +42,7 @@ class ProjectGatlingTest extends ManagementPortalSimulation { .exec(http("Create new project") .post("/api/projects") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "projectName":"PROJECT-${randstring}", "description":"SAMPLE_TEXT", "organization":"SAMPLE_TEXT", "location":"SAMPLE_TEXT", "startDate":"2020-01-01T00:00:00.000Z", "projectStatus":null, "endDate":"2020-01-01T00:00:00.000Z", "projectAdmin":null}""")).asJSON + .body(StringBody("""{"id":null, "projectName":"PROJECT-${randstring}", "description":"SAMPLE_TEXT", "organization":"SAMPLE_TEXT", "location":"SAMPLE_TEXT", "startDate":"2020-01-01T00:00:00.000Z", "projectStatus":null, "endDate":"2020-01-01T00:00:00.000Z", "projectAdmin":null}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_project_url"))).exitHereIfFailed .pause(5) diff --git a/src/gatling/scala/SensorDataGatlingTest.scala b/src/gatling/scala/SensorDataGatlingTest.scala index 35fc874fb..3c6ce7dd6 100644 --- a/src/gatling/scala/SensorDataGatlingTest.scala +++ b/src/gatling/scala/SensorDataGatlingTest.scala @@ -42,7 +42,7 @@ class SensorDataGatlingTest extends ManagementPortalSimulation { .exec(http("Create new sourceData") .post("/api/source-data") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "sourceDataType":"SAMPLE_TEXT", "sourceDataName":"SOURCEDATA-${randstring}", "processingState":null, "keySchema":"SAMPLE_TEXT", "frequency":"SAMPLE_TEXT"}""")).asJSON + .body(StringBody("""{"id":null, "sourceDataType":"SAMPLE_TEXT", "sourceDataName":"SOURCEDATA-${randstring}", "processingState":null, "keySchema":"SAMPLE_TEXT", "frequency":"SAMPLE_TEXT"}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_sourceData_url"))).exitHereIfFailed .pause(5) diff --git a/src/gatling/scala/SourceGatlingTest.scala b/src/gatling/scala/SourceGatlingTest.scala index 473683fe4..a3e7c4259 100644 --- a/src/gatling/scala/SourceGatlingTest.scala +++ b/src/gatling/scala/SourceGatlingTest.scala @@ -35,7 +35,7 @@ class SourceGatlingTest extends ManagementPortalSimulation { .exec(http("Create new sourceType") .post("/api/source-types") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "producer":"GATLING", "model":"MODEL-${randstring}", "catalogVersion":"v1", "sourceTypeScope": "ACTIVE"}""")).asJSON + .body(StringBody("""{"id":null, "producer":"GATLING", "model":"MODEL-${randstring}", "catalogVersion":"v1", "sourceTypeScope": "ACTIVE"}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_sourceType_url")) .check(jsonPath("$.id").saveAs("sourceTypeId"))).exitHereIfFailed @@ -50,7 +50,7 @@ class SourceGatlingTest extends ManagementPortalSimulation { .exec(http("Create new source") .post("/api/sources") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "sourceName":"SOURCE-${randstring}", "assigned":false, "sourceType":{"id":"${sourceTypeId}"}}""")).asJSON + .body(StringBody("""{"id":null, "sourceName":"SOURCE-${randstring}", "assigned":false, "sourceType":{"id":"${sourceTypeId}"}}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_source_url"))).exitHereIfFailed .pause(5) diff --git a/src/gatling/scala/SourceTypeGatlingTest.scala b/src/gatling/scala/SourceTypeGatlingTest.scala index 545d436e6..634295e0b 100644 --- a/src/gatling/scala/SourceTypeGatlingTest.scala +++ b/src/gatling/scala/SourceTypeGatlingTest.scala @@ -41,7 +41,7 @@ class SourceTypeGatlingTest extends ManagementPortalSimulation { .exec(http("Create new sourceType") .post("/api/source-types") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "producer":"GATLING", "model":"MODEL-${randstring}", "catalogVersion":"v1", "sourceTypeScope": "ACTIVE"}""")).asJSON + .body(StringBody("""{"id":null, "producer":"GATLING", "model":"MODEL-${randstring}", "catalogVersion":"v1", "sourceTypeScope": "ACTIVE"}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_sourceType_url"))).exitHereIfFailed .pause(5) diff --git a/src/gatling/scala/SubjectGatlingTest.scala b/src/gatling/scala/SubjectGatlingTest.scala index 2a0314f50..36e7c3a0c 100644 --- a/src/gatling/scala/SubjectGatlingTest.scala +++ b/src/gatling/scala/SubjectGatlingTest.scala @@ -47,7 +47,7 @@ class SubjectGatlingTest extends ManagementPortalSimulation { .exec(http("Create new subject") .post("/api/subjects") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "externalLink":"SAMPLE_TEXT", "enternalId":"${randstring}", "project": {"id": "${project_id}"}}""")).asJSON + .body(StringBody("""{"id":null, "externalLink":"SAMPLE_TEXT", "enternalId":"${randstring}", "project": {"id": "${project_id}"}}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_subject_url"))).exitHereIfFailed .pause(5) diff --git a/src/main/java/org/radarbase/management/ApplicationWebXml.java b/src/main/java/org/radarbase/management/ApplicationWebXml.java index 8c7ea509a..94b27fb01 100644 --- a/src/main/java/org/radarbase/management/ApplicationWebXml.java +++ b/src/main/java/org/radarbase/management/ApplicationWebXml.java @@ -2,7 +2,7 @@ import org.radarbase.management.config.DefaultProfileUtil; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; /** * This is a helper Java class that provides an alternative to creating a web.xml. This will be diff --git a/src/main/java/org/radarbase/management/ManagementPortalApp.java b/src/main/java/org/radarbase/management/ManagementPortalApp.java index b0f0688f8..3b3c03239 100644 --- a/src/main/java/org/radarbase/management/ManagementPortalApp.java +++ b/src/main/java/org/radarbase/management/ManagementPortalApp.java @@ -12,8 +12,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; -import org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration; -import org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -31,8 +29,7 @@ "org.radarbase.management.web" }) @EnableZuulProxy -@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, - MetricRepositoryAutoConfiguration.class}) +@EnableAutoConfiguration @EnableConfigurationProperties({LiquibaseProperties.class, ApplicationProperties.class, ManagementPortalProperties.class}) public class ManagementPortalApp { diff --git a/src/main/java/org/radarbase/management/ManagementPortalTestApp.java b/src/main/java/org/radarbase/management/ManagementPortalTestApp.java index 3d3a1d648..1cbd4c3bc 100644 --- a/src/main/java/org/radarbase/management/ManagementPortalTestApp.java +++ b/src/main/java/org/radarbase/management/ManagementPortalTestApp.java @@ -13,8 +13,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; -import org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration; -import org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -30,8 +28,7 @@ @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = SourceTypeLoader.class)) @EnableZuulProxy -@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, - MetricRepositoryAutoConfiguration.class}) +@EnableAutoConfiguration @EnableConfigurationProperties({LiquibaseProperties.class, ApplicationProperties.class, ManagementPortalProperties.class}) public class ManagementPortalTestApp { diff --git a/src/main/java/org/radarbase/management/config/AsyncConfiguration.java b/src/main/java/org/radarbase/management/config/AsyncConfiguration.java index 1e7d8357e..5c02ac8e8 100644 --- a/src/main/java/org/radarbase/management/config/AsyncConfiguration.java +++ b/src/main/java/org/radarbase/management/config/AsyncConfiguration.java @@ -2,7 +2,6 @@ import io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor; import io.github.jhipster.config.JHipsterProperties; -import java.util.concurrent.Executor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; @@ -27,7 +26,7 @@ public class AsyncConfiguration implements AsyncConfigurer { @Override @Bean(name = "taskExecutor") - public Executor getAsyncExecutor() { + public ExceptionHandlingAsyncTaskExecutor getAsyncExecutor() { log.debug("Creating Async Task Executor"); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize()); diff --git a/src/main/java/org/radarbase/management/config/DatabaseConfiguration.java b/src/main/java/org/radarbase/management/config/DatabaseConfiguration.java index 16eb6793d..e2c43953e 100644 --- a/src/main/java/org/radarbase/management/config/DatabaseConfiguration.java +++ b/src/main/java/org/radarbase/management/config/DatabaseConfiguration.java @@ -1,6 +1,7 @@ package org.radarbase.management.config; import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; +import io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor; import io.github.jhipster.config.JHipsterConstants; import io.github.jhipster.config.liquibase.AsyncSpringLiquibase; import java.sql.SQLException; @@ -16,7 +17,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; -import org.springframework.core.task.TaskExecutor; import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @@ -47,7 +47,8 @@ public Server h2TCPServer() throws SQLException { } @Bean - public SpringLiquibase liquibase(@Qualifier("taskExecutor") TaskExecutor taskExecutor, + public SpringLiquibase liquibase( + @Qualifier("taskExecutor") ExceptionHandlingAsyncTaskExecutor taskExecutor, DataSource dataSource, LiquibaseProperties liquibaseProperties) { // Use liquibase.integration.spring.SpringLiquibase if you don't want Liquibase to start diff --git a/src/main/java/org/radarbase/management/config/MetricsConfiguration.java b/src/main/java/org/radarbase/management/config/MetricsConfiguration.java index cc393d92a..ba30a11c6 100644 --- a/src/main/java/org/radarbase/management/config/MetricsConfiguration.java +++ b/src/main/java/org/radarbase/management/config/MetricsConfiguration.java @@ -19,7 +19,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration @@ -44,13 +43,11 @@ public class MetricsConfiguration extends MetricsConfigurerAdapter { private HikariDataSource hikariDataSource; @Override - @Bean public MetricRegistry getMetricRegistry() { return metricRegistry; } @Override - @Bean public HealthCheckRegistry getHealthCheckRegistry() { return healthCheckRegistry; } diff --git a/src/main/java/org/radarbase/management/config/WebConfigurer.java b/src/main/java/org/radarbase/management/config/WebConfigurer.java index a96fe32de..07e2ed338 100644 --- a/src/main/java/org/radarbase/management/config/WebConfigurer.java +++ b/src/main/java/org/radarbase/management/config/WebConfigurer.java @@ -18,11 +18,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.MimeMappings; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.web.server.MimeMappings; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; @@ -35,7 +35,7 @@ */ @Configuration public class WebConfigurer implements ServletContextInitializer, - EmbeddedServletContainerCustomizer { + WebServerFactoryCustomizer { private static final Logger log = LoggerFactory.getLogger(WebConfigurer.class); @@ -69,16 +69,17 @@ public void onStartup(ServletContext servletContext) throws ServletException { /** * Customize the Servlet engine: Mime types, the document root, the cache. */ + @Override - public void customize(ConfigurableEmbeddedServletContainer container) { + public void customize(ConfigurableServletWebServerFactory factory) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711 mappings.add("html", "text/html;charset=utf-8"); // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64 mappings.add("json", "text/html;charset=utf-8"); - container.setMimeMappings(mappings); + factory.setMimeMappings(mappings); // When running in an IDE or with ./gradlew bootRun, set location of the static web assets. - setLocationForStaticAssets(container); + setLocationForStaticAssets(factory); /* * Enable HTTP/2 for Undertow - https://twitter.com/ankinson/status/829256167700492288 @@ -88,20 +89,20 @@ public void customize(ConfigurableEmbeddedServletContainer container) { */ if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && - container instanceof UndertowEmbeddedServletContainerFactory) { + factory instanceof UndertowServletWebServerFactory) { - ((UndertowEmbeddedServletContainerFactory) container) + ((UndertowServletWebServerFactory) factory) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } - private void setLocationForStaticAssets(ConfigurableEmbeddedServletContainer container) { + private void setLocationForStaticAssets(ConfigurableServletWebServerFactory factory) { File root; String prefixPath = resolvePathPrefix(); root = new File(prefixPath + "build/www/"); if (root.exists() && root.isDirectory()) { - container.setDocumentRoot(root); + factory.setDocumentRoot(root); } } @@ -184,4 +185,5 @@ private void initH2Console(ServletContext servletContext) { h2ConsoleServlet.setInitParameter("-properties", "src/main/resources/"); h2ConsoleServlet.setLoadOnStartup(1); } + } diff --git a/src/main/java/org/radarbase/management/config/audit/AuditEventConverter.java b/src/main/java/org/radarbase/management/config/audit/AuditEventConverter.java index 1558334cb..a1e7a9a13 100644 --- a/src/main/java/org/radarbase/management/config/audit/AuditEventConverter.java +++ b/src/main/java/org/radarbase/management/config/audit/AuditEventConverter.java @@ -4,7 +4,6 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,7 +42,7 @@ public List convertToAuditEvent( public AuditEvent convertToAuditEvent(PersistentAuditEvent persistentAuditEvent) { Instant instant = persistentAuditEvent.getAuditEventDate().atZone(ZoneId.systemDefault()) .toInstant(); - return new AuditEvent(Date.from(instant), persistentAuditEvent.getPrincipal(), + return new AuditEvent(instant, persistentAuditEvent.getPrincipal(), persistentAuditEvent.getAuditEventType(), convertDataToObjects(persistentAuditEvent.getData())); } diff --git a/src/main/java/org/radarbase/management/config/audit/CustomRevisionListener.java b/src/main/java/org/radarbase/management/config/audit/CustomRevisionListener.java index 72822877c..2d6acf554 100644 --- a/src/main/java/org/radarbase/management/config/audit/CustomRevisionListener.java +++ b/src/main/java/org/radarbase/management/config/audit/CustomRevisionListener.java @@ -1,6 +1,7 @@ package org.radarbase.management.config.audit; import org.hibernate.envers.RevisionListener; +import org.radarbase.auth.config.Constants; import org.radarbase.management.domain.audit.CustomRevisionEntity; import org.radarbase.management.domain.support.AutowireHelper; import org.radarbase.management.security.SpringSecurityAuditorAware; @@ -15,6 +16,7 @@ public class CustomRevisionListener implements RevisionListener { public void newRevision(Object revisionEntity) { AutowireHelper.autowire(this, springSecurityAuditorAware); CustomRevisionEntity entity = (CustomRevisionEntity) revisionEntity; - entity.setAuditor(springSecurityAuditorAware.getCurrentAuditor()); + entity.setAuditor(springSecurityAuditorAware.getCurrentAuditor() + .orElse(Constants.SYSTEM_ACCOUNT)); } } diff --git a/src/main/java/org/radarbase/management/domain/audit/CustomRevisionMetadata.java b/src/main/java/org/radarbase/management/domain/audit/CustomRevisionMetadata.java index 7bfe738d7..80ebec89e 100644 --- a/src/main/java/org/radarbase/management/domain/audit/CustomRevisionMetadata.java +++ b/src/main/java/org/radarbase/management/domain/audit/CustomRevisionMetadata.java @@ -1,9 +1,11 @@ package org.radarbase.management.domain.audit; -import org.joda.time.DateTime; import org.springframework.data.history.RevisionMetadata; import org.springframework.util.Assert; +import java.time.Instant; +import java.util.Optional; + public class CustomRevisionMetadata implements RevisionMetadata { private final CustomRevisionEntity entity; @@ -23,17 +25,23 @@ public CustomRevisionMetadata(CustomRevisionEntity entity) { * @see org.springframework.data.history.RevisionMetadata#getRevisionNumber() */ @Override - public Integer getRevisionNumber() { - return entity.getId(); + public Optional getRevisionNumber() { + return Optional.of(entity.getId()); + } + + @Override + public Integer getRequiredRevisionNumber() { + return RevisionMetadata.super.getRequiredRevisionNumber(); } - /* - * (non-Javadoc) - * @see org.springframework.data.history.RevisionMetadata#getRevisionDate() - */ @Override - public DateTime getRevisionDate() { - return new DateTime(entity.getTimestamp()); + public Optional getRevisionInstant() { + return Optional.empty(); + } + + @Override + public Instant getRequiredRevisionInstant() { + return RevisionMetadata.super.getRequiredRevisionInstant(); } /* @@ -45,4 +53,9 @@ public DateTime getRevisionDate() { public T getDelegate() { return (T) entity; } + + @Override + public RevisionType getRevisionType() { + return RevisionMetadata.super.getRevisionType(); + } } diff --git a/src/main/java/org/radarbase/management/domain/support/AbstractEntityListener.java b/src/main/java/org/radarbase/management/domain/support/AbstractEntityListener.java index de84380ed..fead626b5 100644 --- a/src/main/java/org/radarbase/management/domain/support/AbstractEntityListener.java +++ b/src/main/java/org/radarbase/management/domain/support/AbstractEntityListener.java @@ -1,5 +1,6 @@ package org.radarbase.management.domain.support; +import org.radarbase.auth.config.Constants; import org.radarbase.management.domain.AbstractEntity; import org.radarbase.management.security.SpringSecurityAuditorAware; import org.slf4j.Logger; @@ -38,7 +39,8 @@ public class AbstractEntityListener { @PostPersist public void publishPersistEvent(AbstractEntity entity) { AutowireHelper.autowire(this, springSecurityAuditorAware); - log.info(TEMPLATE, ENTITY_CREATED, springSecurityAuditorAware.getCurrentAuditor(), + log.info(TEMPLATE, ENTITY_CREATED, springSecurityAuditorAware.getCurrentAuditor() + .orElse(Constants.SYSTEM_ACCOUNT), entity.getClass().getName(), entity.toString()); } @@ -50,7 +52,8 @@ public void publishPersistEvent(AbstractEntity entity) { @PostUpdate public void publishUpdateEvent(AbstractEntity entity) { AutowireHelper.autowire(this, springSecurityAuditorAware); - log.info(TEMPLATE, ENTITY_UPDATED, springSecurityAuditorAware.getCurrentAuditor(), + log.info(TEMPLATE, ENTITY_UPDATED, springSecurityAuditorAware.getCurrentAuditor() + .orElse(Constants.SYSTEM_ACCOUNT), entity.getClass().getName(), entity.toString()); } @@ -62,7 +65,8 @@ public void publishUpdateEvent(AbstractEntity entity) { @PostRemove public void publishRemoveEvent(AbstractEntity entity) { AutowireHelper.autowire(this, springSecurityAuditorAware); - log.info(TEMPLATE, ENTITY_REMOVED, springSecurityAuditorAware.getCurrentAuditor(), + log.info(TEMPLATE, ENTITY_REMOVED, springSecurityAuditorAware.getCurrentAuditor() + .orElse(Constants.SYSTEM_ACCOUNT), entity.getClass().getName(), entity.toString()); } diff --git a/src/main/java/org/radarbase/management/repository/CustomAuditEventRepository.java b/src/main/java/org/radarbase/management/repository/CustomAuditEventRepository.java index 1320a763e..d5f86148f 100644 --- a/src/main/java/org/radarbase/management/repository/CustomAuditEventRepository.java +++ b/src/main/java/org/radarbase/management/repository/CustomAuditEventRepository.java @@ -3,7 +3,6 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.Date; import java.util.List; import org.radarbase.auth.config.Constants; import org.radarbase.management.config.audit.AuditEventConverter; @@ -30,34 +29,11 @@ public class CustomAuditEventRepository implements AuditEventRepository { private AuditEventConverter auditEventConverter; @Override - public List find(Date after) { - Iterable persistentAuditEvents = - persistenceAuditEventRepository - .findByAuditEventDateAfter(LocalDateTime.from(after.toInstant())); - return auditEventConverter.convertToAuditEvent(persistentAuditEvents); - } - - @Override - public List find(String principal, Date after) { - Iterable persistentAuditEvents; - if (principal == null && after == null) { - persistentAuditEvents = persistenceAuditEventRepository.findAll(); - } else if (after == null) { - persistentAuditEvents = persistenceAuditEventRepository.findByPrincipal(principal); - } else { - persistentAuditEvents = - persistenceAuditEventRepository.findByPrincipalAndAuditEventDateAfter(principal, - LocalDateTime.from(after.toInstant())); - } - return auditEventConverter.convertToAuditEvent(persistentAuditEvents); - } - - @Override - public List find(String principal, Date after, String type) { + public List find(String principal, Instant after, String type) { Iterable persistentAuditEvents = persistenceAuditEventRepository .findByPrincipalAndAuditEventDateAfterAndAuditEventType(principal, - LocalDateTime.from(after.toInstant()), type); + LocalDateTime.from(after), type); return auditEventConverter.convertToAuditEvent(persistentAuditEvents); } @@ -70,9 +46,8 @@ public void add(AuditEvent event) { PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent(); persistentAuditEvent.setPrincipal(event.getPrincipal()); persistentAuditEvent.setAuditEventType(event.getType()); - Instant instant = Instant.ofEpochMilli(event.getTimestamp().getTime()); - persistentAuditEvent - .setAuditEventDate(LocalDateTime.ofInstant(instant, ZoneId.systemDefault())); + persistentAuditEvent.setAuditEventDate(LocalDateTime.ofInstant(event.getTimestamp(), + ZoneId.systemDefault())); persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData())); persistenceAuditEventRepository.save(persistentAuditEvent); } diff --git a/src/main/java/org/radarbase/management/security/SpringSecurityAuditorAware.java b/src/main/java/org/radarbase/management/security/SpringSecurityAuditorAware.java index d951f9fe5..2cdea1d43 100644 --- a/src/main/java/org/radarbase/management/security/SpringSecurityAuditorAware.java +++ b/src/main/java/org/radarbase/management/security/SpringSecurityAuditorAware.java @@ -1,9 +1,10 @@ package org.radarbase.management.security; -import org.radarbase.auth.config.Constants; import org.springframework.data.domain.AuditorAware; import org.springframework.stereotype.Component; +import java.util.Optional; + /** * Implementation of AuditorAware based on Spring Security. */ @@ -11,8 +12,7 @@ public class SpringSecurityAuditorAware implements AuditorAware { @Override - public String getCurrentAuditor() { - String userName = SecurityUtils.getCurrentUserLogin(); - return userName != null ? userName : Constants.SYSTEM_ACCOUNT; + public Optional getCurrentAuditor() { + return Optional.ofNullable(SecurityUtils.getCurrentUserLogin()); } } diff --git a/src/main/java/org/radarbase/management/service/AuditEventService.java b/src/main/java/org/radarbase/management/service/AuditEventService.java index 351664c0a..11eaafd31 100644 --- a/src/main/java/org/radarbase/management/service/AuditEventService.java +++ b/src/main/java/org/radarbase/management/service/AuditEventService.java @@ -46,7 +46,7 @@ public Page findByDates(LocalDateTime fromDate, LocalDateTime toDate } public Optional find(Long id) { - return Optional.ofNullable(persistenceAuditEventRepository.findOne(id)) + return Optional.ofNullable(persistenceAuditEventRepository.findById(id).orElse(null)) .map(auditEventConverter::convertToAuditEvent); } } diff --git a/src/main/java/org/radarbase/management/service/MailService.java b/src/main/java/org/radarbase/management/service/MailService.java index dad086cd3..8999a9aeb 100644 --- a/src/main/java/org/radarbase/management/service/MailService.java +++ b/src/main/java/org/radarbase/management/service/MailService.java @@ -16,7 +16,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.thymeleaf.context.Context; -import org.thymeleaf.spring4.SpringTemplateEngine; +import org.thymeleaf.spring5.SpringTemplateEngine; /** * Service for sending emails.

We use the @Async annotation to send emails asynchronously.

diff --git a/src/main/java/org/radarbase/management/service/ProjectService.java b/src/main/java/org/radarbase/management/service/ProjectService.java index e85df1770..56c559de5 100644 --- a/src/main/java/org/radarbase/management/service/ProjectService.java +++ b/src/main/java/org/radarbase/management/service/ProjectService.java @@ -116,12 +116,12 @@ public List findSourceTypesByProjectId(Long id) { } /** - * Delete the project by id. + * Delete the project by id. * * @param id the id of the entity */ public void delete(Long id) { log.debug("Request to delete Project : {}", id); - projectRepository.delete(id); + projectRepository.deleteById(id); } } diff --git a/src/main/java/org/radarbase/management/service/RevisionService.java b/src/main/java/org/radarbase/management/service/RevisionService.java index 82950077a..ba5c5eb51 100644 --- a/src/main/java/org/radarbase/management/service/RevisionService.java +++ b/src/main/java/org/radarbase/management/service/RevisionService.java @@ -187,8 +187,8 @@ public Page getRevisionsForEntity(Pageable pageable, AbstractEntity } // add the page constraints (offset and amount of results) - query.setFirstResult(pageable.getOffset()) - .setMaxResults(pageable.getPageSize()); + query.setFirstResult(Math.toIntExact(pageable.getOffset())) + .setMaxResults(Math.toIntExact(pageable.getPageSize())); Function dtoMapper = getDtoMapper(entity.getClass()); @@ -197,9 +197,9 @@ public Page getRevisionsForEntity(Pageable pageable, AbstractEntity @SuppressWarnings({"unchecked", "rawtypes"}) List revisionDtos = resultList.stream() .map(objArray -> new RevisionDTO( - new Revision( - new CustomRevisionMetadata((CustomRevisionEntity) objArray[1]), - objArray[0]), + Revision.of( + new CustomRevisionMetadata((CustomRevisionEntity) objArray[1]), + objArray[0]), (RevisionType) objArray[2], dtoMapper.apply(objArray[0]))) .collect(toList()); @@ -215,7 +215,8 @@ public Page getRevisionsForEntity(Pageable pageable, AbstractEntity * @throws NotFoundException if the revision number does not exist */ public RevisionInfoDTO getRevision(Integer revision) throws NotFoundException { - CustomRevisionEntity revisionEntity = revisionEntityRepository.findOne(revision); + CustomRevisionEntity revisionEntity = revisionEntityRepository.findById(revision) + .orElse(null); if (revisionEntity == null) { throw new NotFoundException("Revision not found with revision id", REVISION, ERR_REVISIONS_NOT_FOUND, @@ -238,7 +239,8 @@ public Map> getChangesForRevision(Integer revision) { // show up in revisions where they were still around. However clearing for every request // causes the revisions api to be quite slow so we retrieve the changes manually using // the AuditReader. - CustomRevisionEntity revisionEntity = revisionEntityRepository.findOne(revision); + CustomRevisionEntity revisionEntity = revisionEntityRepository.findById(revision) + .orElse(null); if (revisionEntity == null) { throw new NotFoundException("The requested revision could not be found.", REVISION, ERR_REVISIONS_NOT_FOUND, diff --git a/src/main/java/org/radarbase/management/service/RoleService.java b/src/main/java/org/radarbase/management/service/RoleService.java index 217be9063..88d707695 100644 --- a/src/main/java/org/radarbase/management/service/RoleService.java +++ b/src/main/java/org/radarbase/management/service/RoleService.java @@ -111,7 +111,7 @@ public List findSuperAdminRoles() { @Transactional(readOnly = true) public RoleDTO findOne(Long id) { log.debug("Request to get Role : {}", id); - Role role = roleRepository.findOne(id); + Role role = roleRepository.findById(id).get(); return roleMapper.roleToRoleDTO(role); } @@ -122,7 +122,7 @@ public RoleDTO findOne(Long id) { */ public void delete(Long id) { log.debug("Request to delete Role : {}", id); - roleRepository.delete(id); + roleRepository.deleteById(id); } /** diff --git a/src/main/java/org/radarbase/management/service/SourceDataService.java b/src/main/java/org/radarbase/management/service/SourceDataService.java index ae4a489e1..2ad7bdf54 100644 --- a/src/main/java/org/radarbase/management/service/SourceDataService.java +++ b/src/main/java/org/radarbase/management/service/SourceDataService.java @@ -83,7 +83,7 @@ public Page findAll(Pageable pageable) { @Transactional(readOnly = true) public SourceDataDTO findOne(Long id) { log.debug("Request to get SourceData : {}", id); - SourceData sourceData = sourceDataRepository.findOne(id); + SourceData sourceData = sourceDataRepository.findById(id).get(); return sourceDataMapper.sourceDataToSourceDataDTO(sourceData); } @@ -108,6 +108,6 @@ public Optional findOneBySourceDataName(String sourceDataName) { @Transactional public void delete(Long id) { log.debug("Request to delete SourceData : {}", id); - sourceDataRepository.delete(id); + sourceDataRepository.deleteById(id); } } diff --git a/src/main/java/org/radarbase/management/service/SourceService.java b/src/main/java/org/radarbase/management/service/SourceService.java index b8e3cea3e..ff2a624a3 100644 --- a/src/main/java/org/radarbase/management/service/SourceService.java +++ b/src/main/java/org/radarbase/management/service/SourceService.java @@ -114,7 +114,7 @@ public Optional findOneByName(String sourceName) { @Transactional(readOnly = true) public Optional findOneById(Long id) { log.debug("Request to get Source by id: {}", id); - return Optional.ofNullable(sourceRepository.findOne(id)) + return Optional.ofNullable(sourceRepository.findById(id).orElse(null)) .map(sourceMapper::sourceToSourceDTO); } @@ -130,7 +130,7 @@ public void delete(Long id) { List sources = sourceHistory.getContent().stream().map(Revision::getEntity) .filter(Source::isAssigned).collect(Collectors.toList()); if (sources.isEmpty()) { - sourceRepository.delete(id); + sourceRepository.deleteById(id); } else { Map errorParams = new HashMap<>(); errorParams.put("message", "Cannot delete source with sourceId "); @@ -212,7 +212,7 @@ public MinimalSourceDetailsDTO safeUpdateOfAttributes(Source sourceToUpdate, */ @Transactional public SourceDTO updateSource(SourceDTO sourceDto) { - Source existingSource = sourceRepository.findOne(sourceDto.getId()); + Source existingSource = sourceRepository.findById(sourceDto.getId()).get(); // if the source is being transferred to another project. if (!existingSource.getProject().getId().equals(sourceDto.getProject().getId())) { if (existingSource.isAssigned()) { diff --git a/src/main/java/org/radarbase/management/service/SourceTypeService.java b/src/main/java/org/radarbase/management/service/SourceTypeService.java index b2775183c..06a42e1f5 100644 --- a/src/main/java/org/radarbase/management/service/SourceTypeService.java +++ b/src/main/java/org/radarbase/management/service/SourceTypeService.java @@ -61,7 +61,7 @@ public SourceTypeDTO save(SourceTypeDTO sourceTypeDto) { data.setSourceType(sourceType); } sourceType = sourceTypeRepository.save(sourceType); - sourceDataRepository.save(sourceType.getSourceData()); + sourceDataRepository.saveAll(sourceType.getSourceData()); return sourceTypeMapper.sourceTypeToSourceTypeDTO(sourceType); } @@ -98,7 +98,7 @@ public Page findAll(Pageable pageable) { */ public void delete(Long id) { log.debug("Request to delete SourceType : {}", id); - sourceTypeRepository.delete(id); + sourceTypeRepository.deleteById(id); } /** diff --git a/src/main/java/org/radarbase/management/service/SubjectService.java b/src/main/java/org/radarbase/management/service/SubjectService.java index 6dbba999e..b4c609cbb 100644 --- a/src/main/java/org/radarbase/management/service/SubjectService.java +++ b/src/main/java/org/radarbase/management/service/SubjectService.java @@ -127,7 +127,7 @@ public SubjectDTO createSubject(SubjectDTO subjectDto) { if (subject.getSources() != null && !subject.getSources().isEmpty()) { subject.getSources().forEach(s -> s.assigned(true).subject(subject)); } - sourceRepository.save(subject.getSources()); + sourceRepository.saveAll(subject.getSources()); return subjectMapper.subjectToSubjectReducedProjectDTO(subjectRepository.save(subject)); } @@ -162,7 +162,7 @@ public SubjectDTO updateSubject(SubjectDTO newSubjectDto) { if (newSubjectDto.getId() == null) { return createSubject(newSubjectDto); } - Subject subjectFromDb = subjectRepository.findOne(newSubjectDto.getId()); + Subject subjectFromDb = subjectRepository.findById(newSubjectDto.getId()).get(); //reset all the sources assigned to a subject to unassigned Set sourcesToUpdate = subjectFromDb.getSources(); sourcesToUpdate.forEach(s -> s.subject(null).assigned(false)); @@ -170,7 +170,7 @@ public SubjectDTO updateSubject(SubjectDTO newSubjectDto) { subjectMapper.safeUpdateSubjectFromDTO(newSubjectDto, subjectFromDb); sourcesToUpdate.addAll(subjectFromDb.getSources()); subjectFromDb.getSources().forEach(s -> s.subject(subjectFromDb).assigned(true)); - sourceRepository.save(sourcesToUpdate); + sourceRepository.saveAll(sourcesToUpdate); // update participant role subjectFromDb.getUser().setRoles(updateParticipantRoles(subjectFromDb, newSubjectDto)); return subjectMapper.subjectToSubjectReducedProjectDTO( @@ -215,7 +215,7 @@ public Page findAll(Pageable pageable) { * @return the discontinued subject */ public SubjectDTO discontinueSubject(SubjectDTO subjectDto) { - Subject subject = subjectRepository.findOne(subjectDto.getId()); + Subject subject = subjectRepository.findById(subjectDto.getId()).get(); // reset all the sources assigned to a subject to unassigned unassignAllSources(subject); diff --git a/src/main/java/org/radarbase/management/service/UserService.java b/src/main/java/org/radarbase/management/service/UserService.java index 9827acd35..99c8d9919 100644 --- a/src/main/java/org/radarbase/management/service/UserService.java +++ b/src/main/java/org/radarbase/management/service/UserService.java @@ -247,8 +247,7 @@ public void updateUser(String firstName, String lastName, String email, String l * @return updated user */ public Optional updateUser(UserDTO userDto) { - return Optional.of(userRepository - .findOne(userDto.getId())) + return userRepository.findById(userDto.getId()) .map(user -> { user.setLogin(userDto.getLogin()); user.setFirstName(userDto.getFirstName()); diff --git a/src/main/java/org/radarbase/management/service/dto/RevisionDTO.java b/src/main/java/org/radarbase/management/service/dto/RevisionDTO.java index 2c647b8df..9951e913d 100644 --- a/src/main/java/org/radarbase/management/service/dto/RevisionDTO.java +++ b/src/main/java/org/radarbase/management/service/dto/RevisionDTO.java @@ -24,8 +24,8 @@ public RevisionDTO() { * @param entity the entity */ public RevisionDTO(Revision revision, RevisionType revisionType, Object entity) { - id = revision.getRevisionNumber().intValue(); - timestamp = Instant.ofEpochMilli(revision.getRevisionDate().getMillis()); + id = (int) revision.getRevisionNumber().get(); // Make sure no NPE is thrown. + timestamp = (Instant) revision.getRevisionInstant().get(); // Make sure no NPE is thrown. author = ((CustomRevisionEntity) revision.getMetadata().getDelegate()).getAuditor(); this.entity = entity; this.revisionType = revisionType; diff --git a/src/main/java/org/radarbase/management/service/mapper/decorator/SourceMapperDecorator.java b/src/main/java/org/radarbase/management/service/mapper/decorator/SourceMapperDecorator.java index e471fa2af..d7856804e 100644 --- a/src/main/java/org/radarbase/management/service/mapper/decorator/SourceMapperDecorator.java +++ b/src/main/java/org/radarbase/management/service/mapper/decorator/SourceMapperDecorator.java @@ -40,7 +40,7 @@ public Source descriptiveDTOToSource(MinimalSourceDetailsDTO minimalSource) { public Source sourceDTOToSource(SourceDTO sourceDto) { Source source = delegate.sourceDTOToSource(sourceDto); if (sourceDto.getId() != null) { - Source existingSource = sourceRepository.findOne(sourceDto.getId()); + Source existingSource = sourceRepository.findById(sourceDto.getId()).get(); if (sourceDto.getSubjectLogin() == null) { source.setSubject(existingSource.getSubject()); } else { diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 2ecd5f524..af58ddc1a 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -48,6 +48,11 @@ management: enabled: false # When using the MailService, configure an SMTP server and set this to true db: enabled: true + management: + endpoint: + metrics: + enabled: false + spring: application: name: ManagementPortal diff --git a/src/test/java/org/radarbase/management/service/MetaTokenServiceTest.java b/src/test/java/org/radarbase/management/service/MetaTokenServiceTest.java index 0a2822a6d..90dfbbc2c 100644 --- a/src/test/java/org/radarbase/management/service/MetaTokenServiceTest.java +++ b/src/test/java/org/radarbase/management/service/MetaTokenServiceTest.java @@ -153,7 +153,7 @@ public void testRemovingExpiredMetaToken() { .tokenName("somethingelseandelse") .expiryDate(Instant.now().plus(Duration.ofHours(1))); - metaTokenRepository.save(Arrays.asList(tokenFetched, tokenExpired, tokenNew)); + metaTokenRepository.saveAll(Arrays.asList(tokenFetched, tokenExpired, tokenNew)); metaTokenService.removeStaleTokens(); diff --git a/src/test/java/org/radarbase/management/service/UserServiceIntTest.java b/src/test/java/org/radarbase/management/service/UserServiceIntTest.java index a53f6b458..f0d749bf2 100644 --- a/src/test/java/org/radarbase/management/service/UserServiceIntTest.java +++ b/src/test/java/org/radarbase/management/service/UserServiceIntTest.java @@ -237,7 +237,7 @@ public void testFindNotActivatedUsersByCreationDateBefore() { @Test public void assertThatAnonymousUserIsNotGet() { - final PageRequest pageable = new PageRequest(0, (int) userRepository.count()); + final PageRequest pageable = PageRequest.of(0, (int) userRepository.count()); final Page allManagedUsers = userService.findUsers(new UserFilter(), pageable); assertThat(allManagedUsers.getContent().stream() .noneMatch(user -> Constants.ANONYMOUS_USER.equals(user.getLogin()))) diff --git a/src/test/java/org/radarbase/management/web/rest/AccountResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/AccountResourceIntTest.java index d5735e7e4..b93f9a012 100644 --- a/src/test/java/org/radarbase/management/web/rest/AccountResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/AccountResourceIntTest.java @@ -125,7 +125,7 @@ public void testGetExistingAccount() throws Exception { restUserMockMvc.perform(get("/api/account") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.login").value("test")) .andExpect(jsonPath("$.firstName").value("john")) .andExpect(jsonPath("$.lastName").value("doe")) diff --git a/src/test/java/org/radarbase/management/web/rest/AuditResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/AuditResourceIntTest.java index d04ce901a..84325d064 100644 --- a/src/test/java/org/radarbase/management/web/rest/AuditResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/AuditResourceIntTest.java @@ -113,7 +113,7 @@ public void getAllAudits() throws Exception { // Get all the audits restAuditMockMvc.perform(get("/management/audits")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].principal").value(hasItem(SAMPLE_PRINCIPAL))); } @@ -125,7 +125,7 @@ public void getAudit() throws Exception { // Get the audit restAuditMockMvc.perform(get("/management/audits/{id}", auditEvent.getId())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.principal").value(SAMPLE_PRINCIPAL)); } @@ -142,7 +142,7 @@ public void getAuditsByDate() throws Exception { restAuditMockMvc.perform(get("/management/audits?fromDate=" + fromDate + "&toDate=" + toDate)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].principal").value(hasItem(SAMPLE_PRINCIPAL))); } @@ -160,7 +160,7 @@ public void getNonExistingAuditsByDate() throws Exception { restAuditMockMvc.perform(get("/management/audits?fromDate=" + fromDate + "&toDate=" + toDate)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(header().string("X-Total-Count", "0")); } diff --git a/src/test/java/org/radarbase/management/web/rest/LogsResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/LogsResourceIntTest.java index a3bb1afc6..f06368bf6 100644 --- a/src/test/java/org/radarbase/management/web/rest/LogsResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/LogsResourceIntTest.java @@ -42,7 +42,7 @@ public void setUp() { public void getAllLogs()throws Exception { restLogsMockMvc.perform(get("/management/logs")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); } @Test diff --git a/src/test/java/org/radarbase/management/web/rest/ProfileInfoResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/ProfileInfoResourceIntTest.java index 151d96363..7699a4fea 100644 --- a/src/test/java/org/radarbase/management/web/rest/ProfileInfoResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/ProfileInfoResourceIntTest.java @@ -61,7 +61,7 @@ public void setUp() { public void getProfileInfoWithRibbon() throws Exception { restProfileMockMvc.perform(get("/api/profile-info")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); } @Test @@ -72,7 +72,7 @@ public void getProfileInfoWithoutRibbon() throws Exception { restProfileMockMvc.perform(get("/api/profile-info")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); } @Test @@ -83,6 +83,6 @@ public void getProfileInfoWithoutActiveProfiles() throws Exception { restProfileMockMvc.perform(get("/api/profile-info")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); } } diff --git a/src/test/java/org/radarbase/management/web/rest/ProjectResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/ProjectResourceIntTest.java index a4d293290..b426f539c 100644 --- a/src/test/java/org/radarbase/management/web/rest/ProjectResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/ProjectResourceIntTest.java @@ -258,7 +258,7 @@ public void getAllProjects() throws Exception { // Get all the projectList restProjectMockMvc.perform(get("/api/projects?sort=id,desc")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(project.getId().intValue()))) .andExpect(jsonPath("$.[*].projectName").value(hasItem(DEFAULT_PROJECT_NAME))) .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION))) @@ -280,7 +280,7 @@ public void getProject() throws Exception { // Get the project restProjectMockMvc.perform(get("/api/projects/{projectName}", project.getProjectName())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(project.getId().intValue())) .andExpect(jsonPath("$.projectName").value(DEFAULT_PROJECT_NAME)) .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION)) @@ -307,7 +307,7 @@ public void updateProject() throws Exception { int databaseSizeBeforeUpdate = projectRepository.findAll().size(); // Update the project - Project updatedProject = projectRepository.findOne(project.getId()); + Project updatedProject = projectRepository.findById(project.getId()).get(); updatedProject .projectName(UPDATED_PROJECT_NAME) .description(UPDATED_DESCRIPTION) diff --git a/src/test/java/org/radarbase/management/web/rest/SourceDataResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/SourceDataResourceIntTest.java index 01556e2a5..068d986a7 100644 --- a/src/test/java/org/radarbase/management/web/rest/SourceDataResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/SourceDataResourceIntTest.java @@ -220,7 +220,7 @@ public void getAllSourceData() throws Exception { // Get all the sourceDataList restSourceDataMockMvc.perform(get("/api/source-data?sort=id,desc")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(sourceData.getId().intValue()))) .andExpect(jsonPath("$.[*].sourceDataType").value( hasItem(DEFAULT_SOURCE_DATA_TYPE))) @@ -244,7 +244,7 @@ public void getAllSourceDataWithPagination() throws Exception { // Get all the sourceDataList restSourceDataMockMvc.perform(get("/api/source-data?page=0&size=5&sort=id,desc")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(sourceData.getId().intValue()))) .andExpect(jsonPath("$.[*].sourceDataType").value( hasItem(DEFAULT_SOURCE_DATA_TYPE))) @@ -269,7 +269,7 @@ public void getSourceData() throws Exception { restSourceDataMockMvc.perform(get("/api/source-data/{sourceDataName}", sourceData.getSourceDataName())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(sourceData.getId().intValue())) .andExpect(jsonPath("$.sourceDataType").value(DEFAULT_SOURCE_DATA_TYPE)) .andExpect(jsonPath("$.sourceDataName").value(DEFAULT_SOURCE_DATA_NAME)) @@ -298,7 +298,7 @@ public void updateSourceData() throws Exception { int databaseSizeBeforeUpdate = sourceDataRepository.findAll().size(); // Update the sourceData - SourceData updatedSourceData = sourceDataRepository.findOne(sourceData.getId()); + SourceData updatedSourceData = sourceDataRepository.findById(sourceData.getId()).get(); updatedSourceData .sourceDataType(UPDATED_SOURCE_DATA_TYPE) .sourceDataName(UPDATED_SOURCE_DATA_NAME) diff --git a/src/test/java/org/radarbase/management/web/rest/SourceResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/SourceResourceIntTest.java index e49ad7e56..35a9a9f27 100644 --- a/src/test/java/org/radarbase/management/web/rest/SourceResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/SourceResourceIntTest.java @@ -140,7 +140,7 @@ public void initTest() { List sourceTypeDtos = sourceTypeService.findAll(); assertThat(sourceTypeDtos.size()).isGreaterThan(0); source.setSourceType(sourceTypeMapper.sourceTypeDTOToSourceType(sourceTypeDtos.get(0))); - project = projectRepository.findOne(1L); + project = projectRepository.findById(1L).get(); source.project(project); } @@ -242,7 +242,7 @@ public void getAllSources() throws Exception { // Get all the deviceList restDeviceMockMvc.perform(get("/api/sources?sort=id,desc")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(source.getId().intValue()))) .andExpect(jsonPath("$.[*].sourceId").value(everyItem(notNullValue()))) .andExpect(jsonPath("$.[*].assigned").value( @@ -258,7 +258,7 @@ public void getSource() throws Exception { // Get the source restDeviceMockMvc.perform(get("/api/sources/{sourceName}", source.getSourceName())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(source.getId().intValue())) .andExpect(jsonPath("$.sourceId").value(notNullValue())) .andExpect(jsonPath("$.assigned").value(DEFAULT_ASSIGNED.booleanValue())); @@ -280,7 +280,7 @@ public void updateSource() throws Exception { int databaseSizeBeforeUpdate = sourceRepository.findAll().size(); // Update the source - Source updatedSource = sourceRepository.findOne(source.getId()); + Source updatedSource = sourceRepository.findById(source.getId()).get(); updatedSource .sourceId(UPDATED_SOURCE_PHYSICAL_ID) .assigned(UPDATED_ASSIGNED); diff --git a/src/test/java/org/radarbase/management/web/rest/SourceTypeResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/SourceTypeResourceIntTest.java index 431ed45e4..8ccf833d5 100644 --- a/src/test/java/org/radarbase/management/web/rest/SourceTypeResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/SourceTypeResourceIntTest.java @@ -262,7 +262,7 @@ public void getAllSourceTypes() throws Exception { // Get all the sourceTypeList restSourceTypeMockMvc.perform(get("/api/source-types")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(sourceType.getId().intValue()))) .andExpect(jsonPath("$.[*].producer").value(hasItem(DEFAULT_PRODUCER))) .andExpect(jsonPath("$.[*].model").value(hasItem(DEFAULT_MODEL))) @@ -281,7 +281,7 @@ public void getAllSourceTypesWithPagination() throws Exception { // Get all the sourceTypeList restSourceTypeMockMvc.perform(get("/api/source-types?page=0&size=5&sort=id,desc")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(sourceType.getId().intValue()))) .andExpect(jsonPath("$.[*].producer").value(hasItem(DEFAULT_PRODUCER))) .andExpect(jsonPath("$.[*].model").value(hasItem(DEFAULT_MODEL))) @@ -301,7 +301,7 @@ public void getSourceType() throws Exception { restSourceTypeMockMvc.perform(get("/api/source-types/{prodcuer}/{model}/{version}", sourceType.getProducer(), sourceType.getModel(), sourceType.getCatalogVersion())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(sourceType.getId().intValue())) .andExpect(jsonPath("$.producer").value(DEFAULT_PRODUCER)) .andExpect(jsonPath("$.model").value(DEFAULT_MODEL)) @@ -326,7 +326,7 @@ public void updateSourceType() throws Exception { int databaseSizeBeforeUpdate = sourceTypeRepository.findAll().size(); // Update the sourceType - SourceType updatedSourceType = sourceTypeRepository.findOne(sourceType.getId()); + SourceType updatedSourceType = sourceTypeRepository.findById(sourceType.getId()).get(); updatedSourceType .producer(UPDATED_PRODUCER) .model(UPDATED_MODEL) diff --git a/src/test/java/org/radarbase/management/web/rest/SubjectResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/SubjectResourceIntTest.java index 2b51b3489..b64d2f0c2 100644 --- a/src/test/java/org/radarbase/management/web/rest/SubjectResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/SubjectResourceIntTest.java @@ -182,7 +182,7 @@ public void getAllSubjects() throws Exception { // Get all the subjectList restSubjectMockMvc.perform(get("/api/subjects?sort=id,desc")) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(subjectDto.getId().intValue()))) .andExpect(jsonPath("$.[*].externalLink").value(hasItem(DEFAULT_EXTERNAL_LINK))) .andExpect(jsonPath("$.[*].externalId").value(hasItem(DEFAULT_ENTERNAL_ID))) @@ -198,7 +198,7 @@ public void getSubject() throws Exception { // Get the subject restSubjectMockMvc.perform(get("/api/subjects/{login}", subjectDto.getLogin())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(subjectDto.getId().intValue())) .andExpect(jsonPath("$.externalLink").value(DEFAULT_EXTERNAL_LINK)) .andExpect(jsonPath("$.externalId").value(DEFAULT_ENTERNAL_ID)) @@ -221,7 +221,7 @@ public void updateSubject() throws Exception { final int databaseSizeBeforeUpdate = subjectRepository.findAll().size(); // Update the subject - Subject updatedSubject = subjectRepository.findOne(subjectDto.getId()); + Subject updatedSubject = subjectRepository.findById(subjectDto.getId()).get(); updatedSubject .externalLink(UPDATED_EXTERNAL_LINK) .externalId(UPDATED_ENTERNAL_ID) @@ -250,7 +250,7 @@ public void updateSubjectWithNewProject() throws Exception { final int databaseSizeBeforeUpdate = subjectRepository.findAll().size(); // Update the subject - Subject updatedSubject = subjectRepository.findOne(subjectDto.getId()); + Subject updatedSubject = subjectRepository.findById(subjectDto.getId()).get(); updatedSubject @@ -400,7 +400,7 @@ public void dynamicSourceRegistrationWithoutId() throws Exception { restSubjectMockMvc .perform(get("/api/subjects/{login}/sources?sort=id,desc", subjectDto.getLogin())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").isNotEmpty()); } @@ -457,7 +457,7 @@ public void getSubjectSources() throws Exception { // Get the subject restSubjectMockMvc.perform(get("/api/subjects/{login}/sources", createdSubject.getLogin())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[0].id").value(createdSource.getId().intValue())) .andExpect( jsonPath("$.[0].sourceId").value(createdSource.getSourceId().toString())); @@ -486,7 +486,7 @@ public void getSubjectSourcesWithQueryParam() throws Exception { restSubjectMockMvc.perform(get("/api/subjects/{login}/sources?withInactiveSources=true", createdSubject.getLogin())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(createdSource.getId().intValue())) .andExpect( jsonPath("$.[*].sourceId").value(createdSource.getSourceId().toString())); @@ -520,7 +520,7 @@ public void getInactiveSubjectSourcesWithQueryParam() throws Exception { restSubjectMockMvc.perform(get("/api/subjects/{login}/sources?withInactiveSources=true", updatedSubject.getLogin())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(createdSource.getId().intValue())) .andExpect( jsonPath("$.[*].sourceId").value(createdSource.getSourceId().toString())); @@ -530,7 +530,7 @@ public void getInactiveSubjectSourcesWithQueryParam() throws Exception { .perform(get("/api/subjects/{login}/sources?withInactiveSources=false", updatedSubject.getLogin())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); } diff --git a/src/test/java/org/radarbase/management/web/rest/UserResourceIntTest.java b/src/test/java/org/radarbase/management/web/rest/UserResourceIntTest.java index c39f8a801..9ee855864 100644 --- a/src/test/java/org/radarbase/management/web/rest/UserResourceIntTest.java +++ b/src/test/java/org/radarbase/management/web/rest/UserResourceIntTest.java @@ -261,7 +261,7 @@ public void getAllUsers() throws Exception { restUserMockMvc.perform(get("/api/users?sort=id,desc") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].login").value(hasItem(DEFAULT_LOGIN))) .andExpect(jsonPath("$.[*].firstName").value(hasItem(DEFAULT_FIRSTNAME))) .andExpect(jsonPath("$.[*].lastName").value(hasItem(DEFAULT_LASTNAME))) @@ -278,7 +278,7 @@ public void getUser() throws Exception { // Get the user restUserMockMvc.perform(get("/api/users/{login}", user.getLogin())) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.login").value(user.getLogin())) .andExpect(jsonPath("$.firstName").value(DEFAULT_FIRSTNAME)) .andExpect(jsonPath("$.lastName").value(DEFAULT_LASTNAME)) @@ -301,7 +301,7 @@ public void updateUser() throws Exception { final int databaseSizeBeforeUpdate = userRepository.findAll().size(); // Update the user - User updatedUser = userRepository.findOne(user.getId()); + User updatedUser = userRepository.findById(user.getId()).get(); Set roles = new HashSet<>(); RoleDTO role = new RoleDTO(); @@ -342,7 +342,7 @@ public void updateUserLogin() throws Exception { final int databaseSizeBeforeUpdate = userRepository.findAll().size(); // Update the user - User updatedUser = userRepository.findOne(user.getId()); + User updatedUser = userRepository.findById(user.getId()).get(); Set roles = new HashSet<>(); RoleDTO role = new RoleDTO(); @@ -393,7 +393,7 @@ public void updateUserExistingEmail() throws Exception { userRepository.saveAndFlush(anotherUser); // Update the user - User updatedUser = userRepository.findOne(user.getId()); + User updatedUser = userRepository.findById(user.getId()).get(); Set roles = new HashSet<>(); RoleDTO role = new RoleDTO(); role.setAuthorityName(AuthoritiesConstants.PARTICIPANT); @@ -433,7 +433,7 @@ public void updateUserExistingLogin() throws Exception { userRepository.saveAndFlush(anotherUser); // Update the user - User updatedUser = userRepository.findOne(user.getId()); + User updatedUser = userRepository.findById(user.getId()).get(); Set roles = new HashSet<>(); RoleDTO role = new RoleDTO();