Search in sources :

Example 31 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class AdobeConnectCleanupJob method cleanupMeetings.

/**
 * @param adobe
 */
protected void cleanupMeetings(AdobeConnectProvider adobe, int daysToKeep) {
    boolean success = false;
    Date lowerLimit = new Date((new Date()).getTime() - (daysToKeep * 24 * 60 * 60 * 1000));
    // search all virtual classrooms with the used prefix
    List<String> roomIds = adobe.findClassrooms(AdobeConnectProvider.PREFIX);
    for (String roomId : roomIds) {
        // format is olat-courseId-nodeId, e.g. olat-82823405537032-82823405537043
        // load course and node
        String courseId = roomId.split("-")[1];
        String nodeId = roomId.split("-")[2];
        ICourse course = CourseFactory.loadCourse(Long.parseLong(courseId));
        CourseNode vcNode = course.getRunStructure().getNode(nodeId);
        if (!(vcNode instanceof VCCourseNode)) {
            logger.warn("Tried to cleanup Adobe Connect meeting for a non Adobe Connect course node: " + roomId);
            continue;
        }
        AdobeConnectConfiguration config = (AdobeConnectConfiguration) vcNode.getModuleConfiguration().get(VCCourseNode.CONF_VC_CONFIGURATION);
        if (config == null) {
            // invalid configuration, do nothing and continue
            continue;
        }
        boolean keep = false;
        for (MeetingDate date : config.getMeetingDates()) {
            if (keep)
                continue;
            Date end = date.getEnd();
            keep = lowerLimit.before(end);
        }
        // no planned date in the future, we can delete
        // build the correct roomId
        String toDelete = courseId + "-" + nodeId;
        if (!keep)
            success = adobe.removeClassroom(toDelete, config);
        if (!success) {
            logger.warn("Error when cleaning up Adobe Connect meeting \"" + roomId + "\"");
            continue;
        }
    }
}
Also used : MeetingDate(de.bps.course.nodes.vc.MeetingDate) VCCourseNode(de.bps.course.nodes.VCCourseNode) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) VCCourseNode(de.bps.course.nodes.VCCourseNode) Date(java.util.Date) MeetingDate(de.bps.course.nodes.vc.MeetingDate)

Example 32 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class DeleteUserDataTask method deleteDropboxReturnbox.

private void deleteDropboxReturnbox(Identity identity, File courseDir) {
    File returnboxDir = new File(courseDir, ReturnboxController.RETURNBOX_DIR_NAME);
    File dropboxDir = new File(courseDir, DropboxController.DROPBOX_DIR_NAME);
    if (returnboxDir.exists() || dropboxDir.exists()) {
        ICourse currentCourse = null;
        File[] dropboxReturnboxDirs = new File[] { returnboxDir, dropboxDir };
        for (File dropboxReturnboxDir : dropboxReturnboxDirs) {
            if (!dropboxReturnboxDir.exists())
                continue;
            File[] nodeDirs = dropboxReturnboxDir.listFiles();
            // 3. loop over all node-id e.g. 78933379704296
            for (File nodeDir : nodeDirs) {
                String currentNodeId = nodeDir.getName();
                if (currentCourse == null) {
                    currentCourse = loadCourse(courseDir);
                }
                if (currentCourse == null) {
                    // corrupted course
                    return;
                } else if (isTaskNode(currentCourse, currentNodeId)) {
                    deleteUserDirectory(identity, nodeDir);
                } else if (isProjectBrokerNode(currentCourse, currentNodeId)) {
                    // additional loop over project-id
                    File[] projectDirs = nodeDir.listFiles();
                    for (File projectDir : projectDirs) {
                        deleteUserDirectory(identity, projectDir);
                    }
                } else {
                    log.warn("found dropbox or returnbox and node-type is NO Task- or ProjectBroker-Type courseId=" + courseDir.getName() + " nodeId=" + currentNodeId, null);
                }
            }
        }
    }
}
Also used : ICourse(org.olat.course.ICourse) File(java.io.File)

Example 33 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class CollaborationTools method createCalendarController.

/**
 * Creates a calendar controller
 * @param ureq
 * @param wControl
 * @param resourceableId
 * @return Configured WeeklyCalendarController
 */
public CalendarController createCalendarController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup, boolean isAdmin, boolean isMember) {
    CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
    KalendarRenderWrapper calRenderWrapper = collaborationManager.getCalendar(businessGroup, ureq, isAdmin);
    calRenderWrapper.setPrivateEventsVisible(isAdmin || isMember);
    // add linking
    List<RepositoryEntry> repoEntries = CoreSpringFactory.getImpl(BusinessGroupService.class).findRepositoryEntries(Collections.singleton(businessGroup), 0, -1);
    List<ICourse> courses = new ArrayList<>(repoEntries.size());
    for (RepositoryEntry repoEntry : repoEntries) {
        if (repoEntry.getOlatResource().getResourceableTypeName().equals(CourseModule.getCourseTypeName())) {
            ICourse course = CourseFactory.loadCourse(repoEntry);
            courses.add(course);
        }
    }
    if (!courses.isEmpty()) {
        CourseLinkProviderController clp = new CourseLinkProviderController(null, courses, ureq, wControl);
        calRenderWrapper.setLinkProvider(clp);
    }
    List<KalendarRenderWrapper> calendars = new ArrayList<>();
    calendars.add(calRenderWrapper);
    return new WeeklyCalendarController(ureq, wControl, calendars, WeeklyCalendarController.CALLER_COLLAB, businessGroup, false);
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) WeeklyCalendarController(org.olat.commons.calendar.ui.WeeklyCalendarController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 34 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class InitialAttemptsRuleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = Util.getPackageVelocityRoot(this.getClass()) + "/initial_attempts.html";
    String id = Long.toString(CodeHelper.getRAMUniqueID());
    Translator trans = formLayout.getTranslator();
    FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("attempts.".concat(id), formLayout.getTranslator(), page);
    ruleCont.setRootForm(formLayout.getRootForm());
    formLayout.add(ruleCont);
    ruleCont.getFormItemComponent().contextPut("id", id);
    ICourse course = CourseFactory.loadCourse(entry);
    String currentValue = null;
    String currentUnit = null;
    String currentCourseNode = null;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        currentUnit = r.getRightUnit();
        currentValue = r.getRightOperand();
        currentCourseNode = r.getLeftOperand();
    }
    List<CourseNode> attemptableNodes = new ArrayList<>();
    searchAttemptableNodes(course.getRunStructure().getRootNode(), attemptableNodes);
    String[] nodeKeys = new String[attemptableNodes.size()];
    String[] nodeValues = new String[attemptableNodes.size()];
    for (int i = 0; i < attemptableNodes.size(); i++) {
        CourseNode attemptableNode = attemptableNodes.get(i);
        nodeKeys[i] = attemptableNode.getIdent();
        nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
    }
    courseNodeEl = uifactory.addDropdownSingleselect("coursenodes.".concat(id), null, ruleCont, nodeKeys, nodeValues, null);
    courseNodeEl.setDomReplacementWrapperRequired(false);
    boolean nodeSelected = false;
    if (currentCourseNode != null) {
        for (String nodeKey : nodeKeys) {
            if (currentCourseNode.equals(nodeKey)) {
                courseNodeEl.select(nodeKey, true);
                nodeSelected = true;
            }
        }
    }
    if (!nodeSelected && nodeKeys.length > 0) {
        courseNodeEl.select(nodeKeys[0], true);
    }
    if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
        courseNodeEl.setErrorKey("error.course.node.found", null);
    }
    valueEl = uifactory.addTextElement("attemptvalue.".concat(id), null, 128, currentValue, ruleCont);
    valueEl.setDomReplacementWrapperRequired(false);
    valueEl.setDisplaySize(3);
    String[] unitValues = new String[] { trans.translate(LaunchUnit.day.name()), trans.translate(LaunchUnit.week.name()), trans.translate(LaunchUnit.month.name()), trans.translate(LaunchUnit.year.name()) };
    unitEl = uifactory.addDropdownSingleselect("attemptunit.".concat(id), null, ruleCont, unitKeys, unitValues, null);
    unitEl.setDomReplacementWrapperRequired(false);
    boolean selected = false;
    if (currentUnit != null) {
        for (String unitKey : unitKeys) {
            if (currentUnit.equals(unitKey)) {
                unitEl.select(unitKey, true);
                selected = true;
            }
        }
    }
    if (!selected) {
        unitEl.select(unitKeys[1], true);
    }
    return ruleCont;
}
Also used : Translator(org.olat.core.gui.translator.Translator) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 35 with ICourse

use of org.olat.course.ICourse 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)

Aggregations

ICourse (org.olat.course.ICourse)674 Identity (org.olat.core.id.Identity)262 RepositoryEntry (org.olat.repository.RepositoryEntry)246 CourseNode (org.olat.course.nodes.CourseNode)182 Test (org.junit.Test)158 ArrayList (java.util.ArrayList)102 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)90 Date (java.util.Date)84 URI (java.net.URI)76 HttpResponse (org.apache.http.HttpResponse)76 OLATResource (org.olat.resource.OLATResource)64 File (java.io.File)62 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)52 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)52 Produces (javax.ws.rs.Produces)48 Roles (org.olat.core.id.Roles)44 Path (javax.ws.rs.Path)42 UserRequest (org.olat.core.gui.UserRequest)42 INode (org.olat.core.util.nodes.INode)40 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)40