diff --git a/src/main/java/pluginExperiment/JerseyConfig.java b/src/main/java/pluginExperiment/JerseyConfig.java new file mode 100644 index 0000000..f2f6fce --- /dev/null +++ b/src/main/java/pluginExperiment/JerseyConfig.java @@ -0,0 +1,13 @@ +package pluginExperiment; + +import org.glassfish.jersey.server.ResourceConfig; +import org.springframework.stereotype.Component; + +@Component +public class JerseyConfig extends ResourceConfig { + + public JerseyConfig() { + //packages("com.example.JerseyTest"); + packages( JerseyConfig.class.getPackage().getName()+".resources"); + } +} \ No newline at end of file diff --git a/src/main/java/pluginExperiment/Main.java b/src/main/java/pluginExperiment/Main.java new file mode 100644 index 0000000..ee953ce --- /dev/null +++ b/src/main/java/pluginExperiment/Main.java @@ -0,0 +1,14 @@ +package pluginExperiment; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class Main { + public static void main(String[] args) { + SpringApplication.run(Main.class, args); + + } +} diff --git a/src/main/java/pushPullRefactor/Cache.java b/src/main/java/pushPullRefactor/Cache.java new file mode 100644 index 0000000..6c79872 --- /dev/null +++ b/src/main/java/pushPullRefactor/Cache.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +public @interface Cache { + String value(); +} diff --git a/src/main/java/pushPullRefactor/Facade.java b/src/main/java/pushPullRefactor/Facade.java new file mode 100644 index 0000000..640b7c1 --- /dev/null +++ b/src/main/java/pushPullRefactor/Facade.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +public @interface Facade { + +} diff --git a/src/main/java/pushPullRefactor/Getter.java b/src/main/java/pushPullRefactor/Getter.java new file mode 100644 index 0000000..71729bd --- /dev/null +++ b/src/main/java/pushPullRefactor/Getter.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +public @interface Getter { + +} diff --git a/src/main/java/pushPullRefactor/Init.java b/src/main/java/pushPullRefactor/Init.java new file mode 100644 index 0000000..a927644 --- /dev/null +++ b/src/main/java/pushPullRefactor/Init.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.CONSTRUCTOR) +public @interface Init { + +} diff --git a/src/main/java/pushPullRefactor/Message.java b/src/main/java/pushPullRefactor/Message.java new file mode 100644 index 0000000..48b3a52 --- /dev/null +++ b/src/main/java/pushPullRefactor/Message.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +public @interface Message { + String[] value(); +} diff --git a/src/main/java/pushPullRefactor/Param.java b/src/main/java/pushPullRefactor/Param.java new file mode 100644 index 0000000..821a13c --- /dev/null +++ b/src/main/java/pushPullRefactor/Param.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.PARAMETER) +public @interface Param { + String value(); +} diff --git a/src/main/java/pushPullRefactor/PullReference.java b/src/main/java/pushPullRefactor/PullReference.java new file mode 100644 index 0000000..825792e --- /dev/null +++ b/src/main/java/pushPullRefactor/PullReference.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +public @interface PullReference { + String value(); +} diff --git a/src/main/java/pushPullRefactor/Pullable.java b/src/main/java/pushPullRefactor/Pullable.java new file mode 100644 index 0000000..4f6b722 --- /dev/null +++ b/src/main/java/pushPullRefactor/Pullable.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +public @interface Pullable { + String value(); +} diff --git a/src/main/java/pushPullRefactor/PushReference.java b/src/main/java/pushPullRefactor/PushReference.java new file mode 100644 index 0000000..6049cfb --- /dev/null +++ b/src/main/java/pushPullRefactor/PushReference.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +public @interface PushReference { + String value(); +} diff --git a/src/main/java/pushPullRefactor/Pushable.java b/src/main/java/pushPullRefactor/Pushable.java new file mode 100644 index 0000000..9d70d36 --- /dev/null +++ b/src/main/java/pushPullRefactor/Pushable.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +public @interface Pushable { + +} diff --git a/src/main/java/pushPullRefactor/Resource.java b/src/main/java/pushPullRefactor/Resource.java new file mode 100644 index 0000000..6e82e30 --- /dev/null +++ b/src/main/java/pushPullRefactor/Resource.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +public @interface Resource { + String value(); +} diff --git a/src/main/java/pushPullRefactor/State.java b/src/main/java/pushPullRefactor/State.java new file mode 100644 index 0000000..576ae8f --- /dev/null +++ b/src/main/java/pushPullRefactor/State.java @@ -0,0 +1,9 @@ +package pushPullRefactor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +public @interface State { + +} diff --git a/src/main/java/stockManagement/push/Arrival.java b/src/main/java/stockManagement/push/Arrival.java new file mode 100644 index 0000000..75c9aab --- /dev/null +++ b/src/main/java/stockManagement/push/Arrival.java @@ -0,0 +1,44 @@ +package stockManagement.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 pushPullRefactor.Getter; +import pushPullRefactor.Message; +import pushPullRefactor.Resource; +import pushPullRefactor.State; + + +import com.fasterxml.jackson.core.JsonProcessingException; + +@Path("/arrival") +@Resource("arrival") +@Component +public class Arrival { + private Client client = ClientBuilder.newClient(); + @State + private Map.Entry value; + @PUT + @Message({}) + public void arrive(@FormParam("num") int num, @FormParam("item") String item) throws JsonProcessingException { + this.value = new AbstractMap.SimpleEntry<>(item, num); + Map stock_json = client.target("http://localhost:8080").path("/stock").request().get(HashMap.class); + Map stock = new HashMap<>(); + stock = stock_json; + Form form = new Form(); + form.param("arrival", new ObjectMapper().writeValueAsString(this.value)); + form.param("stock", new ObjectMapper().writeValueAsString(stock)); + Entity
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/available").request().put(entity, String.class); + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/stockManagement/push/Available.java b/src/main/java/stockManagement/push/Available.java new file mode 100644 index 0000000..2d14b42 --- /dev/null +++ b/src/main/java/stockManagement/push/Available.java @@ -0,0 +1,61 @@ +package stockManagement.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("/available") +@Component +@Resource("available") +public class Available { + private Client client = ClientBuilder.newClient(); + @State + private Map.Entry value; + @PUT + @Message({"arrival", "stock"}) + public void updateArrival(@FormParam("arrival") String arrival_json, @FormParam("stock") String stock_json) throws JsonProcessingException { + Map shortage_json = client.target("http://localhost:8080").path("/shortage").request().get(HashMap.class); + Map shortage = new HashMap<>(); + shortage = shortage_json; + Map stock = new HashMap<>(); + { + Map i = new ObjectMapper().readValue(stock_json, HashMap.class); + stock = i; + } + Map.Entry arrival; + { + Map i = new ObjectMapper().readValue(arrival_json, HashMap.class); + arrival = new AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), i.entrySet().iterator().next().getValue()); + } + int temp_get20; + if (stock.get(arrival.getKey()) != null) { + temp_get20 = stock.get(arrival.getKey()); + } else { + temp_get20 = 0; + } + this.value = new AbstractMap.SimpleEntry<>(arrival.getKey(), (arrival.getValue()+temp_get20)); + Form form = new Form(); + form.param("available", new ObjectMapper().writeValueAsString(this.value)); + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/shortage/available").request().post(entity, String.class); + form = new Form(); + form.param("available", new ObjectMapper().writeValueAsString(this.value)); + form.param("shortage", new ObjectMapper().writeValueAsString(shortage)); + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/deriver/available").request().put(entity, String.class); + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/stockManagement/push/Handling.java b/src/main/java/stockManagement/push/Handling.java new file mode 100644 index 0000000..33c1eb3 --- /dev/null +++ b/src/main/java/stockManagement/push/Handling.java @@ -0,0 +1,137 @@ +package stockManagement.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 pushPullRefactor.*; + +import com.fasterxml.jackson.core.JsonProcessingException; + +@Path("/handling") +@Component +@Resource("handling") +public class Handling { + private Client client = ClientBuilder.newClient(); + @Cache("available") + private Map.Entry available; + @Cache("request") + private Map.Entry request; + @PushReference("shipping") + @Pullable("direct") + private String shipping = "/shipping"; + + @PushReference("stock") + private String stock = "/stock"; + + @State + private Map.Entry> value; + @Path("/available") + @PUT + @Message({"available", "shortage"}) + public void updateAvailable(@FormParam("available") String available_json, @FormParam("shortage") String shortage_json) throws JsonProcessingException { + Map shortage = new HashMap<>(); + { + Map i = new ObjectMapper().readValue(shortage_json, HashMap.class); + shortage = i; + } + Map.Entry available; + { + Map i = new ObjectMapper().readValue(available_json, HashMap.class); + available = new AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), i.entrySet().iterator().next().getValue()); + } + this.available = available; + Map.Entry> temp_if6; + int temp_get14; + if (shortage.get(available.getKey()) != null) { + temp_get14 = shortage.get(available.getKey()); + } else { + temp_get14 = 0; + } + if ((available.getValue()>=temp_get14)) { + int temp_get15; + if (shortage.get(available.getKey()) != null) { + temp_get15 = shortage.get(available.getKey()); + } else { + temp_get15 = 0; + } + int temp_get16; + if (shortage.get(available.getKey()) != null) { + temp_get16 = shortage.get(available.getKey()); + } else { + temp_get16 = 0; + } + temp_if6 = new AbstractMap.SimpleEntry<>(available.getKey(), new AbstractMap.SimpleEntry<>(temp_get15, (available.getValue()-temp_get16))); + } else { + temp_if6 = new AbstractMap.SimpleEntry<>(available.getKey(), new AbstractMap.SimpleEntry<>(0, available.getValue())); + } + this.value = temp_if6; + Form form = new Form(); + form.param("handling", new ObjectMapper().writeValueAsString(this.value)); + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path(shipping).request().put(entity, String.class); + + form = new Form(); + form.param("handling", new ObjectMapper().writeValueAsString(this.value)); + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path(stock).request().post(entity, String.class); + } + @Path("/request") + @PUT + @Message({"request", "stock"}) + public void updateRequest(@FormParam("request") String request_json, @FormParam("stock") String stock_json) throws JsonProcessingException { + Map stock = new HashMap<>(); + { + Map i = new ObjectMapper().readValue(stock_json, HashMap.class); + stock = i; + } + Map.Entry request; + { + Map i = new ObjectMapper().readValue(request_json, HashMap.class); + request = new AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), i.entrySet().iterator().next().getValue()); + } + this.request = request; + Map.Entry> temp_if7; + int temp_get17; + if (stock.get(request.getKey()) != null) { + temp_get17 = stock.get(request.getKey()); + } else { + temp_get17 = 0; + } + if ((temp_get17>=request.getValue())) { + int temp_get18; + if (stock.get(request.getKey()) != null) { + temp_get18 = stock.get(request.getKey()); + } else { + temp_get18 = 0; + } + temp_if7 = new AbstractMap.SimpleEntry<>(request.getKey(), new AbstractMap.SimpleEntry<>(request.getValue(), (temp_get18-request.getValue()))); + } else { + int temp_get19; + if (stock.get(request.getKey()) != null) { + temp_get19 = stock.get(request.getKey()); + } else { + temp_get19 = 0; + } + temp_if7 = new AbstractMap.SimpleEntry<>(request.getKey(), new AbstractMap.SimpleEntry<>(0, temp_get19)); + } + this.value = temp_if7; + Form form = new Form(); + form.param("handling", new ObjectMapper().writeValueAsString(this.value)); + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path(this.stock).request().post(entity, String.class); + form = new Form(); + form.param("handling", new ObjectMapper().writeValueAsString(this.value)); + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path(shipping).request().put(entity, String.class); + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry> getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/stockManagement/push/Request.java b/src/main/java/stockManagement/push/Request.java new file mode 100644 index 0000000..ddb090b --- /dev/null +++ b/src/main/java/stockManagement/push/Request.java @@ -0,0 +1,49 @@ +package stockManagement.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 pushPullRefactor.Getter; +import pushPullRefactor.Message; +import pushPullRefactor.Resource; +import pushPullRefactor.State; + +import com.fasterxml.jackson.core.JsonProcessingException; + + +@Path("/request") +@Resource("request") +@Component +public class Request { + private Client client = ClientBuilder.newClient(); + @State + private Map.Entry value; + @PUT + @Message({}) + public void req(@FormParam("num") int num, @FormParam("item") String item) throws JsonProcessingException { + this.value = new AbstractMap.SimpleEntry<>(item, num); + Map stock_json = client.target("http://localhost:8080").path("/stock").request().get(HashMap.class); + Map stock = new HashMap<>(); + stock = stock_json; + Form form = new Form(); + form.param("request", new ObjectMapper().writeValueAsString(this.value)); + form.param("stock", new ObjectMapper().writeValueAsString(stock)); + Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/shortage/request").request().post(entity, String.class); + form = new Form(); + form.param("request", new ObjectMapper().writeValueAsString(this.value)); + form.param("stock", new ObjectMapper().writeValueAsString(stock)); + entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + result = client.target("http://localhost:8080").path("/deriver/request").request().put(entity, String.class); + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/stockManagement/push/Shipping.java b/src/main/java/stockManagement/push/Shipping.java new file mode 100644 index 0000000..e7ab527 --- /dev/null +++ b/src/main/java/stockManagement/push/Shipping.java @@ -0,0 +1,41 @@ +package stockManagement.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 pushPullRefactor.Getter; +import pushPullRefactor.Message; +import pushPullRefactor.Resource; +import pushPullRefactor.State; + +import com.fasterxml.jackson.core.JsonProcessingException; + +@Path("/shipping") +@Component +@Resource("shipping") +public class Shipping { + @State + private Map.Entry value; + @PUT + @Message("deriver") + public void updateDeriver(@FormParam("deriver") String deriver_json) throws JsonProcessingException { + Map.Entry> deriver; + { + Map> i = new ObjectMapper().readValue(deriver_json, HashMap.class); + deriver = new AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), + new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); + } + this.value = new AbstractMap.SimpleEntry<>(deriver.getKey(), deriver.getValue().getKey()); + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry getValue() { + return value; + } +} + diff --git a/src/main/java/stockManagement/push/Shortage.java b/src/main/java/stockManagement/push/Shortage.java new file mode 100644 index 0000000..38a3616 --- /dev/null +++ b/src/main/java/stockManagement/push/Shortage.java @@ -0,0 +1,91 @@ +package stockManagement.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 pushPullRefactor.*; + +import com.fasterxml.jackson.core.JsonProcessingException; + +@Path("/shortage") +@Resource("shortage") +@Component +public class Shortage { + @Cache("available") + private Map.Entry available; + @Cache("request") + private Map.Entry request; + @State + private Map value = new HashMap(); + @Path("/available") + @POST + @Message({}) + public void updateAvailable(@FormParam("available") String available_json) throws JsonProcessingException { + Map.Entry available; + { + Map i = new ObjectMapper().readValue(available_json, HashMap.class); + available = new AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), i.entrySet().iterator().next().getValue()); + } + this.available = available; + Map temp_if24; + int temp_get21; + if (this.value.get(available.getKey()) != null) { + temp_get21 = this.value.get(available.getKey()); + } else { + temp_get21 = 0; + } + if ((available.getValue()>=temp_get21)) { + this.value.put(available.getKey(),0); + temp_if24 = this.value; + } else { + temp_if24 = this.value; + } + this.value = temp_if24; + } + @Path("/request") + @POST + @Message({"request", "stock"}) + public void updateRequest(@FormParam("request") String request_json, @FormParam("stock") String stock_json) throws JsonProcessingException { + Map stock = new HashMap<>(); + { + Map i = new ObjectMapper().readValue(stock_json, HashMap.class); + stock = i; + } + Map.Entry request; + { + Map i = new ObjectMapper().readValue(request_json, HashMap.class); + request = new AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), i.entrySet().iterator().next().getValue()); + } + this.request = request; + Map temp_if26; + int temp_get25; + if (stock.get(request.getKey()) != null) { + temp_get25 = stock.get(request.getKey()); + } else { + temp_get25 = 0; + } + if ((temp_get25>=request.getValue())) { + temp_if26 = this.value; + } else { + int temp_get26; + if (this.value.get(request.getKey()) != null) { + temp_get26 = this.value.get(request.getKey()); + } else { + temp_get26 = 0; + } + this.value.put(request.getKey(),(temp_get26+request.getValue())); + temp_if26 = this.value; + } + this.value = temp_if26; + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/stockManagement/push/Stock.java b/src/main/java/stockManagement/push/Stock.java new file mode 100644 index 0000000..ac490cd --- /dev/null +++ b/src/main/java/stockManagement/push/Stock.java @@ -0,0 +1,36 @@ +package stockManagement.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 pushPullRefactor.*; + +import com.fasterxml.jackson.core.JsonProcessingException; + +@Path("/stock") +@Resource("stock") +@Component +public class Stock { + @State + private Map value = new HashMap(); + @POST + @Message("deriver") + public void updateDeriver(@FormParam("deriver") String deriver_json) throws JsonProcessingException { + Map.Entry> deriver; + { + Map> i = new ObjectMapper().readValue(deriver_json, HashMap.class); + deriver = new AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), new AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next().getValue().entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue().entrySet().iterator().next().getValue())); + } + this.value.put(deriver.getKey(),deriver.getValue().getValue()); + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/resources/application.properties