@Test public void testUnlockAndRelock() { 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"); headers.put(OLD_LOCK, "foo"); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(409, response.getStatus()); transactionalFeature.nextTransaction(); assertFalse(session.getDocument(blobDoc.getRef()).isLocked()); String lock = response.getHeaders().getFirst(LOCK); assertEquals("", lock); } headers.remove(OLD_LOCK); headers.put(LOCK, "foo"); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(200, response.getStatus()); transactionalFeature.nextTransaction(); assertTrue(session.getDocument(blobDoc.getRef()).isLocked()); } headers.put(LOCK, "bar"); headers.put(OLD_LOCK, "foo"); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(200, response.getStatus()); transactionalFeature.nextTransaction(); assertTrue(session.getDocument(blobDoc.getRef()).isLocked()); String lock = LockHelper.getLock(blobDocFileId); assertEquals("bar", lock); } headers.put(LOCK, "bar"); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(409, response.getStatus()); transactionalFeature.nextTransaction(); assertTrue(session.getDocument(blobDoc.getRef()).isLocked()); String lock = response.getHeaders().getFirst(LOCK); assertEquals("bar", lock); } 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 unlockAndRelock(String lock, String oldLock) { logRequest(OPERATION_UNLOCK_AND_RELOCK, LOCK, lock, OLD_LOCK, oldLock); boolean isLocked = doc.isLocked(); if (!isLocked) { logCondition("Document isn't locked"); buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, ""); } logCondition("Document is locked"); String currentLock = getCurrentLock(OPERATION_UNLOCK_AND_RELOCK); if (oldLock.equals(currentLock)) { logCondition(() -> OLD_LOCK + " header is equal to current WOPI lock"); LockHelper.updateLock(fileId, lock); logResponse(OPERATION_UNLOCK_AND_RELOCK, OK.getStatusCode()); return Response.ok().build(); } else { logCondition(() -> OLD_LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, currentLock); } }
FilesEndpoint extends DefaultObject { protected Object unlockAndRelock(String lock, String oldLock) { logRequest(OPERATION_UNLOCK_AND_RELOCK, LOCK, lock, OLD_LOCK, oldLock); boolean isLocked = doc.isLocked(); if (!isLocked) { logCondition("Document isn't locked"); buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, ""); } logCondition("Document is locked"); String currentLock = getCurrentLock(OPERATION_UNLOCK_AND_RELOCK); if (oldLock.equals(currentLock)) { logCondition(() -> OLD_LOCK + " header is equal to current WOPI lock"); LockHelper.updateLock(fileId, lock); logResponse(OPERATION_UNLOCK_AND_RELOCK, OK.getStatusCode()); return Response.ok().build(); } else { logCondition(() -> OLD_LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, currentLock); } } }
FilesEndpoint extends DefaultObject { protected Object unlockAndRelock(String lock, String oldLock) { logRequest(OPERATION_UNLOCK_AND_RELOCK, LOCK, lock, OLD_LOCK, oldLock); boolean isLocked = doc.isLocked(); if (!isLocked) { logCondition("Document isn't locked"); buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, ""); } logCondition("Document is locked"); String currentLock = getCurrentLock(OPERATION_UNLOCK_AND_RELOCK); if (oldLock.equals(currentLock)) { logCondition(() -> OLD_LOCK + " header is equal to current WOPI lock"); LockHelper.updateLock(fileId, lock); logResponse(OPERATION_UNLOCK_AND_RELOCK, OK.getStatusCode()); return Response.ok().build(); } else { logCondition(() -> OLD_LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, currentLock); } }  }
FilesEndpoint extends DefaultObject { protected Object unlockAndRelock(String lock, String oldLock) { logRequest(OPERATION_UNLOCK_AND_RELOCK, LOCK, lock, OLD_LOCK, oldLock); boolean isLocked = doc.isLocked(); if (!isLocked) { logCondition("Document isn't locked"); buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, ""); } logCondition("Document is locked"); String currentLock = getCurrentLock(OPERATION_UNLOCK_AND_RELOCK); if (oldLock.equals(currentLock)) { logCondition(() -> OLD_LOCK + " header is equal to current WOPI lock"); LockHelper.updateLock(fileId, lock); logResponse(OPERATION_UNLOCK_AND_RELOCK, OK.getStatusCode()); return Response.ok().build(); } else { logCondition(() -> OLD_LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, 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 unlockAndRelock(String lock, String oldLock) { logRequest(OPERATION_UNLOCK_AND_RELOCK, LOCK, lock, OLD_LOCK, oldLock); boolean isLocked = doc.isLocked(); if (!isLocked) { logCondition("Document isn't locked"); buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, ""); } logCondition("Document is locked"); String currentLock = getCurrentLock(OPERATION_UNLOCK_AND_RELOCK); if (oldLock.equals(currentLock)) { logCondition(() -> OLD_LOCK + " header is equal to current WOPI lock"); LockHelper.updateLock(fileId, lock); logResponse(OPERATION_UNLOCK_AND_RELOCK, OK.getStatusCode()); return Response.ok().build(); } else { logCondition(() -> OLD_LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_UNLOCK_AND_RELOCK, 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();  }