/** * Queries a file at the specified revision and path with the specified {@link Query}. */ <T> CompletableFuture<Entry<T>> getFile(String projectName, String repositoryName, Revision revision, Query<T> query);
/** * Converts the specified {@code request} to {@link Optional} which contains {@link Query} when * the request has a valid file path. {@link Optional#EMPTY} otherwise. */ @Override public Object convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage request, Class<?> expectedResultType) throws Exception { final String path = getPath(ctx); final Optional<Iterable<String>> jsonPaths = getJsonPaths(ctx); if (jsonPaths.isPresent()) { return Optional.of(Query.ofJsonPath(path, jsonPaths.get())); } if (isValidFilePath(path)) { return Optional.of(Query.of(QueryType.IDENTITY, path)); } return Optional.empty(); }
/** * Converts the specified {@code request} to {@link Optional} which contains {@link Query} when * the request has a valid file path. {@link Optional#EMPTY} otherwise. */ @Override public Object convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage request, Class<?> expectedResultType) throws Exception { final String path = getPath(ctx); final Optional<Iterable<String>> jsonPaths = getJsonPaths(ctx); if (jsonPaths.isPresent()) { return Optional.of(Query.ofJsonPath(path, jsonPaths.get())); } if (isValidFilePath(path)) { return Optional.of(Query.of(QueryType.IDENTITY, path)); } return Optional.empty(); }
/** * Queries a file at two different revisions and returns the diff of the two {@link Query} results. */ <T> CompletableFuture<Change<T>> getDiff(String projectName, String repositoryName, Revision from, Revision to, Query<T> query);
/** * Converts the specified {@code request} to {@link Optional} which contains {@link Query} when * the request has a valid file path. {@link Optional#EMPTY} otherwise. */ @Override public Object convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage request, Class<?> expectedResultType) throws Exception { final String path = getPath(ctx); final Optional<Iterable<String>> jsonPaths = getJsonPaths(ctx); if (jsonPaths.isPresent()) { return Optional.of(Query.ofJsonPath(path, jsonPaths.get())); } if (isValidFilePath(path)) { return Optional.of(Query.of(QueryType.IDENTITY, path)); } return Optional.empty(); }
/** * Retrieves the file at the specified revision and path. This method is a shortcut of * {@code getFile(projectName, repositoryName, revision, Query.identity(path)}. * Consider using {@link #getFile(String, String, Revision, Query)} with {@link Query#ofText(String)} or * {@link Query#ofJson(String)} if you already know the file type. * * @return the {@link Entry} at the given {@code path} */ default CompletableFuture<Entry<?>> getFile(String projectName, String repositoryName, Revision revision, String path) { @SuppressWarnings("unchecked") final CompletableFuture<Entry<?>> f = (CompletableFuture<Entry<?>>) (CompletableFuture<?>) getFile(projectName, repositoryName, revision, Query.of(QueryType.IDENTITY, path)); return f; }
@Override protected com.linecorp.centraldogma.common.Query<?> doBackward(Query query) { switch (query.getType()) { case IDENTITY: return com.linecorp.centraldogma.common.Query.of( com.linecorp.centraldogma.common.QueryType.IDENTITY, query.getPath()); case JSON_PATH: return com.linecorp.centraldogma.common.Query.ofJsonPath(query.getPath(), query.getExpressions()); } throw new Error(); } }
/** * Retrieves the file at the specified revision and path. This method is a shortcut of * {@code getFile(projectName, repositoryName, revision, Query.identity(path)}. * Consider using {@link #getFile(String, String, Revision, Query)} with {@link Query#ofText(String)} or * {@link Query#ofJson(String)} if you already know the file type. * * @return the {@link Entry} at the given {@code path} */ default CompletableFuture<Entry<?>> getFile(String projectName, String repositoryName, Revision revision, String path) { @SuppressWarnings("unchecked") final CompletableFuture<Entry<?>> f = (CompletableFuture<Entry<?>>) (CompletableFuture<?>) getFile(projectName, repositoryName, revision, Query.of(QueryType.IDENTITY, path)); return f; }
@Override protected com.linecorp.centraldogma.common.Query<?> doBackward(Query query) { switch (query.getType()) { case IDENTITY: return com.linecorp.centraldogma.common.Query.of( com.linecorp.centraldogma.common.QueryType.IDENTITY, query.getPath()); case JSON_PATH: return com.linecorp.centraldogma.common.Query.ofJsonPath(query.getPath(), query.getExpressions()); } throw new Error(); } }
/** * Returns the diff of a file between two {@link Revision}s. This method is a shortcut of * {@code getDiff(projectName, repositoryName, from, to, Query.identity(path))}. * Consider using {@link #getDiff(String, String, Revision, Revision, Query)} with * {@link Query#ofText(String)} or {@link Query#ofJson(String)} if you already know the file type. * * @return the {@link Change} that contains the diff of the given {@code path} between the specified * two revisions */ default CompletableFuture<Change<?>> getDiff(String projectName, String repositoryName, Revision from, Revision to, String path) { @SuppressWarnings({ "unchecked", "rawtypes" }) final CompletableFuture<Change<?>> diff = (CompletableFuture<Change<?>>) (CompletableFuture) getDiff(projectName, repositoryName, from, to, Query.of(QueryType.IDENTITY, path)); return diff; }
/** * Returns the diff of a file between two {@link Revision}s. This method is a shortcut of * {@code getDiff(projectName, repositoryName, from, to, Query.identity(path))}. * Consider using {@link #getDiff(String, String, Revision, Revision, Query)} with * {@link Query#ofText(String)} or {@link Query#ofJson(String)} if you already know the file type. * * @return the {@link Change} that contains the diff of the given {@code path} between the specified * two revisions */ default CompletableFuture<Change<?>> getDiff(String projectName, String repositoryName, Revision from, Revision to, String path) { @SuppressWarnings({ "unchecked", "rawtypes" }) final CompletableFuture<Change<?>> diff = (CompletableFuture<Change<?>>) (CompletableFuture) getDiff(projectName, repositoryName, from, to, Query.of(QueryType.IDENTITY, path)); return diff; }
/** * GET /projects/{projectName}/repositories/{repoName}/files/revisions/{revision}{path} * Returns the blob in the path. */ @Get("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/files/revisions/(?<revision>[^/]+)(?<path>/.*$)") @Decorator(HasReadPermission.class) public CompletionStage<EntryDto> getFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, @Param("path") String path, @Param("queryType") Optional<String> queryType, @Param("expression") Optional<String> expressions) { final Query<?> query = Query.of(QueryType.valueOf(queryType.orElse("IDENTITY")), path, expressions.orElse("")); final Repository repo = projectManager().get(projectName).repos().get(repoName); return repo.get(repo.normalizeNow(new Revision(revision)), query) .thenApply(DtoConverter::convert); }
/** * GET /projects/{projectName}/repositories/{repoName}/files/revisions/{revision}{path} * Returns the blob in the path. */ @Get("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/files/revisions/(?<revision>[^/]+)(?<path>/.*$)") public CompletionStage<EntryDto> getFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, @Param("path") String path, @Param("queryType") Optional<String> queryType, @Param("expression") Optional<String> expressions) { final Query<?> query = Query.of(QueryType.valueOf(queryType.orElse("IDENTITY")), path, expressions.orElse("")); final Repository repo = projectManager().get(projectName).repos().get(repoName); return repo.get(repo.normalizeNow(new Revision(revision)), query) .thenApply(DtoConverter::convert); }
/** * GET /projects/{projectName}/repositories/{repoName}/files/revisions/{revision}{path} * Returns the blob in the path. */ @Get("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/files/revisions/(?<revision>[^/]+)(?<path>/.*$)") public CompletionStage<EntryDto> getFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, @Param("path") String path, @Param("queryType") Optional<String> queryType, @Param("expression") Optional<String> expressions) { final Query<?> query = Query.of(QueryType.valueOf(queryType.orElse("IDENTITY")), path, expressions.orElse("")); final Repository repo = projectManager().get(projectName).repos().get(repoName); return repo.get(repo.normalizeNow(new Revision(revision)), query) .thenApply(DtoConverter::convert); }