use of org.olat.portfolio.model.structel.EPStructureElement in project OpenOLAT by OpenOLAT.
the class EPTOCController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source instanceof Link) {
Link link = (Link) source;
if (link.getCommand().equals(DELETE_LINK_CMD)) {
if (artefactClicked != null) {
AbstractArtefact artefact = artefactClicked;
PortfolioStructure parentStruct = getArtefactParentStruct(artefactClicked);
ePFMgr.removeArtefactFromStructure(artefact, parentStruct);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (structureClicked != null) {
if ((structureClicked instanceof EPPage) && !(structureClicked instanceof EPAbstractMap)) {
PortfolioStructure ps = structureClicked;
while (ePFMgr.loadStructureParent(ps) != null) {
ps = ePFMgr.loadStructureParent(ps);
}
int childPages = ePFMgr.countStructureChildren(ps);
if (childPages > 1) {
eSTMgr.removeStructureRecursively(structureClicked);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else {
showError("last.page.not.deletable");
}
} else if (structureClicked instanceof EPStructureElement && !(structureClicked instanceof EPAbstractMap)) {
// structures should always be deletable
eSTMgr.removeStructureRecursively(structureClicked);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else {
showInfo("element.not.deletable");
}
}
}
} else if (source == treeCtr) {
if (event instanceof TreeEvent) {
TreeEvent te = (TreeEvent) event;
if (MenuTree.COMMAND_TREENODE_CLICKED.equals(te.getCommand())) {
doSelectTreeElement(ureq, te);
}
} else if (event instanceof TreeDropEvent) {
TreeDropEvent te = (TreeDropEvent) event;
doDrop(ureq, te.getDroppedNodeId(), te.getTargetNodeId(), te.isAsChild());
}
}
}
use of org.olat.portfolio.model.structel.EPStructureElement in project OpenOLAT by OpenOLAT.
the class EPStructureManagerTest method testCreateAndRetrieveCollectRestrictionElement.
@Test
public void testCreateAndRetrieveCollectRestrictionElement() {
PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-3", "structure-element-3");
epStructureManager.addCollectRestriction(el, "Forum", "minimum", 3);
epStructureManager.savePortfolioStructure(el);
dbInstance.commitAndCloseSession();
PortfolioStructure retrievedEl = epStructureManager.loadPortfolioStructure(el.getOlatResource());
assertNotNull(retrievedEl);
assertTrue(retrievedEl instanceof EPStructureElement);
EPStructureElement retrievedStructEl = (EPStructureElement) retrievedEl;
assertNotNull(retrievedStructEl.getCollectRestrictions());
assertEquals("Forum", retrievedStructEl.getCollectRestrictions().get(0).getArtefactType());
assertEquals("minimum", retrievedStructEl.getCollectRestrictions().get(0).getRestriction());
assertEquals(3, retrievedStructEl.getCollectRestrictions().get(0).getAmount());
}
use of org.olat.portfolio.model.structel.EPStructureElement in project OpenOLAT by OpenOLAT.
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.EPStructureElement in project OpenOLAT by OpenOLAT.
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 EPStructureManager method instantiateClone.
private EPStructureElement instantiateClone(PortfolioStructure source) {
EPStructureElement targetEl = null;
// don't forget the inheritence
if (source instanceof EPPage) {
targetEl = new EPPage();
targetEl.setTitle(((EPPage) source).getTitle());
targetEl.setDescription(((EPPage) source).getDescription());
} else if (source instanceof EPStructureElement) {
targetEl = new EPStructureElement();
targetEl.setTitle(((EPStructureElement) source).getTitle());
targetEl.setDescription(((EPStructureElement) source).getDescription());
}
return targetEl;
}
Aggregations