Search in sources :

Example 81 with PortfolioStructure

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

the class EPStructureManagerTest method testGetReferencedMapsForArtefact.

@Test
public void testGetReferencedMapsForArtefact() {
    PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el", "structure-element");
    dbInstance.commitAndCloseSession();
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    epFrontendManager.addArtefactToStructure(ident1, artefact, el);
    dbInstance.commitAndCloseSession();
    // get the referenced maps
    List<PortfolioStructure> mapList = epFrontendManager.getReferencedMapsForArtefact(artefact);
    assertTrue(((Persistable) el).equalsByPersistableKey((Persistable) mapList.get(0)));
    dbInstance.commitAndCloseSession();
    // make the test more complex
    // reload the structure element
    el = epFrontendManager.loadPortfolioStructureByKey(el.getKey());
    // add artefact to substructure (page) and check for the same map
    PortfolioStructure childEl = epFrontendManager.createAndPersistPortfolioStructureElement(el, "child-structure-el", "child-structure-element");
    el = epFrontendManager.removeArtefactFromStructure(artefact, el);
    epFrontendManager.addArtefactToStructure(ident1, artefact, childEl);
    dbInstance.commitAndCloseSession();
    // get the referenced maps
    List<PortfolioStructure> mapList2 = epFrontendManager.getReferencedMapsForArtefact(artefact);
    assertTrue(((Persistable) el).equalsByPersistableKey((Persistable) mapList2.get(0)));
    dbInstance.commitAndCloseSession();
    // add artefact to 3 maps and check to get all of them
    PortfolioStructure el2 = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-2", "structure-element-2");
    epFrontendManager.addArtefactToStructure(ident1, artefact, el2);
    PortfolioStructure el3 = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-3", "structure-element-3");
    epFrontendManager.addArtefactToStructure(ident1, artefact, el3);
    List<PortfolioStructure> mapList3 = epFrontendManager.getReferencedMapsForArtefact(artefact);
    assertEquals(3, mapList3.size());
    boolean found = false;
    for (PortfolioStructure mapValue : mapList3) {
        if (((Persistable) mapValue).equalsByPersistableKey((Persistable) el)) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : Persistable(org.olat.core.id.Persistable) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 82 with PortfolioStructure

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

the class EPStructureManagerTest method testMoveUp.

@Test
public void testMoveUp() {
    // save parent and 5 children
    PortfolioStructure parentEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "move-up-parent-structure-el-1", "move-up-structure-element");
    List<PortfolioStructure> children = new ArrayList<PortfolioStructure>();
    for (int i = 0; i < 5; i++) {
        PortfolioStructure childEl = epFrontendManager.createAndPersistPortfolioStructureElement(parentEl, "paged-structure-el-" + i, "paged-child-structure-element");
        children.add(childEl);
    }
    dbInstance.commitAndCloseSession();
    // check if the paging return the right children
    List<PortfolioStructure> childrenSubset = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(childrenSubset);
    assertEquals(5, childrenSubset.size());
    assertEquals(children.get(0).getKey(), childrenSubset.get(0).getKey());
    assertEquals(children.get(1).getKey(), childrenSubset.get(1).getKey());
    assertEquals(children.get(2).getKey(), childrenSubset.get(2).getKey());
    assertEquals(children.get(3).getKey(), childrenSubset.get(3).getKey());
    assertEquals(children.get(4).getKey(), childrenSubset.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move up the first place
    epStructureManager.moveUp(parentEl, children.get(0));
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<PortfolioStructure> persistedChildren1 = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(persistedChildren1);
    assertEquals(5, persistedChildren1.size());
    assertEquals(children.get(0).getKey(), persistedChildren1.get(0).getKey());
    assertEquals(children.get(1).getKey(), persistedChildren1.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren1.get(2).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren1.get(3).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren1.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move the second to the first place
    epStructureManager.moveUp(parentEl, children.get(1));
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<PortfolioStructure> persistedChildren2 = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(persistedChildren2);
    assertEquals(5, persistedChildren2.size());
    assertEquals(children.get(1).getKey(), persistedChildren2.get(0).getKey());
    assertEquals(children.get(0).getKey(), persistedChildren2.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren2.get(2).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren2.get(3).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren2.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move up the last
    epStructureManager.moveUp(parentEl, children.get(4));
    epStructureManager.savePortfolioStructure(parentEl);
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<PortfolioStructure> persistedChildren3 = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(persistedChildren3);
    assertEquals(5, persistedChildren3.size());
    assertEquals(children.get(1).getKey(), persistedChildren3.get(0).getKey());
    assertEquals(children.get(0).getKey(), persistedChildren3.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren3.get(2).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren3.get(3).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren3.get(4).getKey());
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 83 with PortfolioStructure

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

the class EPStructureManagerTest method loadPortfolioStructure_resourceable.

@Test
public void loadPortfolioStructure_resourceable() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("EP-res-tmp-");
    // a template
    PortfolioStructureMap template = epStructureManager.createPortfolioMapTemplate(user, "resourced-el", "resource-element");
    epStructureManager.savePortfolioStructure(template);
    dbInstance.commitAndCloseSession();
    OLATResource resource = template.getOlatResource();
    PortfolioStructure structure = epStructureManager.loadPortfolioStructure(resource);
    Assert.assertNotNull(structure);
    Assert.assertEquals(template, structure);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 84 with PortfolioStructure

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

the class EPStructureManagerTest method testChildrenBetweenSeveralSessions.

@Test
public void testChildrenBetweenSeveralSessions() {
    // test save parent and child
    PortfolioStructure parentEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "parent-structure-el", "parent-structure-element");
    PortfolioStructure childEl1 = epFrontendManager.createAndPersistPortfolioStructureElement(parentEl, "multi-session-structure-el-1", "child-structure-element");
    dbInstance.commitAndCloseSession();
    PortfolioStructure childEl2 = epFrontendManager.createAndPersistPortfolioStructureElement(parentEl, "multi-session-structure-el-2", "child-structure-element");
    dbInstance.commitAndCloseSession();
    PortfolioStructure childEl3 = epFrontendManager.createAndPersistPortfolioStructureElement(parentEl, "multi-session-structure-el-3", "child-structure-element");
    ((EPStructureElement) parentEl).setTitle("parent-structure-el-prime");
    epStructureManager.savePortfolioStructure(parentEl);
    dbInstance.commitAndCloseSession();
    // test if all children are saved
    List<PortfolioStructure> retrievedChilrenEl = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(retrievedChilrenEl);
    assertEquals(3, retrievedChilrenEl.size());
    // test if they are ordered
    assertEquals(childEl1.getKey(), retrievedChilrenEl.get(0).getKey());
    assertEquals(childEl2.getKey(), retrievedChilrenEl.get(1).getKey());
    assertEquals(childEl3.getKey(), retrievedChilrenEl.get(2).getKey());
    // test the title too (why not?)
    assertEquals("multi-session-structure-el-1", ((EPStructureElement) retrievedChilrenEl.get(0)).getTitle());
    assertEquals("multi-session-structure-el-2", ((EPStructureElement) retrievedChilrenEl.get(1)).getTitle());
    assertEquals("multi-session-structure-el-3", ((EPStructureElement) retrievedChilrenEl.get(2)).getTitle());
    // test if the change to the parent was not lost
    PortfolioStructure retrievedParentEl = epFrontendManager.loadPortfolioStructureByKey(parentEl.getKey());
    assertEquals("parent-structure-el-prime", ((EPStructureElement) retrievedParentEl).getTitle());
    dbInstance.commitAndCloseSession();
    // test that the children are not always loaded
    PortfolioStructure retrievedParentEl2 = epFrontendManager.loadPortfolioStructureByKey(parentEl.getKey());
    dbInstance.commitAndCloseSession();
    boolean failedToLazyLoadChildren;
    try {
        List<EPStructureToStructureLink> children = ((EPStructureElement) retrievedParentEl2).getInternalChildren();
        failedToLazyLoadChildren = (children == null || children.isEmpty());
    } catch (Exception e) {
        failedToLazyLoadChildren = true;
    }
    assertTrue(failedToLazyLoadChildren);
    dbInstance.commitAndCloseSession();
    // test load parent
    PortfolioStructure retrievedParentEl3 = epFrontendManager.loadStructureParent(childEl1);
    assertNotNull(retrievedParentEl3);
    assertEquals(parentEl.getKey(), retrievedParentEl3.getKey());
    PortfolioStructure retrievedParentEl4 = epFrontendManager.loadStructureParent(childEl2);
    assertNotNull(retrievedParentEl4);
    assertEquals(parentEl.getKey(), retrievedParentEl4.getKey());
    PortfolioStructure retrievedParentEl5 = epFrontendManager.loadStructureParent(childEl3);
    assertNotNull(retrievedParentEl5);
    assertEquals(parentEl.getKey(), retrievedParentEl5.getKey());
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink) Test(org.junit.Test)

Example 85 with PortfolioStructure

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

the class EPStructureManagerTest method testMoveDown.

@Test
public void testMoveDown() {
    // save parent and 5 children
    PortfolioStructure parentEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "move-up-parent-structure-el-1", "move-up-structure-element");
    List<PortfolioStructure> children = new ArrayList<PortfolioStructure>();
    for (int i = 0; i < 5; i++) {
        PortfolioStructure childEl = epFrontendManager.createAndPersistPortfolioStructureElement(parentEl, "paged-structure-el-" + i, "paged-child-structure-element");
        children.add(childEl);
    }
    dbInstance.commitAndCloseSession();
    // check if the paging return the right children
    List<PortfolioStructure> childrenSubset = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(childrenSubset);
    assertEquals(5, childrenSubset.size());
    assertEquals(children.get(0).getKey(), childrenSubset.get(0).getKey());
    assertEquals(children.get(1).getKey(), childrenSubset.get(1).getKey());
    assertEquals(children.get(2).getKey(), childrenSubset.get(2).getKey());
    assertEquals(children.get(3).getKey(), childrenSubset.get(3).getKey());
    assertEquals(children.get(4).getKey(), childrenSubset.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move down the last
    epStructureManager.moveDown(parentEl, children.get(4));
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<PortfolioStructure> persistedChildren1 = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(persistedChildren1);
    assertEquals(5, persistedChildren1.size());
    assertEquals(children.get(0).getKey(), persistedChildren1.get(0).getKey());
    assertEquals(children.get(1).getKey(), persistedChildren1.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren1.get(2).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren1.get(3).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren1.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move down to the last place
    epStructureManager.moveDown(parentEl, children.get(3));
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<PortfolioStructure> persistedChildren2 = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(persistedChildren2);
    assertEquals(5, persistedChildren2.size());
    assertEquals(children.get(0).getKey(), persistedChildren2.get(0).getKey());
    assertEquals(children.get(1).getKey(), persistedChildren2.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren2.get(2).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren2.get(3).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren2.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move down the first to the second position
    epStructureManager.moveDown(parentEl, children.get(0));
    epStructureManager.savePortfolioStructure(parentEl);
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<PortfolioStructure> persistedChildren3 = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(persistedChildren3);
    assertEquals(5, persistedChildren3.size());
    assertEquals(children.get(1).getKey(), persistedChildren3.get(0).getKey());
    assertEquals(children.get(0).getKey(), persistedChildren3.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren3.get(2).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren3.get(3).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren3.get(4).getKey());
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList) 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