Search in sources :

Example 6 with SynchedBinder

use of org.olat.modules.portfolio.model.SynchedBinder in project openolat by klemens.

the class BinderListController method doOpenBinder.

protected BinderController doOpenBinder(UserRequest ureq, BinderRef row) {
    SynchedBinder binder = portfolioService.loadAndSyncBinder(row);
    if (binder.isChanged()) {
        showInfo("warning.binder.synched");
    }
    BinderController selectedBinderCtrl = doOpenBinder(ureq, binder.getBinder());
    if (row instanceof BinderRow) {
        VFSLeaf image = portfolioService.getPosterImageLeaf(binder.getBinder());
        ((BinderRow) row).setBackgroundImage(image);
    }
    return selectedBinderCtrl;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BinderRow(org.olat.modules.portfolio.ui.model.BinderRow) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder)

Example 7 with SynchedBinder

use of org.olat.modules.portfolio.model.SynchedBinder in project openolat by klemens.

the class BinderListController method doCreateBinderFromTemplate.

private void doCreateBinderFromTemplate(UserRequest ureq, RepositoryEntry entry) {
    Binder templateBinder = portfolioService.getBinderByResource(entry.getOlatResource());
    Binder newBinder = portfolioService.assignBinder(getIdentity(), templateBinder, null, null, null);
    DBFactory.getInstance().commit();
    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(newBinder);
    newBinder = synchedBinder.getBinder();
    doOpenBinder(ureq, newBinder).activate(ureq, null, null);
}
Also used : SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder)

Example 8 with SynchedBinder

use of org.olat.modules.portfolio.model.SynchedBinder in project openolat by klemens.

the class BinderListController method doCreateBinderFromCourseTemplate.

private void doCreateBinderFromCourseTemplate(UserRequest ureq, CourseTemplateRow row) {
    RepositoryEntry courseEntry = row.getCourseEntry();
    RepositoryEntry templateEntry = row.getTemplateEntry();
    PortfolioCourseNode courseNode = row.getCourseNode();
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    Binder copyBinder = portfolioService.getBinder(getIdentity(), templateBinder, courseEntry, courseNode.getIdent());
    if (copyBinder == null) {
        Date deadline = courseNode.getDeadline();
        copyBinder = portfolioService.assignBinder(getIdentity(), templateBinder, courseEntry, courseNode.getIdent(), deadline);
        DBFactory.getInstance().commit();
        SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(copyBinder);
        copyBinder = synchedBinder.getBinder();
        if (copyBinder != null) {
            showInfo("map.copied", StringHelper.escapeHtml(templateBinder.getTitle()));
            ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(copyBinder));
            ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_TASK_STARTED, getClass());
        }
    }
    doOpenBinder(ureq, copyBinder).activate(ureq, null, null);
}
Also used : SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Date(java.util.Date)

Example 9 with SynchedBinder

use of org.olat.modules.portfolio.model.SynchedBinder in project openolat by klemens.

the class PortfolioServiceTest method deleteTemplateBinder.

@Test
public void deleteTemplateBinder() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-20");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    List<SectionRef> sections = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        SectionRef templateSectionRef = portfolioService.appendNewSection(i + ". section ", "Section " + i, null, null, templateBinder);
        dbInstance.commit();
        sections.add(templateSectionRef);
        Section templateSection = portfolioService.getSection(templateSectionRef);
        for (int j = 0; j < 10; j++) {
            Assignment assignment = portfolioService.addAssignment(i + "_" + j + " Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
            Assert.assertNotNull(assignment);
        }
        dbInstance.commit();
    }
    // collect the page
    List<Page> assignmentPages = new ArrayList<>();
    for (int k = 0; k < 10; k++) {
        // get a binder from the template
        Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-13" + k);
        Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
        SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
        binder = synchedBinder.getBinder();
        dbInstance.commitAndCloseSession();
        List<Assignment> assignments = portfolioService.getAssignments(binder, null);
        for (Assignment assignment : assignments) {
            Assignment startedAssignment = portfolioService.startAssignment(assignment.getKey(), id);
            Assert.assertNotNull(startedAssignment);
            Page page = startedAssignment.getPage();
            assignmentPages.add(page);
            Assert.assertNotNull(page.getBody());
            dbInstance.commit();
        }
        dbInstance.commitAndCloseSession();
    }
    // delete
    boolean deleted = portfolioService.deleteBinderTemplate(templateBinder, templateEntry);
    dbInstance.commit();
    Assert.assertTrue(deleted);
    // check that the pages exists
    Assert.assertFalse(assignmentPages.isEmpty());
    for (Page page : assignmentPages) {
        Page reloadedPage = portfolioService.getPageByKey(page.getKey());
        Assert.assertNotNull(reloadedPage);
        Section section = reloadedPage.getSection();
        Assert.assertNotNull(section);
    }
}
Also used : ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page) RepositoryEntry(org.olat.repository.RepositoryEntry) Section(org.olat.modules.portfolio.Section) Assignment(org.olat.modules.portfolio.Assignment) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) Identity(org.olat.core.id.Identity) SectionRef(org.olat.modules.portfolio.SectionRef) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Test(org.junit.Test)

Example 10 with SynchedBinder

use of org.olat.modules.portfolio.model.SynchedBinder in project openolat by klemens.

the class PortfolioServiceTest method deleteSynchedBinder.

@Test
public void deleteSynchedBinder() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-12");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-13");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();
    // get section
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
    dbInstance.commit();
    // make 2 assignments
    Section templateSection = portfolioService.getSection(sectionRef);
    Assignment assignment_1 = portfolioService.addAssignment("1 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
    Assignment assignment_2 = portfolioService.addAssignment("2 Assignment", "", "", AssignmentType.essay, templateSection, false, false, false, null);
    dbInstance.commit();
    List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
    Assert.assertEquals(2, templateAssignments.size());
    // synched and check the sections order
    Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
    binder = synchedBinder.getBinder();
    dbInstance.commitAndCloseSession();
    List<Assignment> assignments = portfolioService.getAssignments(binder, null);
    Assignment startedAssignment_1 = portfolioService.startAssignment(assignments.get(0).getKey(), id);
    Assignment startedAssignment_2 = portfolioService.startAssignment(assignments.get(1).getKey(), id);
    Long startedPageKey_1 = startedAssignment_1.getPage().getKey();
    Long startedPageKey_2 = startedAssignment_2.getPage().getKey();
    dbInstance.commitAndCloseSession();
    // add some comments
    OLATResourceable startedPageOres_1 = OresHelper.createOLATResourceableInstance(Page.class, startedPageKey_1);
    userCommentsDao.createComment(id, startedPageOres_1, null, "Hello");
    // delete
    boolean deleted = portfolioService.deleteBinder(binder);
    dbInstance.commit();
    Assert.assertTrue(deleted);
    // check that the template is save
    Assignment reloadAssignment_1 = assignmentDao.loadAssignmentByKey(assignment_1.getKey());
    Assert.assertNotNull(reloadAssignment_1);
    Assignment reloadAssignment_2 = assignmentDao.loadAssignmentByKey(assignment_2.getKey());
    Assert.assertNotNull(reloadAssignment_2);
    // check that the binder is really deleted
    Binder reloadedBinder = binderDao.loadByKey(binder.getKey());
    Assert.assertNull(reloadedBinder);
    Assignment reloadStartedAssignment_1 = assignmentDao.loadAssignmentByKey(startedAssignment_1.getKey());
    Assert.assertNull(reloadStartedAssignment_1);
    Assignment reloadStartedAssignment_2 = assignmentDao.loadAssignmentByKey(startedAssignment_2.getKey());
    Assert.assertNull(reloadStartedAssignment_2);
    Page reloadedStartedPage_1 = pageDao.loadByKey(startedPageKey_1);
    Assert.assertNull(reloadedStartedPage_1);
    Page reloadedStartedPage_2 = pageDao.loadByKey(startedPageKey_2);
    Assert.assertNull(reloadedStartedPage_2);
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) OLATResourceable(org.olat.core.id.OLATResourceable) Page(org.olat.modules.portfolio.Page) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SectionRef(org.olat.modules.portfolio.SectionRef) Section(org.olat.modules.portfolio.Section) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Test(org.junit.Test)

Aggregations

SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)24 Binder (org.olat.modules.portfolio.Binder)22 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Test (org.junit.Test)16 Identity (org.olat.core.id.Identity)16 Section (org.olat.modules.portfolio.Section)16 Assignment (org.olat.modules.portfolio.Assignment)14 Page (org.olat.modules.portfolio.Page)14 SectionRef (org.olat.modules.portfolio.SectionRef)14 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 PortfolioCourseNode (org.olat.course.nodes.PortfolioCourseNode)2 AssessedBinder (org.olat.modules.portfolio.model.AssessedBinder)2 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)2 BinderRow (org.olat.modules.portfolio.ui.model.BinderRow)2