@Test
  public void removePolicyWithInvitation() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Remove policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    // invitation
    final Invitation invitation = securityManager.createAndPersistInvitation();
    invitation.setFirstName("John");
    invitation.setLastName("Doe");
    invitation.setMail("*****@*****.**");
    final EPMapPolicy invitationPolicy = new EPMapPolicy();
    invitationPolicy.setType(Type.invitation);
    invitationPolicy.setInvitation(invitation);
    policies.add(invitationPolicy);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // remove the policy
    policies.clear();
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check if the policies and the invitation are deleted
    final List<EPMapPolicy> deletedPolicies = epFrontendManager.getMapPolicies(map);
    assertNotNull(deletedPolicies);
    assertTrue(deletedPolicies.isEmpty());
  }
  @Test
  public void allUserPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (no policy)
    assertFalse(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check not visible (no policy)
    assertFalse(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));

    // add all user policy
    final EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.allusers);
    epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
    dbInstance.commitAndCloseSession();

    // one policy
    final List<EPMapPolicy> policies1 = epFrontendManager.getMapPolicies(map);
    assertEquals(1, policies1.size());

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (is user)
    assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check not visible (is user)
    assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
  }
예제 #3
0
  /** testUserInsertFindDelete */
  @Test
  public void testUserInsertFindDelete() {
    // create identity and property
    Identity id =
        JunitTestHelper.createAndPersistIdentityAsUser("user-prop-" + UUID.randomUUID().toString());
    Property p =
        pm.createUserPropertyInstance(
            id,
            "catuser",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    p = pm.findUserProperty(id, "catuser", "TestProperty");
    assertNotNull(p);
    assertEquals(p.getStringValue(), "stringValue");
    assertEquals(p.getFloatValue(), new Float(1.1));
    assertEquals(p.getTextValue(), "textValue");

    pm.deleteProperty(p);
    p = pm.findUserProperty(id, "catuser", "TestProperty");
    assertNull(p);
    dbInstance.commitAndCloseSession();
  }
예제 #4
0
  /** testGetAllResourceTypeNames */
  @Test
  public void testGetAllResourceTypeNames() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-3-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    // create a property
    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "catall",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    Assert.assertNotNull(p.getResourceTypeName());
    List<String> resTypeNames = pm.getAllResourceTypeNames();
    assertTrue(resTypeNames.contains(ores.getResourceableTypeName()));
  }
예제 #5
0
  @Test
  public void searchOwnedBinders() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("binder-owner-");
    Binder binder =
        portfolioService.createNewBinder("Binder 2", "Binder with one section.", null, owner);
    dbInstance.commitAndCloseSession();
    portfolioService.appendNewSection("First section", "My first section.", null, null, binder);
    dbInstance.commitAndCloseSession();
    portfolioService.appendNewSection("Second section", "My second section.", null, null, binder);
    dbInstance.commitAndCloseSession();

    List<Section> sections = portfolioService.getSections(binder);
    for (int i = 0; i < 2; i++) {
      Section section = sections.get(1);
      portfolioService.appendNewPage(owner, "Page-1-" + i, "", null, null, section);
      portfolioService.appendNewPage(owner, "Page-2-" + i, "", null, null, section);
    }

    List<BinderStatistics> rows = portfolioService.searchOwnedBinders(owner);
    Assert.assertNotNull(rows);
    Assert.assertEquals(1, rows.size());

    BinderStatistics myBinder = rows.get(0);
    Assert.assertEquals(2, myBinder.getNumOfSections());
    Assert.assertEquals(4, myBinder.getNumOfPages());
  }
예제 #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());
  }
예제 #7
0
  @Test
  public void deleteBinder() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("del-binder-");
    Binder binder = portfolioService.createNewBinder("Binder to delete", "Deletion", "", owner);
    SectionRef sectionRef1 =
        portfolioService.appendNewSection("1. section ", "Section 1", null, null, binder);
    dbInstance.commit();
    SectionRef sectionRef2 =
        portfolioService.appendNewSection("2. section ", "Section 2", null, null, binder);
    dbInstance.commit();
    portfolioService.updateBinderUserInformations(binder, owner);
    dbInstance.commit();

    Section reloadedSection1 = portfolioService.getSection(sectionRef1);
    Page page1 =
        portfolioService.appendNewPage(
            owner, "New page", "A brand new page.", null, null, reloadedSection1);
    Section reloadedSection2 = portfolioService.getSection(sectionRef2);
    Page page2 =
        portfolioService.appendNewPage(
            owner, "New page", "A brand new page.", null, null, reloadedSection2);
    Assert.assertNotNull(page1);
    Assert.assertNotNull(page2);
    dbInstance.commitAndCloseSession();

    // delete
    boolean deleted = portfolioService.deleteBinder(binder);
    dbInstance.commit();
    Assert.assertTrue(deleted);
  }
예제 #8
0
  @Test
  public void binderAndSectionAndPageAccessRights_byIdentity() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-5");
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-6");
    String title = "My published binder";
    String summary = "My live";
    Binder binder = portfolioService.createNewBinder(title, summary, null, owner);
    dbInstance.commit();
    portfolioService.appendNewSection("Section", "Coached section", null, null, binder);
    dbInstance.commit();
    List<Section> sections = portfolioService.getSections(binder);
    Section section = sections.get(0);
    portfolioService.appendNewPage(owner, "Reviewed page", "", null, null, section);
    portfolioService.addAccessRights(section, identity, PortfolioRoles.coach);

    dbInstance.commit();
    List<Page> pages = portfolioService.getPages(section);
    Page page = pages.get(0);
    portfolioService.addAccessRights(page, identity, PortfolioRoles.reviewer);

    // load right
    List<AccessRights> rights = portfolioService.getAccessRights(binder, identity);
    Assert.assertNotNull(rights);
    Assert.assertEquals(2, rights.size());
  }
예제 #9
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());
  }
예제 #10
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);
  }
예제 #11
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);
  }
  @Override
  public AssessmentMode merge(AssessmentMode assessmentMode, boolean forceStatus) {
    assessmentMode.setLastModified(new Date());

    // update begin with lead time
    Date begin = assessmentMode.getBegin();
    Date beginWithLeadTime = evaluateLeadTime(begin, assessmentMode.getLeadTime());
    ((AssessmentModeImpl) assessmentMode).setBeginWithLeadTime(beginWithLeadTime);

    Date end = assessmentMode.getEnd();
    Date endWithFollowupTime = evaluateFollowupTime(end, assessmentMode.getFollowupTime());
    ((AssessmentModeImpl) assessmentMode).setEndWithFollowupTime(endWithFollowupTime);

    AssessmentMode reloadedMode;
    if (assessmentMode.getKey() == null) {
      dbInstance.getCurrentEntityManager().persist(assessmentMode);
      reloadedMode = assessmentMode;
    } else {
      reloadedMode = dbInstance.getCurrentEntityManager().merge(assessmentMode);
    }
    dbInstance.commit();
    if (reloadedMode.isManualBeginEnd()) {
      reloadedMode =
          assessmentModeCoordinationService.syncManuallySetStatus(reloadedMode, forceStatus);
    } else {
      reloadedMode = assessmentModeCoordinationService.syncAutomicallySetStatus(reloadedMode);
    }
    return reloadedMode;
  }
예제 #13
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());
  }
  @Test
  public void isTemplateInUse() {
    // create the template owned by ident1
    final PortfolioStructureMap template =
        epStructureManager.createPortfolioMapTemplate(
            ident1, "Template in user", "Template in use");
    dbInstance.saveObject(template);
    dbInstance.commitAndCloseSession();
    // add a page to it
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // check: the template is not in use
    assertFalse(epFrontendManager.isTemplateInUse(template, null, null, null));

    // use the template: assign the template to ident2
    final PortfolioStructureMap map =
        epFrontendManager.assignStructuredMapToUser(ident2, template, null, null, null, null);
    assertNotNull(map);
    dbInstance.commitAndCloseSession();

    // check: the template is in use
    assertTrue(epFrontendManager.isTemplateInUse(template, null, null, null));
  }
예제 #15
0
  @Test
  public void testReentrantLock() {
    long start = System.currentTimeMillis();
    String asset = "p1";
    // make sure the lock is created first
    PLock pc = pessimisticLockManager.findOrPersistPLock(asset);
    assertNotNull(pc);
    dbInstance.closeSession();

    // test double acquisition within same transaction
    PLock pc1 = pessimisticLockManager.findOrPersistPLock(asset);
    assertNotNull(pc1);
    PLock pc2 = pessimisticLockManager.findOrPersistPLock(asset);
    assertNotNull(pc2);
    dbInstance.closeSession();

    // and without explicit transaction boundary.
    PLock p1 = pessimisticLockManager.findOrPersistPLock(asset);
    assertNotNull(p1);
    PLock p2 = pessimisticLockManager.findOrPersistPLock(asset);
    assertNotNull(p2);
    long stop = System.currentTimeMillis();
    long diff = stop - start;
    assertTrue(
        "5 select's took longer than 10 seconds -> deadlock / lock timeout ? dur in ms was:" + diff,
        diff < 10000);
  }
  public void deleteLifecycle(RepositoryEntryLifecycle lifecycle) {
    RepositoryEntryLifecycle reloadedLifecycle =
        dbInstance
            .getCurrentEntityManager()
            .getReference(RepositoryEntryLifecycle.class, lifecycle.getKey());

    dbInstance.getCurrentEntityManager().remove(reloadedLifecycle);
  }
예제 #17
0
 private void updateInitialLaunchDate(Long courseResId, Identity id, int amount, int field) {
   UserCourseInfosImpl userCourseInfos =
       (UserCourseInfosImpl)
           userCourseInformationsManager.getUserCourseInformations(courseResId, id);
   Date initialLaunch = userCourseInfos.getInitialLaunch();
   Calendar cal = Calendar.getInstance();
   cal.setTime(initialLaunch);
   cal.add(field, amount);
   userCourseInfos.setInitialLaunch(cal.getTime());
   dbInstance.getCurrentEntityManager().merge(userCourseInfos);
   dbInstance.commit();
 }
  /** Same workflow as the repository. This workflow is pretty critical. */
  @Test
  public void isStructuredMapOwner() {
    final OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();

    // create a repository entry
    final RepositoryEntry addedEntry =
        repositoryManager.createRepositoryEntryInstance(ident1.getName());

    addedEntry.setCanDownload(false);
    addedEntry.setCanLaunch(true);
    addedEntry.setDisplayname("test repo");
    addedEntry.setResourcename("-");
    addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);

    // Set the resource on the repository entry and save the entry.
    final OLATResource ores = resourceManager.findOrPersistResourceable(resource);
    addedEntry.setOlatResource(ores);

    // create security group
    final SecurityGroup newGroup = securityManager.createAndPersistSecurityGroup();
    securityManager.createAndPersistPolicy(newGroup, Constants.PERMISSION_ACCESS, newGroup);
    securityManager.createAndPersistPolicy(
        newGroup, Constants.PERMISSION_HASROLE, EPStructureManager.ORES_MAPOWNER);
    securityManager.addIdentityToSecurityGroup(ident1, newGroup);
    addedEntry.setOwnerGroup(newGroup);

    repositoryManager.saveRepositoryEntry(addedEntry);
    dbInstance.commitAndCloseSession();

    // create the template owned by ident1
    final PortfolioStructureMap template =
        epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
    assertNotNull(page1);

    dbInstance.commitAndCloseSession();

    // assign the template to ident2
    final PortfolioStructureMap map =
        epFrontendManager.assignStructuredMapToUser(ident2, template, null, null, null, null);
    assertNotNull(map);
    dbInstance.commitAndCloseSession();

    // check if ident2 is owner of the map
    assertTrue(epFrontendManager.isMapOwner(ident2, map.getOlatResource()));
    // check if ident1 is not the owner of the map
    assertFalse(epFrontendManager.isMapOwner(ident1, map.getOlatResource()));
    // check if ident1 is owner of the template
    assertTrue(epFrontendManager.isMapOwner(ident1, template.getOlatResource()));
  }
  @Test
  public void mergeTwoUserPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Remove policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    // first user policy
    final EPMapPolicy userPolicy1 = new EPMapPolicy();
    userPolicy1.setType(Type.user);
    userPolicy1.getIdentities().add(ident2);
    userPolicy1.getIdentities().add(ident3);
    policies.add(userPolicy1);
    // second user policy
    final EPMapPolicy userPolicy2 = new EPMapPolicy();
    userPolicy2.setType(Type.user);
    userPolicy2.getIdentities().add(ident1);
    policies.add(userPolicy2);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check if the policies are correctly merged
    final List<EPMapPolicy> mergedPolicies = epFrontendManager.getMapPolicies(map);
    assertNotNull(mergedPolicies);
    assertEquals(1, mergedPolicies.size());

    final EPMapPolicy mergedPolicy = mergedPolicies.get(0);
    final List<Identity> identities = mergedPolicy.getIdentities();
    assertEquals(3, identities.size());

    int count1, count2, count3;
    count1 = count2 = count3 = 0;
    for (final Identity identity : identities) {
      if (identity.equalsByPersistableKey(ident1)) {
        count1++;
      } else if (identity.equalsByPersistableKey(ident2)) {
        count2++;
      } else if (identity.equalsByPersistableKey(ident3)) {
        count3++;
      }
    }
    assertEquals(1, count1);
    assertEquals(1, count2);
    assertEquals(1, count3);
  }
  @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);
  }
예제 #21
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));
  }
예제 #22
0
  /**
   * Deletes all Results and ResultSets of a test, selftest or survey
   *
   * @param olatRes
   * @param olatResDet
   * @param repRef
   * @return deleted ResultSets
   */
  public int deleteAllResults(Long olatRes, String olatResDet, Long repRef) {
    StringBuilder sb = new StringBuilder();
    sb.append("select rset from ").append(QTIResultSet.class.getName()).append(" as rset ");
    sb.append(
        " where rset.olatResource=:resId and rset.olatResourceDetail=:resSubPath and rset.repositoryRef=:repoKey ");

    EntityManager em = dbInstance.getCurrentEntityManager();
    List<QTIResultSet> sets =
        em.createQuery(sb.toString(), QTIResultSet.class)
            .setParameter("resId", olatRes)
            .setParameter("resSubPath", olatResDet)
            .setParameter("repoKey", repRef)
            .getResultList();

    StringBuilder delSb = new StringBuilder();
    delSb
        .append("delete from ")
        .append(QTIResult.class.getName())
        .append(" as res where res.resultSet.key=:setKey");
    Query delResults = em.createQuery(delSb.toString());
    for (QTIResultSet set : sets) {
      delResults.setParameter("setKey", set.getKey()).executeUpdate();
      em.remove(set);
    }
    return sets.size();
  }
  @Override
  public AssessmentMode persist(AssessmentMode assessmentMode) {
    assessmentMode.setLastModified(new Date());

    // update begin with lead time
    Date begin = assessmentMode.getBegin();
    Date beginWithLeadTime = evaluateLeadTime(begin, assessmentMode.getLeadTime());
    ((AssessmentModeImpl) assessmentMode).setBeginWithLeadTime(beginWithLeadTime);
    Date end = assessmentMode.getEnd();
    Date endWithFollowupTime = this.evaluateFollowupTime(end, assessmentMode.getFollowupTime());
    ((AssessmentModeImpl) assessmentMode).setEndWithFollowupTime(endWithFollowupTime);

    dbInstance.getCurrentEntityManager().persist(assessmentMode);
    dbInstance.commit();
    return assessmentMode;
  }
예제 #24
0
  @Test
  public void isTemplateInUse() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-9");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // assign a template
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    Binder template = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
    dbInstance.commit();
    Assert.assertNotNull(template);

    boolean inUse = portfolioService.isTemplateInUse(templateBinder, templateEntry, null);
    Assert.assertTrue(inUse);
  }
  @Test
  public void createAndLoadRepositoryEntry() {
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-1");

    String displayName = "Service test 2";
    String resourceName = "ServiceTest";
    String description = "Test the brand new service";
    RepositoryEntry re =
        repositoryService.create(
            initialAuthor, null, resourceName, displayName, description, null, 0);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(re);

    RepositoryEntry loadedEntry = repositoryService.loadByKey(re.getKey());
    Assert.assertNotNull(loadedEntry);
    Assert.assertNotNull(re.getCreationDate());
    Assert.assertNotNull(re.getLastModified());
    Assert.assertNotNull(re.getOlatResource());
    Assert.assertNotNull(loadedEntry.getGroups());
    Assert.assertEquals(1, loadedEntry.getGroups().size());
    // saved?
    Assert.assertEquals(displayName, re.getDisplayname());
    Assert.assertEquals(resourceName, re.getResourcename());
    Assert.assertEquals(description, re.getDescription());
    // default value
    Assert.assertFalse(re.getCanCopy());
    Assert.assertFalse(re.getCanDownload());
    Assert.assertFalse(re.getCanReference());
    Assert.assertEquals(0, re.getAccess());
  }
예제 #26
0
  @Test
  public void testNestedLockingSupported() {
    log.info("testing if nested locking is supported");
    // make sure all three row entries for the locks are created, otherwise the system-wide locking
    // applied on lock-row-creation cannot support row-level-locking by definition.

    PLock pc1 = pessimisticLockManager.findOrPersistPLock("blabla");
    assertNotNull(pc1);
    PLock pc2 = pessimisticLockManager.findOrPersistPLock("blublu");
    assertNotNull(pc2);
    PLock pc3 = pessimisticLockManager.findOrPersistPLock("blibli");
    assertNotNull(pc3);
    dbInstance.closeSession();

    final List<Long> holder = new ArrayList<Long>(1);
    // first thread acquires the two locks and waits and continues holding the lock for some time.
    PLock p1 = pessimisticLockManager.findOrPersistPLock("blabla");
    assertNotNull(p1);
    PLock p3 = pessimisticLockManager.findOrPersistPLock("blibli");
    assertNotNull(p3);

    new Thread(
            new Runnable() {
              public void run() {
                PLock p2 = pessimisticLockManager.findOrPersistPLock("blibli");
                assertNotNull(p2);
                long p2Acquired = System.nanoTime();
                holder.add(new Long(p2Acquired));
                dbInstance.closeSession();
              }
            })
        .start();
    sleep(500);
    boolean acOk = holder.size() == 0;
    // the commit will drop the lock on blibli d
    dbInstance.closeSession();
    sleep(500);
    boolean acNowOk = holder.size() == 1;

    // if row locking is not supported, then the timestamp when p2 has been acquired will be shortly
    // -after- p1 has been released
    assertTrue("since holding the blabla lock, no other may acquire it", acOk);
    assertTrue(
        "after having released the blabla lock, a next waiting thread must have acquired it after some time",
        acNowOk);
  }
예제 #27
0
  @Test
  public void binderAndSectionAndPageAccessRights() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-3");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-4");
    Identity reviewer = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-5");
    String title = "My published binder";
    String summary = "My live";
    Binder binder = portfolioService.createNewBinder(title, summary, null, owner);
    dbInstance.commit();
    portfolioService.appendNewSection("Section", "Coached section", null, null, binder);
    dbInstance.commit();
    List<Section> sections = portfolioService.getSections(binder);
    Section section = sections.get(0);
    portfolioService.appendNewPage(owner, "Reviewed page", "", null, null, section);
    portfolioService.addAccessRights(section, coach, PortfolioRoles.coach);

    dbInstance.commit();
    List<Page> pages = portfolioService.getPages(section);
    Page page = pages.get(0);
    portfolioService.addAccessRights(page, reviewer, PortfolioRoles.reviewer);

    // load right
    List<AccessRights> rights = portfolioService.getAccessRights(binder);
    Assert.assertNotNull(rights);
    Assert.assertEquals(4, rights.size());

    boolean foundOwner = false;
    boolean foundCoach = false;
    boolean foundReviewer = false;

    for (AccessRights right : rights) {
      if (PortfolioRoles.owner.equals(right.getRole()) && owner.equals(right.getIdentity())) {
        foundOwner = true;
      } else if (PortfolioRoles.coach.equals(right.getRole())
          && coach.equals(right.getIdentity())) {
        foundCoach = true;
      } else if (PortfolioRoles.reviewer.equals(right.getRole())
          && reviewer.equals(right.getIdentity())) {
        foundReviewer = true;
      }
    }

    Assert.assertTrue(foundOwner);
    Assert.assertTrue(foundCoach);
    Assert.assertTrue(foundReviewer);
  }
  protected void loadModel() {
    Statistics statistics = dbInstance.getStatistics();
    mainVC.contextPut("isStatisticsEnabled", statistics.isStatisticsEnabled());
    mainVC.contextPut("hibernateStatistics", statistics);

    DatabaseConnectionVO connectionInfos = databaseStatsManager.getConnectionInfos();
    mainVC.contextPut("connectionInfos", connectionInfos);
  }
  @Test
  public void testTaggingOfArtefacts() {
    final AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    dbInstance.commitAndCloseSession();
    assertNotNull(artefact);

    epFrontendManager.setArtefactTag(ident1, artefact, "Hello");
    epFrontendManager.setArtefactTag(ident2, artefact, "Hello");
    epFrontendManager.setArtefactTag(ident2, artefact, "Tchao");
    dbInstance.commitAndCloseSession();

    final List<String> tags = (List<String>) epFrontendManager.getArtefactTags(artefact);
    assertNotNull(tags);
    assertEquals(2, tags.size());
    assertTrue(tags.get(0).equals("Hello") || tags.get(1).equals("Hello"));
    assertTrue(tags.get(0).equals("Tchao") || tags.get(1).equals("Tchao"));
  }
  @Test
  public void testCopyMap() {
    // create two artefacts
    final AbstractArtefact artefact1 = epFrontendManager.createAndPersistArtefact(ident1, "text");
    assertNotNull(artefact1);

    final AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    assertNotNull(artefact2);

    dbInstance.commitAndCloseSession();

    // create a map with a page and the page has two artefacts
    final PortfolioStructureMap originalMap =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Title", "Description");
    final PortfolioStructure newPage =
        epFrontendManager.createAndPersistPortfolioPage(
            originalMap, "Page title", "Page description");
    final boolean successfullLink1 =
        epFrontendManager.addArtefactToStructure(ident1, artefact1, newPage);
    assertTrue(successfullLink1);

    final boolean successfullLink2 =
        epFrontendManager.addArtefactToStructure(ident1, artefact2, newPage);
    assertTrue(successfullLink2);

    dbInstance.commitAndCloseSession();

    // 1 test: copy the map one shoot
    final PortfolioStructureMap copyMap =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Title copy", "Description copy");
    epFrontendManager.copyStructureRecursively(originalMap, copyMap, true);
    assertNotNull(copyMap.getKey());

    dbInstance.commitAndCloseSession();

    // 2 test: copy the map two shoota
    final PortfolioStructureMap copyMap2 =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Title copy 2", "Description copy 2");
    dbInstance.commitAndCloseSession();
    assertNotNull(copyMap2.getKey());

    epFrontendManager.copyStructureRecursively(originalMap, copyMap2, true);
    dbInstance.commitAndCloseSession();
  }