Esempio n. 1
0
  @Test
  public void isTaskInProcess() {
    // prepare
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-11");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    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);
  }
  public GroupAssessmentController(
      UserRequest ureq,
      WindowControl wControl,
      CourseEnvironment courseEnv,
      GTACourseNode courseNode,
      BusinessGroup assessedGroup) {
    super(ureq, wControl, "assessment_per_group");
    this.gtaNode = courseNode;
    this.courseEnv = courseEnv;
    this.assessedGroup = assessedGroup;

    withScore = courseNode.hasScoreConfigured();
    withPassed = courseNode.hasPassedConfigured();
    if (withPassed) {
      cutValue = courseNode.getCutValueConfiguration();
    }
    withComment = courseNode.hasCommentConfigured();

    Roles roles = ureq.getUserSession().getRoles();
    isAdministrativeUser = securityModule.isUserAllowedAdminProps(roles);
    userPropertyHandlers =
        userManager.getUserPropertyHandlersFor(
            GTACoachedGroupGradingController.USER_PROPS_ID, isAdministrativeUser);
    setTranslator(userManager.getPropertyHandlerTranslator(getTranslator()));

    List<IdentityRef> duplicates = gtaManager.getDuplicatedMemberships(courseNode);
    duplicateMemberKeys = new ArrayList<>(duplicates.size());
    for (IdentityRef duplicate : duplicates) {
      duplicateMemberKeys.add(duplicate.getKey());
    }

    initForm(ureq);
    ModelInfos modelInfos = loadModel();
    updateGUI(modelInfos);
  }
Esempio n. 3
0
  @Test
  public void updateTaskName() {
    // create an individual task
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-7");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-8");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList taskList = gtaManager.createIfNotExists(re, node);
    dbInstance.commit();
    Assert.assertNotNull(taskList);

    // select
    gtaManager.selectTask(id1, taskList, node, new File("work_1.txt"));
    gtaManager.selectTask(id2, taskList, node, new File("work_2.txt"));
    dbInstance.commit();

    // change a name
    int rowUpdated = gtaManager.updateTaskName(taskList, "work_1.txt", "changed_work.txt");
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(1, rowUpdated);

    // check
    Task assignedTaskToId1 = gtaManager.getTask(id1, taskList);
    Assert.assertNotNull(assignedTaskToId1);
    Assert.assertEquals("changed_work.txt", assignedTaskToId1.getTaskName());

    List<Task> assignedTaskToId2 = gtaManager.getTasks(id2, re, node);
    Assert.assertNotNull(assignedTaskToId2);
    Assert.assertEquals(1, assignedTaskToId2.size());
    Assert.assertEquals("work_2.txt", assignedTaskToId2.get(0).getTaskName());
  }
Esempio n. 4
0
  /**
   * Create 2 pseudo nodes in a course, and delete the task of the first node and check that the
   * task of second are always there.
   */
  @Test
  public void deleteTaskList_parano() {
    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 = JunitTestHelper.createAndPersistRepositoryEntry("", false);

    // node 1
    GTACourseNode node1 = new GTACourseNode();
    node1.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    TaskList tasks1 = gtaManager.createIfNotExists(re, node1);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks1);
    dbInstance.commit();

    // node 2
    GTACourseNode node2 = new GTACourseNode();
    node2.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    TaskList tasks2 = gtaManager.createIfNotExists(re, node2);
    Assert.assertNotNull(tasks2);
    dbInstance.commit();

    // select node 1
    AssignmentResponse response1 = gtaManager.selectTask(businessGroup, tasks1, node1, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response1);

    // select node 2
    AssignmentResponse response2 = gtaManager.selectTask(businessGroup, tasks2, node2, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response2);

    // check that there is tasks
    List<Task> assignedTasks1 = gtaManager.getTasks(participant, re, node1);
    Assert.assertNotNull(assignedTasks1);
    Assert.assertEquals(1, assignedTasks1.size());

    List<Task> assignedTasks2 = gtaManager.getTasks(participant, re, node2);
    Assert.assertNotNull(assignedTasks2);
    Assert.assertEquals(1, assignedTasks2.size());

    // delete
    int numOfDeletedObjects = gtaManager.deleteTaskList(re, node1);
    Assert.assertEquals(2, numOfDeletedObjects);
    dbInstance.commitAndCloseSession();

    // check that there isn't any tasks in node 1
    List<Task> deletedAssignedTasks = gtaManager.getTasks(participant, re, node1);
    Assert.assertNotNull(deletedAssignedTasks);
    Assert.assertEquals(0, deletedAssignedTasks.size());

    // but always in node 2
    List<Task> notDeletedAssignedTasks2 = gtaManager.getTasks(participant, re, node2);
    Assert.assertNotNull(notDeletedAssignedTasks2);
    Assert.assertEquals(1, notDeletedAssignedTasks2.size());
  }
Esempio n. 5
0
  @Test
  public void createIfNotExists() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    Assert.assertNotNull(node.getIdent());

    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // reload and check
    TaskList reloadedTasks = gtaManager.getTaskList(re, node);
    Assert.assertNotNull(reloadedTasks);
    Assert.assertEquals(tasks, reloadedTasks);
    Assert.assertTrue(reloadedTasks instanceof TaskListImpl);
    TaskListImpl tasksImpl = (TaskListImpl) reloadedTasks;
    Assert.assertNotNull(tasksImpl.getCreationDate());
    Assert.assertNotNull(tasksImpl.getLastModified());
    Assert.assertEquals(re, tasksImpl.getEntry());
    Assert.assertEquals(node.getIdent(), tasksImpl.getCourseNodeIdent());
    dbInstance.commit();

    // check that a second call doesn't create a new task list
    TaskList secondTasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(secondTasks);
    dbInstance.commit();
    Assert.assertEquals(tasks, secondTasks);
  }
Esempio n. 6
0
  @Test
  public void getTasks() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-3");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-4");
    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 = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    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);

    List<Task> assignedTasks = gtaManager.getTasks(participant, re, node);
    Assert.assertNotNull(assignedTasks);
    Assert.assertEquals(1, assignedTasks.size());
  }
Esempio n. 7
0
  @Test
  public void selectTask_identity() {
    // prepare
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    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());
  }
Esempio n. 8
0
  @Test
  public void isTasksInProcess_no() {
    // prepare
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // check
    boolean inProcess = gtaManager.isTasksInProcess(re, node);
    Assert.assertFalse(inProcess);
  }
Esempio n. 9
0
  @Test
  public void assignTask_businessGroup() {
    // prepare
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-3");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-4");
    Identity participant3 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-5");
    Identity participant4 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-6");

    BusinessGroup businessGroup1 =
        businessGroupDao.createAndPersist(
            coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    BusinessGroup businessGroup2 =
        businessGroupDao.createAndPersist(
            coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);

    businessGroupRelationDao.addRole(participant1, businessGroup1, GroupRole.participant.name());
    businessGroupRelationDao.addRole(participant2, businessGroup1, GroupRole.participant.name());
    businessGroupRelationDao.addRole(participant3, businessGroup2, GroupRole.participant.name());
    businessGroupRelationDao.addRole(participant4, businessGroup2, GroupRole.participant.name());
    dbInstance.commit();

    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    businessGroupRelationDao.addRelationToResource(businessGroup1, re);
    businessGroupRelationDao.addRelationToResource(businessGroup2, re);

    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    List<Long> groupKeys = new ArrayList<>(2);
    groupKeys.add(businessGroup1.getKey());
    groupKeys.add(businessGroup2.getKey());
    node.getModuleConfiguration().setList(GTACourseNode.GTASK_GROUPS, groupKeys);
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // group 1 select a task
    AssignmentResponse response = gtaManager.selectTask(businessGroup1, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());

    // only remind group 2
    List<Identity> toRemind = assignTaskRuleSPI.getPeopleToRemind(re, node);
    Assert.assertEquals(2, toRemind.size());
    Assert.assertTrue(toRemind.contains(participant3));
    Assert.assertTrue(toRemind.contains(participant4));
  }
  private void updateGUI(ModelInfos modelInfos) {
    if (modelInfos.isSame()) {
      applyToAllEl.select(onKeys[0], true);
      table.setVisible(false);

      if (groupPassedEl != null) {
        groupPassedEl.setVisible(true);
        Boolean passed = modelInfos.getPassed();
        groupPassedEl.select(onKeys[0], passed != null && passed.booleanValue());
      }
      if (groupScoreEl != null) {
        groupScoreEl.setVisible(true);
        Float score = modelInfos.getScore();
        if (score != null) {
          String scoreVal = AssessmentHelper.getRoundedScore(score);
          groupScoreEl.setValue(scoreVal);
        } else {
          groupScoreEl.setValue("");
        }
      }
      if (groupCommentEl != null) {
        groupCommentEl.setVisible(true);
        String comment = modelInfos.getComment();
        if (comment != null) {
          groupCommentEl.setValue(comment);
        }
      }
    } else {
      applyToAllEl.select(onKeys[0], false);
      table.setVisible(true);
      if (groupPassedEl != null) {
        groupPassedEl.setVisible(false);
      }
      if (groupScoreEl != null) {
        groupScoreEl.setVisible(false);
      }
      if (groupCommentEl != null) {
        groupCommentEl.setVisible(false);
      }
    }

    if (StringHelper.containsNonWhitespace(modelInfos.getDuplicates())) {
      String warning =
          translate(
              "error.duplicate.memberships",
              new String[] {gtaNode.getShortTitle(), modelInfos.getDuplicates()});
      flc.contextPut("duplicateWarning", warning);
    } else {
      flc.contextRemove("duplicateWarning");
    }
  }
Esempio n. 11
0
  @Test
  public void deleteAllTaskLists() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-9");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-10");
    dbInstance.commit();
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());

    GTACourseNode node = new GTACourseNode();
    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());
  }
Esempio n. 12
0
  @Test
  public void isTaskAssigned() {
    // create an individual task
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-6");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    dbInstance.commit();
    Assert.assertNotNull(tasks);

    // select
    File taskFile = new File("bg.txt");
    AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile);
    Assert.assertNotNull(response);
    Assert.assertEquals(Status.ok, response.getStatus());

    // check is assigned
    boolean assigned = gtaManager.isTaskAssigned(tasks, taskFile.getName());
    Assert.assertTrue(assigned);
    boolean notAssigned = gtaManager.isTaskAssigned(tasks, "noise.txt");
    Assert.assertFalse(notAssigned);
  }
Esempio n. 13
0
  @Test
  public void getAssignedTasks() {
    // create an individual task
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-7");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-8");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList taskList = gtaManager.createIfNotExists(re, node);
    dbInstance.commit();
    Assert.assertNotNull(taskList);

    // select
    gtaManager.selectTask(id1, taskList, node, new File("work_1.txt"));
    gtaManager.selectTask(id2, taskList, node, new File("work_2.txt"));

    // get assigned tasks
    List<String> assigned = gtaManager.getAssignedTasks(taskList);
    Assert.assertNotNull(assigned);
    Assert.assertEquals(2, assigned.size());
    Assert.assertTrue(assigned.contains("work_1.txt"));
    Assert.assertTrue(assigned.contains("work_2.txt"));
  }
Esempio n. 14
0
  @Test
  public void assignTask_relativeToInitialLaunchDate() {
    // create a course with 3 members
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("initial-launch-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("initial-launch-2");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("initial-launch-3");

    ICourse course =
        CoursesWebService.createEmptyCourse(null, "initial-launch-dates", "course long name", null);
    RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(id2, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(id3, re, GroupRoles.participant.name());
    dbInstance.commit();

    // create user course infos
    Long courseResId = course.getCourseEnvironment().getCourseResourceableId();
    userCourseInformationsManager.updateUserCourseInformations(re.getOlatResource(), id1);
    userCourseInformationsManager.updateUserCourseInformations(re.getOlatResource(), id2);
    userCourseInformationsManager.updateUserCourseInformations(re.getOlatResource(), id3);
    dbInstance.commit();

    // fake the date
    updateInitialLaunchDate(courseResId, id1, -5, Calendar.DATE);
    updateInitialLaunchDate(courseResId, id2, -35, Calendar.DATE);
    updateInitialLaunchDate(courseResId, id3, -75, Calendar.DATE);
    dbInstance.commitAndCloseSession();

    // create a fake node
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    node.getModuleConfiguration().setBooleanEntry(GTACourseNode.GTASK_RELATIVE_DATES, true);
    node.getModuleConfiguration().setIntValue(GTACourseNode.GTASK_ASSIGNMENT_DEADLINE_RELATIVE, 40);
    node.getModuleConfiguration()
        .setStringValue(
            GTACourseNode.GTASK_ASSIGNMENT_DEADLINE_RELATIVE_TO,
            GTARelativeToDates.courseLaunch.name());

    // need the task list
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    { // check 3 days
      ReminderRuleImpl rule = getAssignedTaskRules(3, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(all.contains(id3));
    }

    { // check 5 days
      ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(id2));
      Assert.assertTrue(all.contains(id3));
    }

    { // check 1 week
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.week);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(id2));
      Assert.assertTrue(all.contains(id3));
    }

    { // check 1 month
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.month);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(id2));
      Assert.assertTrue(all.contains(id3));
    }

    { // check 2 month
      ReminderRuleImpl rule = getAssignedTaskRules(2, LaunchUnit.month);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(3, all.size());
      Assert.assertTrue(all.contains(id1));
      Assert.assertTrue(all.contains(id2));
      Assert.assertTrue(all.contains(id3));
    }
  }
Esempio n. 15
0
  /**
   * Create 2 pseudo courses in a course, and delete the task of the first course and check that the
   * task of second are always there.
   */
  @Test
  public void deleteAllTaskLists_parano() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-20");
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-21");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-22");

    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(coach, re1, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant1, re1, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re1, GroupRoles.participant.name());

    // course 1
    GTACourseNode node1 = new GTACourseNode();
    node1
        .getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks1 = gtaManager.createIfNotExists(re1, node1);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks1);
    dbInstance.commit();

    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(coach, re2, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant1, re2, GroupRoles.participant.name());

    // participant 2 course 2
    GTACourseNode node2 = new GTACourseNode();
    node2
        .getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks2 = gtaManager.createIfNotExists(re2, node2);
    Assert.assertNotNull(tasks2);
    dbInstance.commit();

    // participant 1 and 2 select course 1
    AssignmentResponse response1_1 = gtaManager.selectTask(participant1, tasks1, node1, taskFile);
    AssignmentResponse response1_2 = gtaManager.selectTask(participant2, tasks1, node1, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response1_1);
    Assert.assertNotNull(response1_2);

    // participant 2 select node 2
    AssignmentResponse response2_2 = gtaManager.selectTask(participant2, tasks2, node2, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response2_2);

    // check that there is tasks
    List<Task> assignedTasks1_1 = gtaManager.getTasks(participant1, re1, node1);
    Assert.assertNotNull(assignedTasks1_1);
    Assert.assertEquals(1, assignedTasks1_1.size());

    List<Task> assignedTasks1_2 = gtaManager.getTasks(participant2, re1, node1);
    Assert.assertNotNull(assignedTasks1_2);
    Assert.assertEquals(1, assignedTasks1_2.size());

    List<Task> assignedTasks2_2 = gtaManager.getTasks(participant2, re2, node2);
    Assert.assertNotNull(assignedTasks2_2);
    Assert.assertEquals(1, assignedTasks2_2.size());

    // delete
    int numOfDeletedObjects = gtaManager.deleteAllTaskLists(re1);
    Assert.assertEquals(3, numOfDeletedObjects);
    dbInstance.commitAndCloseSession();

    // check that there isn't any tasks in node 1
    List<Task> deletedAssignedTasks1_1 = gtaManager.getTasks(participant1, re1, node1);
    Assert.assertNotNull(deletedAssignedTasks1_1);
    Assert.assertEquals(0, deletedAssignedTasks1_1.size());

    List<Task> deletedAssignedTasks1_2 = gtaManager.getTasks(participant2, re1, node1);
    Assert.assertNotNull(deletedAssignedTasks1_2);
    Assert.assertEquals(0, deletedAssignedTasks1_2.size());

    // but always in node 2
    List<Task> notDeletedAssignedTasks2_2 = gtaManager.getTasks(participant2, re2, node2);
    Assert.assertNotNull(notDeletedAssignedTasks2_2);
    Assert.assertEquals(1, notDeletedAssignedTasks2_2.size());
  }
Esempio n. 16
0
  @Test
  public void submitTask_relativeLifecycle() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();

    String label = "Life cycle for relative date";
    String softKey = UUID.randomUUID().toString();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -5);
    Date from = cal.getTime();
    cal.add(Calendar.DATE, 20);
    Date to = cal.getTime();
    RepositoryEntryLifecycle lifecycle = reLifeCycleDao.create(label, softKey, true, from, to);
    re.setLifecycle(lifecycle);
    re = dbInstance.getCurrentEntityManager().merge(re);
    dbInstance.commit();

    // create a fake node with a relative submit deadline 15 days after the start of the course
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    node.getModuleConfiguration().setBooleanEntry(GTACourseNode.GTASK_RELATIVE_DATES, true);
    node.getModuleConfiguration().setIntValue(GTACourseNode.GTASK_SUBMIT_DEADLINE_RELATIVE, 15);
    node.getModuleConfiguration()
        .setStringValue(
            GTACourseNode.GTASK_SUBMIT_DEADLINE_RELATIVE_TO, GTARelativeToDates.courseStart.name());

    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commitAndCloseSession();

    // the course has start 5 days before, deadline is 15 days after it
    // conclusion the deadline is 10 days from now

    { // check before 5 days
      ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.day);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(0, all.size());
    }

    { // check before 1 week
      ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.week);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(0, all.size());
    }

    { // check before 10 days
      ReminderRuleImpl rule = getSubmitTaskRules(10, LaunchUnit.day);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }

    { // check before 2 days
      ReminderRuleImpl rule = getSubmitTaskRules(10, LaunchUnit.week);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }

    { // check before 30 days
      ReminderRuleImpl rule = getSubmitTaskRules(30, LaunchUnit.day);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }

    { // check before 1 months
      ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.month);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }

    { // check before 5 months
      ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.month);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }

    { // check before 1 year
      ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.year);
      List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }
  }
Esempio n. 17
0
  @Test
  public void assignTask_individual() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();

    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());

    Calendar cal = Calendar.getInstance();
    cal.add(2, Calendar.MONTH);
    node.getModuleConfiguration()
        .setDateValue(GTACourseNode.GTASK_ASSIGNMENT_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 = assignTaskRuleSPI.getPeopleToRemind(re, node);
    Assert.assertEquals(1, toRemind.size());
    Assert.assertTrue(toRemind.contains(participant2));

    { // check before 30 days
      ReminderRuleImpl rule = getAssignedTaskRules(30, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(0, all.size());
    }

    { // check before 5 weeks
      ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.week);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(0, all.size());
    }

    { // check before 1 month
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.month);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(0, all.size());
    }

    { // check before  90 days
      ReminderRuleImpl rule = getAssignedTaskRules(90, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(toRemind.contains(participant2));
    }

    { // check before  12 weeks
      ReminderRuleImpl rule = getAssignedTaskRules(12, LaunchUnit.week);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(toRemind.contains(participant2));
    }

    { // check before  3 month
      ReminderRuleImpl rule = getAssignedTaskRules(3, LaunchUnit.month);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(toRemind.contains(participant2));
    }

    { // check before 1 year
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.year);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(toRemind.contains(participant2));
    }
  }
  /** @return True if all results are the same */
  private ModelInfos loadModel() {
    // load participants, load datas
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseResourceableId());
    List<Identity> identities =
        businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());

    Map<Identity, AssessmentEntry> identityToEntryMap = new HashMap<>();
    List<AssessmentEntry> entries =
        course
            .getCourseEnvironment()
            .getAssessmentManager()
            .getAssessmentEntries(assessedGroup, gtaNode);
    for (AssessmentEntry entry : entries) {
      identityToEntryMap.put(entry.getIdentity(), entry);
    }

    int count = 0;
    boolean same = true;
    StringBuilder duplicateWarning = new StringBuilder();
    Float scoreRef = null;
    Boolean passedRef = null;
    String commentRef = null;

    List<AssessmentRow> rows = new ArrayList<>(identities.size());
    for (Identity identity : identities) {
      AssessmentEntry entry = identityToEntryMap.get(identity);

      ScoreEvaluation scoreEval = null;
      if (withScore || withPassed) {
        scoreEval = gtaNode.getUserScoreEvaluation(entry);
        if (scoreEval == null) {
          scoreEval = ScoreEvaluation.EMPTY_EVALUATION;
        }
      }

      String comment = null;
      if (withComment && entry != null) {
        comment = entry.getComment();
      }

      boolean duplicate = duplicateMemberKeys.contains(identity.getKey());
      if (duplicate) {
        if (duplicateWarning.length() > 0) duplicateWarning.append(", ");
        duplicateWarning.append(StringHelper.escapeHtml(userManager.getUserDisplayName(identity)));
      }

      AssessmentRow row = new AssessmentRow(identity, duplicate);
      rows.add(row);

      if (withScore) {
        Float score = scoreEval.getScore();
        String pointVal = AssessmentHelper.getRoundedScore(score);
        TextElement pointEl = uifactory.addTextElement("point" + count, null, 5, pointVal, flc);
        pointEl.setDisplaySize(5);
        row.setScoreEl(pointEl);
        if (count == 0) {
          scoreRef = score;
        } else if (!same(scoreRef, score)) {
          same = false;
        }
      }

      if (withPassed && cutValue == null) {
        Boolean passed = scoreEval.getPassed();
        MultipleSelectionElement passedEl =
            uifactory.addCheckboxesHorizontal("check" + count, null, flc, onKeys, onValues);
        if (passed != null && passed.booleanValue()) {
          passedEl.select(onKeys[0], passed.booleanValue());
        }
        row.setPassedEl(passedEl);
        if (count == 0) {
          passedRef = passed;
        } else if (!same(passedRef, passed)) {
          same = false;
        }
      }

      if (withComment) {
        FormLink commentLink =
            uifactory.addFormLink(
                "comment-" + CodeHelper.getRAMUniqueID(),
                "comment",
                "comment",
                null,
                flc,
                Link.LINK);
        if (StringHelper.containsNonWhitespace(comment)) {
          commentLink.setIconLeftCSS("o_icon o_icon_comments");
        } else {
          commentLink.setIconLeftCSS("o_icon o_icon_comments_none");
        }
        commentLink.setUserObject(row);
        row.setComment(comment);
        row.setCommentEditLink(commentLink);

        if (count == 0) {
          commentRef = comment;
        } else if (!same(commentRef, comment)) {
          same = false;
        }
      }

      count++;
    }

    model.setObjects(rows);
    table.reset();

    return new ModelInfos(same, scoreRef, passedRef, commentRef, duplicateWarning.toString());
  }
Esempio n. 19
0
  @Test
  public void assignTask_relativeToDateEnrollment() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    addEnrollmentDate(re, participant1, GroupRoles.participant, -12, Calendar.DATE);
    addEnrollmentDate(re, participant2, GroupRoles.participant, -5, Calendar.DATE);
    dbInstance.commit();

    // create a fake node
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    node.getModuleConfiguration().setBooleanEntry(GTACourseNode.GTASK_RELATIVE_DATES, true);
    node.getModuleConfiguration().setIntValue(GTACourseNode.GTASK_ASSIGNMENT_DEADLINE_RELATIVE, 15);
    node.getModuleConfiguration()
        .setStringValue(
            GTACourseNode.GTASK_ASSIGNMENT_DEADLINE_RELATIVE_TO,
            GTARelativeToDates.enrollment.name());

    // need the task list
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // participant 1 has still 3 days to choose a task
    // participant 2 has still 10 days to choose a task

    { // check before 1 day
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(0, all.size());
    }

    { // check before 5 days
      ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(all.contains(participant1));
    }

    { // check before 1 week
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.week);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(all.contains(participant1));
    }

    { // check before 1 month
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.month);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }
  }
  private void applyChanges(boolean setAsDone) {
    List<AssessmentRow> rows = model.getObjects();
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseResourceableId());
    if (applyToAllEl.isAtLeastSelected(1)) {
      Float score = null;

      if (withScore) {
        String scoreValue = groupScoreEl.getValue();
        if (StringHelper.containsNonWhitespace(scoreValue)) {
          score = Float.parseFloat(scoreValue);
        }
      }

      Boolean passed = null;
      if (withPassed) {
        if (cutValue == null) {
          passed = groupPassedEl.isSelected(0);
        } else if (score != null) {
          passed = (score.floatValue() >= cutValue.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
        }
      }

      for (AssessmentRow row : rows) {
        UserCourseEnvironment userCourseEnv = row.getUserCourseEnvironment(course);
        ScoreEvaluation newScoreEval;
        if (setAsDone) {
          newScoreEval = new ScoreEvaluation(score, passed, AssessmentEntryStatus.done, true, null);
        } else {
          newScoreEval = new ScoreEvaluation(score, passed);
        }
        gtaNode.updateUserScoreEvaluation(newScoreEval, userCourseEnv, getIdentity(), false);
      }

      if (withComment) {
        String comment = groupCommentEl.getValue();
        if (StringHelper.containsNonWhitespace(comment)) {
          for (AssessmentRow row : rows) {
            UserCourseEnvironment userCourseEnv = row.getUserCourseEnvironment(course);
            gtaNode.updateUserUserComment(comment, userCourseEnv, getIdentity());
          }
        }
      }

    } else {
      for (AssessmentRow row : rows) {
        UserCourseEnvironment userCourseEnv = row.getUserCourseEnvironment(course);

        Float score = null;
        if (withScore) {
          String value = row.getScoreEl().getValue();
          if (StringHelper.containsNonWhitespace(value)) {
            score = Float.parseFloat(value);
          }
        }

        Boolean passed = null;
        if (withPassed) {
          if (cutValue == null) {
            passed = row.getPassedEl().isSelected(0);
          } else if (score != null) {
            passed = (score.floatValue() >= cutValue.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
          }
        }

        ScoreEvaluation newScoreEval;
        if (setAsDone) {
          newScoreEval = new ScoreEvaluation(score, passed, AssessmentEntryStatus.done, true, null);
        } else {
          newScoreEval = new ScoreEvaluation(score, passed);
        }
        gtaNode.updateUserScoreEvaluation(newScoreEval, userCourseEnv, getIdentity(), false);

        if (withComment) {
          String comment = row.getComment();
          if (StringHelper.containsNonWhitespace(comment)) {
            gtaNode.updateUserUserComment(comment, userCourseEnv, getIdentity());
          }
        }
      }
    }
  }