use of org.olat.portfolio.manager.EPMapPolicy 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.manager.EPMapPolicy in project openolat by klemens.
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 klemens.
the class EPFrontendManagerTest method removePolicyWithInvitation.
@Test
public void removePolicyWithInvitation() {
// 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>();
// invitation
Invitation invitation = invitationDao.createAndPersistInvitation();
invitation.setFirstName("John");
invitation.setLastName("Doe");
invitation.setMail("john2@doe.ch");
EPMapPolicy invitationPolicy = new EPMapPolicy();
invitationPolicy.setType(Type.invitation);
invitationPolicy.setInvitation(invitation);
policies.add(invitationPolicy);
map = epFrontendManager.updateMapPolicies(map, policies);
dbInstance.commitAndCloseSession();
// remove the policy
policies.clear();
epFrontendManager.updateMapPolicies(map, policies);
dbInstance.commitAndCloseSession();
// check if the policies and the invitation are deleted
List<EPMapPolicy> deletedPolicies = epFrontendManager.getMapPolicies(map);
assertNotNull(deletedPolicies);
assertTrue(deletedPolicies.isEmpty());
}
use of org.olat.portfolio.manager.EPMapPolicy in project openolat by klemens.
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