-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OK-493 Migroidaan jatkuvat sijoittelut seurantapalvelusta
- Loading branch information
Showing
4 changed files
with
111 additions
and
19 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...java/fi/vm/sade/sijoittelu/flyway/V20240419000001__LueJatkuvatSijoittelutSeurannasta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package fi.vm.sade.sijoittelu.flyway; | ||
|
||
import com.google.gson.reflect.TypeToken; | ||
import fi.vm.sade.sijoittelu.kooste.external.resource.viestintapalvelu.RestCasClient; | ||
import fi.vm.sade.sijoittelu.laskenta.util.UrlProperties; | ||
import fi.vm.sade.valinta.seuranta.sijoittelu.dto.SijoitteluDto; | ||
import org.flywaydb.core.api.migration.jdbc.JdbcMigration; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.datasource.SingleConnectionDataSource; | ||
|
||
import java.sql.Connection; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.regex.Pattern; | ||
|
||
public class V20240419000001__LueJatkuvatSijoittelutSeurannasta implements JdbcMigration { | ||
|
||
private static RestCasClient seurantaCasClient; | ||
private static UrlProperties urlProperties; | ||
|
||
// ainakin hahtuvalla seurantapalvelu antaa ulos osittain täyttä roskaa, joten suodatetaan sijoittelut | ||
// joilla validi oid | ||
private static final Pattern OID_PATTERN = Pattern.compile("^[0-9]+(\\.[0-9]+)*$"); | ||
|
||
public static void setDependencies(UrlProperties properties, RestCasClient client) { | ||
urlProperties = properties; | ||
seurantaCasClient = client; | ||
} | ||
|
||
public Collection<SijoitteluDto> hae() { | ||
try { | ||
return seurantaCasClient | ||
.get( | ||
urlProperties.url("valintalaskentakoostepalvelu.seuranta.rest.url") | ||
+ "/sijoittelunseuranta/hae", | ||
new TypeToken<Collection<SijoitteluDto>>() {}, | ||
Collections.emptyMap(), | ||
10 * 60 * 1000) | ||
.get(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void migrate(Connection connection) { | ||
JdbcTemplate template = new JdbcTemplate(); | ||
template.setDataSource(new SingleConnectionDataSource(connection, true)); | ||
for(SijoitteluDto sijoitteluDto : this.hae()) { | ||
if(OID_PATTERN.matcher(sijoitteluDto.getHakuOid()).matches()) { | ||
template.update( | ||
"INSERT INTO jatkuvat " + | ||
"(haku_oid, jatkuva_paalla, viimeksi_ajettu, aloitus, ajotiheys) " + | ||
"VALUES (?, ?, ?::timestamptz, ?::timestamptz, ?)", | ||
sijoitteluDto.getHakuOid(), | ||
sijoitteluDto.isAjossa(), | ||
sijoitteluDto.getViimeksiAjettu(), | ||
sijoitteluDto.getAloitusajankohta(), | ||
sijoitteluDto.getAjotiheys()); | ||
} | ||
} | ||
} | ||
} |
7 changes: 6 additions & 1 deletion
7
...c/main/java/fi/vm/sade/sijoittelu/kooste/sijoittelu/route/impl/SijoitteluRouteConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...rvice/src/main/java/fi/vm/sade/sijoittelu/laskenta/configuration/FlywayConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package fi.vm.sade.sijoittelu.laskenta.configuration; | ||
|
||
import fi.vm.sade.sijoittelu.flyway.V20240419000001__LueJatkuvatSijoittelutSeurannasta; | ||
import fi.vm.sade.sijoittelu.kooste.external.resource.viestintapalvelu.RestCasClient; | ||
import fi.vm.sade.sijoittelu.laskenta.util.UrlProperties; | ||
import org.flywaydb.core.Flyway; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
@Configuration | ||
public class FlywayConfiguration { | ||
|
||
@Autowired | ||
JdbcTemplate jdbcTemplate; | ||
|
||
@Autowired | ||
@Qualifier("SeurantaCasClient") | ||
RestCasClient seurantaCasClient; | ||
|
||
@Autowired | ||
UrlProperties urlProperties; | ||
|
||
public static class FlywayMigrationDone {} | ||
|
||
@Bean | ||
public FlywayMigrationDone doFlywayMigration() { | ||
V20240419000001__LueJatkuvatSijoittelutSeurannasta.setDependencies(this.urlProperties, this.seurantaCasClient); | ||
|
||
Flyway flyway = new Flyway(); | ||
flyway.setSchemas("public"); | ||
flyway.setDataSource(jdbcTemplate.getDataSource()); | ||
flyway.setLocations("/db/migration", "fi.vm.sade.sijoittelu.flyway"); | ||
flyway.setTable("sijoittelu_schema_version"); | ||
flyway.migrate(); | ||
|
||
return new FlywayMigrationDone(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters