Search in sources :

Example 26 with EPStructuredMap

use of org.olat.portfolio.model.structel.EPStructuredMap in project openolat by klemens.

the class EPStructureManager method copyStructureRecursively.

protected void copyStructureRecursively(PortfolioStructure source, PortfolioStructure target, boolean withArtefacts) {
    // all changes are overwritten
    EPStructureElement targetEl = (EPStructureElement) target;
    if (targetEl instanceof EPStructuredMap) {
        ((EPStructuredMap) targetEl).setCopyDate(new Date());
    }
    // update the source
    dbInstance.updateObject(source);
    // reconnect to the session
    EPStructureElement sourceEl = (EPStructureElement) source;
    targetEl.setStyle(sourceEl.getStyle());
    copyEPStructureElementRecursively(sourceEl, targetEl, withArtefacts, true);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) Date(java.util.Date)

Example 27 with EPStructuredMap

use of org.olat.portfolio.model.structel.EPStructuredMap in project openolat by klemens.

the class EPFrontendManager method synchronizeStructuredMapToUserCopy.

/**
 * sync map with its former source (template)
 */
public boolean synchronizeStructuredMapToUserCopy(PortfolioStructureMap map) {
    if (map == null)
        return false;
    final EPStructuredMap userMap = (EPStructuredMap) map;
    Boolean synched = coordinator.getSyncer().doInSync(map.getOlatResource(), new SyncerCallback<Boolean>() {

        public Boolean execute() {
            if (userMap.getStructuredMapSource() == null) {
                return Boolean.FALSE;
            }
            // need to reload it, I don't know why
            Long templateKey = userMap.getStructuredMapSource().getKey();
            userMap.setLastSynchedDate(new Date());
            PortfolioStructure template = structureManager.loadPortfolioStructureByKey(templateKey);
            structureManager.syncStructureRecursively(template, userMap, true);
            return Boolean.TRUE;
        }
    });
    return synched.booleanValue();
}
Also used : EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Date(java.util.Date)

Example 28 with EPStructuredMap

use of org.olat.portfolio.model.structel.EPStructuredMap in project openolat by klemens.

the class EPFrontendManager method submitMap.

private void submitMap(PortfolioStructureMap map, boolean logActivity, Role by) {
    // add an exception
    if (!(map instanceof EPStructuredMap))
        return;
    EPStructuredMap submittedMap = (EPStructuredMap) map;
    structureManager.submitMap(submittedMap);
    EPTargetResource resource = submittedMap.getTargetResource();
    OLATResourceable courseOres = resource.getOLATResourceable();
    ICourse course = CourseFactory.loadCourse(courseOres);
    AssessmentManager am = course.getCourseEnvironment().getAssessmentManager();
    CourseNode courseNode = course.getRunStructure().getNode(resource.getSubPath());
    List<Identity> owners = policyManager.getOwners(submittedMap);
    for (Identity owner : owners) {
        if (courseNode != null) {
            // courseNode might have been deleted meanwhile
            IdentityEnvironment ienv = new IdentityEnvironment();
            ienv.setIdentity(owner);
            UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
            if (logActivity) {
                am.incrementNodeAttempts(courseNode, owner, uce, by);
            } else {
                am.incrementNodeAttemptsInBackground(courseNode, owner, uce);
            }
            RepositoryEntry referenceEntry = courseNode.getReferencedRepositoryEntry();
            RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
            assessmentService.updateAssessmentEntry(owner, courseEntry, courseNode.getIdent(), referenceEntry, AssessmentEntryStatus.inReview);
        }
        assessmentNotificationsHandler.markPublisherNews(owner, course.getResourceableId());
        log.audit("Map " + map + " from " + owner.getName() + " has been submitted.");
    }
}
Also used : EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) EPTargetResource(org.olat.portfolio.model.structel.EPTargetResource) OLATResourceable(org.olat.core.id.OLATResourceable) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessmentManager(org.olat.course.assessment.AssessmentManager) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 29 with EPStructuredMap

use of org.olat.portfolio.model.structel.EPStructuredMap in project openolat by klemens.

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());
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPPage(org.olat.portfolio.model.structel.EPPage) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 30 with EPStructuredMap

use of org.olat.portfolio.model.structel.EPStructuredMap in project openolat by klemens.

the class EPStructureManagerTest method testLoadPortfolioStructuredMaps.

@Test
public void testLoadPortfolioStructuredMaps() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("EP-tmp-");
    // a template
    PortfolioStructureMap template = epStructureManager.createPortfolioMapTemplate(user, "paged-parent-structure-el", "parent-structure-element");
    epStructureManager.savePortfolioStructure(template);
    dbInstance.commitAndCloseSession();
    // clone the template
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioStructuredMap(template, user, "cloned-map", "cloned-map-from-template", null, null, null);
    ((EPStructuredMap) map).setReturnDate(new Date());
    EPTargetResource targetResource = ((EPStructuredMap) map).getTargetResource();
    targetResource.setResourceableTypeName("CourseModule");
    targetResource.setResourceableId(234l);
    targetResource.setSubPath(UUID.randomUUID().toString());
    targetResource.setBusinessPath("[RepositoryEntry:23647600][CourseNode:934600]");
    epStructureManager.savePortfolioStructure(map);
    dbInstance.commitAndCloseSession();
    // load the cloned map another map
    List<PortfolioStructureMap> myCloneAlt = epStructureManager.loadPortfolioStructuredMaps(user, targetResource.getOLATResourceable(), targetResource.getSubPath(), targetResource.getBusinessPath());
    Assert.assertNotNull(myCloneAlt);
    Assert.assertEquals(1, myCloneAlt.size());
    Assert.assertEquals(map, myCloneAlt.get(0));
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) EPTargetResource(org.olat.portfolio.model.structel.EPTargetResource) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Aggregations

EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)34 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)18 EPTargetResource (org.olat.portfolio.model.structel.EPTargetResource)16 Date (java.util.Date)14 RepositoryEntry (org.olat.repository.RepositoryEntry)12 Test (org.junit.Test)10 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)10 Identity (org.olat.core.id.Identity)8 ArrayList (java.util.ArrayList)6 OLATResource (org.olat.resource.OLATResource)6 OLATResourceable (org.olat.core.id.OLATResourceable)4 ICourse (org.olat.course.ICourse)4 CourseNode (org.olat.course.nodes.CourseNode)4 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4 HashSet (java.util.HashSet)2 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)2 Component (org.olat.core.gui.components.Component)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2