diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java index dd4ebf438976d96cfe61b1bf4402569834e57ae7..c29e342fd201643bf579d525e84df57c147b0ae3 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java @@ -1,11 +1,14 @@ package unipotsdam.gf.core.management; +import unipotsdam.gf.core.management.group.Group; import unipotsdam.gf.core.management.project.Project; import unipotsdam.gf.core.management.user.User; import unipotsdam.gf.core.management.user.UserInterests; import unipotsdam.gf.core.management.user.UserProfile; import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; +import java.util.*; + /** * Created by dehne on 31.05.2018. * TODO in DAOs refaktorisieren, sobald es mehr wird @@ -13,12 +16,14 @@ import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; public interface Management { /** * delete a User in the database + * * @param identifier */ void delete(StudentIdentifier identifier); /** * create a User in the database + * * @param user * @param profile */ @@ -26,18 +31,21 @@ public interface Management { /** * create a Project in the database + * * @param project */ void create(Project project); /** * Delete a Project in the database + * * @param project */ void delete(Project project); /** * Add an entry in the M:N table linking users and projects + * * @param user * @param project * @param interests @@ -46,6 +54,7 @@ public interface Management { /** * Check if a user exists in the DB + * * @param user * @return */ @@ -53,6 +62,7 @@ public interface Management { /** * Get all the users linked to a project + * * @param project * @return */ @@ -60,6 +70,7 @@ public interface Management { /** * get the token for the user + * * @param user * @return */ @@ -67,9 +78,18 @@ public interface Management { /** * get the user given his http token + * * @param token * @return */ User getUser(String token); + + void createGroup(List<User> groupMembers, String projectId); + + void addGroupMember(User groupMember, int groupId); + + void deleteGroupMember(User groupMember, int groupId); + + List<Group> getGroups(String projectId); } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java index dfffd4df1fdf0dee228ae9e1d499876342e4219c..2e23b8f5bc7f9072ba5129952f6bcf6ad2f9932d 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java @@ -2,6 +2,7 @@ package unipotsdam.gf.core.management; import unipotsdam.gf.core.database.mysql.MysqlConnect; import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet; +import unipotsdam.gf.core.management.group.Group; import unipotsdam.gf.core.management.project.Project; import unipotsdam.gf.core.management.user.User; import unipotsdam.gf.core.management.user.UserInterests; @@ -91,7 +92,10 @@ public class ManagementImpl implements Management { @Override public List<User> getUsers(Project project) { String query = - "SELECT * FROM users u " + " JOIN projectuser pu ON u.email=pu.userId" + " JOIN projects p ON pu.projectId = p.id" + " WHERE pu.projectId = ?"; + "SELECT * FROM users u " + + " JOIN projectuser pu ON u.email=pu.userId" + + " JOIN projects p ON pu.projectId = p.id" + + " WHERE pu.projectId = ?"; ArrayList<User> result = new ArrayList<User>(); MysqlConnect connect = new MysqlConnect(); @@ -152,4 +156,43 @@ public class ManagementImpl implements Management { return null; } } + + @Override + public void createGroup(List<User> groupMembers, String projectId) { + + for (User groupMember : groupMembers) { + UUID uuid = UUID.randomUUID(); + String token = uuid.toString(); + + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = + "INSERT INTO projects (`projectId`) values (?)"; + VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(mysqlRequest, projectId); + vereinfachtesResultSet.next(); + int id = vereinfachtesResultSet.getInt("id"); + + String mysqlRequest2 = + "INSERT INTO groupuser (`userEmail`, `groupId`) values (?,?)"; + connect.issueInsertOrDeleteStatement(mysqlRequest2, groupMember.getEmail(), projectId); + connect.close(); + } + + + } + + @Override + public void addGroupMember(User groupMember, int groupId) { + + } + + @Override + public void deleteGroupMember(User groupMember, int groupId) { + + } + + @Override + public List<Group> getGroups(String projectId) { + return null; + } } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/group/Group.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/group/Group.java new file mode 100644 index 0000000000000000000000000000000000000000..781c92a711dbf837dbf6ee4eed15229bc6d4d8aa --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/group/Group.java @@ -0,0 +1,26 @@ +package unipotsdam.gf.core.management.group; + +import unipotsdam.gf.core.management.user.User; + +import java.util.*; + +public class Group { + + + + List<User> members; + + public Group(List<User> members) { + this.members = members; + } + + public List<User> getMembers() { + return members; + } + + public void setMembers(List<User> members) { + this.members = members; + } + + +} diff --git a/gemeinsamforschen/src/scripts/dbschema/fltrail.sql b/gemeinsamforschen/src/scripts/dbschema/fltrail.sql index d7978655cfb76571a9bea19f726cacc6ca03364d..ee7f5ec1466c33e1012499debc2efb6141af9bff 100644 --- a/gemeinsamforschen/src/scripts/dbschema/fltrail.sql +++ b/gemeinsamforschen/src/scripts/dbschema/fltrail.sql @@ -1,15 +1,7 @@ -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8mb4 */; - CREATE DATABASE IF NOT EXISTS `fltrail` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `fltrail`; -CREATE TABLE `projects` ( +CREATE TABLE if not exists `projects` ( `id` varchar(400) NOT NULL, `password` varchar(400) NOT NULL, `activ` tinyint(1) NOT NULL, @@ -19,30 +11,38 @@ CREATE TABLE `projects` ( `token` varchar(400) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `tags` ( + +CREATE TABLE if not exists `groups` ( + `id` int NOT NULL AUTO_INCREMENT, + `projectId` varchar(400) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE if not exists groupuser + ( + userEmail varchar(400) NOT NULL, + groupId int NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE if not exists `tags` ( `projectId` varchar(400) NOT NULL, `tag` varchar(400) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `users` ( +CREATE TABLE if not exists `users` ( `name` varchar(400) NOT NULL, `password` varchar(200) NOT NULL, `email` varchar(400) NOT NULL, `token` varchar(800) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE projectuser +CREATE TABLE if not exists projectuser ( projectId varchar(400) NOT NULL, userId varchar(400) NOT NULL -); ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; alter table users add isStudent tinyint(1) default '1' null; - - -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;