Search in sources :

Example 56 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class ReferencableEntriesSearchController method event.

@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source == segmentView) {
        if (event instanceof SegmentViewEvent) {
            SegmentViewEvent sve = (SegmentViewEvent) event;
            String segmentCName = sve.getComponentName();
            Component clickedLink = mainVC.getComponent(segmentCName);
            if (clickedLink == myEntriesLink) {
                searchCtr.doSearchByOwnerLimitType(ureq.getIdentity(), limitTypes);
            } else if (clickedLink == allEntriesLink) {
                switch(canBe) {
                    case referenceable:
                        searchCtr.doSearchForReferencableResourcesLimitType(ureq.getIdentity(), limitTypes, ureq.getUserSession().getRoles());
                        break;
                    case copyable:
                        searchCtr.doSearchForCopyableResourcesLimitType(ureq.getIdentity(), limitTypes, ureq.getUserSession().getRoles());
                        break;
                    case all:
                        searchCtr.doSearchByTypeLimitAccess(limitTypes, ureq);
                        break;
                }
            } else if (clickedLink == searchEntriesLink) {
                searchCtr.displaySearchForm();
            } else if (clickedLink == adminEntriesLink) {
                searchCtr.displayAdminSearchForm();
            }
            mainVC.setDirty(true);
        }
    } else if (source == createRessourceCmp || (source instanceof Link && ((Link) source).getUserObject() instanceof RepositoryHandler)) {
        removeAsListenerAndDispose(cmc);
        removeAsListenerAndDispose(createController);
        RepositoryHandler handler = (RepositoryHandler) ((Link) source).getUserObject();
        createController = handler.createCreateRepositoryEntryController(ureq, getWindowControl());
        listenTo(createController);
        String title = translate(handler.getCreateLabelI18nKey());
        cmc = new CloseableModalController(getWindowControl(), translate("close"), createController.getInitialComponent(), true, title);
        cmc.setCustomWindowCSS("o_sel_author_create_popup");
        listenTo(cmc);
        cmc.activate();
    } else if (source == importRessourceButton) {
        removeAsListenerAndDispose(importController);
        importController = new ImportRepositoryEntryController(ureq, getWindowControl(), limitTypes);
        listenTo(importController);
        removeAsListenerAndDispose(cmc);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), importController.getInitialComponent(), true, "");
        listenTo(cmc);
        cmc.activate();
    }
}
Also used : SegmentViewEvent(org.olat.core.gui.components.segmentedview.SegmentViewEvent) ImportRepositoryEntryController(org.olat.repository.ui.author.ImportRepositoryEntryController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) Component(org.olat.core.gui.components.Component) SegmentViewComponent(org.olat.core.gui.components.segmentedview.SegmentViewComponent) Link(org.olat.core.gui.components.link.Link)

Example 57 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class RepositoryEntryImportExport method exportDoExportContent.

/**
 * Export a repository entry referenced by a course node to the given export directory.
 * User importReferencedRepositoryEntry to import again.
 * @return True upon success, false otherwise.
 */
public boolean exportDoExportContent() {
    // export resource
    RepositoryHandler rh = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    MediaResource mr = rh.getAsMediaResource(re.getOlatResource(), false);
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(new File(baseDirectory, CONTENT_FILE));
        InputStream in = mr.getInputStream();
        if (in == null) {
            HttpServletResponse hres = new HttpServletResponseOutputStream(fOut);
            mr.prepare(hres);
        } else {
            IOUtils.copy(mr.getInputStream(), fOut);
        }
        fOut.flush();
    } catch (IOException fnfe) {
        return false;
    } finally {
        IOUtils.closeQuietly(fOut);
        mr.release();
    }
    return true;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) HttpServletResponseOutputStream(org.olat.core.util.io.HttpServletResponseOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 58 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class RepositoryServiceImpl method copy.

@Override
public RepositoryEntry copy(RepositoryEntry sourceEntry, Identity author, String displayname) {
    OLATResource sourceResource = sourceEntry.getOlatResource();
    OLATResource copyResource = resourceManager.createOLATResourceInstance(sourceResource.getResourceableTypeName());
    RepositoryEntry copyEntry = create(author, null, sourceEntry.getResourcename(), displayname, sourceEntry.getDescription(), copyResource, RepositoryEntry.ACC_OWNERS);
    // copy all fields
    copyEntry.setAuthors(sourceEntry.getAuthors());
    copyEntry.setCredits(sourceEntry.getCredits());
    copyEntry.setExpenditureOfWork(sourceEntry.getExpenditureOfWork());
    copyEntry.setMainLanguage(sourceEntry.getMainLanguage());
    copyEntry.setObjectives(sourceEntry.getObjectives());
    copyEntry.setRequirements(sourceEntry.getRequirements());
    copyEntry = dbInstance.getCurrentEntityManager().merge(copyEntry);
    RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(sourceEntry);
    copyEntry = handler.copy(author, sourceEntry, copyEntry);
    // copy the license
    licenseService.copy(sourceResource, copyResource);
    // copy the image
    RepositoryManager.getInstance().copyImage(sourceEntry, copyEntry);
    // copy media container
    VFSContainer sourceMediaContainer = handler.getMediaContainer(sourceEntry);
    if (sourceMediaContainer != null) {
        VFSContainer targetMediaContainer = handler.getMediaContainer(copyEntry);
        VFSManager.copyContent(sourceMediaContainer, targetMediaContainer);
    }
    ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_CREATE, getClass(), LoggingResourceable.wrap(copyEntry, OlatResourceableType.genRepoEntry));
    lifeIndexer.indexDocument(RepositoryEntryDocument.TYPE, copyEntry.getKey());
    return copyEntry;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler)

Example 59 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class RepositoryServiceImpl method getIntroductionMovie.

@Override
public VFSLeaf getIntroductionMovie(RepositoryEntry re) {
    RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(re);
    VFSContainer mediaContainer = handler.getMediaContainer(re);
    if (mediaContainer != null) {
        List<VFSItem> items = mediaContainer.getItems();
        for (VFSItem item : items) {
            if (item instanceof VFSLeaf && item.getName().startsWith(re.getKey().toString()) && (item.getName().endsWith(".mp4") || item.getName().endsWith(".m4v") || item.getName().endsWith(".flv"))) {
                return (VFSLeaf) item;
            }
        }
    }
    return null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler)

Example 60 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class RepositoryServiceImpl method deletePermanently.

@Override
public ErrorList deletePermanently(RepositoryEntry entry, Identity identity, Roles roles, Locale locale) {
    ErrorList errors = new ErrorList();
    boolean debug = log.isDebug();
    // invoke handler delete callback
    if (debug)
        log.debug("deleteRepositoryEntry start entry=" + entry);
    entry = (RepositoryEntry) dbInstance.loadObject(entry, true);
    if (debug)
        log.debug("deleteRepositoryEntry after load entry=" + entry);
    RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(entry);
    OLATResource resource = entry.getOlatResource();
    // delete old context
    if (!handler.readyToDelete(entry, identity, roles, locale, errors)) {
        return errors;
    }
    userCourseInformationsManager.deleteUserCourseInformations(entry);
    certificatesManager.deleteRepositoryEntry(entry);
    // delete all bookmarks referencing deleted entry
    CoreSpringFactory.getImpl(MarkManager.class).deleteMarks(entry);
    // delete all catalog entries referencing deleted entry
    catalogManager.resourceableDeleted(entry);
    // delete assessment modes
    assessmentModeDao.delete(entry);
    // delete reminders
    reminderDao.delete(entry);
    // delete all policies
    securityManager.deletePolicies(resource);
    // delete reservations
    reservationDao.deleteReservations(resource);
    // delete references
    referenceManager.deleteAllReferencesOf(resource);
    // delete all pending tasks
    persistentTaskDao.delete(resource);
    dbInstance.commit();
    // delete lectures
    CoreSpringFactory.getImpl(LectureService.class).delete(entry);
    dbInstance.commit();
    // delete license
    CoreSpringFactory.getImpl(LicenseService.class).delete(resource);
    dbInstance.commit();
    // detach portfolio if there are some lost
    CoreSpringFactory.getImpl(PortfolioService.class).detachCourseFromBinders(entry);
    dbInstance.commit();
    // inform handler to do any cleanup work... handler must delete the
    // referenced resourceable a swell.
    handler.cleanupOnDelete(entry, resource);
    dbInstance.commit();
    // delete all test sessions
    assessmentTestSessionDao.deleteAllUserTestSessionsByCourse(entry);
    // nullify the reference
    assessmentEntryDao.removeEntryForReferenceEntry(entry);
    assessmentEntryDao.deleteEntryForRepositoryEntry(entry);
    dbInstance.commit();
    if (debug)
        log.debug("deleteRepositoryEntry after reload entry=" + entry);
    deleteRepositoryEntryAndBaseGroups(entry);
    if (debug)
        log.debug("deleteRepositoryEntry Done");
    return errors;
}
Also used : ErrorList(org.olat.repository.ErrorList) PortfolioService(org.olat.modules.portfolio.PortfolioService) MarkManager(org.olat.core.commons.services.mark.MarkManager) LicenseService(org.olat.core.commons.services.license.LicenseService) OLATResource(org.olat.resource.OLATResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) LectureService(org.olat.modules.lecture.LectureService)

Aggregations

RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)74 RepositoryEntry (org.olat.repository.RepositoryEntry)42 RepositoryEntryImportExport (org.olat.repository.RepositoryEntryImportExport)18 OLATResource (org.olat.resource.OLATResource)16 File (java.io.File)14 ICourse (org.olat.course.ICourse)10 RepositoryService (org.olat.repository.RepositoryService)10 ArrayList (java.util.ArrayList)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 MediaResource (org.olat.core.gui.media.MediaResource)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 LockResult (org.olat.core.util.coordinate.LockResult)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6 OrderedRepositoryHandler (org.olat.repository.handlers.RepositoryHandlerFactory.OrderedRepositoryHandler)6 URL (java.net.URL)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4