use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method testSyncMapTemplateToUserMap.
@Test
public void testSyncMapTemplateToUserMap() {
// 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 templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
// create five pages
List<PortfolioStructure> pageRefs = new ArrayList<PortfolioStructure>();
List<PortfolioStructure> elementRefs = new ArrayList<PortfolioStructure>();
for (int i = 0; i < 5; i++) {
PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(templateEl, "sync-template-page-" + i, "sync-template-page-" + i);
pageRefs.add(page);
for (int j = 0; j < 5; j++) {
PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(page, "template-structure-" + i + "." + j, "template-structure-" + i + "." + j);
epStructureManager.addCollectRestriction(struct, "Forum", "minimum", 2);
epStructureManager.savePortfolioStructure(struct);
elementRefs.add(struct);
}
}
// save the template
dbInstance.commitAndCloseSession();
// end create template
// ////////////////////
// make the copy
PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
dbInstance.commitAndCloseSession();
assertNotNull(map);
// ////////////////////////////////
// shuffle the pages and delete one
PortfolioStructure retrievedTemplateEl = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedTemplateEl);
epStructureManager.moveUp(retrievedTemplateEl, pages.get(1));
epStructureManager.moveDown(retrievedTemplateEl, pages.get(2));
epStructureManager.removeStructure(retrievedTemplateEl, pages.get(3));
epStructureManager.savePortfolioStructure(retrievedTemplateEl);
// shuffle a page
List<PortfolioStructure> page1Children = epFrontendManager.loadStructureChildren(pages.get(1));
epStructureManager.moveUp(pages.get(1), page1Children.get(3));
epStructureManager.moveUp(pages.get(1), page1Children.get(2));
epStructureManager.moveUp(pages.get(1), page1Children.get(4));
// and add an element and sub-elements
PortfolioStructure newStruct = epFrontendManager.createAndPersistPortfolioStructureElement(pages.get(1), "new-template-structure-1.6", "template-structure-1.6");
epStructureManager.addCollectRestriction(pages.get(1), "Forum", "minimum", 2);
epStructureManager.savePortfolioStructure(newStruct);
epStructureManager.savePortfolioStructure(pages.get(1));
for (int k = 0; k < 5; k++) {
PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(newStruct, "new-template-structure-2." + k, "template-structure-2." + k);
epStructureManager.addCollectRestriction(struct, "bc", "minimum", 2);
epStructureManager.savePortfolioStructure(struct);
elementRefs.add(struct);
}
dbInstance.commitAndCloseSession();
// end shuffle the pages
// ////////////////////////////////
// //////////////////
// check the template
PortfolioStructure retrievedTemplate2El = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
assertNotNull(retrievedTemplate2El);
assertTrue(retrievedTemplate2El instanceof EPStructuredMapTemplate);
List<PortfolioStructure> retrievedPages2 = epFrontendManager.loadStructureChildren(retrievedTemplate2El);
assertEquals(4, retrievedPages2.size());
assertEquals(4, ((EPStructuredMapTemplate) retrievedTemplate2El).getInternalChildren().size());
// check the shuffled pages
assertEquals(pageRefs.get(1).getKey(), retrievedPages2.get(0).getKey());
assertEquals(pageRefs.get(0).getKey(), retrievedPages2.get(1).getKey());
assertEquals(pageRefs.get(2).getKey(), retrievedPages2.get(2).getKey());
assertEquals(pageRefs.get(4).getKey(), retrievedPages2.get(3).getKey());
// check added element
List<PortfolioStructure> retrievedChildren2 = epFrontendManager.loadStructureChildren(retrievedPages2.get(0));
assertEquals(6, retrievedChildren2.size());
dbInstance.commitAndCloseSession();
// check the template
// //////////////////
// sync the map
epFrontendManager.synchronizeStructuredMapToUserCopy(map);
dbInstance.commitAndCloseSession();
// ///////////////
// check the sync
PortfolioStructure synchedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
assertNotNull(synchedMap);
assertTrue(synchedMap instanceof EPStructuredMap);
List<PortfolioStructure> synchedPages = epFrontendManager.loadStructureChildren(synchedMap);
assertNotNull(synchedPages);
assertEquals(4, synchedPages.size());
assertEquals(((EPStructureElement) pageRefs.get(1)).getTitle(), ((EPStructureElement) synchedPages.get(0)).getTitle());
assertEquals(((EPStructureElement) pageRefs.get(0)).getTitle(), ((EPStructureElement) synchedPages.get(1)).getTitle());
assertEquals(((EPStructureElement) pageRefs.get(2)).getTitle(), ((EPStructureElement) synchedPages.get(2)).getTitle());
assertEquals(((EPStructureElement) pageRefs.get(4)).getTitle(), ((EPStructureElement) synchedPages.get(3)).getTitle());
// check synched key
assertEquals(((EPStructureElement) pageRefs.get(1)).getKey(), ((EPStructureElement) synchedPages.get(0)).getStructureElSource());
assertEquals(((EPStructureElement) pageRefs.get(0)).getKey(), ((EPStructureElement) synchedPages.get(1)).getStructureElSource());
assertEquals(((EPStructureElement) pageRefs.get(2)).getKey(), ((EPStructureElement) synchedPages.get(2)).getStructureElSource());
assertEquals(((EPStructureElement) pageRefs.get(4)).getKey(), ((EPStructureElement) synchedPages.get(3)).getStructureElSource());
// check the new elements
List<PortfolioStructure> retrievedPage1Children = epFrontendManager.loadStructureChildren(synchedPages.get(0));
assertEquals(6, retrievedPage1Children.size());
PortfolioStructure retrievedNewStruct = retrievedPage1Children.get(5);
assertEquals("new-template-structure-1.6", ((EPStructureElement) retrievedNewStruct).getTitle());
List<PortfolioStructure> retrievedNewStructChildren = epFrontendManager.loadStructureChildren(retrievedNewStruct);
assertNotNull(retrievedNewStructChildren);
assertEquals(5, retrievedNewStructChildren.size());
for (int k = 0; k < 5; k++) {
assertEquals("new-template-structure-2." + k, ((EPStructureElement) retrievedNewStructChildren.get(k)).getTitle());
}
// end check the sync
// //////////////////
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method isArtefactsInStructure.
@Test
public void isArtefactsInStructure() {
// create two artefacts
AbstractArtefact artefact1 = epFrontendManager.createAndPersistArtefact(ident1, "text");
assertNotNull(artefact1);
AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "bc");
assertNotNull(artefact2);
dbInstance.commitAndCloseSession();
// create a map with a page and the page has two artefacts
PortfolioStructureMap originalMap = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Title", "Description");
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(originalMap, "Page title", "Page description");
PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(originalMap, "Page title", "Page description");
boolean successfullLink1 = epFrontendManager.addArtefactToStructure(ident1, artefact1, page1);
assertTrue(successfullLink1);
boolean successfullLink2 = epFrontendManager.addArtefactToStructure(ident1, artefact2, page2);
assertTrue(successfullLink2);
dbInstance.commitAndCloseSession();
assertTrue(epFrontendManager.isArtefactInStructure(artefact1, page1));
assertFalse(epFrontendManager.isArtefactInStructure(artefact1, page2));
assertFalse(epFrontendManager.isArtefactInStructure(artefact2, page1));
assertTrue(epFrontendManager.isArtefactInStructure(artefact2, page2));
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
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.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method isStructuredMapOwner.
/**
* Same workflow as the repository. This workflow is pretty critical.
*/
@Test
public void isStructuredMapOwner() {
OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
// create a repository entry
RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "test repo", "desc repo", resource, RepositoryEntry.ACC_OWNERS);
dbInstance.commitAndCloseSession();
// create the template owned by ident1
PortfolioStructureMap template = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
assertNotNull(page1);
dbInstance.commitAndCloseSession();
// assign the template to ident2
PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, template, addedEntry, null, null, null);
assertNotNull(map);
dbInstance.commitAndCloseSession();
// check if ident2 is owner of the map
assertTrue(epFrontendManager.isMapOwner(ident2, map.getOlatResource()));
// check if ident1 is not the owner of the map
assertFalse(epFrontendManager.isMapOwner(ident1, map.getOlatResource()));
// check if ident1 is owner of the template
assertTrue(epFrontendManager.isMapOwner(ident1, template.getOlatResource()));
}
use of org.olat.portfolio.model.structel.PortfolioStructureMap in project OpenOLAT by OpenOLAT.
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());
}
Aggregations