@@ -0,0 +1,3066 @@
+package flyway.asdi2;%0A%0Aimport fi.nls.oskari.util.PropertyUtil;%0Aimport fi.nls.oskari.domain.map.view.Bundle;%0Aimport fi.nls.oskari.log.LogFactory;%0Aimport fi.nls.oskari.log.Logger;%0Aimport org.flywaydb.core.api.migration.BaseJavaMigration;%0Aimport org.flywaydb.core.api.migration.Context;%0Aimport org.oskari.helpers.AppSetupHelper;%0Aimport org.oskari.helpers.BundleHelper;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.SQLException;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Apublic class V1_23_1__migrate_layer_list extends BaseJavaMigration %7B%0A    private static final Logger LOG = LogFactory.getLogger(V1_23_1__migrate_layer_list.class);%0A    private static final String LAYERSELECTOR_BUNDLE_NAME = %22layerselector2%22;%0A    private static final String LAYERSELECTION_BUNDLE_NAME = %22layerselection2%22;%0A    private static final String LAYERLIST_BUNDLE_NAME = %22layerlist%22;%0A    private static final String LAYER_EDITOR_BUNDLE_NAME = %22admin-layereditor%22;%0A%0A    public void migrate(Context context) throws Exception %7B%0A        if(PropertyUtil.getOptional(%22flyway.asdi.1_23_1.skip%22, true)) %7B%0A            LOG.warn(%22You are skipping layer list migration.%22);%0A            return;%0A        %7D%0A        Connection connection = context.getConnection();%0A        createBundles(connection);%0A        updateDefaultAndUserViews(connection);%0A    %7D%0A%0A    private void createBundles(Connection connection) throws Exception %7B%0A        for (String bundleName : Arrays.asList(LAYER_EDITOR_BUNDLE_NAME, LAYERLIST_BUNDLE_NAME)) %7B%0A            Bundle bundle = new Bundle();%0A            bundle.setName(bundleName);%0A            BundleHelper.registerBundle(connection, bundle);%0A            LOG.info(%22Created %22 + bundleName + %22 bundle%22);%0A        %7D%0A    %7D%0A%0A    private void updateDefaultAndUserViews(Connection connection) throws SQLException %7B%0A        Bundle newBundle = BundleHelper.getRegisteredBundle(connection, LAYERLIST_BUNDLE_NAME);%0A        List%3CLong%3E viewIds = AppSetupHelper.getSetupsForUserAndDefaultType(connection);%0A        for(Long viewId : viewIds) %7B%0A            Bundle bundle = AppSetupHelper.getAppBundle(connection, viewId, LAYERSELECTOR_BUNDLE_NAME);%0A            if (bundle == null) %7B%0A%0A                Bundle migratedBetaBundle = AppSetupHelper.getAppBundle(connection, viewId, LAYERLIST_BUNDLE_NAME);%0A                if (migratedBetaBundle != null) %7B%0A                    // view already migrated at beta stage- %3E just remove the old %22selected layers%22 bundle%0A                    AppSetupHelper.removeBundleFromApp(connection, viewId, LAYERSELECTION_BUNDLE_NAME);%0A                %7D%0A                continue;%0A            %7D%0A            newBundle.setSeqNo(bundle.getSeqNo());%0A            newBundle.setConfig(bundle.getConfig());%0A            AppSetupHelper.removeBundleFromApp(connection, viewId, LAYERSELECTOR_BUNDLE_NAME);%0A            AppSetupHelper.removeBundleFromApp(connection, viewId, LAYERSELECTION_BUNDLE_NAME);%0A            AppSetupHelper.addBundleToApp(connection, viewId, LAYERLIST_BUNDLE_NAME);%0A            AppSetupHelper.updateAppBundle(connection, viewId, newBundle);%0A        %7D%0A    %7D%0A%7D%0A

add flyway migration for layerlist