use of org.olat.portfolio.model.structel.EPStructureElement in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_1_1 method fixTemplateEntry.
private void fixTemplateEntry(PortfolioStructure template) {
List<PortfolioStructure> temps = new ArrayList<PortfolioStructure>();
recurseIntoTemplateAndCheck(new ArrayList<PortfolioStructure>(), temps, template);
for (PortfolioStructure portfolioStructure : temps) {
((EPStructureElement) portfolioStructure).setStructureElSource(null);
ePFMgr.savePortfolioStructure(portfolioStructure);
}
}
use of org.olat.portfolio.model.structel.EPStructureElement in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_1_1 method processStructure.
/**
* call the needed methods to really do the magic.
*/
private void processStructure(PortfolioStructure structuredMap) {
List<PortfolioStructure> linkedChildren = ePFMgr.loadStructureChildren(structuredMap);
for (PortfolioStructure childStruct : linkedChildren) {
// reload dbchildren in each run, because of filtering
List<PortfolioStructure> dbChildren;
if (childStruct instanceof EPPage) {
dbChildren = loadMapChildrenByInternalFK(childStruct, structuredMap);
} else {
dbChildren = loadMapChildrenByInternalFK(childStruct, structuredMap.getRoot());
}
// filter the struct that is already linked by a struct->struct link
// and filter such with other struct-source
filterLinkedStructs(childStruct, dbChildren);
log.audit(" found " + dbChildren.size() + " faulty children (of " + childStruct + ") linked by internal fk to be merged and removed afterwards.");
// merge artefacts to the linked struct
mergeLinkedArtefactsToFinalStruct(childStruct, dbChildren);
// collect comments on structures and merge to target
mergeCommentsToFinalStruct(childStruct, dbChildren);
// ratings are not merged, see OLAT-6306
// remove the old elements
removeWrongElements(dbChildren);
// fix root-reference on EPStructureElements
if (!(childStruct instanceof EPPage)) {
if (childStruct.getRoot().equals(childStruct.getRootMap())) {
EPStructureElement realParentRoot = (EPStructureElement) ePFMgr.loadStructureParent(childStruct);
((EPStructureElement) childStruct).setRoot(realParentRoot);
ePFMgr.savePortfolioStructure(childStruct);
}
}
}
// loop children
DBFactory.getInstance().intermediateCommit();
}
use of org.olat.portfolio.model.structel.EPStructureElement in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_1_1 method filterLinkedStructs.
private void filterLinkedStructs(PortfolioStructure filterBase, List<PortfolioStructure> dbChildren) {
for (Iterator<PortfolioStructure> iterator = dbChildren.iterator(); iterator.hasNext(); ) {
PortfolioStructure portfolioStructure = iterator.next();
long filterBaseSourceKey = ((EPStructureElement) filterBase).getStructureElSource();
long structSourceKey = ((EPStructureElement) portfolioStructure).getStructureElSource();
if (portfolioStructure.getKey() == filterBase.getKey() || filterBaseSourceKey != structSourceKey) {
iterator.remove();
}
}
}
use of org.olat.portfolio.model.structel.EPStructureElement 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());
}
use of org.olat.portfolio.model.structel.EPStructureElement 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());
}
Aggregations