Search in sources :

Example 46 with EPStructureElement

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());
        }
    }
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) TreeEvent(org.olat.core.gui.components.tree.TreeEvent) EPPage(org.olat.portfolio.model.structel.EPPage) EPAbstractMap(org.olat.portfolio.model.structel.EPAbstractMap) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) TreeDropEvent(org.olat.core.gui.components.tree.TreeDropEvent) Link(org.olat.core.gui.components.link.Link)

Example 47 with EPStructureElement

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());
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Test(org.junit.Test)

Example 48 with EPStructureElement

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());
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Test(org.junit.Test)

Example 49 with EPStructureElement

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());
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink) Test(org.junit.Test)

Example 50 with EPStructureElement

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;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPPage(org.olat.portfolio.model.structel.EPPage)

Aggregations

EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)66 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)18 EPStructureToStructureLink (org.olat.portfolio.model.structel.EPStructureToStructureLink)16 EPStructureToArtefactLink (org.olat.portfolio.model.structel.EPStructureToArtefactLink)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)8 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)8 EPPage (org.olat.portfolio.model.structel.EPPage)8 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)6 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)6 Identity (org.olat.core.id.Identity)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 OLATResource (org.olat.resource.OLATResource)4 Date (java.util.Date)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2