Search in sources :

Example 46 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo 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 47 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupJson method init.

private GroupInfo init(GroupDescription.Basic group) {
    GroupInfo info = new GroupInfo();
    info.id = Url.encode(group.getGroupUUID().get());
    info.name = Strings.emptyToNull(group.getName());
    info.url = Strings.emptyToNull(group.getUrl());
    info.options = createOptions(group);
    AccountGroup g = GroupDescriptions.toAccountGroup(group);
    if (g != null) {
        info.description = Strings.emptyToNull(g.getDescription());
        info.groupId = g.getId().get();
        if (g.getOwnerGroupUUID() != null) {
            info.ownerId = Url.encode(g.getOwnerGroupUUID().get());
            GroupDescription.Basic o = groupBackend.get(g.getOwnerGroupUUID());
            if (o != null) {
                info.owner = o.getName();
            }
        }
    }
    return info;
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Example 48 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupJson method format.

public GroupInfo format(GroupDescription.Basic group) throws OrmException {
    GroupInfo info = init(group);
    if (options.contains(MEMBERS) || options.contains(INCLUDES)) {
        GroupResource rsrc = new GroupResource(groupControlFactory.controlFor(group));
        initMembersAndIncludes(rsrc, info);
    }
    return info;
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Example 49 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupJson method format.

public GroupInfo format(GroupResource rsrc) throws OrmException {
    GroupInfo info = init(rsrc.getGroup());
    initMembersAndIncludes(rsrc, info);
    return info;
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Example 50 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class ListGroups method getAllGroups.

private List<GroupInfo> getAllGroups() throws OrmException {
    List<GroupInfo> groupInfos;
    List<AccountGroup> groupList;
    if (!projects.isEmpty()) {
        Map<AccountGroup.UUID, AccountGroup> groups = new HashMap<>();
        for (final ProjectControl projectControl : projects) {
            final Set<GroupReference> groupsRefs = projectControl.getAllGroups();
            for (final GroupReference groupRef : groupsRefs) {
                final AccountGroup group = groupCache.get(groupRef.getUUID());
                if (group != null) {
                    groups.put(group.getGroupUUID(), group);
                }
            }
        }
        groupList = filterGroups(groups.values());
    } else {
        groupList = filterGroups(groupCache.all());
    }
    groupInfos = Lists.newArrayListWithCapacity(groupList.size());
    int found = 0;
    int foundIndex = 0;
    for (AccountGroup group : groupList) {
        if (foundIndex++ < start) {
            continue;
        }
        if (limit > 0 && ++found > limit) {
            break;
        }
        groupInfos.add(json.addOptions(options).format(GroupDescriptions.forAccountGroup(group)));
    }
    return groupInfos;
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) HashMap(java.util.HashMap) GroupReference(com.google.gerrit.common.data.GroupReference) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Aggregations

GroupInfo (com.google.gerrit.extensions.common.GroupInfo)92 Test (org.junit.Test)60 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 AccountGroup (com.google.gerrit.entities.AccountGroup)28 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)24 ArrayList (java.util.ArrayList)11 GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)10 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)10 Account (com.google.gerrit.entities.Account)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)8 GroupControl (com.google.gerrit.server.account.GroupControl)8 GroupDescription (com.google.gerrit.entities.GroupDescription)7 GroupReference (com.google.gerrit.entities.GroupReference)7 TestAccount (com.google.gerrit.acceptance.TestAccount)6 InternalGroup (com.google.gerrit.entities.InternalGroup)6 GroupDescription (com.google.gerrit.common.data.GroupDescription)5 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)5 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)5 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)5