Skip to content
Snippets Groups Projects
Verified Commit 8dc3bd2c authored by Torsten Grote's avatar Torsten Grote
Browse files

Implement private group creation and fetching in PrivateGroupManager

parent c934ec30
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment