-
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
10 changed files
with
127 additions
and
43 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.jatkuva.dao.dto.SijoitteluDto; | ||
import fi.vm.sade.sijoittelu.jatkuva.external.resource.viestintapalvelu.RestCasClient; | ||
import fi.vm.sade.sijoittelu.laskenta.util.UrlProperties; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.datasource.SingleConnectionDataSource; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.regex.Pattern; | ||
|
||
public class V20240419000001__LueJatkuvatSijoittelutSeurannasta extends BaseJavaMigration { | ||
|
||
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(Context context) { | ||
JdbcTemplate template = new JdbcTemplate(); | ||
template.setDataSource(new SingleConnectionDataSource(context.getConnection(), 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()); | ||
} | ||
} | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
.../main/java/fi/vm/sade/sijoittelu/jatkuva/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
45 changes: 45 additions & 0 deletions
45
...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,45 @@ | ||
package fi.vm.sade.sijoittelu.laskenta.configuration; | ||
|
||
import fi.vm.sade.sijoittelu.flyway.V20240419000001__LueJatkuvatSijoittelutSeurannasta; | ||
import fi.vm.sade.sijoittelu.jatkuva.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.context.annotation.Profile; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
@Configuration | ||
@Profile({"default", "dev"}) | ||
public class FlywayConfiguration { | ||
|
||
@Autowired | ||
@Qualifier("sijoitteluJdbcTemplate") | ||
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 = Flyway.configure() | ||
.schemas("public") | ||
.dataSource(jdbcTemplate.getDataSource()) | ||
.table("schema_version") | ||
.locations("/db/migration") | ||
.load(); | ||
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
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
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
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
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
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
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