Search in sources :

Example 41 with AbstractArtefact

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

the class EPArtefactManagerTest method testCreateStructureElementArtefact.

@Test
public void testCreateStructureElementArtefact() {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "ep-structure-element");
    if (artefact != null) {
        // handler is disabled or another error occurred while
        // trying to create the artefact
        assertNotNull(artefact);
        assertTrue(artefact instanceof EPStructureElementArtefact);
        EPStructureElementArtefact elementArtefact = (EPStructureElementArtefact) artefact;
        PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-for-artefact", "structure-element-for-artefact");
        elementArtefact.setStructureElement((EPStructureElement) el);
        dbInstance.commitAndCloseSession();
        assertNotNull(artefact.getKey());
        // reload the artefact
        AbstractArtefact persistedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
        assertNotNull(persistedArtefact);
        assertTrue(persistedArtefact instanceof EPStructureElementArtefact);
        EPStructureElementArtefact persistedElementArtefact = (EPStructureElementArtefact) persistedArtefact;
        assertNotNull(persistedElementArtefact.getStructureElement());
        assertEquals(el.getKey(), persistedElementArtefact.getStructureElement().getKey());
    }
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPStructureElementArtefact(org.olat.portfolio.model.artefacts.EPStructureElementArtefact) Test(org.junit.Test)

Example 42 with AbstractArtefact

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

the class EPArtefactManagerTest method testGetArtefactPoolForUser.

@Test
public void testGetArtefactPoolForUser() {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    List<AbstractArtefact> artefactList = epFrontendManager.getArtefactPoolForUser(ident1);
    assertEquals(2, artefactList.size());
    assertTrue(artefactList.contains(artefact));
    assertTrue(artefactList.contains(artefact2));
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 43 with AbstractArtefact

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

the class EPArtefactManagerTest method testDeleteArtefact.

@Test
public void testDeleteArtefact() {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    dbInstance.commitAndCloseSession();
    long artKey = artefact.getKey();
    AbstractArtefact loadedArtefact = epFrontendManager.loadArtefactByKey(artKey);
    // assure the artefact exists in db before deletion
    assertEquals(artefact.getKey(), loadedArtefact.getKey());
    epFrontendManager.deleteArtefact(loadedArtefact);
    AbstractArtefact loadedArtefact2 = epFrontendManager.loadArtefactByKey(artKey);
    assertNull(loadedArtefact2);
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 44 with AbstractArtefact

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

the class EPFrontendManagerTest method deleteMap_pageAndPolicy.

/**
 * Delete a map with policies
 */
@Test
public void deleteMap_pageAndPolicy() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-5");
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(id, "Delete map", "Description");
    PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(map, "Page while be deleted", "Page description");
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(id, "Forum");
    epFrontendManager.addArtefactToStructure(id, artefact, page);
    dbInstance.commitAndCloseSession();
    // add policy
    List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.user);
    userPolicy.getIdentities().add(ident2);
    userPolicy.getIdentities().add(ident3);
    policies.add(userPolicy);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();
    // reload and check
    PortfolioStructure reloadedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    Assert.assertNotNull(reloadedMap);
    OLATResource reloadedResource = reloadedMap.getOlatResource();
    Assert.assertNotNull(reloadedResource);
    Assert.assertEquals(map, reloadedMap);
    boolean shared = epFrontendManager.isMapShared(reloadedResource);
    Assert.assertTrue(shared);
    boolean visibleToIdent2 = epFrontendManager.isMapVisible(ident2, reloadedResource);
    Assert.assertTrue(visibleToIdent2);
    // delete the map
    epFrontendManager.deletePortfolioStructure(reloadedMap);
    dbInstance.commit();
    boolean deletedShared = epFrontendManager.isMapShared(reloadedResource);
    Assert.assertFalse(deletedShared);
    boolean deletedVisibleToIdent2 = epFrontendManager.isMapVisible(ident2, reloadedResource);
    Assert.assertFalse(deletedVisibleToIdent2);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 45 with AbstractArtefact

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

the class EPPerformanceTest method internalTestManyArtefactCreation.

private void internalTestManyArtefactCreation(int artefactAmount) {
    long start = System.currentTimeMillis();
    Runtime r = Runtime.getRuntime();
    for (int j = 0; j < artefactAmount; j++) {
        AbstractArtefact artefact = createAndFillArtefact(j);
        // tag the artefacts
        if (j % 2 == 0) {
            epFrontendManager.setArtefactTags(ident1, artefact, tagList1);
        } else {
            epFrontendManager.setArtefactTags(ident1, artefact, tagList2);
        }
        if (j % 10 == 0) {
            DBFactory.getInstance().closeSession();
        }
        if (j % 100 == 0) {
            logger.info("created another 100 artefacts! -> " + j);
            logger.info("  free memory: " + r.freeMemory());
        }
    }
    // for
    // load the whole artefact list
    long now = System.currentTimeMillis();
    logger.info("created " + artefactAmount + " artefacts in: " + (now - start) + " ms.");
    start = System.currentTimeMillis();
    List<AbstractArtefact> artList = epFrontendManager.getArtefactPoolForUser(ident1);
    now = System.currentTimeMillis();
    logger.info("querying all of them took: " + (now - start) + " ms.");
    assertEquals(artList.size(), artefactAmount);
    // filter artefacts by tags
    EPFilterSettings filterSettings = new EPFilterSettings();
    filterSettings.setTagFilter(new ArrayList<String>(Arrays.asList("Schule")));
    start = System.currentTimeMillis();
    artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, new Roles(false, false, false, false, false, false, false));
    now = System.currentTimeMillis();
    logger.info("filter artefacts by one tag took: " + (now - start) + " ms.");
    assertEquals(artList.size(), artefactAmount / 2);
    filterSettings.setTagFilter(tagList1);
    start = System.currentTimeMillis();
    artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, new Roles(false, false, false, false, false, false, false));
    now = System.currentTimeMillis();
    logger.info("filter artefacts by tagList1 took: " + (now - start) + " ms.");
    assertEquals(artList.size(), artefactAmount / 2);
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Roles(org.olat.core.id.Roles)

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