Search in sources :

Example 1 with MetaInfoFileImpl

use of org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl in project OpenOLAT by OpenOLAT.

the class VFSLockManagerImpl method getVFSLock.

/**
 * Return a lock info base on the VFS lock
 *
 * @param resource
 * @return
 */
public LockInfo getVFSLock(WebResource resource) {
    VFSItem item = extractItem(resource);
    MetaInfoFileImpl info = getMetaInfo(item);
    if (info != null && info.isLocked()) {
        File file = extractFile(item);
        LockInfo lock = null;
        if (fileLocks.containsKey(file)) {
            lock = fileLocks.get(file);
            if (lock != null) {
                lock.setVfsLock(true);
            }
        }
        if (lock == null) {
            lock = new LockInfo(info.getLockedBy(), false, true);
            lock.setWebResource(resource);
            lock.setCreationDate(info.getLockedDate());
            lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy());
            lock.setDepth(1);
            lock.addToken(generateLockToken(lock, info.getLockedBy()));
            fileLocks.put(file, lock);
        }
        return lock;
    }
    return null;
}
Also used : MetaInfoFileImpl(org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File)

Example 2 with MetaInfoFileImpl

use of org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl in project OpenOLAT by OpenOLAT.

the class VFSLockManagerImpl method unlock.

/**
 * Unlock the VFS lock only
 */
@Override
public boolean unlock(VFSItem item, Identity identity, Roles roles) {
    if (item instanceof MetaTagged) {
        MetaInfoFileImpl info = (MetaInfoFileImpl) ((MetaTagged) item).getMetaInfo();
        if (info == null)
            return false;
        info.setLockedBy(null);
        info.setLockedDate(null);
        info.setLocked(false);
        info.write();
        boolean unlocked = false;
        File file = extractFile(item);
        if (file != null && fileLocks.containsKey(file)) {
            LockInfo lock = fileLocks.get(file);
            if (lock.isWebDAVLock()) {
                lock.setVfsLock(false);
            } else {
                if (lock.getWebPath() != null) {
                // LOCK resourceLocks.remove(lock.getWebPath());
                }
                fileLocks.remove(file);
                unlocked = true;
            }
        } else {
            unlocked = true;
        }
        return unlocked;
    }
    return false;
}
Also used : MetaInfoFileImpl(org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) File(java.io.File)

Example 3 with MetaInfoFileImpl

use of org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl in project OpenOLAT by OpenOLAT.

the class VFSLockManagerImpl method getLock.

@Override
public LockInfo getLock(VFSItem item) {
    File file = extractFile(item);
    if (file != null && fileLocks.containsKey(file)) {
        LockInfo lock = fileLocks.get(file);
        if (lock != null) {
            return lock;
        }
    }
    MetaInfoFileImpl info = getMetaInfo(item);
    if (info != null && info.isLocked()) {
        LockInfo lock = new LockInfo(info.getLockedBy(), false, true);
        lock.setCreationDate(info.getLockedDate());
        lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy());
        lock.setDepth(1);
        lock.addToken(generateLockToken(lock, info.getLockedBy()));
        fileLocks.put(file, lock);
        return lock;
    }
    return null;
}
Also used : MetaInfoFileImpl(org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl) File(java.io.File)

Example 4 with MetaInfoFileImpl

use of org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl in project openolat by klemens.

the class VFSLockManagerImpl method lock.

@Override
public boolean lock(VFSItem item, Identity identity, Roles roles) {
    if (item instanceof MetaTagged) {
        MetaInfoFileImpl info = (MetaInfoFileImpl) ((MetaTagged) item).getMetaInfo();
        info.setLockedBy(identity.getKey());
        info.setLockedDate(new Date());
        info.setLocked(true);
        info.write();
        File file = extractFile(item);
        if (file != null && fileLocks.containsKey(file)) {
            LockInfo lock = fileLocks.get(file);
            if (lock != null) {
                lock.setVfsLock(true);
            }
        }
        return true;
    }
    return false;
}
Also used : MetaInfoFileImpl(org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) File(java.io.File) Date(java.util.Date)

Example 5 with MetaInfoFileImpl

use of org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl in project openolat by klemens.

the class VFSLockManagerImpl method getVFSLock.

/**
 * Return a lock info base on the VFS lock
 *
 * @param resource
 * @return
 */
public LockInfo getVFSLock(WebResource resource) {
    VFSItem item = extractItem(resource);
    MetaInfoFileImpl info = getMetaInfo(item);
    if (info != null && info.isLocked()) {
        File file = extractFile(item);
        LockInfo lock = null;
        if (fileLocks.containsKey(file)) {
            lock = fileLocks.get(file);
            if (lock != null) {
                lock.setVfsLock(true);
            }
        }
        if (lock == null) {
            lock = new LockInfo(info.getLockedBy(), false, true);
            lock.setWebResource(resource);
            lock.setCreationDate(info.getLockedDate());
            lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy());
            lock.setDepth(1);
            lock.addToken(generateLockToken(lock, info.getLockedBy()));
            fileLocks.put(file, lock);
        }
        return lock;
    }
    return null;
}
Also used : MetaInfoFileImpl(org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File)

Aggregations

MetaInfoFileImpl (org.olat.core.commons.modules.bc.meta.MetaInfoFileImpl)10 File (java.io.File)8 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)4 Date (java.util.Date)2 VFSItem (org.olat.core.util.vfs.VFSItem)2