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