Search in sources :

Example 16 with MapperKey

use of org.olat.core.dispatcher.mapper.manager.MapperKey in project OpenOLAT by OpenOLAT.

the class MapperServiceTest method testChangingMapper_serializableSessionChanged.

@Test
public void testChangingMapper_serializableSessionChanged() {
    // create a mapper
    int initialNumOfMappers = mapperService.inMemoryCount();
    UserSession session = createUserSession();
    PersistentMapper mapper = new PersistentMapper(UUID.randomUUID().toString());
    MapperKey mapperKey = mapperService.register(session, mapper);
    dbInstance.commitAndCloseSession();
    // retrieve the mapper
    PersistentMapper reloadedMapper = (PersistentMapper) mapperService.getMapperById(session, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper);
    Assert.assertEquals(mapper, reloadedMapper);
    Assert.assertFalse(initialNumOfMappers == mapperService.inMemoryCount());
    // changing the key in the mapper
    String modKey = UUID.randomUUID().toString();
    reloadedMapper.setKey(modKey);
    // remove in memory mappers
    mapperService.cleanUp(Collections.<MapperKey>singletonList(mapperKey));
    mapperService.cleanUp(session.getSessionInfo().getSession().getId());
    Assert.assertEquals(initialNumOfMappers, mapperService.inMemoryCount());
    // reloaded episode 2
    UserSession session2 = createUserSession();
    PersistentMapper reloadedMapper2 = (PersistentMapper) mapperService.getMapperById(session2, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper2);
    Assert.assertEquals(modKey, reloadedMapper2.getKey());
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

Example 17 with MapperKey

use of org.olat.core.dispatcher.mapper.manager.MapperKey in project OpenOLAT by OpenOLAT.

the class BasicController method registerCacheableMapper.

/**
 * Convenience method: registers a cacheable mapper which will be
 * automatically deregistered upon dispose of the controller
 * @param ureq
 * @param cacheableMapperID
 * @param m The mapper
 * @param expirationTime -1 is the default bevahiour, else is expiration time in seconds
 * @return
 */
protected String registerCacheableMapper(UserRequest ureq, String cacheableMapperID, Mapper m, int expirationTime) {
    if (mapperKeys == null) {
        mapperKeys = new ArrayList<MapperKey>(2);
    }
    MapperKey mapperBaseKey;
    UserSession usess = ureq == null ? null : ureq.getUserSession();
    if (cacheableMapperID == null) {
        // use non cacheable as fallback
        mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, m);
    } else {
        mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, cacheableMapperID, m, expirationTime);
    }
    // registration was successful, add to our mapper list
    mapperKeys.add(mapperBaseKey);
    return mapperBaseKey.getUrl();
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey)

Example 18 with MapperKey

use of org.olat.core.dispatcher.mapper.manager.MapperKey in project openolat by klemens.

the class MapperServiceTest method testCleanUpMapper_notSerializable_byMappers.

@Test
public void testCleanUpMapper_notSerializable_byMappers() {
    // number of currently hold mappers
    int numOfMappers = mapperService.inMemoryCount();
    // create a mapper
    UserSession session = createUserSession();
    DummyMapper mapper = new DummyMapper();
    MapperKey mapperKey = mapperService.register(session, mapper);
    dbInstance.commitAndCloseSession();
    // retrieve the mapper
    Mapper reloadedMapper = mapperService.getMapperById(session, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper);
    Assert.assertFalse(numOfMappers == mapperService.inMemoryCount());
    // cleanup
    mapperService.cleanUp(Collections.<MapperKey>singletonList(mapperKey));
    // check 1
    Mapper deletedMapper = mapperService.getMapperById(session, mapperKey.getMapperId());
    Assert.assertNull(deletedMapper);
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

Example 19 with MapperKey

use of org.olat.core.dispatcher.mapper.manager.MapperKey in project openolat by klemens.

the class MapperServiceTest method testChangingMapper_serializableSessionChanged.

@Test
public void testChangingMapper_serializableSessionChanged() {
    // create a mapper
    int initialNumOfMappers = mapperService.inMemoryCount();
    UserSession session = createUserSession();
    PersistentMapper mapper = new PersistentMapper(UUID.randomUUID().toString());
    MapperKey mapperKey = mapperService.register(session, mapper);
    dbInstance.commitAndCloseSession();
    // retrieve the mapper
    PersistentMapper reloadedMapper = (PersistentMapper) mapperService.getMapperById(session, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper);
    Assert.assertEquals(mapper, reloadedMapper);
    Assert.assertFalse(initialNumOfMappers == mapperService.inMemoryCount());
    // changing the key in the mapper
    String modKey = UUID.randomUUID().toString();
    reloadedMapper.setKey(modKey);
    // remove in memory mappers
    mapperService.cleanUp(Collections.<MapperKey>singletonList(mapperKey));
    mapperService.cleanUp(session.getSessionInfo().getSession().getId());
    Assert.assertEquals(initialNumOfMappers, mapperService.inMemoryCount());
    // reloaded episode 2
    UserSession session2 = createUserSession();
    PersistentMapper reloadedMapper2 = (PersistentMapper) mapperService.getMapperById(session2, mapperKey.getMapperId());
    Assert.assertNotNull(reloadedMapper2);
    Assert.assertEquals(modKey, reloadedMapper2.getKey());
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

Example 20 with MapperKey

use of org.olat.core.dispatcher.mapper.manager.MapperKey in project openolat by klemens.

the class BasicController method registerCacheableMapper.

/**
 * Convenience method: registers a cacheable mapper which will be
 * automatically deregistered upon dispose of the controller
 * @param ureq
 * @param cacheableMapperID
 * @param m The mapper
 * @param expirationTime -1 is the default bevahiour, else is expiration time in seconds
 * @return
 */
protected String registerCacheableMapper(UserRequest ureq, String cacheableMapperID, Mapper m, int expirationTime) {
    if (mapperKeys == null) {
        mapperKeys = new ArrayList<MapperKey>(2);
    }
    MapperKey mapperBaseKey;
    UserSession usess = ureq == null ? null : ureq.getUserSession();
    if (cacheableMapperID == null) {
        // use non cacheable as fallback
        mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, m);
    } else {
        mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, cacheableMapperID, m, expirationTime);
    }
    // registration was successful, add to our mapper list
    mapperKeys.add(mapperBaseKey);
    return mapperBaseKey.getUrl();
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey)

Aggregations

MapperKey (org.olat.core.dispatcher.mapper.manager.MapperKey)20 UserSession (org.olat.core.util.UserSession)16 Test (org.junit.Test)14 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 GlobalSettings (org.olat.core.gui.GlobalSettings)2 Windows (org.olat.core.gui.Windows)2 InvalidRequestParameterException (org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException)2 ChiefController (org.olat.core.gui.control.ChiefController)2 Command (org.olat.core.gui.control.winmgr.Command)2 JSCommand (org.olat.core.gui.control.winmgr.JSCommand)2 MediaResourceMapper (org.olat.core.gui.control.winmgr.MediaResourceMapper)2 AsyncMediaResponsible (org.olat.core.gui.media.AsyncMediaResponsible)2 MediaResource (org.olat.core.gui.media.MediaResource)2 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)2 RenderResult (org.olat.core.gui.render.RenderResult)2 Renderer (org.olat.core.gui.render.Renderer)2 StringOutput (org.olat.core.gui.render.StringOutput)2