Skip to content
This repository was archived by the owner on May 13, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .github/workflows/chat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ jobs:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action == 'opened')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn sonar:sonar -Dsonar.projectKey=cryptic-game_cryptic-chat -Dsonar.organization=cryptic-game -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./sonar-scanner.sh
145 changes: 83 additions & 62 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,70 +1,91 @@
<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>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- Custom Plugins -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>

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

<dependencies>
<dependency>
<groupId>com.github.cryptic-game</groupId>
<artifactId>java-lib</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<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>experimental-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
7 changes: 7 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sonar.organization=cryptic-game
sonar.projectKey=cryptic-game_cryptic-chat
sonar.projectName=cryptic-chat
sonar.projectVersion=1.0
sonar.sources=src/main/java/
sonar.java.binaries=target/classes/
sonar.coverage.exclusions=src/test/*,src/main/java/net/cryptic_game/microservice/chat/App.java
13 changes: 13 additions & 0 deletions sonar-scanner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

export SONAR_SCANNER_VERSION=4.0.0.1744
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
rm -rf $SONAR_SCANNER_HOME
mkdir -p $SONAR_SCANNER_HOME
curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
rm $HOME/.sonar/sonar-scanner.zip
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"

sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN
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,66 @@
package net.cryptic_game.microservice.chat.channel;

import net.cryptic_game.microservice.chat.App;
import net.cryptic_game.microservice.wrapper.User;

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

public class Channel {

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

public 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 List<User> getUsers() {
return this.users;
}

public boolean addUser(final User user) {
for (final User u : this.users) {
if (u.getUUID().equals(user.getUUID())) {
return false;
}
}
App.getChannelHandler().notifyAllChannelUsers(ChatAction.MEMBER_JOIN, this, user.getName());
this.users.add(user);
return true;
}

public boolean removeUser(final User user) {
for (final User u : this.users) {
if (u.getUUID().equals(user.getUUID())) {
this.users.remove(user);
App.getChannelHandler().notifyAllChannelUsers(ChatAction.MEMBER_LEAVE, this, user.getName());
return true;
}
}
return false;
}

public User getUserByName(final String name) {
for (final User user : this.users) {
if (user.getName().equals(name)) return user;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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.List;
import java.util.UUID;

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

public class ChannelHandler {

private final List<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 void removeChannel(final UUID channelUuid, final String userUuid) {
final Channel channel = this.getChannelByUUID(channelUuid);
this.notifyAllChannelUsers(ChatAction.CHANNEL_DELETE, channel, userUuid);
this.channels.remove(channel);
}

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

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

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

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

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

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

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

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

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,21 @@
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"),

CHANNEL_DELETE("channel-delete");

final String value;

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

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