@Test public void testRenameFile() throws IOException, JSONException { Map<String, String> headers = new HashMap<>(); headers.put(OVERRIDE, Operation.RENAME_FILE.name()); checkPostNotFound(headers, CONTENTS_PATH); try (CloseableClientResponse response = post(joeToken, headers, blobDocFileId)) { assertEquals(409, response.getStatus()); } headers.put(REQUESTED_NAME, "renamed-test-file"); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(200, response.getStatus()); checkJSONResponse(response, "json/RenameFile.json"); transactionalFeature.nextTransaction(); Blob renamedBlob = (Blob) session.getDocument(blobDoc.getRef()).getPropertyValue(FILE_CONTENT_PROPERTY); assertNotNull(renamedBlob); assertEquals("renamed-test-file.txt", renamedBlob.getFilename()); } headers.put(OVERRIDE, Operation.LOCK.name()); 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(OVERRIDE, Operation.RENAME_FILE.name()); headers.put(REQUESTED_NAME, "renamed-wopi-locked-test-file"); try (CloseableClientResponse response = post(joeToken, headers, blobDocFileId)) { assertEquals(409, response.getStatus()); } try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(200, response.getStatus()); checkJSONResponse(response, "json/RenameFile-wopiLocked.json"); transactionalFeature.nextTransaction(); Blob renamedBlob = (Blob) session.getDocument(blobDoc.getRef()).getPropertyValue(FILE_CONTENT_PROPERTY); assertNotNull(renamedBlob); assertEquals("renamed-wopi-locked-test-file.txt", renamedBlob.getFilename()); } headers.put(LOCK, "bar"); headers.put(REQUESTED_NAME, "renamed-wopi-locked-other-client-test-file"); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(409, response.getStatus()); String lock = response.getHeaders().getFirst(LOCK); assertEquals("foo", lock); transactionalFeature.nextTransaction(); DocumentModel doc = session.getDocument(blobDoc.getRef()); assertTrue(doc.isLocked()); Blob blob = (Blob) doc.getPropertyValue(FILE_CONTENT_PROPERTY); assertNotNull(blob); assertEquals("renamed-wopi-locked-test-file.txt", blob.getFilename()); } session.getDocument(hugeBlobDoc.getRef()).setLock(); transactionalFeature.nextTransaction(); headers.remove(LOCK); headers.put(REQUESTED_NAME, "renamed-wopi-locked-nuxeo-test-file"); try (CloseableClientResponse response = post(johnToken, headers, hugeBlobDocFileId)) { assertEquals(409, response.getStatus()); transactionalFeature.nextTransaction(); DocumentModel doc = session.getDocument(hugeBlobDoc.getRef()); assertTrue(doc.isLocked()); Blob blob = (Blob) doc.getPropertyValue(FILE_CONTENT_PROPERTY); assertNotNull(blob); assertEquals("hugeBlobFilename", blob.getFilename()); } }
public Object renameFile() { checkWritePropertiesPermission(OPERATION_RENAME_FILE); String requestedName = Helpers.readUTF7String(getHeader(OPERATION_RENAME_FILE, REQUESTED_NAME)); if (!doc.isLocked()) { logCondition("Document isn't locked"); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName); return renameBlob(requestedName); } String currentLock = getCurrentLock(OPERATION_RENAME_FILE); String lock = getHeader(OPERATION_RENAME_FILE, LOCK); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return renameBlob(requestedName); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_RENAME_FILE, currentLock); } }
FilesEndpoint extends DefaultObject { public Object renameFile() { checkWritePropertiesPermission(OPERATION_RENAME_FILE); String requestedName = Helpers.readUTF7String(getHeader(OPERATION_RENAME_FILE, REQUESTED_NAME)); if (!doc.isLocked()) { logCondition("Document isn't locked"); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName); return renameBlob(requestedName); } String currentLock = getCurrentLock(OPERATION_RENAME_FILE); String lock = getHeader(OPERATION_RENAME_FILE, LOCK); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return renameBlob(requestedName); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_RENAME_FILE, currentLock); } } }
FilesEndpoint extends DefaultObject { public Object renameFile() { checkWritePropertiesPermission(OPERATION_RENAME_FILE); String requestedName = Helpers.readUTF7String(getHeader(OPERATION_RENAME_FILE, REQUESTED_NAME)); if (!doc.isLocked()) { logCondition("Document isn't locked"); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName); return renameBlob(requestedName); } String currentLock = getCurrentLock(OPERATION_RENAME_FILE); String lock = getHeader(OPERATION_RENAME_FILE, LOCK); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return renameBlob(requestedName); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_RENAME_FILE, currentLock); } }  }
FilesEndpoint extends DefaultObject { public Object renameFile() { checkWritePropertiesPermission(OPERATION_RENAME_FILE); String requestedName = Helpers.readUTF7String(getHeader(OPERATION_RENAME_FILE, REQUESTED_NAME)); if (!doc.isLocked()) { logCondition("Document isn't locked"); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName); return renameBlob(requestedName); } String currentLock = getCurrentLock(OPERATION_RENAME_FILE); String lock = getHeader(OPERATION_RENAME_FILE, LOCK); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return renameBlob(requestedName); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_RENAME_FILE, 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 { public Object renameFile() { checkWritePropertiesPermission(OPERATION_RENAME_FILE); String requestedName = Helpers.readUTF7String(getHeader(OPERATION_RENAME_FILE, REQUESTED_NAME)); if (!doc.isLocked()) { logCondition("Document isn't locked"); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName); return renameBlob(requestedName); } String currentLock = getCurrentLock(OPERATION_RENAME_FILE); String lock = getHeader(OPERATION_RENAME_FILE, LOCK); logRequest(OPERATION_RENAME_FILE, REQUESTED_NAME, requestedName, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return renameBlob(requestedName); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_RENAME_FILE, 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();  }