Newer
Older
algoLike.pull / src / main / java / algoLike / pull / ResultBySelectingA.java
Shinji on 25 Jan 2023 1 KB pullに変更
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("/resultBySelectingA")
@Component
@Resource("resultBySelectingA")
public class ResultBySelectingA {
	private Client client = ClientBuilder.newClient();
	@State
	private Map.Entry<Boolean, Map.Entry<Integer, Integer>> value;
	@PUT
	@Message({})
	public void selectAndAttackA(@FormParam("t") int t, @FormParam("g") int g, @FormParam("b") List<Map.Entry<Integer, Boolean>> b, @FormParam("a") int a) throws JsonProcessingException {
		this.value = new AbstractMap.SimpleEntry<>((b.get(t).getKey()==g),  new AbstractMap.SimpleEntry<>(t, a));
		Form form = new Form();
		form.param("resultBySelectingA", new ObjectMapper().writeValueAsString(this.value));
		Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED);
		String result = client.target("http://localhost:8080").path("/handsA/resultBySelectingA").request().post(entity, String.class);
		form = new Form();
		form.param("resultBySelectingA", new ObjectMapper().writeValueAsString(this.value));
		entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED);
		result = client.target("http://localhost:8080").path("/handsB/resultBySelectingA").request().post(entity, String.class);
	}
	@Produces(MediaType.APPLICATION_JSON)
	@GET
	@Getter
	public Map.Entry<Boolean, Map.Entry<Integer, Integer>> getValue() {
		return value;
	}
}