Search in sources :

Example 61 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project openolat by klemens.

the class EPArtefactManagerTest method testCreateStructureElementArtefact.

@Test
public void testCreateStructureElementArtefact() {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "ep-structure-element");
    if (artefact != null) {
        // handler is disabled or another error occurred while
        // trying to create the artefact
        assertNotNull(artefact);
        assertTrue(artefact instanceof EPStructureElementArtefact);
        EPStructureElementArtefact elementArtefact = (EPStructureElementArtefact) artefact;
        PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-for-artefact", "structure-element-for-artefact");
        elementArtefact.setStructureElement((EPStructureElement) el);
        dbInstance.commitAndCloseSession();
        assertNotNull(artefact.getKey());
        // reload the artefact
        AbstractArtefact persistedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
        assertNotNull(persistedArtefact);
        assertTrue(persistedArtefact instanceof EPStructureElementArtefact);
        EPStructureElementArtefact persistedElementArtefact = (EPStructureElementArtefact) persistedArtefact;
        assertNotNull(persistedElementArtefact.getStructureElement());
        assertEquals(el.getKey(), persistedElementArtefact.getStructureElement().getKey());
    }
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPStructureElementArtefact(org.olat.portfolio.model.artefacts.EPStructureElementArtefact) Test(org.junit.Test)

Example 62 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project openolat by klemens.

the class EPFrontendManagerTest method deleteMap_pageAndPolicy.

/**
 * Delete a map with policies
 */
@Test
public void deleteMap_pageAndPolicy() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-5");
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(id, "Delete map", "Description");
    PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(map, "Page while be deleted", "Page description");
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(id, "Forum");
    epFrontendManager.addArtefactToStructure(id, artefact, page);
    dbInstance.commitAndCloseSession();
    // add policy
    List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.user);
    userPolicy.getIdentities().add(ident2);
    userPolicy.getIdentities().add(ident3);
    policies.add(userPolicy);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();
    // reload and check
    PortfolioStructure reloadedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    Assert.assertNotNull(reloadedMap);
    OLATResource reloadedResource = reloadedMap.getOlatResource();
    Assert.assertNotNull(reloadedResource);
    Assert.assertEquals(map, reloadedMap);
    boolean shared = epFrontendManager.isMapShared(reloadedResource);
    Assert.assertTrue(shared);
    boolean visibleToIdent2 = epFrontendManager.isMapVisible(ident2, reloadedResource);
    Assert.assertTrue(visibleToIdent2);
    // delete the map
    epFrontendManager.deletePortfolioStructure(reloadedMap);
    dbInstance.commit();
    boolean deletedShared = epFrontendManager.isMapShared(reloadedResource);
    Assert.assertFalse(deletedShared);
    boolean deletedVisibleToIdent2 = epFrontendManager.isMapVisible(ident2, reloadedResource);
    Assert.assertFalse(deletedVisibleToIdent2);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 63 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project openolat by klemens.

the class EPFrontendManagerTest method saveMapPolicy.

@Test
public void saveMapPolicy() {
    // create a map
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
    PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();
    // policies are empty
    List<EPMapPolicy> policies = epFrontendManager.getMapPolicies(map);
    // owner policy
    assertEquals(0, policies.size());
    // save a user policy
    EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.user);
    userPolicy.getIdentities().add(ident2);
    epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
    dbInstance.commitAndCloseSession();
    // one policy
    List<EPMapPolicy> policies1 = epFrontendManager.getMapPolicies(map);
    assertEquals(1, policies1.size());
    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (is in policy)
    assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check not visible (not in policy)
    assertFalse(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) Test(org.junit.Test)

Example 64 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project openolat by klemens.

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 65 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project openolat by klemens.

the class EPFrontendManagerTest method testSyncMapTemplateToUserMap.

@Test
public void testSyncMapTemplateToUserMap() {
    // create a template
    OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
    // create a repository entry
    RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "Template in user", "Template in use", resource, RepositoryEntry.ACC_OWNERS);
    // create the template owned by ident1
    PortfolioStructureMap templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    // create five pages
    List<PortfolioStructure> pageRefs = new ArrayList<PortfolioStructure>();
    List<PortfolioStructure> elementRefs = new ArrayList<PortfolioStructure>();
    for (int i = 0; i < 5; i++) {
        PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(templateEl, "sync-template-page-" + i, "sync-template-page-" + i);
        pageRefs.add(page);
        for (int j = 0; j < 5; j++) {
            PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(page, "template-structure-" + i + "." + j, "template-structure-" + i + "." + j);
            epStructureManager.addCollectRestriction(struct, "Forum", "minimum", 2);
            epStructureManager.savePortfolioStructure(struct);
            elementRefs.add(struct);
        }
    }
    // save the template
    dbInstance.commitAndCloseSession();
    // end create template
    // ////////////////////
    // make the copy
    PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
    dbInstance.commitAndCloseSession();
    assertNotNull(map);
    // ////////////////////////////////
    // shuffle the pages and delete one
    PortfolioStructure retrievedTemplateEl = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
    List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedTemplateEl);
    epStructureManager.moveUp(retrievedTemplateEl, pages.get(1));
    epStructureManager.moveDown(retrievedTemplateEl, pages.get(2));
    epStructureManager.removeStructure(retrievedTemplateEl, pages.get(3));
    epStructureManager.savePortfolioStructure(retrievedTemplateEl);
    // shuffle a page
    List<PortfolioStructure> page1Children = epFrontendManager.loadStructureChildren(pages.get(1));
    epStructureManager.moveUp(pages.get(1), page1Children.get(3));
    epStructureManager.moveUp(pages.get(1), page1Children.get(2));
    epStructureManager.moveUp(pages.get(1), page1Children.get(4));
    // and add an element and sub-elements
    PortfolioStructure newStruct = epFrontendManager.createAndPersistPortfolioStructureElement(pages.get(1), "new-template-structure-1.6", "template-structure-1.6");
    epStructureManager.addCollectRestriction(pages.get(1), "Forum", "minimum", 2);
    epStructureManager.savePortfolioStructure(newStruct);
    epStructureManager.savePortfolioStructure(pages.get(1));
    for (int k = 0; k < 5; k++) {
        PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(newStruct, "new-template-structure-2." + k, "template-structure-2." + k);
        epStructureManager.addCollectRestriction(struct, "bc", "minimum", 2);
        epStructureManager.savePortfolioStructure(struct);
        elementRefs.add(struct);
    }
    dbInstance.commitAndCloseSession();
    // end shuffle the pages
    // ////////////////////////////////
    // //////////////////
    // check the template
    PortfolioStructure retrievedTemplate2El = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
    assertNotNull(retrievedTemplate2El);
    assertTrue(retrievedTemplate2El instanceof EPStructuredMapTemplate);
    List<PortfolioStructure> retrievedPages2 = epFrontendManager.loadStructureChildren(retrievedTemplate2El);
    assertEquals(4, retrievedPages2.size());
    assertEquals(4, ((EPStructuredMapTemplate) retrievedTemplate2El).getInternalChildren().size());
    // check the shuffled pages
    assertEquals(pageRefs.get(1).getKey(), retrievedPages2.get(0).getKey());
    assertEquals(pageRefs.get(0).getKey(), retrievedPages2.get(1).getKey());
    assertEquals(pageRefs.get(2).getKey(), retrievedPages2.get(2).getKey());
    assertEquals(pageRefs.get(4).getKey(), retrievedPages2.get(3).getKey());
    // check added element
    List<PortfolioStructure> retrievedChildren2 = epFrontendManager.loadStructureChildren(retrievedPages2.get(0));
    assertEquals(6, retrievedChildren2.size());
    dbInstance.commitAndCloseSession();
    // check the template
    // //////////////////
    // sync the map
    epFrontendManager.synchronizeStructuredMapToUserCopy(map);
    dbInstance.commitAndCloseSession();
    // ///////////////
    // check the sync
    PortfolioStructure synchedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    assertNotNull(synchedMap);
    assertTrue(synchedMap instanceof EPStructuredMap);
    List<PortfolioStructure> synchedPages = epFrontendManager.loadStructureChildren(synchedMap);
    assertNotNull(synchedPages);
    assertEquals(4, synchedPages.size());
    assertEquals(((EPStructureElement) pageRefs.get(1)).getTitle(), ((EPStructureElement) synchedPages.get(0)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(0)).getTitle(), ((EPStructureElement) synchedPages.get(1)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(2)).getTitle(), ((EPStructureElement) synchedPages.get(2)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(4)).getTitle(), ((EPStructureElement) synchedPages.get(3)).getTitle());
    // check synched key
    assertEquals(((EPStructureElement) pageRefs.get(1)).getKey(), ((EPStructureElement) synchedPages.get(0)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(0)).getKey(), ((EPStructureElement) synchedPages.get(1)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(2)).getKey(), ((EPStructureElement) synchedPages.get(2)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(4)).getKey(), ((EPStructureElement) synchedPages.get(3)).getStructureElSource());
    // check the new elements
    List<PortfolioStructure> retrievedPage1Children = epFrontendManager.loadStructureChildren(synchedPages.get(0));
    assertEquals(6, retrievedPage1Children.size());
    PortfolioStructure retrievedNewStruct = retrievedPage1Children.get(5);
    assertEquals("new-template-structure-1.6", ((EPStructureElement) retrievedNewStruct).getTitle());
    List<PortfolioStructure> retrievedNewStructChildren = epFrontendManager.loadStructureChildren(retrievedNewStruct);
    assertNotNull(retrievedNewStructChildren);
    assertEquals(5, retrievedNewStructChildren.size());
    for (int k = 0; k < 5; k++) {
        assertEquals("new-template-structure-2." + k, ((EPStructureElement) retrievedNewStructChildren.get(k)).getTitle());
    }
// end check the sync
// //////////////////
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)236 Test (org.junit.Test)90 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)70 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)54 ArrayList (java.util.ArrayList)40 OLATResource (org.olat.resource.OLATResource)30 Identity (org.olat.core.id.Identity)26 RepositoryEntry (org.olat.repository.RepositoryEntry)24 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)22 EPMapPolicy (org.olat.portfolio.manager.EPMapPolicy)16 EPPage (org.olat.portfolio.model.structel.EPPage)16 EPAbstractMap (org.olat.portfolio.model.structel.EPAbstractMap)12 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)12 DBQuery (org.olat.core.commons.persistence.DBQuery)10 EPFrontendManager (org.olat.portfolio.manager.EPFrontendManager)10 Date (java.util.Date)8 Document (org.apache.lucene.document.Document)8 Link (org.olat.core.gui.components.link.Link)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)8 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)8