Skip to content
Snippets Groups Projects
Commit e6c3f21c authored by Julian Dehne's avatar Julian Dehne
Browse files

feat: implemented group tables for context mocking

parent 2f313a86
No related branches found
No related tags found
No related merge requests found
package unipotsdam.gf.core.management; package unipotsdam.gf.core.management;
import unipotsdam.gf.core.management.group.Group;
import unipotsdam.gf.core.management.project.Project; import unipotsdam.gf.core.management.project.Project;
import unipotsdam.gf.core.management.user.User; import unipotsdam.gf.core.management.user.User;
import unipotsdam.gf.core.management.user.UserInterests; import unipotsdam.gf.core.management.user.UserInterests;
import unipotsdam.gf.core.management.user.UserProfile; import unipotsdam.gf.core.management.user.UserProfile;
import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; import unipotsdam.gf.modules.assessment.controller.StudentIdentifier;
import java.util.*;
/** /**
* Created by dehne on 31.05.2018. * Created by dehne on 31.05.2018.
* TODO in DAOs refaktorisieren, sobald es mehr wird * TODO in DAOs refaktorisieren, sobald es mehr wird
...@@ -13,12 +16,14 @@ import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; ...@@ -13,12 +16,14 @@ import unipotsdam.gf.modules.assessment.controller.StudentIdentifier;
public interface Management { public interface Management {
/** /**
* delete a User in the database * delete a User in the database
*
* @param identifier * @param identifier
*/ */
void delete(StudentIdentifier identifier); void delete(StudentIdentifier identifier);
/** /**
* create a User in the database * create a User in the database
*
* @param user * @param user
* @param profile * @param profile
*/ */
...@@ -26,18 +31,21 @@ public interface Management { ...@@ -26,18 +31,21 @@ public interface Management {
/** /**
* create a Project in the database * create a Project in the database
*
* @param project * @param project
*/ */
void create(Project project); void create(Project project);
/** /**
* Delete a Project in the database * Delete a Project in the database
*
* @param project * @param project
*/ */
void delete(Project project); void delete(Project project);
/** /**
* Add an entry in the M:N table linking users and projects * Add an entry in the M:N table linking users and projects
*
* @param user * @param user
* @param project * @param project
* @param interests * @param interests
...@@ -46,6 +54,7 @@ public interface Management { ...@@ -46,6 +54,7 @@ public interface Management {
/** /**
* Check if a user exists in the DB * Check if a user exists in the DB
*
* @param user * @param user
* @return * @return
*/ */
...@@ -53,6 +62,7 @@ public interface Management { ...@@ -53,6 +62,7 @@ public interface Management {
/** /**
* Get all the users linked to a project * Get all the users linked to a project
*
* @param project * @param project
* @return * @return
*/ */
...@@ -60,6 +70,7 @@ public interface Management { ...@@ -60,6 +70,7 @@ public interface Management {
/** /**
* get the token for the user * get the token for the user
*
* @param user * @param user
* @return * @return
*/ */
...@@ -67,9 +78,18 @@ public interface Management { ...@@ -67,9 +78,18 @@ public interface Management {
/** /**
* get the user given his http token * get the user given his http token
*
* @param token * @param token
* @return * @return
*/ */
User getUser(String token); 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);
} }
...@@ -2,6 +2,7 @@ package unipotsdam.gf.core.management; ...@@ -2,6 +2,7 @@ package unipotsdam.gf.core.management;
import unipotsdam.gf.core.database.mysql.MysqlConnect; import unipotsdam.gf.core.database.mysql.MysqlConnect;
import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet; 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.project.Project;
import unipotsdam.gf.core.management.user.User; import unipotsdam.gf.core.management.user.User;
import unipotsdam.gf.core.management.user.UserInterests; import unipotsdam.gf.core.management.user.UserInterests;
...@@ -91,7 +92,10 @@ public class ManagementImpl implements Management { ...@@ -91,7 +92,10 @@ public class ManagementImpl implements Management {
@Override @Override
public List<User> getUsers(Project project) { public List<User> getUsers(Project project) {
String query = 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>(); ArrayList<User> result = new ArrayList<User>();
MysqlConnect connect = new MysqlConnect(); MysqlConnect connect = new MysqlConnect();
...@@ -152,4 +156,43 @@ public class ManagementImpl implements Management { ...@@ -152,4 +156,43 @@ public class ManagementImpl implements Management {
return null; 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;
}
} }
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;
}
}
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; CREATE DATABASE IF NOT EXISTS `fltrail` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `fltrail`; USE `fltrail`;
CREATE TABLE `projects` ( CREATE TABLE if not exists `projects` (
`id` varchar(400) NOT NULL, `id` varchar(400) NOT NULL,
`password` varchar(400) NOT NULL, `password` varchar(400) NOT NULL,
`activ` tinyint(1) NOT NULL, `activ` tinyint(1) NOT NULL,
...@@ -19,30 +11,38 @@ CREATE TABLE `projects` ( ...@@ -19,30 +11,38 @@ CREATE TABLE `projects` (
`token` varchar(400) NOT NULL `token` varchar(400) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) 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, `projectId` varchar(400) NOT NULL,
`tag` varchar(400) NOT NULL `tag` varchar(400) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `users` ( CREATE TABLE if not exists `users` (
`name` varchar(400) NOT NULL, `name` varchar(400) NOT NULL,
`password` varchar(200) NOT NULL, `password` varchar(200) NOT NULL,
`email` varchar(400) NOT NULL, `email` varchar(400) NOT NULL,
`token` varchar(800) NOT NULL `token` varchar(800) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE projectuser CREATE TABLE if not exists projectuser
( (
projectId varchar(400) NOT NULL, projectId varchar(400) NOT NULL,
userId varchar(400) NOT NULL userId varchar(400) NOT NULL
); ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
alter table users alter table users
add isStudent tinyint(1) default '1' null; 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 */;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment