/** * 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()); }
/** * 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(); }
/** * Returns the projects list. If there is no projects were found on server, empty list is * returned. * * @return {@link Promise} with list of project configuration * @see ProjectConfigDto * @since 4.4.0 */ public Promise<List<ProjectConfigDto>> getProjects() { final String url = getBaseUrl(); return reqFactory .createGetRequest(url) .header(ACCEPT, MimeType.APPLICATION_JSON) .send(unmarshaller.newListUnmarshaller(ProjectConfigDto.class)); }
/** * Removes the item by given {@code path} from the server. * * @param path path to the item * @return {@link Promise} with empty response * @see Path * @since 4.4.0 */ public Promise<Void> deleteItem(Path path) { final String url = getBaseUrl() + encodePath(path); return reqFactory .createRequest(DELETE, url, null, false) .loader(loaderFactory.newLoader("Deleting resource...")) .send(); }
final String url = getBaseUrl() + SEARCH + encodePath(prjPath.addLeadingSeparator());
/** * Creates the project with given {@code configuration}. * * @param configuration the project configuration * @param options additional parameters that need for project generation * @return {@link Promise} with the {@link ProjectConfigDto} * @see ProjectConfigDto * @since 4.4.0 */ public Promise<ProjectConfigDto> createProject( ProjectConfigDto configuration, Map<String, String> options) { UrlBuilder urlBuilder = new UrlBuilder(getBaseUrl()); for (String key : options.keySet()) { urlBuilder.setParameter(key, options.get(key)); } urlBuilder.setParameter("clientId", appContext.getApplicationId().orElse("")); return reqFactory .createPostRequest(urlBuilder.buildString(), configuration) .header(ACCEPT, APPLICATION_JSON) .loader(loaderFactory.newLoader("Creating project...")) .send(unmarshaller.newUnmarshaller(ProjectConfigDto.class)); }
/** * Creates the folder by given {@code path}. * * @param path path to the future folder * @return {@link Promise} with the {@link ItemReference} * @see ItemReference * @see Path * @since 4.4.0 */ public Promise<ItemReference> createFolder(Path path) { final String url = getBaseUrl() + FOLDER + encodePath(path); return reqFactory .createPostRequest(url, null) .loader(loaderFactory.newLoader("Creating folder...")) .send(unmarshaller.newUnmarshaller(ItemReference.class)); }
/** * Returns the item description by given {@code path}. * * @param path path to the item * @return {@link Promise} with the {@link ItemReference} * @see Path * @see ItemReference * @since 4.4.0 */ public Promise<ItemReference> getItem(Path path) { final String url = getBaseUrl() + ITEM + encodePath(path); return reqFactory .createGetRequest(url) .header(ACCEPT, APPLICATION_JSON) .loader(loaderFactory.newLoader("Getting item...")) .send(unmarshaller.newUnmarshaller(ItemReference.class)); }
/** * Gets list of {@link SourceEstimation} for all supposed project types. * * @param path path of the project to resolve * @return {@link Promise} with the list of resolved estimations * @see Path * @see SourceEstimation * @since 4.4.0 */ public Promise<List<SourceEstimation>> resolveSources(Path path) { final String url = getBaseUrl() + RESOLVE + encodePath(path); return reqFactory .createGetRequest(url) .header(ACCEPT, APPLICATION_JSON) .loader(loaderFactory.newLoader("Resolving sources...")) .send(unmarshaller.newListUnmarshaller(SourceEstimation.class)); }
/** * Returns the specific project by given {@code path}. Path to project should be an absolute. * * @param path path to project * @return {@link Promise} with project configuration * @see ProjectConfigDto * @see Path * @since 4.4.0 */ public Promise<ProjectConfigDto> getProject(Path path) { final String url = getBaseUrl() + encodePath(path); return reqFactory .createGetRequest(url) .header(ACCEPT, APPLICATION_JSON) .loader(loaderFactory.newLoader("Getting project...")) .send(unmarshaller.newUnmarshaller(ProjectConfigDto.class)); }
/** * Estimates the given {@code path} to be applied to specified {@code pType} (project type). * * @param path path to the folder * @param pType project type to estimate * @return {@link Promise} with the {@link SourceEstimation} * @see Path * @see SourceEstimation * @since 4.4.0 */ public Promise<SourceEstimation> estimate(Path path, String pType) { final String url = getBaseUrl() + ESTIMATE + encodePath(path) + "?type=" + pType; return reqFactory .createGetRequest(url) .header(ACCEPT, APPLICATION_JSON) .loader(loaderFactory.newLoader("Estimating project...")) .send(unmarshaller.newUnmarshaller(SourceEstimation.class)); }
/** * Reads the project tree starting from {@code path} with given {@code depth}. * * @param path the start point path where read should start * @param depth the depth to read, e.g. -1, 0 or less than {@link Integer#MAX_VALUE} * @param includeFiles include files into response * @return {@link Promise} with tree response * @see Path * @see TreeElement * @since 4.4.0 */ public Promise<TreeElement> getTree(Path path, int depth, boolean includeFiles) { final String url = getBaseUrl() + TREE + encodePath(path.addLeadingSeparator()) + "?depth=" + depth + "&includeFiles=" + includeFiles; // temporary workaround for CHE-3467, remove loader for disable UI blocking // later this loader should be added with the new mechanism of client-server synchronization return reqFactory .createGetRequest(url) .header(ACCEPT, APPLICATION_JSON) .send(unmarshaller.newUnmarshaller(TreeElement.class)); }
/** * Copies the {@code source} item to given {@code target} with {@code newName}. * * @param source the source path to be copied * @param target the target path, should be a container (project or folder) * @param newName the new name of the copied 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> copy(Path source, Path target, String newName, boolean overwrite) { final String url = getBaseUrl() + COPY + encodePath(source) + "?to=" + encodePath(target); final CopyOptions copyOptions = dtoFactory.createDto(CopyOptions.class); copyOptions.setName(newName); copyOptions.setOverWrite(overwrite); return reqFactory .createPostRequest(url, copyOptions) .loader(loaderFactory.newLoader("Copying...")) .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(); }
/** * Creates the file by given {@code path} with given {@code content}. Content may be an empty. * * @param path path to the future file * @param content the file content * @return {@link Promise} with the {@link ItemReference} * @see ItemReference * @see Path * @since 4.4.0 */ public Promise<ItemReference> createFile(Path path, String content) { final String url = getBaseUrl() + FILE + encodePath(path.parent()) + "?name=" + encodePathSegment(path.lastSegment()); return reqFactory .createPostRequest(url, null) .data(content) .loader(loaderFactory.newLoader("Creating file...")) .send(unmarshaller.newUnmarshaller(ItemReference.class)); }