Search in sources :

Example 26 with AssignmentResponse

use of org.olat.course.nodes.gta.AssignmentResponse in project OpenOLAT by OpenOLAT.

the class GTAParticipantController method stepAssignment.

@Override
protected Task stepAssignment(UserRequest ureq, Task assignedTask) {
    assignedTask = super.stepAssignment(ureq, assignedTask);
    if (TaskHelper.inOrNull(assignedTask, TaskProcess.assignment)) {
        mainVC.contextPut("assignmentCssClass", "o_active");
        if (stepPreferences != null) {
            // assignment is very important, open it always
            stepPreferences.setAssignement(Boolean.TRUE);
        }
        // assignment open?
        DueDate dueDate = getAssignementDueDate(assignedTask);
        if (dueDate != null && dueDate.getDueDate() != null && dueDate.getDueDate().compareTo(new Date()) < 0) {
            // assignment is closed
            mainVC.contextPut("assignmentClosed", Boolean.TRUE);
        } else if (userCourseEnv.isCourseReadOnly()) {
            showAssignedTask(ureq, assignedTask);
        } else {
            List<TaskDefinition> availableTasks = gtaManager.getTaskDefinitions(courseEnv, gtaNode);
            // assignment auto or manual
            String assignmentType = config.getStringValue(GTACourseNode.GTASK_ASSIGNEMENT_TYPE);
            if (GTACourseNode.GTASK_ASSIGNEMENT_TYPE_AUTO.equals(assignmentType)) {
                AssignmentResponse response;
                if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
                    response = gtaManager.assignTaskAutomatically(taskList, assessedGroup, courseEnv, gtaNode);
                } else {
                    response = gtaManager.assignTaskAutomatically(taskList, assessedIdentity, courseEnv, gtaNode);
                }
                if (response == null || response.getStatus() == AssignmentResponse.Status.error) {
                    showError("task.assignment.error");
                } else if (response == null || response.getStatus() == AssignmentResponse.Status.noMoreTasks) {
                    showError("error.nomoretasks");
                } else if (response == null || response.getStatus() == AssignmentResponse.Status.ok) {
                    if (response != null) {
                        assignedTask = response.getTask();
                    }
                    showInfo("task.successfully.assigned");
                    showAssignedTask(ureq, assignedTask);
                }
            } else if (GTACourseNode.GTASK_ASSIGNEMENT_TYPE_MANUAL.equals(assignmentType)) {
                availableTaskCtrl = new GTAAvailableTaskController(ureq, getWindowControl(), availableTasks, taskList, assessedGroup, assessedIdentity, courseEnv, gtaNode);
                listenTo(availableTaskCtrl);
                mainVC.put("availableTasks", availableTaskCtrl.getInitialComponent());
            }
        }
    } else {
        mainVC.contextPut("assignmentCssClass", "o_done");
        showAssignedTask(ureq, assignedTask);
    }
    return assignedTask;
}
Also used : AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) List(java.util.List) DueDate(org.olat.course.nodes.gta.model.DueDate) Date(java.util.Date) DueDate(org.olat.course.nodes.gta.model.DueDate)

Example 27 with AssignmentResponse

use of org.olat.course.nodes.gta.AssignmentResponse in project OpenOLAT by OpenOLAT.

the class GTAManagerImpl method selectTask.

private AssignmentResponse selectTask(Identity identity, BusinessGroup businessGroup, TaskList tasks, GTACourseNode cNode, File taskFile) {
    Task currentTask;
    if (businessGroup != null) {
        currentTask = getTask(businessGroup, tasks);
    } else {
        currentTask = getTask(identity, tasks);
    }
    AssignmentResponse response;
    if (currentTask == null) {
        String taskName = taskFile.getName();
        TaskList reloadedTasks = loadForUpdate(tasks);
        String sampling = cNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_SAMPLING);
        if (GTACourseNode.GTASK_SAMPLING_UNIQUE.equals(sampling) && isTaskAssigned(reloadedTasks, taskName)) {
            response = new AssignmentResponse(null, Status.alreadyAssigned);
        } else {
            TaskProcess nextStep = nextStep(TaskProcess.assignment, cNode);
            TaskImpl task = createTask(taskName, reloadedTasks, nextStep, businessGroup, identity, cNode);
            task.setAssignmentDate(new Date());
            dbInstance.getCurrentEntityManager().persist(task);
            syncAssessmentEntry(task, cNode, Role.user);
            response = new AssignmentResponse(task, Status.ok);
        }
        dbInstance.commit();
    } else {
        if (currentTask.getTaskStatus() == TaskProcess.assignment) {
            TaskProcess nextStep = nextStep(currentTask.getTaskStatus(), cNode);
            ((TaskImpl) currentTask).setTaskStatus(nextStep);
            if (taskFile != null) {
                ((TaskImpl) currentTask).setTaskName(taskFile.getName());
            }
        }
        currentTask = dbInstance.getCurrentEntityManager().merge(currentTask);
        syncAssessmentEntry((TaskImpl) currentTask, cNode, Role.user);
        response = new AssignmentResponse(currentTask, Status.ok);
    }
    return response;
}
Also used : Task(org.olat.course.nodes.gta.Task) TaskProcess(org.olat.course.nodes.gta.TaskProcess) TaskImpl(org.olat.course.nodes.gta.model.TaskImpl) TaskList(org.olat.course.nodes.gta.TaskList) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) Date(java.util.Date) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) TaskRevisionDate(org.olat.course.nodes.gta.TaskRevisionDate) DueDate(org.olat.course.nodes.gta.model.DueDate)

Example 28 with AssignmentResponse

use of org.olat.course.nodes.gta.AssignmentResponse in project openolat by klemens.

the class GTAManagerTest method isTaskInProcess.

@Test
public void isTaskInProcess() {
    // prepare
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-11");
    RepositoryEntry re = deployGTACourse();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("solo.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select
    AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response);
    Assert.assertNotNull(response.getTask());
    // check
    boolean inProcess = gtaManager.isTaskInProcess(re, node, taskFile.getName());
    Assert.assertTrue(inProcess);
    // check dummy file name which cannot be in process
    boolean notInProcess = gtaManager.isTaskInProcess(re, node, "qwertz");
    Assert.assertFalse(notInProcess);
}
Also used : TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) Test(org.junit.Test)

Example 29 with AssignmentResponse

use of org.olat.course.nodes.gta.AssignmentResponse in project openolat by klemens.

the class GTAManagerTest method deleteAllTaskLists.

@Test
public void deleteAllTaskLists() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-9");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-10");
    dbInstance.commit();
    RepositoryEntry re = deployGTACourse();
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select
    AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response);
    // check that there is tasks
    List<Task> assignedTasks = gtaManager.getTasks(participant, re, node);
    Assert.assertNotNull(assignedTasks);
    Assert.assertEquals(1, assignedTasks.size());
    // delete
    int numOfDeletedObjects = gtaManager.deleteAllTaskLists(re);
    Assert.assertEquals(2, numOfDeletedObjects);
    dbInstance.commitAndCloseSession();
    // check that there isn't any tasks
    List<Task> deletedAssignedTasks = gtaManager.getTasks(participant, re, node);
    Assert.assertNotNull(deletedAssignedTasks);
    Assert.assertEquals(0, deletedAssignedTasks.size());
}
Also used : Task(org.olat.course.nodes.gta.Task) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) Test(org.junit.Test)

Example 30 with AssignmentResponse

use of org.olat.course.nodes.gta.AssignmentResponse in project openolat by klemens.

the class GTAManagerTest method selectTask_identity.

@Test
public void selectTask_identity() {
    // prepare
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    RepositoryEntry re = deployGTACourse();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("solo.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select
    AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    // check
    Assert.assertNotNull(response);
    Assert.assertNotNull(response.getTask());
    Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());
    Task task = response.getTask();
    Assert.assertNotNull(task.getKey());
    Assert.assertNull(task.getBusinessGroup());
    Assert.assertNotNull(task.getCreationDate());
    Assert.assertNotNull(task.getLastModified());
    Assert.assertEquals(tasks, task.getTaskList());
    Assert.assertEquals("solo.txt", task.getTaskName());
    Assert.assertEquals(participant, task.getIdentity());
}
Also used : Task(org.olat.course.nodes.gta.Task) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) Test(org.junit.Test)

Aggregations

AssignmentResponse (org.olat.course.nodes.gta.AssignmentResponse)36 File (java.io.File)32 TaskList (org.olat.course.nodes.gta.TaskList)32 Test (org.junit.Test)28 Identity (org.olat.core.id.Identity)28 GTACourseNode (org.olat.course.nodes.GTACourseNode)28 RepositoryEntry (org.olat.repository.RepositoryEntry)28 Task (org.olat.course.nodes.gta.Task)20 BusinessGroup (org.olat.group.BusinessGroup)12 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 List (java.util.List)6 TaskRevisionDate (org.olat.course.nodes.gta.TaskRevisionDate)6 DueDate (org.olat.course.nodes.gta.model.DueDate)6 Calendar (java.util.Calendar)4 TaskDueDate (org.olat.course.nodes.gta.TaskDueDate)4 TaskProcess (org.olat.course.nodes.gta.TaskProcess)4 TaskImpl (org.olat.course.nodes.gta.model.TaskImpl)4 ReminderRuleImpl (org.olat.modules.reminder.model.ReminderRuleImpl)4