Search in sources :

Example 16 with AssignmentResponse

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

the class GTAManagerTest method deleteTaskList.

@Test
public void deleteTaskList() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-9");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-10");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(participant, businessGroup, GroupRole.participant.name());
    dbInstance.commit();
    RepositoryEntry re = deployGTACourse();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select
    AssignmentResponse response = gtaManager.selectTask(businessGroup, 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.deleteTaskList(re, node);
    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) BusinessGroup(org.olat.group.BusinessGroup) 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 17 with AssignmentResponse

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

the class GTAReminderRuleTest method submitTask_individual.

@Test
public void submitTask_individual() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = deployGTACourse();
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    Calendar cal = Calendar.getInstance();
    cal.add(2, Calendar.MONTH);
    node.getModuleConfiguration().setDateValue(GTACourseNode.GTASK_SUBMIT_DEADLINE, cal.getTime());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("solo.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select a task
    AssignmentResponse response = gtaManager.selectTask(participant1, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());
    // only remind participant 2
    List<Identity> toRemind = submissionTaskRuleSPI.getPeopleToRemind(re, node);
    Assert.assertEquals(1, toRemind.size());
    Assert.assertTrue(toRemind.contains(participant2));
    {
        // check before 30 days
        ReminderRuleImpl rule = getSubmitTaskRules(30, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 5 weeks
        ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 1 month
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before  90 days
        ReminderRuleImpl rule = getSubmitTaskRules(90, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  12 weeks
        ReminderRuleImpl rule = getSubmitTaskRules(12, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  3 month
        ReminderRuleImpl rule = getSubmitTaskRules(3, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before 1 year
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.year);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Calendar(java.util.Calendar) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) ArrayList(java.util.ArrayList) TaskList(org.olat.course.nodes.gta.TaskList) List(java.util.List) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) Test(org.junit.Test)

Example 18 with AssignmentResponse

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

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 19 with AssignmentResponse

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

the class GTAReminderRuleTest method submitTask_individual.

@Test
public void submitTask_individual() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = deployGTACourse();
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    Calendar cal = Calendar.getInstance();
    cal.add(2, Calendar.MONTH);
    node.getModuleConfiguration().setDateValue(GTACourseNode.GTASK_SUBMIT_DEADLINE, cal.getTime());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("solo.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select a task
    AssignmentResponse response = gtaManager.selectTask(participant1, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());
    // only remind participant 2
    List<Identity> toRemind = submissionTaskRuleSPI.getPeopleToRemind(re, node);
    Assert.assertEquals(1, toRemind.size());
    Assert.assertTrue(toRemind.contains(participant2));
    {
        // check before 30 days
        ReminderRuleImpl rule = getSubmitTaskRules(30, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 5 weeks
        ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 1 month
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before  90 days
        ReminderRuleImpl rule = getSubmitTaskRules(90, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  12 weeks
        ReminderRuleImpl rule = getSubmitTaskRules(12, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  3 month
        ReminderRuleImpl rule = getSubmitTaskRules(3, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before 1 year
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.year);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Calendar(java.util.Calendar) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) ArrayList(java.util.ArrayList) TaskList(org.olat.course.nodes.gta.TaskList) List(java.util.List) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) Test(org.junit.Test)

Example 20 with AssignmentResponse

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

the class GTAManagerTest method selectTask_businessGroup.

@Test
public void selectTask_businessGroup() {
    // prepare
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    dbInstance.commit();
    RepositoryEntry re = deployGTACourse();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select
    AssignmentResponse response = gtaManager.selectTask(businessGroup, 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.getIdentity());
    Assert.assertNotNull(task.getCreationDate());
    Assert.assertNotNull(task.getLastModified());
    Assert.assertEquals(tasks, task.getTaskList());
    Assert.assertEquals("bg.txt", task.getTaskName());
    Assert.assertEquals(businessGroup, task.getBusinessGroup());
}
Also used : Task(org.olat.course.nodes.gta.Task) BusinessGroup(org.olat.group.BusinessGroup) 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