Search in sources :

Example 41 with GroupInfo

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

the class AbstractQueryGroupsTest method format.

protected String format(Iterable<GroupInfo> groups) {
    StringBuilder b = new StringBuilder();
    b.append("[");
    Iterator<GroupInfo> it = groups.iterator();
    while (it.hasNext()) {
        GroupInfo g = it.next();
        b.append("{").append(g.id).append(", ").append("name=").append(g.name).append(", ").append("groupId=").append(g.groupId).append(", ").append("url=").append(g.url).append(", ").append("ownerId=").append(g.ownerId).append(", ").append("owner=").append(g.owner).append(", ").append("description=").append(g.description).append(", ").append("visibleToAll=").append(toBoolean(g.options.visibleToAll)).append("}");
        if (it.hasNext()) {
            b.append(", ");
        }
    }
    b.append("]");
    return b.toString();
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Example 42 with GroupInfo

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

the class AbstractQueryGroupsTest method rawDocument.

@Test
public void rawDocument() throws Exception {
    GroupInfo group1 = createGroup(name("group1"));
    AccountGroup.UUID uuid = AccountGroup.uuid(group1.id);
    Optional<FieldBundle> rawFields = indexes.getSearchIndex().getRaw(uuid, QueryOptions.create(IndexConfig.createDefault(), 0, 10, indexes.getSearchIndex().getSchema().getStoredFields().keySet()));
    assertThat(rawFields).isPresent();
    assertThat(rawFields.get().getValue(GroupField.UUID)).isEqualTo(uuid.get());
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) FieldBundle(com.google.gerrit.index.query.FieldBundle) Test(org.junit.Test)

Example 43 with GroupInfo

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

the class AbstractQueryGroupsTest method byDefaultField.

@Test
public void byDefaultField() throws Exception {
    GroupInfo group1 = createGroup(name("foo-group"));
    GroupInfo group2 = createGroup(name("group2"));
    GroupInfo group3 = createGroupWithDescription(name("group3"), "decription that contains foo and the UUID of group2: " + group2.id);
    assertQuery("non-existing");
    assertQuery("foo", group1, group3);
    assertQuery(group2.id, group2, group3);
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo) Test(org.junit.Test)

Example 44 with GroupInfo

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

the class SuggestReviewersIT method group.

private AccountGroup group(String name) throws Exception {
    GroupInfo group = createGroupFactory.create(name(name)).apply(TopLevelResource.INSTANCE, null);
    GroupDescription.Basic d = groups.parseInternal(Url.decode(group.id));
    return GroupDescriptions.toAccountGroup(d);
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Example 45 with GroupInfo

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

the class AddIncludedGroups method apply.

@Override
public List<GroupInfo> apply(GroupResource resource, Input input) throws MethodNotAllowedException, AuthException, UnprocessableEntityException, OrmException {
    AccountGroup group = resource.toAccountGroup();
    if (group == null) {
        throw new MethodNotAllowedException();
    }
    input = Input.init(input);
    GroupControl control = resource.getControl();
    Map<AccountGroup.UUID, AccountGroupById> newIncludedGroups = new HashMap<>();
    List<GroupInfo> result = new ArrayList<>();
    Account.Id me = control.getUser().getAccountId();
    for (String includedGroup : input.groups) {
        GroupDescription.Basic d = groupsCollection.parse(includedGroup);
        if (!control.canAddGroup()) {
            throw new AuthException(String.format("Cannot add group: %s", d.getName()));
        }
        if (!newIncludedGroups.containsKey(d.getGroupUUID())) {
            AccountGroupById.Key agiKey = new AccountGroupById.Key(group.getId(), d.getGroupUUID());
            AccountGroupById agi = db.get().accountGroupById().get(agiKey);
            if (agi == null) {
                agi = new AccountGroupById(agiKey);
                newIncludedGroups.put(d.getGroupUUID(), agi);
            }
        }
        result.add(json.format(d));
    }
    if (!newIncludedGroups.isEmpty()) {
        auditService.dispatchAddGroupsToGroup(me, newIncludedGroups.values());
        db.get().accountGroupById().insert(newIncludedGroups.values());
        for (AccountGroupById agi : newIncludedGroups.values()) {
            groupIncludeCache.evictParentGroupsOf(agi.getIncludeUUID());
        }
        groupIncludeCache.evictSubgroupsOf(group.getGroupUUID());
    }
    return result;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) HashMap(java.util.HashMap) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) GroupControl(com.google.gerrit.server.account.GroupControl) GroupDescription(com.google.gerrit.common.data.GroupDescription) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById)

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