package cactusServer.resources; import java.util.HashSet; import java.util.Map; import javax.ws.rs.DELETE; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import cactusServer.entities.AddressedEntity; import cactusServer.entities.Angle; import cactusServer.entities.Area; import cactusServer.entities.Area.Allowed; import cactusServer.entities.IDAddressedEntity; import cactusServer.entities.Instance; import cactusServer.entities.Object.Attribute; import cactusServer.entities.ObjectModel; import cactusServer.entities.Plain; import cactusServer.entities.StageModel; import cactusServer.entities.URIAddressedEntity; import cactusServer.models.Instances; import framework.model3D.Position3D; import framework.physics.AngularVelocity3D; import framework.physics.Velocity3D; @Path("/instances") public class InstancesRest { public static final String INSTANCES_URI = "CactusServer/instances"; public InstancesRest() { } // @Path("/test") // @GET // @Produces(MediaType.TEXT_PLAIN) // public String hoge() { // return "deploy jenkins from tomcat"; // } @Path("/{instanceId}") @GET @Produces(MediaType.APPLICATION_JSON) public Instance getInstance(@PathParam("instanceId") String instanceId) { return Instances.getInstance().getInstance(instanceId); } @Path("/{instanceId}/areas/{areaId}") @GET @Produces(MediaType.APPLICATION_JSON) public Area getArea(@PathParam("instanceId") String instanceId, @PathParam("areaId") String areaId) { Instance instance = Instances.getInstance().getInstance(instanceId); if (instance != null) { return instance.getArea(areaId); } return null; } @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; } // @GET // @Path("/characters") // @Produces(MediaType.APPLICATION_JSON) // public Instance getCharacter(@QueryParam("AccountUniqueId") String AccountUniqueId) { // return Instances.getInstance().getCharacter(AccountUniqueId); // } // // @POST // @Path("/{createCharacter}") // @Produces(MediaType.APPLICATION_JSON) // public Instance createCharacter(@QueryParam("characterUniqueId") String characterUniqueId) { // return Instances.getInstance().createCharacter(characterUniqueId); // } // @POST @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity create(@FormParam("name") String name, @FormParam("state") Instance.State state, @FormParam("stageModel") StageModel stageModel) { IDAddressedEntity ae = Instances.getInstance().createInstance(name, state, stageModel); return new URIAddressedEntity((INSTANCES_URI + "/" + ae.getId()), ae.getBody()); } @Path("/{instanceId}/areas") @POST @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity create(@PathParam("instanceId") String instanceId, @FormParam("name") String name, @FormParam("region") Plain[] region, @FormParam("permissions") HashSet<Allowed> permissions) { Instance instance = Instances.getInstance().getInstance(instanceId); IDAddressedEntity ae = instance.createArea(name, region, permissions); return new URIAddressedEntity((INSTANCES_URI + "/" + instanceId + "/areas/" + ae.getId()), ae.getBody()); } @Path("/{instanceId}/objects") @POST @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity create(@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") ObjectModel 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()); } // @DELETE // @Path("/destroyInstance") // @Produces(MediaType.APPLICATION_JSON) // public Instance destroy(@QueryParam("instanceId") String instanceId) { // return Instances.getInstance().destroyInstance(instanceId); // } // // @Path("/{instanceId}") // @PUT // public Instance putInstance(@PathParam("InstanceId") String instanceId, @FormParam("areaId") String areaId, // @FormParam("objectId") String objectId, @FormParam("characterId") String characterId) { // // } }