Search in sources :

Example 11 with MapperKey

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

the class CustomCSS method registerMapper.

/**
 * @param cssBaseContainer
 * @param uSess
 */
private MapperKey registerMapper(final VFSContainer cssBaseContainer, UserSession uSess) {
    // Register mapper as cacheable
    String mapperID = VFSManager.getRealPath(cssBaseContainer);
    MapperKey mapperKey;
    if (mapperID == null) {
        // Can't cache mapper, no cacheable context available
        mapperKey = CoreSpringFactory.getImpl(MapperService.class).register(uSess, cssUriMapper);
    } else {
        // Add classname to the file path to remove conflicts with other
        // usages of the same file path
        mapperID = this.getClass().getSimpleName() + ":" + mapperID + CodeHelper.getRAMUniqueID();
        mapperKey = CoreSpringFactory.getImpl(MapperService.class).register(uSess, mapperID, cssUriMapper);
    }
    return mapperKey;
}
Also used : MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey)

Example 12 with MapperKey

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

the class MapperServiceTest method testGetMapper.

@Test
public void testGetMapper() {
    // 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.assertEquals(mapper, reloadedMapper);
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

Example 13 with MapperKey

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

the class MapperServiceTest method testRegister.

@Test
public void testRegister() {
    UserSession session = createUserSession();
    MapperKey mapperKey = mapperService.register(session, new DummyMapper());
    Assert.assertNotNull(mapperKey);
    Assert.assertNotNull(mapperKey.getMapperId());
    Assert.assertNotNull(mapperKey.getSessionId());
    Assert.assertNotNull(mapperKey.getUrl());
    Assert.assertTrue(mapperService.inMemoryCount() > 0);
}
Also used : UserSession(org.olat.core.util.UserSession) MapperKey(org.olat.core.dispatcher.mapper.manager.MapperKey) Test(org.junit.Test)

Example 14 with MapperKey

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

the class MapperServiceTest method testChangingMapper_serializable.

@Test
public void testChangingMapper_serializable() {
    // 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
    PersistentMapper reloadedMapper2 = (PersistentMapper) mapperService.getMapperById(null, 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 15 with MapperKey

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

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)

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