Initial commit for Software Engineerung & Programming Course
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
2
Dokumentation/Interation 2/WorkingDir/Instructions.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Fuer den Server muss ./src/new_build/server/control/ServerController gestartet werden
|
||||
Fuer den Client muss ./src/new_build/client/view/sepboard.GUIview/Main gestartet werden
|
||||
11
Dokumentation/Interation 2/WorkingDir/WorkingDir.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
After Width: | Height: | Size: 30 KiB |
@@ -0,0 +1,269 @@
|
||||
package new_build.client.controller;
|
||||
|
||||
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.beans.value.ObservableValueBase;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import new_build.client.listener.ConsoleListener;
|
||||
import new_build.client.view.ConsoleView;
|
||||
import new_build.client.view.sepboard.GUIview.controller.ChatController;
|
||||
import new_build.client.view.sepboard.GUIview.controller.ViewController;
|
||||
import new_build.models.client_interfaces.ClientView;
|
||||
import new_build.models.common.Controller;
|
||||
import new_build.models.common.IOLoop;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.MessageChangeObserver;
|
||||
import new_build.models.common.messages.MessageObserver;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.common.polls.Poll;
|
||||
import new_build.models.network_organisation.*;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class ClientController {
|
||||
private Connection connection;
|
||||
private ClientView view;
|
||||
private volatile boolean keepRunning;
|
||||
private volatile UserLogin loggedInUser;
|
||||
private volatile HashMap<Group, GroupInformation> knownTeamMap;
|
||||
private ViewController viewController;
|
||||
public static volatile ClientController controller;
|
||||
private Group workingGroup;
|
||||
private SimpleIntegerProperty integerProperty = new SimpleIntegerProperty();
|
||||
private Message lastMessage;
|
||||
|
||||
public SimpleIntegerProperty getIntegerProperty(){
|
||||
return integerProperty;
|
||||
}
|
||||
public Message lastMessage(){
|
||||
return lastMessage;
|
||||
}
|
||||
|
||||
public HashMap<Group, GroupInformation> getKnownTeamMap(){
|
||||
return knownTeamMap;
|
||||
}
|
||||
public Group getWorkingGroup(){
|
||||
return this.workingGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* delivers targetIp and portToListenTo to the constructor
|
||||
* builds a new array, LinkedList, connection, ioLoop and socket
|
||||
* starts the ioLoop and sends the client the information that the client started successfully.
|
||||
*
|
||||
* @param targetIp
|
||||
* @param portToListenTo
|
||||
*/
|
||||
public ClientController(String targetIp, int portToListenTo) {
|
||||
Socket connectionSocket;
|
||||
keepRunning = true;
|
||||
try {
|
||||
view = new ConsoleView(new ConsoleListener(this), this);
|
||||
connectionSocket = new Socket(targetIp, portToListenTo);
|
||||
connection = new Connection(connectionSocket);
|
||||
this.knownTeamMap = new HashMap<>();
|
||||
System.out.println("client started successfully");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static ClientController getController(){
|
||||
if(controller != null) return controller;
|
||||
else {
|
||||
controller = new ClientController("localhost", 1337);
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* for (endless) loop (the code has to keep running..)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean keepRunning() {
|
||||
return this.keepRunning;
|
||||
}
|
||||
|
||||
public Group getGroupByName(String groupName){
|
||||
for (Group g : this.knownTeamMap.keySet()){
|
||||
if(g.getName().equals(groupName)) return g;
|
||||
}
|
||||
return Group.DEFAULT_GROUP;
|
||||
}
|
||||
public UserLogin getSendingUser(){
|
||||
return this.loggedInUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is for closing the process
|
||||
*/
|
||||
public void close() {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* will exit the process (shut down the process: the keepRunning method will be quit)
|
||||
*
|
||||
* @param status
|
||||
*/
|
||||
public void shutDown(int status) {
|
||||
//maybe join threads for clean shutdown?
|
||||
keepRunning = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* if the message is in an expected class, the message will be displayed
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public void processMessage(Message message) {
|
||||
if (message == null || !message.getControlHeaderType().equals(ServerStatus.class)) {
|
||||
System.out.println("got unexpected Message header - throwing away message ... ");
|
||||
return;
|
||||
}
|
||||
//porcess the message and give it to ClientView
|
||||
switch (((ServerStatus) message.getControlHeader())) {
|
||||
case LOGIN_SUCCESSFUL: {
|
||||
//this.performLoginUpdates(message);
|
||||
assert message.getExtension().getType().equals(LoginData.class);
|
||||
LoginData loginData = ((LoginData) message.getExtension());
|
||||
this.loggedInUser = loginData.getLoggedInUser();
|
||||
this.knownTeamMap = loginData.getGroupInformationMap();
|
||||
System.out.println("loaded logindata ... - username: " + loggedInUser.getUserName());
|
||||
view.displayMessage(message);
|
||||
lastMessage = message;
|
||||
incrementIntegerProperty();
|
||||
break;
|
||||
}
|
||||
case SESSION_EXPIRED:
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
case NEW_MESSAGE: {
|
||||
Group g = message.getGroup();
|
||||
this.getKnownTeamMap().get(g).getMessagesInChatRoom().add(message);
|
||||
view.displayMessage(message);
|
||||
viewController.reactToNewMessage(message);
|
||||
break;
|
||||
}
|
||||
case REGISTRATION_SUCCESSFUL: {
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
}
|
||||
case LOGIN_FAILED:
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
case LOGOUT_SUCCESSFUL:
|
||||
assert message.getExtension() != null && message.getExtension().getType().equals(UserLogin.class);
|
||||
this.loggedInUser = ((UserLogin) message.getExtension());
|
||||
//view.switchScene("chat");
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
case COMMAND_UNKNOWN:
|
||||
break;
|
||||
case PERMISSION_DENIED:
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
case REGISTRATION_FAILED:
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
case MEMBER_JOINED: {
|
||||
Group group = message.getGroup();
|
||||
assert message.getExtension() != null && message.getExtension().getType().equals(Pair.class);
|
||||
Pair<User, PermissionRole> userWithRole = ((Pair<User, PermissionRole>) message.getExtension());
|
||||
this.knownTeamMap.get(group).getRoleMap().put(userWithRole.getA(), userWithRole.getB());
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
}
|
||||
case ROLE_CHANGED: {
|
||||
Group group = message.getGroup();
|
||||
assert message.getExtension() != null && message.getExtension().getType().equals(Pair.class);
|
||||
Pair<User, PermissionRole> userWithRole = ((Pair<User, PermissionRole>) message.getExtension());
|
||||
HashMap<User, PermissionRole> roleMap = knownTeamMap.get(group).getRoleMap();
|
||||
roleMap.remove(userWithRole.getA());
|
||||
roleMap.put(userWithRole.getA(), userWithRole.getB());
|
||||
view.displayMessage(message);
|
||||
break;
|
||||
}
|
||||
case POLL_CREATED: {
|
||||
Group group = message.getGroup();
|
||||
assert message.getExtension() != null && message.getExtension().getType().equals(Poll.class);
|
||||
view.displayMessage(message);
|
||||
}
|
||||
break;
|
||||
case POLL_FINISHED:
|
||||
break;
|
||||
case VOTE_SUCCESSFUL:
|
||||
break;
|
||||
case VOTE_FAILED:
|
||||
break;
|
||||
case PROFILE_CHANGE_SUCCESSFUL:
|
||||
break;
|
||||
case ERR_EXECUTING_COMMAND:
|
||||
break;
|
||||
default: {
|
||||
view.displayMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void incrementIntegerProperty() {
|
||||
this.getIntegerProperty().set(1+this.getIntegerProperty().getValue() % 100000);
|
||||
}
|
||||
|
||||
/**
|
||||
* message will forwarded to the class ioLoop and handled there.
|
||||
*
|
||||
* @param m
|
||||
*/
|
||||
public void sendMessage(Message m) {
|
||||
try {
|
||||
connection.sendMessage(m);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void listenToMessages(){
|
||||
while(this.keepRunning()){
|
||||
try {
|
||||
Message m = connection.getNextMessage();
|
||||
if(m == null) {
|
||||
System.out.println("connection broke - shutting down");
|
||||
close();
|
||||
} else {
|
||||
this.processMessage(m);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
controller = new ClientController("localhost", 1337);
|
||||
}
|
||||
|
||||
public void changeWorkingGroup(String text) {
|
||||
this.workingGroup = this.getGroupByName(text);
|
||||
}
|
||||
|
||||
public void registerViewController(ViewController viewController) {
|
||||
this.viewController = viewController;
|
||||
}
|
||||
|
||||
public ViewController getViewController() {
|
||||
return viewController;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package new_build.client.listener;
|
||||
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.client_interfaces.ClientInputListener;
|
||||
import new_build.models.client_interfaces.ClientView;
|
||||
import new_build.models.common.messages.Command;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ConsoleListener implements ClientInputListener{
|
||||
|
||||
private ClientController controller;
|
||||
private ClientView assignedView;
|
||||
private Scanner scanner;
|
||||
|
||||
/**
|
||||
* constructor of ConsoleListener
|
||||
* delivers the ClientController controller to the constructor
|
||||
* and initializes scanner
|
||||
* @param controller
|
||||
*/
|
||||
public ConsoleListener(ClientController controller){
|
||||
|
||||
this.controller = controller;
|
||||
scanner = new Scanner(System.in);
|
||||
}
|
||||
|
||||
private Message packMessageContent(String[] messageInfo){
|
||||
if(messageInfo.length < 3) return null;
|
||||
Group groupSendTo = controller.getGroupByName(messageInfo[0]);
|
||||
Command command = Command.getCommandFromString(messageInfo[1]);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
switch(command){
|
||||
|
||||
case LOGIN:
|
||||
assert messageInfo.length == 4;
|
||||
builder.append(messageInfo[2] + " " + messageInfo[3]);
|
||||
return new Message(Group.DEFAULT_GROUP, command, null, builder.toString(), null);
|
||||
case REGISTER:
|
||||
assert messageInfo.length == 6;
|
||||
UserLogin loginTry = new UserLogin(0, messageInfo[2], messageInfo[3], messageInfo[4],
|
||||
messageInfo[5]);
|
||||
return new Message(Group.DEFAULT_GROUP, command, null, null, loginTry);
|
||||
case SENDMESSAGE:
|
||||
for(int i = 0;i<messageInfo.length; i++){
|
||||
builder.append(messageInfo[i]);
|
||||
if(i<messageInfo.length-1) builder.append(" ");
|
||||
}
|
||||
return new Message(groupSendTo, command, controller.getSendingUser(), builder.toString(), null);
|
||||
case CHANGEUSER:
|
||||
assert messageInfo.length == 6;
|
||||
UserLogin changedUser = new UserLogin(0, messageInfo[2], messageInfo[3], messageInfo[4],
|
||||
messageInfo[5]);
|
||||
return new Message(Group.DEFAULT_GROUP, command, null, null, changedUser);
|
||||
case LOGOUT:
|
||||
break;
|
||||
case ADDGROUP:
|
||||
break;
|
||||
case ADDUSER:
|
||||
break;
|
||||
case REMOVEUSER:
|
||||
break;
|
||||
case CHANGEROLE:
|
||||
break;
|
||||
case UNKNOWN:
|
||||
break;
|
||||
default: return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread with Run-Loop which receives commands out of the command line
|
||||
* and sends messages to the client
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String[] messageInfo;
|
||||
String groupName;
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
while(controller.keepRunning()){
|
||||
messageInfo = scanner.nextLine().split(" ");
|
||||
if (messageInfo.length < 2) {
|
||||
System.out.println("not enough message-information - syntax is: <group> <command> [<additional information>]");
|
||||
continue;
|
||||
}
|
||||
if (messageInfo.length > 2){
|
||||
for (int i = 2; i<messageInfo.length; i++){
|
||||
content.append(messageInfo[i]);
|
||||
content.append(" ");
|
||||
}
|
||||
}
|
||||
groupName = messageInfo[0];
|
||||
Command command = Command.getCommandFromString(messageInfo[1]);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(int i = 2;i<messageInfo.length;i++){
|
||||
builder.append(messageInfo[i]);
|
||||
if(i<messageInfo.length-1) builder.append(" ");
|
||||
}
|
||||
if (messageInfo.length == 6 && command.equals(Command.REGISTER)){
|
||||
UserLogin loginTry = new UserLogin(0, messageInfo[2], messageInfo[3], messageInfo[4], messageInfo[5]);
|
||||
controller.sendMessage(new Message(controller.getGroupByName(groupName), command,
|
||||
controller.getSendingUser(), builder.toString(), loginTry));
|
||||
}
|
||||
else {
|
||||
if(controller.getSendingUser() != null) System.out.println("SENDING USER EXISTS");
|
||||
controller.sendMessage(new Message(controller.getGroupByName(groupName), command,
|
||||
controller.getSendingUser(), builder.toString(), null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sends the input to the client
|
||||
* @param msg
|
||||
*/
|
||||
|
||||
public void sendInput(Message msg) {
|
||||
controller.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package new_build.client.listener;
|
||||
|
||||
|
||||
public class FXListener {
|
||||
|
||||
//for GUI
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package new_build.client.view;
|
||||
|
||||
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.client_interfaces.ClientInputListener;
|
||||
import new_build.models.client_interfaces.ClientView;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.User;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class ConsoleView implements ClientView {
|
||||
|
||||
private ClientInputListener inputListener;
|
||||
private ClientController controller;
|
||||
/**
|
||||
* delivers inputListener and controller to the constructor
|
||||
* @param inputListener
|
||||
* @param controller
|
||||
*/
|
||||
public ConsoleView(ClientInputListener inputListener, ClientController controller){
|
||||
this.inputListener = inputListener;
|
||||
this.controller = controller;
|
||||
new Thread(inputListener).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* sends the primary text to the console
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
System.out.println("Welcome to Console View - you can enter new Messages to console");
|
||||
}
|
||||
|
||||
/**
|
||||
* this method shall send the delivered message to reactToStatus
|
||||
* @param message
|
||||
*/
|
||||
@Override
|
||||
public void displayMessage(Message message) {
|
||||
this.reactToMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* at this point the message from displayMessage will be forwarded to content
|
||||
* moreover the status and group will be displayed on the console through a StringBuilder
|
||||
* @param message
|
||||
*/
|
||||
@Override
|
||||
public void reactToMessage(Message message) {
|
||||
if (message != null && message.getControlHeaderType().equals(ServerStatus.class)) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("|");
|
||||
builder.append(message.getGroup().getName());
|
||||
builder.append(";");
|
||||
builder.append(message.getTimeStamp());
|
||||
builder.append("|-");
|
||||
builder.append(((ServerStatus) message.getControlHeader()));
|
||||
builder.append("-|");
|
||||
builder.append(message.getContent());
|
||||
builder.append("|");
|
||||
System.out.println(builder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
//nothing needs to be done here?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMessages(HashMap<Group, LinkedList<Message>> messageMap) {
|
||||
for (Group g : messageMap.keySet()) {
|
||||
System.out.println("----Messages in Group " + g.getName() + ": ----");
|
||||
for (Message nextMessage : messageMap.get(g)) {
|
||||
this.displayMessage(nextMessage);
|
||||
}
|
||||
}
|
||||
System.out.println("loaded all messages");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(Group groupInvitedTo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMessage(Group groupSendTo, Message message) {
|
||||
this.displayMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProfileInfo(User user) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package new_build.client.view.sepboard.GUIview;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.client.view.sepboard.GUIview.controller.ViewController;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.MessageObserver;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
private Stage primaryStage;
|
||||
private ViewController currentViewController;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
this.primaryStage = primaryStage;
|
||||
Thread t = new Thread(() -> {
|
||||
ClientController.controller = new ClientController("localhost", 1337);
|
||||
ClientController.controller.listenToMessages();
|
||||
});
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
while (ClientController.controller == null) {
|
||||
try {
|
||||
Thread.sleep(40);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Stage stage = primaryStage;
|
||||
Parent login = null;
|
||||
try {
|
||||
login = FXMLLoader.load(getClass().getResource("resources/layout/login.fxml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
stage.setTitle("SEPboard");
|
||||
stage.getIcons().add(new Image("new_build/client/view/sepboard/GUIview/resources/image/icon.png"));
|
||||
Scene scene = new Scene(login, 800, 600);
|
||||
stage.setScene(scene);
|
||||
stage.setMinWidth(800);
|
||||
stage.setMinHeight(600);
|
||||
stage.show();
|
||||
ClientController.controller.getIntegerProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
|
||||
ClientController.controller.getViewController().reactToNewMessage(ClientController.controller.lastMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
private void changeScene(String changeToScene) throws IOException {
|
||||
|
||||
// Get reference to the button's stage
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.util.Callback;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.data.Sendable;
|
||||
import new_build.models.network_organisation.Group;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 18.06.2017.
|
||||
*/
|
||||
public class ButtonCell implements Callback<TableColumn<Table, Button>, TableCell<Table, Button>> {
|
||||
|
||||
private String buttonText;
|
||||
private UserhubController controller;
|
||||
|
||||
public ButtonCell(String buttonText, UserhubController controller) {
|
||||
this.buttonText = buttonText;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableCell<Table, Button> call(TableColumn<Table, Button> param) {
|
||||
final TableCell<Table, Button> cell = new TableCell<Table, Button>()
|
||||
{;
|
||||
final Button btn = new Button(buttonText);
|
||||
|
||||
@Override
|
||||
public void updateItem( Button item, boolean empty )
|
||||
{
|
||||
super.updateItem( item, empty );
|
||||
if ( empty )
|
||||
{
|
||||
setGraphic( null );
|
||||
setText( null );
|
||||
}
|
||||
else
|
||||
{
|
||||
btn.setOnAction( ( ActionEvent event ) ->
|
||||
{
|
||||
try {
|
||||
ClientController.controller.changeWorkingGroup(btn.getText());
|
||||
controller.changeScene("chat");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} );
|
||||
setGraphic( btn );
|
||||
setText( null );
|
||||
}
|
||||
}
|
||||
};
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
|
||||
import new_build.models.common.messages.Message;
|
||||
|
||||
|
||||
public class ChatBox extends AnchorPane {
|
||||
|
||||
String text;
|
||||
long date;
|
||||
String username;
|
||||
BufferedImage profilePic;
|
||||
|
||||
public ChatBox(AnchorPane layout, Message message){
|
||||
this.getChildren().addAll(layout.getChildren());
|
||||
}
|
||||
|
||||
public void setInformation(Message message){
|
||||
this.text = message.getContent();
|
||||
this.date = message.getTimeStamp().getTime();
|
||||
this.username = message.getSendingUser().getFirstName() + " " + message.getSendingUser().getLastName();
|
||||
this.profilePic = message.getSendingUser().getProfilePic();
|
||||
Label textLabel = new Label(text);
|
||||
textLabel.setMinHeight(200);
|
||||
Label usernameLabel = new Label(username);
|
||||
usernameLabel.setMinHeight(100);
|
||||
Date d = new Date(date);
|
||||
LocalDateTime time = LocalDateTime.ofInstant(d.toInstant(), ZoneId.systemDefault());
|
||||
Label dateLabel = new Label(time.getHour()+":"+time.getMinute()+ " "+time.getDayOfMonth()+"."+time.getMonthValue());
|
||||
Parent text = new AnchorPane();
|
||||
this.getChildren().add(usernameLabel);
|
||||
this.getChildren().add(dateLabel);
|
||||
this.getChildren().add(textLabel);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
import com.sun.deploy.util.SessionState;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.data.Sendable;
|
||||
import new_build.models.common.data.SepFile;
|
||||
import new_build.models.common.messages.Command;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.common.polls.Poll;
|
||||
import new_build.models.common.polls.Vote;
|
||||
import new_build.models.network_organisation.Connection;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.User;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.sql.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
public class ChatController implements ViewController{
|
||||
|
||||
private Group assignedGroup;
|
||||
SepFile chosenFile;
|
||||
|
||||
@FXML
|
||||
private Button sendButton;
|
||||
@FXML
|
||||
private ImageView appendixButton;
|
||||
@FXML
|
||||
private Button backToUserHubButton;
|
||||
@FXML
|
||||
private TextArea messageField;
|
||||
@FXML
|
||||
private ListView<AnchorPane> listView;
|
||||
ObservableList<AnchorPane> chatBoxList = FXCollections.observableArrayList();
|
||||
|
||||
public ChatController(){
|
||||
System.out.println("constr");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addMessage(Message m){
|
||||
try {
|
||||
AnchorPane template = FXMLLoader.load(getClass().getResource(
|
||||
"/new_build/client/view/sepboard/GUIview/resources/layout/message.fxml"));
|
||||
Scene templateScene = new Scene(template);
|
||||
Text contentField = ((Text) templateScene.lookup("#contentField"));
|
||||
Label nameField = ((Label) templateScene.lookup("#nameField"));
|
||||
Label timeField = ((Label) templateScene.lookup("#timeField"));
|
||||
ImageView picField = ((ImageView) templateScene.lookup("#picField"));
|
||||
contentField.setText(m.getContent());
|
||||
System.out.println(System.getProperty("user.dir"));
|
||||
File file = new File(System.getProperty("user.dir") + "/WorkingDir/src/new_build/client/view/sepboard/GUIview/resources/image/" +
|
||||
"Places-user-identity-icon.png");
|
||||
assert file.exists() && file.canRead() && picField != null;
|
||||
Image image = new Image(file.toURI().toString());
|
||||
picField.setImage(image);
|
||||
User u = m.getSendingUser();
|
||||
nameField.setText(u.getFirstName() + " " + u.getLastName());
|
||||
timeField.setText((new Date(m.getTimeStamp().getTime())).toString());
|
||||
ChatBox messageBox = new ChatBox(template, m);
|
||||
chatBoxList.add(messageBox);
|
||||
listView.setItems(chatBoxList);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addPoll(Poll poll){
|
||||
AnchorPane template = null;
|
||||
try {
|
||||
template = FXMLLoader.load(getClass().getResource(
|
||||
"/new_build/client/view/sepboard/GUIview/resources/layout/poll.fxml"));
|
||||
PollBox box = new PollBox(template, poll, this);
|
||||
chatBoxList.add(box);
|
||||
listView.setItems(chatBoxList);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addVote(int id, boolean value){
|
||||
Vote v = new Vote(id, value);
|
||||
Message m = new Message(assignedGroup, Command.VOTE_POLL, ClientController.controller.getSendingUser(),
|
||||
"", v);
|
||||
ClientController.controller.sendMessage(m);
|
||||
}
|
||||
|
||||
public void sendButtonClicked() throws IOException {
|
||||
Message m = new Message(ClientController.controller.getWorkingGroup(),
|
||||
Command.SENDMESSAGE, ClientController.controller.getSendingUser(),
|
||||
messageField.getText(), chosenFile);
|
||||
chosenFile = null;
|
||||
ClientController.controller.sendMessage(m);
|
||||
messageField.setText("");
|
||||
}
|
||||
|
||||
public void pollButtonClicked(){
|
||||
Poll p = new Poll(0, messageField.getText(), new Date(System.currentTimeMillis()));
|
||||
Message m = new Message(assignedGroup, Command.ADDPOLL, ClientController.controller.getSendingUser(),
|
||||
"", p );
|
||||
ClientController.controller.sendMessage(m);
|
||||
messageField.setText("");
|
||||
}
|
||||
|
||||
|
||||
public void appendixButtonClicked() throws IOException {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
this.chosenFile = new SepFile(fileChooser.showOpenDialog(null));
|
||||
}
|
||||
|
||||
public void backToUserHubButtonClicked() throws IOException {
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
changeScene("userhub");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void changeScene(String changeToScene) throws IOException {
|
||||
// Get reference to the button's stage
|
||||
Stage stage = (Stage)sendButton.getScene().getWindow();
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reactToNewMessage(Message m) {
|
||||
if(m.getControlHeaderType().equals(ServerStatus.class) && m.getGroup().equals(assignedGroup)) {
|
||||
ServerStatus status = ((ServerStatus) m.getControlHeader());
|
||||
if (status.equals(ServerStatus.NEW_MESSAGE)) {
|
||||
System.out.println("adding message...");
|
||||
Platform.runLater(() -> {addMessage(m);});
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
System.out.println("chatinit");
|
||||
ClientController.controller.registerViewController(this);
|
||||
assignedGroup = ClientController.controller.getWorkingGroup();
|
||||
for(Message m : ClientController.controller.getKnownTeamMap().get(assignedGroup).getMessagesInChatRoom()){
|
||||
reactToNewMessage(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.scene.control.Hyperlink;
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.util.Callback;
|
||||
|
||||
|
||||
public class HyperlinkCell implements Callback<TableColumn<Table, Hyperlink>, TableCell<Table, Hyperlink>> {
|
||||
|
||||
@Override
|
||||
public TableCell<Table, Hyperlink> call(TableColumn<Table, Hyperlink> arg) {
|
||||
TableCell<Table, Hyperlink> cell = new TableCell<Table, Hyperlink>() {
|
||||
@Override
|
||||
protected void updateItem(Hyperlink item, boolean empty) {
|
||||
setGraphic(item);
|
||||
}
|
||||
};
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.messages.Command;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
|
||||
|
||||
public class LoginController implements ViewController{
|
||||
@FXML
|
||||
private Button loginButton;
|
||||
@FXML
|
||||
private Button registerButton;
|
||||
@FXML
|
||||
private TextField usernameField;
|
||||
@FXML
|
||||
private PasswordField passwordField;
|
||||
|
||||
private void handleButtonAction(ActionEvent event){
|
||||
|
||||
}
|
||||
|
||||
public LoginController(){;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void loginButtonClicked() throws IOException {
|
||||
UserLogin logintry = new UserLogin(0, usernameField.getText(), "","", passwordField.getText());
|
||||
Message m = new Message(Group.DEFAULT_GROUP, Command.LOGIN, logintry, usernameField.getText() + " "
|
||||
+ passwordField.getText(), logintry);
|
||||
ClientController.controller.sendMessage(m);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void registerButtonClicked() throws IOException {
|
||||
this.changeScene("registration");
|
||||
System.out.println("clicked registration");
|
||||
}
|
||||
@FXML
|
||||
private void passwordForgottenLinkClicked() throws IOException {
|
||||
this.changeScene("password_forgotten");
|
||||
}
|
||||
|
||||
private void changeScene(String changeToScene) throws IOException {
|
||||
// Get reference to the button's stage
|
||||
Stage stage = (Stage)registerButton.getScene().getWindow();
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
|
||||
Scene scene = new Scene(root);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reactToNewMessage(Message m) {
|
||||
|
||||
Platform.runLater(() -> {
|
||||
if(m.getControlHeaderType().equals(ServerStatus.class)){
|
||||
ServerStatus status = ((ServerStatus) m.getControlHeader());
|
||||
if (status.equals(ServerStatus.LOGIN_SUCCESSFUL)) try {
|
||||
this.changeScene("userhub");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ClientController.controller.registerViewController(this);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class PasswordForgottenController implements ViewController{
|
||||
@FXML
|
||||
private Button backButton;
|
||||
@FXML
|
||||
private Button registerButton;
|
||||
@FXML
|
||||
private TextField usernameField;
|
||||
@FXML
|
||||
private TextField passwordField;
|
||||
String username;
|
||||
String password;
|
||||
UserLogin userLogin;
|
||||
|
||||
|
||||
private void handleButtonAction(ActionEvent event){
|
||||
username = usernameField.getText();
|
||||
password = passwordField.getText();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void resetPasswordClicked() throws IOException {
|
||||
//userLogin.setPassword(null);
|
||||
//specify new datas, Lieber neues Window dazu ? Sonst kann man das auch einfach alles bei den Einstellungen aendern
|
||||
this.changeScene("profile_settings");
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void backButtonClicked() throws IOException {
|
||||
this.changeScene("login");
|
||||
}
|
||||
|
||||
private void changeScene(String changeToScene) throws IOException {
|
||||
// Get reference to the button's stage
|
||||
Stage stage = (Stage)registerButton.getScene().getWindow();
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reactToNewMessage(Message m) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ClientController.controller.registerViewController(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.text.Text;
|
||||
import new_build.models.common.polls.Poll;
|
||||
|
||||
import static new_build.client.controller.ClientController.controller;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 19.06.2017.
|
||||
*/
|
||||
public class PollBox extends AnchorPane {
|
||||
|
||||
private Poll assignedPoll;
|
||||
|
||||
public PollBox(AnchorPane layout, Poll assignedPoll, ChatController controller){
|
||||
this.assignedPoll = assignedPoll;
|
||||
Scene templateScene = new Scene(layout);
|
||||
Button VoteForButton = ((Button) templateScene.lookup("#VoteForButton"));
|
||||
Button voteAgainstButton = ((Button) templateScene.lookup("#voteAgainstButton"));
|
||||
Label expireDate = ((Label) templateScene.lookup("#expireDate"));
|
||||
Label voteField = ((Label) templateScene.lookup("#voteField"));
|
||||
Text pollText = ((Text) templateScene.lookup("#pollText"));
|
||||
|
||||
VoteForButton.setOnAction((e) -> {
|
||||
controller.addVote(assignedPoll.getPollID(),true);
|
||||
});
|
||||
voteAgainstButton.setOnAction((e) -> {
|
||||
controller.addVote(assignedPoll.getPollID(), false);
|
||||
});
|
||||
expireDate.setText(assignedPoll.getExpiringDate().toString());
|
||||
voteField.setText(assignedPoll.getVotesFor().size() + ":" + assignedPoll.getVotesAgainst().size() + "(" +
|
||||
assignedPoll.getVotesAbstensions().size() + ")");
|
||||
pollText.setText(assignedPoll.getPollText());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Hyperlink;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.User;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class ProfileSettingsController implements ViewController{
|
||||
@FXML
|
||||
Button abortButton;
|
||||
@FXML
|
||||
ImageView profilePicture;
|
||||
private double X;
|
||||
private double Y;
|
||||
@FXML
|
||||
Hyperlink changePictureLink;
|
||||
@FXML
|
||||
private TextField surnameField;
|
||||
@FXML
|
||||
private TextField lastnameField;
|
||||
@FXML
|
||||
private TextField usernameField;
|
||||
@FXML
|
||||
private TextField passwordField;
|
||||
@FXML
|
||||
private TextField approvedPasswordField;
|
||||
String surname;
|
||||
String lastname;
|
||||
String username;
|
||||
String password;
|
||||
String approvedPassword;
|
||||
User user;
|
||||
UserLogin userLogin;
|
||||
|
||||
|
||||
private void handleButtonAction(ActionEvent event){
|
||||
surname = surnameField.getText();
|
||||
lastname = lastnameField.getText();
|
||||
username = usernameField.getText();
|
||||
password = passwordField.getText();
|
||||
approvedPassword = approvedPasswordField.getText();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void changeButtonClicked() throws IOException {/*
|
||||
if(password == approvedPassword){
|
||||
user.setFirstName(surname);
|
||||
user.setLastName(lastname);
|
||||
user.setUserName(username);
|
||||
userLogin.setPassword(password);
|
||||
}*/
|
||||
this.changeScene("userhub");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
this.setImageClip();
|
||||
X = profilePicture.getX();
|
||||
Y = profilePicture.getY();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void abortButtonClicked() throws IOException {
|
||||
this.changeScene("userhub");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void changePictureLinkClicked() throws IOException {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
|
||||
// Set Extension Filter
|
||||
FileChooser.ExtensionFilter jpgFilter = new FileChooser.ExtensionFilter(
|
||||
"JPEG Dateien (*.jpg)",
|
||||
"*.JPG", "*.jpg", "*.JPEG", "*.jpeg");
|
||||
FileChooser.ExtensionFilter gifFilter = new FileChooser.ExtensionFilter(
|
||||
"GIF Dateien",
|
||||
"*.gif", "*.GIF");
|
||||
FileChooser.ExtensionFilter pngFilter = new FileChooser.ExtensionFilter(
|
||||
"PNG Dateien",
|
||||
"*.png", "*.PNG");
|
||||
FileChooser.ExtensionFilter bmpFilter = new FileChooser.ExtensionFilter(
|
||||
"BMP Dateien",
|
||||
"*.bmp", "*.BMP");
|
||||
fileChooser.getExtensionFilters().addAll(jpgFilter, gifFilter, pngFilter, bmpFilter);
|
||||
|
||||
// Datei öffnen und speichern
|
||||
File file = fileChooser.showOpenDialog(null);
|
||||
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(file);
|
||||
Image image = SwingFXUtils.toFXImage(bufferedImage, null);
|
||||
if(image != null) {
|
||||
profilePicture.setImage(image);
|
||||
this.setImageClip();
|
||||
profilePicture.setX(-50);
|
||||
profilePicture.setY(0);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Konnte Bild nicht öffnen!");
|
||||
}
|
||||
}
|
||||
|
||||
private void setImageClip() {
|
||||
double Xwidth = profilePicture.getFitWidth() / 4;
|
||||
double Yheight = profilePicture.getFitHeight() / 2;
|
||||
Circle clip = new Circle(Xwidth, Yheight, 60);
|
||||
profilePicture.setClip(clip);
|
||||
}
|
||||
|
||||
private void changeScene(String changeToScene) throws IOException {
|
||||
// Get reference to the button's stage
|
||||
Stage stage = (Stage)abortButton.getScene().getWindow();
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reactToNewMessage(Message m) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ClientController.controller.registerViewController(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.messages.Command;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
import new_build.server.database.UserLib;
|
||||
import sun.applet.Main;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class RegistrationController implements ViewController{
|
||||
@FXML
|
||||
private Button backButton;
|
||||
@FXML
|
||||
private Button registerButton;
|
||||
@FXML
|
||||
private TextField surnameField;
|
||||
@FXML
|
||||
private TextField lastnameField;
|
||||
@FXML
|
||||
private TextField usernameField;
|
||||
@FXML
|
||||
private PasswordField passwordField;
|
||||
String surName;
|
||||
String lastName;
|
||||
String userName;
|
||||
String password;
|
||||
UserLib user = new UserLib();
|
||||
|
||||
private void handleButtonAction(ActionEvent event){
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void registerButtonClicked() throws IOException {
|
||||
surName = surnameField.getText();
|
||||
lastName = lastnameField.getText();
|
||||
userName = usernameField.getText();
|
||||
password = passwordField.getText();
|
||||
UserLogin user = new UserLogin(0, userName, surName, lastName, password);
|
||||
Message m = new Message(Group.DEFAULT_GROUP, Command.REGISTER, user,
|
||||
"", user);
|
||||
ClientController.controller.sendMessage(m);
|
||||
}
|
||||
@FXML
|
||||
public void backButtonClicked() throws IOException {
|
||||
this.changeScene("login");
|
||||
}
|
||||
|
||||
private void changeScene(String changeToScene) throws IOException {
|
||||
// Get reference to the button's stage
|
||||
Stage stage = (Stage)registerButton.getScene().getWindow();
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reactToNewMessage(Message m) {
|
||||
ServerStatus status = ((ServerStatus) m.getControlHeader());
|
||||
if(status.equals(ServerStatus.REGISTRATION_SUCCESSFUL)) try {
|
||||
this.changeScene("login");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ClientController.controller.registerViewController(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.scene.control.Button;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.GroupInformation;
|
||||
|
||||
public class Table {
|
||||
private final SimpleStringProperty teamname;
|
||||
private final Button chat;
|
||||
private final Button task;
|
||||
|
||||
public Table(String teamname, String chat, String task){
|
||||
this.teamname = new SimpleStringProperty(teamname);
|
||||
this.chat = new Button(chat);
|
||||
this.task = new Button(task);
|
||||
}
|
||||
|
||||
public Button getChatButton(){
|
||||
return chat;
|
||||
}
|
||||
|
||||
public Button getTaskButton(){
|
||||
return task;
|
||||
}
|
||||
|
||||
public String getTeamname(){
|
||||
return teamname.get();
|
||||
}
|
||||
|
||||
public Button getChat(){
|
||||
return chat;
|
||||
}
|
||||
|
||||
public Button getTask(){
|
||||
return task;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.stage.Stage;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.messages.Message;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class TaskboardController implements ViewController{
|
||||
@FXML
|
||||
private Button saveButton;
|
||||
@FXML
|
||||
private Button backToUserHubButton;
|
||||
|
||||
public void saveButtonClicked(){
|
||||
//saves the changes
|
||||
}
|
||||
|
||||
public void backToUserHubButtonClicked() throws IOException {
|
||||
changeScene("userhub");
|
||||
}
|
||||
|
||||
private void changeScene(String changeToScene) throws IOException {
|
||||
// Get reference to the button's stage
|
||||
Stage stage = (Stage)backToUserHubButton.getScene().getWindow();
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reactToNewMessage(Message m) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ClientController.controller.registerViewController(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.shape.Circle;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import new_build.client.controller.ClientController;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.GroupInformation;
|
||||
|
||||
public class UserhubController implements Initializable, ViewController{
|
||||
EventHandler e;
|
||||
@FXML BorderLayout userhubLayout;
|
||||
@FXML Button profileSettingsButton;
|
||||
@FXML ImageView userIcon;
|
||||
@FXML
|
||||
private TableView<Table> tableID;
|
||||
@FXML
|
||||
private TableColumn<Table, String> teamname;
|
||||
@FXML
|
||||
private TableColumn<Table, Button> chat;
|
||||
@FXML
|
||||
private TableColumn<Table, Button> taskboard;
|
||||
Button chatLink = new Button("Chat");
|
||||
Button taskLink = new Button("Task");
|
||||
Table table;
|
||||
Stage stage;
|
||||
String groupName = "";
|
||||
ButtonCell chatCellFacory;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the controller
|
||||
* @param location
|
||||
* @param resources
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources){
|
||||
teamname.setCellValueFactory(new PropertyValueFactory<Table, String>("teamname"));
|
||||
chat.setCellValueFactory(new PropertyValueFactory<Table, Button>("chat"));
|
||||
chatCellFacory = new ButtonCell(groupName, this);
|
||||
ButtonCell taskBoardCellFacory = new ButtonCell("taskboard", this);
|
||||
chat.setCellFactory(chatCellFacory);
|
||||
taskboard.setCellValueFactory(new PropertyValueFactory<Table, Button>("taskboard"));
|
||||
taskboard.setCellFactory(taskBoardCellFacory);
|
||||
final ObservableList<Table> data = FXCollections.observableArrayList();
|
||||
for(Group g: ClientController.controller.getKnownTeamMap().keySet()){
|
||||
this.groupName = g.getName();
|
||||
chatCellFacory = new ButtonCell(g.getName(), this);
|
||||
chat.setCellFactory(chatCellFacory);
|
||||
GroupInformation groupInformation = ClientController.controller.getKnownTeamMap().get(g);
|
||||
data.add(new Table("Gruppe", g.getName(), ""));
|
||||
}
|
||||
tableID.setItems(data);
|
||||
ClientController.controller.registerViewController(this);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void profilSettingsButtonClicked() throws IOException {
|
||||
this.changeScene("profile_settings");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void logoutButtonClicked() throws IOException {
|
||||
this.changeScene("login");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
double X = userIcon.getFitWidth() / 4;
|
||||
double Y = userIcon.getFitHeight() / 2;
|
||||
Circle clip = new Circle(X, Y, 30);
|
||||
userIcon.setClip(clip);
|
||||
ClientController.controller.registerViewController(this);
|
||||
}
|
||||
|
||||
public void changeScene(String changeToScene) throws IOException {
|
||||
// Get reference to the button's stage
|
||||
stage = (Stage)profileSettingsButton.getScene().getWindow();
|
||||
// Load other FXML document
|
||||
Parent root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reactToNewMessage(Message m) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package new_build.client.view.sepboard.GUIview.controller;
|
||||
|
||||
import javafx.fxml.Initializable;
|
||||
import new_build.models.common.messages.Message;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 19.06.2017.
|
||||
*/
|
||||
public interface ViewController extends Initializable{
|
||||
|
||||
public void reactToNewMessage(Message m);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
.text-field {
|
||||
-fx-background-color: #f2f2f2 , #f2f2f2 , #0079bf;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
-fx-prompt-text-fill: #f2f2f2;
|
||||
}
|
||||
|
||||
.text-field:focused {
|
||||
-fx-background-color: #f2f2f2 , #f2f2f2 , #0079bf;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
-fx-prompt-text-fill: #f2f2f2;
|
||||
}
|
||||
|
||||
.button{
|
||||
-fx-padding: 0.7em 0.57em;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-jfx-button-type: RAISED;
|
||||
-fx-background-color: #f2f2f2;
|
||||
-fx-text-fill: #0079bf;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
.text-field {
|
||||
-fx-background-color: #f2f2f2 , #f2f2f2 , #0079bf;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
-fx-prompt-text-fill: #f2f2f2;
|
||||
}
|
||||
|
||||
.text-field:focused {
|
||||
-fx-background-color: #f2f2f2 , #f2f2f2 , #0079bf;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
-fx-prompt-text-fill: #f2f2f2;
|
||||
}
|
||||
|
||||
.button{
|
||||
-fx-padding: 0.7em 0.57em;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-jfx-button-type: RAISED;
|
||||
-fx-background-color: #f2f2f2;
|
||||
-fx-text-fill: #0079bf;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
.text-field {
|
||||
-fx-background-color: #a9a9a9 , white , white;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
}
|
||||
|
||||
.text-field:focused {
|
||||
-fx-background-color: #a9a9a9 , white , white;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
}
|
||||
|
||||
.button{
|
||||
-fx-padding: 0.7em 0.57em;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-jfx-button-type: RAISED;
|
||||
-fx-background-color: #0079bf;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
.text-field {
|
||||
-fx-background-color: #f2f2f2 , #f2f2f2 , #0079bf;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
-fx-prompt-text-fill: #f2f2f2;
|
||||
}
|
||||
|
||||
.text-field:focused {
|
||||
-fx-background-color: #f2f2f2 , #f2f2f2 , #0079bf;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
-fx-prompt-text-fill: #f2f2f2;
|
||||
}
|
||||
|
||||
.button{
|
||||
-fx-padding: 0.7em 0.57em;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-jfx-button-type: RAISED;
|
||||
-fx-background-color: #f2f2f2;
|
||||
-fx-text-fill: #0079bf;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
.text-field {
|
||||
-fx-background-color: #a9a9a9 , white , white;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
}
|
||||
|
||||
.text-field:focused {
|
||||
-fx-background-color: #a9a9a9 , white , white;
|
||||
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 0 -1;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
}
|
||||
|
||||
.button{
|
||||
-fx-padding: 0.7em 0.57em;
|
||||
-fx-background-radius: 0 0 0 0;
|
||||
-jfx-button-type: RAISED;
|
||||
-fx-background-color: #0079bf;
|
||||
-fx-text-fill: #f2f2f2;
|
||||
}
|
||||
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 1012 B |
|
After Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 87 KiB |
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.TextArea?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.ChatController">
|
||||
<left>
|
||||
<BorderPane prefHeight="200.0" prefWidth="550.0" BorderPane.alignment="CENTER">
|
||||
<bottom>
|
||||
<HBox prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<TextArea fx:id="messageField" prefWidth="400.0" wrapText="true">
|
||||
<HBox.margin>
|
||||
<Insets />
|
||||
</HBox.margin>
|
||||
</TextArea>
|
||||
<Button fx:id="sendButton" mnemonicParsing="false" onMouseClicked="#sendButtonClicked" prefWidth="75.0" text="Senden">
|
||||
<HBox.margin>
|
||||
<Insets left="10.0" right="5.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
<Button mnemonicParsing="false">
|
||||
<graphic>
|
||||
<ImageView fitHeight="35.0" fitWidth="35.0" onMouseClicked="#appendixButtonClicked" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/circle_up.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic></Button>
|
||||
</children>
|
||||
<BorderPane.margin>
|
||||
<Insets top="5.0" />
|
||||
</BorderPane.margin>
|
||||
</HBox>
|
||||
</bottom>
|
||||
<top>
|
||||
<HBox spacing="10.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<Label text="Teamchat:">
|
||||
<font>
|
||||
<Font size="25.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="groupID">
|
||||
<font>
|
||||
<Font size="25.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
</top>
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" top="5.0" />
|
||||
</padding>
|
||||
<center>
|
||||
<ListView fx:id="listView" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
|
||||
</center>
|
||||
</BorderPane>
|
||||
</left>
|
||||
<right>
|
||||
<BorderPane prefHeight="200.0" prefWidth="250.0" BorderPane.alignment="CENTER">
|
||||
<top>
|
||||
<Label text="Online" BorderPane.alignment="CENTER">
|
||||
<font>
|
||||
<Font name="System Bold" size="20.0" />
|
||||
</font>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="3.0" top="8.0" />
|
||||
</BorderPane.margin>
|
||||
</Label>
|
||||
</top>
|
||||
<center>
|
||||
<ListView prefHeight="554.0" prefWidth="215.0" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" />
|
||||
</BorderPane.margin>
|
||||
</ListView>
|
||||
</center>
|
||||
<bottom>
|
||||
<Button fx:id="backToUserHub" mnemonicParsing="false" onMouseClicked="#backToUserHubButtonClicked" prefHeight="55.0" prefWidth="172.0" text="Zurück zum UserHub" BorderPane.alignment="CENTER" />
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
</right>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Hyperlink?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.FlowPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: #0079BF;" stylesheets="@../css/md_login.css" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.LoginController">
|
||||
<top>
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #F2F2F2;" BorderPane.alignment="CENTER">
|
||||
<center>
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/logo.png" />
|
||||
</image>
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</ImageView>
|
||||
<Label text="SEPboard" textFill="#0079bf">
|
||||
<font>
|
||||
<Font name="Market-Regular" size="100.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</top>
|
||||
<bottom>
|
||||
<BorderPane BorderPane.alignment="CENTER">
|
||||
<center>
|
||||
<Label text="© SEPboard - 2017" textFill="#f2f2f2" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets />
|
||||
</BorderPane.margin></Label>
|
||||
</center>
|
||||
<right>
|
||||
<Label text="v1.0.0" textFill="#f2f2f2" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets left="-10.0" right="10.0" />
|
||||
</BorderPane.margin></Label>
|
||||
</right>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="10.0" top="-10.0" />
|
||||
</BorderPane.margin>
|
||||
</BorderPane>
|
||||
</bottom>
|
||||
<center>
|
||||
<FlowPane alignment="CENTER" maxHeight="150.0" maxWidth="220.0" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<TextField fx:id="usernameField" minWidth="220.0" promptText="Benutzername" />
|
||||
<PasswordField fx:id="passwordField" minWidth="220.0" promptText="Passwort">
|
||||
<FlowPane.margin>
|
||||
<Insets bottom="5.0" top="5.0" />
|
||||
</FlowPane.margin>
|
||||
</PasswordField>
|
||||
<Hyperlink fx:id="passwordForgottenLink" onMouseClicked="#passwordForgottenLinkClicked" text="Passwort vergessen?" textFill="#f2f2f2">
|
||||
<FlowPane.margin>
|
||||
<Insets bottom="5.0" />
|
||||
</FlowPane.margin>
|
||||
</Hyperlink>
|
||||
<HBox alignment="TOP_CENTER" maxWidth="220.0" minWidth="220.0" prefHeight="100.0" spacing="20.0">
|
||||
<children>
|
||||
<Button fx:id="loginButton" mnemonicParsing="false" onMouseClicked="#loginButtonClicked" text="Login" />
|
||||
<Button fx:id="registerButton" mnemonicParsing="false" onMouseClicked="#registerButtonClicked" text="Registrieren" />
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="20.0" />
|
||||
</BorderPane.margin>
|
||||
</FlowPane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.canvas.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
|
||||
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="64.0" prefWidth="520.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<VBox maxHeight="1.7976931348623157E308" prefHeight="64.0" prefWidth="520.0">
|
||||
<children>
|
||||
<HBox prefHeight="24.0" prefWidth="520.0" style="-fx-background-color: #f5f5dc;">
|
||||
<children>
|
||||
<ImageView id="picField" fitHeight="24.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
|
||||
<Label id="nameField" alignment="CENTER" contentDisplay="CENTER" prefHeight="24.0" prefWidth="366.0" text="FirstName + LastName" textAlignment="CENTER" wrapText="true">
|
||||
<padding>
|
||||
<Insets left="10.0" />
|
||||
</padding>
|
||||
</Label>
|
||||
<Label id="timeField" alignment="CENTER" prefHeight="24.0" prefWidth="193.0" text="Time" />
|
||||
</children>
|
||||
</HBox>
|
||||
<Text id="contentField" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="511.205078125" />
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.FlowPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: #0079BF;" stylesheets="@../css/md_password_forgotten.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.PasswordForgottenController">
|
||||
<top>
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #F2F2F2;" BorderPane.alignment="CENTER">
|
||||
<center>
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/logo.png" />
|
||||
</image>
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</ImageView>
|
||||
<Label text="SEPboard" textFill="#0079bf">
|
||||
<font>
|
||||
<Font name="Market-Regular" size="100.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</top>
|
||||
<bottom>
|
||||
<BorderPane BorderPane.alignment="CENTER">
|
||||
<center>
|
||||
<Label text="© SEPboard - 2017" textFill="#f2f2f2" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets />
|
||||
</BorderPane.margin></Label>
|
||||
</center>
|
||||
<right>
|
||||
<Label text="v1.0.0" textFill="#f2f2f2" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets left="-10.0" right="10.0" />
|
||||
</BorderPane.margin></Label>
|
||||
</right>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="10.0" top="-10.0" />
|
||||
</BorderPane.margin>
|
||||
</BorderPane>
|
||||
</bottom>
|
||||
<center>
|
||||
<FlowPane alignment="CENTER" maxHeight="150.0" maxWidth="220.0" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<TextField fx:id="usernameField" minWidth="220.0" promptText="Benutzername" />
|
||||
<TextField fx:id="secretQuestion" minWidth="220.0" promptText="Geheimfrage">
|
||||
<FlowPane.margin>
|
||||
<Insets bottom="5.0" top="5.0" />
|
||||
</FlowPane.margin></TextField>
|
||||
<HBox alignment="TOP_CENTER" maxWidth="220.0" minWidth="220.0" prefHeight="100.0" spacing="20.0">
|
||||
<children>
|
||||
<Button fx:id="registerButton" mnemonicParsing="false" onMouseClicked="#resetPasswordClicked" text="Passwort zurücksetzen" />
|
||||
<Button fx:id="backButton" mnemonicParsing="false" onMouseClicked="#backButtonClicked" text="Zurück" />
|
||||
</children>
|
||||
<FlowPane.margin>
|
||||
<Insets top="5.0" />
|
||||
</FlowPane.margin>
|
||||
</HBox>
|
||||
</children>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="20.0" />
|
||||
</BorderPane.margin>
|
||||
</FlowPane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="92.0" prefWidth="520.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<VBox prefHeight="42.0" prefWidth="520.0">
|
||||
<children>
|
||||
<HBox prefHeight="106.0" prefWidth="520.0" style="-fx-background-color: #f5f5dc;">
|
||||
<children>
|
||||
<Label alignment="CENTER" prefHeight="43.0" prefWidth="215.0" text="Poll" textAlignment="CENTER" />
|
||||
<Label id="voteField" alignment="CENTER" contentDisplay="CENTER" prefHeight="43.0" prefWidth="222.0" text="Votes" />
|
||||
<Label id="expireDate" alignment="CENTER" prefHeight="43.0" prefWidth="176.0" text="ExpiringDate" />
|
||||
</children>
|
||||
</HBox>
|
||||
<Text id="pollText" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" textAlignment="CENTER" wrappingWidth="520.0" />
|
||||
<HBox maxHeight="-Infinity" prefHeight="23.0" prefWidth="520.0">
|
||||
<children>
|
||||
<Button id="VoteForButton" maxHeight="16.0" mnemonicParsing="false" prefHeight="16.0" prefWidth="328.0" text="Vote For" />
|
||||
<Button id="voteAgainstButton" maxHeight="-Infinity" mnemonicParsing="false" prefHeight="16.0" prefWidth="327.0" text="Vote against" />
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Hyperlink?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" stylesheets="@../css/md_profile_settings.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.ProfileSettingsController">
|
||||
<left>
|
||||
<VBox alignment="TOP_CENTER" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #0079BF;" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<ImageView fx:id="profilePicture" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/justDoIt.jpg" />
|
||||
</image>
|
||||
<VBox.margin>
|
||||
<Insets bottom="7.0" />
|
||||
</VBox.margin>
|
||||
</ImageView>
|
||||
<Hyperlink fx:id="changePictureLink" onMouseClicked="#changePictureLinkClicked" text="Ändern" textFill="#f2f2f2" />
|
||||
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/logo.png" />
|
||||
</image>
|
||||
<VBox.margin>
|
||||
<Insets top="150.0" />
|
||||
</VBox.margin>
|
||||
</ImageView>
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="20.0">
|
||||
<children>
|
||||
<Label text="© SEPboard - 2017" textFill="#f2f2f2" />
|
||||
<Label text="v1.0.0" textFill="#f2f2f2" />
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets top="40.0" />
|
||||
</padding>
|
||||
</VBox>
|
||||
</left>
|
||||
<right>
|
||||
<VBox prefHeight="200.0" prefWidth="600.0" spacing="10.0" style="-fx-background-color: #F2F2F2;" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<TextField fx:id="surname" promptText="Vorname" />
|
||||
<TextField fx:id="lastname" promptText="Nachname" />
|
||||
<TextField fx:id="username" promptText="Benutzername" />
|
||||
<TextField fx:id="password" promptText="Passwort">
|
||||
<VBox.margin>
|
||||
<Insets top="20.0" />
|
||||
</VBox.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="approvedPassword" promptText="Passwort bestätigen" />
|
||||
<HBox alignment="CENTER" prefWidth="200.0" spacing="20.0">
|
||||
<children>
|
||||
<Button mnemonicParsing="false" onMouseClicked="#changeButtonClicked" text="Ändern" />
|
||||
<Button fx:id="abortButton" mnemonicParsing="false" onMouseClicked="#abortButtonClicked" text="Abbrechen" />
|
||||
</children>
|
||||
<VBox.margin>
|
||||
<Insets top="40.0" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets left="40.0" right="40.0" top="40.0" />
|
||||
</padding>
|
||||
</VBox>
|
||||
</right>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.net.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.net.URL?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.FlowPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: #0079BF;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.RegistrationController">
|
||||
<top>
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #F2F2F2;" BorderPane.alignment="CENTER">
|
||||
<center>
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/logo.png" />
|
||||
</image>
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</ImageView>
|
||||
<Label text="SEPboard" textFill="#0079bf">
|
||||
<font>
|
||||
<Font name="Market-Regular" size="100.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</top>
|
||||
<bottom>
|
||||
<BorderPane BorderPane.alignment="CENTER">
|
||||
<center>
|
||||
<Label text="© SEPboard - 2017" textFill="#f2f2f2" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets />
|
||||
</BorderPane.margin></Label>
|
||||
</center>
|
||||
<right>
|
||||
<Label text="v1.0.0" textFill="#f2f2f2" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets left="-10.0" right="10.0" />
|
||||
</BorderPane.margin></Label>
|
||||
</right>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="10.0" top="-10.0" />
|
||||
</BorderPane.margin>
|
||||
</BorderPane>
|
||||
</bottom>
|
||||
<center>
|
||||
<FlowPane alignment="CENTER" maxHeight="150.0" maxWidth="220.0" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<TextField fx:id="surnameField" minWidth="220.0" promptText="Vorname">
|
||||
<FlowPane.margin>
|
||||
<Insets bottom="5.0" />
|
||||
</FlowPane.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="lastnameField" minWidth="220.0" promptText="Nachname">
|
||||
<FlowPane.margin>
|
||||
<Insets bottom="5.0" />
|
||||
</FlowPane.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="usernameField" minWidth="220.0" promptText="Benutzername" />
|
||||
<PasswordField fx:id="passwordField" minWidth="220.0" promptText="Passwort">
|
||||
<FlowPane.margin>
|
||||
<Insets bottom="5.0" top="5.0" />
|
||||
</FlowPane.margin>
|
||||
</PasswordField>
|
||||
<HBox alignment="TOP_CENTER" maxWidth="220.0" minWidth="220.0" prefHeight="100.0" spacing="20.0">
|
||||
<children>
|
||||
<Button fx:id="registerButton" mnemonicParsing="false" onMouseClicked="#registerButtonClicked" text="Registrieren" />
|
||||
<Button fx:id="backButton" mnemonicParsing="false" onMouseClicked="#backButtonClicked" text="Zurück" />
|
||||
</children>
|
||||
<FlowPane.margin>
|
||||
<Insets top="5.0" />
|
||||
</FlowPane.margin>
|
||||
</HBox>
|
||||
</children>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="20.0" />
|
||||
</BorderPane.margin>
|
||||
</FlowPane>
|
||||
</center>
|
||||
<stylesheets>
|
||||
<URL value="@../css/md_login.css" />
|
||||
<URL value="@../css/md_login.css" />
|
||||
</stylesheets>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.geometry.Rectangle2D?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: #0079BF;" stylesheets="@../css/md_userhub.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.UserhubController">
|
||||
<left>
|
||||
<BorderPane prefWidth="550.0" style="-fx-background-color: #F2F2F2;" BorderPane.alignment="CENTER">
|
||||
<top>
|
||||
<Label text="Teams" BorderPane.alignment="CENTER_LEFT">
|
||||
<BorderPane.margin>
|
||||
<Insets left="5.0" top="5.0" />
|
||||
</BorderPane.margin>
|
||||
<font>
|
||||
<Font name="System Bold" size="20.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</top>
|
||||
<center>
|
||||
<TableView fx:id="listOfAllGroups" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<columns>
|
||||
<TableColumn fx:id="teamname" prefWidth="355.0" text="Teamname" />
|
||||
<TableColumn fx:id="chat" minWidth="0.0" prefWidth="85.0" text="Chat" />
|
||||
<TableColumn fx:id="taskboard" minWidth="0.0" prefWidth="109.0" text="Taskboard" />
|
||||
</columns>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="5.0" left="5.0" />
|
||||
</BorderPane.margin>
|
||||
</TableView>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</left>
|
||||
<right>
|
||||
<BorderPane prefWidth="250.0" BorderPane.alignment="CENTER">
|
||||
<top>
|
||||
<Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #f2f2f2;" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets left="5.0" right="5.0" top="35.0" />
|
||||
</BorderPane.margin>
|
||||
<children>
|
||||
<ImageView fx:id="userIcon" fitHeight="98.0" fitWidth="79.0" layoutX="20.0" layoutY="20.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/profile.jpg" />
|
||||
</image>
|
||||
<viewport>
|
||||
<Rectangle2D />
|
||||
</viewport>
|
||||
</ImageView>
|
||||
<Label layoutX="120.0" layoutY="22.0" text="username" />
|
||||
<Label layoutX="118.0" layoutY="41.0" text="Status" />
|
||||
<Button layoutX="158.0" layoutY="148.0" mnemonicParsing="false" onMouseClicked="#logoutButtonClicked" text="Logout" />
|
||||
<Button fx:id="profileSettingsButton" layoutX="20.0" layoutY="148.0" mnemonicParsing="false" onMouseClicked="#profilSettingsButtonClicked" text="Profileinstellungen" />
|
||||
</children>
|
||||
</Pane>
|
||||
</top>
|
||||
</BorderPane>
|
||||
</right>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.geometry.Rectangle2D?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: #0079BF;" stylesheets="@../css/md_userhub.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.UserhubController">
|
||||
<left>
|
||||
<BorderPane prefWidth="550.0" style="-fx-background-color: #F2F2F2;" BorderPane.alignment="CENTER">
|
||||
<top>
|
||||
<Label text="Teams" BorderPane.alignment="CENTER_LEFT">
|
||||
<BorderPane.margin>
|
||||
<Insets left="5.0" top="5.0" />
|
||||
</BorderPane.margin>
|
||||
<font>
|
||||
<Font name="System Bold" size="20.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</top>
|
||||
<center>
|
||||
<TableView fx:id="tableID" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<columns>
|
||||
<TableColumn fx:id="teamname" prefWidth="355.0" text="Teamname" />
|
||||
<TableColumn fx:id="chat" minWidth="0.0" prefWidth="85.0" text="Chat" />
|
||||
<TableColumn fx:id="taskboard" minWidth="0.0" prefWidth="109.0" text="Taskboard" />
|
||||
</columns>
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="5.0" left="5.0" />
|
||||
</BorderPane.margin>
|
||||
</TableView>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</left>
|
||||
<right>
|
||||
<BorderPane prefWidth="250.0" BorderPane.alignment="CENTER">
|
||||
<top>
|
||||
<Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #f2f2f2;" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets left="5.0" right="5.0" top="35.0" />
|
||||
</BorderPane.margin>
|
||||
<children>
|
||||
<ImageView fx:id="userIcon" fitHeight="98.0" fitWidth="79.0" layoutX="20.0" layoutY="20.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../image/profile.jpg" />
|
||||
</image>
|
||||
<viewport>
|
||||
<Rectangle2D />
|
||||
</viewport>
|
||||
</ImageView>
|
||||
<Label layoutX="120.0" layoutY="22.0" text="username" />
|
||||
<Label layoutX="118.0" layoutY="41.0" text="Status" />
|
||||
<Button layoutX="158.0" layoutY="148.0" mnemonicParsing="false" onMouseClicked="#logoutButtonClicked" text="Logout" />
|
||||
<Button fx:id="profileSettingsButton" layoutX="20.0" layoutY="148.0" mnemonicParsing="false" onMouseClicked="#profilSettingsButtonClicked" text="Profileinstellungen" />
|
||||
</children>
|
||||
</Pane>
|
||||
</top>
|
||||
</BorderPane>
|
||||
</right>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,7 @@
|
||||
package new_build.models.client_interfaces;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 15.06.2017.
|
||||
*/
|
||||
public interface ClientInputListener extends Runnable {
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package new_build.models.client_interfaces;
|
||||
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.User;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public interface ClientView {
|
||||
|
||||
/**
|
||||
* gui application or console application implement this
|
||||
* general View-Handling methods
|
||||
*/
|
||||
|
||||
void init();
|
||||
void displayMessage(Message message);
|
||||
void reactToMessage(Message serverstatus);
|
||||
void close();
|
||||
void loadMessages(HashMap<Group, LinkedList<Message>> messageMap);
|
||||
void addGroup(Group groupInvitedTo);
|
||||
void addMessage(Group groupSendTo, Message message);
|
||||
void updateProfileInfo(User user);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package new_build.models.common;
|
||||
|
||||
import new_build.models.common.messages.Message;
|
||||
|
||||
|
||||
public interface Controller<E extends Message> {
|
||||
|
||||
Class<E> getExpectedClass();
|
||||
|
||||
void processMessage(Message message);
|
||||
|
||||
boolean keepRunning();
|
||||
|
||||
void close();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package new_build.models.common;
|
||||
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.Connection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
public class IOLoop<T extends Message> extends Thread{
|
||||
|
||||
private final Connection c;
|
||||
private final Controller assignedController;
|
||||
|
||||
public IOLoop(Connection c, Controller controller){
|
||||
this.c = c;
|
||||
this.assignedController = controller;
|
||||
}
|
||||
|
||||
public void notify(T message){
|
||||
try {
|
||||
this.c.sendMessage(message);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void startConnectionLoop(){
|
||||
System.out.println("Connection loop started");
|
||||
Thread inputThread = new Thread(() -> {
|
||||
while(assignedController.keepRunning()){
|
||||
Message m = null;
|
||||
try {
|
||||
m = c.getNextMessage();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Message recieved!");
|
||||
assignedController.processMessage(m);
|
||||
}
|
||||
});
|
||||
inputThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.startConnectionLoop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package new_build.models.common.data;
|
||||
|
||||
// Every Sendable is a bytearray
|
||||
public interface Sendable {
|
||||
|
||||
Class getType();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package new_build.models.common.data;
|
||||
|
||||
|
||||
import sun.misc.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class SepFile implements Sendable, Serializable{
|
||||
|
||||
private static final long serialVersionUID = -8339564571735716757L;
|
||||
private byte[] file;
|
||||
|
||||
public SepFile(byte[] file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public SepFile(File f){
|
||||
byte[] b = new byte[(int) f.length()];
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(f);
|
||||
fileInputStream.read(b);
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
System.out.print((char)b[i]);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("File Not Found.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e1) {
|
||||
System.out.println("Error Reading The File.");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
this.file = b;
|
||||
}
|
||||
|
||||
public byte[] getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(byte[] file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return SepFile.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package new_build.models.common.data;
|
||||
|
||||
|
||||
public class SepPic implements Sendable{
|
||||
private byte[] picture;
|
||||
|
||||
public SepPic(byte[] picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
public byte[] getFile() {
|
||||
return picture;
|
||||
}
|
||||
|
||||
public void setFile(byte[] picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return SepPic.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package new_build.models.common.messages;
|
||||
|
||||
public enum Command {
|
||||
|
||||
LOGIN("login"), REGISTER("register"),
|
||||
SENDMESSAGE("send"), CHANGEUSER("changeuser"),
|
||||
CHANGEPROFILEPIC("changepic"), LOGOUT("logout"),
|
||||
ADDGROUP("addgroup"), ADDUSER("adduser"),
|
||||
REMOVEUSER("removeuser"), CHANGEROLE("changerole"), UNKNOWN(""),
|
||||
ADDPOLL("addpoll"), VOTE_POLL("vote");
|
||||
|
||||
private String accordingString;
|
||||
|
||||
Command(String accordingString){
|
||||
this.accordingString = accordingString;
|
||||
}
|
||||
|
||||
private static Command[] getAllValues(){
|
||||
Command[] returnArray = {LOGIN, REGISTER, SENDMESSAGE, CHANGEUSER, LOGOUT, ADDGROUP,
|
||||
REMOVEUSER, CHANGEROLE, UNKNOWN, ADDPOLL, VOTE_POLL};
|
||||
return returnArray;
|
||||
}
|
||||
public static Command getCommandFromString(String s){
|
||||
if(s== null) return UNKNOWN;
|
||||
for(Command c : Command.getAllValues()){
|
||||
if(s.equals(c.accordingString)) return c;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package new_build.models.common.messages;
|
||||
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.User;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Date;
|
||||
|
||||
public class Message implements Serializable,Sendable {
|
||||
|
||||
private static final long serialVersionUID = 12371281239L;
|
||||
private String content;
|
||||
private Sendable extension;
|
||||
private User sendingUser;
|
||||
private Group group;
|
||||
private Enum controlHeader;
|
||||
private Date timeStamp;
|
||||
|
||||
public Message(Group group, Enum controllerHeader, User sendingUser, String content, Sendable extension){
|
||||
this.group = group;
|
||||
this.extension = extension;
|
||||
this.content = content;
|
||||
this.controlHeader = controllerHeader;
|
||||
this.sendingUser = sendingUser;
|
||||
this.timeStamp = new Date(new java.util.Date().getTime());
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public Sendable getExtension() {
|
||||
return extension;
|
||||
}
|
||||
|
||||
public boolean hasExtension() {
|
||||
return (this.extension != null);
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public Class getType(){
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public Class<? extends Enum> getControlHeaderType(){
|
||||
return controlHeader.getClass();
|
||||
}
|
||||
|
||||
public Enum getControlHeader(){
|
||||
return this.controlHeader;
|
||||
}
|
||||
|
||||
public User getSendingUser(){
|
||||
return this.sendingUser;
|
||||
}
|
||||
|
||||
public void setTimeStamp(Date timeStamp){
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
public Date getTimeStamp(){
|
||||
return this.timeStamp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package new_build.models.common.messages;
|
||||
|
||||
import javafx.beans.value.ObservableValueBase;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 19.06.2017.
|
||||
*/
|
||||
public class MessageChangeObserver extends ObservableValueBase<Message> {
|
||||
|
||||
private Message message;
|
||||
|
||||
public void setMessage(Message message){
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Message getValue() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package new_build.models.common.messages;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 19.06.2017.
|
||||
*/
|
||||
public class MessageObserver {
|
||||
|
||||
private Message message;
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(Message message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package new_build.models.common.messages;
|
||||
|
||||
|
||||
public enum ServerStatus {
|
||||
|
||||
SESSION_EXPIRED, NEW_MESSAGE, LOGIN_FAILED, LOGIN_SUCCESSFUL,
|
||||
LOGOUT_SUCCESSFUL, COMMAND_UNKNOWN, PERMISSION_DENIED, REGISTRATION_FAILED, REGISTRATION_SUCCESSFUL,
|
||||
MEMBER_JOINED, ROLE_CHANGED, POLL_CREATED, POLL_FINISHED, VOTE_SUCCESSFUL, VOTE_FAILED,
|
||||
PROFILE_CHANGE_SUCCESSFUL, ERR_EXECUTING_COMMAND, GROUP_CREATED, MEMBER_LEFT;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package new_build.models.common.polls;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
import new_build.models.network_organisation.User;
|
||||
|
||||
public class Poll implements Sendable, Serializable{
|
||||
|
||||
|
||||
private static final long serialVersionUID = 3152539989109693280L;
|
||||
private HashMap<User, Boolean> voteMap;
|
||||
private int pollID;
|
||||
private String pollText;
|
||||
private Date expiringDate;
|
||||
private boolean isRunning;
|
||||
|
||||
/*
|
||||
* Poll-Constructor has parameters pollID, groupID, pollText and expiringDate
|
||||
* DO NOT CHANGE PARAMETERS
|
||||
*/
|
||||
public Poll (int pollID, String pollText, Date expiringDate){
|
||||
this.pollID = pollID;
|
||||
this.pollText = pollText;
|
||||
this.expiringDate = expiringDate;
|
||||
this.isRunning = this.checkDate();
|
||||
}
|
||||
|
||||
public LinkedList<User> getVotesFor(){
|
||||
LinkedList<User> userList = new LinkedList<>();
|
||||
for(User u : this.voteMap.keySet()){
|
||||
if(this.voteMap.get(u) != null && this.voteMap.get(u)) userList.add(u);
|
||||
}
|
||||
return userList;
|
||||
|
||||
}
|
||||
public LinkedList<User> getVotesAgainst(){
|
||||
LinkedList<User> userList = new LinkedList<>();
|
||||
for(User u : this.voteMap.keySet()){
|
||||
if(this.voteMap.get(u) != null && !this.voteMap.get(u)) userList.add(u);
|
||||
}
|
||||
return userList;
|
||||
|
||||
}public LinkedList<User> getVotesAbstensions(){
|
||||
LinkedList<User> userList = new LinkedList<>();
|
||||
for(User u : this.voteMap.keySet()){
|
||||
if(this.voteMap.get(u) == null) userList.add(u);
|
||||
}
|
||||
return userList;
|
||||
|
||||
}
|
||||
|
||||
public int getPollID() {
|
||||
return pollID;
|
||||
}
|
||||
|
||||
public HashMap<User, Boolean> getVoteMap(){
|
||||
return this.voteMap;
|
||||
}
|
||||
|
||||
public String getPollText() {
|
||||
return pollText;
|
||||
}
|
||||
|
||||
public Date getExpiringDate() {
|
||||
return expiringDate;
|
||||
}
|
||||
|
||||
public boolean getIsRunning() {
|
||||
return this.isRunning;
|
||||
}
|
||||
|
||||
protected boolean checkDate(){
|
||||
/**
|
||||
* This method returns true when current Date is after expiringDate,
|
||||
* changes isRunning of the poll
|
||||
*/
|
||||
Date now = new Date(System.currentTimeMillis()); //TODO Check whether this method is running correctly
|
||||
if (now.after(expiringDate)) {
|
||||
this.setIsRunning(false);
|
||||
return true;
|
||||
} else {
|
||||
this.setIsRunning(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void addVote(User votingUser, Boolean voteValue){
|
||||
checkDate();
|
||||
if(this.isRunning) this.voteMap.put(votingUser, voteValue);
|
||||
}
|
||||
|
||||
private void setIsRunning(boolean isRunning){
|
||||
this.isRunning = isRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Poll> getType() {
|
||||
return Poll.class;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.pollID = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
package new_build.models.common.polls;
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Vote implements Serializable, Sendable {
|
||||
|
||||
private static final long serialVersionUID = -4714045047489013951L;
|
||||
|
||||
private Boolean value;
|
||||
private int pollVotedIn;
|
||||
|
||||
public Vote(int pollId, Boolean value){
|
||||
this.pollVotedIn = pollId;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getPollVotedIn() {
|
||||
return pollVotedIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Vote> getType() {
|
||||
return Vote.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
|
||||
import new_build.models.common.messages.Message;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
|
||||
|
||||
public class Connection {
|
||||
|
||||
private Socket connectionSocket;
|
||||
private ObjectInputStream ois;
|
||||
private ObjectOutputStream oos;
|
||||
|
||||
/**
|
||||
* This class handles the input and output(as ObjectStream) from the given Socket
|
||||
* @param connectionSocket Given socket, whose Stream you should be reading from or writing to
|
||||
* @throws IOException Exception occurs when one of the stream encounter a problem
|
||||
*/
|
||||
public Connection(Socket connectionSocket) throws IOException {
|
||||
this.connectionSocket = connectionSocket;
|
||||
this.oos = new ObjectOutputStream(connectionSocket.getOutputStream());
|
||||
this.ois = new ObjectInputStream(connectionSocket.getInputStream());
|
||||
System.out.println("connection established!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Message from stream
|
||||
* @return the Message in the stream
|
||||
* @throws IOException Exception occurs when outputStream encounters a problem
|
||||
* @throws ClassNotFoundException Exception occurs when stream can't be read from, or is empty
|
||||
*/
|
||||
public Message getNextMessage() throws IOException, ClassNotFoundException {
|
||||
try{
|
||||
return ((Message) ois.readObject());
|
||||
} catch(SocketException e){
|
||||
System.out.println(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message over the outputStream
|
||||
* @param m the Message to be sent over the outputStream
|
||||
* @throws IOException Exception occurs when message cant be sent
|
||||
*/
|
||||
public void sendMessage(Message m) throws IOException {
|
||||
oos.writeObject(m);
|
||||
oos.flush();
|
||||
System.out.println("message send");
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the socket and the streams
|
||||
* @param ignoreErrors Option to ignoreErrors or not, example: ignore errors, when logging out, but not when server
|
||||
* crashes
|
||||
*/
|
||||
public void close(boolean ignoreErrors){
|
||||
try {
|
||||
ois.close();
|
||||
oos.close();
|
||||
connectionSocket.close();
|
||||
} catch (IOException e){
|
||||
if(!ignoreErrors) e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Group implements Serializable{
|
||||
|
||||
private static int maxId;
|
||||
|
||||
public static final Group DEFAULT_GROUP = new Group(-1, "default");
|
||||
private static final long serialVersionUID = 12312L;
|
||||
private int groupId;
|
||||
private String groupName;
|
||||
|
||||
public Group(int groupId, String groupName){
|
||||
if(groupId >= maxId) maxId = groupId;
|
||||
this.groupId = groupId;
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public static int getNextId() {
|
||||
return ++maxId;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return groupName;
|
||||
}
|
||||
public int getId(){
|
||||
return groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Group)) return false;
|
||||
Group g = ((Group) obj);
|
||||
|
||||
return (g.getName().equals(this.getName()) && g.getId() == this.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.polls.Poll;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 15.06.2017.
|
||||
*/
|
||||
public class GroupInformation implements Serializable, Sendable{
|
||||
|
||||
public GroupInformation(LinkedList<Message> messagesInChatRoom, HashMap<User, PermissionRole>
|
||||
roleMap, LinkedList<Poll> polls) {
|
||||
this.messagesInChatRoom = messagesInChatRoom;
|
||||
this.roleMap = roleMap;
|
||||
this.polls = polls;
|
||||
}
|
||||
|
||||
private LinkedList<Message> messagesInChatRoom;
|
||||
private HashMap<User, PermissionRole> roleMap;
|
||||
private LinkedList<Poll> polls;
|
||||
private UserLogin loggedInUser;
|
||||
|
||||
public LinkedList<Message> getMessagesInChatRoom() {
|
||||
return messagesInChatRoom;
|
||||
}
|
||||
|
||||
public HashMap<User, PermissionRole> getRoleMap() {
|
||||
return roleMap;
|
||||
}
|
||||
|
||||
public LinkedList<Poll> getPolls() {
|
||||
return polls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return GroupInformation.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 14.06.2017.
|
||||
*/
|
||||
public class LoginData implements Serializable, Sendable{
|
||||
|
||||
private static final long serialVersionUID = 2098781514370169741L;
|
||||
private HashMap<Group, GroupInformation> groupInformationMap;
|
||||
private UserLogin loggedInUser;
|
||||
|
||||
public LoginData(HashMap<Group, GroupInformation> groupInformationMap, UserLogin loggedInUser) {
|
||||
this.groupInformationMap = groupInformationMap;
|
||||
this.loggedInUser = loggedInUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return LoginData.class;
|
||||
}
|
||||
|
||||
public HashMap<Group, GroupInformation> getGroupInformationMap() {
|
||||
return groupInformationMap;
|
||||
}
|
||||
|
||||
public UserLogin getLoggedInUser() {
|
||||
return loggedInUser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 17.06.2017.
|
||||
*/
|
||||
public class Pair<A, B> implements Sendable, Serializable{
|
||||
|
||||
private static final long serialVersionUID = -2494341070234283693L;
|
||||
private A a;
|
||||
private B b;
|
||||
|
||||
public Pair(A a, B b){
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public A getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public B getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return a.hashCode()+b.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if((obj instanceof Pair)) {
|
||||
Pair p = ((Pair) obj);
|
||||
return (p.getA().equals(getA()) && p.getB().equals(getB()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return Pair.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.polls.Poll;
|
||||
import new_build.models.common.polls.Vote;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
import new_build.server.control.ServerController;
|
||||
import new_build.server.control.observation.MessageInputListener;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class TeamInfo implements Serializable, Sendable {
|
||||
|
||||
private static final long serialVersionUID = 2387034548297739747L;
|
||||
private LinkedList<MessageInputListener> usersListening;
|
||||
private LinkedList<Message> messagesInChatRoom;
|
||||
private HashMap<User, PermissionRole> roleMap;
|
||||
private LinkedList<Poll> polls;
|
||||
|
||||
public TeamInfo(){
|
||||
this.usersListening = new LinkedList<>();
|
||||
this.messagesInChatRoom = new LinkedList<>();
|
||||
this.roleMap = new HashMap<>();
|
||||
this.polls = new LinkedList<>();
|
||||
}
|
||||
|
||||
public TeamInfo(LinkedList<Message> messagesInChatRoom, HashMap<User, PermissionRole> roleMap, LinkedList<Poll> polls) {
|
||||
this.messagesInChatRoom = messagesInChatRoom;
|
||||
this.roleMap = roleMap;
|
||||
this.polls = polls;
|
||||
this.usersListening = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void addListener(MessageInputListener listener){
|
||||
if(!usersListening.contains(listener))
|
||||
usersListening.add(listener);
|
||||
}
|
||||
public void removeListener(MessageInputListener listener){
|
||||
usersListening.remove(listener);
|
||||
}
|
||||
private Poll getPollById(int id){
|
||||
return null;
|
||||
}
|
||||
public void addMessageToChatroom(Message message){
|
||||
messagesInChatRoom.add(message);
|
||||
for(MessageInputListener listener : usersListening){
|
||||
System.out.println("found observer");
|
||||
listener.sendInformation(message);
|
||||
}
|
||||
}
|
||||
|
||||
public LinkedList<Message> getMessagesInChatRoom() {
|
||||
return messagesInChatRoom;
|
||||
}
|
||||
|
||||
public LinkedList<Poll> getPolls() {
|
||||
return polls;
|
||||
}
|
||||
public HashMap<User, PermissionRole> getRoleMap(){
|
||||
return this.roleMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return TeamInfo.class;
|
||||
}
|
||||
|
||||
public void addPoll(Poll p) {
|
||||
p.setId(++ServerController.maxPollID);
|
||||
polls.add(p);
|
||||
|
||||
}
|
||||
|
||||
public void addVote(User voter, Vote v) {
|
||||
|
||||
Poll pollVotingIn = getPollById(v.getPollVotedIn());
|
||||
if(pollVotingIn.getIsRunning()) pollVotingIn.getVoteMap().put(voter, v.getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class User implements Sendable, Serializable {
|
||||
private static final long serialVersionUID = 12387129738L;
|
||||
private int userID;
|
||||
private String userName;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
transient private BufferedImage profilePic; //placeholder for now
|
||||
|
||||
public User(int userID, String userName, String firstName, String lastName, BufferedImage profilePic) {
|
||||
this.userID = userID;
|
||||
this.userName = userName;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.profilePic = profilePic;
|
||||
}
|
||||
|
||||
public User(int userID, String userName, String firstName, String lastName) {
|
||||
this.userID = userID;
|
||||
this.userName = userName;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.profilePic = null; //later default pic
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getUserName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof User)) return false;
|
||||
User user = (User) obj;
|
||||
return (user.getUserName().equals(this.getUserName()));
|
||||
}
|
||||
|
||||
public int getID(){
|
||||
return userID;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public BufferedImage getProfilePic() {
|
||||
return profilePic;
|
||||
}
|
||||
|
||||
public void setProfilePic(BufferedImage profilePic) {
|
||||
this.profilePic = profilePic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return User.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package new_build.models.network_organisation;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class UserLogin extends User implements Serializable{
|
||||
|
||||
|
||||
private static final long serialVersionUID = 71558279125734178L;
|
||||
private String password;
|
||||
|
||||
public UserLogin(int userID, String userName, String firstName, String lastName, String password) {
|
||||
super(userID, userName, firstName, lastName);
|
||||
this.password = password;
|
||||
}
|
||||
public User removePassword(){
|
||||
return new User(this.getID(), this.getUserName(), this.getFirstName(), this.getLastName());
|
||||
}
|
||||
public String getPassword(){
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return UserLogin.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof UserLogin)) return false;
|
||||
UserLogin login = ((UserLogin) obj);
|
||||
return (super.equals(obj)&&login.getPassword().equals(this.getPassword()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package new_build.server.constants;
|
||||
public class DEBUG {
|
||||
|
||||
public static final boolean SERVER_DEBUG_MESSAGES = true;
|
||||
public static final boolean SERVER_DEBUG_ASSERTIONS = true;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package new_build.server.constants;
|
||||
|
||||
|
||||
/**
|
||||
* This Enum assigns the permissions to the role, roles will be assigned to every group
|
||||
* ServerAdmins get their own group
|
||||
*/
|
||||
|
||||
public enum PermissionRole {
|
||||
|
||||
OWNER(7),
|
||||
TEAMLEADER(3),
|
||||
ADMIN(7),
|
||||
USER(1),
|
||||
NONE(0);
|
||||
|
||||
private int roles;
|
||||
|
||||
PermissionRole(int roles){
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public boolean hasUserRights(){
|
||||
return (this.roles % 2 >= 1);
|
||||
}
|
||||
public boolean hasTeamleaderRights(){
|
||||
return (this.roles % 4 >= 2);
|
||||
}
|
||||
public boolean hasAdminRights(){
|
||||
return (this.roles % 8 >= 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package new_build.server.control;
|
||||
|
||||
|
||||
import new_build.models.common.messages.Command;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.TeamInfo;
|
||||
import new_build.models.network_organisation.User;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
import new_build.server.constants.DEBUG;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
import new_build.server.control.io.ConnectionProcessor;
|
||||
import new_build.server.database.*;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private static final long TIME_TILL_SESSION_EXPIRES = 6000000; // ten minutes
|
||||
|
||||
private ServerController controller;
|
||||
private UserLogin loggedInUser;
|
||||
private User systemUser = new User(-1, "SYSTEM", "", "", null);
|
||||
|
||||
public CommandManager(ServerController controller){
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
|
||||
protected PermissionRole getPermissionLevelInGroup(int userId, Group group){
|
||||
return null;
|
||||
}
|
||||
|
||||
public Message handleCommandAndReturnMessage(Message m){
|
||||
if(m == null) {
|
||||
System.out.println("message null");
|
||||
return null;
|
||||
}
|
||||
if (DEBUG.SERVER_DEBUG_ASSERTIONS) assert m.getContent() != null;
|
||||
if(DEBUG.SERVER_DEBUG_MESSAGES) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Command: ");
|
||||
builder.append(m.getControlHeader());
|
||||
builder.append(" Content: ");
|
||||
builder.append(m.getContent());
|
||||
System.out.println(builder.toString());
|
||||
}
|
||||
/*
|
||||
switch(((Command) m.getControlHeader())){
|
||||
case LOGIN: {
|
||||
String[] credentials = m.getContent().split(" ");
|
||||
if (credentials.length == 2) {
|
||||
String username = credentials[0];
|
||||
String password = credentials[1];
|
||||
UserLogin loginTry = controller.validateLogin(username, password);
|
||||
if (loginTry != null) {
|
||||
TeamInfo clientInfo = controller.getLoginUpdates(loginTry);
|
||||
this.loggedInUser = loginTry;
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.LOGIN_SUCCESSFUL, loginTry, "login successful", clientInfo);
|
||||
}
|
||||
}
|
||||
else return new Message(Group.DEFAULT_GROUP, ServerStatus.LOGIN_FAILED, )
|
||||
}/*
|
||||
case "logout": {
|
||||
if (loggedInUser == null) return new Message(Group.DEFAULT_GROUP, ServerStatus.SESSION_EXPIRED,
|
||||
null, "cant log out, not logged in", null);
|
||||
this.logout();
|
||||
return MessageFormatter.createMessage(m, systemUser, ServerStatus.LOGOUT_SUCCESSFUL);
|
||||
}
|
||||
case "send": {
|
||||
if(!validateSession(m.getSessionKey())) return MessageFormatter.createMessage(m, systemUser, ServerStatus.SESSION_EXPIRED);
|
||||
if(this.getPermissionLevelInGroup(currentSession.getUser().getId(), m.getGroup()).hasUserRights()){
|
||||
messageLib.writeMessageToDatabase(m);
|
||||
return MessageFormatter.createMessage(m, currentSession.getUser(), ServerStatus.NEW_MESSAGE);
|
||||
} else return MessageFormatter.createMessage(m, currentSession.getUser(), ServerStatus.MISSION_DENIED);
|
||||
}
|
||||
case "register": {
|
||||
if(currentSession == null){
|
||||
String[] userInformation = m.getContent().split(" ");
|
||||
if (userInformation.length == 5){
|
||||
// This doesn't work yet, because I don't fckin know how I should be savin' those pictures
|
||||
userLib.registerUser(userInformation[0], userInformation[1], userInformation[2],
|
||||
new File(userInformation[3]), userInformation[4]);
|
||||
return MessageFormatter.createMessage(m, systemUser, ServerStatus.REGISTRATION_SUCCESSFUL);
|
||||
|
||||
}else if(userInformation.length == 4){
|
||||
userLib.registerUser(userInformation[0], userInformation[1], userInformation[2], userInformation[3]);
|
||||
return MessageFormatter.createMessage(m, systemUser, ServerStatus.REGISTRATION_SUCCESSFUL);
|
||||
|
||||
}else{
|
||||
return MessageFormatter.createMessage(m, systemUser, ServerStatus.REGISTRATION_FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
case "changePassword": {
|
||||
if (currentSession != null){
|
||||
int userID = userLib.getUserBySessionKey(currentSession.getSessionKey());
|
||||
String newPassword = m.getContent();
|
||||
// todo
|
||||
userLib.changePassword(userID, newPassword);
|
||||
return MessageFormatter.createMessage(m, systemUser, ServerStatus.REGISTRATION_SUCCESSFUL);
|
||||
|
||||
}
|
||||
}
|
||||
// Add user to group
|
||||
case "add": {
|
||||
return MessageFormatter.createMessage(m, systemUser, ServerStatus.COMMAND_UNKNOWN);
|
||||
|
||||
}
|
||||
default: return MessageFormatter.createMessage(m, systemUser, ServerStatus.COMMAND_UNKNOWN);
|
||||
}*/
|
||||
return null;
|
||||
}
|
||||
public void logout(){
|
||||
if (loggedInUser == null) return;
|
||||
this.controller.removeUserListener(loggedInUser, null);
|
||||
this.loggedInUser = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
package new_build.server.control;
|
||||
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.common.polls.Poll;
|
||||
import new_build.models.network_organisation.*;
|
||||
import new_build.server.constants.DEBUG;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
import new_build.server.control.io.ConnectionProcessor;
|
||||
import new_build.server.control.observation.MessageInputListener;
|
||||
import new_build.server.database.GroupLib;
|
||||
import new_build.server.database.MessageLib;
|
||||
import new_build.server.database.PollLib;
|
||||
import new_build.server.database.UserLib;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.sql.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ServerController {
|
||||
public static volatile int maxPollID = 0;
|
||||
private static final int PORT = 1337;
|
||||
private volatile HashMap<Group, TeamInfo> teamMap;
|
||||
private volatile HashMap<UserLogin, LinkedList<Group>> userGroupMap;
|
||||
private LinkedList<ConnectionProcessor> connectionList;
|
||||
private volatile boolean serverShouldRun;
|
||||
private ServerSocket serverSocket;
|
||||
public static final User SYSTEM = new User(-1, "SYSTEM", "", "", null);
|
||||
private MessageLib messageLib;
|
||||
private PollLib pollLib;
|
||||
private GroupLib groupLib;
|
||||
private UserLib userLib;
|
||||
private Date initTime;
|
||||
//private CommandManager commandManager;
|
||||
//private ClientView terminal;
|
||||
|
||||
|
||||
public ServerController(){
|
||||
try {
|
||||
serverSocket = new ServerSocket(PORT);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Constructor of ServerController failed.\n" + e);
|
||||
}
|
||||
messageLib = new MessageLib();
|
||||
pollLib = new PollLib();
|
||||
groupLib = new GroupLib();
|
||||
userLib = new UserLib();
|
||||
connectionList = new LinkedList<>();
|
||||
teamMap = new HashMap<>();
|
||||
teamMap.put(Group.DEFAULT_GROUP, new TeamInfo());
|
||||
createTeamMap();
|
||||
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("Created TeamMap");
|
||||
userGroupMap = new HashMap<>();
|
||||
createUserGroupMap();
|
||||
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("Created UserGroupMap");
|
||||
serverShouldRun = true;
|
||||
initTime = new Date(new java.util.Date().getTime());
|
||||
waitForConsoleCommands();
|
||||
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("Server initialized at " + initTime);
|
||||
}
|
||||
|
||||
//region Database Stuff
|
||||
public HashMap<Group, TeamInfo> getTeamMap(){
|
||||
return this.teamMap;
|
||||
}
|
||||
|
||||
|
||||
public TeamInfo getTeamFromGroup(Group g){
|
||||
return teamMap.get(g);
|
||||
}
|
||||
|
||||
private void updateDB(){
|
||||
|
||||
//region update from teamMap
|
||||
for (Map.Entry<Group,TeamInfo> tm: teamMap.entrySet()){
|
||||
Group g = tm.getKey();
|
||||
TeamInfo ti = tm.getValue();
|
||||
|
||||
groupLib.insertGroupChanges(g);
|
||||
|
||||
for (Message m: ti.getMessagesInChatRoom()){
|
||||
messageLib.insertChanges(m, initTime);
|
||||
}
|
||||
|
||||
for(Map.Entry<User, PermissionRole> rm: ti.getRoleMap().entrySet()){
|
||||
User u = rm.getKey();
|
||||
PermissionRole pr = rm.getValue();
|
||||
groupLib.insertRoleChanges(g,u,pr);
|
||||
}
|
||||
|
||||
for (Poll p: ti.getPolls()){
|
||||
pollLib.insertChanges(p, g);
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
||||
//region update from userGroupMap
|
||||
for (Map.Entry<UserLogin,LinkedList<Group>> tm: userGroupMap.entrySet()){
|
||||
UserLogin ul = tm.getKey();
|
||||
|
||||
userLib.insertLoginChanges(ul);
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
||||
private void createTeamMap(){
|
||||
Group[] groups = groupLib.getAllGroups();
|
||||
for (Group g: groups) {
|
||||
LinkedList<Message> messageList = messageLib.getMessagesInGroup(g);
|
||||
HashMap<User, PermissionRole> roleMap = groupLib. getRolesInGroup(g);
|
||||
LinkedList<Poll> polls = pollLib.getPollsOfGroup(g);
|
||||
TeamInfo teamInfo = new TeamInfo(messageList, roleMap, polls);
|
||||
teamMap.put(g, teamInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void createUserGroupMap(){
|
||||
UserLogin[] userLogins = userLib.getAllUserLogin();
|
||||
for (UserLogin ul: userLogins){
|
||||
userGroupMap.put(ul,groupLib.getGroupsByUserID(ul.getID()));
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
public void notifyObservers(Message messageToSend){
|
||||
System.out.println("notifying observers...");
|
||||
this.teamMap.get(messageToSend.getGroup()).addMessageToChatroom(messageToSend);
|
||||
}
|
||||
|
||||
|
||||
public boolean serverShouldRun(){
|
||||
return this.serverShouldRun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the selected ConnectionThread to the LinkedList
|
||||
* @param cp is the selected ConnectionThread
|
||||
*/
|
||||
private void addConnection(ConnectionProcessor cp){
|
||||
connectionList.add(cp);
|
||||
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("added a connection - " + connectionList.size() + " total");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deletes the selected ConnectionProcessor from the LinkedList
|
||||
* @param cp is the selected ConnectionProcessor
|
||||
*/
|
||||
public void removeConnection(ConnectionProcessor cp){
|
||||
final boolean removed = connectionList.remove(cp);
|
||||
if (DEBUG.SERVER_DEBUG_MESSAGES) {
|
||||
if(removed) System.out.println("Removed a connection");
|
||||
else System.out.println("Tried but couldn't remove connection");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for incoming connection requests and creates a new thread for them
|
||||
* Adding the new Thread to the connectionList
|
||||
*/
|
||||
private void startConnectionLoop(){
|
||||
Thread connectionLoopThread = new Thread(() -> {
|
||||
while(serverShouldRun){
|
||||
Socket connectionSocket = null;
|
||||
try {
|
||||
connectionSocket = serverSocket.accept();
|
||||
// Generate a new thread for that user/connection
|
||||
ConnectionProcessor connectionProcessor = new ConnectionProcessor(new Connection(connectionSocket), this);
|
||||
this.addConnection(connectionProcessor);
|
||||
connectionProcessor.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("user connection failed!");
|
||||
continue; //trying to connect the next user (or give old one a new chance to connect)
|
||||
}
|
||||
}
|
||||
});
|
||||
connectionLoopThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loop to listen to ServerCommands
|
||||
*/
|
||||
|
||||
private void waitForConsoleCommands(){
|
||||
Thread waitForCommand = new Thread(() -> {
|
||||
Scanner s = new Scanner(System.in);
|
||||
String command;
|
||||
while(serverShouldRun){
|
||||
command = s.nextLine();
|
||||
if (command.contains("shutdown")){
|
||||
shutDown(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
waitForCommand.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes all connections the the clients
|
||||
*/
|
||||
|
||||
private void closeConnections(){
|
||||
for(ConnectionProcessor connection : connectionList) connection.closeConnection();
|
||||
//Server connections get reset/closed here
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts the server down
|
||||
* @param status Exit code
|
||||
*/
|
||||
private void shutDown(int status){
|
||||
closeConnections();
|
||||
updateDB(); // todo is this correct?
|
||||
serverShouldRun = false;
|
||||
System.out.println("Shutting down server... ");
|
||||
System.exit(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Server
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args){
|
||||
ServerController server = new ServerController();
|
||||
server.startConnectionLoop();
|
||||
}
|
||||
|
||||
public void removeUserListener(UserLogin loggedInUser, MessageInputListener inputListenerToRemove) {
|
||||
LinkedList<Group> groupsOfUser = this.userGroupMap.get(loggedInUser);
|
||||
for (Group g : groupsOfUser) {
|
||||
this.teamMap.get(g).removeListener(inputListenerToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
public void addUserListener(UserLogin loggedInUser, MessageInputListener inputListenerToAdd) {
|
||||
LinkedList<Group> groupsOfUser = this.userGroupMap.get(loggedInUser);
|
||||
for (Group g : groupsOfUser){
|
||||
this.teamMap.get(g).addListener(inputListenerToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
public UserLogin validateLogin(String username, String password) {
|
||||
for(UserLogin user : this.userGroupMap.keySet()){
|
||||
if(user.getUserName().equals(username) && user.getPassword().equals(password)) return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public LoginData getLoginUpdates(UserLogin loggedInUser) {
|
||||
LinkedList<Group> groups = this.userGroupMap.get(loggedInUser);
|
||||
HashMap<Group, GroupInformation> loginMap = new HashMap<>();
|
||||
for(Group g : groups){
|
||||
LinkedList<Message> messagesInChatRoom = this.teamMap.get(g).getMessagesInChatRoom();
|
||||
HashMap<User, PermissionRole> roleMap = this.teamMap.get(g).getRoleMap();
|
||||
LinkedList<Poll> pollList = this.teamMap.get(g).getPolls();
|
||||
loginMap.put(g, new GroupInformation(messagesInChatRoom, roleMap, pollList));
|
||||
|
||||
}
|
||||
return new LoginData(loginMap, loggedInUser);
|
||||
}
|
||||
private LinkedList<Poll> polls;
|
||||
public boolean addUser(UserLogin userToAdd, MessageInputListener newListener) {
|
||||
if (this.userGroupMap.keySet().contains(userToAdd)) return false;
|
||||
LinkedList<Group> userList = new LinkedList<>();
|
||||
userList.add(Group.DEFAULT_GROUP);
|
||||
this.userGroupMap.put(userToAdd, userList);
|
||||
this.teamMap.get(Group.DEFAULT_GROUP).getRoleMap().put(userToAdd, PermissionRole.USER);
|
||||
this.teamMap.get(Group.DEFAULT_GROUP).addListener(newListener);
|
||||
return true;
|
||||
}
|
||||
|
||||
public PermissionRole getRightsInGroup(User sendingUser, Group group) {
|
||||
System.out.println("getting rights in group...");
|
||||
TeamInfo tmp = this.teamMap.get(group);
|
||||
if(tmp == null) return PermissionRole.NONE;
|
||||
System.out.println("team exists");
|
||||
UserLogin userLogin = (UserLogin) sendingUser;
|
||||
PermissionRole rtrn = this.teamMap.get(group).getRoleMap().get(userLogin.removePassword());
|
||||
if (rtrn == null) return PermissionRole.NONE;
|
||||
System.out.println("user has role...");
|
||||
System.out.println(rtrn);
|
||||
return rtrn;
|
||||
|
||||
}
|
||||
|
||||
public boolean userRegistered(UserLogin user) {
|
||||
return this.userGroupMap.keySet().contains(user);
|
||||
}
|
||||
|
||||
public void addGroup(User addingUser, String content) {
|
||||
Group newGroup = new Group(Group.getNextId(), content);
|
||||
this.teamMap.put(newGroup, new TeamInfo());
|
||||
this.teamMap.get(newGroup).getRoleMap().put(addingUser, PermissionRole.TEAMLEADER);
|
||||
this.userGroupMap.get(addingUser).add(newGroup);
|
||||
}
|
||||
|
||||
public void changeUser(UserLogin newUser) {
|
||||
LinkedList<Group> userGroups = userGroupMap.get(newUser);
|
||||
userGroupMap.remove(newUser);
|
||||
userGroupMap.put(newUser, userGroups);
|
||||
for(Group g : userGroups){
|
||||
TeamInfo teamWithUser = teamMap.get(g);
|
||||
PermissionRole pm = teamWithUser.getRoleMap().get(newUser);
|
||||
teamWithUser.getRoleMap().put(newUser.removePassword(), pm);
|
||||
teamWithUser.addMessageToChatroom(new Message(g, ServerStatus.PROFILE_CHANGE_SUCCESSFUL,
|
||||
SYSTEM, newUser.getUserName() + " changed his User information", newUser.removePassword()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
package new_build.server.control.io;
|
||||
|
||||
|
||||
|
||||
import new_build.models.common.messages.Command;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.common.messages.ServerStatus;
|
||||
import new_build.models.common.polls.Poll;
|
||||
import new_build.models.common.polls.Vote;
|
||||
import new_build.models.network_organisation.*;
|
||||
import new_build.server.constants.DEBUG;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
import new_build.server.control.CommandManager;
|
||||
import new_build.server.control.ServerController;
|
||||
import new_build.server.control.observation.MessageInputListener;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnectionProcessor extends Thread implements MessageInputListener {
|
||||
|
||||
private Connection assignedConnection;
|
||||
private UserLogin loggedInUser;
|
||||
private ServerController assignedController;
|
||||
private boolean keepConnection;
|
||||
private CommandManager commandManager;
|
||||
|
||||
|
||||
public ConnectionProcessor(Connection assignedConnection, ServerController assignedController){
|
||||
this.assignedConnection = assignedConnection;
|
||||
this.assignedController = assignedController;
|
||||
this.commandManager = new CommandManager(this.assignedController);
|
||||
this.keepConnection = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendInformation(Message message) {
|
||||
try {
|
||||
System.out.println("sending information " + message.getControlHeader());
|
||||
assignedConnection.sendMessage(message);
|
||||
if(((ServerStatus) message.getControlHeader()) == ServerStatus.MEMBER_LEFT &&
|
||||
((User)message.getExtension()).equals(this.loggedInUser)) removeSelf(message.getGroup());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User listeningUser() {
|
||||
return this.loggedInUser;
|
||||
}
|
||||
|
||||
public void setUser(UserLogin u){
|
||||
this.loggedInUser = u;
|
||||
}
|
||||
|
||||
private void listenToMessages(){
|
||||
while(this.getKeepConnection()){
|
||||
try {
|
||||
Message m = this.assignedConnection.getNextMessage();
|
||||
if (m == null){
|
||||
this.keepConnection = false;
|
||||
} else {
|
||||
this.processMessage(m);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.closeConnection();
|
||||
}
|
||||
|
||||
private boolean getKeepConnection(){
|
||||
return (this.keepConnection && this.assignedController.serverShouldRun());
|
||||
}
|
||||
public void closeConnection(){
|
||||
this.keepConnection = false;
|
||||
this.logout();
|
||||
assignedController.removeConnection(this);
|
||||
System.out.println("Connection closed");
|
||||
}
|
||||
private void processMessage(Message message){
|
||||
if (message == null || message.getControlHeaderType() != Command.class) {
|
||||
commandManager.logout();
|
||||
this.closeConnection();
|
||||
return;
|
||||
}
|
||||
Message answer = this.handleCommandAndReturnMessage(message);
|
||||
System.out.println("returning answer to client(s)");
|
||||
switch(((ServerStatus) answer.getControlHeader())){
|
||||
case NEW_MESSAGE: assignedController.notifyObservers(answer);break;
|
||||
case SESSION_EXPIRED: this.sendInformation(answer);break;
|
||||
case LOGIN_SUCCESSFUL: this.sendInformation(answer);break;
|
||||
case LOGIN_FAILED: this.sendInformation(answer);break;
|
||||
case LOGOUT_SUCCESSFUL: this.sendInformation(answer);break;
|
||||
case COMMAND_UNKNOWN: this.sendInformation(answer);break;
|
||||
case PERMISSION_DENIED: this.sendInformation(answer);break;
|
||||
case REGISTRATION_FAILED: this.sendInformation(answer);break;
|
||||
case REGISTRATION_SUCCESSFUL: this.sendInformation(answer);break;
|
||||
case MEMBER_JOINED: assignedController.notifyObservers(answer);break;
|
||||
case ROLE_CHANGED: assignedController.notifyObservers(answer);break;
|
||||
case POLL_CREATED: assignedController.notifyObservers(answer);break;
|
||||
case POLL_FINISHED: assignedController.notifyObservers(answer);break;
|
||||
case VOTE_SUCCESSFUL: assignedController.notifyObservers(answer);break;
|
||||
case VOTE_FAILED: this.sendInformation(answer);break;
|
||||
case PROFILE_CHANGE_SUCCESSFUL: assignedController.notifyObservers(answer);break;
|
||||
case ERR_EXECUTING_COMMAND: this.sendInformation(answer);break;
|
||||
default: this.sendInformation(answer);break;
|
||||
// PROFILE_CHANGE_SUCCESSFUL;
|
||||
}
|
||||
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("processed message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.listenToMessages();
|
||||
}
|
||||
|
||||
private void removeSelf(Group groupToRemoveIn){
|
||||
assignedController.getTeamFromGroup(groupToRemoveIn).removeListener(this);
|
||||
}
|
||||
|
||||
public Message handleCommandAndReturnMessage(Message m) {
|
||||
if (m == null) {
|
||||
System.out.println("message null");
|
||||
return null;
|
||||
}
|
||||
if (DEBUG.SERVER_DEBUG_ASSERTIONS) assert m.getContent() != null;
|
||||
System.out.println("handling incoming message...");
|
||||
if (DEBUG.SERVER_DEBUG_MESSAGES) {
|
||||
String builder = "Command: " +
|
||||
m.getControlHeader() +
|
||||
" Content: " +
|
||||
m.getContent();
|
||||
System.out.println(builder);
|
||||
}
|
||||
|
||||
switch (((Command) m.getControlHeader())) {
|
||||
case LOGIN: {
|
||||
String[] credentials = m.getContent().split(" ");
|
||||
if (credentials.length == 2) {
|
||||
String username = credentials[0];
|
||||
String password = credentials[1];
|
||||
UserLogin loginTry = assignedController.validateLogin(username, password);
|
||||
if (loginTry != null) {
|
||||
LoginData loginData = assignedController.getLoginUpdates(loginTry);
|
||||
this.loggedInUser = loginTry;
|
||||
assignedController.addUserListener(loginTry, this);
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.LOGIN_SUCCESSFUL, loginTry, "login successful", loginData);
|
||||
}
|
||||
}
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.LOGIN_FAILED, null, "login failed", null);
|
||||
}
|
||||
case CHANGEUSER:
|
||||
if(!this.validateCredentials(m.getSendingUser())) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM,
|
||||
"credentials invalid", null);
|
||||
if(m.getExtension().getType().equals(UserLogin.class) &&
|
||||
((UserLogin) m.getExtension()).getUserName().equals(loggedInUser.getUserName())){
|
||||
assignedController.changeUser(((UserLogin) m.getExtension()));
|
||||
|
||||
} else return new Message(Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM,
|
||||
"no or invalid userlogin object send to change to", null);
|
||||
break;
|
||||
case CHANGEPROFILEPIC:
|
||||
if(!this.validateCredentials(m.getSendingUser())) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM,
|
||||
"credentials invalid", null);
|
||||
else if(m.getExtension().getType().equals(BufferedImage.class)){
|
||||
loggedInUser.setProfilePic((BufferedImage) m.getExtension());
|
||||
}
|
||||
case LOGOUT: {
|
||||
if (loggedInUser == null) return new Message(Group.DEFAULT_GROUP, ServerStatus.SESSION_EXPIRED,
|
||||
ServerController.SYSTEM, "cant log out, not logged in", null);
|
||||
else {
|
||||
this.logout();
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.LOGOUT_SUCCESSFUL, ServerController.SYSTEM,
|
||||
"logged out successful", null);
|
||||
}
|
||||
}
|
||||
case REGISTER: {
|
||||
System.out.println("registration incoming...");
|
||||
if(m.getExtension() == null || // Extension is empty
|
||||
!m.getExtension().getType().equals(UserLogin.class) || // Extension isn't a UserLogin
|
||||
assignedController.userRegistered((UserLogin) m.getExtension())){ // Extension isn't an existing User
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.REGISTRATION_FAILED,
|
||||
ServerController.SYSTEM, "registration failed", null);
|
||||
} else if(assignedController.addUser(((UserLogin) m.getExtension()), this)){
|
||||
System.out.println("successful registration");
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.REGISTRATION_SUCCESSFUL,
|
||||
ServerController.SYSTEM, "registration successful", null);
|
||||
} else {
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.REGISTRATION_FAILED,
|
||||
ServerController.SYSTEM, "registration failed, user already exists", null);
|
||||
}
|
||||
}
|
||||
case SENDMESSAGE: {
|
||||
if(!this.validateCredentials(m.getSendingUser())) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM,
|
||||
"credentials invalid", null);
|
||||
else if(assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasUserRights()){
|
||||
System.out.println("message send successfully");
|
||||
return new Message(m.getGroup(), ServerStatus.NEW_MESSAGE, ((UserLogin) m.getSendingUser()).removePassword(),
|
||||
m.getContent(), m.getExtension());
|
||||
}
|
||||
else return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.PERMISSION_DENIED, ServerController.SYSTEM,
|
||||
"credentials invalid", null);
|
||||
}
|
||||
case ADDGROUP:
|
||||
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
|
||||
if(assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasUserRights()){
|
||||
assignedController.addGroup(m.getSendingUser(), m.getContent());
|
||||
assignedController.addUser(((UserLogin) m.getSendingUser()), this);
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.GROUP_CREATED, ServerController.SYSTEM,
|
||||
"group " + m.getGroup().getName() + " created", null);
|
||||
} else return new Message(Group.DEFAULT_GROUP, ServerStatus.PERMISSION_DENIED, ServerController.SYSTEM,
|
||||
"permission denied", null);
|
||||
case ADDUSER:
|
||||
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
|
||||
if(m.getExtension() == null || m.getExtension().getType() != User.class) return new Message(
|
||||
Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM, "no user send in" +
|
||||
" message", null);
|
||||
if(assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasTeamleaderRights()){
|
||||
assignedController.getTeamMap().get(m.getGroup()).getRoleMap().put(((User) m.getExtension()), PermissionRole.USER);
|
||||
return new Message(m.getGroup(), ServerStatus.MEMBER_JOINED, ServerController.SYSTEM, "user " +
|
||||
((User) m.getExtension()).getUserName() + " joined the team", null);
|
||||
}
|
||||
break;
|
||||
case REMOVEUSER:
|
||||
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
|
||||
if(m.getExtension() == null || m.getExtension().getType() != User.class) return new Message(
|
||||
Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM, "no user send in" +
|
||||
" message", null);
|
||||
if(assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasTeamleaderRights()){
|
||||
assignedController.getTeamMap().get(m.getGroup()).getRoleMap().remove(((User) m.getExtension()));
|
||||
return new Message(m.getGroup(), ServerStatus.MEMBER_LEFT, ServerController.SYSTEM, "user " +
|
||||
((User) m.getExtension()).getUserName() + " left the team", m.getExtension());
|
||||
}
|
||||
break;
|
||||
case CHANGEROLE:
|
||||
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
|
||||
if(m.getExtension() == null || m.getExtension().getType() != Pair.class ||
|
||||
((Pair) m.getExtension()).getA().getClass().equals(User.class) ||
|
||||
((Pair) m.getExtension()).getB().getClass().equals(PermissionRole.class)) return new Message(
|
||||
Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM, "no pair of user," +
|
||||
" permissionrole send in message", null);
|
||||
if(assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasTeamleaderRights()){
|
||||
Pair changeData = ((Pair) m.getExtension());
|
||||
User userToChange = ((User) changeData.getA());
|
||||
PermissionRole roleToSet = ((PermissionRole) changeData.getB());
|
||||
if(roleToSet.equals(PermissionRole.ADMIN) || roleToSet.equals(PermissionRole.OWNER))
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.PERMISSION_DENIED, ServerController.SYSTEM ,"cant set role to admin or higher", null);
|
||||
assignedController.getTeamMap().get(m.getGroup()).getRoleMap().put(userToChange, roleToSet);
|
||||
return new Message(m.getGroup(), ServerStatus.MEMBER_LEFT, ServerController.SYSTEM, "userrole of " +
|
||||
((User) m.getExtension()).getUserName() + " changed to " + roleToSet, userToChange);
|
||||
}
|
||||
break;
|
||||
case UNKNOWN:
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.COMMAND_UNKNOWN, ServerController.SYSTEM,
|
||||
"unknown command", null);
|
||||
case ADDPOLL:
|
||||
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
|
||||
if(m.getExtension() == null || m.getExtension().getType() != Poll.class) return new Message(
|
||||
Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM,
|
||||
"no poll send with Message", null);
|
||||
if(assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasUserRights()){
|
||||
Poll createdPoll = ((Poll) m.getExtension());
|
||||
assignedController.getTeamFromGroup(m.getGroup()).addPoll(createdPoll);
|
||||
return new Message(m.getGroup(), ServerStatus.POLL_CREATED, ServerController.SYSTEM,
|
||||
"Poll created", createdPoll);
|
||||
} else return new Message(m.getGroup(), ServerStatus.PERMISSION_DENIED, ServerController.SYSTEM,
|
||||
"permission denied", null);
|
||||
case VOTE_POLL:
|
||||
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
|
||||
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
|
||||
if(m.getExtension() == null || m.getExtension().getType() != Vote.class) return new Message(
|
||||
Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM,
|
||||
"no vote send with Message", null);
|
||||
if (assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasUserRights()){
|
||||
Vote v = ((Vote) m.getExtension());
|
||||
assignedController.getTeamFromGroup(m.getGroup()).addVote(m.getSendingUser(), v);
|
||||
return new Message(m.getGroup(), ServerStatus.VOTE_SUCCESSFUL, ServerController.SYSTEM,
|
||||
"vote added successfully", v);
|
||||
} else return new Message(m.getGroup(), ServerStatus.PERMISSION_DENIED, ServerController.SYSTEM,
|
||||
"permission denied", null);
|
||||
default:
|
||||
return new Message(Group.DEFAULT_GROUP, ServerStatus.COMMAND_UNKNOWN, ServerController.SYSTEM,
|
||||
"unknown command", null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean validateCredentials(User loginTry) {
|
||||
if(loggedInUser == null) {
|
||||
System.out.println("not logged in ... ");
|
||||
return false;
|
||||
}
|
||||
if(loginTry == null){
|
||||
System.out.println("no user object send at all");
|
||||
return false;
|
||||
}
|
||||
if(!loginTry.getType().equals(UserLogin.class)){
|
||||
System.out.println("send user object is no userlogin object");
|
||||
return false;
|
||||
} else {
|
||||
UserLogin login = ((UserLogin) loginTry);
|
||||
if(login.getPassword().equals(this.loggedInUser.getPassword())){
|
||||
System.out.println("equal passwords");
|
||||
if(login.getUserName().equals(this.loggedInUser.getUserName())) {
|
||||
System.out.println("equal username");
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void logout(){
|
||||
if (loggedInUser == null) return;
|
||||
this.assignedController.removeUserListener(loggedInUser, this);
|
||||
this.loggedInUser = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package new_build.server.control.observation;
|
||||
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.User;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Tobias on 15.06.2017.
|
||||
*/
|
||||
public interface MessageInputListener extends Serializable{
|
||||
void sendInformation(Message Message);
|
||||
User listeningUser();
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package new_build.server.database;
|
||||
|
||||
|
||||
import new_build.models.network_organisation.Group;
|
||||
import new_build.models.network_organisation.User;
|
||||
import new_build.server.constants.PermissionRole;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class GroupLib {
|
||||
private SQLConnector sqlConnector;
|
||||
private UserLib userLib;
|
||||
|
||||
public GroupLib() {
|
||||
sqlConnector = new SQLConnector();
|
||||
userLib = new UserLib();
|
||||
}
|
||||
|
||||
public LinkedList<Group> getGroupsByUserID(int userID){
|
||||
ResultSet groups = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT g.groupID, g.groupname " +
|
||||
"FROM groups g " +
|
||||
"INNER JOIN UserInGroup uig " +
|
||||
"ON uig.groupID = g.groupID " +
|
||||
"INNER JOIN user u " +
|
||||
"ON uig.userID = u.userID " +
|
||||
"WHERE u.userID = ''{0}''", userID
|
||||
)
|
||||
);
|
||||
|
||||
LinkedList<Group> groupList = new LinkedList<>();
|
||||
|
||||
try {
|
||||
while (groups.next()) {
|
||||
groupList.add(new Group(groups.getInt("groupID"), groups.getString("groupname")));
|
||||
}
|
||||
return groupList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public HashMap<User, PermissionRole> getRolesInGroup(Group group){
|
||||
HashMap<User, PermissionRole> userMap = new HashMap<>();
|
||||
User user;
|
||||
PermissionRole role;
|
||||
ResultSet userSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT u.userID, uig.permissionRole " +
|
||||
"FROM user u " +
|
||||
"INNER JOIN UserInGroup uig " +
|
||||
"ON u.userID = uig.userID " +
|
||||
"WHERE uig.groupID = ''{0}''", group.getId()
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
while (userSet.next()){
|
||||
user = userLib.getUserByID(userSet.getInt("userID"));
|
||||
role = null;
|
||||
switch (userSet.getInt("permissionRole")){
|
||||
case 0:
|
||||
role = PermissionRole.NONE;
|
||||
break;
|
||||
case 1:
|
||||
role = PermissionRole.USER;
|
||||
break;
|
||||
case 3:
|
||||
role = PermissionRole.TEAMLEADER;
|
||||
break;
|
||||
case 7:
|
||||
role = PermissionRole.ADMIN;
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
userMap.putIfAbsent(user,role);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userMap;
|
||||
}
|
||||
|
||||
public Group[] getAllGroups(){
|
||||
ResultSet groupSet = sqlConnector.executeQuery(
|
||||
"SELECT groupID, groupname " +
|
||||
"FROM groups"
|
||||
);
|
||||
|
||||
Group[] groups = new Group[sqlConnector.resultSetLength(groupSet)];
|
||||
try {
|
||||
groupSet.beforeFirst();
|
||||
for (int i = 0; i < groups.length; i++) {
|
||||
groupSet.next();
|
||||
groups[i] = new Group(groupSet.getInt("groupID"), groupSet.getString("groupname"));
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void insertGroupChanges(Group g){
|
||||
ResultSet existSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT EXISTS(SELECT 1 FROM groups WHERE groupname=''{0}'' LIMIT 1)", g.getName()
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
existSet.next();
|
||||
if (!(existSet.getInt(1)==1) && !(g.getName().equals("default"))){
|
||||
sqlConnector.executeUpdate(
|
||||
MessageFormat.format(
|
||||
"INSERT INTO groups (groupname) VALUES (''{0}'')",g.getName()
|
||||
)
|
||||
);
|
||||
// System.out.println("Change was made in groups");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void insertRoleChanges(Group g, User u, PermissionRole pr){
|
||||
ResultSet existSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT EXISTS(SELECT 1 " +
|
||||
"FROM UserInGroup " +
|
||||
"WHERE userID=''{0}'' AND groupID=''{1}'' AND permissionRole=''{2}'' LIMIT 1)"
|
||||
, u.getID(), g.getId(),pr.getValue()
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
existSet.next();
|
||||
if (!(existSet.getInt(1)==1)){
|
||||
existSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT EXISTS(SELECT 1 " +
|
||||
"FROM UserInGroup " +
|
||||
"WHERE userID=''{0}'' AND groupID=''{1}'' LIMIT 1)"
|
||||
, u.getID(), g.getId()
|
||||
)
|
||||
);
|
||||
existSet.next();
|
||||
if (!(existSet.getInt(1)==1)){
|
||||
sqlConnector.executeUpdate(
|
||||
MessageFormat.format(
|
||||
"INSERT INTO UserInGroup (userID, groupID, permissionRole " +
|
||||
"VALUES (''{0}'', ''{1}'', ''{2}''))"
|
||||
, u.getID(), g.getId(), pr.getValue()
|
||||
)
|
||||
);
|
||||
}else{
|
||||
sqlConnector.executeUpdate(
|
||||
MessageFormat.format(
|
||||
"UPDATE userInGroup " +
|
||||
"SET permissionRole = ''{0}'' " +
|
||||
"WHERE userID=''{1}'' AND groupID = ''{12}''"
|
||||
, pr.getValue(), u.getID(), g.getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package new_build.server.database;
|
||||
|
||||
|
||||
import new_build.models.common.data.Sendable;
|
||||
import new_build.models.common.data.SepFile;
|
||||
import new_build.models.common.messages.Message;
|
||||
import new_build.models.network_organisation.Group;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MessageLib {
|
||||
private SQLConnector sqlConnector;
|
||||
private UserLib userLib;
|
||||
|
||||
public MessageLib() {
|
||||
sqlConnector = new SQLConnector();
|
||||
userLib = new UserLib();
|
||||
}
|
||||
|
||||
public LinkedList<Message> getMessagesInGroup(Group g){
|
||||
LinkedList<Message> messageList = new LinkedList<>();
|
||||
|
||||
ResultSet messageSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT userID, content, extension " +
|
||||
"FROM messages " +
|
||||
"WHERE groupid = ''{0}''", g.getId()
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
while (messageSet.next()){
|
||||
messageList.add(new Message(g,null,userLib.getUserByID(messageSet.getInt("userID")),
|
||||
messageSet.getString("content"), new SepFile(messageSet.getBytes("extension"))));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return messageList;
|
||||
}
|
||||
|
||||
public void insertChanges(Message m, Date serverStart) {
|
||||
if (m.getTimeStamp().getTime() > serverStart.getTime()) {
|
||||
String content = m.getContent();
|
||||
SepFile sepFile = null;
|
||||
byte[] fileArray = null;
|
||||
int userID = m.getSendingUser().getID();
|
||||
int groupID = m.getGroup().getId();
|
||||
Date timeStamp = m.getTimeStamp();
|
||||
Sendable extension;
|
||||
if (m.hasExtension()) {
|
||||
extension = m.getExtension();
|
||||
if (extension.getType().equals(SepFile.class)) {
|
||||
sepFile = (SepFile) extension;
|
||||
}
|
||||
sqlConnector.executeUpdate(
|
||||
MessageFormat.format(
|
||||
"INSERT INTO messages (content, userID, groupID, timestamp, extension) " +
|
||||
"VALUES (''{0}'', ''{1}'', ''{2}'', ''{3}'', ''{4}'')", content, userID, groupID, timeStamp, sepFile.getFile()
|
||||
)
|
||||
);
|
||||
}else{
|
||||
sqlConnector.executeUpdate(
|
||||
MessageFormat.format(
|
||||
"INSERT INTO messages (content, userID, groupID, timestamp, extension) " +
|
||||
"VALUES (''{0}'', ''{1}'', ''{2}'', ''{3}'', ''{4}'')", content, userID, groupID, timeStamp, ""
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// System.out.println("Change was made in messages");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package new_build.server.database;
|
||||
|
||||
|
||||
import new_build.models.common.polls.Poll;
|
||||
import new_build.models.network_organisation.Group;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class PollLib {
|
||||
private SQLConnector sqlConnector;
|
||||
|
||||
public PollLib() {
|
||||
sqlConnector = new SQLConnector();
|
||||
}
|
||||
|
||||
public int[] getPollIDs() {
|
||||
try {
|
||||
ResultSet resultSet = sqlConnector.executeQuery(
|
||||
"SELECT pollID " +
|
||||
"FROM pollData "
|
||||
);
|
||||
int arraySize = sqlConnector.resultSetLength(resultSet);
|
||||
|
||||
int[] pollIDs;
|
||||
try {
|
||||
pollIDs = new int[arraySize];
|
||||
} catch (NegativeArraySizeException ex) {
|
||||
pollIDs = null;
|
||||
}
|
||||
int i = 0;
|
||||
while (resultSet.next()) {
|
||||
assert pollIDs != null;
|
||||
pollIDs[i] = resultSet.getInt("pollID");
|
||||
i++;
|
||||
}
|
||||
return pollIDs;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no pollID attribute, because it's the tables primary key
|
||||
* This Method adds a poll to the pollData table in the DB
|
||||
*
|
||||
* @param groupID the group the poll is assigned to
|
||||
* @param pollDescription the name of the poll
|
||||
* @param pollExpires the date and time the poll expires
|
||||
*/
|
||||
public void addPoll(int groupID, String pollDescription, Date pollExpires) {
|
||||
sqlConnector.executeUpdate(
|
||||
"INSERT INTO pollData (groupID, pollDescription, pollExpires) " +
|
||||
"VALUES ('" + groupID + "', '" + pollDescription + "', '" + pollExpires + "')"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The boolean in Java is a bit, that's why
|
||||
* TODO Check if the poll even exists
|
||||
*
|
||||
* @param pollID the poll you are voting for
|
||||
* @param userID the user that voted
|
||||
* @param vote your vote
|
||||
*/
|
||||
public void addVote(int pollID, int userID, int vote) {
|
||||
sqlConnector.executeUpdate(
|
||||
"INSERT INTO votes (pollID, userID, vote) " +
|
||||
"VALUES ('" + pollID + "', '" + userID + "', '" + vote + "')"
|
||||
);
|
||||
}
|
||||
|
||||
public Poll getPollByID(int pollID) {
|
||||
int groupID;
|
||||
String pollText;
|
||||
Date expiringDate;
|
||||
ResultSet resultSet = sqlConnector.executeQuery(
|
||||
"SELECT groupID, pollDescription, pollExpires " +
|
||||
"FROM pollData " +
|
||||
"WHERE pollID = " + pollID);
|
||||
if (sqlConnector.resultSetLength(resultSet) == 1) {
|
||||
try {
|
||||
groupID = resultSet.getInt("groupid");
|
||||
pollText = resultSet.getString("pollDescription");
|
||||
expiringDate = resultSet.getDate("pollExpires");
|
||||
|
||||
return new Poll(pollID, pollText, expiringDate);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.err.println("Error in getPollByID, ID is not unique");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int[][] getVotesByID(int pollID) {
|
||||
ResultSet resultSet = sqlConnector.executeQuery(
|
||||
"SELECT pollID, vote " +
|
||||
"FROM votes " +
|
||||
"WHERE pollID = " + pollID);
|
||||
|
||||
int voteZahl = sqlConnector.resultSetLength(resultSet);
|
||||
int[][] votes = new int[2][voteZahl];
|
||||
|
||||
|
||||
try {
|
||||
int i = 0;
|
||||
while (resultSet.next()) {
|
||||
votes[0][i] = resultSet.getInt("pollID");
|
||||
votes[1][i] = resultSet.getInt("vote");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return votes;
|
||||
}
|
||||
|
||||
public LinkedList<Poll> getPollsOfGroup(Group g) {
|
||||
LinkedList<Poll> pollList = new LinkedList<>();
|
||||
|
||||
ResultSet pollSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT pollID, pollDescription, pollExpires " +
|
||||
"FROM pollData " +
|
||||
"WHERE groupid = ''{0}''", g.getId()
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
while (pollSet.next()) {
|
||||
Poll poll = new Poll(pollSet.getInt("pollID"),
|
||||
pollSet.getString("pollDescription"), pollSet.getDate("pollExpires"));
|
||||
pollList.add(poll);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return pollList;
|
||||
}
|
||||
|
||||
public void insertChanges(Poll p, Group g){
|
||||
ResultSet existSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT EXISTS(SELECT 1 " +
|
||||
"FROM pollData " +
|
||||
"WHERE pollID = ''{0}'' AND pollDescription = ''{1}'')"
|
||||
, p.getPollID(), p.getPollText()
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
existSet.next();
|
||||
if (!(existSet.getInt(1) == 1)){
|
||||
addPoll(g.getId(), p.getPollText(), p.getExpiringDate());
|
||||
}
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package new_build.server.database;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class SQLConnection {
|
||||
private Connection connection;
|
||||
|
||||
private Connection getConnection(String database, String username, String password) {
|
||||
try {
|
||||
System.out.println("Trying to connect to the database");
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance();
|
||||
String connectionCommand = "jdbc:mysql://" + "sql503.your-server.de" + "/" + database + "?user=" + username + "&password=" + password;
|
||||
connection = DriverManager.getConnection(connectionCommand);
|
||||
System.out.println("Connection to database successful");
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("Couldn't find driver");
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Couldn't connect to database");
|
||||
System.err.println("SQLException: " + e.getMessage());
|
||||
System.err.println("SQLState: " + e.getSQLState());
|
||||
System.err.println("VendorError: " + e.getErrorCode());
|
||||
} catch (IllegalAccessException | InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
public Connection getConnection(){
|
||||
return getConnection(
|
||||
"uni_due",
|
||||
"uni_due_user",
|
||||
"2TasseTee?");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package new_build.server.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
class SQLConnector {
|
||||
private Connection connection;
|
||||
|
||||
SQLConnector() {
|
||||
connection = new SQLConnection().getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes @param in the SQL Database, currently without protectionmechanisms
|
||||
* @param query executed SQL query
|
||||
* @return ResultSet with the SQL Rows
|
||||
*
|
||||
*/
|
||||
ResultSet executeQuery(String query){
|
||||
try {
|
||||
ResultSet returnSet;
|
||||
Statement statement = connection.createStatement();
|
||||
System.out.println("executeQuery: " + query);
|
||||
returnSet = statement.executeQuery(query);
|
||||
return returnSet;
|
||||
}catch(SQLException ex){
|
||||
System.err.println("Error while executing the SQL query:");
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void executeUpdate(String query){
|
||||
try{
|
||||
Statement statement = connection.createStatement();
|
||||
System.err.println("executeUpdate: " + query);
|
||||
statement.executeUpdate(query);
|
||||
}catch(SQLException ex){
|
||||
System.err.println("Error while executing the SQL update:");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
int resultSetLength(ResultSet rs){
|
||||
int size= 0;
|
||||
try {
|
||||
if (rs != null)
|
||||
{
|
||||
rs.beforeFirst();
|
||||
rs.last();
|
||||
size = rs.getRow();
|
||||
return size;
|
||||
}
|
||||
}catch(SQLException ex){
|
||||
System.err.println("Error in LoginLib->getLength():\n" + ex);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package new_build.server.database;
|
||||
|
||||
|
||||
import new_build.models.network_organisation.User;
|
||||
import new_build.models.network_organisation.UserLogin;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import static javax.imageio.ImageIO.*;
|
||||
|
||||
public class UserLib {
|
||||
private SQLConnector sqlConnector;
|
||||
|
||||
public UserLib() {
|
||||
sqlConnector = new SQLConnector();
|
||||
}
|
||||
|
||||
boolean userExists(String userName){
|
||||
ResultSet userSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT userID " +
|
||||
"FROM user " +
|
||||
"WHERE username = ''{0}''", userName
|
||||
)
|
||||
);
|
||||
return sqlConnector.resultSetLength(userSet) == 1;
|
||||
}
|
||||
|
||||
User getUserByID(int userID){
|
||||
String username = null, vorname = null, nachname = null;
|
||||
BufferedImage profilePicture = null;
|
||||
ResultSet userSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT u.userID, u.username, u.Vorname, u.Nachname, u.ProfilePicture " +
|
||||
"FROM user u " +
|
||||
"WHERE u.userID = ''{0}''", userID
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
userSet.next();
|
||||
username = userSet.getString("username");
|
||||
vorname = userSet.getString("Vorname");
|
||||
nachname = userSet.getString("Nachname");
|
||||
byte[] pictureArray = userSet.getBytes("profilePicture");
|
||||
if (pictureArray!= null) {
|
||||
profilePicture = read(new ByteArrayInputStream(pictureArray));
|
||||
}
|
||||
} catch (SQLException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return new User(userID, username, vorname, nachname, profilePicture);
|
||||
}
|
||||
|
||||
public UserLogin[] getAllUserLogin(){
|
||||
int userID;
|
||||
String userName, firstName, lastName, password;
|
||||
ResultSet userLoginSet = sqlConnector.executeQuery("SELECT userID, username, vorname, nachname, password FROM user");
|
||||
|
||||
UserLogin[] userLogins = new UserLogin[sqlConnector.resultSetLength(userLoginSet)];
|
||||
|
||||
try {
|
||||
userLoginSet.beforeFirst();
|
||||
for (int i = 0; i < userLogins.length; i++) {
|
||||
userLoginSet.next();
|
||||
userID = userLoginSet.getInt("userID");
|
||||
userName = userLoginSet.getString("username");
|
||||
firstName = userLoginSet.getString("vorname");
|
||||
lastName = userLoginSet.getString("nachname");
|
||||
password = userLoginSet.getString("password");
|
||||
userLogins[i] = new UserLogin(userID, userName, firstName, lastName, password);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return userLogins;
|
||||
}
|
||||
|
||||
public void insertLoginChanges(UserLogin ul){
|
||||
byte[] pictureArray = null;
|
||||
|
||||
if (ul.getProfilePic()!=null) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
write(ul.getProfilePic(), "png", baos);
|
||||
pictureArray = baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Couldnt transform image to bytearray");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
ResultSet existSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT EXISTS(SELECT 1 " +
|
||||
"FROM user " +
|
||||
"WHERE userID = ''{0}'' AND username = ''{1}'' AND vorname = ''{2}'' AND" +
|
||||
" nachname = ''{3}'' AND password = ''{4}'' AND profilePicture = ''{5}'' LIMIT 1)"
|
||||
, ul.getID(), ul.getUserName(), ul.getFirstName(), ul.getLastName(), ul.getPassword()
|
||||
, pictureArray)
|
||||
);
|
||||
|
||||
try {
|
||||
existSet.next();
|
||||
if(!(existSet.getInt(1)==1)){
|
||||
existSet = sqlConnector.executeQuery(
|
||||
MessageFormat.format(
|
||||
"SELECT EXISTS(SELECT 1 FROM user WHERE userID = ''{0}'')", ul.getID()
|
||||
)
|
||||
);
|
||||
existSet.next();
|
||||
if(!(existSet.getInt(1)==1)){
|
||||
sqlConnector.executeUpdate(
|
||||
MessageFormat.format(
|
||||
"INSERT INTO user (username, vorname, nachname, password, profilePicture)" +
|
||||
"VALUES (''{0}'', ''{1}'', ''{2}'', ''{3}'', ''{4}'')"
|
||||
, ul.getUserName(), ul.getFirstName(), ul.getLastName(),ul.getPassword(),
|
||||
pictureArray
|
||||
)
|
||||
);
|
||||
}else{
|
||||
sqlConnector.executeUpdate(
|
||||
MessageFormat.format(
|
||||
"UPDATE user " +
|
||||
"SET vorname = ''{0}'', nachname = ''{1}''" +
|
||||
", password = ''{2}'', profilePicture = ''{3}'' " +
|
||||
"WHERE userID = ''{4}'' AND username = ''{5}''"
|
||||
, ul.getFirstName(), ul.getLastName(), ul.getPassword(), pictureArray
|
||||
, ul.getID(), ul.getUserName()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||