Changeset 25:2140ef107551 in AnnotationManagerN4J


Ignore:
Timestamp:
Sep 24, 2012, 9:36:33 AM (12 years ago)
Author:
casties
Branch:
default
Message:

adding and deleting group members.

Location:
src/main/java/de/mpiwg/itgroup/annotations
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java

    r24 r25  
    176176        }
    177177        return members;
     178    }
     179   
     180    /**
     181     * Add Person newMember to Group group.
     182     *
     183     * @param group
     184     * @param member
     185     */
     186    public Person addGroupMember(Group group, Person member) {
     187        Node gn = getActorNode(group);
     188        Node pn = getActorNode(member);
     189        Person addedMember = null;
     190        if (gn != null && pn != null) {
     191            getOrCreateRelation(pn, RelationTypes.MEMBER_OF, gn);
     192            addedMember = member;
     193        }
     194        return addedMember;
     195    }
     196   
     197    /**
     198     * Delete Person oldMember from Group group.
     199     *
     200     * @param group
     201     * @param member
     202     */
     203    public void deleteGroupMember(Group group, Person member) {
     204        Node gn = getActorNode(group);
     205        Iterable<Relationship> rels = gn.getRelationships(RelationTypes.MEMBER_OF);
     206        for (Relationship rel : rels) {
     207            Node mn = rel.getStartNode();
     208            if (mn.equals(member)) {
     209                rel.delete();
     210                // there should be only one
     211                break;
     212            }
     213        }       
    178214    }
    179215   
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupMembersResource.java

    r24 r25  
    4848        result += "<p>Members:</p>\n";
    4949        result += "<table>";
     50        result += String.format("<form method=\"post\" action=\"%s\">", thisUrl);
    5051        List<Person> members = store.getMembersOfGroup(group);
    5152        for (Person p : members) {
    5253            result += String.format("<tr><td>%s</td><td>(%s)</td>", p.getName(), p.getIdString());
    53             //result += String.format("<td></td></tr>\n", p.getName(), p.getIdString());
     54            result += String.format("<td><input type=\"submit\" name=\"del_member\" value=\"delete:%s\"></td></tr>\n", p.getIdString());
    5455        }
    5556        result += "</table>\n";
     57        result += "</form>\n";
    5658        result += String.format("<form method=\"post\" action=\"%s\">\n", thisUrl);
    5759        result += "<p>Add new member: <select name=\"add_member\">\n";
     
    8587            return null;
    8688        }
    87        
     89        if (addMemberId != null) {
     90            logger.debug("adding member: "+addMemberId);
     91            Person member = new Person(addMemberId);
     92            store.addGroupMember(group, member);
     93        } else if (delMemberId != null) {
     94            if (delMemberId.startsWith("delete:")) {
     95                delMemberId = delMemberId.substring(7);
     96            }
     97            logger.debug("deleting member: "+delMemberId);
     98            Person member = new Person(delMemberId);
     99            store.deleteGroupMember(group, member);
     100        }
    88101        // return 303: see other
    89102        setStatus(Status.REDIRECTION_SEE_OTHER);
Note: See TracChangeset for help on using the changeset viewer.