Mercurial > hg > AnnotationManagerN4J
changeset 25:2140ef107551
adding and deleting group members.
author | casties |
---|---|
date | Mon, 24 Sep 2012 11:36:33 +0200 |
parents | e208a7b1a37a |
children | f204ce7d1da8 |
files | src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupMembersResource.java |
diffstat | 2 files changed, 51 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Sun Sep 23 16:28:05 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Mon Sep 24 11:36:33 2012 +0200 @@ -178,6 +178,42 @@ } /** + * Add Person newMember to Group group. + * + * @param group + * @param member + */ + public Person addGroupMember(Group group, Person member) { + Node gn = getActorNode(group); + Node pn = getActorNode(member); + Person addedMember = null; + if (gn != null && pn != null) { + getOrCreateRelation(pn, RelationTypes.MEMBER_OF, gn); + addedMember = member; + } + return addedMember; + } + + /** + * Delete Person oldMember from Group group. + * + * @param group + * @param member + */ + public void deleteGroupMember(Group group, Person member) { + Node gn = getActorNode(group); + Iterable<Relationship> rels = gn.getRelationships(RelationTypes.MEMBER_OF); + for (Relationship rel : rels) { + Node mn = rel.getStartNode(); + if (mn.equals(member)) { + rel.delete(); + // there should be only one + break; + } + } + } + + /** * Returns the stored Actor matching the given one. * * @param actor
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupMembersResource.java Sun Sep 23 16:28:05 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupMembersResource.java Mon Sep 24 11:36:33 2012 +0200 @@ -47,12 +47,14 @@ result += String.format("<p>Group: %s <a href=\"%s\">(%s)</a></p>\n", group.getName(), groupsUrl, group.getId()); result += "<p>Members:</p>\n"; result += "<table>"; + result += String.format("<form method=\"post\" action=\"%s\">", thisUrl); List<Person> members = store.getMembersOfGroup(group); for (Person p : members) { result += String.format("<tr><td>%s</td><td>(%s)</td>", p.getName(), p.getIdString()); - //result += String.format("<td></td></tr>\n", p.getName(), p.getIdString()); + result += String.format("<td><input type=\"submit\" name=\"del_member\" value=\"delete:%s\"></td></tr>\n", p.getIdString()); } result += "</table>\n"; + result += "</form>\n"; result += String.format("<form method=\"post\" action=\"%s\">\n", thisUrl); result += "<p>Add new member: <select name=\"add_member\">\n"; for (Actor p : store.getActors("uri", "*", NodeTypes.PERSON)) { @@ -84,7 +86,18 @@ setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return null; } - + if (addMemberId != null) { + logger.debug("adding member: "+addMemberId); + Person member = new Person(addMemberId); + store.addGroupMember(group, member); + } else if (delMemberId != null) { + if (delMemberId.startsWith("delete:")) { + delMemberId = delMemberId.substring(7); + } + logger.debug("deleting member: "+delMemberId); + Person member = new Person(delMemberId); + store.deleteGroupMember(group, member); + } // return 303: see other setStatus(Status.REDIRECTION_SEE_OTHER); // go get same URL