Search in sources :

Example 26 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPStructureToArtefactTest method moveDownArtefact.

@Test
public void moveDownArtefact() {
    // save parent and 5 children
    PortfolioStructure structureEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "move-down-structure-el-1", "move-down-structure-element");
    List<AbstractArtefact> children = new ArrayList<AbstractArtefact>();
    for (int i = 0; i < 5; i++) {
        AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
        artefact.setTitle("move-down-artefact-1-" + i);
        artefact = epFrontendManager.updateArtefact(artefact);
        epFrontendManager.addArtefactToStructure(ident1, artefact, structureEl);
        children.add(artefact);
    }
    dbInstance.commitAndCloseSession();
    // move down the last
    epStructureManager.moveDown(structureEl, children.get(4));
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<AbstractArtefact> persistedChildren1 = epFrontendManager.getArtefacts(structureEl);
    assertNotNull(persistedChildren1);
    assertEquals(5, persistedChildren1.size());
    assertEquals(children.get(0).getKey(), persistedChildren1.get(0).getKey());
    assertEquals(children.get(1).getKey(), persistedChildren1.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren1.get(2).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren1.get(3).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren1.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move to the last place
    epStructureManager.moveDown(structureEl, children.get(3));
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<AbstractArtefact> persistedChildren2 = epFrontendManager.getArtefacts(structureEl);
    assertNotNull(persistedChildren2);
    assertEquals(5, persistedChildren2.size());
    assertEquals(children.get(0).getKey(), persistedChildren2.get(0).getKey());
    assertEquals(children.get(1).getKey(), persistedChildren2.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren2.get(2).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren2.get(3).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren2.get(4).getKey());
    dbInstance.commitAndCloseSession();
    // move down the first
    epStructureManager.moveDown(structureEl, children.get(0));
    dbInstance.commitAndCloseSession();
    // check that all is the same
    List<AbstractArtefact> persistedChildren3 = epFrontendManager.getArtefacts(structureEl);
    assertNotNull(persistedChildren3);
    assertEquals(5, persistedChildren3.size());
    assertEquals(children.get(1).getKey(), persistedChildren3.get(0).getKey());
    assertEquals(children.get(0).getKey(), persistedChildren3.get(1).getKey());
    assertEquals(children.get(2).getKey(), persistedChildren3.get(2).getKey());
    assertEquals(children.get(4).getKey(), persistedChildren3.get(3).getKey());
    assertEquals(children.get(3).getKey(), persistedChildren3.get(4).getKey());
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 27 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPStructureToArtefactTest method collectRestrictionTestByAdding.

@Test
public void collectRestrictionTestByAdding() {
    PortfolioStructure structureEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "move-down-structure-el-1", "move-down-structure-element");
    epStructureManager.addCollectRestriction(structureEl, ForumArtefact.FORUM_ARTEFACT_TYPE, RestrictionsConstants.MAX, 2);
    epStructureManager.savePortfolioStructure(structureEl);
    dbInstance.commitAndCloseSession();
    // check collect restriction
    AbstractArtefact artefact1 = epFrontendManager.createAndPersistArtefact(ident1, ForumArtefact.FORUM_ARTEFACT_TYPE);
    artefact1.setTitle("collect-restriction-1");
    assertTrue(epFrontendManager.addArtefactToStructure(ident1, artefact1, structureEl));
    AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    artefact2.setTitle("collect-restriction-2");
    assertFalse(epFrontendManager.addArtefactToStructure(ident1, artefact2, structureEl));
    AbstractArtefact artefact3 = epFrontendManager.createAndPersistArtefact(ident1, ForumArtefact.FORUM_ARTEFACT_TYPE);
    artefact3.setTitle("collect-restriction-3");
    assertTrue(epFrontendManager.addArtefactToStructure(ident1, artefact3, structureEl));
    AbstractArtefact artefact4 = epFrontendManager.createAndPersistArtefact(ident1, ForumArtefact.FORUM_ARTEFACT_TYPE);
    artefact4.setTitle("collect-restriction-4");
    assertFalse(epFrontendManager.addArtefactToStructure(ident1, artefact4, structureEl));
    dbInstance.commitAndCloseSession();
    // check if the artefacts are really what we want
    List<AbstractArtefact> retrievedArtefacts = epFrontendManager.getArtefacts(structureEl);
    assertNotNull(retrievedArtefacts);
    assertEquals(2, retrievedArtefacts.size());
    // 2 forums artefact, is ok
    assertTrue(epFrontendManager.checkCollectRestriction(structureEl));
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 28 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPStructureToArtefactTest method collectRestrictionTestAfterMax.

@Test
public void collectRestrictionTestAfterMax() {
    PortfolioStructure structureEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "move-down-structure-el-1", "move-down-structure-element");
    epStructureManager.addCollectRestriction(structureEl, ForumArtefact.FORUM_ARTEFACT_TYPE, RestrictionsConstants.MAX, 2);
    epStructureManager.savePortfolioStructure(structureEl);
    dbInstance.commitAndCloseSession();
    // try to add some artefacts
    AbstractArtefact artefact1 = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    artefact1.setTitle("collect-restriction-1");
    assertTrue(epFrontendManager.addArtefactToStructure(ident1, artefact1, structureEl));
    AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    artefact2.setTitle("collect-restriction-2");
    assertFalse(epFrontendManager.addArtefactToStructure(ident1, artefact2, structureEl));
    dbInstance.commitAndCloseSession();
    // check if the structure element is ok, it must be
    assertTrue(epFrontendManager.checkCollectRestriction(structureEl));
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 29 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPStructureToArtefactTest method createStructureToArtefactLink.

@Test
public void createStructureToArtefactLink() {
    // create structure element
    PortfolioStructure structure = epFrontendManager.createAndPersistPortfolioStructureElement(null, "struc-to-art-el", "structure-to-artefact-element");
    // create artefact
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    dbInstance.commitAndCloseSession();
    // test if all is ok
    assertNotNull(structure);
    assertNotNull(artefact);
    assertTrue(artefact instanceof ForumArtefact);
    // create the link
    epFrontendManager.addArtefactToStructure(ident1, artefact, structure);
    dbInstance.commitAndCloseSession();
    // test if the link is persisted
    List<AbstractArtefact> linkedArtfeacts = epFrontendManager.getArtefacts(structure);
    assertNotNull(linkedArtfeacts);
    assertEquals(1, linkedArtfeacts.size());
    assertEquals(artefact.getKey(), linkedArtfeacts.get(0).getKey());
}
Also used : ForumArtefact(org.olat.modules.fo.portfolio.ForumArtefact) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 30 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_7_1_1 method mergeLinkedArtefactsToFinalStruct.

private void mergeLinkedArtefactsToFinalStruct(PortfolioStructure finalStruct, List<PortfolioStructure> wrongStructs) {
    if (wrongStructs == null || wrongStructs.isEmpty())
        return;
    // temporarily remove the collectrestriction, will be added by next sync.
    // TODO: somehow user must be warned, that map may contain too much artefacts on one node
    finalStruct.getCollectRestrictions().clear();
    ePFMgr.savePortfolioStructure(finalStruct);
    int artefactCount = 0;
    for (PortfolioStructure portfolioStructure : wrongStructs) {
        portfolioStructure = ePFMgr.loadPortfolioStructureByKey(portfolioStructure.getKey());
        List<AbstractArtefact> artefacts = ePFMgr.getArtefacts(portfolioStructure);
        for (AbstractArtefact abstractArtefact : artefacts) {
            if (!ePFMgr.isArtefactInStructure(abstractArtefact, finalStruct)) {
                artefactCount++;
                ePFMgr.moveArtefactFromStructToStruct(abstractArtefact, portfolioStructure, finalStruct);
            } else {
                log.audit("An Artefact " + abstractArtefact + " has already been added to new target, therefore will be removed from wrong structure.");
                // TODO: maybe we should save the reflexion on the link artefact -> structure!
                ePFMgr.removeArtefactFromStructure(abstractArtefact, portfolioStructure);
            }
        }
    }
    log.audit("       merged " + artefactCount + " artefacts to new destinations.");
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact)

Aggregations

AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)164 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)70 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)36 Date (java.util.Date)20 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)18 DBQuery (org.olat.core.commons.persistence.DBQuery)10 Link (org.olat.core.gui.components.link.Link)10 Identity (org.olat.core.id.Identity)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)10 List (java.util.List)8 EPFilterSettings (org.olat.portfolio.model.EPFilterSettings)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)6 Step (org.olat.core.gui.control.generic.wizard.Step)6 StepRunnerCallback (org.olat.core.gui.control.generic.wizard.StepRunnerCallback)6 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)6 OLATResourceable (org.olat.core.id.OLATResourceable)6 EPAbstractMap (org.olat.portfolio.model.structel.EPAbstractMap)6 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)6