diff --git a/gemeinsamforschen/pom.xml b/gemeinsamforschen/pom.xml index 34de8955c326892757f510bcbfbb83dce4db8ab4..1fa9a00521ad94d5e557bf69eb9c35cbc5ec409f 100644 --- a/gemeinsamforschen/pom.xml +++ b/gemeinsamforschen/pom.xml @@ -8,6 +8,18 @@ <artifactId>gemeinsamforschen</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + </plugins> + </build> <properties> <org.springframework.version>3.2.4.RELEASE</org.springframework.version> diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/IMunschkin.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/IMunschkin.java new file mode 100644 index 0000000000000000000000000000000000000000..05776056fccc41d9702fe0e16d1b44cf3b755efc --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/IMunschkin.java @@ -0,0 +1,14 @@ +package unipotsdam.gf.munchkin; + +import unipotsdam.gf.munchkin.model.Munschkin; + +import javax.ws.rs.PathParam; + +/** + * Created by dehne on 25.04.2018. + */ +public interface IMunschkin { + + Munschkin getMunschkin (int id); + void letMunchKinFight(Munschkin otherMunchkin); +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/controller/MunschkinLoader.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/controller/MunchkinImpl.java similarity index 84% rename from gemeinsamforschen/src/main/java/unipotsdam/gf/controller/MunschkinLoader.java rename to gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/controller/MunchkinImpl.java index ed7f0c2216753a391b1954343e2c26a690988bfc..65a0f2ba6b538e656e3d54e4fd06e7aea224ee91 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/controller/MunschkinLoader.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/controller/MunchkinImpl.java @@ -1,13 +1,14 @@ -package unipotsdam.gf.controller; +package unipotsdam.gf.munchkin.controller; -import unipotsdam.gf.model.Munschkin; +import unipotsdam.gf.munchkin.IMunschkin; +import unipotsdam.gf.munchkin.model.Munschkin; import java.sql.*; /** * Created by dehne on 24.04.2018. */ -public class MunschkinLoader { +public class MunchkinImpl implements IMunschkin { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost"; @@ -17,8 +18,9 @@ public class MunschkinLoader { static final String PASS = "voyager2"; // Es gibt natürlich auch libraries, die den Datenbankzugriff einfacher gestalten. Ziel soll sein, dass alle - // die Basics können. - public Munschkin loadMunschkin(int id) { + // die Basics können. Es ist auch sinnvoll, die Datenbankzugriffe in eine eigene Klasse auszulagern!! + @Override + public Munschkin getMunschkin(int id) { Munschkin munschkin = new Munschkin(); @@ -80,4 +82,9 @@ public class MunschkinLoader { return munschkin; } + + @Override + public void letMunchKinFight(Munschkin otherMunchkin) { + // TODO was euer Algorithmus sonst noch so kann + } } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/model/Munschkin.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/model/Munschkin.java similarity index 98% rename from gemeinsamforschen/src/main/java/unipotsdam/gf/model/Munschkin.java rename to gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/model/Munschkin.java index e68d85c166f61f8eec469f5e62ed0e1375532f8d..68a3198834259f98aa23d3430f6ca05e22c42d31 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/model/Munschkin.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/model/Munschkin.java @@ -1,4 +1,4 @@ -package unipotsdam.gf.model; +package unipotsdam.gf.munchkin.model; import javax.xml.bind.annotation.XmlRootElement; diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/service/RestyMunschkin.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/service/RestyMunschkin.java similarity index 64% rename from gemeinsamforschen/src/main/java/unipotsdam/gf/service/RestyMunschkin.java rename to gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/service/RestyMunschkin.java index fbe928715ff45f4a71336674566d75030f0d483d..8ae8d6620112334f6ec6bbac641d8d890755e3a2 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/service/RestyMunschkin.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/munchkin/service/RestyMunschkin.java @@ -1,11 +1,12 @@ -package unipotsdam.gf.service; +package unipotsdam.gf.munchkin.service; /** * Created by dehne on 24.04.2018. */ -import unipotsdam.gf.controller.MunschkinLoader; -import unipotsdam.gf.model.Munschkin; +import unipotsdam.gf.munchkin.IMunschkin; +import unipotsdam.gf.munchkin.controller.MunchkinImpl; +import unipotsdam.gf.munchkin.model.Munschkin; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -21,8 +22,8 @@ public class RestyMunschkin { @Produces(MediaType.TEXT_HTML) @Path("/hello/{id}") public String sayHtmlHello(@PathParam("id") String id) { - MunschkinLoader munschkinLoader = new MunschkinLoader(); - Munschkin munschkin = munschkinLoader.loadMunschkin(Integer.parseInt(id)); + IMunschkin munchkinImpl = new MunchkinImpl(); + Munschkin munschkin = munchkinImpl.getMunschkin(Integer.parseInt(id)); return "<html> " + "<title>" + "Hello Munschkin" + "</title>" + "<body><h1>" + munschkin .toString() + "</body></h1>" + "</html> "; } @@ -32,8 +33,8 @@ public class RestyMunschkin { @Produces(MediaType.APPLICATION_XML) @Path("/munschkin/{id}") public Munschkin getMunschkin(@PathParam("id") String id) { - MunschkinLoader munschkinLoader = new MunschkinLoader(); - Munschkin munschkin = munschkinLoader.loadMunschkin(Integer.parseInt(id)); + IMunschkin munchkinImpl = new MunchkinImpl(); + Munschkin munschkin = munchkinImpl.getMunschkin(Integer.parseInt(id)); return munschkin; } diff --git a/gemeinsamforschen/src/test/java/MunschkinLoaderTest.java b/gemeinsamforschen/src/test/java/MunschkinLoaderTest.java index e4bb28aa0f8e74bd4774a6dece0ece637eeacc43..41934e1132b4223c48ed60990b8f2eb000141ba3 100644 --- a/gemeinsamforschen/src/test/java/MunschkinLoaderTest.java +++ b/gemeinsamforschen/src/test/java/MunschkinLoaderTest.java @@ -1,5 +1,6 @@ -import unipotsdam.gf.controller.MunschkinLoader; -import unipotsdam.gf.model.Munschkin; +import unipotsdam.gf.munchkin.IMunschkin; +import unipotsdam.gf.munchkin.controller.MunchkinImpl; +import unipotsdam.gf.munchkin.model.Munschkin; import org.junit.Test; /** @@ -8,8 +9,11 @@ import org.junit.Test; public class MunschkinLoaderTest { @Test public void testMunschKinLoader() { - MunschkinLoader m = new MunschkinLoader(); - Munschkin loadedM = m.loadMunschkin(1); + IMunschkin m = new MunchkinImpl(); + // Nützlich weil: IMunschkin m2 = new HendriksMunchkinImpl(); + + // ab hier ist es dem Code egal, welche Implementation hinter dem Interface steht + Munschkin loadedM = m.getMunschkin(1); assert loadedM != null; System.out.print(loadedM.toString()); }