Skip to content

Commit

Permalink
OPHYK-318 Export all data required by datantuonti process
Browse files Browse the repository at this point in the history
  • Loading branch information
tsu committed Dec 30, 2024
1 parent c3e6803 commit e4f1448
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,35 @@ public class ExportService {
private JdbcTemplate jdbcTemplate;
private final String CREATE_ORGANISAATIO_SQL = """
CREATE TABLE datantuonti_export_new.organisaatio AS
SELECT o.oid as organisaatio_oid
SELECT
o.oid,
(SELECT parent_oid
FROM organisaatio_parent_oids
WHERE organisaatio_id = o.id
AND parent_position = 0) AS parent_oid,
o.oppilaitostyyppi,
o.ytunnus,
o.piilotettu,
(SELECT v.value
FROM monikielinenteksti_values v
WHERE v.id = o.nimi_mkt
AND v.key = 'fi') as nimi_fi,
(SELECT v.value
FROM monikielinenteksti_values v
WHERE v.id = o.nimi_mkt
AND v.key = 'sv') as nimi_sv,
(SELECT v.value
FROM monikielinenteksti_values v
WHERE v.id = o.nimi_mkt
AND v.key = 'en') as nimi_en,
o.alkupvm,
o.lakkautuspvm,
o.yritysmuoto,
o.kotipaikka,
o.maa,
(SELECT string_agg(kielet, ',')
FROM organisaatio_kielet
WHERE organisaatio_id = o.id) as kielet
FROM organisaatio o
WHERE NOT EXISTS(
SELECT 1
Expand All @@ -26,12 +54,34 @@ WHERE NOT EXISTS(
)
);
""";
private final String CREATE_EXPORT_OSOITE_SQL = """
CREATE TABLE datantuonti_export_new.osoite AS
SELECT o.oid,
y.osoitetyyppi,
y.osoite,
y.postinumero,
y.postitoimipaikka,
y.kieli
FROM yhteystieto y
JOIN organisaatio o ON o.id = y.organisaatio_id
WHERE y.osoitetyyppi in ('posti', 'kaynti')
AND NOT EXISTS(
SELECT 1
FROM organisaatio_tyypit
WHERE organisaatio_id = o.id
AND (
tyypit = 'organisaatiotyyppi_08'
OR tyypit = 'organisaatiotyyppi_07'
)
)
""";

@Transactional
public void createSchema() {
jdbcTemplate.execute("DROP SCHEMA IF EXISTS datantuonti_export_new CASCADE");
jdbcTemplate.execute("CREATE SCHEMA datantuonti_export_new");
jdbcTemplate.execute(CREATE_ORGANISAATIO_SQL);
jdbcTemplate.execute(CREATE_EXPORT_OSOITE_SQL);
jdbcTemplate.execute("DROP SCHEMA IF EXISTS datantuonti_export CASCADE");
jdbcTemplate.execute("ALTER SCHEMA datantuonti_export_new RENAME TO datantuonti_export");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void doesNotExportVarhaiskasvastusOrganisaatiot() {
}

private List<String> getExportedOrganisaatioCount() {
return jdbcTemplate.queryForList("SELECT organisaatio_oid FROM datantuonti_export.organisaatio", String.class);
return jdbcTemplate.queryForList("SELECT oid FROM datantuonti_export.organisaatio", String.class);
}

private List<String> getVarhaiskasvatusOrganisaatioOids() {
Expand Down

0 comments on commit e4f1448

Please sign in to comment.