Search in sources :

Example 86 with PortfolioStructure

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

the class EPStructureManagerTest method testChildrenPaging.

@Test
public void testChildrenPaging() {
    // save parent and 20 children
    PortfolioStructure parentEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "paged-parent-structure-el", "parent-structure-element");
    List<PortfolioStructure> children = new ArrayList<PortfolioStructure>();
    for (int i = 0; i < 20; 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, 15, 10);
    assertNotNull(childrenSubset);
    assertEquals(5, childrenSubset.size());
    assertEquals(children.get(15).getKey(), childrenSubset.get(0).getKey());
    assertEquals(children.get(16).getKey(), childrenSubset.get(1).getKey());
    assertEquals(children.get(17).getKey(), childrenSubset.get(2).getKey());
    assertEquals(children.get(18).getKey(), childrenSubset.get(3).getKey());
    assertEquals(children.get(19).getKey(), childrenSubset.get(4).getKey());
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 87 with PortfolioStructure

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

the class EPStructureManagerTest method testCreateAndSaveTreeOfElements.

@Test
public void testCreateAndSaveTreeOfElements() {
    // test save parent and child
    PortfolioStructure parentEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "parent-structure-el", "parent-structure-element");
    PortfolioStructure childEl = epFrontendManager.createAndPersistPortfolioStructureElement(parentEl, "child-structure-el", "child-structure-element");
    dbInstance.commitAndCloseSession();
    // test load by key
    PortfolioStructure retrievedParentEl = epFrontendManager.loadPortfolioStructureByKey(parentEl.getKey());
    assertNotNull(retrievedParentEl);
    assertNotNull(retrievedParentEl.getOlatResource());
    // test load by key
    PortfolioStructure retrievedChildEl = epFrontendManager.loadPortfolioStructureByKey(childEl.getKey());
    PortfolioStructure retrievedParentEl2 = epFrontendManager.loadStructureParent(retrievedChildEl);
    assertNotNull(retrievedChildEl);
    assertNotNull(retrievedChildEl.getOlatResource());
    assertNotNull(retrievedParentEl2);
    assertEquals(parentEl.getKey(), retrievedParentEl2.getKey());
    dbInstance.commitAndCloseSession();
    // test get children
    List<PortfolioStructure> retrievedChilrenEl = epFrontendManager.loadStructureChildren(parentEl);
    assertNotNull(retrievedChilrenEl);
    assertEquals(1, retrievedChilrenEl.size());
    assertEquals(childEl.getKey(), retrievedChilrenEl.get(0).getKey());
    assertNotNull(((EPStructureElement) retrievedChilrenEl.get(0)).getRoot());
    assertEquals(parentEl.getKey(), ((EPStructureElement) retrievedChilrenEl.get(0)).getRoot().getKey());
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Test(org.junit.Test)

Example 88 with PortfolioStructure

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

the class EPStructureManager method getAllReferencesForArtefact.

protected List<PortfolioStructure> getAllReferencesForArtefact(AbstractArtefact artefact) {
    StringBuilder sb = new StringBuilder();
    sb.append("select link.structureElement from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.artefact=:artefactEl ");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("artefactEl", artefact);
    @SuppressWarnings("unchecked") List<PortfolioStructure> pfList = query.list();
    return pfList;
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 89 with PortfolioStructure

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

the class EPStructureManager method deletePortfolioMapTemplate.

/**
 * This method is only for templates.
 * @param res
 */
public void deletePortfolioMapTemplate(OLATResourceable res) {
    PortfolioStructure map = loadPortfolioStructure(res);
    if (map == null) {
        // nothing to delete
        return;
    }
    removeStructureRecursively(map);
    dbInstance.commit();
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Example 90 with PortfolioStructure

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

the class EPStructureManager method countArtefactsRecursively.

protected int countArtefactsRecursively(PortfolioStructure structure, int res) {
    List<PortfolioStructure> childs = loadStructureChildren(structure);
    res = res + countArtefacts(structure);
    for (PortfolioStructure portfolioStructure : childs) {
        res = countArtefactsRecursively(portfolioStructure, res);
    }
    return res;
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

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