Search in sources :

Example 66 with ICourse

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

the class CoursesWebService method createEmptyCourse.

/**
 * Creates an empty course, or a copy from a course if the parameter copyFrom is set.
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The metadatas of the created course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param shortTitle The short title
 * @param title The title
 * @param sharedFolderSoftKey The repository entry key of a shared folder (optional)
 * @param copyFrom The course primary key key to make a copy from (optional)
 * @param initialAuthor The primary key of the initial author (optional)
 * @param noAuthor True to create a course without the author
 * @param request The HTTP request
 * @return It returns the id of the newly created Course
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(@QueryParam("shortTitle") String shortTitle, @QueryParam("title") String title, @QueryParam("displayName") String displayName, @QueryParam("description") String description, @QueryParam("softKey") String softKey, @QueryParam("access") Integer access, @QueryParam("membersOnly") Boolean membersOnly, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("authors") String authors, @QueryParam("location") String location, @QueryParam("managedFlags") String managedFlags, @QueryParam("sharedFolderSoftKey") String sharedFolderSoftKey, @QueryParam("copyFrom") Long copyFrom, @QueryParam("initialAuthor") Long initialAuthor, @QueryParam("setAuthor") @DefaultValue("true") Boolean setAuthor, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CourseConfigVO configVO = new CourseConfigVO();
    configVO.setSharedFolderSoftKey(sharedFolderSoftKey);
    int accessInt = (access == null ? RepositoryEntry.ACC_OWNERS : access.intValue());
    boolean membersOnlyBool = (membersOnly == null ? false : membersOnly.booleanValue());
    if (!StringHelper.containsNonWhitespace(displayName)) {
        displayName = shortTitle;
    }
    ICourse course;
    UserRequest ureq = getUserRequest(request);
    Identity id = null;
    if (setAuthor != null && setAuthor.booleanValue()) {
        if (initialAuthor != null) {
            id = getIdentity(initialAuthor);
        }
        if (id == null) {
            id = ureq.getIdentity();
        }
    }
    if (copyFrom != null) {
        course = copyCourse(copyFrom, ureq, id, shortTitle, title, displayName, description, softKey, accessInt, membersOnlyBool, authors, location, externalId, externalRef, managedFlags, configVO);
    } else {
        course = createEmptyCourse(id, shortTitle, title, displayName, description, softKey, accessInt, membersOnlyBool, authors, location, externalId, externalRef, managedFlags, configVO);
    }
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    CourseVO vo = ObjectFactory.get(course);
    return Response.ok(vo).build();
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CourseVO(org.olat.restapi.support.vo.CourseVO) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 67 with ICourse

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

the class CoursesWebService method importCourse.

public static ICourse importCourse(UserRequest ureq, Identity identity, File fCourseImportZIP, String displayName, String softKey, int access, boolean membersOnly) {
    log.info("REST Import course " + displayName + " START");
    if (!StringHelper.containsNonWhitespace(displayName)) {
        displayName = "import-" + UUID.randomUUID().toString();
    }
    RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(CourseModule.getCourseTypeName());
    RepositoryEntry re = handler.importResource(identity, null, displayName, null, true, Locale.ENGLISH, fCourseImportZIP, null);
    if (StringHelper.containsNonWhitespace(softKey)) {
        re.setSoftkey(softKey);
    }
    // make the repository
    if (membersOnly) {
        re.setMembersOnly(true);
        re.setAccess(RepositoryEntry.ACC_OWNERS);
    } else {
        re.setAccess(access);
    }
    CoreSpringFactory.getImpl(RepositoryService.class).update(re);
    log.info("REST Import course " + displayName + " END");
    // publish
    log.info("REST Publish course " + displayName + " START");
    ICourse course = CourseFactory.loadCourse(re);
    CourseFactory.publishCourse(course, RepositoryEntry.ACC_USERS, false, identity, ureq.getLocale());
    log.info("REST Publish course " + displayName + " END");
    return course;
}
Also used : ICourse(org.olat.course.ICourse) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 68 with ICourse

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

the class CoursesWebService method copyCourse.

private static ICourse copyCourse(Long copyFrom, UserRequest ureq, Identity initialAuthor, String shortTitle, String longTitle, String displayName, String description, String softKey, int access, boolean membersOnly, String authors, String location, String externalId, String externalRef, String managedFlags, CourseConfigVO courseConfigVO) {
    // String learningObjectives = name + " (Example of creating a new course)";
    OLATResourceable originalOresTrans = OresHelper.createOLATResourceableInstance(CourseModule.class, copyFrom);
    RepositoryEntry src = RepositoryManager.getInstance().lookupRepositoryEntry(originalOresTrans, false);
    if (src == null) {
        src = RepositoryManager.getInstance().lookupRepositoryEntry(copyFrom, false);
    }
    if (src == null) {
        log.warn("Cannot find course to copy from: " + copyFrom);
        return null;
    }
    OLATResource originalOres = OLATResourceManager.getInstance().findResourceable(src.getOlatResource());
    boolean isAlreadyLocked = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).isLocked(originalOres);
    LockResult lockResult = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).acquireLock(originalOres, ureq.getIdentity());
    // check range of access
    if (access < 1 || access > RepositoryEntry.ACC_USERS_GUESTS) {
        access = RepositoryEntry.ACC_OWNERS;
    }
    if (lockResult == null || (lockResult != null && lockResult.isSuccess()) && !isAlreadyLocked) {
        RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
        // create new repo entry
        String name;
        if (description == null || description.trim().length() == 0) {
            description = src.getDescription();
        }
        if (courseConfigVO != null && StringHelper.containsNonWhitespace(displayName)) {
            name = displayName;
        } else {
            name = "Copy of " + src.getDisplayname();
        }
        String resName = src.getResourcename();
        if (resName == null) {
            resName = "";
        }
        OLATResource sourceResource = src.getOlatResource();
        OLATResource copyResource = OLATResourceManager.getInstance().createOLATResourceInstance(sourceResource.getResourceableTypeName());
        RepositoryEntry preparedEntry = repositoryService.create(initialAuthor, null, resName, name, description, copyResource, RepositoryEntry.ACC_OWNERS);
        RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src);
        preparedEntry = handler.copy(initialAuthor, src, preparedEntry);
        preparedEntry.setCanDownload(src.getCanDownload());
        if (StringHelper.containsNonWhitespace(softKey)) {
            preparedEntry.setSoftkey(softKey);
        }
        if (StringHelper.containsNonWhitespace(externalId)) {
            preparedEntry.setExternalId(externalId);
        }
        if (StringHelper.containsNonWhitespace(externalRef)) {
            preparedEntry.setExternalRef(externalRef);
        }
        if (StringHelper.containsNonWhitespace(authors)) {
            preparedEntry.setAuthors(authors);
        }
        if (StringHelper.containsNonWhitespace(location)) {
            preparedEntry.setLocation(location);
        }
        if (StringHelper.containsNonWhitespace(managedFlags)) {
            preparedEntry.setManagedFlagsString(managedFlags);
        }
        if (membersOnly) {
            preparedEntry.setMembersOnly(true);
            preparedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
        } else {
            preparedEntry.setAccess(access);
        }
        preparedEntry.setAllowToLeaveOption(src.getAllowToLeaveOption());
        repositoryService.update(preparedEntry);
        // copy image if available
        RepositoryManager.getInstance().copyImage(src, preparedEntry);
        ICourse course = prepareCourse(preparedEntry, shortTitle, longTitle, courseConfigVO);
        RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).releaseLock(lockResult);
        return course;
    }
    return null;
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) OLATResourceable(org.olat.core.id.OLATResourceable) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryService(org.olat.repository.RepositoryService)

Example 69 with ICourse

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

the class CoursesWebService method getCourse.

@Path("{courseId}")
public CourseWebService getCourse(@PathParam("courseId") Long courseId) {
    ICourse course = loadCourse(courseId);
    if (course == null) {
        return null;
    }
    OLATResource ores = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    return new CourseWebService(ores, course);
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) Path(javax.ws.rs.Path)

Example 70 with ICourse

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

the class CourseElementWebService method getTestConfiguration.

/**
 * Retrieves configuration of the test course node
 * @response.representation.200.qname {http://www.example.com}testConfigVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node configuration
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or test node not found
 * @param courseId
 * @param nodeId
 * @return test course node configuration
 */
@GET
@Path("test/{nodeId}/configuration")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTestConfiguration(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId) {
    TestConfigVO config = new TestConfigVO();
    ICourse course = CoursesWebService.loadCourse(courseId);
    CourseNode courseNode = getParentNode(course, nodeId);
    // build configuration with fallback to default values
    ModuleConfiguration moduleConfig = courseNode.getModuleConfiguration();
    Boolean allowCancel = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLECANCEL);
    config.setAllowCancel(allowCancel == null ? false : allowCancel);
    Boolean allowNavi = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLEMENU);
    config.setAllowNavigation(allowNavi == null ? false : allowNavi);
    Boolean allowSuspend = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLESUSPEND);
    config.setAllowSuspend(allowSuspend == null ? false : allowSuspend);
    config.setNumAttempts(moduleConfig.getIntegerSafe(IQEditController.CONFIG_KEY_ATTEMPTS, 0));
    config.setSequencePresentation(moduleConfig.getStringValue(IQEditController.CONFIG_KEY_SEQUENCE, AssessmentInstance.QMD_ENTRY_SEQUENCE_ITEM));
    Boolean showNavi = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_DISPLAYMENU);
    config.setShowNavigation(showNavi == null ? true : showNavi);
    Boolean showQuestionTitle = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_QUESTIONTITLE);
    config.setShowQuestionTitle(showQuestionTitle == null ? true : showQuestionTitle);
    Boolean showResFinish = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_RESULT_ON_FINISH);
    config.setShowResultsAfterFinish(showResFinish == null ? true : showResFinish);
    Boolean showResDate = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_DATE_DEPENDENT_RESULTS);
    config.setShowResultsDependendOnDate(showResDate == null ? false : showResDate);
    config.setShowResultsStartDate((Date) moduleConfig.get(IQEditController.CONFIG_KEY_RESULTS_START_DATE));
    config.setShowResultsEndDate((Date) moduleConfig.get(IQEditController.CONFIG_KEY_RESULTS_END_DATE));
    Boolean showResHomepage = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_RESULT_ON_HOME_PAGE);
    config.setShowResultsOnHomepage(showResHomepage == null ? false : showResHomepage);
    Boolean showScoreInfo = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLESCOREINFO);
    config.setShowScoreInfo(showScoreInfo == null ? true : showScoreInfo);
    Boolean showQuestionProgress = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_QUESTIONPROGRESS);
    config.setShowQuestionProgress(showQuestionProgress == null ? true : showQuestionProgress);
    Boolean showScoreProgress = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_SCOREPROGRESS);
    config.setShowScoreProgress(showScoreProgress == null ? true : showScoreProgress);
    Boolean showSectionsOnly = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_RENDERMENUOPTION);
    config.setShowSectionsOnly(showSectionsOnly == null ? false : showSectionsOnly);
    config.setSummeryPresentation(moduleConfig.getStringValue(IQEditController.CONFIG_KEY_SUMMARY, AssessmentInstance.QMD_ENTRY_SUMMARY_COMPACT));
    return Response.ok(config).build();
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) TestConfigVO(org.olat.restapi.support.vo.elements.TestConfigVO) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) AbstractFeedCourseNode(org.olat.course.nodes.AbstractFeedCourseNode) IQSURVCourseNode(org.olat.course.nodes.IQSURVCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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