@Override public Promise<List<EditedRegion>> getEditedRegions(Path project, Path filePath) { String url = getWsAgentBaseUrl() + EDITS + "?projectPath=" + encodePath(project) + "&filePath=" + encodePath(filePath); return asyncRequestFactory .createGetRequest(url) .send(dtoUnmarshallerFactory.newListUnmarshaller(EditedRegion.class)); }
@Override public Promise<ShowFileContentResponse> showFileContent(Path project, Path file, String version) { String params = "?projectPath=" + encodePath(project) + "&file=" + encodePath(file) + "&version=" + version; String url = getWsAgentBaseUrl() + SHOW + params; return asyncRequestFactory .createGetRequest(url) .loader(loader) .send(dtoUnmarshallerFactory.newUnmarshaller(ShowFileContentResponse.class)); }
@Override public Promise<LogResponse> log( Path project, Path[] fileFilter, int skip, int maxCount, boolean plainText) { StringBuilder params = new StringBuilder() .append("?projectPath=") .append(encodePath(project)) .append("&skip=") .append(skip) .append("&maxCount=") .append(maxCount); if (fileFilter != null) { stream(fileFilter).forEach(file -> params.append("&fileFilter=").append(file)); } String url = getWsAgentBaseUrl() + LOG + params; if (plainText) { return asyncRequestFactory .createGetRequest(url) .send(dtoUnmarshallerFactory.newUnmarshaller(LogResponse.class)); } else { return asyncRequestFactory .createGetRequest(url) .header(ACCEPT, APPLICATION_JSON) .send(dtoUnmarshallerFactory.newUnmarshaller(LogResponse.class)); } }
@Override public Promise<Void> add(Path project, boolean update, Path[] paths) { AddRequest addRequest = dtoFactory.createDto(AddRequest.class).withUpdate(update); addRequest.setFilePattern( paths == null ? DEFAULT_PATTERN : stream(paths).map(path -> path.isEmpty() ? "." : path.toString()).collect(toList())); String url = getWsAgentBaseUrl() + ADD + "?projectPath=" + encodePath(project); return asyncRequestFactory.createPostRequest(url, addRequest).loader(loader).send(); }
@Override public Promise<Void> remove(Path project, Path[] items, boolean cached) { String params = "?projectPath=" + encodePath(project); if (items != null) { for (Path item : items) { params += "&items=" + item.toString(); } } params += "&cached=" + String.valueOf(cached); String url = getWsAgentBaseUrl() + REMOVE + params; return asyncRequestFactory.createDeleteRequest(url).loader(loader).send(); }
@Override public Promise<Status> getStatus(Path project, List<String> filter) { StringBuilder params = new StringBuilder("?projectPath=" + encodePath(project)); if (filter != null) { for (String path : filter) { if (!path.isEmpty()) { params.append("&filter=").append(path); } } } String url = getWsAgentBaseUrl() + STATUS + params; return asyncRequestFactory .createGetRequest(url) .loader(loader) .header(CONTENTTYPE, APPLICATION_JSON) .header(ACCEPT, APPLICATION_JSON) .send(dtoUnmarshallerFactory.newUnmarshaller(Status.class)); }
/** * Reads the file content by given {@code path}. * * @param path path to the file * @return {@link Promise} with file content * @see Path * @since 4.4.0 */ public Promise<String> getFileContent(Path path) { final String url = getBaseUrl() + FILE + encodePath(path); return reqFactory.createGetRequest(url).send(new StringUnmarshaller()); }
@Override public Promise<List<Branch>> branchList(Path project, BranchListMode listMode) { String url = getWsAgentBaseUrl() + BRANCH + "?projectPath=" + encodePath(project) + (listMode == null ? "" : "&listMode=" + listMode); return asyncRequestFactory .createGetRequest(url) .send(dtoUnmarshallerFactory.newListUnmarshaller(Branch.class)); }
@Override public Promise<Void> remoteDelete(Path project, String name) { String url = getWsAgentBaseUrl() + REMOTE + '/' + name + "?projectPath=" + encodePath(project); return asyncRequestFactory.createDeleteRequest(url).loader(loader).send(); }
@Override public Promise<Void> init(Path project, boolean bare) { String url = getWsAgentBaseUrl() + INIT + "?projectPath=" + encodePath(project) + "&bare=" + bare; return asyncRequestFactory.createPostRequest(url, null).loader(loader).send(); }
@Override public Promise<Void> deleteRepository(Path project) { String url = getWsAgentBaseUrl() + REPOSITORY + "?projectPath=" + encodePath(project); return asyncRequestFactory.createDeleteRequest(url).loader(loader).send(); }
@Override public Promise<List<Remote>> remoteList(Path project, String remoteName, boolean verbose) { String params = "?projectPath=" + encodePath(project) + (remoteName != null ? "&remoteName=" + remoteName : "") + "&verbose=" + String.valueOf(verbose); String url = getWsAgentBaseUrl() + REMOTE + params; return asyncRequestFactory .createGetRequest(url) .loader(loader) .send(dtoUnmarshallerFactory.newListUnmarshaller(Remote.class)); }
/** * Writes the file {@code content} by given {@code path}. * * @param path path to the file * @param content the file content * @return {@link Promise} with empty response * @see Path * @since 4.4.0 */ public Promise<Void> setFileContent(Path path, String content) { final String url = getBaseUrl() + FILE + encodePath(path); return reqFactory.createRequest(PUT, url, null, false).data(content).send(); }
@Override public Promise<Void> branchDelete(Path project, String name, boolean force) { String url = getWsAgentBaseUrl() + BRANCH + "?projectPath=" + encodePath(project) + "&name=" + name + "&force=" + force; return asyncRequestFactory.createDeleteRequest(url).loader(loader).send(); }
@Override public Promise<Void> reset( Path project, String commit, ResetRequest.ResetType resetType, Path[] files) { ResetRequest resetRequest = dtoFactory.createDto(ResetRequest.class).withCommit(commit); if (resetType != null) { resetRequest.setType(resetType); } if (files != null) { resetRequest.setFilePattern( stream(files).map(file -> file.isEmpty() ? "." : file.toString()).collect(toList())); } String url = getWsAgentBaseUrl() + RESET + "?projectPath=" + encodePath(project); return asyncRequestFactory.createPostRequest(url, resetRequest).loader(loader).send(); }
@Override public Promise<Revision> commit(Path project, String message, boolean amend, Path[] files) { CommitRequest commitRequest = dtoFactory .createDto(CommitRequest.class) .withMessage(message) .withAmend(amend) .withFiles( stream(files) .filter(file -> !file.isEmpty()) .map(Path::toString) .collect(toList())); String url = getWsAgentBaseUrl() + COMMIT + "?projectPath=" + encodePath(project); return asyncRequestFactory .createPostRequest(url, commitRequest) .loader(loader) .send(dtoUnmarshallerFactory.newUnmarshaller(Revision.class)); }
@Override public Promise<String> checkout(Path project, CheckoutRequest request) { String url = getWsAgentBaseUrl() + CHECKOUT + "?projectPath=" + encodePath(project); return asyncRequestFactory .createPostRequest(url, request) .loader(loader) .send(new StringUnmarshaller()); }
new StringBuilder() .append("?projectPath=") .append(encodePath(project)) .append("&noRenames=") .append(noRenames) .stream() .filter(file -> !file.isEmpty()) .forEach(file -> params.append("&fileFilter=").append(encodePath(valueOf(file))));
@Override public Promise<Void> branchRename(Path project, String oldName, String newName) { String params = "?projectPath=" + encodePath(project) + "&oldName=" + oldName + "&newName=" + newName; String url = getWsAgentBaseUrl() + BRANCH + params; return asyncRequestFactory .createPostRequest(url, null) .loader(loader) .header(CONTENTTYPE, MimeType.APPLICATION_FORM_URLENCODED) .send(); }
/** * Moves the {@code source} item to given {@code target} with {@code newName}. * * @param source the source path to be moved * @param target the target path, should be a container (project or folder) * @param newName the new name of the moved item * @param overwrite overwrite target is such has already exists * @return {@link Promise} with empty response * @see Path * @since 4.4.0 */ public Promise<Void> move(Path source, Path target, String newName, boolean overwrite) { final String url = getBaseUrl() + MOVE + encodePath(source) + "?to=" + encodePath(target); final MoveOptions moveOptions = dtoFactory.createDto(MoveOptions.class); moveOptions.setName(newName); moveOptions.setOverWrite(overwrite); return reqFactory .createPostRequest(url, moveOptions) .loader(loaderFactory.newLoader("Moving...")) .send(); }