@@ -0,0 +1,2745 @@
+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.JSONException;%0Aimport org.json.JSONObject;%0A%0Aimport java.sql.Connection;%0Aimport java.util.List;%0A%0A%0A/**%0A * Adds %22ui-components%22 bundle to mapfull imports.%0A * Fixes an issue of missing PopupService in non-minified envs.%0A */%0Apublic class V1_9_0__add_ui_components_for_views implements JdbcMigration %7B%0A    private static final String BUNDLE_ID = %22ui-components%22;%0A%0A    private static final Logger LOG = LogFactory.getLogger(V1_9_0__add_ui_components_for_views.class);%0A%0A    private ViewService service;%0A    private static final int BATCH_SIZE = 50;%0A    private int updatedViewCount = 0;%0A%0A    public void migrate(Connection connection)%0A            throws Exception %7B%0A        service = new ViewServiceIbatisImpl();%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 addedImport = addImport(mapfull, BUNDLE_ID, %22/Oskari/packages/framework/bundle/%22);%0A            if(!addedImport) %7B%0A                // if not modified, 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 addImport(final Bundle mapfull, String name, String path) throws JSONException %7B%0A        final JSONObject startup = new JSONObject(mapfull.getStartup());%0A        final JSONObject metadata = startup.optJSONObject(%22metadata%22);%0A        if(metadata == null) %7B%0A            return false;%0A        %7D%0A        final JSONObject imports = metadata.optJSONObject(%22Import-Bundle%22);%0A        if(imports == null) %7B%0A            return false;%0A        %7D%0A        JSONObject bundle = imports.optJSONObject(name);%0A        if(bundle != null) %7B%0A            return false;%0A        %7D%0A        bundle = JSONHelper.createJSONObject(%22bundlePath%22, path);%0A        imports.put(name, bundle);%0A        mapfull.setStartup(startup.toString(2));%0A        return true;%0A    %7D%0A%7D%0A

Fix for appsetup with missing import on non-minified envs