Search in sources :

Example 81 with ICourse

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

the class QuickPublishController method doAutoPublish.

private boolean doAutoPublish() {
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, getLocale());
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    if (publishTreeModel.hasPublishableChanges()) {
        List<String> nodeToPublish = new ArrayList<String>();
        visitPublishModel(publishTreeModel.getRootNode(), publishTreeModel, nodeToPublish);
        // only add selection if changes were possible
        for (Iterator<String> selectionIt = nodeToPublish.iterator(); selectionIt.hasNext(); ) {
            String ident = selectionIt.next();
            TreeNode node = publishProcess.getPublishTreeModel().getNodeById(ident);
            if (!publishTreeModel.isSelectable(node)) {
                selectionIt.remove();
            }
        }
        publishProcess.createPublishSetFor(nodeToPublish);
        PublishSetInformations set = publishProcess.testPublishSet(getLocale());
        StatusDescription[] status = set.getWarnings();
        // publish not possible when there are errors
        StringBuilder errMsg = new StringBuilder();
        for (int i = 0; i < status.length; i++) {
            if (status[i].isError()) {
                errMsg.append(status[i].getLongDescription(getLocale()));
                logError("Status error by publish: " + status[i].getLongDescription(getLocale()), null);
            }
        }
        if (errMsg.length() > 0) {
            getWindowControl().setWarning(errMsg.toString());
            return false;
        }
        PublishEvents publishEvents = publishProcess.getPublishEvents();
        try {
            publishProcess.applyPublishSet(getIdentity(), getLocale(), false);
        } catch (Exception e) {
            logError("", e);
        }
        if (publishEvents.getPostPublishingEvents().size() > 0) {
            for (MultiUserEvent event : publishEvents.getPostPublishingEvents()) {
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, courseOres);
            }
        }
    }
    return true;
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) PublishTreeModel(org.olat.course.tree.PublishTreeModel) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) TreeNode(org.olat.core.gui.components.tree.TreeNode) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 82 with ICourse

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

the class BCWebService method getFolder.

/**
 * Retrieves metadata of the course node
 * @response.representation.200.qname {http://www.example.com}folderVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node metadatas
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or parentNode not found
 * @param courseId The course resourceable's id
 * @param nodeId The node's id
 * @param httpRequest The HTTP request
 * @return The persisted structure element (fully populated)
 */
@GET
@Path("{nodeId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolder(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CourseNode courseNode = course.getRunStructure().getNode(nodeId);
    if (courseNode == null || !(courseNode instanceof BCCourseNode)) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    UserRequest ureq = getUserRequest(httpRequest);
    boolean accessible = (new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment())).isAccessible(courseNode, new VisibleTreeFilter());
    if (accessible) {
        Set<String> subscribed = new HashSet<String>();
        NotificationsManager man = NotificationsManager.getInstance();
        List<String> notiTypes = Collections.singletonList("FolderModule");
        List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
        for (Subscriber sub : subs) {
            Long courseKey = sub.getPublisher().getResId();
            if (courseId.equals(courseKey)) {
                subscribed.add(sub.getPublisher().getSubidentifier());
            }
        }
        FolderVO folderVo = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, (BCCourseNode) courseNode, subscribed);
        return Response.ok(folderVo).build();
    } else {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
}
Also used : FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ICourse(org.olat.course.ICourse) BCCourseNode(org.olat.course.nodes.BCCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 83 with ICourse

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

the class QTIArchiver method exportQTI21.

public MediaResource exportQTI21() {
    ICourse course = CourseFactory.loadCourse(courseOres);
    RepositoryEntry testRe = courseNode.getReferencedRepositoryEntry();
    RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    QTI21StatisticSearchParams searchParams = new QTI21StatisticSearchParams(testRe, courseEntry, courseNode.getIdent(), allUsers, anonymUsers);
    return new QTI21ArchiveFormat(locale, searchParams).exportCourseElement();
}
Also used : QTI21StatisticSearchParams(org.olat.ims.qti21.model.QTI21StatisticSearchParams) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) QTI21ArchiveFormat(org.olat.ims.qti21.manager.archive.QTI21ArchiveFormat)

Example 84 with ICourse

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

the class QTIArchiver method hasResults.

public boolean hasResults() {
    if (results != null)
        return results.booleanValue();
    ICourse course = CourseFactory.loadCourse(courseOres);
    RepositoryEntry testRe = courseNode.getReferencedRepositoryEntry();
    boolean success = false;
    if (ImsQTI21Resource.TYPE_NAME.equals(testRe.getOlatResource().getResourceableTypeName())) {
        type = Type.qti21;
        RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        QTI21StatisticSearchParams searchParams = new QTI21StatisticSearchParams(testRe, courseEntry, courseNode.getIdent(), allUsers, anonymUsers);
        success = new QTI21ArchiveFormat(locale, searchParams).hasResults();
    } else {
        type = Type.qti12;
        success = qrm.hasResultSets(courseOres.getResourceableId(), courseNode.getIdent(), testRe.getKey());
    }
    results = Boolean.valueOf(success);
    return success;
}
Also used : QTI21StatisticSearchParams(org.olat.ims.qti21.model.QTI21StatisticSearchParams) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) QTI21ArchiveFormat(org.olat.ims.qti21.manager.archive.QTI21ArchiveFormat)

Example 85 with ICourse

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

the class FinishCallback method execute.

@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
    FOCourseNode node = (FOCourseNode) runContext.get(SendMailStepForm.FORUM);
    ICourse course = (ICourse) runContext.get(SendMailStepForm.ICOURSE);
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    Forum chosenforum = node.loadOrCreateForum(courseEnv);
    Message msg = (Message) runContext.get(SendMailStepForm.MESSAGE_TO_MOVE);
    msg = forumManager.getMessageById(msg.getKey());
    Message parentMessage = (Message) runContext.get(SendMailStepForm.PARENT_MESSAGE);
    if (parentMessage != null) {
        parentMessage = forumManager.getMessageById(parentMessage.getKey());
    }
    if (msg.getParentKey() == null && msg.getThreadtop() == null) {
        msg = forumManager.createOrAppendThreadInAnotherForum(msg, chosenforum, parentMessage);
    } else {
        msg = forumManager.moveMessageToAnotherForum(msg, chosenforum, parentMessage);
    }
    // commit before sending event
    DBFactory.getInstance().commit();
    if ((Boolean) runContext.get(SendMailStepForm.SENDMAIL)) {
        sendMail(ureq, wControl, runContext);
    }
    return StepsMainRunController.DONE_MODIFIED;
}
Also used : CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) Message(org.olat.modules.fo.Message) FOCourseNode(org.olat.course.nodes.FOCourseNode) ICourse(org.olat.course.ICourse) Forum(org.olat.modules.fo.Forum)

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