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;
}
}
}
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);
}
}
}
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;
}
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());
}
}
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());
}
}
Aggregations