use of org.olat.core.util.UserSession in project openolat by klemens.
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);
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class MapperServiceTest method testCleanUpMapper_notSerializable_bySessionId.
@Test
public void testCleanUpMapper_notSerializable_bySessionId() {
// 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
Assert.assertFalse(numOfMappers == mapperService.inMemoryCount());
// cleanup
mapperService.cleanUp(session.getSessionInfo().getSession().getId());
// check 1
Assert.assertEquals(numOfMappers, mapperService.inMemoryCount());
// check 2
Mapper deletedMapper = mapperService.getMapperById(session, mapperKey.getMapperId());
Assert.assertNull(deletedMapper);
}
use of org.olat.core.util.UserSession in project openolat by klemens.
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);
}
use of org.olat.core.util.UserSession in project openolat by klemens.
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());
}
use of org.olat.core.util.UserSession in project openolat by klemens.
the class WebdavStatus method deleteCollection.
/**
* Deletes a collection.
*
* @param path Path to the collection to be deleted
* @param errorList Contains the list of the errors which occurred
*/
private void deleteCollection(HttpServletRequest req, String path, Map<String, Integer> errorList) {
if (log.isDebug())
log.debug("Delete:" + path);
// Prevent deletion of special subdirectories
if (isSpecialPath(path)) {
errorList.put(path, new Integer(WebdavStatus.SC_FORBIDDEN));
return;
}
String ifHeader = req.getHeader("If");
if (ifHeader == null)
ifHeader = "";
String lockTokenHeader = req.getHeader("Lock-Token");
if (lockTokenHeader == null)
lockTokenHeader = "";
final WebResourceRoot resources = getResources(req);
Collection<VFSItem> entries = resources.list(path);
UserSession usess = webDAVManager.getUserSession(req);
for (VFSItem entry : entries) {
String childName = path;
if (!childName.equals("/")) {
childName += "/";
}
childName += entry.getName();
WebResource childResource = resources.getResource(childName);
if (lockManager.isLocked(childResource, ifHeader + lockTokenHeader, usess.getIdentity())) {
errorList.put(childName, new Integer(WebdavStatus.SC_LOCKED));
} else {
if (childResource.isDirectory()) {
deleteCollection(req, childName, errorList);
}
if (!resources.delete(childResource)) {
if (!childResource.isDirectory()) {
// If it's not a collection, then it's an unknown error
errorList.put(childName, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
}
}
}
}
}
Aggregations