Search in sources :

Example 16 with PortfolioStructure

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

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)

Example 17 with PortfolioStructure

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

the class EPStructureManagerTest method testGetStructureElementsForUser.

@Test
public void testGetStructureElementsForUser() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("EP-1-");
    PortfolioStructure el = epFrontendManager.createAndPersistPortfolioDefaultMap(user, "users-test-map", "a-map-to-test-get-afterwards");
    Assert.assertNotNull(el);
    dbInstance.commitAndCloseSession();
    List<SecurityGroup> secGroups = securityManager.getSecurityGroupsForIdentity(user);
    Assert.assertNotNull(secGroups);
    Assert.assertTrue(secGroups.size() >= 1);
    List<PortfolioStructure> elRes = epStructureManager.getStructureElementsForUser(user, ElementType.DEFAULT_MAP);
    Assert.assertNotNull(elRes);
    Assert.assertEquals(1, elRes.size());
    Assert.assertEquals("users-test-map", elRes.get(0).getTitle());
    // get another map
    PortfolioStructure el2 = epFrontendManager.createAndPersistPortfolioDefaultMap(user, "users-test-map-2", "2-a-map-to-test-get-afterwards");
    Assert.assertNotNull(el2);
    dbInstance.commitAndCloseSession();
    List<PortfolioStructure> elRes2 = epStructureManager.getStructureElementsForUser(user);
    Assert.assertNotNull(elRes2);
    Assert.assertEquals(2, elRes2.size());
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) Test(org.junit.Test)

Example 18 with PortfolioStructure

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

the class PortfolioCourseNode method importNode.

@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
    RepositoryEntryImportExport rie = new RepositoryEntryImportExport(importDirectory, getIdent());
    if (withReferences && rie.anyExportedPropertiesAvailable()) {
        RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(EPTemplateMapResource.TYPE_NAME);
        RepositoryEntry re = handler.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
        if (re != null) {
            EPFrontendManager ePFMgr = CoreSpringFactory.getImpl(EPFrontendManager.class);
            PortfolioStructure map = ePFMgr.loadPortfolioStructure(re.getOlatResource());
            PortfolioCourseNodeEditController.setReference(re, map, getModuleConfiguration());
        } else {
            PortfolioCourseNodeEditController.removeReference(getModuleConfiguration());
        }
    } else {
        PortfolioCourseNodeEditController.removeReference(getModuleConfiguration());
    }
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager)

Example 19 with PortfolioStructure

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

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)

Example 20 with PortfolioStructure

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

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)

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