Search in sources :

Example 6 with ApiImplicitParams

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

the class ReplicationHandler method replicate.

@ApiOperation("Replicate the stores of a remote Indy")
@ApiImplicitParams({ @ApiImplicitParam(paramType = "body", name = "body", dataType = "org.commonjava.indy.model.core.dto.ReplicationDTO", required = true, value = "The configuration determining how replication should be handled, and what remote site to replicate.") })
@POST
@Produces(ApplicationContent.application_json)
public Response replicate(@Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
    Response response;
    try {
        String user = securityManager.getUser(securityContext, request);
        ReplicationDTO dto = serializer.readValue(request.getInputStream(), ReplicationDTO.class);
        final Set<StoreKey> replicated = controller.replicate(dto, user);
        final Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("replicationCount", replicated.size());
        params.put("items", replicated);
        response = responseHelper.formatOkResponseWithJsonEntity(params);
    } catch (final IndyWorkflowException | IOException e) {
        logger.error(String.format("Replication failed: %s", e.getMessage()), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ReplicationDTO(org.commonjava.indy.model.core.dto.ReplicationDTO) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey) LinkedHashMap(java.util.LinkedHashMap) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with ApiImplicitParams

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

the class StoreAdminHandler method create.

@ApiOperation("Create a new store")
@ApiResponses({ @ApiResponse(code = 201, response = ArtifactStore.class, message = "The store was created"), @ApiResponse(code = 409, message = "A store with the specified type and name already exists") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@POST
@Consumes(ApplicationContent.application_json)
@Produces(ApplicationContent.application_json)
public Response create(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @Context final UriInfo uriInfo, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
    final StoreType st = StoreType.get(type);
    Response response = null;
    String json = null;
    try {
        json = IOUtils.toString(request.getInputStream());
        // logger.warn("=> JSON: " + json);
        json = objectMapper.patchLegacyStoreJson(json);
    } catch (final IOException e) {
        final String message = "Failed to read " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = responseHelper.formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    ArtifactStore store = null;
    try {
        store = objectMapper.readValue(json, st.getStoreClass());
    } catch (final IOException e) {
        final String message = "Failed to parse " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = responseHelper.formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    logger.info("\n\nGot artifact store: {}\n\n", store);
    try {
        String user = securityManager.getUser(securityContext, request);
        if (adminController.store(store, user, false)) {
            final URI uri = uriInfo.getBaseUriBuilder().path("/api/admin/stores").path(store.getPackageType()).path(store.getType().singularEndpointName()).build(store.getName());
            response = responseHelper.formatCreatedResponseWithJsonEntity(uri, store);
        } else {
            response = status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json).build();
        }
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) IOException(java.io.IOException) URI(java.net.URI) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project CzechIdMng by bcvsolutions.

the class IdmRoleCatalogueController method findRoots.

@ResponseBody
@RequestMapping(value = "/search/roots", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLECATALOGUE_AUTOCOMPLETE + "')")
@ApiOperation(value = "Search root catalogues", nickname = "searchRootRoleCatalogues", tags = { IdmRoleCatalogueController.TAG })
@ApiImplicitParams({ @ApiImplicitParam(name = "page", dataType = "string", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "string", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") })
public Resources<?> findRoots(@RequestParam(required = false) MultiValueMap<String, Object> parameters, @PageableDefault Pageable pageable) {
    IdmRoleCatalogueFilter filter = toFilter(parameters);
    filter.setRoots(Boolean.TRUE);
    // 
    return toResources(find(filter, pageable, IdmBasePermission.AUTOCOMPLETE), IdmTreeNode.class);
}
Also used : IdmRoleCatalogueFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCatalogueFilter) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project CzechIdMng by bcvsolutions.

the class IdmTreeNodeController method findChildren.

@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.TREENODE_AUTOCOMPLETE + "')")
@RequestMapping(value = "/search/children", method = RequestMethod.GET)
@ApiOperation(value = "Search sub tree nodes", nickname = "searchChildrenTreeNodes", tags = { IdmTreeNodeController.TAG }, notes = "Finds direct chilren by given parent node uuid identifier. Set 'parent' parameter.")
@ApiImplicitParams({ @ApiImplicitParam(name = "page", dataType = "string", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "string", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") })
public Resources<?> findChildren(@RequestParam(required = false) MultiValueMap<String, Object> parameters, @PageableDefault Pageable pageable) {
    IdmTreeNodeFilter filter = toFilter(parameters);
    filter.setRecursively(false);
    // 
    return toResources(find(filter, pageable, IdmBasePermission.AUTOCOMPLETE), IdmTreeNode.class);
}
Also used : IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ApiImplicitParams

use of io.swagger.annotations.ApiImplicitParams in project swagger-core by swagger-api.

the class ParameterProcessorTest method implicitParameterLongTypeProcessorTest.

@Test(description = "test for issue #1873 fixing.")
public void implicitParameterLongTypeProcessorTest() throws NoSuchMethodException {
    final ApiImplicitParams params = getClass().getDeclaredMethod("implicitParametrizedMethodLongType").getAnnotation(ApiImplicitParams.class);
    final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), String.class, Collections.<Annotation>singletonList(params.value()[0]));
    assertEquals(param0.getName(), "id");
    assertEquals(param0.getIn(), "path");
    assertEquals(param0.getRequired(), true);
    assertEquals(param0.getType(), "integer");
    assertEquals(param0.getFormat(), "int64");
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) PathParameter(io.swagger.models.parameters.PathParameter) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Aggregations

ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)29 ApiOperation (io.swagger.annotations.ApiOperation)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 IOException (java.io.IOException)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Response (javax.ws.rs.core.Response)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 ApiResponse (io.swagger.annotations.ApiResponse)6 URI (java.net.URI)6 POST (javax.ws.rs.POST)6 Produces (javax.ws.rs.Produces)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 PathParameter (io.swagger.models.parameters.PathParameter)3