Search in sources :

Example 16 with PortfolioService

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

the class CmdAddToEPortfolioImpl method execute.

/**
 * might return NULL!, if item clicked was removed meanwhile or if portfolio is disabled or if only the folder-artefact-handler is disabled.
 *
 * @see org.olat.core.commons.modules.bc.commands.FolderCommand#execute(org.olat.core.commons.modules.bc.components.FolderComponent,
 *      org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.core.gui.translator.Translator)
 */
@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
    String pos = ureq.getParameter(ListRenderer.PARAM_EPORT);
    if (!StringHelper.containsNonWhitespace(pos)) {
        // somehow parameter did not make it to us
        status = FolderCommandStatus.STATUS_FAILED;
        getWindowControl().setError(translator.translate("failed"));
        return null;
    }
    status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
    if (status == FolderCommandStatus.STATUS_SUCCESS) {
        currentItem = folderComponent.getCurrentContainerChildren().get(Integer.parseInt(pos));
        status = FolderCommandHelper.sanityCheck2(wControl, folderComponent, currentItem);
    }
    if (status == FolderCommandStatus.STATUS_FAILED) {
        return null;
    }
    if (portfolioV2Module.isEnabled()) {
        PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
        MediaHandler handler = null;
        String extension = FileUtils.getFileSuffix(currentItem.getName());
        if (StringHelper.containsNonWhitespace(extension)) {
            if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension)) {
                handler = portfolioService.getMediaHandler(ImageHandler.IMAGE_TYPE);
            }
        // TODO video
        }
        if (handler == null) {
            handler = portfolioService.getMediaHandler(FileHandler.FILE_TYPE);
        }
        collectStepsCtrl = new CollectArtefactController(ureq, wControl, currentItem, handler, "");
    } else {
        EPArtefactHandler<?> artHandler = portfolioModule.getArtefactHandler(FileArtefact.FILE_ARTEFACT_TYPE);
        AbstractArtefact artefact = artHandler.createArtefact();
        artHandler.prefillArtefactAccordingToSource(artefact, currentItem);
        artefact.setAuthor(getIdentity());
        collectStepsCtrl = new ArtefactWizzardStepsController(ureq, wControl, artefact, currentItem.getParentContainer());
    }
    return collectStepsCtrl;
}
Also used : PortfolioService(org.olat.modules.portfolio.PortfolioService) MediaHandler(org.olat.modules.portfolio.MediaHandler) CollectArtefactController(org.olat.modules.portfolio.ui.wizard.CollectArtefactController) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact)

Example 17 with PortfolioService

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

the class BinderTemplateHandler method copy.

@Override
public RepositoryEntry copy(Identity author, RepositoryEntry source, RepositoryEntry target) {
    PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
    Binder templateSource = portfolioService.getBinderByResource(source.getOlatResource());
    portfolioService.copyBinder(templateSource, target);
    return target;
}
Also used : Binder(org.olat.modules.portfolio.Binder) PortfolioService(org.olat.modules.portfolio.PortfolioService)

Example 18 with PortfolioService

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

the class BinderTemplateHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
    try {
        // create resource
        OLATResource resource = portfolioService.createBinderTemplateResource();
        OlatRootFolderImpl fResourceRootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
        File fResourceFileroot = fResourceRootContainer.getBasefile();
        File zipRoot = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
        FileResource.copyResource(file, filename, zipRoot);
        // create repository entry
        RepositoryEntry re = repositoryService.create(initialAuthor, initialAuthorAlt, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
        // import binder
        File binderFile = new File(zipRoot, BinderTemplateResource.BINDER_XML);
        Binder transientBinder = BinderXStream.fromPath(binderFile.toPath());
        File posterImage = null;
        if (StringHelper.containsNonWhitespace(transientBinder.getImagePath())) {
            posterImage = new File(zipRoot, transientBinder.getImagePath());
        }
        portfolioService.importBinder(transientBinder, re, posterImage);
        RepositoryEntryImportExport rei = new RepositoryEntryImportExport(re, zipRoot);
        if (rei.anyExportedPropertiesAvailable()) {
            re = rei.importContent(re, fResourceRootContainer.createChildContainer("media"));
        }
        // delete the imported files
        FileUtils.deleteDirsAndFiles(zipRoot, true, true);
        return re;
    } catch (IOException e) {
        log.error("", e);
        return null;
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) PortfolioService(org.olat.modules.portfolio.PortfolioService) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) File(java.io.File) RepositoryService(org.olat.repository.RepositoryService)

Example 19 with PortfolioService

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

the class BinderTemplateHandler method createResource.

@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
    OLATResource resource = portfolioService.createBinderTemplateResource();
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    portfolioService.createAndPersistBinderTemplate(initialAuthor, re, locale);
    DBFactory.getInstance().commit();
    return re;
}
Also used : PortfolioService(org.olat.modules.portfolio.PortfolioService) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 20 with PortfolioService

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

the class BinderTemplateMediaResource 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())) {
        PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
        Binder loadedTemplate = portfolioService.getBinderByKey(template.getKey());
        String label = loadedTemplate.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));
        zout.setLevel(9);
        zout.putNextEntry(new ZipEntry("binder.xml"));
        BinderXStream.toStream(loadedTemplate, zout);
        zout.closeEntry();
        if (StringHelper.containsNonWhitespace(loadedTemplate.getImagePath())) {
            File posterImage = portfolioService.getPosterImageFile(loadedTemplate);
            if (posterImage.exists()) {
                zout.putNextEntry(new ZipEntry(loadedTemplate.getImagePath()));
                FileUtils.copyFile(posterImage, new ShieldOutputStream(zout));
                zout.closeEntry();
            }
        }
        OLATResource resource = templateEntry.getOlatResource();
        File baseContainer = FileResourceManager.getInstance().getFileResource(resource);
        RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(templateEntry, baseContainer);
        importExport.exportDoExportProperties(zout);
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) PortfolioService(org.olat.modules.portfolio.PortfolioService) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) OLATResource(org.olat.resource.OLATResource) File(java.io.File)

Aggregations

PortfolioService (org.olat.modules.portfolio.PortfolioService)24 Binder (org.olat.modules.portfolio.Binder)12 Controller (org.olat.core.gui.control.Controller)10 EvaluationFormController (org.olat.modules.forms.ui.EvaluationFormController)8 MultiEvaluationFormController (org.olat.modules.portfolio.ui.MultiEvaluationFormController)8 RepositoryEntry (org.olat.repository.RepositoryEntry)7 File (java.io.File)6 PortfolioHomeController (org.olat.modules.portfolio.ui.PortfolioHomeController)6 OLATResource (org.olat.resource.OLATResource)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CalendarController (org.olat.commons.calendar.ui.CalendarController)4 WeeklyCalendarController (org.olat.commons.calendar.ui.WeeklyCalendarController)4 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)4 Translator (org.olat.core.gui.translator.Translator)4 Identity (org.olat.core.id.Identity)4 CourseLinkProviderController (org.olat.course.run.calendar.CourseLinkProviderController)4 InfoGroupRunController (org.olat.group.ui.run.InfoGroupRunController)4 ChatToolController (org.olat.instantMessaging.ui.ChatToolController)4 ContactFormController (org.olat.modules.co.ContactFormController)4