remove enunciate since we are using openapi now

This commit is contained in:
Eduard Heimbuch
2020-02-24 13:36:34 +01:00
parent 6d9256ed99
commit 7e1e77af2b
12 changed files with 183 additions and 613 deletions

13
pom.xml
View File

@@ -184,12 +184,6 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
<version>${enunciate.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.mapstruct</groupId> <groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId> <artifactId>mapstruct-jdk8</artifactId>
@@ -453,12 +447,6 @@
<version>2.3</version> <version>2.3</version>
</plugin> </plugin>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>${enunciate.version}</version>
</plugin>
<plugin> <plugin>
<groupId>sonia.scm.maven</groupId> <groupId>sonia.scm.maven</groupId>
<artifactId>smp-maven-plugin</artifactId> <artifactId>smp-maven-plugin</artifactId>
@@ -843,7 +831,6 @@
<jaxrs.version>2.1.1</jaxrs.version> <jaxrs.version>2.1.1</jaxrs.version>
<resteasy.version>4.4.1.Final</resteasy.version> <resteasy.version>4.4.1.Final</resteasy.version>
<jersey-client.version>1.19.4</jersey-client.version> <jersey-client.version>1.19.4</jersey-client.version>
<enunciate.version>2.11.1</enunciate.version>
<jackson.version>2.10.0</jackson.version> <jackson.version>2.10.0</jackson.version>
<guice.version>4.0</guice.version> <guice.version>4.0</guice.version>
<jaxb.version>2.3.0</jaxb.version> <jaxb.version>2.3.0</jaxb.version>

View File

@@ -137,12 +137,6 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- rest documentation -->
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
</dependency>
<!-- event bus --> <!-- event bus -->
<dependency> <dependency>

View File

@@ -173,101 +173,7 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>plugin-doc</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-enunciate-configuration</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/doc</directory>
<filtering>true</filtering>
<includes>
<include>**/enunciate.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<configFile>${project.build.directory}/enunciate.xml</configFile>
<docsDir>${project.build.directory}</docsDir>
<docsSubdir>restdocs</docsSubdir>
</configuration>
<dependencies>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-top</artifactId>
<version>${enunciate.version}</version>
<exclusions>
<exclusion>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-swagger</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-lombok</artifactId>
<version>${enunciate.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/doc/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@@ -1,8 +1,6 @@
package sonia.scm.legacy; package sonia.scm.legacy;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import sonia.scm.NotFoundException; import sonia.scm.NotFoundException;
import sonia.scm.repository.Repository; import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryManager;
@@ -26,12 +24,6 @@ public class LegacyRepositoryService {
@GET @GET
@Path("{id}") @Path("{id}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
@ResponseCode(code = 403, condition = "not authorized, the current user does not have the \"repository:read:global\" privilege"),
@ResponseCode(code = 500, condition = "internal server error")
})
public NamespaceAndNameDto getNameAndNamespaceForRepositoryId(@PathParam("id") String repositoryId) { public NamespaceAndNameDto getNameAndNamespaceForRepositoryId(@PathParam("id") String repositoryId) {
Repository repo = repositoryManager.get(repositoryId); Repository repo = repositoryManager.get(repositoryId);
if (repo == null) { if (repo == null) {

View File

@@ -916,107 +916,9 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins>
</build>
</profile>
<profile>
<id>doc</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-enunciate-configuration</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/doc</directory>
<filtering>true</filtering>
<includes>
<include>**/enunciate.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<configFile>${project.build.directory}/enunciate.xml</configFile>
<docsDir>${project.build.directory}</docsDir>
<docsSubdir>restdocs</docsSubdir>
</configuration>
<dependencies>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-top</artifactId>
<version>${enunciate.version}</version>
<exclusions>
<exclusion>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-swagger</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-lombok</artifactId>
<version>${enunciate.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/doc/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile>
</profiles> </profiles>
</project> </project>

View File

@@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010, Sebastian Sdorra
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of SCM-Manager; nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
http://bitbucket.org/sdorra/scm-manager
-->
<!--
Document : enunciate.xml
Created on : October 2, 2011, 12:02 PM
Author : Sebastian Sdorra
Description: Enunciate configuration
-->
<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.9.0.xsd"
slug="scm-manager" version="${project.version}">
<title>SCM-Manager API</title>
<description>
<![CDATA[
<h1>SCM-Manager API</h1>
<p>This page describes the RESTful Web Service API of <a href="https://www.scm-manager.org">SCM-Manager</a> ${project.version}.</p>
]]>
</description>
<api-classes/>
<modules>
<jaxrs datatype-detection="local">
<application path="/api" />
</jaxrs>
<docs disableResourceLinks="true" includeApplicationPath="true" />
</modules>
</enunciate>

View File

@@ -1,10 +1,10 @@
/** /**
* Copyright (c) 2010, Sebastian Sdorra * Copyright (c) 2010, Sebastian Sdorra
* All rights reserved. * All rights reserved.
* * <p>
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * <p>
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
@@ -13,7 +13,7 @@
* 3. Neither the name of SCM-Manager; nor the names of its * 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* * <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -24,13 +24,11 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* * <p>
* http://bitbucket.org/sdorra/scm-manager * http://bitbucket.org/sdorra/scm-manager
*
*/ */
package sonia.scm.api.rest.resources; package sonia.scm.api.rest.resources;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
@@ -38,10 +36,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import sonia.scm.FeatureNotSupportedException; import sonia.scm.FeatureNotSupportedException;
@@ -100,8 +94,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
// @Path("import/repositories") // @Path("import/repositories")
public class RepositoryImportResource public class RepositoryImportResource {
{
/** /**
* the logger for RepositoryImportResource * the logger for RepositoryImportResource
@@ -119,8 +112,7 @@ public class RepositoryImportResource
*/ */
@Inject @Inject
public RepositoryImportResource(RepositoryManager manager, public RepositoryImportResource(RepositoryManager manager,
RepositoryServiceFactory serviceFactory) RepositoryServiceFactory serviceFactory) {
{
this.manager = manager; this.manager = manager;
this.serviceFactory = serviceFactory; this.serviceFactory = serviceFactory;
} }
@@ -138,30 +130,16 @@ public class RepositoryImportResource
* @param name name of the repository * @param name name of the repository
* @param inputStream input bundle * @param inputStream input bundle
* @param compressed true if the bundle is gzip compressed * @param compressed true if the bundle is gzip compressed
*
* @return empty response with location header which points to the imported repository * @return empty response with location header which points to the imported repository
* @since 1.43 * @since 1.43
*/ */
@POST @POST
@Path("{type}/bundle") @Path("{type}/bundle")
@StatusCodes({
@ResponseCode(code = 201, condition = "created", additionalHeaders = {
@ResponseHeader(name = "Location", description = "uri to the imported repository")
}),
@ResponseCode(
code = 400,
condition = "bad request, the import bundle feature is not supported by this type of repositories or the parameters are not valid"
),
@ResponseCode(code = 409, condition = "conflict, a repository with the name already exists"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(TypeHint.NO_CONTENT.class)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
public Response importFromBundle(@Context UriInfo uriInfo, public Response importFromBundle(@Context UriInfo uriInfo,
@PathParam("type") String type, @FormParam("name") String name, @PathParam("type") String type, @FormParam("name") String name,
@FormParam("bundle") InputStream inputStream, @QueryParam("compressed") @FormParam("bundle") InputStream inputStream, @QueryParam("compressed")
@DefaultValue("false") boolean compressed) @DefaultValue("false") boolean compressed) {
{
Repository repository = doImportFromBundle(type, name, inputStream, Repository repository = doImportFromBundle(type, name, inputStream,
compressed); compressed);
@@ -179,39 +157,24 @@ public class RepositoryImportResource
* @param name name of the repository * @param name name of the repository
* @param inputStream input bundle * @param inputStream input bundle
* @param compressed true if the bundle is gzip compressed * @param compressed true if the bundle is gzip compressed
*
* @return empty response with location header which points to the imported * @return empty response with location header which points to the imported
* repository * repository
* @since 1.43 * @since 1.43
*/ */
@POST @POST
@Path("{type}/bundle.html") @Path("{type}/bundle.html")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(
code = 400,
condition = "bad request, the import bundle feature is not supported by this type of repositories or the parameters are not valid"
),
@ResponseCode(code = 409, condition = "conflict, a repository with the name already exists"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(RestActionUploadResult.class)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML) @Produces(MediaType.TEXT_HTML)
public Response importFromBundleUI(@PathParam("type") String type, public Response importFromBundleUI(@PathParam("type") String type,
@FormParam("name") String name, @FormParam("name") String name,
@FormParam("bundle") InputStream inputStream, @QueryParam("compressed") @FormParam("bundle") InputStream inputStream, @QueryParam("compressed")
@DefaultValue("false") boolean compressed) @DefaultValue("false") boolean compressed) {
{
Response response; Response response;
try try {
{
doImportFromBundle(type, name, inputStream, compressed); doImportFromBundle(type, name, inputStream, compressed);
response = Response.ok(new RestActionUploadResult(true)).build(); response = Response.ok(new RestActionUploadResult(true)).build();
} } catch (WebApplicationException ex) {
catch (WebApplicationException ex)
{
logger.warn("error durring bundle import", ex); logger.warn("error durring bundle import", ex);
response = Response.fromResponse(ex.getResponse()).entity( response = Response.fromResponse(ex.getResponse()).entity(
new RestActionUploadResult(false)).build(); new RestActionUploadResult(false)).build();
@@ -229,29 +192,15 @@ public class RepositoryImportResource
* @param uriInfo uri info * @param uriInfo uri info
* @param type repository type * @param type repository type
* @param request request object * @param request request object
*
* @return empty response with location header which points to the imported * @return empty response with location header which points to the imported
* repository * repository
* @since 1.43 * @since 1.43
*/ */
@POST @POST
@Path("{type}/url") @Path("{type}/url")
@StatusCodes({ @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ResponseCode(code = 201, condition = "created", additionalHeaders = {
@ResponseHeader(name = "Location", description = "uri to the imported repository")
}),
@ResponseCode(
code = 400,
condition = "bad request, the import feature is not supported by this type of repositories or the parameters are not valid"
),
@ResponseCode(code = 409, condition = "conflict, a repository with the name already exists"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(TypeHint.NO_CONTENT.class)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response importFromUrl(@Context UriInfo uriInfo, public Response importFromUrl(@Context UriInfo uriInfo,
@PathParam("type") String type, UrlImportRequest request) @PathParam("type") String type, UrlImportRequest request) {
{
RepositoryPermissions.create().check(); RepositoryPermissions.create().check();
checkNotNull(request, "request is required"); checkNotNull(request, "request is required");
checkArgument(!Strings.isNullOrEmpty(request.getName()), checkArgument(!Strings.isNullOrEmpty(request.getName()),
@@ -268,17 +217,12 @@ public class RepositoryImportResource
Repository repository = create(type, request.getName()); Repository repository = create(type, request.getName());
RepositoryService service = null; RepositoryService service = null;
try try {
{
service = serviceFactory.create(repository); service = serviceFactory.create(repository);
service.getPullCommand().pull(request.getUrl()); service.getPullCommand().pull(request.getUrl());
} } catch (IOException ex) {
catch (IOException ex)
{
handleImportFailure(ex, repository); handleImportFailure(ex, repository);
} } finally {
finally
{
IOUtil.close(service); IOUtil.close(service);
} }
@@ -290,23 +234,12 @@ public class RepositoryImportResource
* directory. <strong>Note:</strong> This method requires admin privileges. * directory. <strong>Note:</strong> This method requires admin privileges.
* *
* @param type repository type * @param type repository type
*
* @return imported repositories * @return imported repositories
*/ */
@POST @POST
@Path("{type}") @Path("{type}")
@StatusCodes({ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ResponseCode(code = 200, condition = "success"), public Response importRepositories(@PathParam("type") String type) {
@ResponseCode(
code = 400,
condition = "bad request, the import feature is not supported by this type of repositories"
),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(Repository[].class)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response importRepositories(@PathParam("type") String type)
{
RepositoryPermissions.create().check(); RepositoryPermissions.create().check();
List<Repository> repositories = new ArrayList<Repository>(); List<Repository> repositories = new ArrayList<Repository>();
@@ -315,7 +248,8 @@ public class RepositoryImportResource
//J- //J-
return Response.ok( return Response.ok(
new GenericEntity<List<Repository>>(repositories) {} new GenericEntity<List<Repository>>(repositories) {
}
).build(); ).build();
//J+ //J+
} }
@@ -327,32 +261,22 @@ public class RepositoryImportResource
* @return imported repositories * @return imported repositories
*/ */
@POST @POST
@StatusCodes({ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ResponseCode(code = 200, condition = "success"), public Response importRepositories() {
@ResponseCode(
code = 400,
condition = "bad request, the import feature is not supported by this type of repositories"
),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(Repository[].class)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response importRepositories()
{
RepositoryPermissions.create().check(); RepositoryPermissions.create().check();
logger.info("start directory import for all supported repository types"); logger.info("start directory import for all supported repository types");
List<Repository> repositories = new ArrayList<Repository>(); List<Repository> repositories = new ArrayList<Repository>();
for (Type t : findImportableTypes()) for (Type t : findImportableTypes()) {
{
importFromDirectory(repositories, t.getName()); importFromDirectory(repositories, t.getName());
} }
//J- //J-
return Response.ok( return Response.ok(
new GenericEntity<List<Repository>>(repositories) {} new GenericEntity<List<Repository>>(repositories) {
}
).build(); ).build();
//J+ //J+
} }
@@ -363,72 +287,50 @@ public class RepositoryImportResource
* of failed directories. <strong>Note:</strong> This method requires admin privileges. * of failed directories. <strong>Note:</strong> This method requires admin privileges.
* *
* @param type repository type * @param type repository type
*
* @return imported repositories * @return imported repositories
* @since 1.43 * @since 1.43
*/ */
@POST @POST
@Path("{type}/directory") @Path("{type}/directory")
@StatusCodes({ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(
code = 400,
condition = "bad request, the import feature is not supported by this type of repositories"
),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(ImportResult.class)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response importRepositoriesFromDirectory( public Response importRepositoriesFromDirectory(
@PathParam("type") String type) @PathParam("type") String type) {
{
RepositoryPermissions.create().check(); RepositoryPermissions.create().check();
Response response; Response response;
RepositoryHandler handler = manager.getHandler(type); RepositoryHandler handler = manager.getHandler(type);
if (handler != null) if (handler != null) {
{
logger.info("start directory import for repository type {}", type); logger.info("start directory import for repository type {}", type);
try try {
{
ImportResult result; ImportResult result;
ImportHandler importHandler = handler.getImportHandler(); ImportHandler importHandler = handler.getImportHandler();
if (importHandler instanceof AdvancedImportHandler) if (importHandler instanceof AdvancedImportHandler) {
{
logger.debug("start directory import, using advanced import handler"); logger.debug("start directory import, using advanced import handler");
result = result =
((AdvancedImportHandler) importHandler) ((AdvancedImportHandler) importHandler)
.importRepositoriesFromDirectory(manager); .importRepositoriesFromDirectory(manager);
} } else {
else
{
logger.debug("start directory import, using normal import handler"); logger.debug("start directory import, using normal import handler");
result = new ImportResult(importHandler.importRepositories(manager), result = new ImportResult(importHandler.importRepositories(manager),
ImmutableList.<String>of()); ImmutableList.<String>of());
} }
response = Response.ok(result).build(); response = Response.ok(result).build();
} } catch (FeatureNotSupportedException ex) {
catch (FeatureNotSupportedException ex)
{
logger logger
.warn( .warn(
"import feature is not supported by repository handler for type " "import feature is not supported by repository handler for type "
.concat(type), ex); .concat(type), ex);
response = Response.status(Response.Status.BAD_REQUEST).build(); response = Response.status(Response.Status.BAD_REQUEST).build();
} } catch (IOException ex) {
catch (IOException ex)
{
logger.warn("exception occured durring directory import", ex); logger.warn("exception occured durring directory import", ex);
response = Response.serverError().build(); response = Response.serverError().build();
} }
} } else {
else
{
logger.warn("could not find reposiotry handler for type {}", type); logger.warn("could not find reposiotry handler for type {}", type);
response = Response.status(Response.Status.BAD_REQUEST).build(); response = Response.status(Response.Status.BAD_REQUEST).build();
} }
@@ -445,25 +347,16 @@ public class RepositoryImportResource
* @return list of repository types * @return list of repository types
*/ */
@GET @GET
@TypeHint(Type[].class) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@StatusCodes({ public Response getImportableTypes() {
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(
code = 400,
condition = "bad request, the import feature is not supported by this type of repositories"
),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getImportableTypes()
{
RepositoryPermissions.create().check(); RepositoryPermissions.create().check();
List<Type> types = findImportableTypes(); List<Type> types = findImportableTypes();
//J- //J-
return Response.ok( return Response.ok(
new GenericEntity<List<Type>>(types) {} new GenericEntity<List<Type>>(types) {
}
).build(); ).build();
//J+ //J+
} }
@@ -473,14 +366,11 @@ public class RepositoryImportResource
/** /**
* Build rest response for repository. * Build rest response for repository.
* *
*
* @param uriInfo uri info * @param uriInfo uri info
* @param repository imported repository * @param repository imported repository
*
* @return rest response * @return rest response
*/ */
private Response buildResponse(UriInfo uriInfo, Repository repository) private Response buildResponse(UriInfo uriInfo, Repository repository) {
{
URI location = uriInfo.getBaseUriBuilder().path( URI location = uriInfo.getBaseUriBuilder().path(
RepositoryResource.class).path(repository.getId()).build(); RepositoryResource.class).path(repository.getId()).build();
@@ -490,15 +380,12 @@ public class RepositoryImportResource
/** /**
* Check repository type for support for the given command. * Check repository type for support for the given command.
* *
*
* @param type repository type * @param type repository type
* @param cmd command * @param cmd command
* @param request request object * @param request request object
*/ */
private void checkSupport(Type type, Command cmd, Object request) private void checkSupport(Type type, Command cmd, Object request) {
{ if (!(type instanceof RepositoryType)) {
if (!(type instanceof RepositoryType))
{
logger.warn("type {} is not a repository type", type.getName()); logger.warn("type {} is not a repository type", type.getName());
throw new WebApplicationException(Response.Status.BAD_REQUEST); throw new WebApplicationException(Response.Status.BAD_REQUEST);
@@ -506,8 +393,7 @@ public class RepositoryImportResource
Set<Command> cmds = ((RepositoryType) type).getSupportedCommands(); Set<Command> cmds = ((RepositoryType) type).getSupportedCommands();
if (!cmds.contains(cmd)) if (!cmds.contains(cmd)) {
{
logger.warn("type {} does not support this type of import: {}", logger.warn("type {} does not support this type of import: {}",
type.getName(), request); type.getName(), request);
@@ -518,24 +404,18 @@ public class RepositoryImportResource
/** /**
* Creates a new repository with the given name and type. * Creates a new repository with the given name and type.
* *
*
* @param type repository type * @param type repository type
* @param name repository name * @param name repository name
*
* @return newly created repository * @return newly created repository
*/ */
private Repository create(String type, String name) private Repository create(String type, String name) {
{
Repository repository = null; Repository repository = null;
try try {
{
// TODO #8783 // TODO #8783
// repository = new Repository(null, type, name); // repository = new Repository(null, type, name);
manager.create(repository); manager.create(repository);
} } catch (InternalRepositoryException ex) {
catch (InternalRepositoryException ex)
{
handleGenericCreationFailure(ex, type, name); handleGenericCreationFailure(ex, type, name);
} }
@@ -545,17 +425,14 @@ public class RepositoryImportResource
/** /**
* Start bundle import. * Start bundle import.
* *
*
* @param type repository type * @param type repository type
* @param name name of the repository * @param name name of the repository
* @param inputStream bundle stream * @param inputStream bundle stream
* @param compressed true if the bundle is gzip compressed * @param compressed true if the bundle is gzip compressed
*
* @return imported repository * @return imported repository
*/ */
private Repository doImportFromBundle(String type, String name, private Repository doImportFromBundle(String type, String name,
InputStream inputStream, boolean compressed) InputStream inputStream, boolean compressed) {
{
RepositoryPermissions.create().check(); RepositoryPermissions.create().check();
checkArgument(!Strings.isNullOrEmpty(name), checkArgument(!Strings.isNullOrEmpty(name),
@@ -564,8 +441,7 @@ public class RepositoryImportResource
Repository repository; Repository repository;
try try {
{
Type t = type(type); Type t = type(type);
checkSupport(t, Command.UNBUNDLE, "bundle"); checkSupport(t, Command.UNBUNDLE, "bundle");
@@ -576,26 +452,19 @@ public class RepositoryImportResource
File file = File.createTempFile("scm-import-", ".bundle"); File file = File.createTempFile("scm-import-", ".bundle");
try try {
{
long length = Files.asByteSink(file).writeFrom(inputStream); long length = Files.asByteSink(file).writeFrom(inputStream);
logger.info("copied {} bytes to temp, start bundle import", length); logger.info("copied {} bytes to temp, start bundle import", length);
service = serviceFactory.create(repository); service = serviceFactory.create(repository);
service.getUnbundleCommand().setCompressed(compressed).unbundle(file); service.getUnbundleCommand().setCompressed(compressed).unbundle(file);
} } catch (InternalRepositoryException ex) {
catch (InternalRepositoryException ex)
{
handleImportFailure(ex, repository); handleImportFailure(ex, repository);
} } finally {
finally
{
IOUtil.close(service); IOUtil.close(service);
IOUtil.delete(file); IOUtil.delete(file);
} }
} } catch (IOException ex) {
catch (IOException ex)
{
logger.warn("could not create temporary file", ex); logger.warn("could not create temporary file", ex);
throw new WebApplicationException(ex); throw new WebApplicationException(ex);
@@ -607,42 +476,29 @@ public class RepositoryImportResource
/** /**
* Method description * Method description
* *
*
* @return * @return
*/ */
private List<Type> findImportableTypes() private List<Type> findImportableTypes() {
{
List<Type> types = new ArrayList<Type>(); List<Type> types = new ArrayList<Type>();
Collection<Type> handlerTypes = manager.getTypes(); Collection<Type> handlerTypes = manager.getTypes();
for (Type t : handlerTypes) for (Type t : handlerTypes) {
{
RepositoryHandler handler = manager.getHandler(t.getName()); RepositoryHandler handler = manager.getHandler(t.getName());
if (handler != null) if (handler != null) {
{ try {
try if (handler.getImportHandler() != null) {
{
if (handler.getImportHandler() != null)
{
types.add(t); types.add(t);
} }
} } catch (FeatureNotSupportedException ex) {
catch (FeatureNotSupportedException ex) if (logger.isTraceEnabled()) {
{
if (logger.isTraceEnabled())
{
logger.trace("import handler is not supported", ex); logger.trace("import handler is not supported", ex);
} } else if (logger.isInfoEnabled()) {
else if (logger.isInfoEnabled())
{
logger.info("{} handler does not support import of repositories", logger.info("{} handler does not support import of repositories",
t.getName()); t.getName());
} }
} }
} } else if (logger.isWarnEnabled()) {
else if (logger.isWarnEnabled())
{
logger.warn("could not find handler for type {}", t.getName()); logger.warn("could not find handler for type {}", t.getName());
} }
} }
@@ -653,14 +509,12 @@ public class RepositoryImportResource
/** /**
* Handle creation failures. * Handle creation failures.
* *
*
* @param ex exception * @param ex exception
* @param type repository type * @param type repository type
* @param name name of the repository * @param name name of the repository
*/ */
private void handleGenericCreationFailure(Exception ex, String type, private void handleGenericCreationFailure(Exception ex, String type,
String name) String name) {
{
logger.error(String.format("could not create repository %s with type %s", logger.error(String.format("could not create repository %s with type %s",
type, name), ex); type, name), ex);
@@ -670,20 +524,15 @@ public class RepositoryImportResource
/** /**
* Handle import failures. * Handle import failures.
* *
*
* @param ex exception * @param ex exception
* @param repository repository * @param repository repository
*/ */
private void handleImportFailure(Exception ex, Repository repository) private void handleImportFailure(Exception ex, Repository repository) {
{
logger.error("import for repository failed, delete repository", ex); logger.error("import for repository failed, delete repository", ex);
try try {
{
manager.delete(repository); manager.delete(repository);
} } catch (InternalRepositoryException | NotFoundException e) {
catch (InternalRepositoryException | NotFoundException e)
{
logger.error("can not delete repository after import failure", e); logger.error("can not delete repository after import failure", e);
} }
@@ -694,27 +543,21 @@ public class RepositoryImportResource
/** /**
* Import repositories from a specific type. * Import repositories from a specific type.
* *
*
* @param repositories repository list * @param repositories repository list
* @param type type of repository * @param type type of repository
*/ */
private void importFromDirectory(List<Repository> repositories, String type) private void importFromDirectory(List<Repository> repositories, String type) {
{
RepositoryHandler handler = manager.getHandler(type); RepositoryHandler handler = manager.getHandler(type);
if (handler != null) if (handler != null) {
{
logger.info("start directory import for repository type {}", type); logger.info("start directory import for repository type {}", type);
try try {
{
List<String> repositoryNames = List<String> repositoryNames =
handler.getImportHandler().importRepositories(manager); handler.getImportHandler().importRepositories(manager);
if (repositoryNames != null) if (repositoryNames != null) {
{ for (String repositoryName : repositoryNames) {
for (String repositoryName : repositoryNames)
{
// TODO #8783 // TODO #8783
/*Repository repository = null; //manager.get(type, repositoryName); /*Repository repository = null; //manager.get(type, repositoryName);
@@ -729,22 +572,14 @@ public class RepositoryImportResource
}*/ }*/
} }
} }
} } catch (FeatureNotSupportedException ex) {
catch (FeatureNotSupportedException ex)
{
throw new WebApplicationException(ex, Response.Status.BAD_REQUEST); throw new WebApplicationException(ex, Response.Status.BAD_REQUEST);
} } catch (IOException ex) {
catch (IOException ex) throw new WebApplicationException(ex);
{ } catch (InternalRepositoryException ex) {
throw new WebApplicationException(ex); throw new WebApplicationException(ex);
} }
catch (InternalRepositoryException ex) } else {
{
throw new WebApplicationException(ex);
}
}
else
{
throw new WebApplicationException(Response.Status.BAD_REQUEST); throw new WebApplicationException(Response.Status.BAD_REQUEST);
} }
} }
@@ -752,17 +587,13 @@ public class RepositoryImportResource
/** /**
* Method description * Method description
* *
*
* @param type * @param type
*
* @return * @return
*/ */
private Type type(String type) private Type type(String type) {
{
RepositoryHandler handler = manager.getHandler(type); RepositoryHandler handler = manager.getHandler(type);
if (handler == null) if (handler == null) {
{
logger.warn("no handler for type {} found", type); logger.warn("no handler for type {} found", type);
throw new WebApplicationException(Response.Status.NOT_FOUND); throw new WebApplicationException(Response.Status.NOT_FOUND);
@@ -778,24 +609,21 @@ public class RepositoryImportResource
*/ */
@XmlRootElement(name = "import") @XmlRootElement(name = "import")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public static class UrlImportRequest public static class UrlImportRequest {
{
/** /**
* Constructs ... * Constructs ...
*
*/ */
public UrlImportRequest() {} public UrlImportRequest() {
}
/** /**
* Constructs a new {@link UrlImportRequest} * Constructs a new {@link UrlImportRequest}
* *
*
* @param name name of the repository * @param name name of the repository
* @param url external url of the repository * @param url external url of the repository
*/ */
public UrlImportRequest(String name, String url) public UrlImportRequest(String name, String url) {
{
this.name = name; this.name = name;
this.url = url; this.url = url;
} }
@@ -806,8 +634,7 @@ public class RepositoryImportResource
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String toString() public String toString() {
{
//J- //J-
return MoreObjects.toStringHelper(this) return MoreObjects.toStringHelper(this)
.add("name", name) .add("name", name)
@@ -821,40 +648,44 @@ public class RepositoryImportResource
/** /**
* Returns name of the repository. * Returns name of the repository.
* *
*
* @return name of the repository * @return name of the repository
*/ */
public String getName() public String getName() {
{
return name; return name;
} }
/** /**
* Returns external url of the repository. * Returns external url of the repository.
* *
*
* @return external url of the repository * @return external url of the repository
*/ */
public String getUrl() public String getUrl() {
{
return url; return url;
} }
//~--- fields ------------------------------------------------------------- //~--- fields -------------------------------------------------------------
/** name of the repository */ /**
* name of the repository
*/
private String name; private String name;
/** external url of the repository */ /**
* external url of the repository
*/
private String url; private String url;
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** repository manager */ /**
* repository manager
*/
private final RepositoryManager manager; private final RepositoryManager manager;
/** repository service factory */ /**
* repository service factory
*/
private final RepositoryServiceFactory serviceFactory; private final RepositoryServiceFactory serviceFactory;
} }

View File

@@ -1,9 +1,8 @@
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.ResponseHeaders;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -181,7 +180,14 @@ public class BranchRootResource {
@Path("") @Path("")
@Consumes(VndMediaType.BRANCH_REQUEST) @Consumes(VndMediaType.BRANCH_REQUEST)
@Operation(summary = "Create branch", description = "Creates a new branch.", tags = "Repository") @Operation(summary = "Create branch", description = "Creates a new branch.", tags = "Repository")
@ApiResponse(responseCode = "201", description = "create success") @ApiResponse(
responseCode = "201",
description = "create success",
headers = @Header(
name = "Location",
description = "uri to the created branch"
)
)
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"push\" privilege") @ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"push\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a branch with this name already exists") @ApiResponse(responseCode = "409", description = "conflict, a branch with this name already exists")
@@ -192,7 +198,6 @@ public class BranchRootResource {
mediaType = VndMediaType.ERROR_TYPE, mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class) schema = @Schema(implementation = ErrorDto.class)
)) ))
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created branch"))
public Response create(@PathParam("namespace") String namespace, public Response create(@PathParam("namespace") String namespace,
@PathParam("name") String name, @PathParam("name") String name,
@Valid BranchRequestDto branchRequest) throws IOException { @Valid BranchRequestDto branchRequest) throws IOException {

View File

@@ -1,8 +1,7 @@
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.ResponseHeaders;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -97,7 +96,14 @@ public class GroupCollectionResource {
@Path("") @Path("")
@Consumes(VndMediaType.GROUP) @Consumes(VndMediaType.GROUP)
@Operation(summary = "Create group", description = "Creates a new group.", tags = "Group") @Operation(summary = "Create group", description = "Creates a new group.", tags = "Group")
@ApiResponse(responseCode = "201", description = "create success") @ApiResponse(
responseCode = "201",
description = "create success",
headers = @Header(
name = "Location",
description = "uri to the created group"
)
)
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"group\" privilege") @ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"group\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a group with this name already exists") @ApiResponse(responseCode = "409", description = "conflict, a group with this name already exists")
@@ -109,7 +115,6 @@ public class GroupCollectionResource {
schema = @Schema(implementation = ErrorDto.class) schema = @Schema(implementation = ErrorDto.class)
) )
) )
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created group"))
public Response create(@Valid GroupDto group) { public Response create(@Valid GroupDto group) {
return adapter.create(group, return adapter.create(group,
() -> dtoToGroupMapper.map(group), () -> dtoToGroupMapper.map(group),

View File

@@ -1,8 +1,7 @@
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.ResponseHeaders;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -105,7 +104,14 @@ public class RepositoryCollectionResource {
@Path("") @Path("")
@Consumes(VndMediaType.REPOSITORY) @Consumes(VndMediaType.REPOSITORY)
@Operation(summary = "Create repository", description = "Creates a new repository.", tags = "Repository") @Operation(summary = "Create repository", description = "Creates a new repository.", tags = "Repository")
@ApiResponse(responseCode = "201", description = "create success") @ApiResponse(
responseCode = "201",
description = "create success",
headers = @Header(
name = "Location",
description = "uri to the created repository"
)
)
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"repository\" privilege") @ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"repository\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a repository with this name already exists") @ApiResponse(responseCode = "409", description = "conflict, a repository with this name already exists")
@@ -116,7 +122,6 @@ public class RepositoryCollectionResource {
mediaType = VndMediaType.ERROR_TYPE, mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class) schema = @Schema(implementation = ErrorDto.class)
)) ))
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created repository"))
public Response create(@Valid RepositoryDto repository, @QueryParam("initialize") boolean initialize) { public Response create(@Valid RepositoryDto repository, @QueryParam("initialize") boolean initialize) {
AtomicReference<Repository> reference = new AtomicReference<>(); AtomicReference<Repository> reference = new AtomicReference<>();
Response response = adapter.create(repository, Response response = adapter.create(repository,

View File

@@ -1,8 +1,7 @@
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.ResponseHeaders;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -92,7 +91,14 @@ public class RepositoryRoleCollectionResource {
@Path("") @Path("")
@Consumes(VndMediaType.REPOSITORY_ROLE) @Consumes(VndMediaType.REPOSITORY_ROLE)
@Operation(summary = "Create repository role", description = "Creates a new repository role.", tags = "Repository role") @Operation(summary = "Create repository role", description = "Creates a new repository role.", tags = "Repository role")
@ApiResponse(responseCode = "201", description = "create success") @ApiResponse(
responseCode = "201",
description = "create success",
headers = @Header(
name = "Location",
description = "uri to the created repository role"
)
)
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"repositoryRole\" privilege") @ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"repositoryRole\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a repository role with this name already exists") @ApiResponse(responseCode = "409", description = "conflict, a repository role with this name already exists")
@@ -103,7 +109,6 @@ public class RepositoryRoleCollectionResource {
mediaType = VndMediaType.ERROR_TYPE, mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class) schema = @Schema(implementation = ErrorDto.class)
)) ))
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created repositoryRole"))
public Response create(@Valid RepositoryRoleDto repositoryRole) { public Response create(@Valid RepositoryRoleDto repositoryRole) {
return adapter.create(repositoryRole, () -> dtoToRepositoryRoleMapper.map(repositoryRole), u -> resourceLinks.repositoryRole().self(u.getName())); return adapter.create(repositoryRole, () -> dtoToRepositoryRoleMapper.map(repositoryRole), u -> resourceLinks.repositoryRole().self(u.getName()));
} }

View File

@@ -1,8 +1,7 @@
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.ResponseHeaders;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -101,7 +100,14 @@ public class UserCollectionResource {
@Path("") @Path("")
@Consumes(VndMediaType.USER) @Consumes(VndMediaType.USER)
@Operation(summary = "Create user", description = "Creates a new user.", tags = "User") @Operation(summary = "Create user", description = "Creates a new user.", tags = "User")
@ApiResponse(responseCode = "201", description = "create success") @ApiResponse(
responseCode = "201",
description = "create success",
headers = @Header(
name = "Location",
description = "uri to the created user"
)
)
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"user\" privilege") @ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"user\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a user with this name already exists") @ApiResponse(responseCode = "409", description = "conflict, a user with this name already exists")
@@ -112,7 +118,6 @@ public class UserCollectionResource {
mediaType = VndMediaType.ERROR_TYPE, mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class) schema = @Schema(implementation = ErrorDto.class)
)) ))
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created user"))
public Response create(@Valid UserDto user) { public Response create(@Valid UserDto user) {
return adapter.create(user, () -> dtoToUserMapper.map(user, passwordService.encryptPassword(user.getPassword())), u -> resourceLinks.user().self(u.getName())); return adapter.create(user, () -> dtoToUserMapper.map(user, passwordService.encryptPassword(user.getPassword())), u -> resourceLinks.user().self(u.getName()));
} }