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("/resultByDrawingB") @Component @Resource("resultByDrawingB") public class ResultByDrawingB { private Client client = ClientBuilder.newClient(); @State private Map.Entry<Boolean, Integer> value; @PUT @Message({}) public void drawAndAttackB(@FormParam("g") int g, @FormParam("a") List<Map.Entry<Integer, Boolean>> a, @FormParam("t") int t) throws JsonProcessingException { this.value = new AbstractMap.SimpleEntry<>((a.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("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); for (Map.Entry<Integer, Boolean> i: deck) { form.param("deck", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path("/handsB/resultByDrawingB").request().post(entity, String.class); form = new Form(); form.param("resultByDrawingB", new ObjectMapper().writeValueAsString(this.value)); entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); result = client.target("http://localhost:8080").path("/deck/resultByDrawingB").request().post(entity, String.class); form = new Form(); form.param("resultByDrawingB", 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/resultByDrawingB").request().post(entity, String.class); } @Produces(MediaType.APPLICATION_JSON) @GET @Getter public Map.Entry<Boolean, Integer> getValue() { return value; } }