Search in sources :

Example 26 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class AuthorListController method doDownload.

protected void doDownload(UserRequest ureq, AuthoringEntryRow row) {
    RepositoryHandler typeToDownload = repositoryHandlerFactory.getRepositoryHandler(row.getResourceType());
    if (typeToDownload == null) {
        StringBuilder sb = new StringBuilder(translate("error.download"));
        sb.append(": No download handler for repository entry: ").append(row.getKey());
        showError(sb.toString());
        return;
    }
    RepositoryEntry entry = repositoryService.loadByKey(row.getKey());
    OLATResourceable ores = entry.getOlatResource();
    if (ores == null) {
        showError("error.download");
        return;
    }
    boolean isAlreadyLocked = typeToDownload.isLocked(ores);
    try {
        lockResult = typeToDownload.acquireLock(ores, ureq.getIdentity());
        if (lockResult == null || (lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            MediaResource mr = typeToDownload.getAsMediaResource(ores, false);
            if (mr != null) {
                repositoryService.incrementDownloadCounter(entry);
                ureq.getDispatchResult().setResultingMediaResource(mr);
            } else {
                showError("error.export");
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        } else if (lockResult != null && lockResult.isSuccess() && isAlreadyLocked) {
            String fullName = userManager.getUserDisplayName(lockResult.getOwner());
            showInfo("warning.course.alreadylocked.bySameUser", fullName);
            // invalid lock, it was already locked
            lockResult = null;
        } else {
            String fullName = userManager.getUserDisplayName(lockResult.getOwner());
            showInfo("warning.course.alreadylocked", fullName);
        }
    } finally {
        if ((lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            typeToDownload.releaseLock(lockResult);
            lockResult = null;
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) OrderedRepositoryHandler(org.olat.repository.handlers.RepositoryHandlerFactory.OrderedRepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 27 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class CourseWebService method getRepoFileById.

/**
 * Export the course
 * @response.representation.200.mediaType application/zip
 * @response.representation.200.doc The course as a ZIP file
 * @response.representation.401.doc Not authorized to export the course
 * @response.representation.404.doc The course not found
 * @return It returns the <code>CourseVO</code> object representing the course.
 */
@GET
@Path("file")
@Produces({ "application/zip", MediaType.APPLICATION_OCTET_STREAM })
public Response getRepoFileById(@Context HttpServletRequest request) {
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    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();
    }
    Identity identity = getIdentity(request);
    boolean canDownload = re.getCanDownload() && typeToDownload.supportsDownload();
    if (isAdmin(request) || RepositoryManager.getInstance().isOwnerOfRepositoryEntry(identity, re)) {
        canDownload = true;
    } else if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    if (!canDownload) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    OLATResource ores = OLATResourceManager.getInstance().findResourceable(re.getOlatResource());
    if (ores == null) {
        return Response.serverError().status(Status.NOT_FOUND).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) {
                rs.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) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class ModifyCourseEvent method deployCourseFromZIP.

/**
 * Deploys a course from an exported course ZIP file. This process is unatended and
 * therefore relies on some default assumptions on how to setup the entry and add
 * any referenced resources to the repository.
 *
 * @param exportedCourseZIPFile
 */
public static RepositoryEntry deployCourseFromZIP(File exportedCourseZIPFile, String softKey, int access) {
    RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(exportedCourseZIPFile);
    if (!StringHelper.containsNonWhitespace(softKey)) {
        softKey = importExport.getSoftkey();
    }
    RepositoryEntry existingEntry = repositoryManager.lookupRepositoryEntryBySoftkey(softKey, false);
    if (existingEntry != null) {
        log.info("RepositoryEntry with softkey " + softKey + " already exists. Course will not be deployed.");
        return existingEntry;
    }
    RepositoryHandler courseHandler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(CourseModule.getCourseTypeName());
    RepositoryEntry re = courseHandler.importResource(null, importExport.getInitialAuthor(), importExport.getDisplayName(), importExport.getDescription(), true, Locale.ENGLISH, exportedCourseZIPFile, exportedCourseZIPFile.getName());
    re.setSoftkey(softKey);
    repositoryService.update(re);
    ICourse course = loadCourse(re);
    publishCourse(course, access, false, null, Locale.ENGLISH);
    return re;
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler)

Example 29 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class IQSURVCourseNode method importNode.

@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
    RepositoryEntryImportExport rie = new RepositoryEntryImportExport(importDirectory, getIdent());
    if (withReferences && rie.anyExportedPropertiesAvailable()) {
        RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(SurveyFileResource.TYPE_NAME);
        RepositoryEntry re = handler.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
        IQEditController.setIQReference(re, getModuleConfiguration());
    } else {
        IQEditController.removeIQReference(getModuleConfiguration());
    }
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 30 with RepositoryHandler

use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.

the class ScormCourseNode method importNode.

@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
    RepositoryEntryImportExport rie = new RepositoryEntryImportExport(importDirectory, getIdent());
    if (withReferences && rie.anyExportedPropertiesAvailable()) {
        RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(ScormCPFileResource.TYPE_NAME);
        RepositoryEntry re = handler.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
        ScormEditController.setScormCPReference(re, getModuleConfiguration());
    } else {
        CPEditController.removeCPReference(getModuleConfiguration());
    }
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry)

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