Search in sources :

Example 11 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class PageDAOTest method getOwnedPages.

@Test
public void getOwnedPages() {
    // an owned binder
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-1");
    Binder binder = portfolioService.createNewBinder("Binder p2", "A binder with 2 page", null, author);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page1 = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    Page page2 = pageDao.createAndPersist("Page 2", "A page with content.", null, null, true, reloadedSection, null);
    Page page3 = pageDao.createAndPersist("Anime", "Princess Mononoke is the second most famous anime of Miazaki.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    // a not owned binder
    BinderImpl binderAlt = binderDao.createAndPersist("Not my binder", "A binder that I don't own", null, null);
    Section sectionAlt = binderDao.createSection("Section", "First section", null, null, binderAlt);
    dbInstance.commitAndCloseSession();
    Section reloadedSectionAlt = binderDao.loadSectionByKey(sectionAlt.getKey());
    Page pageAlt = pageDao.createAndPersist("Page alt", "A page with alternative content.", null, null, true, reloadedSectionAlt, null);
    dbInstance.commitAndCloseSession();
    // reload
    List<Page> sectionPages = pageDao.getOwnedPages(author, null);
    Assert.assertNotNull(sectionPages);
    Assert.assertEquals(3, sectionPages.size());
    Assert.assertTrue(sectionPages.contains(page1));
    Assert.assertTrue(sectionPages.contains(page2));
    Assert.assertTrue(sectionPages.contains(page3));
    Assert.assertFalse(sectionPages.contains(pageAlt));
    // reload
    List<Page> searchedPages = pageDao.getOwnedPages(author, "Miazaki");
    Assert.assertNotNull(searchedPages);
    Assert.assertEquals(1, searchedPages.size());
    Assert.assertFalse(searchedPages.contains(page1));
    Assert.assertFalse(searchedPages.contains(page2));
    Assert.assertTrue(searchedPages.contains(page3));
    Assert.assertFalse(sectionPages.contains(pageAlt));
}
Also used : Binder(org.olat.modules.portfolio.Binder) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Identity(org.olat.core.id.Identity) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 12 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class EvaluationFormResponseDAOTest method createResponseforPortfolio.

@Test
public void createResponseforPortfolio() {
    // prepare a test case with the binder up to the page body
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("eva-1");
    BinderImpl binder = binderDao.createAndPersist("Binder evaluation 1", "A binder with an evaluation", null, null);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commit();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with an evalutation.", null, null, true, reloadedSection, null);
    dbInstance.commit();
    RepositoryEntry formEntry = createFormEntry("Eva. form for responses");
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    EvaluationFormSession session = evaluationFormSessionDao.createSessionForPortfolio(id, reloadedBody, formEntry);
    dbInstance.commit();
    // create a response
    String responseIdentifier = UUID.randomUUID().toString();
    BigDecimal numericalValue = new BigDecimal("2.2");
    String stringuifiedResponse = numericalValue.toPlainString();
    Path fileResponse = Paths.get("this", "is", "a", "path");
    EvaluationFormResponse response = evaluationFormResponseDao.createResponse(responseIdentifier, numericalValue, stringuifiedResponse, fileResponse, session);
    dbInstance.commit();
    Assert.assertNotNull(response);
    Assert.assertNotNull(response.getKey());
    Assert.assertNotNull(response.getCreationDate());
    Assert.assertNotNull(response.getLastModified());
    Assert.assertEquals(session, response.getSession());
    Assert.assertEquals(numericalValue, response.getNumericalResponse());
    Assert.assertEquals(stringuifiedResponse, response.getStringuifiedResponse());
    Assert.assertEquals(fileResponse, response.getFileResponse());
    Assert.assertEquals(responseIdentifier, response.getResponseIdentifier());
}
Also used : Path(java.nio.file.Path) EvaluationFormSession(org.olat.modules.forms.EvaluationFormSession) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) EvaluationFormResponse(org.olat.modules.forms.EvaluationFormResponse) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 13 with BinderImpl

use of org.olat.modules.portfolio.model.BinderImpl in project OpenOLAT by OpenOLAT.

the class BinderUserInformationsDAOTest method updateBinderUserInformations.

@Test
public void updateBinderUserInformations() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bu-1");
    BinderImpl binder = binderDao.createAndPersist("Binder infos", "Binder with one section.", null, null);
    dbInstance.commitAndCloseSession();
    // update the infos
    binderUserInformationsDAO.updateBinderUserInformations(binder, identity);
    dbInstance.commit();
    // load the infos and check
    BinderUserInformations infos = binderUserInformationsDAO.getBinderUserInfos(binder, identity);
    Assert.assertNotNull(infos);
    Assert.assertNotNull(infos.getKey());
    Assert.assertNotNull(infos.getCreationDate());
    Assert.assertNotNull(infos.getLastModified());
    Assert.assertNotNull(infos.getInitialLaunch());
    Assert.assertNotNull(infos.getRecentLaunch());
    Assert.assertEquals(1, infos.getVisit());
    Assert.assertEquals(binder, infos.getBinder());
    Assert.assertEquals(identity, infos.getIdentity());
}
Also used : BinderUserInformations(org.olat.modules.portfolio.BinderUserInformations) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 14 with BinderImpl

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

the class PortfolioServiceImpl method getRepositoryEntry.

@Override
public RepositoryEntry getRepositoryEntry(Binder binder) {
    OLATResource resource = ((BinderImpl) binder).getOlatResource();
    Long resourceKey = resource.getKey();
    return repositoryService.loadByResourceKey(resourceKey);
}
Also used : OLATResource(org.olat.resource.OLATResource) BinderImpl(org.olat.modules.portfolio.model.BinderImpl)

Example 15 with BinderImpl

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

the class BinderDAO method deleteBinder.

public int deleteBinder(BinderRef binderRef) {
    int rows = userInformationsDAO.deleteBinderUserInfos(binderRef);
    BinderImpl binder = (BinderImpl) loadByKey(binderRef.getKey());
    List<Section> sections = new ArrayList<>(binder.getSections());
    for (Section section : sections) {
        List<Page> pages = new ArrayList<>(section.getPages());
        section.getPages().clear();
        section = dbInstance.getCurrentEntityManager().merge(section);
        for (Page page : pages) {
            if (page != null) {
                rows += pageDao.deletePage(page);
                rows += pageUserInfosDao.delete(page);
            }
        }
        rows += assessmentSectionDao.deleteAssessmentSections(section);
        Group baseGroup = section.getBaseGroup();
        rows += groupDao.removeMemberships(baseGroup);
        dbInstance.getCurrentEntityManager().remove(section);
        dbInstance.getCurrentEntityManager().remove(baseGroup);
        rows += 2;
    }
    binder.getSections().clear();
    Group baseGroup = binder.getBaseGroup();
    rows += groupDao.removeMemberships(baseGroup);
    dbInstance.getCurrentEntityManager().remove(binder);
    dbInstance.getCurrentEntityManager().remove(baseGroup);
    return rows + 2;
}
Also used : Group(org.olat.basesecurity.Group) ArrayList(java.util.ArrayList) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section)

Aggregations

BinderImpl (org.olat.modules.portfolio.model.BinderImpl)64 Section (org.olat.modules.portfolio.Section)40 Test (org.junit.Test)38 Page (org.olat.modules.portfolio.Page)32 Identity (org.olat.core.id.Identity)22 Binder (org.olat.modules.portfolio.Binder)14 PageUserInformations (org.olat.modules.portfolio.PageUserInformations)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 OLATResource (org.olat.resource.OLATResource)10 ICourse (org.olat.course.ICourse)8 CourseNode (org.olat.course.nodes.CourseNode)8 PortfolioCourseNode (org.olat.course.nodes.PortfolioCourseNode)8 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)8 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)8 AssessedBinder (org.olat.modules.portfolio.model.AssessedBinder)8 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)8 Date (java.util.Date)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 PageBody (org.olat.modules.portfolio.PageBody)6 BigDecimal (java.math.BigDecimal)4