Search in sources :

Example 11 with EPStructureElement

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

Example 12 with EPStructureElement

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

Example 13 with EPStructureElement

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

Example 14 with EPStructureElement

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());
}
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 15 with EPStructureElement

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

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