Search in sources :

Example 1 with LockInfo

use of io.milton.http.LockInfo in project lobcder by skoulouzis.

the class WebDataResource method getCurrentLock.

@Override
public LockToken getCurrentLock() {
    if (getLogicalData().getLockTokenID() == null) {
        return null;
    } else {
        LockInfo lockInfo = new LockInfo(LockInfo.LockScope.valueOf(getLogicalData().getLockScope()), LockInfo.LockType.valueOf(getLogicalData().getLockType()), getLogicalData().getLockedByUser(), LockInfo.LockDepth.valueOf(getLogicalData().getLockDepth()));
        LockTimeout lockTimeOut = new LockTimeout(getLogicalData().getLockTimeout());
        return new LockToken(getLogicalData().getLockTokenID(), lockInfo, lockTimeOut);
    }
}
Also used : LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo) LockTimeout(io.milton.http.LockTimeout)

Example 2 with LockInfo

use of io.milton.http.LockInfo in project lobcder by skoulouzis.

the class ItemBean method main.

// / test
public static void main(String[] args) {
    try {
        DatatypeFactory df = DatatypeFactory.newInstance();
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        ItemBean ldb = new ItemBean();
        ldb.setUid(123L);
        ldb.setCreateDate(df.newXMLGregorianCalendar(gregorianCalendar));
        ldb.setType(Type.FILE);
        ldb.setName("Name");
        ldb.setParentRef(45L);
        Permissions p = new Permissions();
        p.setOwner("Dima");
        p.getRead().add("group_read1");
        p.getRead().add("group_read2");
        p.getWrite().add("group_write1");
        ldb.setPermissions(p);
        ldb.setParentRef(46L);
        ldb.addContentType("application/xml");
        ldb.setPath("/qwa/qwe");
        List<PDRIDescr> pris = new ArrayList<>();
        // pdril.getPdriList().add(new PdriBean("name", "url", "username", "password", false, null, false));
        // pdril.getPdriList().add(new PdriBean("name2","url", "username", "password", false, null, false));
        // ldb.setPdriList(pdril);
        LockInfo lockInfo = new LockInfo(LockInfo.LockScope.EXCLUSIVE, LockInfo.LockType.WRITE, "user", LockInfo.LockDepth.INFINITY);
        // LockTokenBean lockToken = new LockTokenBean();
        // lockToken.setLocktoken("token-name");
        // lockToken.setLockInfo(lockInfo);
        // lockToken.setLockedUntil(df.newXMLGregorianCalendar(gregorianCalendar));
        // ldb.setLock(lockToken);
        DriBean dri = new DriBean();
        dri.setStatus(DriBean.Status.unavailable);
        ldb.setDri(dri);
        JAXBContext context = JAXBContext.newInstance(ItemBean.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(ldb, System.err);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) DatatypeFactory(javax.xml.datatype.DatatypeFactory) PDRIDescr(nl.uva.cs.lobcder.resources.PDRIDescr) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Permissions(nl.uva.cs.lobcder.auth.Permissions) LockInfo(io.milton.http.LockInfo) JAXBContext(javax.xml.bind.JAXBContext)

Example 3 with LockInfo

use of io.milton.http.LockInfo in project lobcder by skoulouzis.

the class MemoryLockManagerTest method testLockUnLock.

public void testLockUnLock() throws NotAuthorizedException {
    LockTimeout timeout = new LockTimeout(100l);
    LockInfo lockInfo = new LockInfo(LockInfo.LockScope.NONE, LockInfo.LockType.READ, "me", LockInfo.LockDepth.ZERO);
    SimpleFileContentService contentService = new SimpleFileContentService();
    FsResource resource = new FsFileResource(null, null, new File(File.pathSeparator), contentService);
    // lock it
    LockResult res = lockManager.lock(timeout, lockInfo, resource);
    assertNotNull(res);
    assertTrue(res.isSuccessful());
    // check is locked
    LockToken token = lockManager.getCurrentToken(resource);
    assertNotNull(token);
    assertEquals(token.tokenId, res.getLockToken().tokenId);
    // unlock
    lockManager.unlock(token.tokenId, resource);
    // check removed
    token = lockManager.getCurrentToken(resource);
    assertNull(token);
}
Also used : FsResource(io.milton.http.fs.FsResource) LockResult(io.milton.http.LockResult) FsFileResource(io.milton.http.fs.FsFileResource) LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo) SimpleFileContentService(io.milton.http.fs.SimpleFileContentService) File(java.io.File) LockTimeout(io.milton.http.LockTimeout)

Example 4 with LockInfo

use of io.milton.http.LockInfo in project lobcder by skoulouzis.

the class SimpleLockManager method getCurrentToken.

public LockToken getCurrentToken(LockableResource r) {
    CurrentLock lock = locksByUniqueId.get(r.getUniqueId());
    if (lock == null)
        return null;
    LockToken token = new LockToken();
    token.info = new LockInfo(LockInfo.LockScope.EXCLUSIVE, LockInfo.LockType.WRITE, lock.lockedByUser, LockInfo.LockDepth.ZERO);
    token.info.lockedByUser = lock.lockedByUser;
    token.timeout = lock.token.timeout;
    token.tokenId = lock.token.tokenId;
    return token;
}
Also used : LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo)

Example 5 with LockInfo

use of io.milton.http.LockInfo in project lobcder by skoulouzis.

the class LockHandler method parseLockInfo.

private LockInfo parseLockInfo(Request request) throws IOException, SAXException {
    InputStream in = request.getInputStream();
    XMLReader reader = XMLReaderFactory.createXMLReader();
    LockInfoSaxHandler handler = new LockInfoSaxHandler();
    reader.setContentHandler(handler);
    reader.parse(new InputSource(in));
    LockInfo info = handler.getInfo();
    // todo
    info.depth = LockDepth.INFINITY;
    info.lockedByUser = null;
    if (request.getAuthorization() != null) {
        info.lockedByUser = request.getAuthorization().getUser();
    }
    if (info.lockedByUser == null) {
    }
    return info;
}
Also used : InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) LockInfoSaxHandler(io.milton.http.LockInfoSaxHandler) LockInfo(io.milton.http.LockInfo) XMLReader(org.xml.sax.XMLReader)

Aggregations

LockInfo (io.milton.http.LockInfo)8 LockToken (io.milton.http.LockToken)5 LockTimeout (io.milton.http.LockTimeout)4 LockResult (io.milton.http.LockResult)2 LockInfoSaxHandler (io.milton.http.LockInfoSaxHandler)1 FsFileResource (io.milton.http.fs.FsFileResource)1 FsResource (io.milton.http.fs.FsResource)1 SimpleFileContentService (io.milton.http.fs.SimpleFileContentService)1 LockingCollectionResource (io.milton.resource.LockingCollectionResource)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 DatatypeFactory (javax.xml.datatype.DatatypeFactory)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Permissions (nl.uva.cs.lobcder.auth.Permissions)1 PDRIDescr (nl.uva.cs.lobcder.resources.PDRIDescr)1 InputSource (org.xml.sax.InputSource)1