Search in sources :

Example 1 with ReviewerStateInternal

use of com.google.gerrit.server.notedb.ReviewerStateInternal in project gerrit by GerritCodeReview.

the class ReviewerSet method fromApprovals.

public static ReviewerSet fromApprovals(Iterable<PatchSetApproval> approvals) {
    PatchSetApproval first = null;
    Table<ReviewerStateInternal, Account.Id, Timestamp> reviewers = HashBasedTable.create();
    for (PatchSetApproval psa : approvals) {
        if (first == null) {
            first = psa;
        } else {
            checkArgument(first.getKey().getParentKey().getParentKey().equals(psa.getKey().getParentKey().getParentKey()), "multiple change IDs: %s, %s", first.getKey(), psa.getKey());
        }
        Account.Id id = psa.getAccountId();
        reviewers.put(REVIEWER, id, psa.getGranted());
        if (psa.getValue() != 0) {
            reviewers.remove(CC, id);
        }
    }
    return new ReviewerSet(reviewers);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp)

Example 2 with ReviewerStateInternal

use of com.google.gerrit.server.notedb.ReviewerStateInternal in project gerrit by GerritCodeReview.

the class ChangeField method getReviewerByEmailFieldValues.

@VisibleForTesting
static List<String> getReviewerByEmailFieldValues(ReviewerByEmailSet reviewersByEmail) {
    List<String> r = new ArrayList<>(reviewersByEmail.asTable().size() * 2);
    for (Table.Cell<ReviewerStateInternal, Address, Timestamp> c : reviewersByEmail.asTable().cellSet()) {
        String v = getReviewerByEmailFieldValue(c.getRowKey(), c.getColumnKey());
        r.add(v);
        if (c.getColumnKey().getName() != null) {
            // Add another entry without the name to provide search functionality on the email
            Address emailOnly = new Address(c.getColumnKey().getEmail());
            r.add(getReviewerByEmailFieldValue(c.getRowKey(), emailOnly));
        }
        r.add(v + ',' + c.getValue().getTime());
    }
    return r;
}
Also used : ImmutableTable(com.google.common.collect.ImmutableTable) Table(com.google.common.collect.Table) Address(com.google.gerrit.server.mail.Address) ArrayList(java.util.ArrayList) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) Timestamp(java.sql.Timestamp) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ReviewerStateInternal

use of com.google.gerrit.server.notedb.ReviewerStateInternal in project gerrit by GerritCodeReview.

the class ChangeRebuilderImpl method buildUpdates.

@Override
public void buildUpdates(NoteDbUpdateManager manager, ChangeBundle bundle) throws IOException, OrmException {
    manager.setCheckExpectedState(false).setRefLogMessage("Rebuilding change");
    Change change = new Change(bundle.getChange());
    if (bundle.getPatchSets().isEmpty()) {
        throw new NoPatchSetsException(change.getId());
    }
    // We will rebuild all events, except for draft comments, in buckets based
    // on author and timestamp.
    List<Event> events = new ArrayList<>();
    ListMultimap<Account.Id, DraftCommentEvent> draftCommentEvents = MultimapBuilder.hashKeys().arrayListValues().build();
    events.addAll(getHashtagsEvents(change, manager));
    // Delete ref only after hashtags have been read
    deleteChangeMetaRef(change, manager.getChangeRepo().cmds);
    deleteDraftRefs(change, manager.getAllUsersRepo());
    Integer minPsNum = getMinPatchSetNum(bundle);
    TreeMap<PatchSet.Id, PatchSetEvent> patchSetEvents = new TreeMap<>(ReviewDbUtil.intKeyOrdering());
    for (PatchSet ps : bundle.getPatchSets()) {
        PatchSetEvent pse = new PatchSetEvent(change, ps, manager.getChangeRepo().rw);
        patchSetEvents.put(ps.getId(), pse);
        events.add(pse);
        for (Comment c : getComments(bundle, serverId, Status.PUBLISHED, ps)) {
            CommentEvent e = new CommentEvent(c, change, ps, patchListCache);
            events.add(e.addDep(pse));
        }
        for (Comment c : getComments(bundle, serverId, Status.DRAFT, ps)) {
            DraftCommentEvent e = new DraftCommentEvent(c, change, ps, patchListCache);
            draftCommentEvents.put(c.author.getId(), e);
        }
    }
    ensurePatchSetOrder(patchSetEvents);
    for (PatchSetApproval psa : bundle.getPatchSetApprovals()) {
        PatchSetEvent pse = patchSetEvents.get(psa.getPatchSetId());
        if (pse != null) {
            events.add(new ApprovalEvent(psa, change.getCreatedOn()).addDep(pse));
        }
    }
    for (Table.Cell<ReviewerStateInternal, Account.Id, Timestamp> r : bundle.getReviewers().asTable().cellSet()) {
        events.add(new ReviewerEvent(r, change.getCreatedOn()));
    }
    Change noteDbChange = new Change(null, null, null, null, null);
    for (ChangeMessage msg : bundle.getChangeMessages()) {
        Event msgEvent = new ChangeMessageEvent(change, noteDbChange, msg, change.getCreatedOn());
        if (msg.getPatchSetId() != null) {
            PatchSetEvent pse = patchSetEvents.get(msg.getPatchSetId());
            if (pse == null) {
                // Ignore events for missing patch sets.
                continue;
            }
            msgEvent.addDep(pse);
        }
        events.add(msgEvent);
    }
    sortAndFillEvents(change, noteDbChange, bundle.getPatchSets(), events, minPsNum);
    EventList<Event> el = new EventList<>();
    for (Event e : events) {
        if (!el.canAdd(e)) {
            flushEventsToUpdate(manager, el, change);
            checkState(el.canAdd(e));
        }
        el.add(e);
    }
    flushEventsToUpdate(manager, el, change);
    EventList<DraftCommentEvent> plcel = new EventList<>();
    for (Account.Id author : draftCommentEvents.keys()) {
        for (DraftCommentEvent e : Ordering.natural().sortedCopy(draftCommentEvents.get(author))) {
            if (!plcel.canAdd(e)) {
                flushEventsToDraftUpdate(manager, plcel, change);
                checkState(plcel.canAdd(e));
            }
            plcel.add(e);
        }
        flushEventsToDraftUpdate(manager, plcel, change);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ArrayList(java.util.ArrayList) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp) PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Comment(com.google.gerrit.reviewdb.client.Comment) Table(com.google.common.collect.Table) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) TreeMap(java.util.TreeMap) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) GerritServerId(com.google.gerrit.server.config.GerritServerId) ObjectId(org.eclipse.jgit.lib.ObjectId)

Example 4 with ReviewerStateInternal

use of com.google.gerrit.server.notedb.ReviewerStateInternal in project gerrit by GerritCodeReview.

the class ChangeFieldTest method reviewerFieldValues.

@Test
public void reviewerFieldValues() {
    Table<ReviewerStateInternal, Account.Id, Timestamp> t = HashBasedTable.create();
    Timestamp t1 = TimeUtil.nowTs();
    t.put(ReviewerStateInternal.REVIEWER, new Account.Id(1), t1);
    Timestamp t2 = TimeUtil.nowTs();
    t.put(ReviewerStateInternal.CC, new Account.Id(2), t2);
    ReviewerSet reviewers = ReviewerSet.fromTable(t);
    List<String> values = ChangeField.getReviewerFieldValues(reviewers);
    assertThat(values).containsExactly("REVIEWER,1", "REVIEWER,1," + t1.getTime(), "CC,2", "CC,2," + t2.getTime());
    assertThat(ChangeField.parseReviewerFieldValues(values)).isEqualTo(reviewers);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ReviewerSet(com.google.gerrit.server.ReviewerSet) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 5 with ReviewerStateInternal

use of com.google.gerrit.server.notedb.ReviewerStateInternal in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method reviewerByState.

public Predicate<ChangeData> reviewerByState(String who, ReviewerStateInternal state, boolean forDefaultField) throws QueryParseException, OrmException {
    Predicate<ChangeData> reviewerByEmailPredicate = null;
    if (args.index.getSchema().hasField(ChangeField.REVIEWER_BY_EMAIL)) {
        Address address = Address.tryParse(who);
        if (address != null) {
            reviewerByEmailPredicate = ReviewerByEmailPredicate.forState(args, address, state);
        }
    }
    Predicate<ChangeData> reviewerPredicate = null;
    try {
        Set<Account.Id> accounts = parseAccount(who);
        if (!forDefaultField || accounts.size() <= MAX_ACCOUNTS_PER_DEFAULT_FIELD) {
            reviewerPredicate = Predicate.or(accounts.stream().map(id -> ReviewerPredicate.forState(args, id, state)).collect(toList()));
        }
    } catch (QueryParseException e) {
        // Propagate this exception only if we can't use 'who' to query by email
        if (reviewerByEmailPredicate == null) {
            throw e;
        }
    }
    if (reviewerPredicate != null && reviewerByEmailPredicate != null) {
        return Predicate.or(reviewerPredicate, reviewerByEmailPredicate);
    } else if (reviewerPredicate != null) {
        return reviewerPredicate;
    } else if (reviewerByEmailPredicate != null) {
        return reviewerByEmailPredicate;
    } else {
        return Predicate.any();
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) GroupBackend(com.google.gerrit.server.account.GroupBackend) ChangeControl(com.google.gerrit.server.project.ChangeControl) OrmException(com.google.gwtorm.server.OrmException) ProjectCache(com.google.gerrit.server.project.ProjectCache) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Inject(com.google.inject.Inject) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) Config(org.eclipse.jgit.lib.Config) ChangeTriplet(com.google.gerrit.server.change.ChangeTriplet) CapabilityControl(com.google.gerrit.server.account.CapabilityControl) VersionedAccountQueries(com.google.gerrit.server.account.VersionedAccountQueries) Map(java.util.Map) CHANGE_ID_PATTERN(com.google.gerrit.reviewdb.client.Change.CHANGE_ID_PATTERN) ProvisionException(com.google.inject.ProvisionException) SubmitDryRun(com.google.gerrit.server.git.strategy.SubmitDryRun) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Schema(com.google.gerrit.server.index.Schema) Collection(java.util.Collection) ListChildProjects(com.google.gerrit.server.project.ListChildProjects) Set(java.util.Set) Collectors(java.util.stream.Collectors) Predicate(com.google.gerrit.server.query.Predicate) Objects(java.util.Objects) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) List(java.util.List) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) RefNames(com.google.gerrit.reviewdb.client.RefNames) ChangeData.asChanges(com.google.gerrit.server.query.change.ChangeData.asChanges) Optional(java.util.Optional) Providers(com.google.inject.util.Providers) Pattern(java.util.regex.Pattern) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) GroupReference(com.google.gerrit.common.data.GroupReference) Branch(com.google.gerrit.reviewdb.client.Branch) ChangeIndexRewriter(com.google.gerrit.server.index.change.ChangeIndexRewriter) AccountCache(com.google.gerrit.server.account.AccountCache) Iterables(com.google.common.collect.Iterables) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Change(com.google.gerrit.reviewdb.client.Change) GroupBackends(com.google.gerrit.server.account.GroupBackends) CommentsUtil(com.google.gerrit.server.CommentsUtil) Function(java.util.function.Function) Enums(com.google.common.base.Enums) SubmitRecord(com.google.gerrit.common.data.SubmitRecord) HashSet(java.util.HashSet) NotSignedInException(com.google.gerrit.common.errors.NotSignedInException) IndexConfig(com.google.gerrit.server.index.IndexConfig) Lists(com.google.common.collect.Lists) Account(com.google.gerrit.reviewdb.client.Account) SchemaUtil(com.google.gerrit.server.index.SchemaUtil) CurrentUser(com.google.gerrit.server.CurrentUser) AccountResolver(com.google.gerrit.server.account.AccountResolver) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) PatchListCache(com.google.gerrit.server.patch.PatchListCache) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) VersionedAccountDestinations(com.google.gerrit.server.account.VersionedAccountDestinations) Ints(com.google.common.primitives.Ints) ChangeField(com.google.gerrit.server.index.change.ChangeField) QueryParseException(com.google.gerrit.server.query.QueryParseException) Collectors.toList(java.util.stream.Collectors.toList) Address(com.google.gerrit.server.mail.Address) LimitPredicate(com.google.gerrit.server.query.LimitPredicate) Provider(com.google.inject.Provider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ListMembers(com.google.gerrit.server.group.ListMembers) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) TrackingFooters(com.google.gerrit.server.config.TrackingFooters) FieldDef(com.google.gerrit.server.index.FieldDef) ChangeIndexCollection(com.google.gerrit.server.index.change.ChangeIndexCollection) VisibleForTesting(com.google.common.annotations.VisibleForTesting) QueryBuilder(com.google.gerrit.server.query.QueryBuilder) ChangeIndex(com.google.gerrit.server.index.change.ChangeIndex) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil) Address(com.google.gerrit.server.mail.Address) QueryParseException(com.google.gerrit.server.query.QueryParseException)

Aggregations

ReviewerStateInternal (com.google.gerrit.server.notedb.ReviewerStateInternal)8 Timestamp (java.sql.Timestamp)6 Account (com.google.gerrit.reviewdb.client.Account)5 ImmutableTable (com.google.common.collect.ImmutableTable)3 Change (com.google.gerrit.reviewdb.client.Change)3 Address (com.google.gerrit.server.mail.Address)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Table (com.google.common.collect.Table)2 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)2 CurrentUser (com.google.gerrit.server.CurrentUser)2 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)2 ChangeControl (com.google.gerrit.server.project.ChangeControl)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Enums (com.google.common.base.Enums)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1