Search in sources :

Example 1 with AccountAttribute

use of com.google.gerrit.server.data.AccountAttribute in project gerrit by GerritCodeReview.

the class EventFactory method asAccountAttribute.

/**
   * Create an AuthorAttribute for the given person ident suitable for serialization to JSON.
   *
   * @param ident
   * @return object suitable for serialization to JSON
   */
public AccountAttribute asAccountAttribute(PersonIdent ident) {
    AccountAttribute who = new AccountAttribute();
    who.name = ident.getName();
    who.email = ident.getEmailAddress();
    return who;
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute)

Example 2 with AccountAttribute

use of com.google.gerrit.server.data.AccountAttribute in project gerrit by GerritCodeReview.

the class EventDeserializerTest method refUpdatedEvent.

@Test
public void refUpdatedEvent() {
    RefUpdatedEvent refUpdatedEvent = new RefUpdatedEvent();
    RefUpdateAttribute refUpdatedAttribute = new RefUpdateAttribute();
    refUpdatedAttribute.refName = "refs/heads/master";
    refUpdatedEvent.refUpdate = createSupplier(refUpdatedAttribute);
    AccountAttribute accountAttribute = new AccountAttribute();
    accountAttribute.email = "some.user@domain.com";
    refUpdatedEvent.submitter = createSupplier(accountAttribute);
    Gson gsonSerializer = new GsonBuilder().registerTypeAdapter(Supplier.class, new SupplierSerializer()).create();
    String serializedEvent = gsonSerializer.toJson(refUpdatedEvent);
    Gson gsonDeserializer = new GsonBuilder().registerTypeAdapter(Event.class, new EventDeserializer()).registerTypeAdapter(Supplier.class, new SupplierDeserializer()).create();
    RefUpdatedEvent e = (RefUpdatedEvent) gsonDeserializer.fromJson(serializedEvent, Event.class);
    assertThat(e).isNotNull();
    assertThat(e.refUpdate).isInstanceOf(Supplier.class);
    assertThat(e.refUpdate.get().refName).isEqualTo(refUpdatedAttribute.refName);
    assertThat(e.submitter).isInstanceOf(Supplier.class);
    assertThat(e.submitter.get().email).isEqualTo(accountAttribute.email);
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute) RefUpdateAttribute(com.google.gerrit.server.data.RefUpdateAttribute) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Supplier(com.google.common.base.Supplier) Test(org.junit.Test)

Example 3 with AccountAttribute

use of com.google.gerrit.server.data.AccountAttribute in project gerrit by GerritCodeReview.

the class EventFactory method asAccountAttribute.

/**
   * Create an AuthorAttribute for the given account suitable for serialization to JSON.
   *
   * @param account
   * @return object suitable for serialization to JSON
   */
public AccountAttribute asAccountAttribute(Account account) {
    if (account == null) {
        return null;
    }
    AccountAttribute who = new AccountAttribute();
    who.name = account.getFullName();
    who.email = account.getPreferredEmail();
    who.username = account.getUserName();
    return who;
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute)

Example 4 with AccountAttribute

use of com.google.gerrit.server.data.AccountAttribute in project gerrit by GerritCodeReview.

the class EventFactory method asPatchSetAttribute.

/**
   * Create a PatchSetAttribute for the given patchset suitable for serialization to JSON.
   *
   * @param db Review database
   * @param patchSet
   * @return object suitable for serialization to JSON
   */
public PatchSetAttribute asPatchSetAttribute(ReviewDb db, RevWalk revWalk, Change change, PatchSet patchSet) {
    PatchSetAttribute p = new PatchSetAttribute();
    p.revision = patchSet.getRevision().get();
    p.number = patchSet.getPatchSetId();
    p.ref = patchSet.getRefName();
    p.uploader = asAccountAttribute(patchSet.getUploader());
    p.createdOn = patchSet.getCreatedOn().getTime() / 1000L;
    p.isDraft = patchSet.isDraft();
    PatchSet.Id pId = patchSet.getId();
    try {
        p.parents = new ArrayList<>();
        RevCommit c = revWalk.parseCommit(ObjectId.fromString(p.revision));
        for (RevCommit parent : c.getParents()) {
            p.parents.add(parent.name());
        }
        UserIdentity author = toUserIdentity(c.getAuthorIdent());
        if (author.getAccount() == null) {
            p.author = new AccountAttribute();
            p.author.email = author.getEmail();
            p.author.name = author.getName();
            p.author.username = "";
        } else {
            p.author = asAccountAttribute(author.getAccount());
        }
        List<Patch> list = patchListCache.get(change, patchSet).toPatchList(pId);
        for (Patch pe : list) {
            if (!Patch.isMagic(pe.getFileName())) {
                p.sizeDeletions -= pe.getDeletions();
                p.sizeInsertions += pe.getInsertions();
            }
        }
        p.kind = changeKindCache.getChangeKind(db, change, patchSet);
    } catch (IOException e) {
        log.error("Cannot load patch set data for " + patchSet.getId(), e);
    } catch (PatchListNotAvailableException e) {
        log.error(String.format("Cannot get size information for %s.", pId), e);
    }
    return p;
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute) UserIdentity(com.google.gerrit.reviewdb.client.UserIdentity) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) IOException(java.io.IOException) Patch(com.google.gerrit.reviewdb.client.Patch) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

AccountAttribute (com.google.gerrit.server.data.AccountAttribute)4 Supplier (com.google.common.base.Supplier)1 Patch (com.google.gerrit.reviewdb.client.Patch)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 UserIdentity (com.google.gerrit.reviewdb.client.UserIdentity)1 PatchSetAttribute (com.google.gerrit.server.data.PatchSetAttribute)1 RefUpdateAttribute (com.google.gerrit.server.data.RefUpdateAttribute)1 PatchListNotAvailableException (com.google.gerrit.server.patch.PatchListNotAvailableException)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 IOException (java.io.IOException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 Test (org.junit.Test)1