@@ -0,0 +1,2361 @@
+package flyway.ptistats;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.SQLException;%0A%0Aimport org.flywaydb.core.api.migration.jdbc.JdbcMigration;%0Aimport org.json.JSONObject;%0A%0Aimport fi.nls.oskari.domain.map.OskariLayer;%0Aimport fi.nls.oskari.util.JSONHelper;%0A%0Apublic class V1_9__use_resources_for_thematic_map_layers implements JdbcMigration %7B%0A%0A    private static final String RESOURCES_URL_PREFIX = %22resources://%22;%0A    private static final String DIR = %22stats-regionsets/%22;%0A%0A    private enum ResourceStatLayer %7B%0A%0A        NUTS1(%22dummy:nuts1%22, %22nuts1_2017.json%22, %22koodi_2%22, %22nimi%22),%0A        ERVA(%22dummy:erva%22, %22erva_2017.json%22, %22ERVAnro%22, %22ERVA%22),%0A        SHP(%22dummy:sairaanhoitopiiri%22, %22sairaanhoitopiirit_2017.json%22, %22Sairaanhoi%22, %22nimi%22);%0A%0A        final String layerName;%0A        final String resourcePath;%0A        final String regionIdTag;%0A        final String nameIdTag;%0A%0A        private ResourceStatLayer(String layerName, String resourcePath, String regionIdTag, String nameIdTag) %7B%0A            this.layerName = layerName;%0A            this.resourcePath = resourcePath;%0A            this.regionIdTag = regionIdTag;%0A            this.nameIdTag = nameIdTag;%0A        %7D%0A%0A        private JSONObject getAttributes() %7B%0A            JSONObject statistics = new JSONObject();%0A            JSONHelper.putValue(statistics, %22featuresUrl%22, getFeaturesUrl());%0A            JSONHelper.putValue(statistics, %22regionIdTag%22, regionIdTag);%0A            JSONHelper.putValue(statistics, %22nameIdTag%22, nameIdTag);%0A            return JSONHelper.createJSONObject(%22statistics%22, statistics);%0A        %7D%0A%0A        private String getFeaturesUrl() %7B%0A            return RESOURCES_URL_PREFIX + DIR + resourcePath;%0A        %7D%0A%0A    %7D%0A%0A    public void migrate(Connection connection) throws SQLException %7B%0A        String sql = %22UPDATE oskari_maplayer %22%0A                + %22SET attributes = ? %22%0A                + %22WHERE type = ? AND name = ?%22;%0A        try (PreparedStatement ps = connection.prepareStatement(sql)) %7B%0A            ps.setString(2, OskariLayer.TYPE_STATS);%0A            for (ResourceStatLayer layer : ResourceStatLayer.values()) %7B%0A                String attributes = layer.getAttributes().toString();%0A                ps.setString(1, attributes);%0A                ps.setString(3, layer.layerName);%0A            %7D%0A            ps.executeUpdate();%0A        %7D%0A    %7D%0A%0A%7D%0A

Add migration