diff --git a/pom.xml b/pom.xml
index 6cdac6dead..ded9ad197e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -227,6 +227,10 @@
org.springframework.boot
spring-boot-starter-jdbc
+
+ org.springframework.session
+ spring-session-jdbc
+
@@ -445,9 +449,9 @@
1.16
- com.typesafe.akka
- akka-slf4j_2.11
- 2.5.31
+ org.scala-lang
+ scala-library
+ 2.11.12
@@ -516,6 +520,12 @@
9.22.3
+
+ software.amazon.awssdk
+ cloudwatch
+ 2.20.162
+
+
org.springframework.boot
@@ -609,16 +619,15 @@
- com.typesafe.akka
- akka-testkit_2.11
- 2.5.31
+ org.testcontainers
+ postgresql
+ 1.20.3
test
org.testcontainers
- postgresql
- 1.19.0
- test
+ localstack
+ 1.20.3
diff --git a/src/main/java/fi/vm/sade/valinta/kooste/App.java b/src/main/java/fi/vm/sade/valinta/kooste/App.java
index 587bcd3713..12d8fd83fd 100644
--- a/src/main/java/fi/vm/sade/valinta/kooste/App.java
+++ b/src/main/java/fi/vm/sade/valinta/kooste/App.java
@@ -1,12 +1,13 @@
package fi.vm.sade.valinta.kooste;
-import java.io.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
+import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, MongoAutoConfiguration.class})
+@EnableScheduling
public class App {
public static final String CONTEXT_PATH = "/valintalaskentakoostepalvelu";
diff --git a/src/main/java/fi/vm/sade/valinta/kooste/configuration/AwsConfiguration.java b/src/main/java/fi/vm/sade/valinta/kooste/configuration/AwsConfiguration.java
new file mode 100644
index 0000000000..f5b28813d9
--- /dev/null
+++ b/src/main/java/fi/vm/sade/valinta/kooste/configuration/AwsConfiguration.java
@@ -0,0 +1,38 @@
+package fi.vm.sade.valinta.kooste.configuration;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClientBuilder;
+
+@Configuration
+public class AwsConfiguration {
+
+ @Bean
+ public CloudWatchClient cloudWatchClient(Environment environment) throws URISyntaxException {
+ boolean isLocal =
+ Arrays.stream(environment.getActiveProfiles())
+ .anyMatch(
+ env ->
+ (env.equalsIgnoreCase("test")
+ || env.equalsIgnoreCase("mockservices")
+ || env.equalsIgnoreCase("dev")));
+
+ CloudWatchClientBuilder builder =
+ CloudWatchClient.builder().credentialsProvider(DefaultCredentialsProvider.create());
+
+ if (isLocal) {
+ builder
+ .region(Region.US_EAST_1)
+ .endpointOverride(new URI("http://localhost:" + System.getProperty("localstackPort")));
+ }
+
+ return builder.build();
+ }
+}
diff --git a/src/main/java/fi/vm/sade/valinta/kooste/configuration/SecurityConfiguration.java b/src/main/java/fi/vm/sade/valinta/kooste/configuration/SecurityConfiguration.java
index 03a4d00481..47b3ea548a 100644
--- a/src/main/java/fi/vm/sade/valinta/kooste/configuration/SecurityConfiguration.java
+++ b/src/main/java/fi/vm/sade/valinta/kooste/configuration/SecurityConfiguration.java
@@ -21,12 +21,16 @@
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession;
+import org.springframework.session.web.http.CookieSerializer;
+import org.springframework.session.web.http.DefaultCookieSerializer;
@Profile({"default", "dev"})
@Configuration
@Order(2)
@EnableMethodSecurity(securedEnabled = true)
@EnableWebSecurity
+@EnableJdbcHttpSession
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private Environment environment;
@@ -152,4 +156,14 @@ protected void configure(HttpSecurity http) throws Exception {
protected void configure(AuthenticationManagerBuilder auth) {
auth.authenticationProvider(casAuthenticationProvider());
}
+
+ @Bean
+ public CookieSerializer cookieSerializer() {
+ DefaultCookieSerializer serializer = new DefaultCookieSerializer();
+ serializer.setUseSecureCookie(true);
+ serializer.setCookieName("JSESSIONID");
+ serializer.setCookiePath("/valintalaskentakoostepalvelu");
+ serializer.setUseBase64Encoding(false);
+ return serializer;
+ }
}
diff --git a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/HttpClients.java b/src/main/java/fi/vm/sade/valinta/kooste/external/resource/HttpClients.java
index 27befd193a..a243bd1fad 100644
--- a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/HttpClients.java
+++ b/src/main/java/fi/vm/sade/valinta/kooste/external/resource/HttpClients.java
@@ -274,6 +274,7 @@ public RestCasClient getSuoritusrekisteriCasClient(
return new RestCasClient(
new CasConfig.CasConfigBuilder(
username, password, ticketsUrl, service, CSRF_VALUE, CALLER_ID, "")
+ .setNumberOfRetries(0)
.setJsessionName("JSESSIONID")
.build());
}
diff --git a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/seuranta/LaskentaSeurantaAsyncResource.java b/src/main/java/fi/vm/sade/valinta/kooste/external/resource/seuranta/LaskentaSeurantaAsyncResource.java
deleted file mode 100644
index d159c31451..0000000000
--- a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/seuranta/LaskentaSeurantaAsyncResource.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package fi.vm.sade.valinta.kooste.external.resource.seuranta;
-
-import fi.vm.sade.valinta.kooste.valintalaskenta.resource.LaskentaParams;
-import fi.vm.sade.valinta.seuranta.dto.HakukohdeDto;
-import fi.vm.sade.valinta.seuranta.dto.HakukohdeTila;
-import fi.vm.sade.valinta.seuranta.dto.IlmoitusDto;
-import fi.vm.sade.valinta.seuranta.dto.LaskentaDto;
-import fi.vm.sade.valinta.seuranta.dto.LaskentaTila;
-import fi.vm.sade.valinta.seuranta.dto.TunnisteDto;
-import io.reactivex.Observable;
-import java.util.List;
-import java.util.Optional;
-import org.springframework.http.ResponseEntity;
-
-public interface LaskentaSeurantaAsyncResource {
-
- Observable> otaSeuraavaLaskentaTyonAlle();
-
- Observable laskenta(String uuid);
-
- Observable resetoiTilat(String uuid);
-
- Observable luoLaskenta(
- LaskentaParams laskentaParams, List hakukohdeOids);
-
- Observable merkkaaHakukohteenTila(
- String uuid,
- String hakukohdeOid,
- HakukohdeTila tila,
- Optional ilmoitusDtoOptional);
-
- Observable merkkaaLaskennanTila(
- String uuid,
- LaskentaTila tila,
- HakukohdeTila hakukohdetila,
- Optional ilmoitusDtoOptional);
-
- Observable merkkaaLaskennanTila(
- String uuid, LaskentaTila tila, Optional ilmoitusDtoOptional);
-}
diff --git a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/seuranta/impl/LaskentaSeurantaAsyncResourceImpl.java b/src/main/java/fi/vm/sade/valinta/kooste/external/resource/seuranta/impl/LaskentaSeurantaAsyncResourceImpl.java
deleted file mode 100644
index 75d88288d6..0000000000
--- a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/seuranta/impl/LaskentaSeurantaAsyncResourceImpl.java
+++ /dev/null
@@ -1,195 +0,0 @@
-package fi.vm.sade.valinta.kooste.external.resource.seuranta.impl;
-
-import com.google.gson.reflect.TypeToken;
-import fi.vm.sade.valinta.kooste.external.resource.seuranta.LaskentaSeurantaAsyncResource;
-import fi.vm.sade.valinta.kooste.external.resource.viestintapalvelu.RestCasClient;
-import fi.vm.sade.valinta.kooste.url.UrlConfiguration;
-import fi.vm.sade.valinta.kooste.valintalaskenta.resource.LaskentaParams;
-import fi.vm.sade.valinta.seuranta.dto.HakukohdeDto;
-import fi.vm.sade.valinta.seuranta.dto.HakukohdeTila;
-import fi.vm.sade.valinta.seuranta.dto.IlmoitusDto;
-import fi.vm.sade.valinta.seuranta.dto.LaskentaDto;
-import fi.vm.sade.valinta.seuranta.dto.LaskentaTila;
-import fi.vm.sade.valinta.seuranta.dto.TunnisteDto;
-import io.reactivex.Observable;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Function;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-
-@Service
-public class LaskentaSeurantaAsyncResourceImpl implements LaskentaSeurantaAsyncResource {
- private final Logger LOG = LoggerFactory.getLogger(getClass());
-
- private final RestCasClient restCasClient;
-
- private final UrlConfiguration urlConfiguration;
-
- @Autowired
- public LaskentaSeurantaAsyncResourceImpl(
- @Qualifier("ValintalaskentaCasClient") RestCasClient restCasClient) {
- this.restCasClient = restCasClient;
- this.urlConfiguration = UrlConfiguration.getInstance();
- }
-
- @Override
- public Observable> otaSeuraavaLaskentaTyonAlle() {
- Function> extractor =
- response -> StringUtils.isBlank(response) ? Optional.empty() : Optional.of(response);
- return Observable.fromFuture(
- this.restCasClient
- .get(
- this.urlConfiguration.url(
- "seuranta-service.seuranta.laskenta.otaseuraavalaskentatyonalle"),
- Map.of("Accept", "text/plain"),
- 10 * 60 * 1000)
- .thenApply(response -> response.getResponseBody())
- .thenApply(extractor));
- }
-
- public Observable laskenta(String uuid) {
- return Observable.fromFuture(
- this.restCasClient.get(
- this.urlConfiguration.url("seuranta-service.seuranta.kuormantasaus.laskenta", uuid),
- new TypeToken() {},
- Collections.emptyMap(),
- 10 * 60 * 1000));
- }
-
- public Observable resetoiTilat(String uuid) {
- return Observable.fromFuture(
- this.restCasClient.put(
- this.urlConfiguration.url(
- "seuranta-service.seuranta.kuormantasaus.laskenta.resetoi", uuid),
- new TypeToken() {},
- uuid,
- Collections.emptyMap(),
- 10 * 60 * 1000));
- }
-
- public Observable luoLaskenta(
- LaskentaParams laskentaParams, List hakukohdeOids) {
-
- String url =
- this.urlConfiguration.url(
- "seuranta-service.seuranta.kuormantasaus.laskenta.tyyppi",
- laskentaParams.getHakuOid(),
- laskentaParams.getLaskentatyyppi());
- url += "?userOID=" + URLEncoder.encode(laskentaParams.getUserOID(), StandardCharsets.UTF_8);
- if (laskentaParams.getNimi() != null) {
- url += "&nimi=" + URLEncoder.encode(laskentaParams.getNimi(), StandardCharsets.UTF_8);
- }
- url += "&haunnimi=" + URLEncoder.encode(laskentaParams.getHaunNimi(), StandardCharsets.UTF_8);
- url += "&erillishaku=" + laskentaParams.isErillishaku();
- if (laskentaParams.getValinnanvaihe() != null) {
- url += "&valinnanvaihe=" + laskentaParams.getValinnanvaihe();
- }
- if (laskentaParams.getIsValintakoelaskenta() != null) {
- url += "&valintakoelaskenta=" + laskentaParams.getIsValintakoelaskenta();
- }
-
- return Observable.fromFuture(
- this.restCasClient.post(
- url, new TypeToken<>() {}, hakukohdeOids, Collections.emptyMap(), 10 * 60 * 1000));
- }
-
- public Observable merkkaaLaskennanTila(
- String uuid, LaskentaTila tila, Optional ilmoitusDtoOptional) {
- String url =
- this.urlConfiguration.url(
- "seuranta-service.seuranta.kuormantasaus.laskenta.tila", uuid, tila);
- try {
- if (ilmoitusDtoOptional.isPresent()) {
- return Observable.fromFuture(
- this.restCasClient
- .post(url, ilmoitusDtoOptional.get(), Collections.emptyMap(), 10 * 60 * 1000)
- .thenApply(r -> ResponseEntity.ok().build()));
- } else {
- return Observable.fromFuture(
- this.restCasClient
- .put(url, tila, Collections.emptyMap(), 10 * 60 * 1000)
- .thenApply(r -> ResponseEntity.ok().build()));
- }
- } catch (Exception e) {
- LOG.error("Seurantapalvelun kutsu paatyi virheeseen!" + url, e);
- return Observable.error(e);
- }
- }
-
- public Observable merkkaaLaskennanTila(
- String uuid,
- LaskentaTila tila,
- HakukohdeTila hakukohdetila,
- Optional ilmoitusDtoOptional) {
- String url =
- this.urlConfiguration.url(
- "seuranta-service.seuranta.kuormantasaus.laskenta.tila.hakukohde",
- uuid,
- tila,
- hakukohdetila);
- try {
- if (ilmoitusDtoOptional.isPresent()) {
- return Observable.fromFuture(
- this.restCasClient
- .post(url, ilmoitusDtoOptional.get(), Collections.emptyMap(), 10 * 60 * 1000)
- .thenApply(r -> ResponseEntity.ok().build()));
- } else {
- return Observable.fromFuture(
- this.restCasClient
- .put(url, new TypeToken<>() {}, tila, Collections.emptyMap(), 10 * 60 * 1000)
- .thenApply(r -> ResponseEntity.ok().build()));
- }
- } catch (Exception e) {
- LOG.error("Seurantapalvelun kutsu " + url + " laskennalle " + uuid + " paatyi virheeseen", e);
- return Observable.error(e);
- }
- }
-
- @Override
- public Observable merkkaaHakukohteenTila(
- String uuid,
- String hakukohdeOid,
- HakukohdeTila tila,
- Optional ilmoitusDtoOptional) {
- String url =
- this.urlConfiguration.url(
- "seuranta-service.seuranta.kuormantasaus.laskenta.hakukohde.tila",
- uuid,
- hakukohdeOid,
- tila);
- try {
- if (ilmoitusDtoOptional.isPresent()) {
- return Observable.fromFuture(
- this.restCasClient
- .post(url, ilmoitusDtoOptional.get(), Collections.emptyMap(), 10 * 60 * 1000)
- .thenApply(r -> ResponseEntity.ok().build()));
- } else {
- return Observable.fromFuture(
- this.restCasClient
- .put(url, new TypeToken<>() {}, tila, Collections.emptyMap(), 10 * 60 * 1000)
- .thenApply(r -> ResponseEntity.ok().build()));
- }
- } catch (Exception e) {
- LOG.error(
- "Seurantapalvelun kutsu "
- + url
- + " laskennalle "
- + uuid
- + " ja hakukohteelle "
- + hakukohdeOid
- + " paatyi virheeseen",
- e);
- return Observable.error(e);
- }
- }
-}
diff --git a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/valintaperusteet/ValintaperusteetAsyncResource.java b/src/main/java/fi/vm/sade/valinta/kooste/external/resource/valintaperusteet/ValintaperusteetAsyncResource.java
index c8ced1d4b1..9402a59311 100644
--- a/src/main/java/fi/vm/sade/valinta/kooste/external/resource/valintaperusteet/ValintaperusteetAsyncResource.java
+++ b/src/main/java/fi/vm/sade/valinta/kooste/external/resource/valintaperusteet/ValintaperusteetAsyncResource.java
@@ -3,7 +3,6 @@
import fi.vm.sade.service.valintaperusteet.dto.HakukohdeImportDTO;
import fi.vm.sade.service.valintaperusteet.dto.HakukohdeJaValintakoeDTO;
import fi.vm.sade.service.valintaperusteet.dto.HakukohdeJaValintaperusteDTO;
-import fi.vm.sade.service.valintaperusteet.dto.HakukohdeViiteDTO;
import fi.vm.sade.service.valintaperusteet.dto.ValinnanVaiheJonoillaDTO;
import fi.vm.sade.service.valintaperusteet.dto.ValintakoeDTO;
import fi.vm.sade.service.valintaperusteet.dto.ValintaperusteDTO;
@@ -25,9 +24,6 @@ Observable