Changeset 24:e208a7b1a37a in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupResource.java
- Timestamp:
- Sep 23, 2012, 2:28:05 PM (12 years ago)
- Branch:
- default
- Children:
- 25:2140ef107551, 28:f4ed2ed33e5b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.