Implement private group creation and fetching in PrivateGroupManager

This commit is contained in:
Torsten Grote
2016-10-13 17:19:27 -03:00
parent c934ec30aa
commit 8dc3bd2c4c
2 changed files with 37 additions and 1 deletions

View File

@@ -18,6 +18,9 @@ public interface PrivateGroupManager extends MessageTracker {
@NotNull
ClientId getClientId();
/** Adds a new private group. */
GroupId addPrivateGroup(String name) throws DbException;
/** Removes a dissolved private group. */
void removePrivateGroup(GroupId g) throws DbException;

View File

@@ -28,6 +28,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Logger;
@@ -70,6 +71,21 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
return CLIENT_ID;
}
@Override
public GroupId addPrivateGroup(String name) throws DbException {
PrivateGroup group;
Transaction txn = db.startTransaction(false);
try {
LocalAuthor a = identityManager.getLocalAuthor(txn);
group = privateGroupFactory.createPrivateGroup(name, a);
db.addGroup(txn, group.getGroup());
txn.setComplete();
} finally {
db.endTransaction(txn);
}
return group.getId();
}
@Override
public void removePrivateGroup(GroupId g) throws DbException {
@@ -137,7 +153,24 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
@NotNull
@Override
public Collection<PrivateGroup> getPrivateGroups() throws DbException {
return Collections.emptyList();
Collection<Group> groups;
Transaction txn = db.startTransaction(true);
try {
groups = db.getGroups(txn, getClientId());
txn.setComplete();
} finally {
db.endTransaction(txn);
}
try {
Collection<PrivateGroup> privateGroups =
new ArrayList<PrivateGroup>(groups.size());
for (Group g : groups) {
privateGroups.add(privateGroupFactory.parsePrivateGroup(g));
}
return privateGroups;
} catch (FormatException e) {
throw new DbException(e);
}
}
@Override