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);
}
}
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);
}
}
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);
}
}
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;
}
}
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);
}
}
Aggregations