use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
the class RepositoryEntriesResource method importFileResource.
private RepositoryEntry importFileResource(Identity identity, File fResource, String resourcename, String displayname, String softkey, int access) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryHandlerFactory handlerFactory = CoreSpringFactory.getImpl(RepositoryHandlerFactory.class);
try {
RepositoryHandler handler = null;
for (String type : handlerFactory.getSupportedTypes()) {
RepositoryHandler h = handlerFactory.getRepositoryHandler(type);
ResourceEvaluation eval = h.acceptImport(fResource, fResource.getName());
if (eval != null && eval.isValid()) {
handler = h;
break;
}
}
RepositoryEntry addedEntry = null;
if (handler != null) {
Locale locale = I18nModule.getDefaultLocale();
addedEntry = handler.importResource(identity, null, displayname, "", true, locale, fResource, fResource.getName());
if (StringHelper.containsNonWhitespace(resourcename)) {
addedEntry.setResourcename(resourcename);
}
if (StringHelper.containsNonWhitespace(softkey)) {
addedEntry.setSoftkey(softkey);
}
if (access < RepositoryEntry.ACC_OWNERS || access > RepositoryEntry.ACC_USERS_GUESTS) {
addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
} else {
addedEntry.setAccess(access);
}
addedEntry = repositoryService.update(addedEntry);
}
return addedEntry;
} catch (Exception e) {
log.error("Fail to import a resource", e);
throw new WebApplicationException(e);
}
}
use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
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.repository.handlers.RepositoryHandler in project openolat by klemens.
the class CourseNodeFactory method launchReferencedRepoEntryEditor.
/**
* Launch an editor for the repository entry which is referenced in the given
* course node. The editor is launched in a new tab.
*
* @param ureq
* @param node
*/
public boolean launchReferencedRepoEntryEditor(UserRequest ureq, WindowControl wControl, CourseNode node) {
RepositoryEntry repositoryEntry = node.getReferencedRepositoryEntry();
if (repositoryEntry == null) {
// do nothing
return false;
}
RepositoryHandler typeToEdit = RepositoryHandlerFactory.getInstance().getRepositoryHandler(repositoryEntry);
if (typeToEdit.supportsEdit(repositoryEntry.getOlatResource()) == EditionSupport.no) {
log.error("Trying to edit repository entry which has no associated editor: " + typeToEdit);
return false;
}
try {
String businessPath = "[RepositoryEntry:" + repositoryEntry.getKey() + "][Editor:0]";
NewControllerFactory.getInstance().launch(businessPath, ureq, wControl);
return true;
} catch (CorruptedCourseException e) {
log.error("Course corrupted: " + repositoryEntry.getKey() + " (" + repositoryEntry.getOlatResource().getResourceableId() + ")", e);
return false;
}
}
use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
the class BlogCourseNode method importNode.
@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
if (withReferences) {
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(BlogFileResource.TYPE_NAME);
importFeed(handler, importDirectory, owner, locale);
} else {
FeedNodeEditController.removeReference(getModuleConfiguration());
}
}
use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
the class IQTESTCourseNode 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()) {
File file = rie.importGetExportedFile();
RepositoryHandler handlerQTI21 = RepositoryHandlerFactory.getInstance().getRepositoryHandler(ImsQTI21Resource.TYPE_NAME);
RepositoryEntry re;
if (handlerQTI21.acceptImport(file, "repo.zip").isValid()) {
re = handlerQTI21.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
getModuleConfiguration().set(IQEditController.CONFIG_KEY_TYPE_QTI, IQEditController.CONFIG_VALUE_QTI21);
} else {
RepositoryHandler handlerQTI = RepositoryHandlerFactory.getInstance().getRepositoryHandler(TestFileResource.TYPE_NAME);
re = handlerQTI.importResource(owner, rie.getInitialAuthor(), rie.getDisplayName(), rie.getDescription(), false, locale, rie.importGetExportedFile(), null);
}
IQEditController.setIQReference(re, getModuleConfiguration());
} else {
IQEditController.removeIQReference(getModuleConfiguration());
}
}
Aggregations