Search in sources :

Example 6 with ApiImplicitParam

use of io.swagger.annotations.ApiImplicitParam in project indy by Commonjava.

the class PromoteResource method promotePaths.

@ApiOperation("Promote paths from a source repository into a target repository/group (subject to validation).")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON request specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteRequest")
@Path("/paths/promote")
@POST
@Consumes(ApplicationContent.application_json)
public Response promotePaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
    PathsPromoteRequest req = null;
    Response response = null;
    try {
        final String json = IOUtils.toString(request.getInputStream());
        logger.info("Got promotion request:\n{}", json);
        req = mapper.readValue(json, PathsPromoteRequest.class);
    } catch (final IOException e) {
        response = formatResponse(e, "Failed to read DTO from request body.");
    }
    if (response != null) {
        return response;
    }
    try {
        PackageTypeDescriptor packageTypeDescriptor = PackageTypes.getPackageTypeDescriptor(req.getSource().getPackageType());
        final String baseUrl = uriInfo.getBaseUriBuilder().path(packageTypeDescriptor.getContentRestBasePath()).build(req.getSource().getType().singularEndpointName(), req.getSource().getName()).toString();
        final PathsPromoteResult result = manager.promotePaths(req, baseUrl);
        // TODO: Amend response status code based on presence of error? This would have consequences for client API...
        response = formatOkResponseWithJsonEntity(result, mapper);
    } catch (PromotionException | IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PackageTypeDescriptor(org.commonjava.indy.model.core.PackageTypeDescriptor) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) IOException(java.io.IOException) PromotionException(org.commonjava.indy.promote.data.PromotionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Example 7 with ApiImplicitParam

use of io.swagger.annotations.ApiImplicitParam in project indy by Commonjava.

the class PromoteResource method resumePaths.

@ApiOperation("RESUME promotion of paths from a source repository into a target repository/group (subject to validation), presumably after a previous failure condition has been corrected.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/resume")
@POST
@Consumes(ApplicationContent.application_json)
public Response resumePaths(@Context final HttpServletRequest request) {
    PathsPromoteResult result = null;
    Response response = null;
    try {
        result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
    } catch (final IOException e) {
        response = formatResponse(e, "Failed to read DTO from request body.");
    }
    if (response != null) {
        return response;
    }
    try {
        result = manager.resumePathsPromote(result);
        // TODO: Amend response status code based on presence of error? This would have consequences for client API...
        response = formatOkResponseWithJsonEntity(result, mapper);
    } catch (PromotionException | IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) PromotionException(org.commonjava.indy.promote.data.PromotionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Example 8 with ApiImplicitParam

use of io.swagger.annotations.ApiImplicitParam in project indy by Commonjava.

the class PromoteResource method rollbackPaths.

@ApiOperation("Rollback promotion of any completed paths to a source repository from a target repository/group.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/rollback")
@POST
@Consumes(ApplicationContent.application_json)
public Response rollbackPaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
    PathsPromoteResult result = null;
    Response response = null;
    try {
        result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
    } catch (final IOException e) {
        response = formatResponse(e, "Failed to read DTO from request body.");
    }
    if (response != null) {
        return response;
    }
    try {
        result = manager.rollbackPathsPromote(result);
        // TODO: Amend response status code based on presence of error? This would have consequences for client API...
        response = formatOkResponseWithJsonEntity(result, mapper);
    } catch (PromotionException | IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) PromotionException(org.commonjava.indy.promote.data.PromotionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Example 9 with ApiImplicitParam

use of io.swagger.annotations.ApiImplicitParam in project java-chassis by ServiceComb.

the class ApiImplicitParamMethodProcessor method process.

@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
    ApiImplicitParam paramAnnotation = (ApiImplicitParam) annotation;
    Parameter parameter = AnnotationUtils.createParameter(operationGenerator.getSwagger(), paramAnnotation);
    operationGenerator.addMethodAnnotationParameter(parameter);
}
Also used : Parameter(io.swagger.models.parameters.Parameter) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam)

Example 10 with ApiImplicitParam

use of io.swagger.annotations.ApiImplicitParam in project java-chassis by ServiceComb.

the class ApiImplicitParamsClassProcessor method process.

@Override
public void process(Object annotation, SwaggerGenerator swaggerGenerator) {
    ApiImplicitParams apiImplicitParamsAnnotation = (ApiImplicitParams) annotation;
    ClassAnnotationProcessor processor = swaggerGenerator.getContext().findClassAnnotationProcessor(ApiImplicitParam.class);
    for (ApiImplicitParam paramAnnotation : apiImplicitParamsAnnotation.value()) {
        processor.process(paramAnnotation, swaggerGenerator);
    }
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ClassAnnotationProcessor(io.servicecomb.swagger.generator.core.ClassAnnotationProcessor) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam)

Aggregations

ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)10 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponse (io.swagger.annotations.ApiResponse)6 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 Response (javax.ws.rs.core.Response)6 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)6 IOException (java.io.IOException)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)4 PromotionException (org.commonjava.indy.promote.data.PromotionException)4 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)3 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 Paths (java.nio.file.Paths)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2