Newer
Older
CactusServer / src / main / java / cactusServer / resources / ObjectsRest.java
t-kazehaya on 12 Jun 2018 1 KB 細かな修正をしました
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;

@Path("/instances/{instanceId}/objects")
public class ObjectsRest {

//	@Path("/{instanceId}/objects/{objectId}")
	@Path("/{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((InstancesRest.INSTANCES_URI + "/" + instanceId + "/objects/" + ae.getId()), ae.getBody());
	} 

}