Skip to content
Snippets Groups Projects
ProjectCreationProcess.java 5.48 KiB
Newer Older
package unipotsdam.gf.process;

Julian Dehne's avatar
Julian Dehne committed
import unipotsdam.gf.exceptions.*;
import unipotsdam.gf.interfaces.ICommunication;
wiepke's avatar
wiepke committed
import unipotsdam.gf.modules.annotation.model.Category;
import unipotsdam.gf.modules.assessment.AssessmentMechanism;
import unipotsdam.gf.modules.communication.model.RocketChatUser;
import unipotsdam.gf.modules.group.GroupDAO;
import unipotsdam.gf.modules.group.GroupFormationMechanism;
import unipotsdam.gf.modules.project.Management;
import unipotsdam.gf.modules.project.Project;
wiepke's avatar
wiepke committed
import unipotsdam.gf.modules.project.ProjectConfiguration;
import unipotsdam.gf.modules.user.User;
import unipotsdam.gf.process.constraints.ConstraintsImpl;
import unipotsdam.gf.process.phases.Phase;
Axel's avatar
Axel committed
import unipotsdam.gf.process.tasks.Task;
import unipotsdam.gf.process.tasks.TaskDAO;
import unipotsdam.gf.process.tasks.TaskName;
Julian Dehne's avatar
Julian Dehne committed
import unipotsdam.gf.session.GFContexts;

import javax.inject.Inject;
import javax.inject.Singleton;
Julian Dehne's avatar
Julian Dehne committed
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
wiepke's avatar
wiepke committed
import java.util.HashMap;

import static unipotsdam.gf.modules.group.GroupFormationMechanism.SingleUser;


@Singleton
public class ProjectCreationProcess {


    @Inject
    private ConstraintsImpl constraintsImpl;

    @Inject
    private Management iManagement;

    @Inject
    private TaskDAO taskDao;

    @Inject
    private GroupDAO groupDAO;

    @Inject
    private ICommunication iCommunication;
Julian Dehne's avatar
Julian Dehne committed
    @Inject
    private GFContexts gfContexts;

     * @param project which project is created
     * @param author who creates the project
Julian Dehne's avatar
Julian Dehne committed
    public void createProject(Project project, User author)
            throws RocketChatDownException, UserDoesNotExistInRocketChatException {
        project.setAuthorEmail(author.getEmail());
        try {
            iManagement.create(project);
        } catch (Exception e) {
            throw new WebApplicationException("Project already exists");
        }
        taskDao.createTaskWaitForParticipants(project, author);

        // create chatromm
        iCommunication.createEmptyChatRoom(project.getName(), false);

     * @param project which project is entered
     * @param user who is participates the project
Julian Dehne's avatar
Julian Dehne committed
    public void studentEntersProject(Project project, User user)
            throws RocketChatDownException, UserDoesNotExistInRocketChatException {
        // student enters project
        iManagement.register(user, project, null);

        // create info for student
Axel's avatar
Axel committed
        Task task = taskDao.createWaitingForGroupFormationTask(project, user);

        // ev. notifity teacher for new student
        // ev. send email that he is now part of project and will be notified if something happens
        Boolean groupsCanBeFormed = constraintsImpl.checkIfGroupsCanBeFormed(project);
        if (groupsCanBeFormed) {
            GroupFormationMechanism groupFormationMechanism = groupDAO.getGroupFormationMechanism(project);
wiepke's avatar
wiepke committed
            if (!groupFormationMechanism.equals(SingleUser) && !groupFormationMechanism
                    .equals(GroupFormationMechanism.Manual)) {
                taskDao.persistTeacherTask(project, TaskName.EDIT_FORMED_GROUPS, Phase.GroupFormation);
            } else {
Axel's avatar
Axel committed
                taskDao.persistTeacherTask(project, TaskName.CLOSE_GROUP_FINDING_PHASE, Phase.GroupFormation);
                taskDao.updateForAll(task);
Axel's avatar
Axel committed
                //phases.endPhase(Phase.GroupFormation, project);
        iCommunication.addUserToChatRoom(user, project.getName());
Julian Dehne's avatar
Julian Dehne committed

    public void createUser(User user)
            throws UserExistsInMysqlException, RocketChatDownException, UserExistsInRocketChatException {
        if(iManagement.exists(user)) {
            throw new UserExistsInMysqlException();
        }
        // create user in rocket chat
        iCommunication.registerUser(user);
        // create user in mysql
        iManagement.create(user, null);

    }

    public Boolean authenticateUser(User user, HttpServletRequest req)
            throws UserDoesNotExistInRocketChatException, RocketChatDownException {
        // todo implement

        RocketChatUser isLoggedIn = null;
        try  {
        isLoggedIn = iCommunication.loginUser(user);
Julian Dehne's avatar
Julian Dehne committed
        gfContexts.updateUserSessionWithRocketChat(req, isLoggedIn);
        } catch(Exception e) {
            System.out.println("rocketchat funktioniert nicht ... mache trotzdem weiter");
        } finally {
            if (isLoggedIn != null) {
            gfContexts.updateUserWithEmail(req, isLoggedIn);
            return iManagement.exists(user);
            } else {
                gfContexts.updateUserWithEmail(req, user);
                return iManagement.exists(user);
            }
        }
    public void deleteUser(User user) throws RocketChatDownException, UserDoesNotExistInRocketChatException {
        iManagement.delete(user);
        iCommunication.delete(user);
    }

    public void deleteProject(Project project) throws RocketChatDownException, UserDoesNotExistInRocketChatException {
        // TODO implement
        iManagement.delete(project);
        iCommunication.deleteChatRoom(project);
    }
     * @param project the project to delete
    public void deleteProject(Project project) {
        try {
            iManagement.delete(project);
        } catch (Exception e) {
            throw new WebApplicationException("Project already exists");
        }
        //taskDao.createTaskWaitForParticipants(project, author);