@Test public void testLock() { Map<String, String> headers = new HashMap<>(); headers.put(OVERRIDE, Operation.LOCK.name()); checkPostNotFound(headers); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(400, response.getStatus()); } headers.put(LOCK, ""); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(400, response.getStatus()); } headers.put(LOCK, "foo"); try (CloseableClientResponse response = post(joeToken, headers, blobDocFileId)) { assertEquals(409, response.getStatus()); } assertLockResponseOKForJohn(headers); assertLockResponseOKForJohn(headers); headers.put(LOCK, "bar"); assertConflictResponseWithLock(headers); session.getDocument(hugeBlobDoc.getRef()).setLock(); transactionalFeature.nextTransaction(); try (CloseableClientResponse response = post(johnToken, headers, hugeBlobDocFileId)) { assertEquals(409, response.getStatus()); transactionalFeature.nextTransaction(); assertTrue(session.getDocument(hugeBlobDoc.getRef()).isLocked()); } }
protected Object lock(String lock) { logRequest(OPERATION_LOCK, LOCK, lock); boolean isLocked = doc.isLocked(); if (!isLocked || !LockHelper.isLocked(fileId)) { logCondition("Document isn't locked or there is no WOPI lock for this file id"); checkWritePropertiesPermission(OPERATION_LOCK); if (!isLocked) { logCondition("Document isn't locked"); logNuxeoAction("Locking document"); doc.setLock(); } LockHelper.addLock(fileId, lock); return buildItemVersionResponse(OPERATION_LOCK, blob); } logCondition("Document is locked and there is a WOPI lock for this file id"); String currentLock = getCurrentLock(OPERATION_LOCK); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); LockHelper.refreshLock(fileId); return buildItemVersionResponse(OPERATION_LOCK, blob); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_LOCK, currentLock); } }
FilesEndpoint extends DefaultObject { protected Object lock(String lock) { logRequest(OPERATION_LOCK, LOCK, lock); boolean isLocked = doc.isLocked(); if (!isLocked || !LockHelper.isLocked(fileId)) { logCondition("Document isn't locked or there is no WOPI lock for this file id"); checkWritePropertiesPermission(OPERATION_LOCK); if (!isLocked) { logCondition("Document isn't locked"); logNuxeoAction("Locking document"); doc.setLock(); } LockHelper.addLock(fileId, lock); return buildItemVersionResponse(OPERATION_LOCK, blob); } logCondition("Document is locked and there is a WOPI lock for this file id"); String currentLock = getCurrentLock(OPERATION_LOCK); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); LockHelper.refreshLock(fileId); return buildItemVersionResponse(OPERATION_LOCK, blob); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_LOCK, currentLock); } } }
FilesEndpoint extends DefaultObject { protected Object lock(String lock) { logRequest(OPERATION_LOCK, LOCK, lock); boolean isLocked = doc.isLocked(); if (!isLocked || !LockHelper.isLocked(fileId)) { logCondition("Document isn't locked or there is no WOPI lock for this file id"); checkWritePropertiesPermission(OPERATION_LOCK); if (!isLocked) { logCondition("Document isn't locked"); logNuxeoAction("Locking document"); doc.setLock(); } LockHelper.addLock(fileId, lock); return buildItemVersionResponse(OPERATION_LOCK, blob); } logCondition("Document is locked and there is a WOPI lock for this file id"); String currentLock = getCurrentLock(OPERATION_LOCK); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); LockHelper.refreshLock(fileId); return buildItemVersionResponse(OPERATION_LOCK, blob); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_LOCK, currentLock); } }  }
FilesEndpoint extends DefaultObject { protected Object lock(String lock) { logRequest(OPERATION_LOCK, LOCK, lock); boolean isLocked = doc.isLocked(); if (!isLocked || !LockHelper.isLocked(fileId)) { logCondition("Document isn't locked or there is no WOPI lock for this file id"); checkWritePropertiesPermission(OPERATION_LOCK); if (!isLocked) { logCondition("Document isn't locked"); logNuxeoAction("Locking document"); doc.setLock(); } LockHelper.addLock(fileId, lock); return buildItemVersionResponse(OPERATION_LOCK, blob); } logCondition("Document is locked and there is a WOPI lock for this file id"); String currentLock = getCurrentLock(OPERATION_LOCK); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); LockHelper.refreshLock(fileId); return buildItemVersionResponse(OPERATION_LOCK, blob); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_LOCK, currentLock); } }  @Override void initialize(Object... args); @GET @Produces(MediaType.APPLICATION_JSON) Response checkFileInfo(); @GET @Path("contents") Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader); @POST Object doPost(@HeaderParam(OVERRIDE) Operation operation); Object putRelativeFile(); Object renameFile(); Object getShareUrl(); @POST @Path("contents") Object doPostContents(@HeaderParam(OVERRIDE) Operation operation); Object putFile(); }
FilesEndpoint extends DefaultObject { protected Object lock(String lock) { logRequest(OPERATION_LOCK, LOCK, lock); boolean isLocked = doc.isLocked(); if (!isLocked || !LockHelper.isLocked(fileId)) { logCondition("Document isn't locked or there is no WOPI lock for this file id"); checkWritePropertiesPermission(OPERATION_LOCK); if (!isLocked) { logCondition("Document isn't locked"); logNuxeoAction("Locking document"); doc.setLock(); } LockHelper.addLock(fileId, lock); return buildItemVersionResponse(OPERATION_LOCK, blob); } logCondition("Document is locked and there is a WOPI lock for this file id"); String currentLock = getCurrentLock(OPERATION_LOCK); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); LockHelper.refreshLock(fileId); return buildItemVersionResponse(OPERATION_LOCK, blob); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_LOCK, currentLock); } }  @Override void initialize(Object... args); @GET @Produces(MediaType.APPLICATION_JSON) Response checkFileInfo(); @GET @Path("contents") Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader); @POST Object doPost(@HeaderParam(OVERRIDE) Operation operation); Object putRelativeFile(); Object renameFile(); Object getShareUrl(); @POST @Path("contents") Object doPostContents(@HeaderParam(OVERRIDE) Operation operation); Object putFile();  }