Search in sources :

Example 11 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo 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 12 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo 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 13 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class GeneralPreferencesIT method getPreferencesWithConfiguredDefaults.

@Test
public void getPreferencesWithConfiguredDefaults() throws Exception {
    GeneralPreferencesInfo d = GeneralPreferencesInfo.defaults();
    int newChangesPerPage = d.changesPerPage * 2;
    GeneralPreferencesInfo update = new GeneralPreferencesInfo();
    update.changesPerPage = newChangesPerPage;
    gApi.config().server().setDefaultPreferences(update);
    GeneralPreferencesInfo o = gApi.accounts().id(user42.getId().toString()).getPreferences();
    // assert configured defaults
    assertThat(o.changesPerPage).isEqualTo(newChangesPerPage);
    // assert hard-coded defaults
    assertPrefs(o, d, "my", "changeTable", "changesPerPage");
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 14 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class GeneralPreferencesIT method setGeneralPreferences.

@Test
public void setGeneralPreferences() throws Exception {
    boolean newSignedOffBy = !GeneralPreferencesInfo.defaults().signedOffBy;
    GeneralPreferencesInfo update = new GeneralPreferencesInfo();
    update.signedOffBy = newSignedOffBy;
    GeneralPreferencesInfo result = gApi.config().server().setDefaultPreferences(update);
    assertThat(result.signedOffBy).named("signedOffBy").isEqualTo(newSignedOffBy);
    result = gApi.config().server().getDefaultPreferences();
    GeneralPreferencesInfo expected = GeneralPreferencesInfo.defaults();
    expected.signedOffBy = newSignedOffBy;
    assertPrefs(result, expected, "my");
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class AbstractPushForReview method tearDown.

@After
public void tearDown() throws Exception {
    setApiUser(admin);
    GeneralPreferencesInfo prefs = gApi.accounts().id(admin.id.get()).getPreferences();
    prefs.publishCommentsOnPush = false;
    gApi.accounts().id(admin.id.get()).setPreferences(prefs);
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) After(org.junit.After)

Aggregations

GeneralPreferencesInfo (com.google.gerrit.extensions.client.GeneralPreferencesInfo)19 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)8 Test (org.junit.Test)8 Repository (org.eclipse.jgit.lib.Repository)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 Account (com.google.gerrit.reviewdb.client.Account)3 VersionedAccountPreferences (com.google.gerrit.server.account.VersionedAccountPreferences)3 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)2 HashMap (java.util.HashMap)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 RestResponse (com.google.gerrit.acceptance.RestResponse)1 Capable (com.google.gerrit.common.data.Capable)1 MenuItem (com.google.gerrit.extensions.client.MenuItem)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)1 Change (com.google.gerrit.reviewdb.client.Change)1