use of org.olat.core.gui.media.MediaResource 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);
}
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class RepositoryEntryImageMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
if (rootContainer == null) {
rootContainer = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
}
if (relPath.startsWith("/")) {
relPath = relPath.substring(1, relPath.length());
}
MediaResource resource = null;
VFSItem image = rootContainer.resolve(relPath);
if (image instanceof VFSLeaf) {
if (image instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) image).getMetaInfo();
if (info != null) {
// 121 is needed to fill the div
VFSLeaf thumbnail = info.getThumbnail(180, 120, true);
if (thumbnail != null) {
resource = new VFSMediaResource(thumbnail);
}
}
}
if (resource == null) {
resource = new VFSMediaResource((VFSLeaf) image);
}
}
return resource;
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class RepositoryEntryRuntimeController method doDownload.
private void doDownload(UserRequest ureq) {
if (handler == null) {
StringBuilder sb = new StringBuilder(translate("error.download"));
sb.append(": No download handler for repository entry: ").append(re.getKey());
showError(sb.toString());
return;
}
RepositoryEntry entry = repositoryService.loadByKey(re.getKey());
OLATResourceable ores = entry.getOlatResource();
if (ores == null) {
showError("error.download");
return;
}
boolean isAlreadyLocked = handler.isLocked(ores);
try {
lockResult = handler.acquireLock(ores, ureq.getIdentity());
if (lockResult == null || (lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
MediaResource mr = handler.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)) {
handler.releaseLock(lockResult);
lockResult = null;
}
}
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class GoToRecordingController method event.
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == downloadLink) {
String url = recording.getDownloadUrl();
MediaResource downloadUrl = new RedirectMediaResource(url);
ureq.getDispatchResult().setResultingMediaResource(downloadUrl);
}
}
use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.
the class DisplayPortraitManager method getPortraitResource.
/**
* Get the portrait media resource by identity name (username)
* @param identity
* @return imageResource portrait
*/
private MediaResource getPortraitResource(String username, String portraitName) {
MediaResource imageResource = null;
File imgFile = getPortraitFile(username, portraitName);
if (imgFile != null && imgFile.exists()) {
imageResource = new FileMediaResource(imgFile);
}
return imageResource;
}
Aggregations