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());
}
}
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));
}
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);
}
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);
}
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);
}
Aggregations