diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee2feda..8a7574b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: maven:3-jdk-8 build: - script: "mvn clean package --settings .gitlab/settings.xml" + script: "mvn clean install deploy site:deploy --settings .gitlab/settings.xml" artifacts: name: "Commons" paths: diff --git a/.gitlab/settings.xml b/.gitlab/settings.xml index 1d1636c..8093b52 100644 --- a/.gitlab/settings.xml +++ b/.gitlab/settings.xml @@ -3,7 +3,7 @@ univentoEU download - PLCtNT3GEM43bvBc2mRvQMsYe!0JtB + ${env.password} diff --git a/Commons.iml b/Commons.iml index d2bd4a9..6674208 100644 --- a/Commons.iml +++ b/Commons.iml @@ -55,5 +55,6 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 37f5f10..7b3a476 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,79 @@ 1.0-SNAPSHOT univento.eu Common Code + 2016 + Das Commons Modul stellt alles zur Verfügung was von allen anderen Modulen benötigt wird, wie etwa Datenbank Zugriffe + https://development.univento.eu/docs/Commons + + + univentoEU + https://univento.eu + + + + + joethei + Johannes Theiner + joethei@univento.eu + https://joethei.de + univentoEU + + architect + developer + + Europe/Berlin + + https://de.gravatar.com/userimage/65052389/84435a829d76e6b6c48d67cdd463c6ab.png?size=300 + + + + + + gitlab + https://development.univento.eu/issues/Commons + + + + gitlab + https://development.univento.eu/ci/Commons + + + + + univentoEU + https://development.univento.eu/maven/repositories/univento + + + univento.commons + univento Commons + sftp://development.univento.eu/doc/Commons + + + + org.apache.maven.plugins + maven-site-plugin + 3.6 + + + org.apache.maven.enforcer + enforcer + + + validate + + enforce + + + + + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -45,13 +115,6 @@ - - - univentoEU - http://play.univento.eu:8081/repository/univento/ - - - org.projectlombok @@ -139,5 +202,10 @@ 4.12 test + + org.gitlab + java-gitlab-api + 1.2.7 + \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/Commons.java b/src/main/java/eu/univento/commons/Commons.java index 73a3029..a81ec5a 100644 --- a/src/main/java/eu/univento/commons/Commons.java +++ b/src/main/java/eu/univento/commons/Commons.java @@ -9,7 +9,7 @@ import lombok.Getter; /** * @author joethei - * @version 1.0 + * @version 1.1 */ @Getter diff --git a/src/main/java/eu/univento/commons/event/MessageEvent.java b/src/main/java/eu/univento/commons/event/MessageEvent.java new file mode 100644 index 0000000..23d8952 --- /dev/null +++ b/src/main/java/eu/univento/commons/event/MessageEvent.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.commons.event; + +/** + * @author joethei + * @version 0.1 + */ +public interface MessageEvent { + + void onMessageReceived(String queue, String message); + void onMessageSend(String queue, String message); +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/messaging/MessageHandler.java b/src/main/java/eu/univento/commons/messaging/MessageHandler.java new file mode 100644 index 0000000..7aab4a8 --- /dev/null +++ b/src/main/java/eu/univento/commons/messaging/MessageHandler.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.commons.messaging; + +import eu.univento.commons.Commons; +import eu.univento.commons.event.MessageEvent; +import io.vertx.core.json.JsonObject; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author joethei + * @version 1.0 + */ +public class MessageHandler { + + private static List events = new ArrayList<>(); + + public static void registerListener(String queue, MessageEvent event) { + events.add(event); + Commons.getCommons().getMessagingManager().getRabbitMQ().getClient().basicConsume(queue, "univento." + queue, res -> { + if(!res.succeeded()) res.cause().printStackTrace(); + }); + + Commons.getCommons().getVertx().eventBus().consumer(queue, msg -> { + JsonObject json = (JsonObject) msg.body(); + event.onMessageReceived(queue, json.getString("body")); + }); + } + + public static void sendMessage(String queue, String message) { + Commons.getCommons().getMessagingManager().getRabbitMQ().getClient().basicPublish("", queue, new JsonObject().put("body", message), res -> { + if(res.succeeded()) { + for(MessageEvent event : events) { + event.onMessageSend(queue, message); + } + }else res.cause().printStackTrace(); + }); + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/messaging/MessagingManager.java b/src/main/java/eu/univento/commons/messaging/MessagingManager.java index 274d4c2..9c3bb20 100644 --- a/src/main/java/eu/univento/commons/messaging/MessagingManager.java +++ b/src/main/java/eu/univento/commons/messaging/MessagingManager.java @@ -11,7 +11,7 @@ import lombok.Getter; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class MessagingManager { diff --git a/src/main/java/eu/univento/commons/messaging/RabbitMQ.java b/src/main/java/eu/univento/commons/messaging/RabbitMQ.java index 9cb191f..a7eebd4 100644 --- a/src/main/java/eu/univento/commons/messaging/RabbitMQ.java +++ b/src/main/java/eu/univento/commons/messaging/RabbitMQ.java @@ -12,7 +12,7 @@ import lombok.Getter; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class RabbitMQ { diff --git a/src/main/java/eu/univento/commons/utils/Files.java b/src/main/java/eu/univento/commons/utils/Files.java new file mode 100644 index 0000000..d31c769 --- /dev/null +++ b/src/main/java/eu/univento/commons/utils/Files.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 univento.eu - All rights reserved + * You are not allowed to use, distribute or modify this code + */ + +package eu.univento.commons.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** + * @author joethei + * @version 1.0 + */ +public class Files { + + public static void unzip(File zipFile, File folder) { + byte[] buffer = new byte[1024]; + + try { + if (!folder.exists()) { + folder.mkdir(); + } + + ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); + ZipEntry entry; + while ((entry = zis.getNextEntry()) != null) { + + String fileName = entry.getName(); + File newFile = new File(folder + File.separator + fileName); + + new File(newFile.getParent()).mkdirs(); + + FileOutputStream fos = new FileOutputStream(newFile); + + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + + fos.close(); + } + + zis.closeEntry(); + zis.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 8d027a6..24a1abe 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -25,4 +25,6 @@ RabbitMQ.Host = vps.joethei.de RabbitMQ.Port = 5672 RabbitMQ.Username = univento RabbitMQ.Password = tYRHXZNm4exW@QB6rMm72pHnafrT8wQ5ebGPEetJDBVU2mj25kTVXuYeQavb#EYr -RabbitMQ.VirtualHost = univento \ No newline at end of file +RabbitMQ.VirtualHost = univento +Gitlab.Host = https://gitlab.com/ +Gitlab.token = add token here \ No newline at end of file