Search in sources :

Example 36 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class EPFrontendManagerTest method isStructuredMapOwner.

/**
 * Same workflow as the repository. This workflow is pretty critical.
 */
@Test
public void isStructuredMapOwner() {
    OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
    // create a repository entry
    RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "test repo", "desc repo", resource, RepositoryEntry.ACC_OWNERS);
    dbInstance.commitAndCloseSession();
    // create the template owned by ident1
    PortfolioStructureMap template = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();
    // assign the template to ident2
    PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, template, addedEntry, 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()));
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 37 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class EPFrontendManagerTest method deleteMap_template.

/**
 * Delete a portfolio template
 */
@Test
public void deleteMap_template() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-6");
    // save parent and 20 children
    OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
    RepositoryEntry re = repositoryService.create(id, null, "", "Template to delete", "", resource, RepositoryEntry.ACC_OWNERS);
    PortfolioStructureMap template = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(id, re);
    PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(template, "Page while be deleted", "Page description");
    dbInstance.commitAndCloseSession();
    // reload and check
    PortfolioStructure reloadedTemplate = epFrontendManager.loadPortfolioStructureByKey(template.getKey());
    Assert.assertNotNull(reloadedTemplate);
    OLATResource reloadedResource = reloadedTemplate.getOlatResource();
    Assert.assertNotNull(reloadedResource);
    Assert.assertEquals(template, reloadedTemplate);
    List<PortfolioStructure> reloadedPages = epFrontendManager.loadStructureChildren(reloadedTemplate);
    Assert.assertNotNull(reloadedPages);
    Assert.assertEquals(1, reloadedPages.size());
    Assert.assertEquals(page, reloadedPages.get(0));
    // delete
    RepositoryEntry reloadedRe = repositoryService.loadByKey(re.getKey());
    Roles roles = new Roles(true, false, false, false, false, false, false);
    repositoryService.deletePermanently(reloadedRe, id, roles, Locale.GERMAN);
    dbInstance.commit();
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 38 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class EPStructureManagerTest method testCreateAndSaveElement.

@Test
public void testCreateAndSaveElement() {
    PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el", "structure-element");
    dbInstance.commitAndCloseSession();
    assertNotNull(el);
    assertNotNull(el.getOlatResource());
    PortfolioStructure retrievedEl = epFrontendManager.loadPortfolioStructureByKey(el.getKey());
    assertNotNull(retrievedEl);
    assertNotNull(retrievedEl.getOlatResource());
    OLATResource resource = resourceManager.findResourceable(el.getResourceableId(), el.getResourceableTypeName());
    assertNotNull(resource);
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 39 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class EPStructureManagerTest method testAddAuthorToMap.

@Test
public void testAddAuthorToMap() {
    // save the map
    PortfolioStructureMap map = epStructureManager.createPortfolioMapTemplate(ident1, "add-author-map-1", "add-an-author-to-map-template");
    epStructureManager.savePortfolioStructure(map);
    dbInstance.commitAndCloseSession();
    // add an author
    epStructureManager.addAuthor(map, ident2);
    dbInstance.commitAndCloseSession();
    // check that the author are in the
    OLATResource resource = resourceManager.findResourceable(map.getResourceableId(), map.getResourceableTypeName());
    assertNotNull(resource);
    RepositoryEntry re = repositoryManager.lookupRepositoryEntry(resource, false);
    assertNotNull(re);
    List<Identity> authors = repositoryService.getMembers(re, GroupRoles.owner.name());
    assertEquals(2, authors.size());
    // owner
    assertTrue(authors.contains(ident1));
    // owner
    assertTrue(authors.contains(ident2));
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 40 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class PropertyTest method testFindWithIdentityList.

@Test
public void testFindWithIdentityList() {
    // create identities, resource and properties
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("cat-id-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("cat-id-2-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("cat-id-3-" + UUID.randomUUID().toString());
    OLATResource ores = JunitTestHelper.createRandomResource();
    Property p1 = pm.createPropertyInstance(id1, null, ores, "catidentlist", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue");
    pm.saveProperty(p1);
    Property p2 = pm.createPropertyInstance(id2, null, ores, "catidentlist", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue");
    pm.saveProperty(p2);
    Property p3 = pm.createPropertyInstance(id3, null, ores, "catidentlist", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue");
    pm.saveProperty(p3);
    dbInstance.commitAndCloseSession();
    // check with empty list
    List<Property> emptyProps = pm.findProperties(Collections.<Identity>emptyList(), ores, "catidentlist", "TestProperty");
    assertNotNull(emptyProps);
    Assert.assertTrue(emptyProps.isEmpty());
    // check with a real value and a dummy
    List<Identity> identities = new ArrayList<Identity>();
    identities.add(id1);
    identities.add(id2);
    List<Property> props = pm.findProperties(identities, ores, "catidentlist", "TestProperty");
    assertNotNull(props);
    Assert.assertEquals(2, props.size());
    Assert.assertTrue(props.contains(p1));
    Assert.assertTrue(props.contains(p2));
}
Also used : ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26