Return the created InternalGroup internally after a group creation

This change is a prerequisite for migrating groups to NoteDb.

Change-Id: I47767c7d085310ccc2fab1d1384119ef32031e24
This commit is contained in:
Alice Kober-Sotzek
2017-10-16 15:32:00 +02:00
committed by Dave Borowitz
parent ffe9b358aa
commit 51a68b6c4b
2 changed files with 7 additions and 7 deletions

View File

@@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.common.data.GroupDescription;
import com.google.gerrit.common.data.GroupDescriptions;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.api.groups.GroupInput;
import com.google.gerrit.extensions.client.ListGroupsOption;
@@ -162,7 +161,7 @@ public class CreateGroup implements RestModifyView<TopLevelResource, GroupInput>
}
}
return json.format(GroupDescriptions.forAccountGroup(createGroup(args)));
return json.format(new InternalGroupDescription(createGroup(args)));
}
private AccountGroup.Id owner(GroupInput input) throws UnprocessableEntityException {
@@ -173,7 +172,7 @@ public class CreateGroup implements RestModifyView<TopLevelResource, GroupInput>
return null;
}
private AccountGroup createGroup(CreateGroupArgs createGroupArgs)
private InternalGroup createGroup(CreateGroupArgs createGroupArgs)
throws OrmException, ResourceConflictException, IOException {
String nameLower = createGroupArgs.getGroupName().toLowerCase(Locale.US);
@@ -206,14 +205,12 @@ public class CreateGroup implements RestModifyView<TopLevelResource, GroupInput>
group.setDescription(createGroupArgs.groupDescription);
}
try {
groupsUpdateProvider
return groupsUpdateProvider
.get()
.addGroup(db, group, ImmutableSet.copyOf(createGroupArgs.initialMembers));
} catch (OrmDuplicateKeyException e) {
throw new ResourceConflictException(
"group '" + createGroupArgs.getGroupName() + "' already exists");
}
return group;
}
}

View File

@@ -116,12 +116,15 @@ public class GroupsUpdate {
* @throws OrmException if an error occurs while reading/writing from/to ReviewDb
* @throws IOException if the cache entry of one of the new members couldn't be invalidated, or
* the new group couldn't be indexed
* @return the created group
*/
public void addGroup(ReviewDb db, AccountGroup group, Set<Account.Id> memberIds)
public InternalGroup addGroup(ReviewDb db, AccountGroup group, Set<Account.Id> memberIds)
throws OrmException, IOException {
addNewGroup(db, group);
addNewGroupMembers(db, group, memberIds);
groupCache.onCreateGroup(group.getGroupUUID());
return InternalGroup.create(group, ImmutableSet.copyOf(memberIds), ImmutableSet.of());
}
/**