Search in sources :

Example 1 with VersionedAccountPreferences

use of com.google.gerrit.server.account.VersionedAccountPreferences in project gerrit by GerritCodeReview.

the class GetPreferences method readFromGit.

static GeneralPreferencesInfo readFromGit(GitRepositoryManager gitMgr, GeneralPreferencesLoader loader, AllUsersName allUsersName, GeneralPreferencesInfo in) throws IOException, ConfigInvalidException, RepositoryNotFoundException {
    try (Repository git = gitMgr.openRepository(allUsersName)) {
        VersionedAccountPreferences p = VersionedAccountPreferences.forDefault();
        p.load(git);
        GeneralPreferencesInfo r = loadSection(p.getConfig(), UserConfigSections.GENERAL, null, new GeneralPreferencesInfo(), GeneralPreferencesInfo.defaults(), in);
        // TODO(davido): Maintain cache of default values in AllUsers repository
        return loader.loadMyMenusAndUrlAliases(r, p, null);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences)

Example 2 with VersionedAccountPreferences

use of com.google.gerrit.server.account.VersionedAccountPreferences in project gerrit by GerritCodeReview.

the class Schema_119 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    JdbcSchema schema = (JdbcSchema) db;
    Connection connection = schema.getConnection();
    String tableName = "accounts";
    String emailStrategy = "email_strategy";
    Set<String> columns = schema.getDialect().listColumns(connection, tableName);
    Map<Account.Id, GeneralPreferencesInfo> imports = new HashMap<>();
    try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
        ResultSet rs = stmt.executeQuery("select " + "account_id, " + "maximum_page_size, " + "show_site_header, " + "use_flash_clipboard, " + "download_url, " + "download_command, " + (columns.contains(emailStrategy) ? emailStrategy + ", " : "copy_self_on_email, ") + "date_format, " + "time_format, " + "relative_date_in_change_table, " + "diff_view, " + "size_bar_in_change_table, " + "legacycid_in_change_table, " + "review_category_strategy, " + "mute_common_path_prefixes " + "from " + tableName)) {
        while (rs.next()) {
            GeneralPreferencesInfo p = new GeneralPreferencesInfo();
            Account.Id accountId = new Account.Id(rs.getInt(1));
            p.changesPerPage = (int) rs.getShort(2);
            p.showSiteHeader = toBoolean(rs.getString(3));
            p.useFlashClipboard = toBoolean(rs.getString(4));
            p.downloadScheme = convertToModernNames(rs.getString(5));
            p.downloadCommand = toDownloadCommand(rs.getString(6));
            p.emailStrategy = toEmailStrategy(rs.getString(7), columns.contains(emailStrategy));
            p.dateFormat = toDateFormat(rs.getString(8));
            p.timeFormat = toTimeFormat(rs.getString(9));
            p.relativeDateInChangeTable = toBoolean(rs.getString(10));
            p.diffView = toDiffView(rs.getString(11));
            p.sizeBarInChangeTable = toBoolean(rs.getString(12));
            p.legacycidInChangeTable = toBoolean(rs.getString(13));
            p.reviewCategoryStrategy = toReviewCategoryStrategy(rs.getString(14));
            p.muteCommonPathPrefixes = toBoolean(rs.getString(15));
            p.defaultBaseForMerges = GeneralPreferencesInfo.defaults().defaultBaseForMerges;
            imports.put(accountId, p);
        }
    }
    if (imports.isEmpty()) {
        return;
    }
    try (Repository git = mgr.openRepository(allUsersName);
        RevWalk rw = new RevWalk(git)) {
        BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
        for (Map.Entry<Account.Id, GeneralPreferencesInfo> e : imports.entrySet()) {
            try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git, bru)) {
                md.getCommitBuilder().setAuthor(serverUser);
                md.getCommitBuilder().setCommitter(serverUser);
                VersionedAccountPreferences p = VersionedAccountPreferences.forUser(e.getKey());
                p.load(md);
                storeSection(p.getConfig(), UserConfigSections.GENERAL, null, e.getValue(), GeneralPreferencesInfo.defaults());
                p.commit(md);
            }
        }
        bru.execute(rw, NullProgressMonitor.INSTANCE);
    } catch (ConfigInvalidException | IOException ex) {
        throw new OrmException(ex);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) HashMap(java.util.HashMap) Statement(java.sql.Statement) Connection(java.sql.Connection) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) ResultSet(java.sql.ResultSet) GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 3 with VersionedAccountPreferences

use of com.google.gerrit.server.account.VersionedAccountPreferences in project gerrit by GerritCodeReview.

the class Schema_115 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    Map<Account.Id, DiffPreferencesInfo> imports = new HashMap<>();
    try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM account_diff_preferences")) {
        Set<String> availableColumns = getColumns(rs);
        while (rs.next()) {
            Account.Id accountId = new Account.Id(rs.getInt("id"));
            DiffPreferencesInfo prefs = new DiffPreferencesInfo();
            if (availableColumns.contains("context")) {
                prefs.context = (int) rs.getShort("context");
            }
            if (availableColumns.contains("expand_all_comments")) {
                prefs.expandAllComments = toBoolean(rs.getString("expand_all_comments"));
            }
            if (availableColumns.contains("hide_line_numbers")) {
                prefs.hideLineNumbers = toBoolean(rs.getString("hide_line_numbers"));
            }
            if (availableColumns.contains("hide_top_menu")) {
                prefs.hideTopMenu = toBoolean(rs.getString("hide_top_menu"));
            }
            if (availableColumns.contains("ignore_whitespace")) {
                // Enum with char as value
                prefs.ignoreWhitespace = toWhitespace(rs.getString("ignore_whitespace"));
            }
            if (availableColumns.contains("intraline_difference")) {
                prefs.intralineDifference = toBoolean(rs.getString("intraline_difference"));
            }
            if (availableColumns.contains("line_length")) {
                prefs.lineLength = rs.getInt("line_length");
            }
            if (availableColumns.contains("manual_review")) {
                prefs.manualReview = toBoolean(rs.getString("manual_review"));
            }
            if (availableColumns.contains("render_entire_file")) {
                prefs.renderEntireFile = toBoolean(rs.getString("render_entire_file"));
            }
            if (availableColumns.contains("retain_header")) {
                prefs.retainHeader = toBoolean(rs.getString("retain_header"));
            }
            if (availableColumns.contains("show_line_endings")) {
                prefs.showLineEndings = toBoolean(rs.getString("show_line_endings"));
            }
            if (availableColumns.contains("show_tabs")) {
                prefs.showTabs = toBoolean(rs.getString("show_tabs"));
            }
            if (availableColumns.contains("show_whitespace_errors")) {
                prefs.showWhitespaceErrors = toBoolean(rs.getString("show_whitespace_errors"));
            }
            if (availableColumns.contains("skip_deleted")) {
                prefs.skipDeleted = toBoolean(rs.getString("skip_deleted"));
            }
            if (availableColumns.contains("skip_uncommented")) {
                prefs.skipUncommented = toBoolean(rs.getString("skip_uncommented"));
            }
            if (availableColumns.contains("syntax_highlighting")) {
                prefs.syntaxHighlighting = toBoolean(rs.getString("syntax_highlighting"));
            }
            if (availableColumns.contains("tab_size")) {
                prefs.tabSize = rs.getInt("tab_size");
            }
            if (availableColumns.contains("theme")) {
                // Enum with name as values; can be null
                prefs.theme = toTheme(rs.getString("theme"));
            }
            if (availableColumns.contains("hide_empty_pane")) {
                prefs.hideEmptyPane = toBoolean(rs.getString("hide_empty_pane"));
            }
            if (availableColumns.contains("auto_hide_diff_table_header")) {
                prefs.autoHideDiffTableHeader = toBoolean(rs.getString("auto_hide_diff_table_header"));
            }
            imports.put(accountId, prefs);
        }
    }
    if (imports.isEmpty()) {
        return;
    }
    try (Repository git = mgr.openRepository(allUsersName);
        RevWalk rw = new RevWalk(git)) {
        BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
        for (Map.Entry<Account.Id, DiffPreferencesInfo> e : imports.entrySet()) {
            try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git, bru)) {
                md.getCommitBuilder().setAuthor(serverUser);
                md.getCommitBuilder().setCommitter(serverUser);
                VersionedAccountPreferences p = VersionedAccountPreferences.forUser(e.getKey());
                p.load(md);
                storeSection(p.getConfig(), UserConfigSections.DIFF, null, e.getValue(), DiffPreferencesInfo.defaults());
                p.commit(md);
            }
        }
        bru.execute(rw, NullProgressMonitor.INSTANCE);
    } catch (ConfigInvalidException | IOException ex) {
        throw new OrmException(ex);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) HashMap(java.util.HashMap) Statement(java.sql.Statement) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) ResultSet(java.sql.ResultSet) VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) HashMap(java.util.HashMap) Map(java.util.Map) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 4 with VersionedAccountPreferences

use of com.google.gerrit.server.account.VersionedAccountPreferences in project gerrit by GerritCodeReview.

the class GetDiffPreferences method readFromGit.

static DiffPreferencesInfo readFromGit(GitRepositoryManager gitMgr, AllUsersName allUsersName, DiffPreferencesInfo in) throws IOException, ConfigInvalidException, RepositoryNotFoundException {
    try (Repository git = gitMgr.openRepository(allUsersName)) {
        // Load all users prefs.
        VersionedAccountPreferences dp = VersionedAccountPreferences.forDefault();
        dp.load(git);
        DiffPreferencesInfo allUserPrefs = new DiffPreferencesInfo();
        loadSection(dp.getConfig(), UserConfigSections.DIFF, null, allUserPrefs, DiffPreferencesInfo.defaults(), in);
        return allUserPrefs;
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo)

Example 5 with VersionedAccountPreferences

use of com.google.gerrit.server.account.VersionedAccountPreferences in project gerrit by GerritCodeReview.

the class SetPreferences method writeToGit.

private GeneralPreferencesInfo writeToGit(GeneralPreferencesInfo i) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
    try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
        VersionedAccountPreferences p = VersionedAccountPreferences.forDefault();
        p.load(md);
        storeSection(p.getConfig(), UserConfigSections.GENERAL, null, i, GeneralPreferencesInfo.defaults());
        com.google.gerrit.server.account.SetPreferences.storeMyMenus(p, i.my);
        com.google.gerrit.server.account.SetPreferences.storeUrlAliases(p, i.urlAliases);
        p.commit(md);
        accountCache.evictAll();
        GeneralPreferencesInfo r = loadSection(p.getConfig(), UserConfigSections.GENERAL, null, new GeneralPreferencesInfo(), GeneralPreferencesInfo.defaults(), null);
        return loader.loadMyMenusAndUrlAliases(r, p, null);
    }
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) VersionedAccountPreferences(com.google.gerrit.server.account.VersionedAccountPreferences) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

VersionedAccountPreferences (com.google.gerrit.server.account.VersionedAccountPreferences)6 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)4 Repository (org.eclipse.jgit.lib.Repository)4 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)3 GeneralPreferencesInfo (com.google.gerrit.extensions.client.GeneralPreferencesInfo)3 Account (com.google.gerrit.reviewdb.client.Account)2 OrmException (com.google.gwtorm.server.OrmException)2 IOException (java.io.IOException)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 JdbcSchema (com.google.gwtorm.jdbc.JdbcSchema)1 Connection (java.sql.Connection)1