Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

WIP: Create Chat MicroService #2

Open
wants to merge 42 commits into
base: experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1e5da4f
Added Channel Object (#1)
MarcelCoding Oct 15, 2019
be63c75
Added ChannelHandler Class (#1)
MarcelCoding Oct 15, 2019
18d35f5
Added Channel ChannelEndpoints (#1)
MarcelCoding Oct 15, 2019
9b3a203
Added User Notifications for Leave and Join Events. (#1)
MarcelCoding Oct 15, 2019
62a7888
Added Hardcoded Channel "global". (#1)
MarcelCoding Oct 15, 2019
c9be939
Added toString() when UUID is added to JSON. (#1)
MarcelCoding Oct 15, 2019
5e36c2a
Fixed Dependencies (#1)
MarcelCoding Oct 15, 2019
0781f14
Fixed some issues (#1)
JannikEmmerich Oct 16, 2019
44be490
Removed unused dependency (#1)
JannikEmmerich Oct 16, 2019
be7e97d
Added Message System.
MarcelCoding Oct 28, 2019
4dbcf1d
Removed unused stuff. (#1)
MarcelCoding Oct 29, 2019
38dd168
Added UUID to "/channel/members" Endpoint. (#2)
MarcelCoding Oct 29, 2019
dd63579
Updated Type Error in "/messages/whisper". (#1)
MarcelCoding Oct 29, 2019
f379d87
Add Method to delete Channels. (#1)
MarcelCoding Oct 29, 2019
e7bc787
Added JUnit Stuff. (#1)
MarcelCoding Oct 29, 2019
67b9254
Added Channel Tests. (#1)
MarcelCoding Oct 29, 2019
21f7d28
Added ChannelHandler Tests. (#1)
MarcelCoding Oct 29, 2019
aa71913
Merge branch 'experimental' into issue/1-create-chat-microservice
Defelo Oct 29, 2019
ba6755e
Changed Type UUID.class to String.class. (#1)
MarcelCoding Oct 29, 2019
57fd9d2
Merge remote-tracking branch 'origin/issue/1-create-chat-microservice…
MarcelCoding Oct 29, 2019
f60d43b
Changed UUID to UUID.toString() (#1)
MarcelCoding Oct 29, 2019
4ad0dcd
Updated Tests. (#1)
MarcelCoding Oct 30, 2019
fe49418
Fixed SonarCloud Stuff. (#1)
MarcelCoding Oct 30, 2019
5507f3b
Updated SonarCloud Stuff in Class Channel. (#1)
MarcelCoding Oct 30, 2019
1d6ccd4
Added getUserByName to Channel Object. (#1)
MarcelCoding Oct 30, 2019
60e2ff7
Changed Whisper to User by Uuid to Whisper to User by Name. (#1)
MarcelCoding Oct 30, 2019
6f15ff8
Fixed Test Bug in Channel Object. (#1)
MarcelCoding Oct 30, 2019
5505f82
Fixed SonarCloud (hopefully) (#1)
JannikEmmerich Nov 1, 2019
4894fac
made sonar-scanner.sh executable (#1)
Defelo Nov 2, 2019
4ce91ab
Create sonar-project.properties
JannikEmmerich Nov 2, 2019
2552996
Update sonar-project.properties
JannikEmmerich Nov 2, 2019
0f363ba
Update sonar-project.properties
JannikEmmerich Nov 2, 2019
ebba44b
Fixed some issues (#1)
JannikEmmerich Nov 7, 2019
266d034
Fixed Unit Tests for Channel (#1)
JannikEmmerich Nov 7, 2019
bbd60ab
Added Some more Tests & Updated JavaLib. (#1)
MarcelCoding Nov 8, 2019
59eea50
Added Some more Tests & removed removed model package. (#1)
MarcelCoding Nov 8, 2019
aa8c341
Changed excluded File 'Main' to 'App'. (#1)
MarcelCoding Nov 8, 2019
b7008b0
Changed JavaLib Version to Experimental. (#1)
MarcelCoding Nov 8, 2019
58f3ad8
Added some Unittests. (#1)
MarcelCoding Nov 26, 2019
828dfc0
Removed Null Pointer Bug. (#1)
MarcelCoding Nov 26, 2019
bd471a8
Added Some more Unit tests. (#1)
MarcelCoding Nov 27, 2019
d91f952
Added Tests for Channel Endpoints. (#1)
MarcelCoding Nov 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 62 additions & 62 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.cryptic_game.microservice</groupId>
<artifactId>chat</artifactId>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>
<groupId>net.cryptic_game.microservice</groupId>
<artifactId>chat</artifactId>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>cryptic-game-chat</name>
<description>offical chat microservice of cryptic-game</description>
<url>https://cryptic-game.net</url>
<name>cryptic-game-chat</name>
<description>offical chat microservice of cryptic-game</description>
<url>https://cryptic-game.net</url>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>net.cryptic_game.microservice.chat.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>net.cryptic_game.microservice.chat.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.cryptic-game</groupId>
<artifactId>java-lib</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.github.cryptic-game</groupId>
<artifactId>java-lib</artifactId>
<version>experimental-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
26 changes: 17 additions & 9 deletions src/main/java/net/cryptic_game/microservice/chat/App.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package net.cryptic_game.microservice.chat;

import org.apache.log4j.BasicConfigurator;

import net.cryptic_game.microservice.MicroService;
import net.cryptic_game.microservice.chat.channel.ChannelHandler;
import org.apache.log4j.BasicConfigurator;

public class App extends MicroService {

public App() {
super("chat");
}
private static ChannelHandler channelHandler;

private App() {
super("chat");
}

public static void main(String[] args) {
BasicConfigurator.configure();

public static void main(String[] args) {
BasicConfigurator.configure();
channelHandler = new ChannelHandler();
channelHandler.addChanel("global");

new App();
}
new App();
}

public static ChannelHandler getChannelHandler() {
return channelHandler;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package net.cryptic_game.microservice.chat.channel;

import net.cryptic_game.microservice.wrapper.User;

import java.util.ArrayList;
import java.util.UUID;

public class Channel {

private final UUID uuid;
private final ArrayList<User> users;
private String name;

Channel(final String name) {
this.uuid = UUID.randomUUID();
this.name = name;
this.users = new ArrayList<>();
}

public UUID getUuid() {
return this.uuid;
}

public String getName() {
return this.name;
}

public void setName(final String name) {
this.name = name;
}

public ArrayList<User> getUsers() {
return this.users;
}

public boolean addUser(final User user) {
for (User u : users) {
if (u.getUUID().equals(user.getUUID())) {
return false;
}
}
this.users.add(user);
return true;
}

public boolean removeUser(final User user) {
for (User u : users) {
if (u.getUUID().equals(user.getUUID())) {
this.users.remove(user);
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.cryptic_game.microservice.chat.channel;

import net.cryptic_game.microservice.MicroService;
import net.cryptic_game.microservice.utils.JSONBuilder;
import net.cryptic_game.microservice.wrapper.User;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;

import static net.cryptic_game.microservice.utils.JSONBuilder.anJSON;

public class ChannelHandler {

private final ArrayList<Channel> channels;

public ChannelHandler() {
this.channels = new ArrayList<>();
}

public Channel addChanel(final String name) {
final Channel channel = new Channel(name);
this.channels.add(channel);
return channel;
}

public Channel getChannelByUUID(final UUID uuid) {
for (final Channel channel : this.channels) if (channel.getUuid().equals(uuid)) return channel;
return null;
}

public ArrayList<Channel> getChannels() {
return this.channels;
}

public void notifyUser(final User user, final ChatAction action, final Channel channel, final UUID target) {
this.notifyUsers(new ArrayList<>(Collections.singletonList(user)), action, channel, target);
}

public void notifyUser(final User user, final ChatAction action, final Channel channel, final UUID target, final JSONObject content) {
this.notifyUsers(new ArrayList<>(Collections.singletonList(user)), action, channel, target, content);
}

public void notifyUsers(final ArrayList<User> users, final ChatAction action, final Channel channel, final UUID target) {
this.notifyUsers(users, action, channel, target, null);
}

public void notifyAllChannelUsers(final ChatAction action, final Channel channel, final UUID target) {
this.notifyUsers(channel.getUsers(), action, channel, target, null);
}

public void notifyAllChannelUsers(final ChatAction action, final Channel channel, final UUID target, final JSONObject content) {
this.notifyUsers(channel.getUsers(), action, channel, target, content);
}

public void notifyUsers(final ArrayList<User> users, ChatAction action, final Channel channel, final UUID target, final JSONObject content) {
final JSONBuilder data = anJSON()
.add("action", action.getValue())
.add("channel", channel.getUuid().toString())
.add("user", target.toString());

if (content != null) {
data.add("content", content);
}

final JSONObject json = anJSON()
.add("notify-id", "chat-update")
.add("origin", "chat")
.add("data", data.build()
).build();

users.forEach(user -> MicroService.getInstance().sendToUser(user.getUUID(), json));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.cryptic_game.microservice.chat.channel;

public enum ChatAction {
MEMBER_JOIN("member-join"),
MEMBER_LEAVE("member-leave"),

SEND_MESSAGE("send-message"),
WHISPER_MESSAGE("whisper-message");

final String value;

ChatAction(final String value) {
this.value = value;
}

public String getValue() {
return this.value;
}
}
Loading