use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method isTemplateInUse.
@Test
public void isTemplateInUse() {
// create a template
OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
// create a repository entry
RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "Template in user", "Template in use", resource, RepositoryEntry.ACC_OWNERS);
// create the template owned by ident1
PortfolioStructureMap template = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
dbInstance.commitAndCloseSession();
// add a page to it
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
assertNotNull(page1);
dbInstance.commitAndCloseSession();
// check: the template is not in use
assertFalse(epFrontendManager.isTemplateInUse(template, null, null, null));
// use the template: assign the template to ident2
PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, template, addedEntry, null, null, null);
assertNotNull(map);
dbInstance.commitAndCloseSession();
// check: the template is in use
assertTrue(epFrontendManager.isTemplateInUse(template, null, null, null));
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method testAssignMapTemplateToUser.
@Test
public void testAssignMapTemplateToUser() {
// create a template
OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
// create a repository entry
RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "template-1", "map-template-1", resource, RepositoryEntry.ACC_OWNERS);
dbInstance.commitAndCloseSession();
// create the template owned by ident1
PortfolioStructureMap templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
// first page
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-1", "template-page-1");
// structure element 1 from page 1
PortfolioStructure struct11 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.1", "template-structure-1.1");
epStructureManager.addCollectRestriction(struct11, "Forum", "minimum", 2);
epStructureManager.savePortfolioStructure(struct11);
// structure element 2 from page 1
PortfolioStructure struct12 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.2", "template-structure-1.2");
assertNotNull(struct12);
// first page
PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-2", "template-page-2");
// structure element 1 from page 2
PortfolioStructure struct21 = epFrontendManager.createAndPersistPortfolioStructureElement(page2, "template-structure-2.1", "template-structure-2.1");
epStructureManager.addCollectRestriction(struct21, "bc", "maximum", 4);
epStructureManager.savePortfolioStructure(struct21);
// save the template
dbInstance.commitAndCloseSession();
// make the copy
PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
dbInstance.commitAndCloseSession();
assertNotNull(map);
// check the copy
PortfolioStructure retrievedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
assertNotNull(retrievedMap);
assertTrue(retrievedMap instanceof EPStructuredMap);
assertNotNull(((EPStructuredMap) retrievedMap).getStructuredMapSource());
assertEquals(templateEl.getKey(), ((EPStructuredMap) retrievedMap).getStructuredMapSource().getKey());
// check pages of the copied map
List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedMap);
assertNotNull(pages);
assertEquals(2, pages.size());
assertTrue(pages.get(0) instanceof EPPage);
assertTrue(pages.get(1) instanceof EPPage);
assertEquals("template-page-1", ((EPStructureElement) pages.get(0)).getTitle());
assertEquals("template-page-2", ((EPStructureElement) pages.get(1)).getTitle());
// check root
assertNotNull(((EPStructureElement) pages.get(0)).getRoot());
assertEquals(retrievedMap.getKey(), ((EPStructureElement) pages.get(0)).getRoot().getKey());
// check children of the pages
List<PortfolioStructure> structs1 = epFrontendManager.loadStructureChildren(pages.get(0));
assertNotNull(structs1);
assertEquals(2, structs1.size());
assertTrue(structs1.get(0) instanceof EPStructureElement);
assertTrue(structs1.get(1) instanceof EPStructureElement);
EPStructureElement struct11El = (EPStructureElement) structs1.get(0);
assertEquals("template-structure-1.1", struct11El.getTitle());
assertEquals("template-structure-1.2", ((EPStructureElement) structs1.get(1)).getTitle());
// check root
assertNotNull(((EPStructureElement) structs1.get(0)).getRoot());
assertEquals(retrievedMap.getKey(), ((EPStructureElement) structs1.get(0)).getRoot().getKey());
assertNotNull(((EPStructureElement) structs1.get(1)).getRoot());
assertEquals(retrievedMap.getKey(), ((EPStructureElement) structs1.get(1)).getRoot().getKey());
// check collect restriction
assertNotNull(struct11El.getCollectRestrictions());
assertEquals("Forum", struct11El.getCollectRestrictions().get(0).getArtefactType());
assertEquals("minimum", struct11El.getCollectRestrictions().get(0).getRestriction());
assertEquals(2, struct11El.getCollectRestrictions().get(0).getAmount());
List<PortfolioStructure> structs2 = epFrontendManager.loadStructureChildren(pages.get(1));
assertNotNull(structs2);
assertEquals(1, structs2.size());
assertTrue(structs2.get(0) instanceof EPStructureElement);
EPStructureElement struct21El = (EPStructureElement) structs2.get(0);
assertEquals("template-structure-2.1", struct21El.getTitle());
// check root
assertNotNull(struct21El.getRoot());
assertEquals(retrievedMap.getKey(), struct21El.getRoot().getKey());
// check collect restriction
assertNotNull(struct21El.getCollectRestrictions());
assertEquals("bc", struct21El.getCollectRestrictions().get(0).getArtefactType());
assertEquals("maximum", struct21El.getCollectRestrictions().get(0).getRestriction());
assertEquals(4, struct21El.getCollectRestrictions().get(0).getAmount());
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap 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.model.structel.PortfolioStructureMap 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.model.structel.PortfolioStructureMap 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();
}
Aggregations