package algoLike.push; import java.util.*; import javax.ws.rs.*; import javax.ws.rs.client.*; import javax.ws.rs.core.*; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; import pushPullRefactor.Getter; import pushPullRefactor.Message; import pushPullRefactor.Resource; import pushPullRefactor.State; @Path("/resultByDrawingA") @Component @Resource("resultByDrawingA") public class ResultByDrawingA { private Client client = ClientBuilder.newClient(); @State private Map.Entry<Boolean, Integer> value; @PUT @Message({}) public void drawAndAttackA(@FormParam("g") int g, @FormParam("b") List<Map.Entry<Integer, Boolean>> b, @FormParam("t") int t) throws JsonProcessingException { this.value = new AbstractMap.SimpleEntry<>((b.get(t).getKey()==g), t); List<Map<Integer, Boolean>> deck_json = client.target("http://localhost:8080").path("/deck").request().get(ArrayList.class); List<Map.Entry<Integer, Boolean>> deck = new ArrayList<>(); for (Map<Integer, Boolean> i: deck_json) { deck.add(i.entrySet().iterator().next()); } Form form = new Form(); form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/deck/resultByDrawingA").request().post(entity, String.class); form = new Form(); form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); for (Map.Entry<Integer, Boolean> i: deck) { form.param("deck", new ObjectMapper().writeValueAsString(i)); } entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); result = client.target("http://localhost:8080").path("/handsB/resultByDrawingA").request().post(entity, String.class); form = new Form(); form.param("resultByDrawingA", new ObjectMapper().writeValueAsString(this.value)); for (Map.Entry<Integer, Boolean> i: deck) { form.param("deck", new ObjectMapper().writeValueAsString(i)); } entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); result = client.target("http://localhost:8080").path("/handsA/resultByDrawingA").request().post(entity, String.class); } @Produces(MediaType.APPLICATION_JSON) @GET @Getter public Map.Entry<Boolean, Integer> getValue() { return value; } }