Search in sources :

Example 6 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler 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 7 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler 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 8 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project OpenOLAT by OpenOLAT.

the class RepositoryEntryResource method getRepoFileById.

/**
 * Download the export zip file of a repository entry.
 * @response.representation.mediaType multipart/form-data
 * @response.representation.doc Download the resource file
 * @response.representation.200.mediaType application/zip
 * @response.representation.200.doc Download the repository entry as export zip file
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The resource could not found
 * @response.representation.406.doc Download of this resource is not possible
 * @response.representation.409.doc The resource is locked
 * @param repoEntryKey
 * @param request The HTTP request
 * @return
 */
@GET
@Path("file")
@Produces({ "application/zip", MediaType.APPLICATION_OCTET_STREAM })
public Response getRepoFileById(@PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
    RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
    if (re == null)
        return Response.serverError().status(Status.NOT_FOUND).build();
    RepositoryHandler typeToDownload = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    if (typeToDownload == null)
        return Response.serverError().status(Status.NOT_FOUND).build();
    OLATResource ores = OLATResourceManager.getInstance().findResourceable(re.getOlatResource());
    if (ores == null)
        return Response.serverError().status(Status.NOT_FOUND).build();
    Identity identity = getIdentity(request);
    boolean isAuthor = RestSecurityHelper.isAuthor(request);
    boolean isOwner = repositoryManager.isOwnerOfRepositoryEntry(identity, re);
    if (!(isAuthor | isOwner))
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    boolean canDownload = re.getCanDownload() && typeToDownload.supportsDownload();
    if (!canDownload)
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    boolean isAlreadyLocked = typeToDownload.isLocked(ores);
    LockResult lockResult = null;
    try {
        lockResult = typeToDownload.acquireLock(ores, identity);
        if (lockResult == null || (lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            MediaResource mr = typeToDownload.getAsMediaResource(ores, false);
            if (mr != null) {
                repositoryService.incrementDownloadCounter(re);
                // success
                return Response.ok(mr.getInputStream()).cacheControl(cc).build();
            } else
                return Response.serverError().status(Status.NO_CONTENT).build();
        } else
            return Response.serverError().status(Status.CONFLICT).build();
    } finally {
        if ((lockResult != null && lockResult.isSuccess() && !isAlreadyLocked))
            typeToDownload.releaseLock(lockResult);
    }
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) OLATResource(org.olat.resource.OLATResource) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project OpenOLAT by OpenOLAT.

the class QuestionListController method doOpenCreateRepositoryTest.

private void doOpenCreateRepositoryTest(UserRequest ureq, List<QuestionItemShort> items, String type) {
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(addController);
    RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(type);
    addController = handler.createCreateRepositoryEntryController(ureq, getWindowControl());
    addController.setCreateObject(new QItemList(items));
    listenTo(addController);
    cmc = new CloseableModalController(getWindowControl(), translate("close"), addController.getInitialComponent());
    listenTo(cmc);
    cmc.activate();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) QItemList(org.olat.modules.qpool.model.QItemList)

Example 10 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project OpenOLAT by OpenOLAT.

the class ImportRepositoryEntryController method doImport.

private void doImport() {
    RepositoryHandler handler;
    if (handlerForUploadedResources == null || handlerForUploadedResources.isEmpty()) {
        handler = null;
    } else if (handlerForUploadedResources.size() == 1) {
        handler = handlerForUploadedResources.get(0).getHandler();
    } else if (selectType.isOneSelected()) {
        String type = selectType.getSelectedKey();
        handler = repositoryHandlerFactory.getRepositoryHandler(type);
    } else {
        handler = null;
    }
    if (handler != null) {
        String displayname = displaynameEl.getValue();
        File uploadedFile = uploadFileEl.getUploadFile();
        String uploadedFilename = uploadFileEl.getUploadFileName();
        boolean withReferences = referencesEl.isAtLeastSelected(1);
        importedEntry = handler.importResource(getIdentity(), null, displayname, "", withReferences, getLocale(), uploadedFile, uploadedFilename);
        if (importedEntry == null) {
            showWarning("error.import");
        } else {
            ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_CREATE, getClass(), LoggingResourceable.wrap(importedEntry, OlatResourceableType.genRepoEntry));
            repositoryManager.triggerIndexer(importedEntry);
        }
    }
}
Also used : RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) File(java.io.File)

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