Search in sources :

Example 46 with AbstractArtefact

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

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 47 with AbstractArtefact

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

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 48 with AbstractArtefact

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

the class EPStructureToArtefactTest method addArtefactsToStructure.

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

Example 49 with AbstractArtefact

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

the class EPStructureToArtefactTest method testArtefactsPaging.

@Test
public void testArtefactsPaging() {
    // save parent and 20 children
    PortfolioStructure structureEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "paged-structure-el", "paged-structure-element");
    List<AbstractArtefact> children = new ArrayList<AbstractArtefact>();
    for (int i = 0; i < 20; i++) {
        AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
        artefact.setTitle("paged-artefact-" + i);
        artefact = epFrontendManager.updateArtefact(artefact);
        epFrontendManager.addArtefactToStructure(ident1, artefact, structureEl);
        children.add(artefact);
    }
    dbInstance.commitAndCloseSession();
    List<AbstractArtefact> childrenSubset = epStructureManager.getArtefacts(structureEl, 15, 10);
    assertNotNull(childrenSubset);
    assertEquals(5, childrenSubset.size());
    assertEquals(children.get(15).getKey(), childrenSubset.get(0).getKey());
    assertEquals(children.get(16).getKey(), childrenSubset.get(1).getKey());
    assertEquals(children.get(17).getKey(), childrenSubset.get(2).getKey());
    assertEquals(children.get(18).getKey(), childrenSubset.get(3).getKey());
    assertEquals(children.get(19).getKey(), childrenSubset.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 50 with AbstractArtefact

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

the class EPStructureToArtefactTest method saveArtefact.

/**
 * Persist all properties and check them
 */
@Test
public void saveArtefact() {
    // create artefact
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.set(Calendar.MILLISECOND, 0);
    Date collectionDate = cal.getTime();
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    artefact.setTitle("artefact-title");
    artefact.setBusinessPath("business-path");
    artefact.setCollectionDate(collectionDate);
    artefact.setDescription("artefact-description");
    artefact.setReflexion("artefact-reflexion");
    artefact.setSignature(70);
    artefact.setFulltextContent("fulltext-content");
    artefact.setSource("artefact-source");
    artefact = epFrontendManager.updateArtefact(artefact);
    dbInstance.commitAndCloseSession();
    // test if the link is persisted
    AbstractArtefact retrievedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
    assertNotNull(retrievedArtefact);
    assertEquals(artefact.getKey(), retrievedArtefact.getKey());
    assertEquals("artefact-title", retrievedArtefact.getTitle());
    assertEquals("business-path", retrievedArtefact.getBusinessPath());
    assertEquals("artefact-description", retrievedArtefact.getDescription());
    assertEquals("artefact-reflexion", retrievedArtefact.getReflexion());
    assertEquals(70, retrievedArtefact.getSignature());
    assertEquals("fulltext-content", retrievedArtefact.getFulltextContent());
    assertEquals("artefact-source", retrievedArtefact.getSource());
    assertEquals(ident1.getKey(), retrievedArtefact.getAuthor().getKey());
    // check date
    assertNotNull(retrievedArtefact.getCollectionDate());
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(collectionDate);
    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(retrievedArtefact.getCollectionDate());
    assertTrue(cal1.compareTo(cal2) == 0);
}
Also used : Calendar(java.util.Calendar) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Date(java.util.Date) Test(org.junit.Test)

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