Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 22:b1fb0d117877
adding and listing groups via html works now.
no editing of group membership yet.
no authentication yet.
author | casties |
---|---|
date | Thu, 20 Sep 2012 17:42:26 +0200 |
parents | f0f55ab768c9 |
children | e208a7b1a37a |
comparison
equal
deleted
inserted
replaced
21:1ac626309352 | 22:b1fb0d117877 |
---|---|
137 } | 137 } |
138 } | 138 } |
139 return false; | 139 return false; |
140 } | 140 } |
141 | 141 |
142 /** | |
143 * Returns the members of the group. | |
144 * | |
145 * @param group | |
146 * @return | |
147 */ | |
148 public List<Person> getMembersOfGroup(Group group) { | |
149 ArrayList<Person> members = new ArrayList<Person>(); | |
150 Node gn = getActorNode(group); | |
151 Iterable<Relationship> rels = gn.getRelationships(RelationTypes.MEMBER_OF); | |
152 for (Relationship rel : rels) { | |
153 Node memberNode = rel.getStartNode(); | |
154 Actor member = createActorFromNode(memberNode); | |
155 // make sure we're getting a group | |
156 if (!(member instanceof Person)) { | |
157 logger.error("source of MEMBER_OF is not PERSON! rel=" + rel); | |
158 continue; | |
159 } | |
160 members.add((Person) member); | |
161 } | |
162 return members; | |
163 } | |
164 | |
165 /** | |
166 * Returns the stored Actor matching the given one. | |
167 * | |
168 * @param actor | |
169 * @return | |
170 */ | |
171 public Actor getActor(Actor actor) { | |
172 Node actorNode = getActorNode(actor); | |
173 Actor storedActor = createActorFromNode(actorNode); | |
174 return storedActor; | |
175 } | |
176 | |
177 /** | |
178 * Stores an Actor (Person or Group). Creates a new actor Node or returns an existing one. | |
179 * | |
180 * @param actor | |
181 * @return | |
182 */ | |
183 public Actor storeActor(Actor actor) { | |
184 Node actorNode = getOrCreateActorNode(actor); | |
185 Actor storedActor = createActorFromNode(actorNode); | |
186 return storedActor; | |
187 } | |
188 | |
142 /** | 189 /** |
143 * Returns the Annotation with the given id. | 190 * Returns the Annotation with the given id. |
144 * | 191 * |
145 * @param id | 192 * @param id |
146 * @return | 193 * @return |
533 } | 580 } |
534 } | 581 } |
535 return target; | 582 return target; |
536 } | 583 } |
537 | 584 |
585 protected Node getActorNode(Actor actor) { | |
586 // Person/Group is identified by URI or id | |
587 String uri = actor.getUriString(); | |
588 Index<Node> idx; | |
589 if (actor.isGroup()) { | |
590 idx = getNodeIndex(NodeTypes.GROUP); | |
591 } else { | |
592 idx = getNodeIndex(NodeTypes.PERSON); | |
593 } | |
594 IndexHits<Node> persons = idx.get("uri", uri); | |
595 Node person = persons.getSingle(); | |
596 return person; | |
597 } | |
598 | |
538 protected Node getOrCreateActorNode(Actor actor) { | 599 protected Node getOrCreateActorNode(Actor actor) { |
539 // Person/Group is identified by URI or id | 600 // Person/Group is identified by URI or id |
540 String uri = actor.getUriString(); | 601 String uri = actor.getUriString(); |
541 String name = actor.getName(); | 602 String name = actor.getName(); |
542 String id = actor.getId(); | 603 String id = actor.getId(); |