Mercurial > hg > AnnotationManagerN4J
changeset 29:3be0ebb6d5ad
Merge with 1cf7203009f26a8a55fc387adcb8ae6ca681520c
author | dwinter |
---|---|
date | Tue, 25 Sep 2012 09:35:26 +0200 |
parents | f4ed2ed33e5b (current diff) 6bc918105c9a (diff) |
children | 05b631a084d0 |
files | src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.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 Tue Sep 25 09:32:56 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Tue Sep 25 09:35:26 2012 +0200 @@ -214,6 +214,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 Tue Sep 25 09:32:56 2012 +0200 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupMembersResource.java Tue Sep 25 09:35:26 2012 +0200 @@ -46,13 +46,15 @@ result = "<html><body>\n<h1>Group members</h1>\n"; result += String.format("<p>Group: %s <a href=\"%s\">(%s)</a></p>\n", group.getName(), groupsUrl, group.getId()); result += "<p>Members:</p>\n"; + result += String.format("<form method=\"post\" action=\"%s\">", thisUrl); result += "<table>"; 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