Search in sources :

Example 1 with ParsedPatchSetApproval

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

the class ChangeNotesParser method parseCopiedApproval.

/**
 * Parses copied {@link PatchSetApproval}.
 */
private void parseCopiedApproval(PatchSet.Id psId, Instant ts, String line) throws ConfigInvalidException {
    ParsedPatchSetApproval parsedPatchSetApproval = ChangeNoteUtil.parseCopiedApproval(line);
    checkFooter(parsedPatchSetApproval.accountIdent().isPresent(), FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
    PersonIdent accountIdent = RawParseUtils.parsePersonIdent(parsedPatchSetApproval.accountIdent().get());
    checkFooter(accountIdent != null, FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
    Account.Id accountId = parseIdent(accountIdent);
    Account.Id realAccountId = null;
    if (parsedPatchSetApproval.realAccountIdent().isPresent()) {
        PersonIdent realIdent = RawParseUtils.parsePersonIdent(parsedPatchSetApproval.realAccountIdent().get());
        checkFooter(realIdent != null, FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
        realAccountId = parseIdent(realIdent);
    }
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(parsedPatchSetApproval.labelVote());
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval.Builder psa = PatchSetApproval.builder().key(PatchSetApproval.key(psId, accountId, LabelId.create(l.label()))).uuid(parsedPatchSetApproval.uuid().map(PatchSetApproval::uuid)).value(l.value()).granted(ts).tag(parsedPatchSetApproval.tag()).copied(true);
    if (realAccountId != null) {
        psa.realAccountId(realAccountId);
    }
    approvals.putIfAbsent(psa.key(), psa);
    bufferedApprovals.add(psa);
}
Also used : Account(com.google.gerrit.entities.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelVote(com.google.gerrit.server.util.LabelVote) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval)

Example 2 with ParsedPatchSetApproval

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

the class ChangeNotesParser method parseApproval.

private void parseApproval(PatchSet.Id psId, Account.Id accountId, Account.Id realAccountId, Instant ts, String line) throws ConfigInvalidException {
    if (accountId == null) {
        throw parseException("patch set %s requires an identified user as uploader", psId.get());
    }
    PatchSetApproval.Builder psa;
    ParsedPatchSetApproval parsedPatchSetApproval = ChangeNoteUtil.parseApproval(line);
    if (line.startsWith("-")) {
        psa = parseRemoveApproval(psId, accountId, realAccountId, ts, parsedPatchSetApproval);
    } else {
        psa = parseAddApproval(psId, accountId, realAccountId, ts, parsedPatchSetApproval);
    }
    bufferedApprovals.add(psa);
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval)

Example 3 with ParsedPatchSetApproval

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

the class ChangeNotesParser method parseAddApproval.

/**
 * Parses {@link PatchSetApproval} out of the {@link ChangeNoteUtil#FOOTER_LABEL} value.
 */
private PatchSetApproval.Builder parseAddApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Instant ts, ParsedPatchSetApproval parsedPatchSetApproval) throws ConfigInvalidException {
    Account.Id approverId = parseApprover(committerId, parsedPatchSetApproval);
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(parsedPatchSetApproval.labelVote());
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, parsedPatchSetApproval.footerLine());
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval.Builder psa = PatchSetApproval.builder().key(PatchSetApproval.key(psId, approverId, LabelId.create(l.label()))).uuid(parsedPatchSetApproval.uuid().map(PatchSetApproval::uuid)).value(l.value()).granted(ts).tag(Optional.ofNullable(tag));
    if (!Objects.equals(realAccountId, committerId)) {
        psa.realAccountId(realAccountId);
    }
    approvals.putIfAbsent(psa.key(), psa);
    return psa;
}
Also used : Account(com.google.gerrit.entities.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) LabelVote(com.google.gerrit.server.util.LabelVote) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval)

Aggregations

PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)3 ParsedPatchSetApproval (com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval)3 Account (com.google.gerrit.entities.Account)2 LabelVote (com.google.gerrit.server.util.LabelVote)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)1