use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPPerformanceTest method internalTestCreateManyMaps.
private void internalTestCreateManyMaps(int mapAmount) {
long start = System.currentTimeMillis();
// prepare some artefacts to link to maps later
ArrayList<AbstractArtefact> artefacts = new ArrayList<AbstractArtefact>(10);
for (int i = 1; i < 11; i++) {
artefacts.add(createAndFillArtefact(i));
}
for (int k = 1; k < mapAmount; k++) {
PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "a test map number " + k, LOREM_STRING_512);
// attach sites and structures to it
ArrayList<PortfolioStructure> structs = new ArrayList<PortfolioStructure>();
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "test page1 for map " + k, LOREM_STRING_512);
structs.add(page1);
PortfolioStructure struct11 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "struct1 in page1 for map" + k, LOREM_STRING_512);
structs.add(struct11);
PortfolioStructure struct12 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "struct2 in page1 for map" + k, LOREM_STRING_512);
structs.add(struct12);
PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(map, "test page2 for map " + k, LOREM_STRING_512);
structs.add(page2);
PortfolioStructure struct21 = epFrontendManager.createAndPersistPortfolioStructureElement(page2, "struct1 in page2 for map" + k, LOREM_STRING_512);
structs.add(struct21);
PortfolioStructure struct22 = epFrontendManager.createAndPersistPortfolioStructureElement(page2, "struct2 in page2 for map" + k, LOREM_STRING_512);
structs.add(struct22);
// attach different artefacts to several places in map
int l = 1;
for (Iterator<PortfolioStructure> iterator = structs.iterator(); iterator.hasNext(); ) {
PortfolioStructure portfolioStructure = iterator.next();
epFrontendManager.addArtefactToStructure(ident1, artefacts.get(l), portfolioStructure);
// add two artefacts
if (l % 2 == 0) {
epFrontendManager.addArtefactToStructure(ident1, artefacts.get(l + 1), portfolioStructure);
}
l++;
}
// for attach
// share the map with all users
EPMapPolicy userPolicy = new EPMapPolicy();
userPolicy.setType(Type.allusers);
epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
dbInstance.commitAndCloseSession();
}
// for maps
long now = System.currentTimeMillis();
logger.info("created " + mapAmount + " maps, attached artefacts and shared maps to public in: " + (now - start) + " ms.");
// load all maps
start = System.currentTimeMillis();
List<PortfolioStructure> publicMaps = epFrontendManager.getStructureElementsFromOthers(ident2, null, ElementType.STRUCTURED_MAP, ElementType.DEFAULT_MAP);
now = System.currentTimeMillis();
logger.info("got all public maps in: " + (now - start) + " ms.");
// simulate queries done in EPMultipleMapController for all public maps:
start = System.currentTimeMillis();
long sharedQ = 0;
long countArtefactQ = 0;
long countChildQ = 0;
long qstart = 0;
int j = 0;
Runtime r = Runtime.getRuntime();
for (PortfolioStructure map : publicMaps) {
j++;
qstart = System.currentTimeMillis();
epFrontendManager.isMapShared((PortfolioStructureMap) map);
sharedQ += System.currentTimeMillis() - qstart;
qstart = System.currentTimeMillis();
epFrontendManager.countArtefactsInMap((PortfolioStructureMap) map);
countArtefactQ += System.currentTimeMillis() - qstart;
// lookup structured maps: if received from a template, would also do a lookup on repository entry!
// EPTargetResource resource = structMap.getTargetResource();
// RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(resource.getOLATResourceable(), false);
qstart = System.currentTimeMillis();
epFrontendManager.countStructureChildren(map);
countChildQ += System.currentTimeMillis() - qstart;
if (j % 100 == 0) {
showStatsForStep(j, start, sharedQ, countArtefactQ, countChildQ, r);
}
}
logger.info("============= get overall stats ==============");
showStatsForStep(mapAmount, start, sharedQ, countArtefactQ, countChildQ, r);
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPStructureManagerTest method testCountStructureElementsFromOthers.
@Test
public void testCountStructureElementsFromOthers() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("EP-tmp-");
PortfolioStructureMap map = epStructureManager.createPortfolioDefaultMap("map-el", "map-element");
epStructureManager.savePortfolioStructure(map);
dbInstance.commitAndCloseSession();
// clone the template
int count = epStructureManager.countStructureElementsFromOthers(user, null);
Assert.assertEquals(0, count);
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method deleteMap_pageAndArtefact.
/**
* Create a map with a page and an artefact. Delete it.
*/
@Test
public void deleteMap_pageAndArtefact() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-4");
PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(id, "Delete map", "Description");
PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(map, "Page while be deleted", "Page description");
assertNotNull(page);
dbInstance.commitAndCloseSession();
// create artefact
AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(id, "Forum");
dbInstance.commitAndCloseSession();
// create the link
epFrontendManager.addArtefactToStructure(id, artefact, page);
dbInstance.commitAndCloseSession();
// reload and check
PortfolioStructure reloadedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
Assert.assertNotNull(reloadedMap);
Assert.assertEquals(map, reloadedMap);
List<PortfolioStructure> reloadedPages = epFrontendManager.loadStructureChildren(reloadedMap);
Assert.assertNotNull(reloadedPages);
Assert.assertEquals(1, reloadedPages.size());
PortfolioStructure reloadedPage = reloadedPages.get(0);
Assert.assertEquals(page, reloadedPage);
List<AbstractArtefact> reloadedArtefacts = epFrontendManager.getArtefacts(reloadedPage);
Assert.assertNotNull(reloadedArtefacts);
Assert.assertEquals(1, reloadedArtefacts.size());
AbstractArtefact reloadedArtefact = reloadedArtefacts.get(0);
Assert.assertEquals(artefact, reloadedArtefact);
dbInstance.commitAndCloseSession();
// delete the map
epFrontendManager.deletePortfolioStructure(reloadedMap);
dbInstance.commit();
// what is deleted?
AbstractArtefact notDeletedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
Assert.assertNotNull(notDeletedArtefact);
PortfolioStructure deletedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
Assert.assertNull(deletedMap);
PortfolioStructure deletedPage = epFrontendManager.loadPortfolioStructureByKey(page.getKey());
Assert.assertNull(deletedPage);
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method mergeTwoUserPolicies.
@Test
public void mergeTwoUserPolicies() {
// create a map
PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Remove policies", "Description");
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
assertNotNull(page1);
dbInstance.commitAndCloseSession();
// save a list of policies
List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
// first user policy
EPMapPolicy userPolicy1 = new EPMapPolicy();
userPolicy1.setType(Type.user);
userPolicy1.getIdentities().add(ident2);
userPolicy1.getIdentities().add(ident3);
policies.add(userPolicy1);
// second user policy
EPMapPolicy userPolicy2 = new EPMapPolicy();
userPolicy2.setType(Type.user);
userPolicy2.getIdentities().add(ident1);
policies.add(userPolicy2);
epFrontendManager.updateMapPolicies(map, policies);
dbInstance.commitAndCloseSession();
// check if the policies are correctly merged
List<EPMapPolicy> mergedPolicies = epFrontendManager.getMapPolicies(map);
assertNotNull(mergedPolicies);
assertEquals(1, mergedPolicies.size());
EPMapPolicy mergedPolicy = mergedPolicies.get(0);
List<Identity> identities = mergedPolicy.getIdentities();
assertEquals(3, identities.size());
int count1, count2, count3;
count1 = count2 = count3 = 0;
for (Identity identity : identities) {
if (identity.equalsByPersistableKey(ident1)) {
count1++;
} else if (identity.equalsByPersistableKey(ident2)) {
count2++;
} else if (identity.equalsByPersistableKey(ident3)) {
count3++;
}
}
assertEquals(1, count1);
assertEquals(1, count2);
assertEquals(1, count3);
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPMultipleMapController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
super.event(ureq, source, event);
if (source == delMapCtrl) {
if (DialogBoxUIFactory.isYesEvent(event)) {
PortfolioStructure mapToDel = (PortfolioStructure) ((DialogBoxController) source).getUserObject();
String title = mapToDel.getTitle();
ePFMgr.deletePortfolioStructure(mapToDel);
showInfo("delete.map.success", title);
ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrapPortfolioOres(mapToDel));
ThreadLocalUserActivityLogger.log(EPLoggingAction.EPORTFOLIO_MAP_REMOVED, getClass());
initOrUpdateMaps(ureq);
}
} else if (source == copyMapCtrl) {
if (event.equals(Event.CANCELLED_EVENT)) {
fireEvent(ureq, Event.CANCELLED_EVENT);
return;
}
int pos = DialogBoxUIFactory.getButtonPos(event);
boolean withArtefacts = false;
PortfolioStructure mapToCopy = (PortfolioStructure) ((DialogBoxController) source).getUserObject();
// shift clicked pos, when "with artefacts" was hidden before
if (!ePFMgr.isMapOwner(getIdentity(), mapToCopy))
pos++;
if (pos == 2) {
// clicked cancel button
fireEvent(ureq, Event.CANCELLED_EVENT);
return;
} else if (pos == 0)
withArtefacts = true;
PortfolioStructureMap targetMap = ePFMgr.createAndPersistPortfolioDefaultMap(getIdentity(), translate("map.copy.of", mapToCopy.getTitle()), mapToCopy.getDescription());
ePFMgr.copyStructureRecursively(mapToCopy, targetMap, withArtefacts);
// open the map
String title = targetMap.getTitle();
showInfo("copy.map.success", title);
initOrUpdateMaps(ureq);
String businessPath = "[" + targetMap.getClass().getSimpleName() + ":" + targetMap.getResourceableId() + "]";
NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
} else if (source == mapViewCtrl) {
if (EPStructureEvent.CLOSE.equals(event.getCommand())) {
myPanel.popContent();
fireEvent(ureq, event);
removeAsListenerAndDispose(mapViewCtrl);
mapViewCtrl = null;
// refresh on close (back-link) to prevent stale object errors, when map got changed meanwhile
initOrUpdateMaps(ureq);
addToHistory(ureq);
} else if (EPStructureEvent.SUBMIT.equals(event.getCommand()) || event.equals(Event.CHANGED_EVENT)) {
// refresh on submission of a map or on any other changes which needs an ui-update
initOrUpdateMaps(ureq);
}
} else if (source == shareListController) {
shareBox.deactivate();
removeAsListenerAndDispose(shareListController);
initOrUpdateMaps(ureq);
}
if (event instanceof EPStructureChangeEvent) {
// event from child
String evCmd = event.getCommand();
if (evCmd.equals(EPStructureChangeEvent.ADDED) || evCmd.equals(EPStructureChangeEvent.CHANGED)) {
initOrUpdateMaps(ureq);
}
}
}
Aggregations