use of org.olat.portfolio.manager.EPMapPolicy in project openolat by klemens.
the class EPFrontendManagerTest method allUserPolicies.
@Test
public void allUserPolicies() {
// create a map
PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
assertNotNull(page1);
dbInstance.commitAndCloseSession();
// check visiblity (is owner)
assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
// check visibility (no policy)
assertFalse(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
// check not visible (no policy)
assertFalse(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
// add all user policy
EPMapPolicy userPolicy = new EPMapPolicy();
userPolicy.setType(Type.allusers);
epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
dbInstance.commitAndCloseSession();
// one policy
List<EPMapPolicy> policies1 = epFrontendManager.getMapPolicies(map);
assertEquals(1, policies1.size());
// check visiblity (is owner)
assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
// check visibility (is user)
assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
// check not visible (is user)
assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
}
use of org.olat.portfolio.manager.EPMapPolicy in project openolat by klemens.
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.manager.EPMapPolicy in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method allMapPolicies.
@Test
public void allMapPolicies() {
// create a map
PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "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>();
// user policy
EPMapPolicy userPolicy = new EPMapPolicy();
userPolicy.setType(Type.user);
userPolicy.getIdentities().add(ident2);
userPolicy.getIdentities().add(ident3);
policies.add(userPolicy);
// invitation
Invitation invitation = invitationDao.createAndPersistInvitation();
invitation.setFirstName("John");
invitation.setLastName("Doe");
invitation.setMail("john@doe.ch");
EPMapPolicy invitationPolicy = new EPMapPolicy();
invitationPolicy.setType(Type.invitation);
invitationPolicy.setInvitation(invitation);
policies.add(invitationPolicy);
epFrontendManager.updateMapPolicies(map, policies);
dbInstance.commitAndCloseSession();
// check visiblity (is owner)
assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
// check visibility (is in policy)
assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
// check visible (is in policy)
assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
// retrieved policies
List<EPMapPolicy> savedPolicies = epFrontendManager.getMapPolicies(map);
assertTrue(!savedPolicies.isEmpty());
}
use of org.olat.portfolio.manager.EPMapPolicy 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);
}
use of org.olat.portfolio.manager.EPMapPolicy 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);
}
Aggregations