Search in sources :

Example 86 with AbstractArtefact

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

the class EPFrontendManagerTest method testTaggingOfArtefacts.

@Test
public void testTaggingOfArtefacts() {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    dbInstance.commitAndCloseSession();
    assertNotNull(artefact);
    epFrontendManager.setArtefactTag(ident1, artefact, "Hello");
    epFrontendManager.setArtefactTag(ident2, artefact, "Hello");
    epFrontendManager.setArtefactTag(ident2, artefact, "Tchao");
    dbInstance.commitAndCloseSession();
    List<String> tags = epFrontendManager.getArtefactTags(artefact);
    assertNotNull(tags);
    assertEquals(2, tags.size());
    assertTrue(tags.get(0).equals("Hello") || tags.get(1).equals("Hello"));
    assertTrue(tags.get(0).equals("Tchao") || tags.get(1).equals("Tchao"));
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 87 with AbstractArtefact

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

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

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

the class EPFrontendManagerTest method deleteMap_withOldPolicy.

@Test
public void deleteMap_withOldPolicy() {
    // create map
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-7");
    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.commit();
    // create an old policy manually
    SecurityGroup secGroup = securityManager.createAndPersistSecurityGroup();
    Policy policy = securityManager.createAndPersistPolicy(secGroup, "allusers_" + Constants.PERMISSION_READ, map.getOlatResource());
    Assert.assertNotNull(policy);
    dbInstance.commitAndCloseSession();
    // delete the map
    PortfolioStructure reloadedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    epFrontendManager.deletePortfolioStructure(reloadedMap);
    dbInstance.commit();
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) Policy(org.olat.basesecurity.Policy) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) Test(org.junit.Test)

Example 89 with AbstractArtefact

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

the class EPPerformanceTest method createAndFillArtefact.

/**
 * create a heavy filled artefact!
 * @param j number of artefact
 * @return
 */
private AbstractArtefact createAndFillArtefact(int j) {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, ForumArtefact.FORUM_ARTEFACT_TYPE);
    artefact.setFulltextContent(getLoremStringFactor512(2));
    artefact.setReflexion(getLoremStringFactor512(3));
    artefact.setDescription(LOREM_STRING_512);
    artefact.setTitle("Test Artefact number" + j);
    artefact.setSignature(60);
    artefact.setCollectionDate(new Date());
    artefact.setBusinessPath("a dummy businessPath entry");
    artefact.setSource("some Forum was my source");
    return epFrontendManager.updateArtefact(artefact);
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Date(java.util.Date)

Example 90 with AbstractArtefact

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

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