Search in sources :

Example 1 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class CourseGlossaryFactory method createCourseGlossaryMainRunController.

/**
 * The glossarymaincontroller allows browsing in the glossary. A flag enables
 * the edit mode.
 *
 * @param windowControl
 * @param ureq
 * @param courseConfig use the glossary configuration from the given course
 *          configuration
 * @param hasGlossaryEditRights
 * @return
 */
public static GlossaryMainController createCourseGlossaryMainRunController(WindowControl lwControl, UserRequest lureq, CourseConfig cc, boolean hasGlossaryRights) {
    if (cc.hasGlossary()) {
        RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(cc.getGlossarySoftKey(), false);
        if (repoEntry == null) {
            // seems to be removed
            return null;
        }
        RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
        boolean owner = repositoryService.hasRole(lureq.getIdentity(), repoEntry, GroupRoles.owner.name());
        VFSContainer glossaryFolder = GlossaryManager.getInstance().getGlossaryRootFolder(repoEntry.getOlatResource());
        Properties glossProps = GlossaryItemManager.getInstance().getGlossaryConfig(glossaryFolder);
        boolean editUsersEnabled = "true".equals(glossProps.getProperty(GlossaryItemManager.EDIT_USERS));
        GlossarySecurityCallback secCallback;
        if (lureq.getUserSession().getRoles().isGuestOnly()) {
            secCallback = new GlossarySecurityCallbackImpl();
        } else {
            secCallback = new GlossarySecurityCallbackImpl(hasGlossaryRights, owner, editUsersEnabled, lureq.getIdentity().getKey());
        }
        return new GlossaryMainController(lwControl, lureq, glossaryFolder, repoEntry.getOlatResource(), secCallback, true);
    }
    return null;
}
Also used : GlossarySecurityCallback(org.olat.core.commons.modules.glossary.GlossarySecurityCallback) GlossaryMainController(org.olat.core.commons.modules.glossary.GlossaryMainController) GlossarySecurityCallbackImpl(org.olat.core.commons.modules.glossary.GlossarySecurityCallbackImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) Properties(java.util.Properties) RepositoryService(org.olat.repository.RepositoryService)

Example 2 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class CourseSite method createController.

@Override
protected MainLayoutController createController(UserRequest ureq, WindowControl wControl, SiteConfiguration config) {
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
    if (entry == null) {
        return getAlternativeController(ureq, wControl, config);
    }
    MainLayoutController c;
    ICourse course = CourseFactory.loadCourse(entry);
    UserSession usess = ureq.getUserSession();
    // course-launch-state depending course-settings
    RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, entry);
    boolean isAllowedToLaunch = reSecurity.canLaunch();
    boolean hasAccess = false;
    if (isAllowedToLaunch) {
        // either check with securityCallback or use access-settings from course-nodes
        if (siteSecCallback != null) {
            hasAccess = siteSecCallback.isAllowedToLaunchSite(ureq);
        } else if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(course)) {
            hasAccess = false;
        } else {
            // check within course: accessibility of course root node
            CourseNode rootNode = course.getRunStructure().getRootNode();
            UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment());
            NodeEvaluation nodeEval = rootNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
            boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
            hasAccess = mayAccessWholeTreeUp && nodeEval.isVisible();
        }
    }
    // load course (admins always see content) or alternative controller if course is not launchable
    if (hasAccess || usess.getRoles().isOLATAdmin()) {
        rs.incrementLaunchCounter(entry);
        // build up the context path for linked course
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, entry, new StateSite(this), wControl, true);
        CourseRuntimeController runCtr = new CourseRuntimeController(ureq, bwControl, entry, reSecurity, new RuntimeControllerCreator() {

            @Override
            public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry re, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
                return new RunMainController(uureq, wwControl, toolbarPanel, CourseFactory.loadCourse(re), re, security, assessmentMode);
            }
        }, false, true);
        // Configure run controller
        // a: don't show close link, is opened as site not tab
        runCtr.setCourseCloseEnabled(false);
        // b: don't show toolbar
        if (!showToolController) {
            runCtr.setToolControllerEnabled(false);
        }
        c = runCtr;
    } else {
        // access restricted (not in group / author) -> show controller
        // defined in olat_extensions (type autoCreator)
        c = getAlternativeController(ureq, wControl, config);
    }
    return c;
}
Also used : TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) AssessmentMode(org.olat.course.assessment.AssessmentMode) StateSite(org.olat.core.id.context.StateSite) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) RunMainController(org.olat.course.run.RunMainController) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RunMainController(org.olat.course.run.RunMainController) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) Controller(org.olat.core.gui.control.Controller) RuntimeControllerCreator(org.olat.repository.ui.RepositoryEntryRuntimeController.RuntimeControllerCreator) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) UserSession(org.olat.core.util.UserSession) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RepositoryManager(org.olat.repository.RepositoryManager) CourseNode(org.olat.course.nodes.CourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService)

Example 3 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class CourseSiteContextEntryControllerCreator method createLaunchController.

/**
 * Create a launch controller used to launch the given repo entry.
 * @param re
 * @param initialViewIdentifier if null the default view will be started, otherwise a controllerfactory type dependant view will be activated (subscription subtype)
 * @param ureq
 * @param wControl
 * @return null if no entry was found, a no access message controller if not allowed to launch or the launch
 * controller if successful.
 */
private Controller createLaunchController(RepositoryEntry re, UserRequest ureq, WindowControl wControl) {
    if (re == null) {
        return messageController(ureq, wControl, "repositoryentry.not.existing");
    }
    UserSession usess = ureq.getUserSession();
    if (re.getAccess() == RepositoryEntry.DELETED) {
        Roles roles = usess.getRoles();
        if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
            return messageController(ureq, wControl, "repositoryentry.deleted");
        }
    }
    if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(re.getOlatResource())) {
        return null;
    }
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, re);
    if (!reSecurity.canLaunch()) {
        return messageController(ureq, wControl, "launch.noaccess");
    }
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    rs.incrementLaunchCounter(re);
    RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    WindowControl bwControl;
    OLATResourceable businessOres = re;
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(businessOres);
    if (ce.equals(wControl.getBusinessControl().getCurrentContextEntry())) {
        bwControl = wControl;
    } else {
        bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
    }
    MainLayoutController ctrl = handler.createLaunchController(re, reSecurity, ureq, bwControl);
    if (ctrl == null) {
        throw new AssertException("could not create controller for repositoryEntry " + re);
    }
    return ctrl;
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) UserSession(org.olat.core.util.UserSession) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) Roles(org.olat.core.id.Roles) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 4 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class QTIHandler method createResource.

protected RepositoryEntry createResource(String type, FileResource ores, Identity initialAuthor, String displayname, String description, Object object, Locale locale) {
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource resource = OLATResourceManager.getInstance().findOrPersistResourceable(ores);
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    DBFactory.getInstance().commit();
    File fRepositoryQTI = new File(FileResourceManager.getInstance().getFileResourceRoot(re.getOlatResource()), "qti.zip");
    QTIEditorPackageImpl qtiPackage = new QTIEditorPackageImpl(displayname, type, locale);
    if (object instanceof QItemList) {
        QItemList itemToImport = (QItemList) object;
        QTIQPoolServiceProvider provider = (QTIQPoolServiceProvider) CoreSpringFactory.getBean("qtiPoolServiceProvider");
        provider.exportToEditorPackage(qtiPackage, itemToImport.getItems(), true);
    }
    qtiPackage.savePackageTo(fRepositoryQTI);
    return re;
}
Also used : QTIEditorPackageImpl(org.olat.ims.qti.editor.QTIEditorPackageImpl) QTIQPoolServiceProvider(org.olat.ims.qti.qpool.QTIQPoolServiceProvider) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) RepositoryService(org.olat.repository.RepositoryService) QItemList(org.olat.modules.qpool.model.QItemList)

Example 5 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

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)

Aggregations

RepositoryService (org.olat.repository.RepositoryService)76 RepositoryEntry (org.olat.repository.RepositoryEntry)72 OLATResource (org.olat.resource.OLATResource)32 Identity (org.olat.core.id.Identity)20 Produces (javax.ws.rs.Produces)18 Path (javax.ws.rs.Path)16 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)14 File (java.io.File)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 GET (javax.ws.rs.GET)10 UserRequest (org.olat.core.gui.UserRequest)8 WindowControl (org.olat.core.gui.control.WindowControl)8 ICourse (org.olat.course.ICourse)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 UserVO (org.olat.user.restapi.UserVO)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Before (org.junit.Before)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 GlossaryResource (org.olat.fileresource.types.GlossaryResource)6