@Test public void testPutRelativeFile() { String data = "new content"; Map<String, String> headers = new HashMap<>(); headers.put(OVERRIDE, Operation.PUT_RELATIVE.name()); checkPostNotFound(headers); try (CloseableClientResponse response = post(johnToken, data, headers, blobDocFileId)) { assertEquals(501, response.getStatus()); } headers.put(SUGGESTED_TARGET, "new file.docx"); headers.put(RELATIVE_TARGET, "new file.docx"); try (CloseableClientResponse response = post(johnToken, data, headers, blobDocFileId)) { assertEquals(501, response.getStatus()); } headers.remove(SUGGESTED_TARGET); try (CloseableClientResponse response = post(joeToken, data, headers, blobDocFileId)) { assertEquals(501, response.getStatus()); } }
public Object putRelativeFile() { String suggestedTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, true); if (suggestedTarget != null) { suggestedTarget = Helpers.readUTF7String(suggestedTarget); } String relativeTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, RELATIVE_TARGET, true); if (relativeTarget != null) { relativeTarget = Helpers.readUTF7String(relativeTarget); } String fileConversion = getHeader(OPERATION_PUT_RELATIVE_FILE, FILE_CONVERSION, true); logRequest(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, suggestedTarget, RELATIVE_TARGET, relativeTarget, FILE_CONVERSION, fileConversion); if (StringUtils.isEmpty(suggestedTarget) == StringUtils.isEmpty(relativeTarget)) { logCondition(() -> SUGGESTED_TARGET + " and " + RELATIVE_TARGET + " headers are both present or not present, yet they are mutually exclusive"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } final String newFileName; if (StringUtils.isNotEmpty(suggestedTarget)) { logCondition(() -> SUGGESTED_TARGET + " header is present"); newFileName = suggestedTarget.startsWith(".") ? FilenameUtils.getBaseName(blob.getFilename()) + suggestedTarget : suggestedTarget; } else { newFileName = relativeTarget; } if (StringUtils.isEmpty(fileConversion)) { logCondition(() -> FILE_CONVERSION + " header is not present, yet new file creation is not supported"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } logCondition(() -> FILE_CONVERSION + " header is present, handling file conversion"); DocumentModel newDoc = createVersionFromRequestBody(newFileName); String token = Helpers.getJWTToken(request); String newFileId = FileInfo.computeFileId(newDoc, xpath); String wopiSrc = String.format("%s%s%s?%s=%s", wopiBaseURL, FILES_ENDPOINT_PATH, newFileId, ACCESS_TOKEN_PARAMETER, token); String hostViewUrl = Helpers.getWOPIURL(baseURL, ACTION_VIEW, newDoc, xpath); String hostEditUrl = Helpers.getWOPIURL(baseURL, ACTION_EDIT, newDoc, xpath); Map<String, Serializable> map = new HashMap<>(); map.put(NAME, newFileName); map.put(URL, wopiSrc); map.put(HOST_VIEW_URL, hostViewUrl); map.put(HOST_EDIT_URL, hostEditUrl); logResponse(OPERATION_PUT_RELATIVE_FILE, OK.getStatusCode(), map); return Response.ok(map).type(MediaType.APPLICATION_JSON).build(); }
FilesEndpoint extends DefaultObject { public Object putRelativeFile() { String suggestedTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, true); if (suggestedTarget != null) { suggestedTarget = Helpers.readUTF7String(suggestedTarget); } String relativeTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, RELATIVE_TARGET, true); if (relativeTarget != null) { relativeTarget = Helpers.readUTF7String(relativeTarget); } String fileConversion = getHeader(OPERATION_PUT_RELATIVE_FILE, FILE_CONVERSION, true); logRequest(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, suggestedTarget, RELATIVE_TARGET, relativeTarget, FILE_CONVERSION, fileConversion); if (StringUtils.isEmpty(suggestedTarget) == StringUtils.isEmpty(relativeTarget)) { logCondition(() -> SUGGESTED_TARGET + " and " + RELATIVE_TARGET + " headers are both present or not present, yet they are mutually exclusive"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } final String newFileName; if (StringUtils.isNotEmpty(suggestedTarget)) { logCondition(() -> SUGGESTED_TARGET + " header is present"); newFileName = suggestedTarget.startsWith(".") ? FilenameUtils.getBaseName(blob.getFilename()) + suggestedTarget : suggestedTarget; } else { newFileName = relativeTarget; } if (StringUtils.isEmpty(fileConversion)) { logCondition(() -> FILE_CONVERSION + " header is not present, yet new file creation is not supported"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } logCondition(() -> FILE_CONVERSION + " header is present, handling file conversion"); DocumentModel newDoc = createVersionFromRequestBody(newFileName); String token = Helpers.getJWTToken(request); String newFileId = FileInfo.computeFileId(newDoc, xpath); String wopiSrc = String.format("%s%s%s?%s=%s", wopiBaseURL, FILES_ENDPOINT_PATH, newFileId, ACCESS_TOKEN_PARAMETER, token); String hostViewUrl = Helpers.getWOPIURL(baseURL, ACTION_VIEW, newDoc, xpath); String hostEditUrl = Helpers.getWOPIURL(baseURL, ACTION_EDIT, newDoc, xpath); Map<String, Serializable> map = new HashMap<>(); map.put(NAME, newFileName); map.put(URL, wopiSrc); map.put(HOST_VIEW_URL, hostViewUrl); map.put(HOST_EDIT_URL, hostEditUrl); logResponse(OPERATION_PUT_RELATIVE_FILE, OK.getStatusCode(), map); return Response.ok(map).type(MediaType.APPLICATION_JSON).build(); } }
FilesEndpoint extends DefaultObject { public Object putRelativeFile() { String suggestedTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, true); if (suggestedTarget != null) { suggestedTarget = Helpers.readUTF7String(suggestedTarget); } String relativeTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, RELATIVE_TARGET, true); if (relativeTarget != null) { relativeTarget = Helpers.readUTF7String(relativeTarget); } String fileConversion = getHeader(OPERATION_PUT_RELATIVE_FILE, FILE_CONVERSION, true); logRequest(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, suggestedTarget, RELATIVE_TARGET, relativeTarget, FILE_CONVERSION, fileConversion); if (StringUtils.isEmpty(suggestedTarget) == StringUtils.isEmpty(relativeTarget)) { logCondition(() -> SUGGESTED_TARGET + " and " + RELATIVE_TARGET + " headers are both present or not present, yet they are mutually exclusive"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } final String newFileName; if (StringUtils.isNotEmpty(suggestedTarget)) { logCondition(() -> SUGGESTED_TARGET + " header is present"); newFileName = suggestedTarget.startsWith(".") ? FilenameUtils.getBaseName(blob.getFilename()) + suggestedTarget : suggestedTarget; } else { newFileName = relativeTarget; } if (StringUtils.isEmpty(fileConversion)) { logCondition(() -> FILE_CONVERSION + " header is not present, yet new file creation is not supported"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } logCondition(() -> FILE_CONVERSION + " header is present, handling file conversion"); DocumentModel newDoc = createVersionFromRequestBody(newFileName); String token = Helpers.getJWTToken(request); String newFileId = FileInfo.computeFileId(newDoc, xpath); String wopiSrc = String.format("%s%s%s?%s=%s", wopiBaseURL, FILES_ENDPOINT_PATH, newFileId, ACCESS_TOKEN_PARAMETER, token); String hostViewUrl = Helpers.getWOPIURL(baseURL, ACTION_VIEW, newDoc, xpath); String hostEditUrl = Helpers.getWOPIURL(baseURL, ACTION_EDIT, newDoc, xpath); Map<String, Serializable> map = new HashMap<>(); map.put(NAME, newFileName); map.put(URL, wopiSrc); map.put(HOST_VIEW_URL, hostViewUrl); map.put(HOST_EDIT_URL, hostEditUrl); logResponse(OPERATION_PUT_RELATIVE_FILE, OK.getStatusCode(), map); return Response.ok(map).type(MediaType.APPLICATION_JSON).build(); }  }
FilesEndpoint extends DefaultObject { public Object putRelativeFile() { String suggestedTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, true); if (suggestedTarget != null) { suggestedTarget = Helpers.readUTF7String(suggestedTarget); } String relativeTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, RELATIVE_TARGET, true); if (relativeTarget != null) { relativeTarget = Helpers.readUTF7String(relativeTarget); } String fileConversion = getHeader(OPERATION_PUT_RELATIVE_FILE, FILE_CONVERSION, true); logRequest(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, suggestedTarget, RELATIVE_TARGET, relativeTarget, FILE_CONVERSION, fileConversion); if (StringUtils.isEmpty(suggestedTarget) == StringUtils.isEmpty(relativeTarget)) { logCondition(() -> SUGGESTED_TARGET + " and " + RELATIVE_TARGET + " headers are both present or not present, yet they are mutually exclusive"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } final String newFileName; if (StringUtils.isNotEmpty(suggestedTarget)) { logCondition(() -> SUGGESTED_TARGET + " header is present"); newFileName = suggestedTarget.startsWith(".") ? FilenameUtils.getBaseName(blob.getFilename()) + suggestedTarget : suggestedTarget; } else { newFileName = relativeTarget; } if (StringUtils.isEmpty(fileConversion)) { logCondition(() -> FILE_CONVERSION + " header is not present, yet new file creation is not supported"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } logCondition(() -> FILE_CONVERSION + " header is present, handling file conversion"); DocumentModel newDoc = createVersionFromRequestBody(newFileName); String token = Helpers.getJWTToken(request); String newFileId = FileInfo.computeFileId(newDoc, xpath); String wopiSrc = String.format("%s%s%s?%s=%s", wopiBaseURL, FILES_ENDPOINT_PATH, newFileId, ACCESS_TOKEN_PARAMETER, token); String hostViewUrl = Helpers.getWOPIURL(baseURL, ACTION_VIEW, newDoc, xpath); String hostEditUrl = Helpers.getWOPIURL(baseURL, ACTION_EDIT, newDoc, xpath); Map<String, Serializable> map = new HashMap<>(); map.put(NAME, newFileName); map.put(URL, wopiSrc); map.put(HOST_VIEW_URL, hostViewUrl); map.put(HOST_EDIT_URL, hostEditUrl); logResponse(OPERATION_PUT_RELATIVE_FILE, OK.getStatusCode(), map); return Response.ok(map).type(MediaType.APPLICATION_JSON).build(); }  @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 putRelativeFile() { String suggestedTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, true); if (suggestedTarget != null) { suggestedTarget = Helpers.readUTF7String(suggestedTarget); } String relativeTarget = getHeader(OPERATION_PUT_RELATIVE_FILE, RELATIVE_TARGET, true); if (relativeTarget != null) { relativeTarget = Helpers.readUTF7String(relativeTarget); } String fileConversion = getHeader(OPERATION_PUT_RELATIVE_FILE, FILE_CONVERSION, true); logRequest(OPERATION_PUT_RELATIVE_FILE, SUGGESTED_TARGET, suggestedTarget, RELATIVE_TARGET, relativeTarget, FILE_CONVERSION, fileConversion); if (StringUtils.isEmpty(suggestedTarget) == StringUtils.isEmpty(relativeTarget)) { logCondition(() -> SUGGESTED_TARGET + " and " + RELATIVE_TARGET + " headers are both present or not present, yet they are mutually exclusive"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } final String newFileName; if (StringUtils.isNotEmpty(suggestedTarget)) { logCondition(() -> SUGGESTED_TARGET + " header is present"); newFileName = suggestedTarget.startsWith(".") ? FilenameUtils.getBaseName(blob.getFilename()) + suggestedTarget : suggestedTarget; } else { newFileName = relativeTarget; } if (StringUtils.isEmpty(fileConversion)) { logCondition(() -> FILE_CONVERSION + " header is not present, yet new file creation is not supported"); logResponse(OPERATION_PUT_RELATIVE_FILE, SC_NOT_IMPLEMENTED); throw new NotImplementedException(); } logCondition(() -> FILE_CONVERSION + " header is present, handling file conversion"); DocumentModel newDoc = createVersionFromRequestBody(newFileName); String token = Helpers.getJWTToken(request); String newFileId = FileInfo.computeFileId(newDoc, xpath); String wopiSrc = String.format("%s%s%s?%s=%s", wopiBaseURL, FILES_ENDPOINT_PATH, newFileId, ACCESS_TOKEN_PARAMETER, token); String hostViewUrl = Helpers.getWOPIURL(baseURL, ACTION_VIEW, newDoc, xpath); String hostEditUrl = Helpers.getWOPIURL(baseURL, ACTION_EDIT, newDoc, xpath); Map<String, Serializable> map = new HashMap<>(); map.put(NAME, newFileName); map.put(URL, wopiSrc); map.put(HOST_VIEW_URL, hostViewUrl); map.put(HOST_EDIT_URL, hostEditUrl); logResponse(OPERATION_PUT_RELATIVE_FILE, OK.getStatusCode(), map); return Response.ok(map).type(MediaType.APPLICATION_JSON).build(); }  @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();  }