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