Search in sources :

Example 86 with Section

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

the class PageDAOTest method getPages_section.

@Test
public void getPages_section() {
    BinderImpl binder = binderDao.createAndPersist("Binder p2", "A binder with 2 page", null, null);
    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("Page 3", "A page with the demonstration of Hawking about black hole'evaporation.", null, null, true, reloadedSection, null);
    dbInstance.commitAndCloseSession();
    // reload
    List<Page> sectionPages = pageDao.getPages(reloadedSection);
    Assert.assertNotNull(sectionPages);
    Assert.assertEquals(3, sectionPages.size());
    Assert.assertTrue(sectionPages.contains(page1));
    Assert.assertTrue(sectionPages.contains(page2));
    Assert.assertTrue(sectionPages.contains(page3));
}
Also used : BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) Test(org.junit.Test)

Example 87 with Section

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

the class ExportBinderAsCPResource method createImsManifest.

private ManifestType createImsManifest(Binder binder, List<Section> sections, List<Page> pages) {
    ManifestType manifest = cpObjectFactory.createManifestType();
    manifest.setIdentifier(UUID.randomUUID().toString());
    // schema
    ManifestMetadataType metadataType = cpObjectFactory.createManifestMetadataType();
    manifest.setMetadata(metadataType);
    // organizations
    OrganizationsType organizations = cpObjectFactory.createOrganizationsType();
    manifest.setOrganizations(organizations);
    OrganizationType organization = cpObjectFactory.createOrganizationType();
    organization.setIdentifier("binder_" + binder.getKey());
    organization.setTitle(binder.getTitle());
    organization.setStructure("hierarchical");
    organizations.getOrganization().add(organization);
    organizations.setDefault(organization);
    ResourcesType resources = cpObjectFactory.createResourcesType();
    manifest.setResources(resources);
    Map<Section, ItemType> sectionToItemMap = new HashMap<>();
    for (Section section : sections) {
        ItemType sectionItem = cpObjectFactory.createItemType();
        String itemIdentifier = "section_" + section.getKey().toString();
        String resourceIdentifier = "res_" + itemIdentifier;
        sectionItem.setTitle(section.getTitle());
        sectionItem.setIdentifier(itemIdentifier);
        sectionItem.setIdentifierref(resourceIdentifier);
        sectionItem.setIsvisible(Boolean.TRUE);
        organization.getItem().add(sectionItem);
        sectionToItemMap.put(section, sectionItem);
        ResourceType resource = cpObjectFactory.createResourceType();
        resource.setIdentifier(resourceIdentifier);
        resource.setType("webcontent");
        resource.setHref(sectionFilename(section));
        resources.getResource().add(resource);
    }
    for (Page page : pages) {
        ItemType sectionItem = sectionToItemMap.get(page.getSection());
        if (sectionItem == null) {
            continue;
        }
        ItemType pageItem = cpObjectFactory.createItemType();
        pageItem.setTitle(page.getTitle());
        String itemIdentifier = "page_" + page.getKey().toString();
        String resourceIdentifier = "res_" + itemIdentifier;
        pageItem.setIdentifier(itemIdentifier);
        pageItem.setIdentifierref(resourceIdentifier);
        pageItem.setIsvisible(Boolean.TRUE);
        sectionItem.getItem().add(pageItem);
        ResourceType resource = cpObjectFactory.createResourceType();
        resource.setIdentifier(resourceIdentifier);
        resource.setType("webcontent");
        resource.setHref(pageFilename(page));
        resources.getResource().add(resource);
    }
    return manifest;
}
Also used : ManifestMetadataType(org.olat.imscp.xml.manifest.ManifestMetadataType) ResourcesType(org.olat.imscp.xml.manifest.ResourcesType) ManifestType(org.olat.imscp.xml.manifest.ManifestType) OrganizationsType(org.olat.imscp.xml.manifest.OrganizationsType) HashMap(java.util.HashMap) ItemType(org.olat.imscp.xml.manifest.ItemType) ResourceType(org.olat.imscp.xml.manifest.ResourceType) Page(org.olat.modules.portfolio.Page) OrganizationType(org.olat.imscp.xml.manifest.OrganizationType) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section)

Example 88 with Section

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

the class ExportBinderAsCPResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding("UTF-8");
    } catch (Exception e) {
        log.error("", e);
    }
    try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
        Binder binder = portfolioService.getBinderByKey(binderRef.getKey());
        String label = binder.getTitle();
        String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
        String file = secureLabel + ".zip";
        hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
        hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
        // load pages
        List<Section> sections = portfolioService.getSections(binder);
        List<Page> pages = portfolioService.getPages(binder, null);
        // manifest
        ManifestType manifest = createImsManifest(binder, sections, pages);
        zout.putNextEntry(new ZipEntry("imsmanifest.xml"));
        write(manifest, new ShieldOutputStream(zout));
        zout.closeEntry();
        // write pages
        for (Section section : sections) {
            exportSection(section, zout);
        }
        // write pages
        for (Page page : pages) {
            exportPage(page, zout);
        }
        // theme and javascripts
        exportCSSAndJs(zout);
        // make it readable offline
        ByteArrayOutputStream manifestOut = new ByteArrayOutputStream();
        write(manifest, manifestOut);
        String manifestXml = new String(manifestOut.toByteArray());
        String indexSrc = sectionFilename(sections.get(0));
        CPOfflineReadableManager.getInstance().makeCPOfflineReadable(manifestXml, indexSrc, zout);
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) ManifestType(org.olat.imscp.xml.manifest.ManifestType) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) Page(org.olat.modules.portfolio.Page) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 89 with Section

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

the class PublishController method reloadData.

public void reloadData() {
    binderRow.getChildren().clear();
    binderRow.getAccessRights().clear();
    List<AccessRights> rights = portfolioService.getAccessRights(binder);
    boolean canEditBinderAccessRights = secCallback.canEditAccessRights(binder);
    for (AccessRights right : rights) {
        if (right.getSectionKey() == null && right.getPageKey() == null) {
            if (PortfolioRoles.invitee.equals(right.getRole())) {
                // only access
                continue;
            }
            Link editLink = null;
            if (canEditBinderAccessRights && !PortfolioRoles.owner.equals(right.getRole())) {
                String id = "edit_" + (counter++);
                editLink = LinkFactory.createLink(id, id, "edit_access", "edit", getTranslator(), mainVC, this, Link.LINK);
            }
            binderRow.getAccessRights().add(new AccessRightsRow(binder, right, editLink));
        }
    }
    List<AssessmentSection> assessmentSections = portfolioService.getAssessmentSections(binder, getIdentity());
    Map<Section, AssessmentSection> sectionToAssessmentSectionMap = new HashMap<>();
    for (AssessmentSection assessmentSection : assessmentSections) {
        sectionToAssessmentSectionMap.put(assessmentSection.getSection(), assessmentSection);
    }
    // sections
    List<Section> sections = portfolioService.getSections(binder);
    Map<Long, PortfolioElementRow> sectionMap = new HashMap<>();
    for (Section section : sections) {
        boolean canEditSectionAccessRights = secCallback.canEditAccessRights(section);
        boolean canViewSectionAccessRights = secCallback.canViewAccessRights(section);
        if (canEditSectionAccessRights || canViewSectionAccessRights) {
            PortfolioElementRow sectionRow = new PortfolioElementRow(section, sectionToAssessmentSectionMap.get(section));
            binderRow.getChildren().add(sectionRow);
            sectionMap.put(section.getKey(), sectionRow);
            for (AccessRights right : rights) {
                if (section.getKey().equals(right.getSectionKey()) && right.getPageKey() == null) {
                    Link editLink = null;
                    if (canEditSectionAccessRights && !PortfolioRoles.owner.equals(right.getRole())) {
                        String id = "edit_" + (counter++);
                        editLink = LinkFactory.createLink(id, id, "edit_access", "edit", getTranslator(), mainVC, this, Link.LINK);
                        sectionRow.getAccessRights().add(new AccessRightsRow(section, right, editLink));
                    }
                }
            }
        }
    }
    // pages
    List<Page> pages = portfolioService.getPages(binder, null);
    for (Page page : pages) {
        boolean canEditPageAccessRights = secCallback.canEditAccessRights(page);
        boolean canViewPageAccessRights = secCallback.canViewAccessRights(page);
        if (canEditPageAccessRights || canViewPageAccessRights) {
            Section section = page.getSection();
            PortfolioElementRow sectionRow = sectionMap.get(section.getKey());
            if (sectionRow == null) {
                logError("Section not found: " + section.getKey() + " of page: " + page.getKey(), null);
                continue;
            }
            PortfolioElementRow pageRow = new PortfolioElementRow(page, null);
            sectionRow.getChildren().add(pageRow);
            for (AccessRights right : rights) {
                if (page.getKey().equals(right.getPageKey())) {
                    Link editLink = null;
                    if (canEditPageAccessRights && !PortfolioRoles.owner.equals(right.getRole())) {
                        String id = "edit_" + (counter++);
                        editLink = LinkFactory.createLink(id, id, "edit_access", "edit", getTranslator(), mainVC, this, Link.LINK);
                        pageRow.getAccessRights().add(new AccessRightsRow(page, right, editLink));
                    }
                }
            }
        }
    }
    mainVC.setDirty(true);
}
Also used : HashMap(java.util.HashMap) Page(org.olat.modules.portfolio.Page) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) AccessRights(org.olat.modules.portfolio.model.AccessRights) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Link(org.olat.core.gui.components.link.Link)

Example 90 with Section

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

the class SectionDatesEditController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    Section reloadedSection = portfolioService.getSection(section);
    reloadedSection.setOverrideBeginEndDates(true);
    reloadedSection.setBeginDate(beginDateEl.getDate());
    reloadedSection.setEndDate(endDateEl.getDate());
    section = portfolioService.updateSection(reloadedSection);
    if (section.getSectionStatus() == SectionStatus.closed && section.getEndDate() != null && section.getEndDate().compareTo(new Date()) >= 0) {
        portfolioService.changeSectionStatus(section, SectionStatus.inProgress, getIdentity());
        ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_SECTION_REOPEN, getClass(), LoggingResourceable.wrap(section));
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : Section(org.olat.modules.portfolio.Section) Date(java.util.Date)

Aggregations

Section (org.olat.modules.portfolio.Section)190 Page (org.olat.modules.portfolio.Page)100 Test (org.junit.Test)86 Identity (org.olat.core.id.Identity)80 Binder (org.olat.modules.portfolio.Binder)72 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)68 Assignment (org.olat.modules.portfolio.Assignment)48 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)40 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)38 ArrayList (java.util.ArrayList)36 RepositoryEntry (org.olat.repository.RepositoryEntry)26 SectionRef (org.olat.modules.portfolio.SectionRef)24 HashMap (java.util.HashMap)22 Date (java.util.Date)16 PageUserInformations (org.olat.modules.portfolio.PageUserInformations)14 BigDecimal (java.math.BigDecimal)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 SectionImpl (org.olat.modules.portfolio.model.SectionImpl)12 PortfolioElementRow (org.olat.modules.portfolio.ui.model.PortfolioElementRow)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10