Changeset 24:e208a7b1a37a in AnnotationManagerN4J for src
- Timestamp:
- Sep 23, 2012, 2:28:05 PM (13 years ago)
- Branch:
- default
- Children:
- 25:2140ef107551, 28:f4ed2ed33e5b
- Location:
- src/main/java/de/mpiwg/itgroup/annotations
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
r22 r24 72 72 Node person = getNodeIndex(NodeTypes.PERSON).get("uri", userUri).getSingle(); 73 73 return person; 74 } 75 76 public List<Actor> getActors(String key, String query, NodeTypes type) { 77 ArrayList<Actor> actors = new ArrayList<Actor>(); 78 Index<Node> idx = getNodeIndex(type); 79 if (key == null) { 80 key = "uri"; 81 query = "*"; 82 } 83 IndexHits<Node> actorNodes = idx.query(key, query); 84 for (Node actorNode : actorNodes) { 85 Actor actor = createActorFromNode(actorNode); 86 actors.add(actor); 87 } 88 return actors; 74 89 } 75 90 -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupMembersResource.java
r23 r24 6 6 import java.util.List; 7 7 8 import org.apache.log4j.Logger;9 8 import org.restlet.data.Form; 10 9 import org.restlet.data.MediaType; … … 15 14 import org.restlet.resource.Get; 16 15 import org.restlet.resource.Post; 17 import org.restlet.resource.ServerResource;18 16 19 17 import de.mpiwg.itgroup.annotations.Actor; 20 import de.mpiwg.itgroup.annotations.Group;21 18 import de.mpiwg.itgroup.annotations.Person; 22 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 23 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; 19 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore.NodeTypes; 24 20 25 21 /** … … 29 25 * 30 26 */ 31 public class GroupMembersResource extends ServerResource { 32 33 public static Logger logger = Logger.getLogger(GroupMembersResource.class); 34 35 private AnnotationStore store; 27 public class GroupMembersResource extends GroupResource { 36 28 37 29 /** … … 44 36 public Representation doGetHTML(Representation entity) { 45 37 // id from URI /annotations/groups/{id}/members 46 String id = (String) getRequest().getAttributes().get("id"); 47 logger.debug("group-id=" + id); 48 if (id == null || id.isEmpty()) { 38 if (requestId == null || requestId.isEmpty()) { 49 39 // invalid id 50 40 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); … … 52 42 } 53 43 String result = null; 54 store = getAnnotationStore(); 55 Reference groupsUrl = this.getReference().getParentRef(); 56 result = "<html><body>\n<h1>Members of group</h1>\n"; 57 Group group = new Group(id); 58 group = (Group) store.getActor(group); 44 Reference thisUrl = this.getReference(); 45 Reference groupsUrl = thisUrl.getParentRef(); 46 result = "<html><body>\n<h1>Group members</h1>\n"; 59 47 result += String.format("<p>Group: %s <a href=\"%s\">(%s)</a></p>\n", group.getName(), groupsUrl, group.getId()); 60 48 result += "<p>Members:</p>\n"; … … 62 50 List<Person> members = store.getMembersOfGroup(group); 63 51 for (Person p : members) { 64 result += String.format("<tr><td>%s</td><td>(%s)</td></tr>\n", p.getName(), p.getIdString()); 52 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()); 65 54 } 66 55 result += "</table>\n"; 67 result += "<form method=\"post\" action=\"\">\n"; 68 result += "<p>Add new member: <select name=\"new_member\">\n"; 69 result += String.format("<option value=\"%s\">%s</option>\n", "casties", "casties"); 56 result += String.format("<form method=\"post\" action=\"%s\">\n", thisUrl); 57 result += "<p>Add new member: <select name=\"add_member\">\n"; 58 for (Actor p : store.getActors("uri", "*", NodeTypes.PERSON)) { 59 result += String.format("<option value=\"%s\">%s</option>\n", p.getIdString(), p.getName()); 60 } 70 61 result += "</select>\n"; 71 62 result += "<input type=\"submit\"/>\n"; … … 77 68 78 69 /** 79 * POST creates a newGroup.70 * POST adds or deletes members of the Group. 80 71 * 81 72 * @return … … 83 74 @Post 84 75 public Representation doPost(Representation entity) { 85 logger.debug(" AnnotationsUiGroupdoPost!");76 logger.debug("GroupMembersResource doPost!"); 86 77 // TODO: do authentication 87 78 Form form = new Form(entity); 88 String id = form.getFirstValue("id"); 89 String name = form.getFirstValue("name"); 90 if (id == null || id.isEmpty()) { 91 // invalid id 79 String addMemberId = form.getFirstValue("add_member"); 80 String delMemberId = form.getFirstValue("del_member"); 81 if (group == null || ((addMemberId == null || addMemberId.isEmpty()) 82 && (delMemberId == null || delMemberId.isEmpty()))) { 83 // no id 92 84 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); 93 85 return null; 94 86 } 95 String gid = null; 96 Group newGroup = new Group(gid, null, name); 97 store = getAnnotationStore(); 98 Actor storedGroup = store.storeActor(newGroup); 99 gid = storedGroup.getId(); 87 100 88 // return 303: see other 101 89 setStatus(Status.REDIRECTION_SEE_OTHER); 102 // go GET URL for this group 103 Reference groupUrl = this.getReference(); 104 groupUrl.addSegment(gid); 105 this.getResponse().setLocationRef(groupUrl); 90 // go get same URL 91 Reference thisUrl = this.getReference(); 92 this.getResponse().setLocationRef(thisUrl); 106 93 return null; 107 94 } 108 95 109 protected AnnotationStore getAnnotationStore() {110 if (store == null) {111 store = ((BaseRestlet) getApplication()).getAnnotationStore();112 }113 return store;114 }115 96 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupResource.java
r23 r24 5 5 6 6 import org.apache.log4j.Logger; 7 import org.restlet.data.Form;8 7 import org.restlet.data.MediaType; 9 8 import org.restlet.data.Reference; … … 12 11 import org.restlet.representation.StringRepresentation; 13 12 import org.restlet.resource.Get; 14 import org.restlet.resource. Post;13 import org.restlet.resource.ResourceException; 15 14 import org.restlet.resource.ServerResource; 16 15 17 import de.mpiwg.itgroup.annotations.Actor;18 16 import de.mpiwg.itgroup.annotations.Group; 19 17 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; … … 30 28 public static Logger logger = Logger.getLogger(GroupResource.class); 31 29 32 private AnnotationStore store; 30 protected AnnotationStore store; 31 32 protected String requestId; 33 34 protected Group group; 35 36 @Override 37 protected void doInit() throws ResourceException { 38 super.doInit(); 39 // id from URI /annotations/groups/{id} 40 requestId = (String) getRequest().getAttributes().get("id"); 41 logger.debug("group-id=" + requestId); 42 // get store instance 43 if (store == null) { 44 store = ((BaseRestlet) getApplication()).getAnnotationStore(); 45 } 46 // get group from store 47 if (requestId != null) { 48 group = (Group) store.getActor(new Group(requestId)); 49 } 50 } 33 51 34 52 /** … … 40 58 @Get("html") 41 59 public Representation doGetHTML(Representation entity) { 42 // id from URI /annotations/groups/{id} 43 String id = (String) getRequest().getAttributes().get("id"); 44 logger.debug("group-id=" + id); 45 if (id == null || id.isEmpty()) { 60 if (requestId == null || requestId.isEmpty()) { 46 61 // invalid id 47 62 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); … … 49 64 } 50 65 String result = null; 51 store = getAnnotationStore();52 66 Reference groupsUrl = this.getReference().getParentRef(); 53 67 result = "<html><body>\n<h1>Group</h1>\n"; 54 68 result += String.format("<p><a href=\"%s\">All groups</a></p>", groupsUrl); 55 Group group = new Group(id);56 group = (Group) store.getActor(group);57 69 result += "<table>"; 58 70 result += String.format("<tr><td><b>id</b></td><td>%s</td></tr>\n", group.getId()); … … 68 80 } 69 81 70 /**71 * POST creates a new Group.72 *73 * @return74 */75 @Post76 public Representation doPost(Representation entity) {77 logger.debug("AnnotationsUiGroup doPost!");78 // TODO: do authentication79 Form form = new Form(entity);80 String id = form.getFirstValue("id");81 String name = form.getFirstValue("name");82 if (id == null || id.isEmpty()) {83 // invalid id84 setStatus(Status.CLIENT_ERROR_BAD_REQUEST);85 return null;86 }87 String gid = null;88 Group newGroup = new Group(gid, null, name);89 store = getAnnotationStore();90 Actor storedGroup = store.storeActor(newGroup);91 gid = storedGroup.getId();92 // return 303: see other93 setStatus(Status.REDIRECTION_SEE_OTHER);94 // go GET URL for this group95 Reference groupUrl = this.getReference();96 groupUrl.addSegment(gid);97 this.getResponse().setLocationRef(groupUrl);98 return null;99 }100 101 protected AnnotationStore getAnnotationStore() {102 if (store == null) {103 store = ((BaseRestlet) getApplication()).getAnnotationStore();104 }105 return store;106 }107 82 }
Note: See TracChangeset
for help on using the changeset viewer.