Search in sources :

Example 11 with Assignment

use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.

the class PortfolioServiceTest method syncBinder_moveInNewSection_moreComplexCase.

@Test
public void syncBinder_moveInNewSection_moreComplexCase() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-11");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();
    // make 2 sections
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    SectionRef sectionRef0 = portfolioService.getSections(templateBinder).get(0);
    // add 2 sections
    SectionRef sectionRef1 = portfolioService.appendNewSection("1 section ", "Section 1", null, null, templateBinder);
    SectionRef sectionRef2 = portfolioService.appendNewSection("2 section ", "Section 2", null, null, templateBinder);
    dbInstance.commit();
    // make 4 assignments
    Section templateSection0 = portfolioService.getSection(sectionRef0);
    Section templateSection1 = portfolioService.getSection(sectionRef1);
    Section templateSection2 = portfolioService.getSection(sectionRef2);
    Assignment assignment0_1 = portfolioService.addAssignment("0.1 Assignment", "", "", AssignmentType.essay, templateSection0, false, false, false, null);
    Assignment assignment1_1 = portfolioService.addAssignment("1.1 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    Assignment assignment1_2 = portfolioService.addAssignment("1.2 Assignment", "", "", AssignmentType.essay, templateSection1, false, false, false, null);
    Assignment assignment2_1 = portfolioService.addAssignment("2.1 Assignment", "", "", AssignmentType.essay, templateSection2, false, false, false, null);
    Assignment assignment2_2 = portfolioService.addAssignment("2.2 Assignment", "", "", AssignmentType.essay, templateSection2, false, false, false, null);
    dbInstance.commit();
    List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
    Assert.assertEquals(5, templateAssignments.size());
    // a user take the binder and synched it a first time
    Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "74", null);
    dbInstance.commit();
    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(synchedBinder);
    Assert.assertEquals(binder, synchedBinder.getBinder());
    // start all assignments
    List<Assignment> assignments = portfolioService.getAssignments(binder, null);
    Assert.assertEquals(5, assignments.size());
    for (Assignment assignment : assignments) {
        portfolioService.startAssignment(assignment.getKey(), id);
        dbInstance.commit();
    }
    dbInstance.commit();
    // check that the student has it's 4 pages
    List<Page> pages = portfolioService.getPages(binder, null);
    Assert.assertEquals(5, pages.size());
    // author create 2 new sections, move the 4 to the top
    SectionRef sectionRef3 = portfolioService.appendNewSection("3 section ", "Section 3", null, null, templateBinder);
    SectionRef sectionRef4 = portfolioService.appendNewSection("4 section ", "Section 4", null, null, templateBinder);
    dbInstance.commit();
    Section templateSection3 = portfolioService.getSection(sectionRef3);
    Section templateSection4 = portfolioService.getSection(sectionRef4);
    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();
    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();
    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();
    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();
    // add new assignment
    Assignment assignment3_1 = portfolioService.addAssignment("3.1 Assignment", "", "", AssignmentType.essay, templateSection3, false, false, false, null);
    Assignment assignment4_1 = portfolioService.addAssignment("4.1 Assignment", "", "", AssignmentType.essay, templateSection4, false, false, false, null);
    dbInstance.commit();
    // the author move some assignments
    portfolioService.moveAssignment(templateSection1, assignment1_1, templateSection3);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection1, assignment1_2, templateSection2);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection2, assignment2_1, templateSection3);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection2, assignment2_2, templateSection4);
    dbInstance.commitAndCloseSession();
    // update the data of some assignments
    assignment2_1 = assignmentDao.loadAssignmentByKey(assignment2_1.getKey());
    assignment4_1 = assignmentDao.loadAssignmentByKey(assignment4_1.getKey());
    assignment2_1 = portfolioService.updateAssignment(assignment2_1, "2.1 Assignment", "Assignment 2 description", "", AssignmentType.essay, false, false, false, null);
    assignment4_1 = portfolioService.updateAssignment(assignment4_1, "4.1 Assignment", "Assignment 4 description", "", AssignmentType.document, false, false, false, null);
    dbInstance.commit();
    // check the move
    List<Assignment> templateAssignmentsSection0 = portfolioService.getAssignments(templateSection0, null);
    Assert.assertTrue(templateAssignmentsSection0.contains(assignment0_1));
    List<Assignment> templateAssignmentsSection1 = portfolioService.getAssignments(templateSection1, null);
    Assert.assertTrue(templateAssignmentsSection1.isEmpty());
    List<Assignment> templateAssignmentsSection2 = portfolioService.getAssignments(templateSection2, null);
    Assert.assertEquals(1, templateAssignmentsSection2.size());
    Assert.assertTrue(templateAssignmentsSection2.contains(assignment1_2));
    List<Assignment> templateAssignmentsSection3 = portfolioService.getAssignments(templateSection3, null);
    Assert.assertEquals(3, templateAssignmentsSection3.size());
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment1_1));
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment2_1));
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment3_1));
    List<Assignment> templateAssignmentsSection4 = portfolioService.getAssignments(templateSection4, null);
    Assert.assertEquals(2, templateAssignmentsSection4.size());
    Assert.assertTrue(templateAssignmentsSection4.contains(assignment2_2));
    Assert.assertTrue(templateAssignmentsSection4.contains(assignment4_1));
    // synched and check the sections order
    SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
    Binder freshBinder = synchedBinder2.getBinder();
    dbInstance.commitAndCloseSession();
    List<Section> sections = portfolioService.getSections(freshBinder);
    Assert.assertEquals(5, sections.size());
    Section section4 = sections.get(0);
    Section section0 = sections.get(1);
    Section section1 = sections.get(2);
    Section section2 = sections.get(3);
    Section section3 = sections.get(4);
    Assert.assertEquals(templateSection0, section0.getTemplateReference());
    Assert.assertEquals(templateSection1, section1.getTemplateReference());
    Assert.assertEquals(templateSection2, section2.getTemplateReference());
    Assert.assertEquals(templateSection3, section3.getTemplateReference());
    Assert.assertEquals(templateSection4, section4.getTemplateReference());
    // load pages from section 0
    List<Page> pagesSection0 = portfolioService.getPages(section0);
    Assert.assertEquals(1, pagesSection0.size());
    Page page0_1 = pagesSection0.get(0);
    Assert.assertTrue(page0_1.getTitle().equals("0.1 Assignment"));
    // load pages from section 1
    List<Page> pagesSection1 = portfolioService.getPages(section1);
    Assert.assertTrue(pagesSection1.isEmpty());
    // and pages from section 2
    List<Page> pagesSection2 = portfolioService.getPages(section2);
    Assert.assertEquals(1, pagesSection2.size());
    Page page1_2 = pagesSection2.get(0);
    Assert.assertTrue(page1_2.getTitle().equals("1.2 Assignment"));
    // and pages from section 3
    List<Page> pagesSection3 = portfolioService.getPages(section3);
    Assert.assertEquals(2, pagesSection3.size());
    Page page1_1 = pagesSection3.get(0);
    Page page2_1 = pagesSection3.get(1);
    Assert.assertTrue(page1_1.getTitle().equals("1.1 Assignment") || page1_1.getTitle().equals("2.1 Assignment"));
    Assert.assertTrue(page2_1.getTitle().equals("1.1 Assignment") || page2_1.getTitle().equals("2.1 Assignment"));
    // and pages from section 4
    List<Page> pagesSection4 = portfolioService.getPages(section4);
    Assert.assertEquals(1, pagesSection4.size());
    Page page2_2 = pagesSection4.get(0);
    Assert.assertTrue(page2_2.getTitle().equals("2.2 Assignment"));
    // check the assignments
    // section 0
    List<Assignment> assignmentsSection0 = section0.getAssignments();
    Assert.assertEquals(1, assignmentsSection0.size());
    Assignment templateSynchedSection0a = assignmentsSection0.get(0).getTemplateReference();
    Assert.assertTrue(assignment0_1.equals(templateSynchedSection0a));
    // section 1
    List<Assignment> assignmentsSection1 = section1.getAssignments();
    Assert.assertTrue(assignmentsSection1.isEmpty());
    // section 2
    List<Assignment> assignmentsSection2 = section2.getAssignments();
    Assert.assertEquals(1, assignmentsSection2.size());
    Assignment templateSynchedSection2a = assignmentsSection2.get(0).getTemplateReference();
    Assert.assertTrue(assignment1_2.equals(templateSynchedSection2a));
    // section 3
    List<Assignment> assignmentsSection3 = section3.getAssignments();
    Assert.assertEquals(3, assignmentsSection3.size());
    Assignment templateSynchedSection3a = assignmentsSection3.get(0).getTemplateReference();
    Assignment templateSynchedSection3b = assignmentsSection3.get(1).getTemplateReference();
    Assignment templateSynchedSection3c = assignmentsSection3.get(2).getTemplateReference();
    Assert.assertTrue(assignment3_1.equals(templateSynchedSection3a) || assignment3_1.equals(templateSynchedSection3b) || assignment3_1.equals(templateSynchedSection3c));
    Assert.assertTrue(assignment2_1.equals(templateSynchedSection3a) || assignment2_1.equals(templateSynchedSection3b) || assignment2_1.equals(templateSynchedSection3c));
    Assert.assertTrue(assignment1_1.equals(templateSynchedSection3a) || assignment1_1.equals(templateSynchedSection3b) || assignment1_1.equals(templateSynchedSection3c));
    // section 4
    List<Assignment> assignmentsSection4 = section4.getAssignments();
    Assert.assertEquals(2, assignmentsSection4.size());
    Assignment templateSynchedSection4a = assignmentsSection4.get(0).getTemplateReference();
    Assignment templateSynchedSection4b = assignmentsSection4.get(1).getTemplateReference();
    Assert.assertTrue(assignment2_2.equals(templateSynchedSection4a) || assignment2_2.equals(templateSynchedSection4b));
    Assert.assertTrue(assignment4_1.equals(templateSynchedSection4a) || assignment4_1.equals(templateSynchedSection4b));
    // check update of assignments
    Assert.assertEquals("Assignment 2 description", assignment2_1.getSummary());
    Assert.assertEquals("Assignment 4 description", assignment4_1.getSummary());
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) Binder(org.olat.modules.portfolio.Binder) 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)

Example 12 with Assignment

use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.

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)

Example 13 with Assignment

use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.

the class PageMetadataController method initAssignments.

private void initAssignments(UserRequest ureq) {
    boolean needMapper = false;
    List<UserAssignmentInfos> assignmentInfos = new ArrayList<>(assignments.size());
    for (Assignment assignment : assignments) {
        List<File> documents = null;
        File storage = fileStorage.getAssignmentDirectory(assignment);
        if (storage != null) {
            documents = Arrays.<File>asList(storage.listFiles());
            if (documents.size() > 0) {
                needMapper = true;
            }
        }
        UserAssignmentInfos infos = new UserAssignmentInfos(assignment, documents);
        assignmentInfos.add(infos);
    }
    mainVC.contextPut("assignments", assignmentInfos);
    if (needMapper) {
        String mapperUri = registerCacheableMapper(ureq, "assigment-" + page.getKey(), new DocumentMapper());
        mainVC.contextPut("mapperUri", mapperUri);
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) UserAssignmentInfos(org.olat.modules.portfolio.ui.model.UserAssignmentInfos) ArrayList(java.util.ArrayList) File(java.io.File)

Example 14 with Assignment

use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.

the class EvaluationFormHandler method getContent.

@Override
public PageRunElement getContent(UserRequest ureq, WindowControl wControl, PageElement element, PageElementRenderingHints hints) {
    Controller ctrl = null;
    if (element instanceof EvaluationFormPart) {
        PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
        // find assignment
        EvaluationFormPart eva = (EvaluationFormPart) element;
        PageBody body = eva.getBody();
        Assignment assignment = portfolioService.getAssignment(body);
        if (assignment == null) {
            ctrl = getController(ureq, wControl, body, eva);
        } else {
            ctrl = getControllerForAssignment(ureq, wControl, body, assignment, hints.isOnePage());
        }
    }
    if (ctrl == null) {
        Translator translator = Util.createPackageTranslator(PortfolioHomeController.class, ureq.getLocale());
        String title = translator.translate("warning.evaluation.not.visible.title");
        String text = translator.translate("warning.evaluation.not.visible.text");
        ctrl = MessageUIFactory.createWarnMessage(ureq, wControl, title, text);
    }
    return new PageRunControllerElement(ctrl);
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) PageRunControllerElement(org.olat.modules.portfolio.ui.editor.PageRunControllerElement) EvaluationFormPart(org.olat.modules.portfolio.model.EvaluationFormPart) PortfolioService(org.olat.modules.portfolio.PortfolioService) Translator(org.olat.core.gui.translator.Translator) MultiEvaluationFormController(org.olat.modules.portfolio.ui.MultiEvaluationFormController) Controller(org.olat.core.gui.control.Controller) EvaluationFormController(org.olat.modules.forms.ui.EvaluationFormController) PortfolioHomeController(org.olat.modules.portfolio.ui.PortfolioHomeController) PageBody(org.olat.modules.portfolio.PageBody)

Example 15 with Assignment

use of org.olat.modules.portfolio.Assignment in project OpenOLAT by OpenOLAT.

the class AssignmentDAOTest method createBinderWithAssignment.

@Test
public void createBinderWithAssignment() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("assign-1");
    Binder binder = portfolioService.createNewBinder("Assignment binder 1", "Difficult!", null, owner);
    dbInstance.commit();
    portfolioService.appendNewSection("Section", "Assignment section", null, null, binder);
    dbInstance.commit();
    // create assignment
    List<Section> sections = portfolioService.getSections(binder);
    Assignment assignment = assignmentDao.createAssignment("Difficult", "Very difficult", "The difficult content", null, AssignmentType.essay, AssignmentStatus.template, sections.get(0), false, false, false, null);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(assignment);
    Assert.assertNotNull(assignment.getKey());
    Assert.assertNotNull(assignment.getCreationDate());
    Assert.assertNotNull(assignment.getLastModified());
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) Binder(org.olat.modules.portfolio.Binder) Identity(org.olat.core.id.Identity) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Aggregations

Assignment (org.olat.modules.portfolio.Assignment)78 Section (org.olat.modules.portfolio.Section)48 Binder (org.olat.modules.portfolio.Binder)30 Identity (org.olat.core.id.Identity)28 Test (org.junit.Test)26 Page (org.olat.modules.portfolio.Page)26 ArrayList (java.util.ArrayList)24 RepositoryEntry (org.olat.repository.RepositoryEntry)20 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)18 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)18 SectionRef (org.olat.modules.portfolio.SectionRef)16 File (java.io.File)8 HashMap (java.util.HashMap)8 List (java.util.List)8 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 SectionImpl (org.olat.modules.portfolio.model.SectionImpl)8 PortfolioElementRow (org.olat.modules.portfolio.ui.model.PortfolioElementRow)8 Link (org.olat.core.gui.components.link.Link)6