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());
}
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());
}
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());
}
}
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;
}
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;
}
Aggregations