Skip to content

Commit

Permalink
Merge pull request #220 from ZakarFin/update-tk-config
Browse files Browse the repository at this point in the history
Use new dataset for Kuntien avainluvut
  • Loading branch information
ZakarFin authored Nov 7, 2023
2 parents a7a1f21 + b2960c7 commit 09af47d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package flyway.ptistats;

import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import fi.nls.oskari.util.JSONHelper;
import org.json.JSONObject;

/**
* Updates references to indicator ids after 1.44 migration since id also references px-file name that changes yearly
*/
public class V1_59__update_refs_to_saved_indicators_tk extends V1_47__update_refs_to_saved_indicators_tk {
private static final Logger LOG = LogFactory.getLogger(V1_59__update_refs_to_saved_indicators_tk.class);
private static final String ID_SEPARATOR = "::";

// for overriding purposes next year...
// though next year we'll need a new version of getBundleStates() as it's
// SELECT appsetup_id, seqno, state FROM oskari_appsetup_bundles WHERE bundle_id = ? AND state LIKE '%kuntien_avainluvut%'
public String getNewFileName() {
return "142h.px";
}
public String getOldFileName() {
return "kuntien_avainluvut_2021_aikasarja.px";
}

protected boolean updateState(JSONObject state) {
boolean modified = super.updateState(state);
if (modified) {
String activeValue = state.optString("active", "");
if (activeValue.contains(getOldFileName())) {
// FROM: 3_kuntien_avainluvut_2021_aikasarja.px::M411_Vuosi="2021"
// TO: 3_142h.px::M411_Vuosi="2021"
String newActiveValue = activeValue.replace(getOldFileName(), getNewFileName());
JSONHelper.putValue(state, "active", newActiveValue);
}
}
return modified;
}

protected String getNewId(String oldId) {
String[] parts = oldId.split(ID_SEPARATOR);
if (parts.length != 2 || !parts[0].equalsIgnoreCase(getOldFileName())) {
// something weird here
LOG.warn("Unidentified id:", oldId);
return oldId;
}
return getNewFileName() + ID_SEPARATOR + parts[1];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

UPDATE oskari_statistical_datasource
SET locale = '{"fi":{"name":"Tilastokeskus - Kuntien avainluvut 2022 aluejaolla"},"sv":{"name":"Statistikcentralen - Kommunernas nyckeltal enligt områdesindelningen år 2022"},"en":{"name":"Statistics Finland - Municipal key figures with the 2022 regional division"}}',
config='{
"url": "https://statfin.stat.fi/PxWeb/api/v1/{language}/Kuntien_avainluvut/uusin/142h.px",
"info": {
"url": "http://www.tilastokeskus.fi"
},
"metadataFile": "/tilastokeskus_pxweb_metadata.json",
"regionKey": "Alue",
"indicatorKey": "Tiedot",
"hints" : {
"dimensions" : [ {
"id" : "Vuosi",
"sort" : "DESC"
}]
}
}'
WHERE locale LIKE '%Tilastokeskus - Kuntien avainluvut 2021 aluejaolla%';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

UPDATE oskari_statistical_datasource_regionsets SET config = '{
"regionType":"kunta",
"valueProcessor": "fi.nls.oskari.control.statistics.plugins.pxweb.parser.PrefixedRegionsValueProcessor",
"statsRegionPrefix": "KU"
}'
where datasource_id = (select id from oskari_statistical_datasource where locale like '%Tilastokeskus - Kuntien avainluvut 2022 aluejaolla%') AND config = '{"regionType":"kunta"}';

0 comments on commit 09af47d

Please sign in to comment.