Initial commit for Software Engineerung & Programming Course

Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
Tuan-Dat Tran
2024-04-14 02:30:44 +02:00
commit 5e44b7547f
511 changed files with 50289 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: new_build.client.view.sepboard.GUIview.Main

14
WorkingDir/WorkingDir.iml Normal file
View File

@@ -0,0 +1,14 @@
<?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" />
<orderEntry type="library" name="mysql-connector-java-5.1.42-bin (2)" level="project" />
<orderEntry type="library" name="mysql-connector-java-5.1.42-bin (2)" level="project" />
<orderEntry type="library" name="mysql-connector-java-5.1.42-bin (3)" level="project" />
</component>
</module>

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: new_build.server.control.ServerController

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,341 @@
package new_build.client.controller;
import javafx.beans.property.SimpleIntegerProperty;
import new_build.client.listener.ConsoleListener;
import new_build.client.view.ConsoleView;
import new_build.client.view.sepboard.GUIview.controller.TaskboardController;
import new_build.client.view.sepboard.GUIview.controller.ViewController;
import new_build.models.client_interfaces.ClientView;
import new_build.models.common.data.Sendable;
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.models.taskboard.EditTask;
import new_build.models.taskboard.Task;
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 {
public static final String IP = "localhost";
public static final int PORT = 1337;
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;
boolean connectionSuccessful = false;
int connectionAttempt = 0;
String errorMessage = "Connection couldnt be established, trying again in 5 seconds.\nAttempt: ";
keepRunning = true;
view = new ConsoleView(new ConsoleListener(this), this);
while (!connectionSuccessful){
try {
connectionSocket = new Socket(targetIp, portToListenTo);
connection = new Connection(connectionSocket);
connectionSuccessful = true;
} catch (IOException e) {
connectionAttempt++;
connectionSuccessful = false;
if (connectionAttempt>=5){
System.err.println("Couldn't connect to server.\nShutdown program.");
shutDown(-1);
} else {
System.err.println(errorMessage + connectionAttempt);
}
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
this.knownTeamMap = new HashMap<>();
System.out.println("client started successfully");
}
public static ClientController getController(){
if(controller != null) return controller;
else {
controller = new ClientController(IP, PORT);
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 BMthod 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;
System.exit(-1);
}
/**
* 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;
}
System.out.println(message.getContent() + " " + message.getControlHeader().name());
//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);
this.getViewController().reactToNewMessage(message);
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);
viewController.reactToNewMessage(message);
break;
}
case LOGIN_FAILED:
view.displayMessage(message);
viewController.reactToNewMessage(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);
viewController.reactToNewMessage(message);
break;
case MEMBER_JOINED: {
Group group = message.getGroup();
this.getKnownTeamMap().get(group).getMessagesInChatRoom().add(message);
assert message.getExtension() != null && message.getExtension().getType().equals(Pair.class);
User userWithRole = (User) message.getExtension();
this.knownTeamMap.get(group).getRoleMap().put(userWithRole, PermissionRole.USER);
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
}
case ROLE_CHANGED: {
this.getKnownTeamMap().get(message.getGroup()).getMessagesInChatRoom().add(message);
Group group = message.getGroup();
assert message.getExtension() != null && message.getExtension().getType().equals(Pair.class);
Pair<User, PermissionRole> changeUser = ((Pair<User, PermissionRole>) message.getExtension());
HashMap<User, PermissionRole> roleMap = knownTeamMap.get(group).getRoleMap();
roleMap.remove(changeUser.getA());
roleMap.put(changeUser.getA(), changeUser.getB());
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
}
case POLL_CREATED: {
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
}
case POLL_FINISHED:
System.out.println("poll finished");
this.getKnownTeamMap().get(this.getWorkingGroup()).getMessagesInChatRoom().add(message);
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
case VOTE_SUCCESSFUL:
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
case VOTE_FAILED:
view.displayMessage(message);
break;
case GROUP_CREATED:
if (message.getExtension().getClass() == GroupInformation.class){
GroupInformation groupInformation = (GroupInformation) message.getExtension();
this.getKnownTeamMap().put(groupInformation.getGroup(), groupInformation);
viewController.reactToNewMessage(message);
}
break;
case MEMBER_LEFT:
this.getKnownTeamMap().get(message.getGroup()).getMessagesInChatRoom().add(message);
this.getKnownTeamMap().get(message.getGroup()).getRoleMap().remove(message.getExtension());
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
case TASK_ADDED:
this.getKnownTeamMap().get(message.getGroup()).getMessagesInChatRoom().add(message);
this.getKnownTeamMap().get(message.getGroup()).getTasks().add((Task) message.getExtension());
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
case TASK_CHANGED:
this.getKnownTeamMap().get(message.getGroup()).getMessagesInChatRoom().add(message);
this.handleCommand_TASK_CHANGED((Task) message.getExtension());
view.displayMessage(message);
viewController.reactToNewMessage(message);
break;
case PROFILE_CHANGE_SUCCESSFUL:
UserLogin changedUser = (UserLogin) message.getExtension();
System.out.println("changedUser.getFirstName() = " + changedUser.getFirstName() + " " + changedUser.getLastName());
handleCommand_PROFILE_CHANGE_SUCCESSFUL(changedUser);
viewController.reactToNewMessage(message);
view.displayMessage(message);
break;
case ERR_EXECUTING_COMMAND:
view.displayMessage(message);
break;
case USERLIST_SEND:
viewController.reactToNewMessage(message);
default: {
view.displayMessage(message);
viewController.reactToNewMessage(message);
}
}
}
private void handleCommand_PROFILE_CHANGE_SUCCESSFUL(UserLogin changedUser) {
this.loggedInUser = changedUser;
}
private void handleCommand_TASK_CHANGED(Task task) {
System.out.println(task.getTaskID() + " " + task.getState().name());
LinkedList <Task> tasks = this.getKnownTeamMap().get(task.getGroup()).getTasks();
for(Task e: tasks){
if(e.getTaskID() == task.getTaskID()){
tasks.remove(e);
tasks.add(task);
break;
}
}
}
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 void changeWorkingGroup(String text) {
this.workingGroup = this.getGroupByName(text);
}
public void registerViewController(ViewController viewController) {
this.viewController = viewController;
}
public ViewController getViewController() {
return viewController;
}
}

View File

@@ -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.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], null);
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], null);
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], null);
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);
}
}

View File

@@ -0,0 +1,99 @@
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.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(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) {
}
}

View File

@@ -0,0 +1,69 @@
package new_build.client.view.sepboard.GUIview;
import javafx.application.Application;
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 java.io.IOException;
public class Main extends Application {
private static Stage mainStage;
private ViewController currentViewController;
@Override
public void start(Stage primaryStage) throws Exception {
mainStage = primaryStage;
Thread t = new Thread(() -> {
ClientController.controller = new ClientController(ClientController.IP, ClientController.PORT);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
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;
try {
login = FXMLLoader.load(getClass().getResource("resources/layout/login.fxml"));
Scene scene = new Scene(login, 800, 600);
stage.setTitle("SEPboard");
stage.getIcons().add(new Image("new_build/client/view/sepboard/GUIview/resources/image/icon.png"));
stage.setScene(scene);
stage.setMinWidth(800);
stage.setMinHeight(600);
stage.show();
} catch (IOException e) {
System.out.println("couldn't load login scene");
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
public static void changeScene(String changeToScene) throws IOException {
// Get reference to the button's stage
// Load other FXML document
Parent root = FXMLLoader.load(Main.class.getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
mainStage.setScene(new Scene(root));
mainStage.show();
}
}

View File

@@ -0,0 +1,58 @@
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 java.io.IOException;
/**
* 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 (Exception e) {
e.printStackTrace();
}
} );
setGraphic( btn );
setText( null );
}
}
};
return cell;
}
}

View File

@@ -0,0 +1,183 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import javafx.scene.layout.FlowPane;
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.User;
import new_build.server.control.ServerController;
/**
* Pane Class as View Element for Chat Messages
*/
public class ChatBox extends MessagePane {
String text;
long date;
String displayName;
String userName;
byte[] profilePic;
Message assignedMessage;
boolean containsImage;
boolean containsFile;
public ChatBox(FlowPane layout, Message message){
this.getChildren().addAll(layout.getChildren());
this.assignedMessage = message;
Sendable extension = this.assignedMessage.getExtension();
if(extension != null && extension.getType() == SepFile.class) {
SepFile file = (SepFile) extension;
for(PictureFileEnding ending : PictureFileEnding.values()) {
if(file.getName().endsWith(ending.getFileEnding())) {
containsImage = true;
}
}
if(!containsImage) {
containsFile = true;
}
}
extractInfoFromMessage(message);
}
/**
* Adds the message content for the View Element
* @param message Message Object
*/
public void setInformation(Message message){
extractInfoFromMessage(message);
Label textLabel = new Label(text);
textLabel.setMinHeight(200);
Label usernameLabel = new Label(displayName);
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);
}
private void extractInfoFromMessage(Message message) {
User sendingUser = message.getSendingUser();
this.userName = message.getSendingUser().getUserName();
this.text = message.getContent();
this.date = message.getTimeStamp().getTime();
if (sendingUser.getUserName().toLowerCase() != "system") {
this.displayName = message.getSendingUser().getFirstName() + " " + message.getSendingUser().getLastName();
} else {
this.displayName = "";
}
this.profilePic = message.getSendingUser().getProfilePic();
}
/**
* Returns true if message is an poll.
* Returns false if message is not an poll
* @return
*/
@Override
public boolean isPoll() {
return false;
}
/**
* Returns true if message is an expired poll.
* Returns false if message is not an expired poll.
* @return
*/
@Override
public boolean isClosedPoll() {
return false;
}
/**
* Return Message Date
* @return
*/
public Date getDate() {
return this.assignedMessage.getTimeStamp();
}
/**
* Return the sending user of the Message
* @return
*/
public User getUser() {
return this.assignedMessage.getSendingUser();
};
public String getDisplayName() {
return this.displayName;
}
/**
* Returns true if message is an system message
* Returns false if message is not an system message
* @return
*/
public boolean isSystemMessage() {
return this.assignedMessage
.getSendingUser()
.getUserName()
.equals(ServerController.SYSTEM.getUserName());
}
/**
* Returns true if message has an attachement
* Returns false if message has not an attachement
* @return
*/
@Override
public boolean hasAttachement() {
return this.containsFile;
}
/**
* Returns true if message has an picture attachement
* Returns false if message has not an picture attachement
* @return
*/
@Override
public boolean hasPictureAttachement() {
return this.containsImage;
}
/**
* Returns true if message date is between date a and date b
* Returns false if message date is not between date a and date b
* @param a Start Date
* @param b End Date
* @return
*/
@Override
public boolean isInDate(Date a, Date b) {
if(new Date(this.date).after(a) && new Date(this.date).before(b)) {
return true;
} else {
return false;
}
}
/**
* Returns true if message is written by passed username
* Returns false if message is not written by passed username
* @param filteredUserName Username to compare
* @return
*/
public boolean writtenByUser(String filteredUserName) {
System.out.println(filteredUserName + " equals " + this.userName + " ?");
return filteredUserName.equals(userName);
}
}

View File

@@ -0,0 +1,666 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
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.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.*;
import new_build.models.taskboard.Task;
import new_build.server.constants.PermissionRole;
import new_build.server.control.ServerController;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.sql.Date;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* Controller Class of the Chat View.
* Implements the Filter function for Chat Messages,
* View Logic and Message Handling.
*/
public class ChatController implements ViewController{
private static DateFormat chatDateFormat = new SimpleDateFormat("dd.MM.yy HH:mm");
/**
* Filter selector for no filter.
*/
public static final String KEIN_FILTER = "Kein Filter ausgewählt";
/**
* Filter selector for active polls.
*/
public static final String LAUFENDE_ABSTIMMUNGEN = "Laufende Abstimmungen";
/**
* Filter selector for closed polls.
*/
public static final String ABGESCHLOSSENE_ABSTIMMUNGEN = "Abgeschlossene Abstimmungen";
/**
* Filter selector for messages with attachements.
*/
public static final String NACHRICHTEN_MIT_DATEIANHANG = "Nachrichten mit Dateianhang";
/**
* Filter selector for messages with picture attachements.
*/
public static final String NACHRICHT_MIT_BILDANHANG = "Nachricht mit Bildanhang";
/**
* Filter selector for users.
*/
public static final String BENUTZER = "Benutzer";
/**
* Filter Selector for system messages.
*/
public static final String SYSTEMNACHRICHTEN = "Systemnachrichten";
/**
* Filter Selector for messages between two dates.
*/
public static final String DATUM = "Datum";
private Group assignedGroup;
SepFile chosenFile;
@FXML
private DatePicker datePicker;
@FXML
private ChoiceBox<Integer> hours;
@FXML
private ChoiceBox<Integer> minutes;
@FXML
private Button sendButton;
@FXML
private ImageView appendixButton;
@FXML
private Button backToUserHubButton;
@FXML
private ListView<Label> userRoleList;
private ObservableList<Label> userRoles = FXCollections.observableArrayList();
@FXML
private TextArea messageField;
@FXML
private ListView<MessagePane> listView;
ObservableList<MessagePane> chatBoxList = FXCollections.observableArrayList();
ObservableList<MessagePane> orderedList = FXCollections.observableArrayList();
private List<PollBox> pollBoxList;
@FXML
private ChoiceBox filterSelector;
@FXML
private Label groupIDLabel;
@FXML
private HBox chatLabelBox;
private Filter currentFilter;
private Stage dialogStage;
public ChatController(){
System.out.println("constr");
pollBoxList = new ArrayList<>();
}
@SuppressWarnings("unchecked")
@Override
public void initialize(URL location, ResourceBundle resources) {
System.out.println("chatinit");
filterSelector.getItems().addAll(
KEIN_FILTER,
LAUFENDE_ABSTIMMUNGEN,
ABGESCHLOSSENE_ABSTIMMUNGEN,
NACHRICHTEN_MIT_DATEIANHANG,
NACHRICHT_MIT_BILDANHANG,
BENUTZER,
SYSTEMNACHRICHTEN,
DATUM);
filterSelector.getSelectionModel().selectFirst();
listView.setItems(chatBoxList);
ClientController.controller.registerViewController(this);
assignedGroup = ClientController.controller.getWorkingGroup();
GroupInformation groupInformation = ClientController.controller.getKnownTeamMap().get(assignedGroup);
int pollListIndex = 0;
int messageListIndex = 0;
LinkedList<Message> messageList = groupInformation.getMessagesInChatRoom();
LinkedList<Poll> pollList = groupInformation.getPolls();
Poll currPoll = null;
Message m = null;
Timestamp messageTimestamp = null;
Timestamp pollTimestamp = null;
while (pollListIndex < pollList.size() || messageListIndex < messageList.size()){
if (pollListIndex < pollList.size()){
currPoll = pollList.get(pollListIndex);
} else {
currPoll = new Poll(Integer.MAX_VALUE, "",
new Timestamp(Long.MAX_VALUE), new Timestamp(Long.MAX_VALUE));
}
if (messageListIndex < messageList.size()) {
m = messageList.get(messageListIndex);
} else {
m = new Message(null, null, null, null, null);
m.setTimeStamp(new Date(Long.MAX_VALUE));
}
messageTimestamp = new Timestamp(m.getTimeStamp().getTime());
pollTimestamp = currPoll.getCreationDate();
if (messageTimestamp.before(pollTimestamp)){
addMessage(m);
messageListIndex++;
} else if (pollTimestamp.before(messageTimestamp)){
addPoll(currPoll);
pollListIndex++;
}
}
this.addUsersToRoleList();
messageField.setPromptText("Enter your message here...");
User sendingUser = ClientController.controller.getSendingUser().removePassword();
HashMap <User, PermissionRole> groupRoleMap =
ClientController.controller.getKnownTeamMap().get(assignedGroup).getRoleMap();
if (groupRoleMap.get(sendingUser)!=null) {
if (groupRoleMap.get(sendingUser).hasAdminRights()){
this.includeAdminButton();
}
}
this.choiceboxSelectionChangeListener();
this.groupIDLabel.setText(this.assignedGroup.getName());
this.setUpTimeChoiceBox();
//First shown message should be a poll
this.setFirstMessageAsPoll();
}
private void setUpTimeChoiceBox() {
hours.getItems().addAll(IntStream.range(0, 24).boxed().collect(Collectors.toList()));
minutes.getItems().addAll(IntStream.range(0, 6).boxed().map(n -> 10 * n).collect(Collectors.toList()));
}
/**
* Method to detect whether an message is an "normal" text message or an status message
* @param m
*/
@Override
public void reactToNewMessage(Message m) {
if(m.getControlHeaderType().equals(ServerStatus.class) && m.getGroup().equals(assignedGroup)) {
ServerStatus status = ((ServerStatus) m.getControlHeader());
switch (status){
case NEW_MESSAGE: {
System.out.println("adding message...");
Platform.runLater(() -> {
addMessage(m);
});
break;
}
case POLL_CREATED: {
Group group = m.getGroup();
Poll newPoll = ((Poll) m.getExtension());
ClientController.getController().getKnownTeamMap().get(m.getGroup()).getMessagesInChatRoom().add(m);
ClientController.getController().getKnownTeamMap().get(group).getPolls().add(newPoll);
Platform.runLater(() -> addPoll(newPoll));
break;
}
case VOTE_SUCCESSFUL : {
Platform.runLater(() -> addVote(m.getSendingUser(), ((Vote) m.getExtension())));
break;
}
case POLL_FINISHED: {
Message pollFinishedMessage = new Message(m.getGroup(),
ServerStatus.NEW_MESSAGE, ServerController.SYSTEM, m.getContent(), m.getExtension());
Platform.runLater(() -> addMessage(pollFinishedMessage));
break;
}
case TASK_ADDED: {
Task t = (Task) m.getExtension();
Message taskAddedMessage = new Message(m.getGroup(), ServerStatus.TASK_ADDED,
ServerController.SYSTEM, "Task with Title \'" + t.getTitle()
+ "\' added", null);
Platform.runLater(() -> addMessage(taskAddedMessage));
break;
}
case TASK_CHANGED:
Task t = (Task) m.getExtension();
Message taskAddedMessage = new Message(m.getGroup(), ServerStatus.TASK_ADDED,
ServerController.SYSTEM, "Task with Title \'" + t.getTitle()
+ "\' added", null);
Platform.runLater(() -> addMessage(taskAddedMessage));
break;
case MEMBER_JOINED: {
Platform.runLater(() -> addMessage(m));
break;
}
case ROLE_CHANGED: {
Platform.runLater(() -> addMessage(m));
break;
}
case MEMBER_LEFT: {
Platform.runLater(() -> addMessage(m));
break;
}
}
this.setFirstMessageAsPoll();
}
}
/**
* Method to change an Scene in the View.
* @param changeToScene Scene to change to
*/
public void changeScene(String changeToScene) {
try {
// 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();
} catch (Exception e){
e.printStackTrace();
}
}
/**
* EventListener for Send Button
* @throws IOException
*/
public void sendButtonClicked() throws IOException {
if (messageField.getText().equals("")) return;
Message m = new Message(ClientController.controller.getWorkingGroup(),
Command.SENDMESSAGE, ClientController.controller.getSendingUser(),
messageField.getText(), chosenFile);
chosenFile = null;
ClientController.controller.sendMessage(m);
messageField.setText("");
}
/**
* EventListener for Poll Button
*/
public void pollButtonClicked(){
if (hours.getValue() == null || minutes.getValue() == null || datePicker.getValue() == null) return;
LocalTime time = LocalTime.of(hours.getValue(), minutes.getValue());
LocalDate date = datePicker.getValue();
Timestamp timestamp = Timestamp.valueOf(time.atDate(date));
Poll p = new Poll(0, messageField.getText(), timestamp);
Message m = new Message(assignedGroup, Command.ADDPOLL, ClientController.controller.getSendingUser(),
"", p );
ClientController.controller.sendMessage(m);
messageField.setText("");
}
/**
* EventListener for attachement Button.
* @throws IOException
*/
public void appendixButtonClicked() throws IOException {
FileChooser fileChooser = new FileChooser();
File fileWithPath = fileChooser.showOpenDialog(null);
if (fileWithPath == null) return;
int lastIndexBeforeFileEnding = fileWithPath.getName().lastIndexOf(".");
System.out.println(lastIndexBeforeFileEnding + " laxt index before ending of selected file ...");
String fileEnding = fileWithPath.getName().substring(lastIndexBeforeFileEnding+1);
System.out.println("filending is: " + fileEnding);
SepFile tempFile = new SepFile(fileWithPath, fileWithPath.getName());
for (PictureFileEnding ending : PictureFileEnding.values()){
if (fileEnding.equals(ending.getFileEnding())) makeFilePicture(tempFile);
}
if (tempFile.getByteData() != null){
this.chosenFile = tempFile;
System.out.println("valid file is captured");
}
}
/**
* EventListener for Back to Userhub Button
* @throws IOException
*/
public void backToUserHubButtonClicked() throws IOException {
Platform.runLater(() -> {
try {
ClientController.controller.getKnownTeamMap().get(assignedGroup).updateReadIndex();
changeScene("userhub");
} catch (Exception e) {
e.printStackTrace();
}
});
}
/**
* Add message to the ListView
* @param m Message Object
*/
public void addMessage(Message m){
try {
FlowPane 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"));
Pane extensionPane = ((Pane) templateScene.lookup("#extensionPane"));
contentField.setText(m.getContent());
System.out.println(System.getProperty("user.dir"));
byte[] profilePic = m.getSendingUser().getProfilePic();
javafx.scene.image.Image image;
if(profilePic == null) image = new Image
("/new_build/client/view/sepboard/GUIview/resources/image/Places-user-identity-icon" +
".png");
else {
ByteArrayInputStream in = new ByteArrayInputStream(m.getSendingUser().getProfilePic());
image = new Image(in);
}
picField.setImage(image);
User u = m.getSendingUser();
nameField.setText(u.getUserName() + " (" + u.getFirstName() + " " + u.getLastName() + ")");
if (u.getFirstName().equals("SYSTEM")) {
nameField.setTextFill(Color.web("#ff0000"));
}
timeField.setText(chatDateFormat.format((new Date(m.getTimeStamp().getTime()))));
if (m.getExtension() != null && m.getExtension().getType() == SepFile.class){
System.out.println("found a file with message");
SepFile sendedFile = (SepFile) m.getExtension();
if (sendedFile.isImage()) addImageToMessage(sendedFile, extensionPane);
else addFileToMessage(sendedFile, extensionPane);
} else System.out.println("message does not contain a file");
ChatBox messageBox = new ChatBox(template, m);
chatBoxList.add(messageBox);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Add Vote to an Poll.
* @param id Poll ID
* @param value Value for Poll
*/
public void addVote(int id, boolean value){
User votingUser = ClientController.getController().getSendingUser().removePassword();
Vote v = new Vote(id, votingUser, value);
Message voteMessage = new Message(assignedGroup, Command.VOTE_POLL, ClientController.controller.getSendingUser(),
"", v);
ClientController.controller.sendMessage(voteMessage);
}
/**
* EventListener for detecting selection of an element in the filter choicebox.
*/
@SuppressWarnings("unchecked")
public void choiceboxSelectionChangeListener() {
// Add eventlistener to choicebox.
filterSelector.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("ListView Selection Changed (selected: " + newValue.toString() + ")");
//React to different elements in choicebox
if(newValue.toString().equals(KEIN_FILTER)) {
listView.setItems(chatBoxList);
} else if (newValue.toString().equals(LAUFENDE_ABSTIMMUNGEN)) {
System.out.println("Laufende Abstimmungen ausgewählt");
orderedList.clear();
for(int i = 0; i < chatBoxList.size(); i++) {
if(chatBoxList.get(i).isPoll()) {
orderedList.add(chatBoxList.get(i));
}
}
listView.setItems(orderedList);
} else if (newValue.toString().equals(ABGESCHLOSSENE_ABSTIMMUNGEN)) {
System.out.println("Abgeschlossene Abstimmungen ausgewählt");
orderedList.clear();
for(int i = 0; i < chatBoxList.size(); i++) {
if(chatBoxList.get(i).isClosedPoll()) {
orderedList.add(chatBoxList.get(i));
}
}
listView.setItems(orderedList);
} else if (newValue.toString().equals(NACHRICHTEN_MIT_DATEIANHANG)) {
System.out.println("Nachrichten mit Dateianhang");
orderedList.clear();
for(int i = 0; i < chatBoxList.size(); i++) {
if(chatBoxList.get(i).hasAttachement()) {
orderedList.add(chatBoxList.get(i));
}
}
listView.setItems(orderedList);
} else if (newValue.toString().equals(NACHRICHT_MIT_BILDANHANG)) {
currentFilter = new Filter() {
@Override
public boolean passesFilter(MessagePane messageBox) {
return messageBox.hasPictureAttachement();
}
};
System.out.println("Nachrichten mit Bildanhang");
orderedList.clear();
for(int i = 0; i < chatBoxList.size(); i++) {
if (currentFilter.passesFilter(chatBoxList.get(i))) {
orderedList.add(chatBoxList.get(i));
}
}
listView.setItems(orderedList);
} else if (newValue.toString().equals(BENUTZER)) {
System.out.println("Benutzer ausgewählt");
// Test
this.dialogStage = new Stage();
UserSearch controller = new UserSearch(this);
FXMLLoader dialogLoader = new FXMLLoader(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/user_search.fxml"));
dialogLoader.setController(controller);
Parent root = null;
try {
root = dialogLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
Scene scene = new Scene(root);
dialogStage.setScene(scene);
dialogStage.showAndWait();
} else if (newValue.toString().equals(SYSTEMNACHRICHTEN)) {
currentFilter = new Filter() {
@Override
public boolean passesFilter(MessagePane messageBox) {
return messageBox.isSystemMessage();
}
};
System.out.println("Systemnachrichten ausgewählt");
orderedList.clear();
for(int i = 0; i < chatBoxList.size(); i++) {
if(currentFilter.passesFilter(chatBoxList.get(i))) {
orderedList.add(chatBoxList.get(i));
}
}
listView.setItems(orderedList);
} else if (newValue.toString().equals(DATUM)) {
System.out.println("Datum ausgewählt");
this.dialogStage = new Stage();
TimeSearch controller = new TimeSearch(this);
FXMLLoader dialogLoader = new FXMLLoader(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/time_search.fxml"));
dialogLoader.setController(controller);
Parent root = null;
try {
root = dialogLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
Scene scene = new Scene(root);
dialogStage.setScene(scene);
dialogStage.showAndWait();
}
});
}
/**
* Set passed fiter.
* @param newFilter Filter to set
*/
public void setFilter(Filter newFilter) {
this.currentFilter = newFilter;
}
/**
* Apply filter to the ListView of the chat.
*/
public void applyFilter() {
this.orderedList.clear();
for (MessagePane pane : this.chatBoxList){
if (currentFilter.passesFilter(pane)) {
orderedList.add(pane);
System.out.println("applies to filter");
}
}
if (dialogStage != null) dialogStage.close();
dialogStage = null;
listView.setItems(orderedList);
}
//--private-methods-------------------------------------------------------------------------------------------
private void includeAdminButton() {
Button adminButton = new Button("Benutzerverwaltung");
adminButton.setOnAction((e) -> {
changeScene("clientManagement_general");
});
chatLabelBox.getChildren().addAll(adminButton);
}
/**
* Add poll to the ListView
* @param poll Poll to add
*/
private void addPoll(Poll poll){
System.out.println("adding poll");
FlowPane 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);
pollBoxList.add(box);
if (poll.getIsRunning()) {
chatBoxList.add(0, box);
} else {
chatBoxList.add(box);
}
listView.setItems(chatBoxList);
} catch (IOException e) {
e.printStackTrace();
}
}
private void addVote(User votingUser, Vote newVote) {
for (Poll p : ClientController.controller.getKnownTeamMap()
.get(ClientController.controller.getWorkingGroup()).getPolls()){
if (p.getPollID() == newVote.getPollVotedIn()){
p.addVote(votingUser, newVote.getValue());
PollBox box = this.getPollBoxById(p.getPollID());
box.update();
}
}
}
/**
* Add file to a message.
* @param sendedFile File to add to the message
* @param extensionPane ViewElement
*/
private void addFileToMessage(SepFile sendedFile, Pane extensionPane) {
System.out.println("file is no image");
HBox fileselectionBox = new HBox();
Label FileLabel = new Label(sendedFile.getName());
DownloadButton downloadButton = new DownloadButton(sendedFile);
fileselectionBox.getChildren().addAll(FileLabel, downloadButton);
extensionPane.getChildren().add(fileselectionBox);
}
/**
* Add Image to a message.
* @param sendedFile Image to add to the message
* @param extensionPane ViewElement
*/
private void addImageToMessage(SepFile sendedFile, Pane extensionPane) {
System.out.println("file is image");
ImageView imageView = new ImageView();
Image image = new Image(new ByteArrayInputStream(sendedFile.getByteData()));
imageView.setImage(image);
imageView.setFitHeight(250);
extensionPane.getChildren().add(imageView);
extensionPane.setPrefWidth(imageView.getFitWidth());
extensionPane.setPrefHeight(imageView.getFitHeight());
extensionPane.setMinHeight(imageView.getFitHeight());
extensionPane.setMaxHeight(imageView.getFitHeight());
extensionPane.autosize();
}
private void addUsersToRoleList(){
HashMap<User, PermissionRole> userRoleMap = ClientController.controller.getKnownTeamMap()
.get(ClientController.controller.getWorkingGroup()).getRoleMap();
for(User u : userRoleMap.keySet()){
System.out.println("adding a new label ...");
Label l = new Label();
l.setText(u.getUserName() + " - " + userRoleMap.get(u));
userRoles.add(l);
}
userRoleList.setItems(userRoles);
}
private PollBox getPollBoxById(int id) {
Optional<PollBox> foundBox = pollBoxList.stream()
.filter(b -> b.getAssignedPoll().getPollID() == id).findFirst();
return foundBox.get();
}
private void makeFilePicture(SepFile pictureFile) {
pictureFile.setImage(true);
}
private void setFirstMessageAsPoll(){
Platform.runLater(()->{
if ((this.pollBoxList == null && this.chatBoxList == null )
|| this.pollBoxList.size() == 0 && this.chatBoxList.size() == 0) return;
if (!(this.chatBoxList.get(0) instanceof PollBox)){
for (int i = 0; i < this.pollBoxList.size(); i++){
if (this.pollBoxList.get(i).getAssignedPoll().getIsRunning()){
PollBox temp = this.pollBoxList.get(i);
this.chatBoxList.add(0, temp);
System.out.println("New poll pinned as first message!");
}
}
}
});
}
}

View File

@@ -0,0 +1,58 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.event.ActionEvent;
import new_build.client.controller.ClientController;
import new_build.client.view.sepboard.GUIview.Main;
import new_build.models.common.Controller;
import new_build.models.network_organisation.Group;
import new_build.server.constants.PermissionRole;
import java.io.IOException;
public class DefaultButtonHandleStrategy implements GroupButtonHandleStrategy{
@Override
public void chatButtonClicked(Group invokingGroup, ActionEvent e) {
ClientController.controller.changeWorkingGroup(invokingGroup.getName());
try {
Main.changeScene("chat");
} catch (IOException e1) {
e1.printStackTrace();
}
}
/**
* If the user is the group admin, the scene will be changed to the task board for admin.
* Else the user gets to a task board with restricted rights
* @param invokingGroup
* @param e
*/
@Override
public void taskBoardButtonClicked(Group invokingGroup, ActionEvent e) {
ClientController.controller.changeWorkingGroup(invokingGroup.getName());
try {
if(ClientController.controller.getKnownTeamMap().get(invokingGroup).getRoleMap()
.get(ClientController.controller.getSendingUser().removePassword()).hasTeamleaderRights()){
Main.changeScene("taskboardForAdmin");
} else {
Main.changeScene("taskboard");
}
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("Error - can't change to TaskBoard view");
}
}
@Override
public void leaveButtonClicked(Group invokingGroup, ActionEvent e) {
System.out.println("not yet implemented");
}
@Override
public void notificationsSwitched(Group invokingGroup, ActionEvent e) {
System.out.println("not yet implemented");
}
}

View File

@@ -0,0 +1,41 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.scene.control.Button;
import javafx.stage.FileChooser;
import new_build.models.common.data.SepFile;
import java.io.*;
/**
* Controller class for the Download Button
*/
public class DownloadButton extends Button {
private SepFile file;
public DownloadButton(SepFile fileToDownload){
super("Download file");
this.file = fileToDownload;
setOnAction(e -> letUserSaveFile());
}
/**
* Opens file chooser for save location of downloading file.
* Download process
*/
private void letUserSaveFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialFileName(file.getName());
File file = fileChooser.showSaveDialog(this.getScene().getWindow());
if (file != null) {
try {
FileOutputStream fileWriter = new FileOutputStream(file);
fileWriter.write(this.file.getByteData());
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,6 @@
package new_build.client.view.sepboard.GUIview.controller;
public interface Filter {
boolean passesFilter(MessagePane messageBox);
}

View File

@@ -0,0 +1,12 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.scene.layout.AnchorPane;
public class GroupBox extends AnchorPane {
public GroupBox(AnchorPane groupBoxTemplate) {
this.getChildren().add(groupBoxTemplate);
}
}

View File

@@ -0,0 +1,17 @@
package new_build.client.view.sepboard.GUIview.controller;
import new_build.models.network_organisation.Group;
import javafx.event.ActionEvent;
/**
* Created by Tobias on 21.06.2017.
*/
public interface GroupButtonHandleStrategy {
void chatButtonClicked(Group invokingGroup, ActionEvent e);
void taskBoardButtonClicked(Group invokingGroup, ActionEvent e);
void leaveButtonClicked(Group invokingGroup, ActionEvent e);
void notificationsSwitched(Group invokingGroup, ActionEvent e);
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,137 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.application.Platform;
import javafx.event.EventHandler;
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.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.text.Font;
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;
/**
* Controller class for the Login View
*/
public class LoginController implements ViewController{
@FXML
private Button loginButton;
@FXML
private Button registerButton;
@FXML
private TextField usernameField;
@FXML
private PasswordField passwordField;
@FXML
private Label passwordIsFalse;
private void handleButtonAction(ActionEvent event){
}
public LoginController(){
}
/**
* EventListener for the Login button
* @throws IOException
*/
@FXML
public void loginButtonClicked() throws IOException {
UserLogin logintry = new UserLogin(0, usernameField.getText(), "","", passwordField.getText(), null);
Message m = new Message(Group.DEFAULT_GROUP, Command.LOGIN, logintry, usernameField.getText() + " "
+ passwordField.getText(), logintry);
ClientController.controller.sendMessage(m);
}
/**
* If the registerButton has been clicked, the scene switches to registration
* @throws IOException
*/
@FXML
public void registerButtonClicked() throws IOException {
this.changeScene("registration");
System.out.println("clicked registration");
}
@FXML
private void passwordForgottenLinkClicked() throws IOException {
this.changeScene("password_forgotten");
}
public void changeScene(String changeToScene) {
try{
// 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();
} catch(Exception e){
e.printStackTrace();
}
}
/**
* If login was successful the scene changes to the userhub scene.
* Else the user stays at the login scene and will be informed about the wrong access data.
* @param m
*/
@Override
public void reactToNewMessage(Message m) {
System.out.println("got informed about the message");
Platform.runLater(() -> {
if(m.getControlHeaderType().equals(ServerStatus.class)){
ServerStatus status = ((ServerStatus) m.getControlHeader());
if (status.equals(ServerStatus.LOGIN_SUCCESSFUL)) try {
System.out.println("changing the scene to userhub");
this.changeScene("userhub");
} catch (Exception e) {
e.printStackTrace();
}
else if(status.equals(ServerStatus.LOGIN_FAILED)){
passwordIsFalse.setVisible(true);
}
}
});
}
@Override
public void initialize(URL location, ResourceBundle resources) {
ClientController.controller.registerViewController(this);
System.out.println("initialized successfully");
passwordIsFalse.setVisible(false);
Font.loadFont(getClass().getResourceAsStream("/resources/font/ff_market.ttf"), 14);
final EventHandler<KeyEvent> handler = keyEvent -> {
if (keyEvent.getCode() == KeyCode.ENTER) {
UserLogin logintry = new UserLogin(0, usernameField.getText(), "", "", passwordField.getText(), null);
Message m = new Message(Group.DEFAULT_GROUP, Command.LOGIN, logintry, usernameField.getText() + " "
+ passwordField.getText(), logintry);
ClientController.controller.sendMessage(m);
}
};
usernameField.addEventHandler(KeyEvent.KEY_PRESSED, handler);
passwordField.addEventHandler(KeyEvent.KEY_PRESSED, handler);
}
}

View File

@@ -0,0 +1,18 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.scene.layout.FlowPane;
import new_build.models.network_organisation.User;
import java.util.Date;
public abstract class MessagePane extends FlowPane{
public abstract boolean isPoll();
public abstract boolean isClosedPoll();
public abstract Date getDate();
public abstract User getUser();
public abstract boolean isSystemMessage();
public abstract boolean hasAttachement();
public abstract boolean hasPictureAttachement();
public abstract boolean isInDate(Date a, Date b);
public abstract boolean writtenByUser(String filteredUserName);
}

View File

@@ -0,0 +1,72 @@
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");
}
public void changeScene(String changeToScene) {
try {
// 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();
} catch (Exception e){
e.printStackTrace();
}
}
@Override
public void reactToNewMessage(Message m) {
}
@Override
public void initialize(URL location, ResourceBundle resources) {
ClientController.controller.registerViewController(this);
}
}

View File

@@ -0,0 +1,16 @@
package new_build.client.view.sepboard.GUIview.controller;
public enum PictureFileEnding {
JPG("jpg"), PNG("png"), JPEG("jpeg"), GIF("gif");
private final String fileEnding;
PictureFileEnding(String fileEnding) {
this.fileEnding = fileEnding;
}
public String getFileEnding(){
return fileEnding;
}
}

View File

@@ -0,0 +1,161 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import new_build.models.common.polls.Poll;
import new_build.models.network_organisation.User;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
/**
* Pane Class as View Element for Chat Messages
*/
public class PollBox extends MessagePane {
private static final DateFormat pollDateFormat = new SimpleDateFormat("hh.MM.yyyy HH:mm");
private Poll assignedPoll;
private final PollBoxFieldData fieldData;
public void update(){
updatePollText();
}
public Poll getAssignedPoll() {
return assignedPoll;
}
/**
*
* @param layout layout to present the poll-information
* @param assignedPoll poll that is presented
* @param controller controller, the poll is presented on
*
* Constructs and fills the PollBox
*/
public PollBox(FlowPane 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"));
fieldData = new PollBoxFieldData(templateScene).fillData();
VoteForButton.setOnAction((e) -> {
controller.addVote(assignedPoll.getPollID(),true);
});
voteAgainstButton.setOnAction((e) -> {
controller.addVote(assignedPoll.getPollID(), false);
});
updatePollText();
this.getChildren().addAll(layout.getChildren());
}
private void updatePollText() {
System.out.println("updateing poll data");
fieldData.getExpireDate().setText(pollDateFormat.format(assignedPoll.getExpiringDate()));
fieldData.getVoteField().setText(assignedPoll.getVotesFor().size() + ":" + assignedPoll.getVotesAgainst()
.size() + "(" +
assignedPoll.getVotesAbstensions().size() + ")");
fieldData.getPollText().setText(assignedPoll.getPollText());
System.out.println(fieldData.getExpireDate().getText() + " "
+ fieldData.getVoteField().getText() + " "
+ fieldData.getPollText().getText()
);
}
/**
*
* @return if this instance is a running poll
*/
@Override
public boolean isPoll() {
if(this.assignedPoll.getIsRunning()) {
return true;
} else {
return false;
}
}
@Override
public boolean isClosedPoll() {
// this.assignedPoll.getExpiringDate().before(java.sql.Date.valueOf(LocalDate.now()))
if(!this.assignedPoll.getIsRunning()) {
return true;
} else {
return false;
}
}
/**
*
* @return ExpiringDate from assigned Poll
*/
@Override
public Date getDate() {
return this.getDate();
}
/**
*
* @return creatingUser of assignedPoll
*/
@Override
public User getUser() {
return null;
}
@Override
public boolean isSystemMessage() {
return false;
}
/**
*
* @return that this is not a system-message
*/
@Override
public boolean hasAttachement() {
return false;
}
/**
* @return that this has no PictureAttachement f
*/
@Override
public boolean hasPictureAttachement() {
return false;
}
/**
*
* @param a left border of timespan
* @param b right border of timespan
* @return that this pollbox cant be filtered for a timespan
*/
@Override
public boolean isInDate(Date a, Date b) {
return false;
}
/**
*
* @param filteredUserName
* @return that this pollbox cant be filtered by a username
*/
@Override
public boolean writtenByUser(String filteredUserName) {
return false;
}
}

View File

@@ -0,0 +1,35 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.text.Text;
class PollBoxFieldData {
private Scene templateScene;
private Label expireDate;
private Label voteField;
private Text pollText;
public PollBoxFieldData(Scene templateScene) {
this.templateScene = templateScene;
}
public Label getExpireDate() {
return expireDate;
}
public Label getVoteField() {
return voteField;
}
public Text getPollText() {
return pollText;
}
public PollBoxFieldData fillData() {
expireDate = ((Label) templateScene.lookup("#expireDate"));
voteField = ((Label) templateScene.lookup("#voteField"));
pollText = ((Text) templateScene.lookup("#pollText"));
return this;
}
}

View File

@@ -0,0 +1,210 @@
package new_build.client.view.sepboard.GUIview.controller;
import com.sun.javafx.fxml.builder.JavaFXImageBuilder;
import javafx.embed.swing.SwingFXUtils;
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.Label;
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.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 javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ResourceBundle;
/**
* Controller class for the Profile Settings View
*/
public class ProfileSettingsController implements ViewController{
@FXML
Button abortButton;
@FXML
ImageView profilePicture;
@FXML
Hyperlink changePictureLink;
@FXML
private TextField surnameField;
@FXML
private TextField lastnameField;
@FXML
private TextField passwordField;
@FXML
private TextField approvedPasswordField;
@FXML
private Label passwordWrongLabel;
@Override
public void initialize(URL location, ResourceBundle resources) {
ClientController.controller.registerViewController(this);
UserLogin currentUser = ClientController.getController().getSendingUser();
Image profileImage = null;
this.setImageClip();
if (currentUser.getProfilePic() != null){
ByteArrayInputStream in = new ByteArrayInputStream(currentUser.getProfilePic());
profileImage = new Image(in);
} else {
profileImage = new Image("/new_build/client/view/sepboard/GUIview/resources/image/" +
"Places-user-identity-icon.png");
}
profilePicture.setImage(profileImage);
surnameField.setText(currentUser.getFirstName());
lastnameField.setText(currentUser.getLastName());
}
@Override
public void reactToNewMessage(Message m) {
if (m.getControlHeader() == ServerStatus.PROFILE_CHANGE_SUCCESSFUL){
System.out.println("ProfileSettingsController: Received a new message");
}
}
public void changeScene(String changeToScene) {
try {
// 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();
} catch (Exception e){
e.printStackTrace();
}
}
/**
* Changes will be saved.
* Scene changes to Userhub.
* @throws IOException
*/
@FXML
private void changeButtonClicked() throws IOException {
UserLogin changes = this.setUpNewUserLogin();
Message message = new Message(Group.DEFAULT_GROUP,
Command.CHANGEUSER,
ClientController.controller.getSendingUser(),
"changing profile of userID " + ClientController.controller.getSendingUser().getID(),
changes);
System.out.println("New UserLogin for username " + ClientController.controller.getSendingUser().getUserName());
System.out.println("FirstName: " + ClientController.controller.getSendingUser().getFirstName());
System.out.println("LastName: " + ClientController.controller.getSendingUser().getLastName());
System.out.println("Password: " + ClientController.controller.getSendingUser().getPassword());
ClientController.controller.sendMessage(message);
this.changeScene("userhub");
}
/**
* The scene will be changed to userhub after pressing the abort Button
* @throws IOException
*/
@FXML
private void abortButtonClicked() throws IOException {
this.changeScene("userhub");
}
/**
* Method to change the users Profilepicture
* Sets ExtensionFilters because Java only support JPG, GIF, PNG and BMP.
* Opens file and sends it to the server.
* Sets the picture in View.
* @throws IOException
*/
@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);
Path path = Paths.get(file.toURI());
byte[] imagedata = Files.readAllBytes(path);
ClientController.controller.getSendingUser().setProfilePic(imagedata);
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 = 50.0;
double Yheight = 75.0;
Circle clip = new Circle(Xwidth, Yheight, 60);
profilePicture.setClip(clip);
}
private UserLogin setUpNewUserLogin(){
UserLogin currentUserLogin = ClientController.controller.getSendingUser();
String surname;
String lastname;
String password;
if (this.surnameField.getText().isEmpty()){
surname = currentUserLogin.getFirstName();
} else {
surname = surnameField.getText();
}
if (this.lastnameField.getText().isEmpty()){
lastname = currentUserLogin.getLastName();
} else {
lastname = lastnameField.getText();
}
if (this.passwordField.getText().isEmpty()){
password = currentUserLogin.getPassword();
} else {
//TODO password check
password = this.passwordField.getText();
}
UserLogin changedUserLogin = new UserLogin(currentUserLogin.getID(),
currentUserLogin.getUserName(),
surname,
lastname,
password,
ClientController.controller.getSendingUser().getProfilePic());
return changedUserLogin;
}
}

View File

@@ -0,0 +1,114 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.application.Platform;
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 java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller Class for the Registration View
*/
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){
}
/**
* EventListener for the Register Button
* Sends REGISTER Message to the Server.
* @throws IOException
*/
@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, null);
Message m = new Message(Group.DEFAULT_GROUP, Command.REGISTER, user,
"", user);
ClientController.controller.sendMessage(m);
}
/**
* Changes the scene to login
* @throws IOException
*/
@FXML
public void backButtonClicked() throws IOException {
this.changeScene("login");
}
public void changeScene(String changeToScene) {
try {
// 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"));
Platform.runLater(
() -> {
stage.setScene(new Scene(root));
stage.show();
}
);
}catch (IOException e){
e.printStackTrace();
}
}
/**
* If the registration was successful, the scene will be changed to login
* @param m
*/
@Override
public void reactToNewMessage(Message m) {
ServerStatus status = ((ServerStatus) m.getControlHeader());
if(status.equals(ServerStatus.REGISTRATION_SUCCESSFUL)) try {
this.changeScene("login");
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
ClientController.controller.registerViewController(this);
}
}

View File

@@ -0,0 +1,35 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.Button;
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;
}
}

View File

@@ -0,0 +1,401 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.InputEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.FlowPane;
import new_build.client.controller.ClientController;
import new_build.client.view.sepboard.GUIview.Main;
import new_build.models.common.data.Sendable;
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.GroupInformation;
import new_build.models.network_organisation.User;
import new_build.models.taskboard.EditTask;
import new_build.models.taskboard.State;
import new_build.models.taskboard.Task;
import new_build.server.constants.PermissionRole;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.ResourceBundle;
public class TaskboardController implements ViewController{
@FXML
private Button createTaskButton;
@FXML
private Button backToUserHubButton;
@FXML
private Button approveButton;
@FXML
private Button novateTaskButton;
@FXML
private Button changeTaskToButton;
@FXML
private Button deliverTaskButton;
@FXML
private TextField headerField;
@FXML
private TextField newTaskField;
@FXML
private ChoiceBox<State> changeStateOfTask = new ChoiceBox<>();
@FXML
private ListView<AnchorPane> listUsers = new ListView<>();
@FXML
private ListView<FlowPane> tableTasksApproved = new ListView<>();
private ObservableList<FlowPane> observableTasksApproved;
@FXML
private ListView<AnchorPane> listTasksCreated = new ListView<>();
private ObservableList<AnchorPane> observableTasksCreated;
private Task markedTask;
private User markedUser;
private LinkedList<Task> taskList;
private Group assignedGroup;
/**
* invokes the methods and updates them
* @param location
* @param resources
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
ClientController.controller.registerViewController(this);
this.assignedGroup = ClientController.controller.getWorkingGroup();
this.taskList = ClientController.controller.getKnownTeamMap().get(assignedGroup).getTasks();
this.observableTasksCreated = FXCollections.observableArrayList();
this.observableTasksApproved = FXCollections.observableArrayList();
this.setUpUsers();
this.setUpStateChoiceBox();
this.setUpCreatedTasks();
this.setUpApprovedTasks();
this.listTasksCreated.setItems(observableTasksCreated);
this.tableTasksApproved.setItems(observableTasksApproved);
}
@Override
/**
* Reacting to new messages:
* case TASK_ADDED: The task list of this group adds the new task
* case TASK_CHANGED: The task list drops the old version of the task and adds the new version, which is sent in the message
* in the end the view gets updated
*/
public void reactToNewMessage(Message m) {
System.out.println("TaskBoardController: Reacting to a new incoming message");
Platform.runLater(()->{
if (m.getControlHeader().equals(ServerStatus.TASK_ADDED)){
//TaskList of GroupInformation is already adapted in processMessage() of class ClientController
Task temp = (Task) m.getExtension();
observableTasksCreated.add(this.createTaskCreated(temp));
} else if (m.getControlHeader().equals(ServerStatus.TASK_CHANGED)){
//TaskList of GroupInformation is already adapted in processMessage() of class ClientController
Task temp = (Task) m.getExtension();
observableTasksApproved.add(this.createTaskApproved(temp));
} else {
System.out.println("TaskBoardController: ServerStatus not found");
}
});
listTasksCreated.setItems(observableTasksCreated);
tableTasksApproved.setItems(observableTasksApproved);
}
/**
* This method is used to create a task
*/
public void createTaskButtonClicked() throws IOException {
if (headerField.getText().length() < 3){
return;
}
Task task = new Task(headerField.getText(), newTaskField.getText(),
ClientController.controller.getWorkingGroup());
this.createAndSendMessage(task, Command.ADDTASK);
this.headerField.setText("");
this.newTaskField.setText("");
}
/**
* Changes scene to userHub
* @throws IOException
*/
public void backToUserHubButtonClicked() throws IOException {
changeScene("userhub");
}
/**
* This method is used by the team leader to approve a task, changes the state of a task from CREATED to PLANNED
* @throws IOException
*/
public void approveButtonClicked() throws IOException {
this.listTasksCreated.getItems().remove(
this.listTasksCreated.getSelectionModel().getSelectedItem());
this.listTasksCreated.refresh();
EditTask edit = new EditTask(this.markedTask.getTaskID(), State.PLANNED, null);
this.createAndSendMessage(edit, Command.CHANGETASK);
}
/**
* Assigning the marked user to the marked task
* @throws IOException
*/
public void changeUserButtonClicked() throws IOException {
this.tableTasksApproved.getItems().remove(
this.tableTasksApproved.getSelectionModel().getSelectedItem());
this.tableTasksApproved.refresh();
EditTask edit = new EditTask(this.markedTask.getTaskID(), null, this.markedUser);
this.createAndSendMessage(edit, Command.CHANGETASK);
}
/**
* This method uses the marked item in the ChoiceBox to send a <code>CHANGETASK</code> message
*/
public void changeTaskToButtonClicked() throws IOException{
if (!this.checkUserPermission()) {
System.out.println("Permission denied - can't change task " + markedTask.getTaskID());
return;
}
EditTask edit;
this.tableTasksApproved.getItems().remove(
this.tableTasksApproved.getSelectionModel().getSelectedItem());
this.tableTasksApproved.refresh();
State state = (State) changeStateOfTask.getSelectionModel().getSelectedItem();
if (this.markedTask != null){
edit = new EditTask(this.markedTask.getTaskID(), state, null);
} else {
edit = null;
}
this.createAndSendMessage(edit, Command.CHANGETASK);
}
/**
* User assigns himself to the marked task in the table
* @throws IOException
*/
public void novateTaskButtonClicked() throws IOException{
if(!this.checkUserPermission()) {
System.out.println("Permission denied - can't change task " + markedTask.getTaskID());
return;
}
this.tableTasksApproved.getItems().remove(
this.tableTasksApproved.getSelectionModel().getSelectedItem());
this.tableTasksApproved.refresh();
System.out.println("Button Clicked: " + this.markedTask.toString());
EditTask edit = new EditTask(this.markedTask.getTaskID(), null, ClientController.controller.getSendingUser());
this.createAndSendMessage(edit, Command.CHANGETASK);
}
public void changeScene(String changeToScene) {
try {
Main.changeScene(changeToScene);
} catch (IOException e) {
e.printStackTrace();
}
}
//-private-methods------------------------------------------------------------------
/** Uses the current group & the current user to send a message
*
* @param command
* @param extension: Task.java or EditTask.java
*/
private void createAndSendMessage(Sendable extension, Command command){
if (extension == null) return;
Message msg = new Message(ClientController.controller.getWorkingGroup(),
command,
ClientController.controller.getSendingUser(),
"taskboard message",
extension);
ClientController.controller.sendMessage(msg);
System.out.println("TaskboardController: Message sent" + extension.toString());
}
/**
* This method creates tasks as anchorpanes for the listTasksCreated
* @param task
* @return
* @throws IOException
*/
private AnchorPane createTaskCreated(Task task) {
try {
AnchorPane taskPane = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/taskboard_layout_small.fxml"));
Label nameLabel = (Label) taskPane.lookup("#taskboardName");
Label taskboardContent = (Label) taskPane.lookup("#taskboardContent");
Label taskboardUser = (Label) taskPane.lookup("#taskboardUser");
Label taskboardBeginningDate = (Label) taskPane.lookup("#taskboardBeginningDate");
Label taskboardEndingDate = (Label) taskPane.lookup("#taskboardEndingDate");
taskPane.setOnMouseClicked(new EventHandler<InputEvent>(){
@Override
public void handle(InputEvent event) {
markedTask = task;
}
});
nameLabel.setText(task.getTitle());
taskboardContent.setText(task.getContent());
taskboardUser.setText("No user yet");
taskboardBeginningDate.setText(task.getDate().toString());
if(task.getFinishingDate() != null){
taskboardEndingDate.setText(task.getFinishingDate().toString());
}else{
taskboardEndingDate.setText("Not finished");
}
return taskPane;
} catch(IOException e) {
e.printStackTrace();
}
return null;
}
/**
* Creating a task as an AnchorPane for the tableTasksApproved
* @param task
* @return
*/
private FlowPane createTaskApproved(Task task){
try {
FlowPane pane = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/taskBox.fxml"));
Scene layout = new Scene(pane);
Label taskName = (Label) layout.lookup("#taskName");
Label taskContent = (Label) layout.lookup("#taskContent");
Label taskUser = (Label) layout.lookup("#taskUser");
Label taskState = (Label) layout.lookup("#taskState");
Label taskBeginningDate = (Label) layout.lookup("#taskBeginningDate");
Label taskEndingDate = (Label) layout.lookup("#taskEndingDate");
pane.setOnMouseClicked(new EventHandler<InputEvent>(){
@Override
public void handle(InputEvent event) {
markedTask = task;
}
});
System.out.println(task.toString());
taskName.setText(task.getTitle());
taskContent.setText(task.getContent());
taskBeginningDate.setText(task.getDate().toString());
taskState.setText(task.getState().name());
if (task.getUser() != null) taskUser.setText(task.getUser().getUserName());
if (task.getFinishingDate() != null) taskEndingDate.setText(task.getFinishingDate().toString());
return pane;
} catch (IOException e) {
System.out.println("Error - Can't access to layout - TaskBox");
e.printStackTrace();
}
return null;
}
/**
* Lists the users in a list view which are in the group
* Creating a userbox as anchorpane for listUsers
* @param user
* @return
*/
private AnchorPane createUserBox(User user){
try {
AnchorPane layout = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/taskboard_user_layout.fxml"));
Label userName = (Label) layout.lookup("#taskboardUser");
userName.setText(user.getUserName());
layout.setOnMouseClicked(new EventHandler<InputEvent>(){
@Override
public void handle(InputEvent event) {
markedUser = user;
}
});
return layout;
} catch (IOException e) {
System.out.println("Error - Can't access to layout - UserBox");
e.printStackTrace();
}
return null;
}
private boolean checkUserPermission(){
if (this.markedTask.getUser() == null) {
//markedTask is free to assign
return true;
} else if (this.markedTask.getUser().getUserName().equals(ClientController.controller.getSendingUser().getUserName())) {
//Assigned user is assigned to the task
return true;
} else {
PermissionRole roleOfUser = ClientController.controller.getKnownTeamMap()
.get(ClientController.controller.getWorkingGroup())
.getRoleMap().get(ClientController.controller.getSendingUser());
if (roleOfUser.hasTeamleaderRights() || roleOfUser.hasAdminRights()){
//Assigned user has teamleader rights or admin rights
return true;
}
}
//user has no permission
return false;
}
private void setUpUsers(){
Group g = ClientController.controller.getWorkingGroup();
for(User u : ClientController.controller.getKnownTeamMap().get(g).getRoleMap().keySet()){
listUsers.getItems().add(createUserBox(u));
}
}
/**
* Fills the choice box with items
*/
private void setUpStateChoiceBox() {
changeStateOfTask.getItems().addAll(
State.PLANNED,
State.IN_PROGRESS,
State.IN_CHECK,
State.FINISHED
);
}
private void setUpCreatedTasks(){
Platform.runLater(()->{
this.observableTasksCreated.clear();
});
for (Task task: this.taskList){
Platform.runLater(()-> {
if (task.getState() == State.CREATED){
this.observableTasksCreated.add(this.createTaskCreated(task));
}
});
}
}
private void setUpApprovedTasks(){
Platform.runLater(()->{
this.observableTasksApproved.clear();
});
for (Task task: this.taskList){
Platform.runLater(()-> {
if (task.getState() == State.PLANNED || task.getState() == State.IN_CHECK ||
task.getState() == State.IN_PROGRESS || task.getState() == State.FINISHED){
this.observableTasksApproved.add(this.createTaskApproved(task));
}
});
}
}
}

View File

@@ -0,0 +1,74 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import java.awt.image.BufferedImage;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import new_build.models.common.messages.Message;
import new_build.models.network_organisation.Pair;
/**
* Controller Class for the Time Dialog of the Chat filter.
*/
public class TimeSearch extends AnchorPane {
@FXML
DatePicker startDatePicker;
@FXML
DatePicker endDatePicker;
@FXML
Button SearchButton;
boolean sButtonClicked = false;
private ChatController assignedController;
public TimeSearch(ChatController assignedController){
this.assignedController = assignedController;
}
/**
* Returns Start Date for the Filter.
* @return Start Date
*/
public Date getStartDate() {
LocalDate localDate = this.startDatePicker.getValue();
Instant instant = Instant.from(localDate.atStartOfDay(ZoneId.systemDefault()));
Date startDate = Date.from(instant);
return startDate;
}
/**
* Returns End Date for the Filter.
* @return End Date
*/
public Date getEndDate() {
LocalDate localDate = this.endDatePicker.getValue();
Instant instant = Instant.from(localDate.atStartOfDay(ZoneId.systemDefault()));
Date endDate = Date.from(instant);
return endDate;
}
/**
* EventListener for the Search Button
*/
public void searchButtonClicked() {
assignedController.setFilter(new Filter() {
@Override
public boolean passesFilter(MessagePane messageBox) {
return messageBox.isInDate(getStartDate(), getEndDate());
}
});
assignedController.applyFilter();
}
}

View File

@@ -0,0 +1,19 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.scene.control.Label;
import new_build.models.network_organisation.User;
import new_build.server.constants.PermissionRole;
public class UserLabel extends Label {
private final User displayedUser;
public UserLabel(User displayedUser, PermissionRole permissionRole){
super(displayedUser.getFirstName()+ " " + displayedUser.getLastName()+ " -> " + permissionRole);
this.displayedUser = displayedUser;
}
public User getDisplayedUser() {
return displayedUser;
}
}

View File

@@ -0,0 +1,62 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import new_build.models.network_organisation.User;
import new_build.client.controller.ClientController;
/**
* Controller Class for the User Dialog of the Chat Filter.
*/
public class UserSearch {
@FXML
ListView userListView;
@FXML
Button selectButton;
private ChatController assignedController;
public UserSearch(ChatController assignedController) {
this.assignedController = assignedController;
}
/**
* Returns the selected Username of the User List.
* @return username Selected User
*/
public String getUserName() {
String username = ((Label)userListView.getSelectionModel().getSelectedItem()).getText();
System.out.println("filtering for " + username);
return username;
}
/**
* EventListener for the Select Button
*/
public void selectButtonClicked() {
assignedController.setFilter(new Filter() {
@Override
public boolean passesFilter(MessagePane messageBox) {
return messageBox.writtenByUser(getUserName());
}
});
assignedController.applyFilter();
}
public void initialize() {
selectButton.setOnAction(e -> this.selectButtonClicked());
ObservableList<Label> userList = FXCollections.observableArrayList();
for (User u : ClientController.controller.getKnownTeamMap().get(ClientController.controller.getWorkingGroup()).getRoleMap().keySet()){
userList.add(new Label(u.getUserName()));
}
userListView.setItems(userList);
}
}

View File

@@ -0,0 +1,202 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
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 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.GroupInformation;
import new_build.models.network_organisation.UserLogin;
public class UserhubController implements Initializable, ViewController{
@FXML
BorderLayout userhubLayout;
@FXML Button profileSettingsButton;
@FXML Button createNewGroupButton;
@FXML ImageView userIcon;
@FXML Label usernameLabel;
@FXML Label firstnameLabel;
@FXML Label lastnameLabel;
@FXML
TextField newGroupName;
@FXML ListView<AnchorPane> groupList;
private ObservableList<AnchorPane> groupBoxList = FXCollections.observableArrayList();
private GroupButtonHandleStrategy buttonHandleStrategy = new DefaultButtonHandleStrategy();
Stage stage;
/**
* Initializes the controller
* @param location
* @param resources
*/
@Override
public void initialize(URL location, ResourceBundle resources){
//chance the name of the label in displayName, user firstname, user lastname
lastnameLabel.setText("Nachname: "+ClientController.controller.getSendingUser().getLastName());
firstnameLabel.setText("Vorname: "+ ClientController.controller.getSendingUser().getFirstName());
usernameLabel.setText("Benutzername: "+ ClientController.controller.getSendingUser().getUserName());
//settings for the group box
for(Group g: ClientController.controller.getKnownTeamMap().keySet()) {
try {
AnchorPane groupBoxTemplate = FXMLLoader.load(getClass().getResource(
"/new_build/client/view/sepboard/GUIview/resources/layout/groupbox.fxml"));
Scene tempScene = new Scene(groupBoxTemplate);
Label groupNameLabel = (Label) tempScene.lookup("#groupNameLabel");
Label amountOfUsersLabel = (Label) tempScene.lookup("#amountOfUsersLabel");
Label newMessagesLabel = (Label) tempScene.lookup("#newMessagesLabel");
Label newPollsLabel = (Label) tempScene.lookup("#newPollsLabel");
Button chatButton = (Button) tempScene.lookup("#chatButton");
Button taskboardButton = (Button) tempScene.lookup("#taskboardButton");
ToggleButton notificationsButton = (ToggleButton) tempScene.lookup("#notificationsButton");
Button leaveGroupButton = (Button) tempScene.lookup("#leaveGroupButton");
groupNameLabel.setText("Gruppe: " + g.getName());
GroupInformation groupInformation = ClientController.controller.getKnownTeamMap()
.get(g);
newMessagesLabel.setText(" new Messages: " + groupInformation.getNumberOfUnReadMessages() + "");
newPollsLabel.setText("new Polls: " + ClientController.controller.getKnownTeamMap()
.get(g).getPolls().size() + "");
chatButton.setOnAction((e) -> buttonHandleStrategy.chatButtonClicked(g, e));
taskboardButton.setOnAction((e) -> buttonHandleStrategy.taskBoardButtonClicked(g, e));
groupBoxList.add(groupBoxTemplate);
} catch (IOException e1) {
e1.printStackTrace();
}
}
ClientController.controller.registerViewController(this);
groupList.setItems(groupBoxList);
}
/**
* Changes the scene to profile settings
* @throws IOException
*/
@FXML
private void profilSettingsButtonClicked() throws IOException {
this.changeScene("profile_settings");
}
/**
* Changes the scene to login and the user will be logged out
* @throws IOException
*/
@FXML
private void logoutButtonClicked() throws IOException {
Stage stage = (Stage) profileSettingsButton.getScene().getWindow();
stage.close();
}
@FXML
private void createNewGroupButtonClicked(){
Message creationMessage = new Message(Group.DEFAULT_GROUP, Command.ADDGROUP,
ClientController.controller.getSendingUser(), this.newGroupName.getText(), null);
ClientController.controller.sendMessage(creationMessage);
}
@FXML
private void initialize() {
byte[] image = ClientController.controller.getSendingUser().getProfilePic();
ClientController.controller.getSendingUser().setProfilePic(image);
if(image != null) {
double X = userIcon.getFitWidth() / 4;
double Y = userIcon.getFitHeight() / 2;
Circle clip = new Circle(X, Y, 30);
userIcon.setClip(clip);
}
}
public void changeScene(String changeToScene) {
try {
// 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();
} catch (Exception e){
e.printStackTrace();
}
}
@Override
public void reactToNewMessage(Message m) {
System.out.println("react to message userhubcontroller");
Platform.runLater(() -> {
if(m.getControlHeaderType().equals(ServerStatus.class)){
ServerStatus status = ((ServerStatus) m.getControlHeader());
if (status.equals(ServerStatus.GROUP_CREATED)){
groupBoxList.add(this.groupCreatedPane(m));
}
}
});
groupList.setItems(groupBoxList);
}
private AnchorPane groupCreatedPane(Message m){
Group g;
AnchorPane groupBoxTemplate;
Scene tempScene;
Label groupNameLabel;
Label newMessagesLabel;
Label newPollsLabel;
Button chatButton;
Button taskboardButton;
GroupInformation groupInformation;
g = ((GroupInformation)m.getExtension()).getGroup();
try {
groupBoxTemplate = FXMLLoader.load(getClass().getResource(
"/new_build/client/view/sepboard/GUIview/resources/layout/groupbox.fxml"));
} catch (IOException e) {
groupBoxTemplate = null;
e.printStackTrace();
}
tempScene = new Scene(groupBoxTemplate);
groupNameLabel = (Label) tempScene.lookup("#groupNameLabel");
newMessagesLabel = (Label) tempScene.lookup("#newMessagesLabel");
newPollsLabel = (Label) tempScene.lookup("#newPollsLabel");
chatButton = (Button) tempScene.lookup("#chatButton");
taskboardButton = (Button) tempScene.lookup("#taskboardButton");
groupNameLabel.setText("Gruppe: " + g.getName());
groupInformation = ClientController.controller.getKnownTeamMap()
.get(g);
newMessagesLabel.setText(" new Messages: " + groupInformation.getNumberOfUnReadMessages() + "");
newPollsLabel.setText("new Polls: " + ClientController.controller.getKnownTeamMap()
.get(g).getRunningPolls().size() + "");
chatButton.setOnAction((e) -> buttonHandleStrategy.chatButtonClicked(g, e));
taskboardButton.setOnAction((e) -> buttonHandleStrategy.taskBoardButtonClicked(g, e));
return groupBoxTemplate;
}
}

View File

@@ -0,0 +1,183 @@
package new_build.client.view.sepboard.GUIview.controller;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
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.ListView;
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.Pair;
import new_build.models.network_organisation.User;
import new_build.models.network_organisation.UserList;
import new_build.server.constants.PermissionRole;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle;
public class UsermanagementController implements ViewController{
@FXML
private ListView<UserLabel> listOfClientManagement;
private ObservableList<UserLabel> observableUsersInGroup = FXCollections.observableArrayList();
@FXML
private Button teamleaderButton;
@FXML
private Button addButton;
@FXML
private Button removeButton;
@FXML
private Button goBackButton;
@Override
public void initialize(URL location, ResourceBundle resources) {
ClientController.controller.registerViewController(this);
this.listOfClientManagement.setItems(this.observableUsersInGroup);
goBackButton.setOnAction(e -> {
changeScene("chat");
});
//addUserPermissionMapToListView();
Message userListRequest = new Message(ClientController.controller.getWorkingGroup(),
Command.GET_ALL_USERS, ClientController.controller.getSendingUser(),
"getallusers", null);
ClientController.controller.sendMessage(userListRequest);
}
public void reactToNewMessage(Message m) {
Platform.runLater(() -> {
if (m.getControlHeader() == ServerStatus.USERLIST_SEND){
this.observableUsersInGroup.clear();
UserList allUsers = ((UserList) m.getExtension());
for (Pair<User, PermissionRole> u : allUsers.getUsersWithRole()){
/*System.out.println(u.getFirstName() + " " + u.getLastName());
boolean userAlreadyDisplayed = false;
for (UserLabel userLabel : this.observableUsersInGroup){
if (u.equals(userLabel.getDisplayedUser())){
userAlreadyDisplayed = true;
}
}
if (!userAlreadyDisplayed) */observableUsersInGroup.add(new UserLabel(u.getA(), u.getB()));
}
} else if ( m.getControlHeader() == ServerStatus.ROLE_CHANGED ||
m.getControlHeader() == ServerStatus.MEMBER_LEFT ||
m.getControlHeader() == ServerStatus.MEMBER_JOINED){
this.changeScene("clientManagement_general"); //KISS
}
});
}
@Override
public void changeScene(String changeToScene) {
// Get reference to the button's stage
Stage stage = (Stage)removeButton.getScene().getWindow();
// Load other FXML document
Parent root = null;
try {
root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/" + changeToScene + ".fxml"));
} catch (IOException e) {
e.printStackTrace();
}
if (root == null) {
try {
root = FXMLLoader.load(getClass().getResource("/new_build/client/view/sepboard/GUIview/resources/layout/userhub.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
}
stage.setScene(new Scene(root));
stage.show();
}
//settings of teamlederButton
public void teamleaderButtonClicked(){
if (validSelection()) ChangeSelectedUserPermissions(PermissionRole.TEAMLEADER);
}
//settings of adding a user to a group
public void addButtonClicked(){
if (validSelection()) ChangeSelectedUserPermissions(PermissionRole.USER);
}
//settings of removing a user of a group
public void removeButtonClicked(){
if (validSelection()) ChangeSelectedUserPermissions(PermissionRole.NONE);
}
//settings for backButton
public void backButtonClicked(){
this.changeScene("chat");
}
//---private-methods--------------------------------------------------------------
private void addUserPermissionMapToListView() {
HashMap<User, PermissionRole> groupPermissionMap = ClientController
.controller.getKnownTeamMap()
.get(ClientController.controller.getWorkingGroup()).getRoleMap();
for (User u : groupPermissionMap.keySet()){
PermissionRole userPermission = groupPermissionMap.get(u);
UserLabel userInformationLabel = new UserLabel(u, userPermission);
observableUsersInGroup.add(userInformationLabel);
}
}
//settings for commands and sending messages to controller
private void ChangeSelectedUserPermissions(PermissionRole roleToChangeTo) {
Command command = getCommandFromRole(roleToChangeTo);
User workingUser = getSelectedUserInList();
if (workingUser == null) return;
if (command == Command.CHANGEROLE){
Pair<User, PermissionRole> userWithRoleChange = new Pair<>(workingUser, PermissionRole.TEAMLEADER);
Message roleChangeMessage = new Message(ClientController.controller.getWorkingGroup(),
command, ClientController.controller.getSendingUser(),
"", userWithRoleChange);
ClientController.controller.sendMessage(roleChangeMessage);
}
Message removeMessage = new Message(ClientController.controller.getWorkingGroup(),
command, ClientController.controller.getSendingUser(),
"", workingUser);
ClientController.controller.sendMessage(removeMessage);
}
//create commands fits by the role
private Command getCommandFromRole(PermissionRole roleToChangeTo) {
switch (roleToChangeTo){
case NONE: return Command.REMOVEUSER;
case USER: return Command.ADDUSER;
case TEAMLEADER: return Command.CHANGEROLE;
default: throw new RuntimeException("unexpected Command From PermissionRole Change Request");
}
}
//get the selected user in the list
private User getSelectedUserInList() {
return this.listOfClientManagement
.getSelectionModel()
.getSelectedItem()
.getDisplayedUser();
}
//check if user is valid
private boolean validSelection() {
return getSelectedUserInList() != null;
}
}

View File

@@ -0,0 +1,14 @@
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{
void reactToNewMessage(Message m);
void changeScene(String sceneToChangeTo);
}

View File

@@ -0,0 +1,8 @@
.list-cell:even {
-fx-background-color: white;
-fx-text-fill: black;
}
.list-cell:odd {
-fx-background-color: white;
-fx-text-fill: black;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,21 @@
.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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1012 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

View File

@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.DatePicker?>
<?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.layout.VBox?>
<?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.0.112" 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="140.0" prefWidth="545.0" BorderPane.alignment="CENTER">
<children>
<TextArea fx:id="messageField" prefHeight="115.0" prefWidth="398.0" wrapText="true">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</TextArea>
<VBox prefHeight="100.0" prefWidth="148.0">
<children>
<HBox minHeight="20.0" prefHeight="40.0" prefWidth="147.0">
<children>
<Button fx:id="sendButton" minHeight="20.0" mnemonicParsing="false" onMouseClicked="#sendButtonClicked" prefHeight="54.0" prefWidth="108.0" text="Senden">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin></Button>
<Button minHeight="20.0" mnemonicParsing="false" onAction="#appendixButtonClicked" prefHeight="45.0" prefWidth="40.0">
<graphic>
<ImageView fitHeight="27.0" fitWidth="30.0" opacity="0.7" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../image/circle_up.png" />
</image>
</ImageView>
</graphic></Button>
</children>
</HBox>
<VBox prefHeight="65.0" prefWidth="145.0">
<children>
<DatePicker fx:id="datePicker" />
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<ChoiceBox fx:id="hours" prefWidth="150.0" />
<ChoiceBox fx:id="minutes" prefWidth="150.0" />
</children>
</HBox>
</children>
</VBox>
<Button fx:id="pollSender" minHeight="30.0" mnemonicParsing="false" onMouseClicked="#pollButtonClicked" prefHeight="39.0" prefWidth="145.0" text="Abstimmung" textAlignment="CENTER" />
</children>
</VBox>
</children>
<BorderPane.margin>
<Insets top="5.0" />
</BorderPane.margin>
</HBox>
</bottom>
<top>
<HBox fx:id="chatLabelBox" spacing="10.0" BorderPane.alignment="CENTER">
<children>
<Label text="Teamchat:">
<font>
<Font size="25.0" />
</font>
</Label>
<Label fx:id="groupIDLabel" text="groupID">
<font>
<Font size="25.0" />
</font>
</Label>
<ChoiceBox id="filterSelector" fx:id="filterSelector" prefHeight="31.0" prefWidth="160.0">
<HBox.margin>
<Insets bottom="5.0" />
</HBox.margin></ChoiceBox>
</children>
</HBox>
</top>
<padding>
<Insets bottom="5.0" left="5.0" top="5.0" />
</padding>
<center>
<ListView fx:id="listView" prefHeight="341.0" prefWidth="545.0" styleClass="pane-list" stylesheets="@../css/list_style.css" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
</left>
<right>
<BorderPane prefHeight="600.0" prefWidth="230.0" BorderPane.alignment="CENTER">
<top>
<Label text="User" 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 fx:id="userRoleList" prefHeight="554.0" prefWidth="215.0" styleClass="pane-list" stylesheets="@../css/list_style.css" 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="215.0" text="Zurück zum UserHub" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="5.0" />
</BorderPane.margin></Button>
</bottom>
</BorderPane>
</right>
</BorderPane>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1">
<children>
<FlowPane alignment="CENTER" columnHalignment="CENTER" prefHeight="40.0" prefWidth="600.0" style="-fx-background-color: #0079BF;">
<children>
<Label text="Hinzufügen" textFill="#f2f2f2">
<font>
<Font name="System Bold" size="25.0" />
</font>
</Label>
</children>
</FlowPane>
<SplitPane dividerPositions="0.8003502626970228" layoutX="2.0" layoutY="40.0" prefHeight="360.0" prefWidth="600.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<ScrollPane fx:id="listOfClientsToAdd" prefHeight="358.0" prefWidth="476.0" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="339.0" prefWidth="232.0" style="-fx-background-color: #65b5da;">
<children>
<VBox alignment="CENTER" layoutX="4.0" layoutY="181.0" prefHeight="176.0" prefWidth="103.0" spacing="100.0">
<children>
<Button fx:id="addButton" mnemonicParsing="false" text="Hinzufügen" />
<Button fx:id="closeButton" mnemonicParsing="false" text="Schließen" />
</children>
</VBox>
<ImageView fx:id="imageOfClient" fitHeight="91.0" fitWidth="96.0" layoutX="8.0" layoutY="6.0" pickOnBounds="true" preserveRatio="true" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.UsermanagementController">
<children>
<SplitPane dividerPositions="0.6655518394648829" layoutX="-1.0" layoutY="35.0" prefHeight="366.0" prefWidth="600.0" AnchorPane.topAnchor="35.0">
<items>
<ListView fx:id="listOfClientManagement" prefHeight="311.0" prefWidth="383.0" />
<VBox alignment="CENTER" prefHeight="364.0" prefWidth="285.0" spacing="50.0" style="-fx-background-color: #65b5da;">
<children>
<Button fx:id="teamleaderButton" mnemonicParsing="false" onAction="#teamleaderButtonClicked" prefHeight="30.0" prefWidth="90.0" text="Teamleader" />
<Button fx:id="addButton" mnemonicParsing="false" onAction="#addButtonClicked" prefHeight="30.0" prefWidth="90.0" text="Hinzufügen" />
<Button fx:id="removeButton" mnemonicParsing="false" onAction="#removeButtonClicked" prefHeight="30.0" prefWidth="90.0" text="Entfernen" />
<Button fx:id="goBackButton" alignment="CENTER" contentDisplay="TEXT_ONLY" mnemonicParsing="false" onAction="#backButtonClicked" prefHeight="30.0" prefWidth="90.0" text="Zurück" />
</children>
</VBox>
</items>
</SplitPane>
<HBox layoutY="-3.0" prefHeight="38.0" prefWidth="600.0" style="-fx-background-color: #0079BF;">
<children>
<Label alignment="CENTER" prefHeight="42.0" prefWidth="572.0" text="Benutzerverwaltung" textAlignment="CENTER" textFill="#f2f2f2">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Label>
</children>
</HBox>
</children>
</AnchorPane>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="118.0" prefWidth="535.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox prefHeight="118.0" prefWidth="535.0">
<children>
<HBox prefHeight="41.0" prefWidth="392.0" style="-fx-background-color: #1ca0ed;">
<children>
<Label id="groupNameLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="325.0" text="Groupname" textAlignment="CENTER" />
<Label id="amountOfUsersLabel" alignment="CENTER" prefHeight="40.0" prefWidth="308.0" text="Amount of Users" />
</children>
</HBox>
<HBox prefHeight="40.0" prefWidth="392.0">
<children>
<Label id="newMessagesLabel" alignment="CENTER" prefHeight="39.0" prefWidth="425.0" text="New Messages: ?" textAlignment="CENTER" />
<Label id="newPollsLabel" alignment="CENTER" prefHeight="39.0" prefWidth="415.0" text="New Polls: ?" textAlignment="CENTER" />
</children>
</HBox>
<HBox prefHeight="40.0" prefWidth="392.0">
<children>
<Button id="chatButton" mnemonicParsing="false" prefHeight="39.0" prefWidth="285.0" text="Chat" textAlignment="CENTER" />
<Button id="taskboardButton" mnemonicParsing="false" prefHeight="39.0" prefWidth="267.0" text="Taskboard" textAlignment="CENTER" />
</children>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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;" 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 style="-fx-font-family: &quot;FF Market&quot;;" 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" prefHeight="37.0" prefWidth="220.0" promptText="Benutzername" />
<PasswordField fx:id="passwordField" minWidth="220.0" promptText="Passwort">
<FlowPane.margin>
<Insets bottom="5.0" top="5.0" />
</FlowPane.margin>
<HBox.margin>
<Insets />
</HBox.margin>
</PasswordField>
<Label fx:id="passwordIsFalse" text="Benutzername oder Passwort falsch !" textFill="#ffe900">
<FlowPane.margin>
<Insets bottom="20.0" />
</FlowPane.margin>
</Label>
<HBox alignment="TOP_CENTER" maxWidth="220.0" minWidth="220.0" prefHeight="56.0" prefWidth="220.0" spacing="20.0">
<children>
<Button fx:id="loginButton" mnemonicParsing="false" onMouseClicked="#loginButtonClicked" prefHeight="45.0" prefWidth="75.0" text="Login" />
<Button fx:id="registerButton" mnemonicParsing="false" onMouseClicked="#registerButtonClicked" prefHeight="45.0" prefWidth="104.0" text="Registrieren" />
</children>
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</HBox>
</children>
<BorderPane.margin>
<Insets bottom="60.0" />
</BorderPane.margin>
</FlowPane>
</center>
</BorderPane>

View File

@@ -0,0 +1,32 @@
<?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.*?>
<FlowPane maxHeight="Infinity" maxWidth="Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="77.0" prefWidth="520.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox maxHeight="Infinity" prefHeight="77.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" />
<Pane id="extensionPane" prefHeight="38.0" prefWidth="520.0" />
</children>
</VBox>
</children>
</FlowPane>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1">
<children>
<FlowPane alignment="CENTER" columnHalignment="CENTER" prefHeight="40.0" prefWidth="600.0" style="-fx-background-color: #0079BF;">
<children>
<Label text="Hinzufügen" textFill="#f2f2f2">
<font>
<Font name="System Bold" size="25.0" />
</font>
</Label>
</children>
</FlowPane>
<SplitPane dividerPositions="0.8003502626970228" layoutX="2.0" layoutY="40.0" prefHeight="360.0" prefWidth="600.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<ScrollPane fx:id="listOfClientsToAdd" prefHeight="358.0" prefWidth="476.0" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="339.0" prefWidth="232.0" style="-fx-background-color: #65b5da;">
<children>
<VBox alignment="CENTER" layoutX="4.0" layoutY="181.0" prefHeight="176.0" prefWidth="103.0" spacing="100.0">
<children>
<Button fx:id="addButton" mnemonicParsing="false" text="Hinzufügen" />
<Button fx:id="closeButton" mnemonicParsing="false" text="Schließen" />
</children>
</VBox>
<ImageView fx:id="imageOfClient" fitHeight="91.0" fitWidth="96.0" layoutX="8.0" layoutY="6.0" pickOnBounds="true" preserveRatio="true" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1">
<children>
<SplitPane dividerPositions="0.6655518394648829" layoutX="-1.0" layoutY="35.0" prefHeight="366.0" prefWidth="600.0" AnchorPane.topAnchor="35.0">
<items>
<ListView fx:id="listOfClientManagement" prefHeight="311.0" prefWidth="383.0" />
<VBox alignment="CENTER" prefHeight="364.0" prefWidth="285.0" spacing="50.0" style="-fx-background-color: #65b5da;">
<children>
<Button fx:id="teamleaderButton" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="Teamleader" />
<Button fx:id="addButton" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="Hinzufügen" />
<Button fx:id="removeButton" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="Löschen" />
<Button fx:id="goBackButton" alignment="CENTER" contentDisplay="TEXT_ONLY" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="Zurück" />
</children>
</VBox>
</items>
</SplitPane>
<HBox layoutY="-3.0" prefHeight="38.0" prefWidth="600.0" style="-fx-background-color: #0079BF;">
<children>
<Label alignment="CENTER" prefHeight="42.0" prefWidth="572.0" text="Benutzerverwaltung" textAlignment="CENTER" textFill="#f2f2f2">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Label>
</children>
</HBox>
</children>
</AnchorPane>

View File

@@ -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>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<FlowPane 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>
</FlowPane>

View File

@@ -0,0 +1,71 @@
<?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.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.0.121" 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">
<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="surnameField" />
<TextField fx:id="lastnameField" />
<TextField fx:id="passwordField" promptText="Passwort">
<VBox.margin>
<Insets top="20.0" />
</VBox.margin>
</TextField>
<TextField fx:id="approvedPasswordField" />
<Label fx:id="passwordWrongLabel" alignment="CENTER" contentDisplay="CENTER" text="Passwort Bestätigung falsch" textAlignment="CENTER" textFill="#d70808" visible="false" />
<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>

View File

@@ -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>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<FlowPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="72.0" prefWidth="560.0" style="-fx-background-color: #0079bf;" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox prefHeight="42.0" prefWidth="540.0">
<children>
<Label fx:id="taskName" text="taskName" textFill="#bcbcbc">
<padding>
<Insets left="230.0" />
</padding></Label>
<HBox fx:id="taskboardEndingDate" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #f0f0f0;">
<children>
<Label fx:id="taskState" text="State" textFill="#5d5d5d" />
<Label fx:id="taskContent" text="Inhalt" textFill="#5e5d5d">
<padding>
<Insets left="160.0" />
</padding>
</Label>
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #f0f0f0;">
<children>
<Label fx:id="taskUser" text="User" textFill="#5d5d5d" />
<Label fx:id="taskBeginningDate" text="Datum" textFill="#5d5d5d">
<padding>
<Insets left="190.0" />
</padding>
</Label>
<Label fx:id="taskEndingDate" text="Enddatum" textFill="#5d5d5d">
<padding>
<Insets left="100.0" />
</padding>
</Label>
</children>
</HBox>
</children>
</VBox>
</children>
</FlowPane>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?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.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.TaskboardController">
<top>
<Label text="Taskboard" textFill="#f2f2f2" BorderPane.alignment="CENTER">
<font>
<Font name="System Bold" size="26.0" />
</font>
</Label>
</top>
<center>
<VBox prefHeight="387.0" prefWidth="800.0" style="-fx-background-color: #f2f2f2;" BorderPane.alignment="CENTER">
<children>
<ListView fx:id="tableTasksApproved" prefHeight="336.0" prefWidth="779.0" />
</children>
</VBox>
</center>
<bottom>
<Pane prefHeight="226.0" prefWidth="800.0" style="-fx-background-color: #f2f2f2;" BorderPane.alignment="CENTER">
<children>
<TextField fx:id="newTaskField" layoutX="287.0" layoutY="68.0" prefHeight="104.0" prefWidth="243.0" promptText="Neue Aufgabe" />
<Button fx:id="createTaskButton" layoutX="287.0" layoutY="181.0" mnemonicParsing="false" onMouseClicked="#createTaskButtonClicked" prefHeight="31.0" prefWidth="166.0" text="Aufgabe erstellen" />
<Button fx:id="novateTaskButton" layoutX="606.0" layoutY="22.0" mnemonicParsing="false" onMouseClicked="#novateTaskButtonClicked" prefHeight="31.0" prefWidth="182.0" text="Task übernehmen" />
<TextField fx:id="headerField" layoutX="286.0" layoutY="19.0" prefHeight="37.0" prefWidth="245.0" promptText="Überschrift" />
<Button fx:id="backToUserHubButton" layoutX="662.0" layoutY="181.0" mnemonicParsing="false" onMouseClicked="#backToUserHubButtonClicked" prefHeight="31.0" prefWidth="126.0" text="Zurück" />
<Label layoutX="14.0" layoutY="19.0" prefHeight="21.0" prefWidth="193.0" text="Aufgabe verschieben nach: " />
<ChoiceBox fx:id="changeStateOfTask" layoutX="14.0" layoutY="41.0" prefWidth="150.0" />
<Button fx:id="changeTaskToButton" layoutX="14.0" layoutY="98.0" mnemonicParsing="false" onMouseClicked="#changeTaskToButtonClicked" prefHeight="31.0" prefWidth="151.0" text="Status ändern" />
</children>
</Pane>
</bottom>
</BorderPane>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600" prefWidth="800" style="-fx-background-color: #0079BF;" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.TaskboardController">
<top>
<Label text="Taskboard" textFill="#f2f2f2" BorderPane.alignment="CENTER">
<font>
<Font name="System Bold" size="26.0" />
</font>
</Label>
</top>
<right>
<Pane prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: #f2f2f2;" BorderPane.alignment="CENTER">
<children>
<TextField fx:id="newTaskField" layoutX="280.0" layoutY="366.0" prefHeight="106.0" prefWidth="191.0" promptText="neue Aufgabe" />
<Button fx:id="createTaskButton" layoutX="280.0" layoutY="477.0" mnemonicParsing="false" onMouseClicked="#createTaskButtonClicked" prefHeight="31.0" prefWidth="191.0" text="Aufgabe erstellen" />
<Button fx:id="changeTaskToButton" layoutX="19.0" layoutY="476.0" mnemonicParsing="false" onMouseClicked="#changeTaskToButtonClicked" prefHeight="32.0" prefWidth="151.0" text="Status ändern" />
<ListView fx:id="listTasksCreated" layoutX="595.0" layoutY="324.0" prefHeight="144.0" prefWidth="198.0" />
<Text layoutX="20.0" layoutY="412.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Aufgabe verschieben nach:" wrappingWidth="177.64892578125" />
<ChoiceBox fx:id="changeStateOfTask" layoutX="20.0" layoutY="423.0" prefHeight="31.0" prefWidth="150.0" />
<Button fx:id="approveButton" layoutX="595.0" layoutY="476.0" mnemonicParsing="false" onMouseClicked="#approveButtonClicked" prefHeight="32.0" prefWidth="197.0" text="Genehmigen" />
<TextField fx:id="headerField" layoutX="279.0" layoutY="324.0" prefHeight="38.0" prefWidth="191.0" promptText="Überschrift" />
<Button fx:id="backToUserHubButton" layoutX="677.0" layoutY="517.0" mnemonicParsing="false" onMouseClicked="#backToUserHubButtonClicked" prefHeight="31.0" prefWidth="106.0" text="Zurück" />
<Button fx:id="novateTaskButton" layoutX="17.0" layoutY="293.0" mnemonicParsing="false" onMouseClicked="#novateTaskButtonClicked" prefHeight="31.0" prefWidth="156.0" text="Task übernehmen" />
<ListView fx:id="tableTasksApproved" layoutX="3.0" layoutY="5.0" prefHeight="281.0" prefWidth="585.0" />
<ListView fx:id="listUsers" layoutX="593.0" layoutY="6.0" prefHeight="246.0" prefWidth="197.0" />
<Button fx:id="deliverTaskButton" layoutX="594.0" layoutY="255.0" mnemonicParsing="false" onMouseClicked="#changeUserButtonClicked" prefHeight="31.0" prefWidth="196.0" text="Task übergeben" />
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Pane>
</right>
</BorderPane>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane prefHeight="304.0" prefWidth="255.0" xmlns="http://javafx.com/javafx/8.0.131" xmlns:fx="http://javafx.com/fxml/1" fx:controller="new_build.client.view.sepboard.GUIview.controller.TaskboardController">
<children>
<FlowPane layoutX="8.0" layoutY="14.0" prefHeight="313.0" prefWidth="234.0">
<children>
<VBox prefHeight="296.0" prefWidth="224.0">
<children>
<Label text="Name" />
<TextField />
<Label text="Inhalt" />
<TextArea prefHeight="92.0" prefWidth="224.0" />
<Label text="Benutzer" />
<TextField />
<Label text="Anfangsdatum" />
<DatePicker />
<Label text="Enddatum" />
<DatePicker />
</children>
</VBox>
</children>
</FlowPane>
</children>
</AnchorPane>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane prefHeight="143.0" prefWidth="166.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" >
<children>
<VBox prefHeight="143.0" prefWidth="166.0">
<children>
<Label fx:id="taskboardName" prefHeight="27.0" prefWidth="166.0" />
<Label fx:id="taskboardContent" prefHeight="24.0" prefWidth="166.0" />
<Label fx:id="taskboardUser" prefHeight="26.0" prefWidth="166.0" />
<Label fx:id="taskboardBeginningDate" prefHeight="25.0" prefWidth="166.0" />
<Label fx:id="taskboardEndingDate" prefHeight="35.0" prefWidth="166.0" />
</children>
</VBox>
</children>
</AnchorPane>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane prefHeight="36.0" prefWidth="166.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox prefHeight="49.0" prefWidth="166.0">
<children>
<Label fx:id="taskboardUser" />
</children>
</VBox>
</children>
</AnchorPane>

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<AnchorPane id="time_search" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="216.0" prefWidth="267.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox prefHeight="216.0" prefWidth="267.0">
<children>
<BorderPane prefHeight="117.0" prefWidth="267.0">
<center>
<DatePicker id="startDatePicker" fx:id="startDatePicker" BorderPane.alignment="CENTER" />
</center>
<top>
<Label text="Von" BorderPane.alignment="CENTER" />
</top>
</BorderPane>
<BorderPane prefHeight="114.0" prefWidth="267.0">
<center>
<DatePicker id="endDatePicker" fx:id="endDatePicker" BorderPane.alignment="CENTER" />
</center>
<top>
<Label text="Bis" BorderPane.alignment="CENTER" />
</top>
</BorderPane>
<HBox prefHeight="56.0" prefWidth="399.0">
<children>
<Label alignment="CENTER" prefHeight="35.0" prefWidth="135.0" text="Bestätigen" />
<Button id="searchButton" mnemonicParsing="false" onAction="#searchButtonClicked" prefHeight="40.0" prefWidth="135.0" text="Suchen" />
</children>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="user_search" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="143.0" prefWidth="201.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ListView id="userList" fx:id="userListView" layoutX="13.0" layoutY="13.0" prefHeight="80.0" prefWidth="175.0" />
<Button id="selectButton" fx:id="selectButton" layoutX="57.0" layoutY="100.0" mnemonicParsing="false" text="Auswählen" />
</children>
</AnchorPane>

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Rectangle2D?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TextField?>
<?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.0.112" 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>
<left>
<ListView fx:id="groupList" prefHeight="565.0" prefWidth="552.0" style="-fx-background-color: #ffffff;" styleClass="pane-list" stylesheets="@../css/list_style.css" BorderPane.alignment="CENTER" />
</left>
</BorderPane>
</left>
<right>
<BorderPane prefHeight="600.0" prefWidth="299.0" BorderPane.alignment="CENTER">
<top>
<Pane prefHeight="344.0" prefWidth="228.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="64.0" fitWidth="58.0" layoutX="175.0" layoutY="5.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../image/profile.jpg" />
</image>
<viewport>
<Rectangle2D />
</viewport>
</ImageView>
<Label fx:id="usernameLabel" layoutX="20.0" layoutY="48.0" prefHeight="21.0" prefWidth="198.0" text="username: " />
<Label fx:id="firstnameLabel" layoutX="21.0" layoutY="69.0" prefHeight="21.0" prefWidth="197.0" text="firstname: " />
<Button layoutX="166.0" layoutY="129.0" mnemonicParsing="false" onMouseClicked="#logoutButtonClicked" prefHeight="43.0" prefWidth="68.0" text="Logout" />
<Button fx:id="profileSettingsButton" layoutX="14.0" layoutY="129.0" mnemonicParsing="false" onMouseClicked="#profilSettingsButtonClicked" prefHeight="43.0" prefWidth="144.0" text="Profileinstellungen" />
<Button fx:id="createNewGroupButton" layoutX="14.0" layoutY="254.0" mnemonicParsing="false" onMouseClicked="#createNewGroupButtonClicked" text="neue Gruppe erstellen" />
<TextField fx:id="newGroupName" layoutX="14.0" layoutY="216.0" promptText="Gruppennamen" />
<Label fx:id="lastnameLabel" layoutX="20.0" layoutY="88.0" prefHeight="21.0" prefWidth="199.0" text="lastname: " />
</children>
</Pane>
</top>
</BorderPane>
</right>
</BorderPane>

View File

@@ -0,0 +1,7 @@
package new_build.models.client_interfaces;
/**
* Created by Tobias on 15.06.2017.
*/
public interface ClientInputListener extends Runnable {
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -0,0 +1,9 @@
package new_build.models.common.data;
// Every Sendable is a bytearray
public interface Sendable {
Class getType();
}

View File

@@ -0,0 +1,67 @@
package new_build.models.common.data;
import javafx.scene.control.Label;
import java.io.*;
public class SepFile implements Sendable, Serializable{
private static final long serialVersionUID = -8339564571735716757L;
private byte[] file;
private String name;
private boolean isImage = false;
public SepFile(byte[] file, String name) {
this.file = file;
this.name = name;
}
public SepFile(File f, String name){
this.name = name;
if (f == null) return;
byte[] b = new byte[(int) f.length()];
System.out.println("creating a file");
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[] getByteData() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
}
@Override
public Class getType() {
return SepFile.class;
}
public String getName() {
return this.name;
}
public boolean isImage() {
return this.isImage;
}
public void setImage(boolean isImage) {
this.isImage = isImage;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,32 @@
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"),
ADDTASK("addtask"), CHANGETASK("changetask"),
GET_ALL_USERS("getallusers");
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, ADDTASK, CHANGETASK};
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;
}
}

View File

@@ -0,0 +1,73 @@
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 = 4788505745262030072L;
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;
}
}

View File

@@ -0,0 +1,9 @@
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, TASK_ADDED, TASK_CHANGED, USERLIST_SEND
}

View File

@@ -0,0 +1,140 @@
package new_build.models.common.polls;
import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
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 = new HashMap<>();
private int pollID;
private String pollText;
private Timestamp creationDate;
private Timestamp expiringDate;
private boolean isRunning;
/*
* Poll-Constructor has parameters pollID, groupID, pollText and expiringDate
* DO NOT CHANGE PARAMETERS
*/
public Poll (int pollID, String pollText, Timestamp expiringDate){
this.voteMap = new HashMap<>();
this.pollID = pollID;
this.pollText = pollText;
this.creationDate = new Timestamp(new java.util.Date().getTime());
this.expiringDate = expiringDate;
this.isRunning = this.checkDate();
}
public Poll (int pollID, String pollText, Timestamp creationDate, Timestamp expiringDate){
this.voteMap = new HashMap<>();
this.pollID = pollID;
this.pollText = pollText;
this.creationDate = creationDate;
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(){
System.out.println("voteListSize: " + this.voteMap.size());
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 Timestamp getCreationDate() {
return creationDate;
}
public int getPollID() {
return pollID;
}
public HashMap<User, Boolean> getVoteMap(){
return this.voteMap;
}
public String getPollText() {
return pollText;
}
public Timestamp getExpiringDate() {
return expiringDate;
}
public boolean getIsRunning() {
return this.isRunning;
}
public boolean checkDate(){
/**
* This method returns true when current Date is after expiringDate,
* changes isRunning of the poll
*/
Timestamp now = new Timestamp(new java.util.Date().getTime());
if (expiringDate.after(now)) {
this.setIsRunning(false);
return true;
} else {
this.setIsRunning(true);
return false;
}
}
public 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;
}
public void stopRunning() {
this.isRunning = false;
}
}

View File

@@ -0,0 +1,44 @@
package new_build.models.common.polls;
import new_build.models.common.data.Sendable;
import new_build.models.network_organisation.User;
import java.io.Serializable;
public class Vote implements Serializable, Sendable {
private static final long serialVersionUID = -4714045047489013951L;
private Boolean value;
private int pollVotedIn;
private User userVoted;
public Vote(int pollId, Boolean value){
this.pollVotedIn = pollId;
this.value = value;
}
public Vote(int pollId, User userVoted, Boolean value){
this.pollVotedIn = pollId;
this.value = value;
this.userVoted = userVoted;
}
public Boolean getValue() {
return value;
}
public int getPollVotedIn() {
return pollVotedIn;
}
public User getUserVoted() {
return userVoted;
}
@Override
public Class<Vote> getType() {
return Vote.class;
}
}

View File

@@ -0,0 +1,72 @@
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{
Message gotMessage = (Message) ois.readObject();
return (gotMessage);
} 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();
}
}
}

View File

@@ -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());
}
}

View File

@@ -0,0 +1,85 @@
package new_build.models.network_organisation;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
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.taskboard.Task;
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{
private static final long serialVersionUID = 3059023065395505390L;
private int readIndex;
private LinkedList<Message> messagesInChatRoom;
private HashMap<User, PermissionRole> roleMap;
private LinkedList<Poll> polls;
private LinkedList<Task> tasks;
private Group group;
public GroupInformation(LinkedList<Message> messagesInChatRoom, HashMap<User, PermissionRole>
roleMap, LinkedList<Poll> polls, LinkedList<Task> tasks) {
this.readIndex = 0;
this.messagesInChatRoom = messagesInChatRoom;
this.roleMap = roleMap;
this.polls = (polls == null)? new LinkedList<>() : polls;
this.tasks = tasks;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public void updateReadIndex(){
this.readIndex= messagesInChatRoom.size();
}
public int getNumberOfUnReadMessages(){
return messagesInChatRoom.size() - readIndex;
}
public LinkedList<Message> getMessagesInChatRoom() {
return messagesInChatRoom;
}
public HashMap<User, PermissionRole> getRoleMap() {
return roleMap;
}
public LinkedList<Poll> getPolls() {
return polls;
}
public LinkedList<Poll> getRunningPolls(){
LinkedList<Poll> runningPoll = new LinkedList<>();
for (Poll p: this.getPolls()){
if (p.getIsRunning()){
runningPoll.add(p);
}
}
return runningPoll;
}
public LinkedList<Task> getTasks() {
return tasks;
}
@Override
public Class getType() {
return GroupInformation.class;
}
}

View File

@@ -0,0 +1,37 @@
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;
public class LoginData implements Serializable, Sendable{
private static final long serialVersionUID = 2098781514370169741L;
private HashMap<Group, GroupInformation> groupInformationMap;
private UserLogin loggedInUser;
/**
* The Object the client gets if he loggs in, containing necessary information
* @param groupInformationMap Group of the user
* @param loggedInUser UserLogin
*/
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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,147 @@
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.messages.ServerStatus;
import new_build.models.common.polls.Poll;
import new_build.models.common.polls.Vote;
import new_build.models.taskboard.State;
import new_build.models.taskboard.Task;
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.sql.Date;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.LinkedList;
public class TeamInfo implements Serializable, Sendable {
private static final long serialVersionUID = 2387034548297739747L;
private Group assignedGroup;
private LinkedList<MessageInputListener> usersListening;
private LinkedList<Message> messagesInChatRoom;
private HashMap<User, PermissionRole> roleMap;
private LinkedList<Poll> polls;
private LinkedList<Task> tasks;
public TeamInfo(Group assignedGroup){
this.assignedGroup = assignedGroup;
this.usersListening = new LinkedList<>();
this.messagesInChatRoom = new LinkedList<>();
this.roleMap = new HashMap<>();
this.polls = new LinkedList<>();
this.tasks = new LinkedList<>();
}
public TeamInfo(Group assignedGroup, LinkedList<Message> messagesInChatRoom, HashMap<User, PermissionRole> roleMap,
LinkedList<Poll> polls, LinkedList <Task> tasks) {
this.assignedGroup = assignedGroup;
this.messagesInChatRoom = messagesInChatRoom;
this.roleMap = roleMap;
this.polls = polls;
if (tasks == null) this.tasks = new LinkedList<>();
this.tasks = tasks;
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){
for (Poll p : this.polls){
if ( p.getPollID() == id) return p;
}
throw new RuntimeException("coudlnt find poll clicked on!");
}
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 addVoteAndStopIfFull(User voter, Vote v) {
Poll pollVotingIn = getPollById(v.getPollVotedIn());
assert voter != null && v != null;
if(pollVotingIn.getIsRunning()) pollVotingIn.getVoteMap().put(voter, v.getValue());
if (this.getRoleMap().keySet().size() == pollVotingIn.getVoteMap().keySet().size()){
pollVotingIn.stopRunning();
addMessageToChatroom(new Message(assignedGroup, ServerStatus.POLL_FINISHED,
ServerController.SYSTEM, "Poll finished! - " + pollVotingIn.getVotesFor().size() +
" users voted yes, " + pollVotingIn.getVotesAgainst().size() + " users voted no, " +
pollVotingIn.getVotesAbstensions().size() + " abstenstions", null));
}
}
public void addTask(Task task){
this.tasks.add(task);
}
public void changeTaskState(Task task, State state){
Task temp = this.getTaskbyID(task.getTaskID());
if (temp != null) {
Date finishingDate = null;
if (state != State.FINISHED){
finishingDate = null;
} else {
finishingDate = Date.valueOf(LocalDate.now());
}
Task newTask = new Task(temp.getTaskID(),temp.getUser() , temp.getGroup(), temp.getTitle(), temp.getContent(), temp.getDate(), finishingDate, state);
this.getTasks().remove(this.getTaskbyID(task.getTaskID()));
this.getTasks().add(newTask);
}
}
public void changeTaskUser(Task task, User user){
Task temp = this.getTaskbyID(task.getTaskID());
if (temp != null){
Task newTask = new Task(temp.getTaskID(), user, temp.getGroup(), temp.getTitle(), temp.getContent(), temp.getDate(), temp.getFinishingDate(), State.PLANNED);
this.getTasks().remove(this.getTaskbyID(task.getTaskID()));
this.getTasks().add(newTask);
}
temp.setUser(user);
temp.setState(State.PLANNED);
}
public Task getTaskbyID(int taskID){
for (Task t: tasks){
if (t.getTaskID() == taskID) return t;
}
return null;
}
public LinkedList<Task> getTasks() {
return this.tasks;
}
}

View File

@@ -0,0 +1,89 @@
package new_build.models.network_organisation;
import new_build.models.common.data.Sendable;
import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.sql.Timestamp;
public class User implements Sendable, Serializable {
private static final long serialVersionUID = 12387129738L;
public static User NO_USER = new User(-42, "", "", "", null);
private int userID;
private String userName;
private String firstName;
private String lastName;
private byte[] profilePic;
public Timestamp getLogoutTimestamp() {
return logoutTimestamp;
}
public void setLogoutTimestamp(Timestamp logoutTimestamp) {
this.logoutTimestamp = logoutTimestamp;
}
private Timestamp logoutTimestamp;
public User(int userID, String userName, String firstName, String lastName, byte[] profilePic) {
this.userID = userID;
this.userName = userName;
this.firstName = firstName;
this.lastName = lastName;
this.profilePic = profilePic;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@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 byte[] getProfilePic() {
return profilePic;
}
public void setProfilePic(byte[] profilePic) {
this.profilePic = profilePic;
}
@Override
public Class getType() {
return User.class;
}
}

View File

@@ -0,0 +1,27 @@
package new_build.models.network_organisation;
import new_build.models.common.data.Sendable;
import new_build.server.constants.PermissionRole;
import java.io.Serializable;
import java.util.List;
public class UserList implements Sendable, Serializable {
private static final long serialVersionUID = 2007934987660949184L;
private List<Pair<User, PermissionRole>> usersWithRole;
public List<Pair<User, PermissionRole>> getUsersWithRole() {
return usersWithRole;
}
public UserList(List<Pair<User, PermissionRole>> usersWithRole) {
this.usersWithRole = usersWithRole;
}
@Override
public Class getType() {
return UserList.class;
}
}

View File

@@ -0,0 +1,38 @@
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, byte[]
profilePic) {
super(userID, userName, firstName, lastName, profilePic);
this.password = password;
}
public User removePassword(){
return new User(this.getID(), this.getUserName(), this.getFirstName(), this.getLastName(), this.getProfilePic());
}
public String getPassword(){
return this.password;
}
@Override
public Class getType() {
return UserLogin.class;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof UserLogin)) return super.equals(obj);
UserLogin login = ((UserLogin) obj);
return (super.equals(obj)&&login.getPassword().equals(this.getPassword()));
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@@ -0,0 +1,45 @@
package new_build.models.taskboard;
import java.io.Serializable;
import new_build.models.common.data.Sendable;
import new_build.models.network_organisation.User;
public class EditTask implements Sendable, Serializable {
/**
*
*/
private static final long serialVersionUID = -7021793132207005974L;
private int taskID;
private State state;
private User user;
public EditTask (int taskID, State state, User user){
this.taskID = taskID;
if (state != null) this.state = state;
if (user != null) this.user = user;
}
public int getTaskID() {
return taskID;
}
public State getState() {
return state;
}
public User getUser() {
return user;
}
@Override
public Class getType() {
// TODO Auto-generated method stub
return EditTask.class;
}
public String toString(){
return "Edit task " + this.getTaskID();
}
}

View File

@@ -0,0 +1,13 @@
package new_build.models.taskboard;
public enum State {
CREATED,
PLANNED,
IN_PROGRESS,
IN_CHECK,
FINISHED;
public String toString(){
return this.name();
}
}

View File

@@ -0,0 +1,115 @@
package new_build.models.taskboard;
import java.io.Serializable;
import java.sql.Date;
import java.time.LocalDate;
import new_build.models.common.data.Sendable;
import new_build.models.network_organisation.Group;
import new_build.models.network_organisation.User;
public class Task implements Serializable, Sendable {
/**
*
*/
private static final long serialVersionUID = -6667163577248501284L;
private int taskID;
private Group group;
private String title, content;
private Date date, finishingDate;
private User user;
private State state;
/**
* Constructor to create a new Task
* @param title
* @param content
* @param group
*/
public Task (String title, String content, Group group){
this.group = group;
this.title = title;
this.content = content;
this.date = Date.valueOf(LocalDate.now());
this.state = State.CREATED;
}
public Task(int taskID, User user,Group group, String title, String content, Date date, Date finishingDate, State state){
this.taskID = taskID;
this.group = group;
this.title = title;
this.content = content;
this.date = date;
if (user != null) this.user = user;
if (finishingDate != null) this.finishingDate = finishingDate;
this.state = state;
}
public int getTaskID() {
return taskID;
}
public void setTaskID(int taskID) {
this.taskID = taskID;
}
public Date getFinishingDate() {
return finishingDate;
}
private void setFinishingDate(Date finishingDate) {
this.finishingDate = finishingDate;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
this.setState(State.PLANNED);
}
public State getState() {
return state;
}
public void setState(State state) {
if (state != State.FINISHED){
this.setFinishingDate(null);
this.state = state;
} else {
this.setFinishingDate(Date.valueOf(LocalDate.now()));
this.state = state;
}
}
public Group getGroup() {
return group;
}
public String getTitle() {
return title;
}
public String getContent() {
return content;
}
public Date getDate() {
return date;
}
@Override
public Class getType() {
return Task.class;
}
@Override
public String toString(){
return "Task " + this.taskID + ": " + this.title + " for group " + this.group.getName();
}
}

View File

@@ -0,0 +1,7 @@
package new_build.server.constants;
public class DEBUG {
public static final boolean SERVER_DEBUG_MESSAGES = true;
public static final boolean SERVER_DEBUG_ASSERTIONS = true;
public static final boolean USE_DATABASE_INFORMATION = true;
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,566 @@
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.models.taskboard.Task;
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.TaskLib;
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.*;
public class ServerController {
public static volatile int maxPollID = 0;
public static volatile int maxTaskID = 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", "SYSTEM", "", null);
private MessageLib messageLib;
private PollLib pollLib;
private GroupLib groupLib;
private UserLib userLib;
private TaskLib taskLib;
//private CommandManager commandManager;
//private ClientView terminal;
public ServerController(){
createServerSocket();
initFields();
createServerDataStructure();
waitForConsoleCommands();
showInitMessage();
}
/**
* Serversocket on port 1337 is created to accept connections
*/
private void createServerSocket() {
try {
serverSocket = new ServerSocket(PORT);
} catch (IOException e) {
System.err.println("Constructor of ServerController failed.\n" + e);
}
}
/**
* Prints the time the server started
*/
private void showInitMessage() {
Date initTime = new Date(new java.util.Date().getTime());
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("Server initialized at " + initTime);
}
/**
* Create the teamMap and userGroupMap.
* TeamMap contains every group and its data, like messages, polls and tasks.
* UserGroupMap contains every user and the groups he's a part of.
*/
private void createServerDataStructure() {
teamMap.put(Group.DEFAULT_GROUP, new TeamInfo(Group.DEFAULT_GROUP));
createTeamMap();
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("Created TeamMap");
createUserGroupMap();
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("Created UserGroupMap");
}
/**
* Initialize the Objects in the ServerController.
* userlib, messagelib, polllib, tasklib, grouplib connectionlist, teammap, usergroupmap are initialized.
*/
private void initFields() {
if (DEBUG.USE_DATABASE_INFORMATION){
userLib = new UserLib();
messageLib = new MessageLib(userLib);
pollLib = new PollLib(userLib);
taskLib = new TaskLib(userLib);
groupLib = new GroupLib(userLib);
}
connectionList = new LinkedList<>();
teamMap = new HashMap<>();
userGroupMap = new HashMap<>();
serverShouldRun = true;
}
/**
* Getter for the teamMap
* @return The TeamMap
*/
public HashMap<Group, TeamInfo> getTeamMap(){
return this.teamMap;
}
/**
* Get the TeamInfo of the group from the teamMap
* @param g
* @return
*/
public TeamInfo getTeamFromGroup(Group g){
if (teamMap.get(g) == null) {
System.out.println("Group not found");
}
return teamMap.get(g);
}
//region Database Stuff
/**
* Used to connect to the database
*/
private void connectToDB(){
userLib.connect();
messageLib.connect();
groupLib.connect();
pollLib.connect();
taskLib.connect();
}
/**
* used to disconnect from the database
*/
private void closeDBConnection(){
pollLib.close();
groupLib.close();
messageLib.close();
userLib.close();
taskLib.close();
}
/**
* used to edit the logout timestamp inside of the database
*/
public void updateLogoutTimestampOfUser(UserLogin user){
connectToDB();
userLib.logout(user);
closeDBConnection();
}
/**
* Fills up the teamMap with entries from the database, same goes for userGroupMap
*/
private void updateFromDB(){
if(DEBUG.USE_DATABASE_INFORMATION) {
connectToDB();
//region update from teamMap
for (Map.Entry<Group, TeamInfo> tm : teamMap.entrySet()) {
Group g = tm.getKey();
TeamInfo ti = tm.getValue();
groupLib.insertGroupChanges(g);
insertMessagesFromDB(ti);
insertRolesFromDB(ti, g);
insertPollsFromDB(ti, g);
insertTasksFromDB(ti);
}
//endregion
//region update from userGroupMap
for (Map.Entry<UserLogin, LinkedList<Group>> tm : userGroupMap.entrySet()) {
UserLogin ul = tm.getKey();
userLib.insertLoginChanges(ul);
}
//endregion
closeDBConnection();
if (DEBUG.SERVER_DEBUG_MESSAGES) System.out.println("Disconnected from all db");
}
}
/**
* Used by the updateFromDB() Method to
* @param ti the Teaminfo it should be added to
* @param g the group it should be added to
*/
private void insertPollsFromDB(TeamInfo ti, Group g) {
for (Poll p: ti.getPolls()){
pollLib.insertPollChanges(g, p);
}
}
/**
* Used by the updateFromDB() Method to
* @param ti the Teaminfo it should be added to
* @param g the group it should be added to
*/
private void insertRolesFromDB(TeamInfo ti, Group g) {
for(Map.Entry<User, PermissionRole> rm: ti.getRoleMap().entrySet()){
User u = rm.getKey();
PermissionRole pr = rm.getValue();
groupLib.insertRoleChanges(g,u,pr);
}
}
/**
* Used by the updateFromDB() Method to
* @param ti the Teaminfo it should be added to
*/
private void insertTasksFromDB(TeamInfo ti){
for (Task t: ti.getTasks()){
taskLib.insertTaskChanges(t);
}
}
/**
* Used by the updateFromDB() Method to
* @param ti the Teaminfo it should be added to
*/
private void insertMessagesFromDB(TeamInfo ti) {
for (Message m: ti.getMessagesInChatRoom()){
messageLib.insertMessageChanges(m);
}
}
/**
* fills up the teamMap with the groups information
*/
private void createTeamMap(){
if(DEBUG.USE_DATABASE_INFORMATION){
connectToDB();
Group[] groups = groupLib.getAllGroups();
fillTeamMapWIthInformation(groups);
closeDBConnection();
}
}
/**
* fills up the teamMap with the groups information
* @param groups List of every group
*/
private void fillTeamMapWIthInformation(Group[] groups) {
for (Group g: groups) {
LinkedList<Message> messageList = messageLib.getMessagesInGroup(g);
HashMap<User, PermissionRole> roleMap = groupLib. getRolesInGroup(g);
LinkedList<Poll> polls = pollLib.getPollsOfGroup(g);
for (Poll p: polls) {
if (p != null){
if (p.getPollID()>maxPollID){
maxPollID = p.getPollID();
}
}
}
LinkedList<Task> tasks = taskLib.getTasksOfGroup(g);
TeamInfo teamInfo = new TeamInfo(g, messageList, roleMap, polls, tasks);
for (Task t: tasks) {
if (t != null){
if (t.getTaskID()>maxTaskID){
maxTaskID = t.getTaskID();
}
}
}
teamMap.put(g, teamInfo);
}
}
/**
* fills up the userGroupMap with the groups information
*/
private void createUserGroupMap(){
if(DEBUG.USE_DATABASE_INFORMATION){
connectToDB();
UserLogin[] userLogins = userLib.getAllUserLogin();
for (UserLogin ul: userLogins){
userGroupMap.put(ul,groupLib.getGroupsByUserID(ul.getID()));
}
closeDBConnection();
}
}
//endregion
/**
* In case a message is sent this
* @param messageToSend
*/
public void notifyObservers(Message messageToSend){
System.out.println("notifying observers...");
this.teamMap.get(messageToSend.getGroup()).addMessageToChatroom(messageToSend);
}
/**
* returns whether the server should still run
* @return serverShouldRun boolean
*/
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;
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!");
}
}
});
connectionLoopThread.start();
}
/**
* Loop to listen to ServerCommands
*/
private void waitForConsoleCommands(){
Thread waitForCommand = new Thread(() -> {
Scanner s = new Scanner(System.in);
while(serverShouldRun){
waitForAndExecuteCommands(s);
}
});
waitForCommand.start();
}
/**
* The Commands that can be executed
* @param s the command reader
*/
private void waitForAndExecuteCommands(Scanner s) {
String command;
command = s.nextLine();
if (command.contains("shutdown")){
shutDown(0);
}else if(command.contains("update")){
initFields();
createUserGroupMap();
createTeamMap();
}else if(command.contains("commit")){
updateFromDB();
}
}
/**
* 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();
updateFromDB();
serverShouldRun = false;
die(status);
}
/**
* Finally shuts down the server
* @param status
*/
private void die(int status) {
System.out.println("Shutting down server... ");
System.exit(status);
}
/**
* Removse listener from the loggedInUser, for example in case of a logout
* @param loggedInUser the user you want to remove the listener from
* @param inputListenerToRemove the listener
*/
public void removeUserListener(UserLogin loggedInUser, MessageInputListener inputListenerToRemove) {
LinkedList<Group> groupsOfUser = this.userGroupMap.get(loggedInUser);
for (Group g : groupsOfUser) {
this.teamMap.get(g).removeListener(inputListenerToRemove);
}
}
/**
* Adds listener for the loggedInUser
* @param loggedInUser the user you want to add the listener to
* @param inputListenerToAdd the listener
*/
public void addUserListener(UserLogin loggedInUser, MessageInputListener inputListenerToAdd) {
LinkedList<Group> groupsOfUser = this.userGroupMap.get(loggedInUser);
for (Group g : groupsOfUser){
this.teamMap.get(g).addListener(inputListenerToAdd);
}
}
/**
* Checks whether the combination of the username and password exists in the userGroupMap
* @param username username for userLogin
* @param password password for userLogin
* @return userLogin-Object, returns null if the user doesn't exist
*/
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;
}
/**
* Creates the LoginData Object for the Client, it contains the User and his teamMap
* @param loggedInUser the user that you want the information to
* @return the LoginData of the corresponding user
*/
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();
LinkedList<Task> taskList = this.teamMap.get(g).getTasks();
loginMap.put(g, new GroupInformation(messagesInChatRoom, roleMap, pollList, taskList));
}
return new LoginData(loginMap, loggedInUser);
}
/**
* If the user already exist, abort function and return false
* else, create a linked list of group elements.
* first the default group is added, the group every user is a part of, to get the system messages
* add user to the list and return true
* @param userToAdd The user that should be registered/added
* @param newListener The users listener/The way the server can talk to the corresponding client
* @return whether the user can be added or not (defined by, whether the user already exists)
*/
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;
}
/**
* get the PermissionRole of the user in the group
* @param sendingUser the user to check the permission from
* @param group the GroupName to check the user in
* @return the PermissionRole of the user in the group
*/
public PermissionRole getRightsInGroup(User sendingUser, Group group) {
System.out.println("getting rights in group...");
TeamInfo teamInfoOfGroup = this.teamMap.get(group);
if(teamInfoOfGroup == null) return PermissionRole.NONE;
System.out.println("team exists");
UserLogin userLogin = (UserLogin) sendingUser;
PermissionRole roleOfUser = this.teamMap.get(group).getRoleMap().get(userLogin.removePassword());
if (roleOfUser == null) return PermissionRole.NONE;
System.out.println("user has role...");
System.out.println(roleOfUser);
return roleOfUser;
}
/**
* Check if user alrady exists
* @param user the selected user
* @return whether a user is alrady in the userGroupMap
*/
public boolean userRegistered(UserLogin user) {
return this.userGroupMap.keySet().contains(user);
}
/**
* create a new group, add it to teamMap
* @param addingUser the user that shall become the leader
* @param content the first content inside of the new group
*/
public Group addGroup(User addingUser, String content, MessageInputListener newListener) {
Group newGroup = new Group(Group.getNextId(), content);
TeamInfo newTeamInfo = new TeamInfo(newGroup);
newTeamInfo.addListener(newListener);
this.teamMap.put(newGroup, newTeamInfo);
this.teamMap.get(newGroup).getRoleMap().put(addingUser, PermissionRole.ADMIN);
this.userGroupMap.get(addingUser).add(newGroup);
return newGroup;
}
public void finishPoll(Group pollGroup, Poll pollToFinish){
pollToFinish.stopRunning();
Message pollFinishMessage = new Message(pollGroup, ServerStatus.POLL_FINISHED, SYSTEM,
"Poll finish", pollToFinish);
this.notifyObservers(pollFinishMessage);
}
/**
* edit the user information,
* old instance of Userlogin will be removed, the new instance of UserLogin gets assigned
* @param newUser the user whose information should be edited
*/
public void changeUser(UserLogin newUser) {
System.out.println("changing user info ...");
LinkedList<Group> temp = this.userGroupMap.get(this.findUserByName(newUser.getUserName()));
this.getAllUsersAsList().remove(this.findUserByName(newUser.getUserName()));
this.userGroupMap.put(newUser, temp);
}
private UserLogin findUserByName(String userName) {
for (UserLogin userLogin : userGroupMap.keySet()){
if (userName.equals(userLogin.getUserName())) return userLogin;
}
return null;
}
/**
* Initialize Server
* @param args well its something
*/
public static void main(String[] args){
ServerController server = new ServerController();
server.startConnectionLoop();
}
public Set<UserLogin> getAllUsersAsList() {
return this.userGroupMap.keySet();
}
}

View File

@@ -0,0 +1,698 @@
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.models.taskboard.*;
import new_build.server.constants.DEBUG;
import new_build.server.constants.PermissionRole;
import new_build.server.control.ServerController;
import new_build.server.control.observation.MessageInputListener;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
public class ConnectionProcessor extends Thread implements MessageInputListener {
public static final Message REGISTRATION_FAILED_MESSAGE = new Message(Group.DEFAULT_GROUP, ServerStatus.REGISTRATION_FAILED,
ServerController.SYSTEM, "registration failed", null);
public static final Message REGISTRATION_SUCCESSFUL_MESSAGE = new Message(Group.DEFAULT_GROUP, ServerStatus.REGISTRATION_SUCCESSFUL,
ServerController.SYSTEM, "registration successful", null);
public static final Message TASK_NOT_CREATED_MESSAGE = new Message(Group.DEFAULT_GROUP,
ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM, "Task was not created", null);
public static final Message CREDENTIALS_INVALID_MESSAGE = new Message(Group.DEFAULT_GROUP,
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
public static final Message PERMISSION_DENIED_MESSAGE = new Message(Group.DEFAULT_GROUP, ServerStatus.PERMISSION_DENIED, ServerController.SYSTEM,
"permission denied", null);
public static final Message SESSION_EXPIRED_MESSAGE = new Message(Group.DEFAULT_GROUP, ServerStatus.SESSION_EXPIRED,
ServerController.SYSTEM, "cant log out, not logged in", null);
public static final Message LOGGED_OUT_MESSAGE = new Message(Group.DEFAULT_GROUP, ServerStatus.LOGOUT_SUCCESSFUL, ServerController.SYSTEM,
"logged out successful", null);
public static final Message ERR_EXECUTING_COMMAND_MESSAGE = new Message(Group.DEFAULT_GROUP,
ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM, "Error executing command!", null);
public static final Message POLL_NOT_FOUND_MESSAGE = new Message(Group.DEFAULT_GROUP, ServerStatus.LOGOUT_SUCCESSFUL,
ServerController.SYSTEM, "Couldn't find the Poll you voted for.", null);
private Connection assignedConnection;
private UserLogin loggedInUser;
private ServerController assignedController;
private boolean keepConnection;
private static final Message FALSE_CREDENTIALS_MESSAGE = new Message(
Group.DEFAULT_GROUP,
ServerStatus.SESSION_EXPIRED,
ServerController.SYSTEM,
"credentials invalid",
null);
public ConnectionProcessor(Connection assignedConnection, ServerController assignedController){
this.assignedConnection = assignedConnection;
this.assignedController = assignedController;
this.keepConnection = true;
}
@Override
public void sendInformation(Message message) {
try {
System.out.println("sending information " + message.getControlHeader());
assignedConnection.sendMessage(message);
removeSelfIfMemberLeft(message);
} catch (IOException e) {
e.printStackTrace();
}
}
private void removeSelfIfMemberLeft(Message message) {
if(message.getControlHeader() == ServerStatus.MEMBER_LEFT &&
message.getExtension().equals(this.loggedInUser)) removeSelf(message.getGroup());
}
@Override
public User listeningUser() {
return this.loggedInUser;
}
/**
* Set the user of this Connection
* @param u user that uses this connection
*/
public void setUser(UserLogin u){
this.loggedInUser = u;
}
/**
* The main of this thread
* While the connection should be kept: Get the message of the connection and process it, if it isn't null
* If the connection shouldn't be kept anymore, close this Thread
*/
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();
}
/**
*
* @return Whether this keepConnection and the Server should be running
*/
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) {
this.logout();
this.closeConnection();
return;
}
if (message.hasExtension()){
System.out.println("Extension is instance of " + message.getExtension().getType().getName());
}
Message answer = this.handleCommandAndReturnMessage(message);
selectListenersToSendTo(answer);
}
private void selectListenersToSendTo(Message answer) {
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 TASK_ADDED: this.assignedController.notifyObservers(answer);break;
case TASK_CHANGED: this.assignedController.notifyObservers(answer);break;
case PROFILE_CHANGE_SUCCESSFUL: this.sendInformation(answer);break; //TODO Changes are shown just for the assigned user
case ERR_EXECUTING_COMMAND: this.sendInformation(answer);break;
default: this.sendInformation(answer);break;
// PROFILE_CHANGE_SUCCESSFUL;
}
}
@Override
public void run() {
this.listenToMessages();
}
private void removeSelf(Group groupToRemoveIn){
assignedController.getTeamFromGroup(groupToRemoveIn).removeListener(this);
}
/**
* The core of the whole thing the incoming message is processed here
* Current commands are:
* - login
* - changeUser
* - changeProfilePic
* - logout
* - register
* - sendMessage
* - addGroup
* - addUser
* - removeUser
* - changeRole
* - unknown
* - addPoll
* - votePoll
* - addTask
* - changeTask
* @param m the message that is supposed to be "analyzed"
* @return the reactive message
*/
public Message handleCommandAndReturnMessage(Message m) {
if (messageInvalid(m)) return null;
printServerTerminalInfo(m);
switch (((Command) m.getControlHeader())) {
case LOGIN:
return handleLoginCommand(m);
case CHANGEUSER:
return handleChangeUserCommand(m);
case CHANGEPROFILEPIC:
return ERR_EXECUTING_COMMAND_MESSAGE;
case LOGOUT:
return handleLogoutCommand();
case REGISTER:
return handleRegisterCommand(m);
case SENDMESSAGE:
return handleSendMessageCommand(m);
case ADDGROUP:
return handleAddGroupCommand(m);
case ADDUSER:
return handleAddUserCommand(m);
case REMOVEUSER:
return handleRemoveUserCommand(m);
case CHANGEROLE:
return handleChangeRoleCommand(m);
case ADDPOLL:
return handleAddPollCommand(m);
case VOTE_POLL:
return handleVotePollCommand(m);
case ADDTASK:
return handleAddTaskCommand(m);
case CHANGETASK:
return handleChangeTaskCommand(m);
case UNKNOWN:
return returnCommandUnknownMessage();
case GET_ALL_USERS:
return getAllUsersOnServer(m);
default:
return returnCommandUnknownMessage();
}
}
private Message getAllUsersOnServer(Message message) {
UserLogin user = (UserLogin) message.getSendingUser();
if (validateCredentials(user) && assignedController.getRightsInGroup(user, message.getGroup()).hasAdminRights
()) {
Set<UserLogin> userList = assignedController.getAllUsersAsList();
List<Pair<User, PermissionRole>> usersWithRole = new ArrayList<>();
for (User u : userList){
Pair<User, PermissionRole> userWithRole = new Pair<>(u, assignedController.getRightsInGroup(u,
message.getGroup()));
usersWithRole.add(userWithRole);
}
UserList listToReturn = new UserList(usersWithRole);
return createUserListReturnMessage(listToReturn);
}
return PERMISSION_DENIED_MESSAGE;
}
private Message createUserListReturnMessage(UserList listToReturn) {
return new Message(Group.DEFAULT_GROUP,
ServerStatus.USERLIST_SEND,
ServerController.SYSTEM,
"send all users",
listToReturn);
}
private Message handleLoginCommand(Message m) {
String[] credentials = m.getContent().split(" "); // format of credentials = [username, password]
if ((credentials.length == 2) && (loggedInUser == null)) {
UserLogin loginTry = assignedController.validateLogin(credentials[0], credentials[1]);
if (loginSuccessful(loginTry)) {
LoginData loginData = makeLoginUpdates(loginTry);
return new Message(Group.DEFAULT_GROUP, ServerStatus.LOGIN_SUCCESSFUL, loginTry, "login successful", loginData);
}
} // ErrorMessage
return new Message(Group.DEFAULT_GROUP, ServerStatus.LOGIN_FAILED, null, "login failed", null);
}
private boolean loginSuccessful(UserLogin loginTry) {
return loginTry != null;
}
private LoginData makeLoginUpdates(UserLogin loginTry) {
LoginData loginData = assignedController.getLoginUpdates(loginTry);
this.loggedInUser = loginTry;
assignedController.addUserListener(loginTry, this);
return loginData;
}
private Message handleChangeUserCommand(Message m) {
if(!this.validateCredentials(m.getSendingUser())) return FALSE_CREDENTIALS_MESSAGE;
return handleUserChange(m);
}
private Message handleLogoutCommand() {
if (loggedInUser == null) return SESSION_EXPIRED_MESSAGE;
else {
this.logout();
return LOGGED_OUT_MESSAGE;
}
}
private Message handleRegisterCommand(Message m) {
System.out.println("registration incoming...");
if(hasWrongExtension(m, UserLogin.class)) return getErrorMessage("no user send");
if(assignedController.userRegistered((UserLogin) m.getExtension()))
return getErrorMessage("user already exists");
else if(assignedController.addUser(((UserLogin) m.getExtension()), this)){ // if user alrady exists
System.out.println("successful registration");
return REGISTRATION_SUCCESSFUL_MESSAGE;
} else { // if user isn't a UserLogin, an existing User or already exists
return getErrorMessage("unsuccessful registration");
}
}
private Message handleSendMessageCommand(Message m) {
if(!this.validateCredentials(m.getSendingUser())){
return FALSE_CREDENTIALS_MESSAGE;
} else if(hasUserRights(m)){
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);
}
private Message handleAddGroupCommand(Message m) {
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
if (m.getContent().equals("") || groupNameExists(m.getContent())) return ERR_EXECUTING_COMMAND_MESSAGE;
return getGroupCreatedMessage(m, createNewGroupWithMessage(m));
}
private boolean groupNameExists(String content) {
return assignedController.getTeamMap()
.keySet().stream()
.anyMatch(g -> g.getName().equals(content));
}
private Message handleAddUserCommand(Message m) {
if(!(validateCredentials(m.getSendingUser()))) return SESSION_EXPIRED_MESSAGE;
if(m.getExtension() == null || !(m.getExtension() instanceof User))
return getErrorMessage("no user send with command");
if(hasTeamLeaderRights(m)){
User joiningUser = ((User) m.getExtension());
assignedController.getTeamMap().get(m.getGroup()).getRoleMap().put(joiningUser, PermissionRole.USER);
return getUserJoinedMessage(m, joiningUser);
} else return PERMISSION_DENIED_MESSAGE;
}
private Message handleRemoveUserCommand(Message m) {
if(!(validateCredentials(m.getSendingUser()))) return new Message(Group.DEFAULT_GROUP,
ServerStatus.SESSION_EXPIRED, ServerController.SYSTEM, "credentials invalid", null);
if(m.getExtension() == null || !(m.getExtension() instanceof User)) return new Message(
Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM, "no user send in" +
" message", null);
if(hasTeamLeaderRights(m)){
assignedController.getTeamMap().get(m.getGroup()).getRoleMap().remove(m.getExtension());
return getUserLeftMessage(m);
} else return PERMISSION_DENIED_MESSAGE;
}
private Message handleChangeRoleCommand(Message m) {
if(!(validateCredentials(m.getSendingUser())))
return new Message(
Group.DEFAULT_GROUP,
ServerStatus.SESSION_EXPIRED,
ServerController.SYSTEM,
"credentials invalid",
null);
if (!isExtensionPair(m))
return this.getErrorMessage("no Role-Pair send with Command");
if(assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasAdminRights()){
return tryRoleChangeAndReturnMessage(m);
}
return PERMISSION_DENIED_MESSAGE;
}
private Message tryRoleChangeAndReturnMessage(Message m) {
Pair changeData = ((Pair) m.getExtension());
User userToChange = ((User) changeData.getA());
PermissionRole roleToSet = ((PermissionRole) changeData.getB());
if(isChangeToAdminOrHigher(roleToSet)) {
return PERMISSION_DENIED_MESSAGE;
}else {
assignedController.getTeamMap().get(m.getGroup()).getRoleMap().put(userToChange, roleToSet);
return getRoleChangedMessage(m, userToChange, roleToSet);
}
}
private Message getRoleChangedMessage(Message m, User userToChange, PermissionRole roleToSet) {
Pair<User, PermissionRole> returnPair = new Pair<>(userToChange, roleToSet);
if (roleToSet == PermissionRole.NONE) return new Message(m.getGroup(), ServerStatus.MEMBER_LEFT, ServerController
.SYSTEM, "User " + userToChange.getFirstName() + " " + userToChange.getLastName() + " left",
returnPair);
else return new Message(m.getGroup(), ServerStatus.ROLE_CHANGED, ServerController.SYSTEM, "userrole of " +
userToChange.getUserName() + " changed to " + roleToSet, returnPair);
}
private Message handleAddPollCommand(Message m) {
if(!(validateCredentials(m.getSendingUser()))) return CREDENTIALS_INVALID_MESSAGE;
if(this.hasWrongExtension(m, Poll.class))
return getErrorMessage("no poll send with message");
if(!hasUserRights(m)) return PERMISSION_DENIED_MESSAGE;
Poll createdPoll = createPollFromExtension(m);
if (createdPoll == null) return ERR_EXECUTING_COMMAND_MESSAGE;
Group pollsGroup = m.getGroup() ;
Timer pollFinishTimer = new Timer();
java.util.Date expireingDate = new Date(createdPoll.getExpiringDate().getTime());
pollFinishTimer.schedule(new TimerTask() {
@Override
public void run() {
assignedController.finishPoll(m.getGroup(), createdPoll);
}
}, expireingDate);
createdPoll.setId(ServerController.maxPollID);
assignedController.getTeamFromGroup(pollsGroup).addPoll(createdPoll);
Optional<Poll> toSendPoll = assignedController.getTeamMap().get(m.getGroup()).getPolls()
.stream().filter(p -> p.getPollID() == ServerController.maxPollID).findFirst();
if (toSendPoll.isPresent()){
Message toSendMessage = getPollCreatedMessage(m, toSendPoll.get());
ServerController.maxPollID++;
return toSendMessage;
} else{
return POLL_NOT_FOUND_MESSAGE;
}
}
private Message getPollCreatedMessage(Message m, Poll createdPoll) {
return new Message(m.getGroup(), ServerStatus.POLL_CREATED, ServerController.SYSTEM,
"Poll created", createdPoll);
}
private Poll createPollFromExtension(Message m) {
Poll createdPoll = ((Poll) m.getExtension());
if (createdPoll.getExpiringDate().before(Date.from(Instant.now()))) return null;
return createdPoll;
}
private Message handleVotePollCommand(Message m) {
if(!(validateCredentials(m.getSendingUser()))) {
return FALSE_CREDENTIALS_MESSAGE;
}
if(this.hasWrongExtension(m, Vote.class))
return getErrorMessage("no vote send with message");
Vote votedVote = (Vote) m.getExtension();
votedVote.getPollVotedIn();
Optional<Poll> votedPoll = assignedController.getTeamMap().get(m.getGroup()).getPolls()
.stream().filter(p -> p.getPollID() == votedVote.getPollVotedIn()).findFirst();
boolean correctPoll = votedPoll.get().getPollID() == votedVote.getPollVotedIn();
if (hasUserRights(m)) {
if (votedPoll.isPresent()){
if (correctPoll && votedPoll.get().getIsRunning()){
return makeDataChangesAndReturnVoteSuccessfulMessage(m);
} else {
return ERR_EXECUTING_COMMAND_MESSAGE;
}
} else {
return ERR_EXECUTING_COMMAND_MESSAGE;
}
} else {
return PERMISSION_DENIED_MESSAGE;
}
}
private Message makeDataChangesAndReturnVoteSuccessfulMessage(Message m) {
Vote v = ((Vote) m.getExtension());
assignedController.getTeamFromGroup(m.getGroup()).addVoteAndStopIfFull(loggedInUser.removePassword(), v);
return getVoteSuccessfulMessage(m, v);
}
private Message getVoteSuccessfulMessage(Message m, Vote v) {
return new Message(m.getGroup(),
ServerStatus.VOTE_SUCCESSFUL,
m.getSendingUser(),
"vote added successfully",
v);
}
private Message handleAddTaskCommand(Message m) {
if (m.getExtension() == null){
System.out.println("Task not created - Extension not found");
return TASK_NOT_CREATED_MESSAGE;
}
Task temp = (Task) m.getExtension();
ServerController.maxTaskID++;
temp.setTaskID(ServerController.maxTaskID);
Timer pollFinishTimer = new Timer();
System.out.println(m.getGroup().getName());
if (assignedController.getTeamFromGroup(m.getGroup()) == null) {
System.out.println("Task not created - Group not found!");
return TASK_NOT_CREATED_MESSAGE;
}
assignedController.getTeamFromGroup(m.getGroup()).addTask(temp);
return getTaskAddedMessage(m, temp);
}
private Message getTaskAddedMessage(Message m, Task task) {
return new Message(m.getGroup(),
ServerStatus.TASK_ADDED,
ServerController.SYSTEM,
"Task has been added",
task);
}
private Message handleChangeTaskCommand(Message m) {
//Checking message has Extension
if (m.getExtension() == null)
return ERR_EXECUTING_COMMAND_MESSAGE;
TeamInfo temp = this.assignedController.getTeamFromGroup(m.getGroup());
Task task = temp.getTaskbyID(((EditTask) m.getExtension()).getTaskID());
int taskID = task.getTaskID();
new_build.models.taskboard.State state = ((EditTask) m.getExtension()).getState();
if (task.getUser() == null
|| task.getUser().getID() == m.getSendingUser().getID()
|| this.assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasTeamleaderRights()){
} else {
return PERMISSION_DENIED_MESSAGE;
}
new_build.models.taskboard.State currentState = task.getState();
//Checking permission of user
if (currentState.name().equals("CREATED")
&& !this.assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasTeamleaderRights()){
return PERMISSION_DENIED_MESSAGE;
}
//Checking changes to do
if (state != null){
//State only gets changed
temp.changeTaskState(task, state);
} else if(((EditTask) m.getExtension()).getUser() != null) {
//operating user of the task gets changed including task's state
temp.changeTaskUser(task, ((EditTask) m.getExtension()).getUser());
} else {
return ERR_EXECUTING_COMMAND_MESSAGE;
}
//Returning the updated task
Task changedTask = temp.getTaskbyID(taskID);
System.out.println(changedTask.getTaskID() + " " + changedTask.getState().name());
return new Message(m.getGroup(), ServerStatus.TASK_CHANGED, ServerController.SYSTEM, "Task changed!", changedTask);
}
private Message returnCommandUnknownMessage() {
return new Message(Group.DEFAULT_GROUP, ServerStatus.COMMAND_UNKNOWN, ServerController.SYSTEM,
"unknown command", null);
}
private boolean hasUserRights(Message m) {
return assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasUserRights();
}
private Message getErrorMessage(String content) {
return new Message(
Group.DEFAULT_GROUP,
ServerStatus.ERR_EXECUTING_COMMAND,
ServerController.SYSTEM,
content,
null);
}
private boolean isChangeToAdminOrHigher(PermissionRole roleToSet) {
return roleToSet.equals(PermissionRole.ADMIN) || roleToSet.equals(PermissionRole.OWNER);
}
private boolean hasTeamLeaderRights(Message m) {
return assignedController.getRightsInGroup(m.getSendingUser(), m.getGroup()).hasTeamleaderRights();
}
private boolean isExtensionPair(Message m) {
boolean isPair = !hasWrongExtension(m, Pair.class);
if (isPair) {
Pair userWithRole = (Pair) m.getExtension();
return (userWithRole).getA().getClass().equals(User.class) ||
(userWithRole).getB().getClass().equals(PermissionRole.class);
} else return false;
}
private Message getUserLeftMessage(Message m) {
return new Message(m.getGroup(), ServerStatus.MEMBER_LEFT, ServerController.SYSTEM, "user " +
((User) m.getExtension()).getUserName() + " left the team", m.getExtension());
}
private Message getUserJoinedMessage(Message m, User joinedUser) {
return new Message(m.getGroup(), ServerStatus.MEMBER_JOINED, ServerController.SYSTEM, "user " +
joinedUser.getUserName() + " joined the team", joinedUser);
}
private Message getGroupCreatedMessage(Message m, Group g) {
HashMap<User, PermissionRole> tempRoleMap = new HashMap<>();
tempRoleMap.put(m.getSendingUser(), PermissionRole.ADMIN);
LinkedList<Message> messageList = new LinkedList<>();
GroupInformation gi = new GroupInformation(messageList, tempRoleMap,
new LinkedList<Poll>(), new LinkedList<Task>());
gi.setGroup(g);
return new Message(Group.DEFAULT_GROUP, ServerStatus.GROUP_CREATED, ServerController.SYSTEM,
"group " + m.getContent() + " created", gi);
}
private Group createNewGroupWithMessage(Message m) {
Group newGroup = assignedController.addGroup(m.getSendingUser(), m.getContent(), this);
assignedController.addUser(((UserLogin) m.getSendingUser()), this);
return newGroup;
}
private Message handleUserChange(Message m) {
if(!hasWrongExtension(m, UserLogin.class) && ((UserLogin) m.getExtension()).getUserName().equals(loggedInUser.getUserName())){
UserLogin newUser = ((UserLogin) m.getExtension());
UserLogin changes = new UserLogin(newUser.getID(),
newUser.getUserName(),
newUser.getFirstName(),
newUser.getLastName(),
newUser.getPassword(),
newUser.getProfilePic());
this.assignedController.changeUser(changes);
this.loggedInUser = changes;
return new Message(m.getGroup(), ServerStatus.PROFILE_CHANGE_SUCCESSFUL, ServerController.SYSTEM,
"user changed", changes);
} else return new Message(Group.DEFAULT_GROUP, ServerStatus.ERR_EXECUTING_COMMAND, ServerController.SYSTEM,
"no or invalid userlogin object send to change to", null);
}
private boolean hasWrongExtension(Message m, Class expectedExtensionType) {
return m.getExtension() == null || !m.getExtension().getType().equals(expectedExtensionType);
}
private void printServerTerminalInfo(Message m) {
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);
}
}
private boolean messageInvalid(Message m) {
if (m == null) {
System.out.println("message null");
return true;
}
return false;
}
/**
*
* @param loginTry User that tries to do something
* @return is the user allowed to do such thing?
*/
private boolean validateCredentials(User loginTry) {
if(loggedInUser == null) { // if the user isn't logged in
System.out.println("not logged in ... ");
return false;
}
if(loginTry == null){ //
System.out.println("no user object sent 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); // make User a UserLogin
return userNameAndPasswordEqual(login);
}
}
private boolean userNameAndPasswordEqual(UserLogin login) {
if(login.getPassword().equals(this.loggedInUser.getPassword())){ // is the
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(){
this.assignedController.updateLogoutTimestampOfUser(loggedInUser);
if (loggedInUser == null) return;
this.assignedController.removeUserListener(loggedInUser, this);
this.loggedInUser = null;
}
}

View File

@@ -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();
}

Some files were not shown because too many files have changed in this diff Show More