package algoLike.push; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import pushPullRefactor.*; import javax.ws.rs.*; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Form; import javax.ws.rs.core.MediaType; import java.util.*; @Path("/handsA") @Resource("handsA") public class HandsA { private Map.Entry<Boolean, Integer> resultByDrawingB; private Map.Entry<Boolean, Integer> resultByDrawingA; private Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingB; private Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingA; private Client client = ClientBuilder.newClient(); @PushReference("loseA") @Pullable("direct") private String loseA = "/loseA"; @State private List<Map.Entry<Integer, Boolean>> value = new ArrayList<Map.Entry<Integer, Boolean>>(); @Message({}) public void updateResultByDrawingB(@FormParam("result") Map.Entry<Boolean, Integer> resultByDrawingB) throws JsonProcessingException { this.resultByDrawingB = resultByDrawingB; List<Map.Entry<Integer, Boolean>> temp_if17; if (resultByDrawingB.getKey()) { this.value.set(resultByDrawingB.getValue(), new AbstractMap.SimpleEntry<>(this.value.get(resultByDrawingB.getValue()).getKey(), true)); temp_if17 = this.value; } else { temp_if17 = this.value; } value = temp_if17; Form form = new Form(); for (Map.Entry<Integer, Boolean> i : this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); } @Message({}) public void updateResultByDrawingA(Map.Entry<Boolean, Integer> resultByDrawingA, List<Map.Entry<Integer, Boolean>> deck) throws JsonProcessingException { this.resultByDrawingA = resultByDrawingA; List<Map.Entry<Integer, Boolean>> temp_if18; if (resultByDrawingA.getKey()) { this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), false)); this.value.sort(Comparator.comparing(Map.Entry<Integer, Boolean>::getKey)); temp_if18 = this.value; } else { this.value.add(0, new AbstractMap.SimpleEntry<>(deck.get(0).getKey(), true)); this.value.sort(Comparator.comparing(Map.Entry<Integer, Boolean>::getKey)); temp_if18 = this.value; } value = temp_if18; Form form = new Form(); for (Map.Entry<Integer, Boolean> i : this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); } @Message({}) public void updateResultBySelectingB(Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingB) throws JsonProcessingException { this.resultBySelectingB = resultBySelectingB; List<Map.Entry<Integer, Boolean>> temp_if20; if (resultBySelectingB.getKey()) { this.value.set(resultBySelectingB.getValue().getKey(), new AbstractMap.SimpleEntry<>( this.value.get(resultBySelectingB.getValue().getKey()).getKey(), true)); temp_if20 = this.value; } else { temp_if20 = this.value; } value = temp_if20; Form form = new Form(); for (Map.Entry<Integer, Boolean> i : this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); } @Message({}) public void updateResultBySelectingA(Map.Entry<Boolean, Map.Entry<Integer, Integer>> resultBySelectingA) throws JsonProcessingException { this.resultBySelectingA = resultBySelectingA; List<Map.Entry<Integer, Boolean>> temp_if21; if (resultBySelectingA.getKey()) { temp_if21 = this.value; } else { this.value.set(resultBySelectingA.getValue().getValue(), new AbstractMap.SimpleEntry<>( this.value.get(resultBySelectingA.getValue().getValue()).getKey(), true)); temp_if21 = this.value; } value = temp_if21; Form form = new Form(); for (Map.Entry<Integer, Boolean> i : this.value) { form.param("handsA", new ObjectMapper().writeValueAsString(i)); } Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); String result = client.target("http://localhost:8080").path(loseA).request().put(entity, String.class); } @Produces(MediaType.APPLICATION_JSON) @GET @Getter public List<Map.Entry<Integer, Boolean>> getValue() { return value; } }