diff --git a/src/main/java/cactusServer/resources/InstancesRest.java b/src/main/java/cactusServer/resources/InstancesRest.java index af19f0d..3d61e3d 100644 --- a/src/main/java/cactusServer/resources/InstancesRest.java +++ b/src/main/java/cactusServer/resources/InstancesRest.java @@ -27,6 +27,7 @@ import cactusServer.entities.Plain; import cactusServer.entities.Player; import cactusServer.models.Instances; +import net.arnx.jsonic.JSON; @Path("/instances") @RequestScoped @@ -37,56 +38,62 @@ } - - - -// @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); + //@Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public String getInstance(@PathParam("instanceId") String instanceId) { + return JSON.encode(Instances.getInstance().getInstance(instanceId)); + } + + @Path("{instanceId}/areas") + @GET + //@Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public String getArea(@PathParam("areaId") String areaId) { + HashMap areaMap = new HashMap<>(); + return JSON.encode(areaMap); } @Path("/{instanceId}/areas/{areaId}") @GET - @Produces(MediaType.APPLICATION_JSON) - public Area getArea(@PathParam("instanceId") String instanceId, @PathParam("areaId") String areaId) { + //@Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public String getArea(@PathParam("instanceId") String instanceId, @PathParam("areaId") String areaId) { Instance instance = Instances.getInstance().getInstance(instanceId); if (instance != null) { - return instance.getArea(areaId); + return JSON.encode(instance.getArea(areaId)); } return null; } + + @GET - @Produces(MediaType.APPLICATION_JSON) - public HashMap getInstances(){ - return Instances.getInstance().getInstances(); + //@Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public String getInstances(){ + return JSON.encode(Instances.getInstance().getInstances()); } @POST - @Produces(MediaType.APPLICATION_JSON) - public HashMap createInstance(@FormParam("name") String name, @FormParam("stageID") int stageID) { + //@Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public String createInstance(@FormParam("name") String name, @FormParam("stageID") int stageID) { HashMap idMap = Instances.getInstance().createInstance(name, stageID); HashMap uriMap = new HashMap<>(); for (String id : idMap.keySet()) { String uri = (INSTANCES_URI + "/") + id; uriMap.put(uri, idMap.get(id)); } - return uriMap; + return JSON.encode(uriMap); } @Path("/{instanceId}/areas") @POST - @Produces(MediaType.APPLICATION_JSON) - public HashMap createArea(@PathParam("instanceId") String instanceId, @FormParam("name") String name, + //@Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public String createArea(@PathParam("instanceId") String instanceId, @FormParam("name") String name, @FormParam("region") Plain[] region, @FormParam("permissions") HashSet permissions) { Instance instance = Instances.getInstance().getInstance(instanceId); HashMap idMap = instance.createArea(name, region, permissions); @@ -95,24 +102,28 @@ String uri = (INSTANCES_URI + "/" + instanceId + "/areas/") + id; uriMap.put(uri, idMap.get(id)); } - return uriMap; + return JSON.encode(uriMap); } @Path("/{instanceId}") @PUT - @Produces(MediaType.APPLICATION_JSON) - public Instance updateInstance(@PathParam("instanceId") String instanceId, @FormParam("state") Instance.State state) { + //@Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public String updateInstance(@PathParam("instanceId") String instanceId, @FormParam("state") Instance.State state) { Instance instance = Instances.getInstance().getInstance(instanceId); - return instance.update(state); + return JSON.encode(instance.update(state)); } -// @Path("/{instanceId}") -// @PUT -// @Produces(MediaType.APPLICATION_JSON) -// public Instance updateInstance(@FormParam("state") State state) { -// return Instances.getInstance(name, state, stageID) -// } - + + + +// @Path("/test") +// @GET +// @Produces(MediaType.TEXT_PLAIN) +// public String hoge() { +// return "deploy jenkins from tomcat"; +// } + // @DELETE // @Path("/destroyInstance") // @Produces(MediaType.APPLICATION_JSON) @@ -120,14 +131,5 @@ // 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) { - // - // } }