-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from ZakarFin/update-tk-config
Use new dataset for Kuntien avainluvut
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app-resources/src/main/java/flyway/ptistats/V1_59__update_refs_to_saved_indicators_tk.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,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]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app-resources/src/main/resources/flyway/ptistats/V1_57__update_tk_config.sql
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,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%'; |
7 changes: 7 additions & 0 deletions
7
app-resources/src/main/resources/flyway/ptistats/V1_58__add_region_id_prefix_config.sql
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,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"}'; |