use of org.olat.core.util.coordinate.LockResult 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.core.util.coordinate.LockResult in project openolat by klemens.
the class IQConfigurationController method doIQReference.
private void doIQReference(UserRequest urequest, RepositoryEntry re, boolean manualCorrection) {
// repository search controller done
if (re != null) {
if (CoordinatorManager.getInstance().getCoordinator().getLocker().isLocked(re.getOlatResource(), null)) {
LockResult lockResult = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(re.getOlatResource(), urequest.getIdentity(), null);
String fullName = CoreSpringFactory.getImpl(UserManager.class).getUserDisplayName(lockResult.getOwner());
showError("error.entry.locked", fullName);
if (lockResult.isSuccess()) {
// improbable concurrency security
CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(lockResult);
}
} else {
if (editTestButton != null) {
myContent.remove(editTestButton);
}
IQEditController.setIQReference(re, moduleConfiguration);
String displayName = StringHelper.escapeHtml(re.getDisplayname());
previewLink = LinkFactory.createCustomLink("command.preview.link", "command.preview", displayName, Link.NONTRANSLATED, myContent, this);
previewLink.setIconLeftCSS("o_icon o_icon-fw o_icon_preview");
previewLink.setCustomEnabledLinkCSS("o_preview");
previewLink.setTitle(getTranslator().translate("command.preview"));
previewButton = LinkFactory.createButtonSmall("command.preview", myContent, this);
previewButton.setIconLeftCSS("o_icon o_icon-fw o_icon_preview");
myContent.contextPut("dontRenderRepositoryButton", new Boolean(true));
// If of type test, get min, max, cut - put in module config and push
// to velocity
boolean isOnyx = OnyxModule.isOnyxTest(re.getOlatResource());
myContent.contextPut("isOnyx", Boolean.valueOf(isOnyx));
if (isOnyx) {
myContent.contextPut("onyxDisplayName", displayName);
moduleConfiguration.set(IQEditController.CONFIG_KEY_TYPE_QTI, IQEditController.CONFIG_VALUE_QTI2);
} else if (ImsQTI21Resource.TYPE_NAME.equals(re.getOlatResource().getResourceableTypeName())) {
moduleConfiguration.set(IQEditController.CONFIG_KEY_TYPE_QTI, IQEditController.CONFIG_VALUE_QTI21);
if (isEditable(urequest.getIdentity(), urequest.getUserSession().getRoles(), re)) {
editTestButton = LinkFactory.createButtonSmall("command.editRepFile", myContent, this);
}
} else {
moduleConfiguration.set(IQEditController.CONFIG_KEY_TYPE_QTI, IQEditController.CONFIG_VALUE_QTI1);
if (isEditable(urequest.getIdentity(), urequest.getUserSession().getRoles(), re)) {
editTestButton = LinkFactory.createButtonSmall("command.editRepFile", myContent, this);
}
}
if (manualCorrection) {
myContent.contextPut(IQEditController.CONFIG_CORRECTION_MODE, "manual");
} else {
myContent.contextPut(IQEditController.CONFIG_CORRECTION_MODE, "auto");
}
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
}
}
use of org.olat.core.util.coordinate.LockResult in project OpenOLAT by OpenOLAT.
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.core.util.coordinate.LockResult in project OpenOLAT by OpenOLAT.
the class CatalogWebService method deleteCatalogEntry.
/**
* Deletes the catalog entry with the path specified in the URL.
* @response.representation.200.qname {http://www.example.com}catalogEntryVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The catalog entry
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_CATALOGENTRYVO}
* @response.representation.401.doc Not authorized
* @response.representation.404.doc The path could not be resolved to a valid catalog entry
* @param path The path
* @param httpRquest The HTTP request
* @return The response
*/
@DELETE
@Path("{path:.*}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCatalogEntry(@PathParam("path") List<PathSegment> path, @Context HttpServletRequest httpRequest) {
Long key = getCatalogEntryKeyFromPath(path);
if (key == null) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
CatalogEntry ce = catalogManager.loadCatalogEntry(key);
if (ce == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (!canAdminSubTree(ce, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Identity id = getUserRequest(httpRequest).getIdentity();
LockResult lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockRes, id, LOCK_TOKEN);
if (!lock.isSuccess()) {
return getLockedResponse(lock, httpRequest);
}
try {
catalogManager.deleteCatalogEntry(ce);
} catch (Exception e) {
throw new WebApplicationException(e);
} finally {
CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(lock);
}
return Response.ok().build();
}
use of org.olat.core.util.coordinate.LockResult in project OpenOLAT by OpenOLAT.
the class FeedManagerImpl method acquireLock.
@Override
public LockResult acquireLock(OLATResourceable feed, Item item, Identity identity) {
String key = itemKey(item, feed);
if (key.length() >= OresHelper.ORES_TYPE_LENGTH) {
key = Encoder.md5hash(key);
}
OLATResourceable itemResource = OresHelper.createOLATResourceableType(key);
LockResult lockResult = coordinator.getLocker().acquireLock(itemResource, identity, key);
return lockResult;
}
Aggregations