Search in sources :

Example 6 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class GetAuditLog method apply.

@Override
public List<? extends GroupAuditEventInfo> apply(GroupResource rsrc) throws AuthException, ResourceNotFoundException, MethodNotAllowedException, OrmException {
    if (rsrc.toAccountGroup() == null) {
        throw new MethodNotAllowedException();
    } else if (!rsrc.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }
    AccountGroup group = db.get().accountGroups().get(rsrc.toAccountGroup().getId());
    if (group == null) {
        throw new ResourceNotFoundException();
    }
    AccountLoader accountLoader = accountLoaderFactory.create(true);
    List<GroupAuditEventInfo> auditEvents = new ArrayList<>();
    for (AccountGroupMemberAudit auditEvent : db.get().accountGroupMembersAudit().byGroup(group.getId()).toList()) {
        AccountInfo member = accountLoader.get(auditEvent.getKey().getParentKey());
        auditEvents.add(GroupAuditEventInfo.createAddUserEvent(accountLoader.get(auditEvent.getAddedBy()), auditEvent.getKey().getAddedOn(), member));
        if (!auditEvent.isActive()) {
            auditEvents.add(GroupAuditEventInfo.createRemoveUserEvent(accountLoader.get(auditEvent.getRemovedBy()), auditEvent.getRemovedOn(), member));
        }
    }
    for (AccountGroupByIdAud auditEvent : db.get().accountGroupByIdAud().byGroup(group.getId()).toList()) {
        AccountGroup.UUID includedGroupUUID = auditEvent.getKey().getIncludeUUID();
        AccountGroup includedGroup = groupCache.get(includedGroupUUID);
        GroupInfo member;
        if (includedGroup != null) {
            member = groupJson.format(GroupDescriptions.forAccountGroup(includedGroup));
        } else {
            GroupDescription.Basic groupDescription = groupBackend.get(includedGroupUUID);
            member = new GroupInfo();
            member.id = Url.encode(includedGroupUUID.get());
            member.name = groupDescription.getName();
        }
        auditEvents.add(GroupAuditEventInfo.createAddGroupEvent(accountLoader.get(auditEvent.getAddedBy()), auditEvent.getKey().getAddedOn(), member));
        if (!auditEvent.isActive()) {
            auditEvents.add(GroupAuditEventInfo.createRemoveGroupEvent(accountLoader.get(auditEvent.getRemovedBy()), auditEvent.getRemovedOn(), member));
        }
    }
    accountLoader.fill();
    // sort by date in reverse order so that the newest audit event comes first
    Collections.sort(auditEvents, new Comparator<GroupAuditEventInfo>() {

        @Override
        public int compare(GroupAuditEventInfo e1, GroupAuditEventInfo e2) {
            return e2.date.compareTo(e1.date);
        }
    });
    return auditEvents;
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) GroupDescription(com.google.gerrit.common.data.GroupDescription) GroupAuditEventInfo(com.google.gerrit.extensions.common.GroupAuditEventInfo) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountGroupByIdAud(com.google.gerrit.reviewdb.client.AccountGroupByIdAud) AccountLoader(com.google.gerrit.server.account.AccountLoader) AccountGroupMemberAudit(com.google.gerrit.reviewdb.client.AccountGroupMemberAudit) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 7 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class ReviewerJson method format.

public List<ReviewerInfo> format(Collection<ReviewerResource> rsrcs) throws OrmException, PermissionBackendException {
    List<ReviewerInfo> infos = Lists.newArrayListWithCapacity(rsrcs.size());
    AccountLoader loader = accountLoaderFactory.create(true);
    ChangeData cd = null;
    for (ReviewerResource rsrc : rsrcs) {
        if (cd == null || !cd.getId().equals(rsrc.getChangeId())) {
            cd = changeDataFactory.create(db.get(), rsrc.getControl().getNotes());
        }
        ReviewerInfo info = format(new ReviewerInfo(rsrc.getReviewerUser().getAccountId().get()), permissionBackend.user(rsrc.getReviewerUser()).database(db).change(cd), cd);
        loader.put(info);
        infos.add(info);
    }
    loader.fill();
    return infos;
}
Also used : AccountLoader(com.google.gerrit.server.account.AccountLoader) ChangeData(com.google.gerrit.server.query.change.ChangeData) ReviewerInfo(com.google.gerrit.extensions.api.changes.ReviewerInfo)

Example 8 with AccountLoader

use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.

the class TestSubmitRule method apply.

@Override
public List<Record> apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, OrmException {
    if (input == null) {
        input = new TestSubmitRuleInput();
    }
    if (input.rule != null && !rules.isProjectRulesEnabled()) {
        throw new AuthException("project rules are disabled");
    }
    input.filters = MoreObjects.firstNonNull(input.filters, filters);
    SubmitRuleEvaluator evaluator = new SubmitRuleEvaluator(changeDataFactory.create(db.get(), rsrc.getControl()));
    List<SubmitRecord> records = evaluator.setPatchSet(rsrc.getPatchSet()).setLogErrors(false).setSkipSubmitFilters(input.filters == Filters.SKIP).setRule(input.rule).evaluate();
    List<Record> out = Lists.newArrayListWithCapacity(records.size());
    AccountLoader accounts = accountInfoFactory.create(true);
    for (SubmitRecord r : records) {
        out.add(new Record(r, accounts));
    }
    if (!out.isEmpty()) {
        out.get(0).prologReductionCount = evaluator.getReductionsConsumed();
    }
    accounts.fill();
    return out;
}
Also used : SubmitRuleEvaluator(com.google.gerrit.server.project.SubmitRuleEvaluator) SubmitRecord(com.google.gerrit.common.data.SubmitRecord) TestSubmitRuleInput(com.google.gerrit.extensions.common.TestSubmitRuleInput) AccountLoader(com.google.gerrit.server.account.AccountLoader) AuthException(com.google.gerrit.extensions.restapi.AuthException) SubmitRecord(com.google.gerrit.common.data.SubmitRecord)

Aggregations

AccountLoader (com.google.gerrit.server.account.AccountLoader)8 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)5 ArrayList (java.util.ArrayList)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 Account (com.google.gerrit.reviewdb.client.Account)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 GroupDescription (com.google.gerrit.common.data.GroupDescription)1 GroupReference (com.google.gerrit.common.data.GroupReference)1 SubmitRecord (com.google.gerrit.common.data.SubmitRecord)1 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)1 ReviewerInfo (com.google.gerrit.extensions.api.changes.ReviewerInfo)1 GroupAuditEventInfo (com.google.gerrit.extensions.common.GroupAuditEventInfo)1 GroupBaseInfo (com.google.gerrit.extensions.common.GroupBaseInfo)1 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)1 SuggestedReviewerInfo (com.google.gerrit.extensions.common.SuggestedReviewerInfo)1 TestSubmitRuleInput (com.google.gerrit.extensions.common.TestSubmitRuleInput)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1