diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..80b7128 --- /dev/null +++ b/build.gradle @@ -0,0 +1,24 @@ +plugins { + id 'org.springframework.boot' version '2.6.7' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'java' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '11' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-jersey' + implementation 'org.springframework.boot:spring-boot-starter-web' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.jar Binary files differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..41dfb87 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/setting.gradle b/setting.gradle new file mode 100644 index 0000000..01416a4 --- /dev/null +++ b/setting.gradle @@ -0,0 +1 @@ +rootProject.name = 'stockManagement.push' \ No newline at end of file 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/pull/Arrival.java b/src/main/java/stockManagement/pull/Arrival.java new file mode 100644 index 0000000..75c9aab --- /dev/null +++ b/src/main/java/stockManagement/pull/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/pull/Available.java b/src/main/java/stockManagement/pull/Available.java new file mode 100644 index 0000000..2d14b42 --- /dev/null +++ b/src/main/java/stockManagement/pull/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/pull/Handling.java b/src/main/java/stockManagement/pull/Handling.java new file mode 100644 index 0000000..33c1eb3 --- /dev/null +++ b/src/main/java/stockManagement/pull/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/pull/Request.java b/src/main/java/stockManagement/pull/Request.java new file mode 100644 index 0000000..ddb090b --- /dev/null +++ b/src/main/java/stockManagement/pull/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/pull/Shipping.java b/src/main/java/stockManagement/pull/Shipping.java new file mode 100644 index 0000000..f053836 --- /dev/null +++ b/src/main/java/stockManagement/pull/Shipping.java @@ -0,0 +1,42 @@ +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; + private Client client = ClientBuilder.newClient(); + @PUT + @Message("handling") + public void updateHandling(@FormParam("handling") String handling_json) throws JsonProcessingException { + Map.Entry> handling; + { + Map> i = new ObjectMapper().readValue(handling_json, HashMap.class); + handling = 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<>(handling.getKey(), handling.getValue().getKey()); + } + @Produces(MediaType.APPLICATION_JSON) + @GET + @Getter + public Map.Entry getValue() { + return value; + } +} + diff --git a/src/main/java/stockManagement/pull/Shortage.java b/src/main/java/stockManagement/pull/Shortage.java new file mode 100644 index 0000000..38a3616 --- /dev/null +++ b/src/main/java/stockManagement/pull/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/pull/Stock.java b/src/main/java/stockManagement/pull/Stock.java new file mode 100644 index 0000000..ac490cd --- /dev/null +++ b/src/main/java/stockManagement/pull/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