Search in sources :

Example 26 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPArtefactWizzardStepCallback method execute.

/**
 * @see org.olat.core.gui.control.generic.wizard.StepRunnerCallback#execute(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.core.gui.control.generic.wizard.StepsRunContext)
 */
@Override
public Step execute(UserRequest ureq2, WindowControl wControl, StepsRunContext runContext) {
    boolean hasChanges = false;
    if (runContext.containsKey("artefact")) {
        hasChanges = true;
        AbstractArtefact locArtefact = (AbstractArtefact) runContext.get("artefact");
        ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager");
        PortfolioModule portfolioModule = (PortfolioModule) CoreSpringFactory.getBean("portfolioModule");
        // set the defined signature level, if its not from inside olat
        if (locArtefact.getSignature() < 0 && ((runContext.containsKey("copyright.accepted") && (Boolean) runContext.get("copyright.accepted")) || !portfolioModule.isCopyrightStepEnabled())) {
            locArtefact.setSignature(-1 * locArtefact.getSignature());
        }
        ePFMgr.updateArtefact(locArtefact);
        if (runContext.containsKey("tempArtFolder")) {
            // a new text or file-artefact was created, copy everything to destination
            VFSContainer tmpFolder = (VFSContainer) runContext.get("tempArtFolder");
            copyFromTempToArtefactContainer(locArtefact, tmpFolder);
        } else if (tempUpload != null) {
            // an artefact was collected in bc, only copy the selected file
            copyFromBCToArtefactContainer(locArtefact, tempUpload);
        }
        // add to a structure if any was selected
        if (runContext.containsKey("selectedStructure")) {
            PortfolioStructure parentStructure = (PortfolioStructure) runContext.get("selectedStructure");
            if (parentStructure != null) {
                ePFMgr.addArtefactToStructure(ureq2.getIdentity(), locArtefact, parentStructure);
            }
        }
        @SuppressWarnings("unchecked") List<String> allTags = (List<String>) runContext.get("artefactTagsList");
        ePFMgr.setArtefactTags(ureq2.getIdentity(), locArtefact, allTags);
        ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrapPortfolioOres(locArtefact));
        ThreadLocalUserActivityLogger.log(EPLoggingAction.EPORTFOLIO_ARTEFACT_ADDED, getClass());
    }
    return hasChanges ? StepsMainRunController.DONE_MODIFIED : StepsMainRunController.DONE_UNCHANGED;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) List(java.util.List) PortfolioModule(org.olat.portfolio.PortfolioModule)

Example 27 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPXStreamHandler method getAsObject.

public static final PortfolioStructure getAsObject(File fMapXml, boolean withArtefacts) {
    try {
        // extract from zip
        InputStream in = new FileInputStream(fMapXml);
        ZipInputStream zipIn = new ZipInputStream(in);
        // open the entry of the map
        zipIn.getNextEntry();
        Writer buffer = new StringWriter();
        if (!withArtefacts) {
            Transformer transformer = filterArtefactsTemplates.newTransformer();
            transformer.transform(new StreamSource(zipIn), new StreamResult(buffer));
        } else {
            IOUtils.copy(zipIn, buffer, "UTF-8");
        }
        PortfolioStructure struct = (PortfolioStructure) myStream.fromXML(buffer.toString());
        // OLAT-6344: reset ownerGroup from earlier exports. A new group is created by import in ePFMgr.importPortfolioMapTemplate() later on anyway.
        ((EPAbstractMap) struct).setGroups(null);
        return struct;
    } catch (Exception e) {
        log.error("Cannot export this map: " + fMapXml, e);
    }
    return null;
}
Also used : EPAbstractMap(org.olat.portfolio.model.structel.EPAbstractMap) ZipInputStream(java.util.zip.ZipInputStream) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) FileInputStream(java.io.FileInputStream) StringWriter(java.io.StringWriter) Writer(java.io.Writer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException)

Example 28 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class PortfolioHandler method copy.

@Override
public RepositoryEntry copy(Identity author, RepositoryEntry source, RepositoryEntry target) {
    OLATResource sourceResource = source.getOlatResource();
    OLATResource targetResource = target.getOlatResource();
    EPFrontendManager ePFMgr = CoreSpringFactory.getImpl(EPFrontendManager.class);
    PortfolioStructure structure = ePFMgr.loadPortfolioStructure(sourceResource);
    PortfolioStructure newStructure = EPXStreamHandler.copy(structure);
    ePFMgr.importPortfolioMapTemplate(newStructure, targetResource);
    return target;
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager)

Example 29 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class PortfolioHandler method getAsMediaResource.

/**
 * Transform the map in a XML file and zip it (Repository export want a zip)
 * @see org.olat.repository.handlers.RepositoryHandler#getAsMediaResource(org.olat.core.id.OLATResourceable)
 */
@Override
public MediaResource getAsMediaResource(OLATResourceable res, boolean backwardsCompatible) {
    MediaResource mr = null;
    EPFrontendManager ePFMgr = CoreSpringFactory.getImpl(EPFrontendManager.class);
    PortfolioStructure structure = ePFMgr.loadPortfolioStructure(res);
    try {
        InputStream inOut = EPXStreamHandler.toStream(structure);
        mr = new StreamedMediaResource(inOut, null, null, null);
    } catch (IOException e) {
        log.error("Cannot export this map: " + structure, e);
    }
    return mr;
}
Also used : InputStream(java.io.InputStream) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) MediaResource(org.olat.core.gui.media.MediaResource) StreamedMediaResource(org.olat.core.gui.media.StreamedMediaResource) IOException(java.io.IOException) StreamedMediaResource(org.olat.core.gui.media.StreamedMediaResource) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager)

Example 30 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPImportTest method testImportFromOpenOLAT_81_Hibernate3.

@Test
public void testImportFromOpenOLAT_81_Hibernate3() throws URISyntaxException {
    URL mapUrl = EPImportTest.class.getResource("map_81.xml.zip");
    assertNotNull(mapUrl);
    File mapFile = new File(mapUrl.toURI());
    PortfolioStructure rootStructure = EPXStreamHandler.getAsObject(mapFile, false);
    OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
    // import the map
    PortfolioStructureMap importedMap = epFrontendManager.importPortfolioMapTemplate(rootStructure, resource);
    Assert.assertNotNull(importedMap);
    dbInstance.commitAndCloseSession();
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)236 Test (org.junit.Test)90 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)70 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)54 ArrayList (java.util.ArrayList)40 OLATResource (org.olat.resource.OLATResource)30 Identity (org.olat.core.id.Identity)26 RepositoryEntry (org.olat.repository.RepositoryEntry)24 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)22 EPMapPolicy (org.olat.portfolio.manager.EPMapPolicy)16 EPPage (org.olat.portfolio.model.structel.EPPage)16 EPAbstractMap (org.olat.portfolio.model.structel.EPAbstractMap)12 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)12 DBQuery (org.olat.core.commons.persistence.DBQuery)10 EPFrontendManager (org.olat.portfolio.manager.EPFrontendManager)10 Date (java.util.Date)8 Document (org.apache.lucene.document.Document)8 Link (org.olat.core.gui.components.link.Link)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)8 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)8