@@ -0,0 +1,2658 @@
+package flyway.oskari;%0A%0Aimport fi.nls.oskari.log.LogFactory;%0Aimport fi.nls.oskari.log.Logger;%0Aimport fi.nls.oskari.util.JSONHelper;%0Aimport org.flywaydb.core.api.migration.BaseJavaMigration;%0Aimport org.flywaydb.core.api.migration.Context;%0Aimport org.json.JSONObject;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class V2_3_1__migrate_wps_params extends BaseJavaMigration %7B%0A    private static final Logger LOG = LogFactory.getLogger(V2_3_1__migrate_wps_params.class);%0A    public static final String WPS_PARAMS = %22wpsParams%22;%0A%0A    @Override%0A    public void migrate(Context context) throws Exception %7B%0A        Connection conn = context.getConnection();%0A        getLayerAttributes(conn).forEach((id, attr) -%3E migrateWpsParams(conn, id, attr));%0A    %7D%0A    private void migrateWpsParams (Connection conn, int id, JSONObject attr) %7B%0A        String wpsString = attr.optString(WPS_PARAMS);%0A        if (wpsString.isEmpty()) %7B%0A            //skip%0A            return;%0A        %7D%0A        try %7B%0A            JSONObject wpsParams = new JSONObject(wpsString);%0A            JSONHelper.putValue(attr, WPS_PARAMS, wpsParams);%0A            updateAttributes(conn, id, attr);%0A        %7D catch (Exception ignored) %7B%0A            LOG.warn(%22Failed to migrate WPS params String:%22, wpsString, %22to JSONObject for layer:%22, id);%0A        %7D%0A    %7D%0A    private void updateAttributes (Connection conn, int layerId, JSONObject attributes) throws SQLException %7B%0A        final String sql = %22UPDATE oskari_maplayer SET attributes=? where id=?%22;%0A        try(PreparedStatement statement = conn.prepareStatement(sql)) %7B%0A            statement.setString(1, attributes.toString());%0A            statement.setInt(2, layerId);%0A            statement.execute();%0A        %7D%0A    %7D%0A    private Map%3CInteger, JSONObject%3E getLayerAttributes(Connection conn) throws SQLException %7B%0A        Map%3CInteger, JSONObject%3E attributes = new HashMap%3C%3E();%0A        // only WFS layers have WPS params%0A        final String sql = %22SELECT id, attributes FROM oskari_maplayer where type = 'wfslayer'%22;%0A        try(PreparedStatement statement = conn.prepareStatement(sql)) %7B%0A            try (ResultSet rs = statement.executeQuery()) %7B%0A                while(rs.next()) %7B%0A                    int id = rs.getInt(%22id%22);%0A                    JSONObject attr = JSONHelper.createJSONObject(rs.getString(%22attributes%22));%0A                    attributes.put(id, attr);%0A                %7D%0A            %7D%0A        %7D%0A        LOG.info(%22Found%22, attributes.size(), %22WFS layers for WPS migration%22);%0A        return attributes;%0A    %7D%0A%7D%0A

add wps params string to jsonobject flyway migration