@@ -0,0 +1,2681 @@
+package flyway.asdi;%0A%0Aimport fi.nls.oskari.domain.map.view.Bundle;%0Aimport fi.nls.oskari.domain.map.view.View;%0Aimport fi.nls.oskari.log.LogFactory;%0Aimport fi.nls.oskari.log.Logger;%0Aimport fi.nls.oskari.map.view.ViewService;%0Aimport fi.nls.oskari.map.view.ViewServiceIbatisImpl;%0Aimport fi.nls.oskari.util.JSONHelper;%0Aimport fi.nls.oskari.view.modifier.ViewModifier;%0Aimport org.flywaydb.core.api.migration.jdbc.JdbcMigration;%0Aimport org.json.JSONArray;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0Aimport java.sql.Connection;%0Aimport java.util.List;%0A%0A/**%0A * Created by SMAKINEN on 29.6.2015.%0A */%0Apublic class V1_5_1__Add_marker_support implements JdbcMigration %7B%0A%0A    private static final Logger LOG = LogFactory.getLogger(V1_5_1__Add_marker_support.class);%0A%0A    private ViewService service = new ViewServiceIbatisImpl();%0A    private static final int BATCH_SIZE = 50;%0A    private int updatedViewCount = 0;%0A%0A    private static final String PLUGIN_NAME = %22Oskari.mapframework.mapmodule.MarkersPlugin%22;%0A%0A    public void migrate(Connection connection)%0A            throws Exception %7B%0A        int page = 1;%0A        while(updateViews(page)) %7B%0A            page++;%0A        %7D%0A        LOG.info(%22Updated views:%22, updatedViewCount);%0A    %7D%0A    private boolean updateViews(int page)%0A            throws Exception %7B%0A        List%3CView%3E list = service.getViews(page, BATCH_SIZE);%0A        LOG.info(%22Got%22, list.size(), %22views on page%22, page);%0A        for(View view : list) %7B%0A            final Bundle mapfull = view.getBundleByName(ViewModifier.BUNDLE_MAPFULL);%0A            boolean addedPlugin = addPlugin(mapfull);%0A            if(!addedPlugin) %7B%0A                // if neither was done, skip update%0A                continue;%0A            %7D%0A            service.updateBundleSettingsForView(view.getId(), mapfull);%0A            updatedViewCount++;%0A        %7D%0A        return list.size() == BATCH_SIZE;%0A    %7D%0A%0A%0A    private boolean addPlugin(final Bundle mapfull) throws JSONException %7B%0A        final JSONObject config = mapfull.getConfigJSON();%0A        final JSONArray plugins = config.optJSONArray(%22plugins%22);%0A        if(plugins == null) %7B%0A            throw new RuntimeException(%22No plugins%22 + config.toString(2));%0A            //continue;%0A        %7D%0A        boolean found = false;%0A        for(int i = 0; i %3C plugins.length(); ++i) %7B%0A            JSONObject plugin = plugins.getJSONObject(i);%0A            if(PLUGIN_NAME.equals(plugin.optString(%22id%22))) %7B%0A                found = true;%0A                break;%0A            %7D%0A        %7D%0A        // add plugin if not there yet%0A        if(!found) %7B%0A            plugins.put(JSONHelper.createJSONObject(%22id%22, PLUGIN_NAME));%0A        %7D%0A        return true;%0A    %7D%0A%7D%0A

Add MarkersPlugin to views that dont have it