@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));
  }
Example #2
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());
  }
Example #3
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());
  }
Example #4
0
  @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 = 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();
    // 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());
  }
  @Test
  public void testRemoveCoach_withBusinessGroups() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");

    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());

    BusinessGroup businessGroup =
        businessGroupDao.createAndPersist(
            coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(businessGroup, re);

    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();

    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(coach, context, publisherData);
    dbInstance.commitAndCloseSession();

    // remove member and coach as coach of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(coach);
    repositoryManager.removeTutors(owner, removeIdentities, re);

    // wait for the remove of subscription
    waitForCondition(
        new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
    sleep(1000);

    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertFalse(subscribedMember);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
  }
 @Override
 public BusinessGroup getBusinessGroup(KalendarRenderWrapper kalendarRenderWrapper) {
   String caller = kalendarRenderWrapper.getKalendar().getType();
   if (caller.equals(CalendarController.CALLER_COLLAB)
       || caller.equals(CalendarManager.TYPE_GROUP)) {
     Long resId = Long.parseLong(kalendarRenderWrapper.getKalendar().getCalendarID());
     if (resId != null) {
       BusinessGroup businessGroup = businessGroupDao.load(resId);
       if (businessGroup != null) {
         return businessGroup;
       }
     }
   }
   return null;
 }