Search in sources :

Example 21 with LockResult

use of org.olat.core.util.coordinate.LockResult in project OpenOLAT by OpenOLAT.

the class IQManager method createIQDisplayController.

/**
 * IMS QTI Display Controller from within course -> moduleConfiguration
 *
 * concurrent access check needed -> Editor may save (commit changes) while displaying reads old/new data mix (files and xml structure)
 */
public Controller createIQDisplayController(ModuleConfiguration moduleConfiguration, IQSecurityCallback secCallback, UserRequest ureq, WindowControl wControl, long courseResId, String courseNodeIdent, NavigatorDelegate delegate) {
    // two cases:
    // -- VERY RARE CASE -- 1) qti is open in an editor session right now on the screen (or session on the way to timeout)
    // -- 99% of cases   -- 2) qti is ready to be run as test/survey
    String repositorySoftkey = (String) moduleConfiguration.get(IQEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftkey, false);
    if (re == null) {
        log.error("The test repository entry with this soft key could not be found: " + repositorySoftkey);
        Translator translator = Util.createPackageTranslator(this.getClass(), ureq.getLocale());
        String title = translator.translate("error.test.deleted.title");
        String msg = translator.translate("error.test.deleted.msg");
        return MessageUIFactory.createInfoMessage(ureq, wControl, title, msg);
    } else if (CoordinatorManager.getInstance().getCoordinator().getLocker().isLocked(re.getOlatResource(), null)) {
        Translator translator = Util.createPackageTranslator(this.getClass(), ureq.getLocale());
        // so this resource is locked, let's find out who locked it
        LockResult lockResult = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(re.getOlatResource(), ureq.getIdentity(), null);
        String fullName = userManager.getUserDisplayName(lockResult.getOwner());
        return MessageUIFactory.createInfoMessage(ureq, wControl, translator.translate("status.currently.locked.title"), translator.translate("status.currently.locked", new String[] { fullName }));
    } else {
        ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(re, OlatResourceableType.iq));
        return new IQDisplayController(moduleConfiguration, secCallback, ureq, wControl, courseResId, courseNodeIdent, delegate);
    }
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) Translator(org.olat.core.gui.translator.Translator) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 22 with LockResult

use of org.olat.core.util.coordinate.LockResult in project OpenOLAT by OpenOLAT.

the class IQManager method createIQDisplayController.

/**
 * IMS QTI Display Controller used for IMS course node run view, or for the direct launching from learning resources.
 *
 * concurrent access check needed -> Editor may save (commit changes) while displaying reads old/new data mix (files and xml structure)
 *
 * @param res
 * @param resolver
 * @param type
 * @param secCallback
 * @param ureq
 * @param wControl
 * @return
 */
public MainLayoutController createIQDisplayController(OLATResourceable res, Resolver resolver, String type, IQSecurityCallback secCallback, UserRequest ureq, WindowControl wControl) {
    ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(res, OlatResourceableType.iq));
    // -- 99% of cases   -- 2) qti is ready to be run as test/survey
    if (CoordinatorManager.getInstance().getCoordinator().getLocker().isLocked(res, null)) {
        LockResult lockEntry = CoordinatorManager.getInstance().getCoordinator().getLocker().aquirePersistentLock(res, ureq.getIdentity(), null);
        String fullName = userManager.getUserDisplayName(lockEntry.getOwner());
        GenericMainController glc = createLockedMessageController(ureq, wControl, fullName);
        return glc;
    } else {
        Controller controller = new IQDisplayController(resolver, type, secCallback, ureq, wControl);
        // fxdiff BAKS-7 Resume function
        OLATResourceableListeningWrapperController dwc = new OLATResourceableListeningWrapperController(ureq, wControl, res, controller, null, ureq.getIdentity());
        return dwc;
    }
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) GenericMainController(org.olat.core.gui.control.generic.layout.GenericMainController) OLATResourceableListeningWrapperController(org.olat.core.util.controller.OLATResourceableListeningWrapperController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) GenericMainController(org.olat.core.gui.control.generic.layout.GenericMainController) IQEditController(org.olat.course.nodes.iq.IQEditController) OLATResourceableListeningWrapperController(org.olat.core.util.controller.OLATResourceableListeningWrapperController) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) Controller(org.olat.core.gui.control.Controller)

Example 23 with LockResult

use of org.olat.core.util.coordinate.LockResult in project openolat by klemens.

the class IQManager method createIQDisplayController.

/**
 * IMS QTI Display Controller used for IMS course node run view, or for the direct launching from learning resources.
 *
 * concurrent access check needed -> Editor may save (commit changes) while displaying reads old/new data mix (files and xml structure)
 *
 * @param res
 * @param resolver
 * @param type
 * @param secCallback
 * @param ureq
 * @param wControl
 * @return
 */
public MainLayoutController createIQDisplayController(OLATResourceable res, Resolver resolver, String type, IQSecurityCallback secCallback, UserRequest ureq, WindowControl wControl) {
    ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(res, OlatResourceableType.iq));
    // -- 99% of cases   -- 2) qti is ready to be run as test/survey
    if (CoordinatorManager.getInstance().getCoordinator().getLocker().isLocked(res, null)) {
        LockResult lockEntry = CoordinatorManager.getInstance().getCoordinator().getLocker().aquirePersistentLock(res, ureq.getIdentity(), null);
        String fullName = userManager.getUserDisplayName(lockEntry.getOwner());
        GenericMainController glc = createLockedMessageController(ureq, wControl, fullName);
        return glc;
    } else {
        Controller controller = new IQDisplayController(resolver, type, secCallback, ureq, wControl);
        // fxdiff BAKS-7 Resume function
        OLATResourceableListeningWrapperController dwc = new OLATResourceableListeningWrapperController(ureq, wControl, res, controller, null, ureq.getIdentity());
        return dwc;
    }
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) GenericMainController(org.olat.core.gui.control.generic.layout.GenericMainController) OLATResourceableListeningWrapperController(org.olat.core.util.controller.OLATResourceableListeningWrapperController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) GenericMainController(org.olat.core.gui.control.generic.layout.GenericMainController) IQEditController(org.olat.course.nodes.iq.IQEditController) OLATResourceableListeningWrapperController(org.olat.core.util.controller.OLATResourceableListeningWrapperController) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) Controller(org.olat.core.gui.control.Controller)

Example 24 with LockResult

use of org.olat.core.util.coordinate.LockResult in project openolat by klemens.

the class IQManager method createIQDisplayController.

/**
 * IMS QTI Display Controller from within course -> moduleConfiguration
 *
 * concurrent access check needed -> Editor may save (commit changes) while displaying reads old/new data mix (files and xml structure)
 */
public Controller createIQDisplayController(ModuleConfiguration moduleConfiguration, IQSecurityCallback secCallback, UserRequest ureq, WindowControl wControl, long courseResId, String courseNodeIdent, NavigatorDelegate delegate) {
    // two cases:
    // -- VERY RARE CASE -- 1) qti is open in an editor session right now on the screen (or session on the way to timeout)
    // -- 99% of cases   -- 2) qti is ready to be run as test/survey
    String repositorySoftkey = (String) moduleConfiguration.get(IQEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftkey, false);
    if (re == null) {
        log.error("The test repository entry with this soft key could not be found: " + repositorySoftkey);
        Translator translator = Util.createPackageTranslator(this.getClass(), ureq.getLocale());
        String title = translator.translate("error.test.deleted.title");
        String msg = translator.translate("error.test.deleted.msg");
        return MessageUIFactory.createInfoMessage(ureq, wControl, title, msg);
    } else if (CoordinatorManager.getInstance().getCoordinator().getLocker().isLocked(re.getOlatResource(), null)) {
        Translator translator = Util.createPackageTranslator(this.getClass(), ureq.getLocale());
        // so this resource is locked, let's find out who locked it
        LockResult lockResult = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(re.getOlatResource(), ureq.getIdentity(), null);
        String fullName = userManager.getUserDisplayName(lockResult.getOwner());
        return MessageUIFactory.createInfoMessage(ureq, wControl, translator.translate("status.currently.locked.title"), translator.translate("status.currently.locked", new String[] { fullName }));
    } else {
        ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(re, OlatResourceableType.iq));
        return new IQDisplayController(moduleConfiguration, secCallback, ureq, wControl, courseResId, courseNodeIdent, delegate);
    }
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) Translator(org.olat.core.gui.translator.Translator) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 25 with LockResult

use of org.olat.core.util.coordinate.LockResult in project openolat by klemens.

the class CatalogWebService method addOwner.

/**
 * Add an owner of the local sub tree
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The catalog entry
 * @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_USERVOes}
 * @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 identityKey The id of the user
 * @param httpRquest The HTTP request
 * @return The response
 */
@PUT
@Path("{path:.*}/owners/{identityKey}")
public Response addOwner(@PathParam("path") List<PathSegment> path, @PathParam("identityKey") Long identityKey, @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 (!isAuthor(httpRequest) && !canAdminSubTree(ce, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity identity = securityManager.loadIdentityByKey(identityKey, false);
    if (identity == null) {
        return Response.serverError().status(Status.NOT_FOUND).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 {
        SecurityGroup sg = ce.getOwnerGroup();
        if (sg == null) {
            ce.setOwnerGroup(securityManager.createAndPersistSecurityGroup());
            DBFactory.getInstance().intermediateCommit();
        }
        securityManager.addIdentityToSecurityGroup(identity, ce.getOwnerGroup());
    } catch (Exception e) {
        throw new WebApplicationException(e);
    } finally {
        CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(lock);
    }
    return Response.ok().build();
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) WebApplicationException(javax.ws.rs.WebApplicationException) CatalogEntry(org.olat.repository.CatalogEntry) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) WebApplicationException(javax.ws.rs.WebApplicationException) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Aggregations

LockResult (org.olat.core.util.coordinate.LockResult)28 Identity (org.olat.core.id.Identity)16 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 CatalogEntry (org.olat.repository.CatalogEntry)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 OLATResourceable (org.olat.core.id.OLATResourceable)6 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)6 OLATResource (org.olat.resource.OLATResource)6 Consumes (javax.ws.rs.Consumes)4 DELETE (javax.ws.rs.DELETE)4 GET (javax.ws.rs.GET)4 PUT (javax.ws.rs.PUT)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 SecurityGroup (org.olat.basesecurity.SecurityGroup)4 MediaResource (org.olat.core.gui.media.MediaResource)4 LockEntry (org.olat.core.util.coordinate.LockEntry)4 RepositoryService (org.olat.repository.RepositoryService)4 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)4