@Test void createRepositoryWithSameName() { final WebClient client = dogma.httpClient(); createRepository(client, "myNewRepo"); final AggregatedHttpResponse aRes = createRepository(client, "myNewRepo"); assertThat(ResponseHeaders.of(aRes.headers()).status()).isEqualTo(HttpStatus.CONFLICT); final String expectedJson = '{' + " \"exception\": \"" + RepositoryExistsException.class.getName() + "\"," + " \"message\": \"Repository 'myPro/myNewRepo' exists already.\"" + '}'; assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson); }
@Post("/projects/{projectName}/repos") @StatusCode(201) @ResponseConverter(CreateApiResponseConverter.class) @RequiresRole(roles = ProjectRole.OWNER) public CompletableFuture<RepositoryDto> createRepository(ServiceRequestContext ctx, Project project, CreateRepositoryRequest request, Author author) { if (Project.isReservedRepoName(request.name())) { return HttpApiUtil.throwResponse(ctx, HttpStatus.FORBIDDEN, "A reserved repository cannot be created."); } return execute(Command.createRepository(author, project.name(), request.name())) .thenCompose(unused -> mds.addRepo(author, project.name(), request.name())) .handle(returnOrThrow(() -> DtoConverter.convert(project.repos().get(request.name())))); }
RepositoryServiceV1 extends AbstractService { @Post("/projects/{projectName}/repos") @StatusCode(201) @ResponseConverter(CreateApiResponseConverter.class) @RequiresRole(roles = ProjectRole.OWNER) public CompletableFuture<RepositoryDto> createRepository(ServiceRequestContext ctx, Project project, CreateRepositoryRequest request, Author author) { if (Project.isReservedRepoName(request.name())) { return HttpApiUtil.throwResponse(ctx, HttpStatus.FORBIDDEN, "A reserved repository cannot be created."); } return execute(Command.createRepository(author, project.name(), request.name())) .thenCompose(unused -> mds.addRepo(author, project.name(), request.name())) .handle(returnOrThrow(() -> DtoConverter.convert(project.repos().get(request.name())))); } }
RepositoryServiceV1 extends AbstractService { @Post("/projects/{projectName}/repos") @StatusCode(201) @ResponseConverter(CreateApiResponseConverter.class) @RequiresRole(roles = ProjectRole.OWNER) public CompletableFuture<RepositoryDto> createRepository(ServiceRequestContext ctx, Project project, CreateRepositoryRequest request, Author author) { if (Project.isReservedRepoName(request.name())) { return HttpApiUtil.throwResponse(ctx, HttpStatus.FORBIDDEN, "A reserved repository cannot be created."); } return execute(Command.createRepository(author, project.name(), request.name())) .thenCompose(unused -> mds.addRepo(author, project.name(), request.name())) .handle(returnOrThrow(() -> DtoConverter.convert(project.repos().get(request.name())))); } RepositoryServiceV1(ProjectManager projectManager, CommandExecutor executor,
                               MetadataService mds); }
RepositoryServiceV1 extends AbstractService { @Post("/projects/{projectName}/repos") @StatusCode(201) @ResponseConverter(CreateApiResponseConverter.class) @RequiresRole(roles = ProjectRole.OWNER) public CompletableFuture<RepositoryDto> createRepository(ServiceRequestContext ctx, Project project, CreateRepositoryRequest request, Author author) { if (Project.isReservedRepoName(request.name())) { return HttpApiUtil.throwResponse(ctx, HttpStatus.FORBIDDEN, "A reserved repository cannot be created."); } return execute(Command.createRepository(author, project.name(), request.name())) .thenCompose(unused -> mds.addRepo(author, project.name(), request.name())) .handle(returnOrThrow(() -> DtoConverter.convert(project.repos().get(request.name())))); } RepositoryServiceV1(ProjectManager projectManager, CommandExecutor executor,
                               MetadataService mds); @Get("/projects/{projectName}/repos") CompletableFuture<List<RepositoryDto>> listRepositories(ServiceRequestContext ctx, Project project,
                                                                   @Param @Nullable String status, User user); @Post("/projects/{projectName}/repos") @StatusCode(201) @ResponseConverter(CreateApiResponseConverter.class) @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<RepositoryDto> createRepository(ServiceRequestContext ctx, Project project,
                                                             CreateRepositoryRequest request,
                                                             Author author); @Delete("/projects/{projectName}/repos/{repoName}") @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<Void> removeRepository(ServiceRequestContext ctx,
                                                    @Param String repoName,
                                                    Repository repository,
                                                    Author author); @Delete("/projects/{projectName}/repos/{repoName}/removed") @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<Void> purgeRepository(@Param String repoName,
                                                   Project project, Author author); @Consumes("application/json-patch+json") @Patch("/projects/{projectName}/repos/{repoName}") @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<RepositoryDto> patchRepository(@Param String repoName,
                                                            Project project,
                                                            JsonNode node,
                                                            Author author); @Get("/projects/{projectName}/repos/{repoName}/revision/{revision}") @RequiresReadPermission Map<String, Integer> normalizeRevision(Repository repository, @Param String revision); }
RepositoryServiceV1 extends AbstractService { @Post("/projects/{projectName}/repos") @StatusCode(201) @ResponseConverter(CreateApiResponseConverter.class) @RequiresRole(roles = ProjectRole.OWNER) public CompletableFuture<RepositoryDto> createRepository(ServiceRequestContext ctx, Project project, CreateRepositoryRequest request, Author author) { if (Project.isReservedRepoName(request.name())) { return HttpApiUtil.throwResponse(ctx, HttpStatus.FORBIDDEN, "A reserved repository cannot be created."); } return execute(Command.createRepository(author, project.name(), request.name())) .thenCompose(unused -> mds.addRepo(author, project.name(), request.name())) .handle(returnOrThrow(() -> DtoConverter.convert(project.repos().get(request.name())))); } RepositoryServiceV1(ProjectManager projectManager, CommandExecutor executor,
                               MetadataService mds); @Get("/projects/{projectName}/repos") CompletableFuture<List<RepositoryDto>> listRepositories(ServiceRequestContext ctx, Project project,
                                                                   @Param @Nullable String status, User user); @Post("/projects/{projectName}/repos") @StatusCode(201) @ResponseConverter(CreateApiResponseConverter.class) @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<RepositoryDto> createRepository(ServiceRequestContext ctx, Project project,
                                                             CreateRepositoryRequest request,
                                                             Author author); @Delete("/projects/{projectName}/repos/{repoName}") @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<Void> removeRepository(ServiceRequestContext ctx,
                                                    @Param String repoName,
                                                    Repository repository,
                                                    Author author); @Delete("/projects/{projectName}/repos/{repoName}/removed") @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<Void> purgeRepository(@Param String repoName,
                                                   Project project, Author author); @Consumes("application/json-patch+json") @Patch("/projects/{projectName}/repos/{repoName}") @RequiresRole(roles = ProjectRole.OWNER) CompletableFuture<RepositoryDto> patchRepository(@Param String repoName,
                                                            Project project,
                                                            JsonNode node,
                                                            Author author); @Get("/projects/{projectName}/repos/{repoName}/revision/{revision}") @RequiresReadPermission Map<String, Integer> normalizeRevision(Repository repository, @Param String revision);  }