package cactusServer.resources; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import cactusServer.entities.Angle; import cactusServer.entities.IDAddressedEntity; import cactusServer.entities.Instance; import cactusServer.entities.URIAddressedEntity; import cactusServer.entities.Object.Attribute; import cactusServer.models.Instances; import framework.model3D.Position3D; import framework.physics.AngularVelocity3D; import framework.physics.Velocity3D; public class ObjectsRest { public static final String INSTANCES_URI = "/CactusServer/rest/instances"; public ObjectsRest() { } @Path("/{instanceId}/objects/{objectId}") @GET @Produces(MediaType.APPLICATION_JSON) public Object getObject(@PathParam("instanceId") String instanceId, @PathParam("objectId") String objectId) { Instance instance = Instances.getInstance().getInstance(instanceId); if (instance != null) { return instance.getObject(objectId); } return null; } @Path("/{instanceId}/objects") @POST @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity createObject(@PathParam("instanceId") String instanceId, @FormParam("position") Position3D position, @FormParam("velocity") Velocity3D velocity, @FormParam("angularVelocity") AngularVelocity3D angularVelocity, @FormParam("angle") Angle angle, @FormParam("attribute") Attribute attribute, @FormParam("model") String model) { Instance instance = Instances.getInstance().getInstance(instanceId); IDAddressedEntity ae = instance.createObject(position, velocity, angularVelocity, angle, attribute, model); return new URIAddressedEntity((INSTANCES_URI + "/" + instanceId + "/objects/" + ae.getId()), ae.getBody()); } }