use of io.swagger.annotations.ApiImplicitParams in project java-chassis by ServiceComb.
the class ApiImplicitParamsMethodProcessor method process.
@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
ApiImplicitParams apiImplicitParamsAnnotation = (ApiImplicitParams) annotation;
MethodAnnotationProcessor processor = operationGenerator.getContext().findMethodAnnotationProcessor(ApiImplicitParam.class);
for (ApiImplicitParam paramAnnotation : apiImplicitParamsAnnotation.value()) {
processor.process(paramAnnotation, operationGenerator);
}
}
use of io.swagger.annotations.ApiImplicitParams in project vertx-swagger by bobxwang.
the class RestApiVerticle method handle.
@BBRouter(path = "/catalogue/products/:producttype/:productid", httpMethod = HttpMethod.GET)
@ApiImplicitParams({ @ApiImplicitParam(name = "producttype", value = "产品类型", required = true, dataType = "string", paramType = "path"), @ApiImplicitParam(name = "productid", value = "产品标识", dataType = "string", paramType = "path") })
private void handle(RoutingContext ctx) {
String productType = ctx.request().getParam("producttype");
String productID = ctx.request().getParam("productid");
ctx.response().putHeader("content-type", "application/json;charset=UTF-8").end(new JsonObject().put("now", new Date().toString()).put("producttype", productType).put("productid", productID).encodePrettily());
}
use of io.swagger.annotations.ApiImplicitParams in project nifi by apache.
the class ProcessGroupResource method uploadTemplate.
/**
* Imports the specified template.
*
* @param httpServletRequest request
* @param in The template stream
* @return A templateEntity or an errorResponse XML snippet.
* @throws InterruptedException if interrupted
*/
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_XML)
@Path("{id}/templates/upload")
@ApiOperation(value = "Uploads a template", response = TemplateEntity.class, authorizations = { @Authorization(value = "Write - /process-groups/{uuid}") })
@ApiImplicitParams(value = { @ApiImplicitParam(name = "template", value = "The binary content of the template file being uploaded.", required = true, type = "file", paramType = "formData") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response uploadTemplate(@Context final HttpServletRequest httpServletRequest, @Context final UriInfo uriInfo, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId, @FormDataParam("template") final InputStream in) throws InterruptedException {
// unmarshal the template
final TemplateDTO template;
try {
JAXBContext context = JAXBContext.newInstance(TemplateDTO.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
XMLStreamReader xsr = XmlUtils.createSafeReader(in);
JAXBElement<TemplateDTO> templateElement = unmarshaller.unmarshal(xsr, TemplateDTO.class);
template = templateElement.getValue();
} catch (JAXBException jaxbe) {
logger.warn("An error occurred while parsing a template.", jaxbe);
String responseXml = String.format("<errorResponse status=\"%s\" statusText=\"The specified template is not in a valid format.\"/>", Response.Status.BAD_REQUEST.getStatusCode());
return Response.status(Response.Status.OK).entity(responseXml).type("application/xml").build();
} catch (IllegalArgumentException iae) {
logger.warn("Unable to import template.", iae);
String responseXml = String.format("<errorResponse status=\"%s\" statusText=\"%s\"/>", Response.Status.BAD_REQUEST.getStatusCode(), iae.getMessage());
return Response.status(Response.Status.OK).entity(responseXml).type("application/xml").build();
} catch (Exception e) {
logger.warn("An error occurred while importing a template.", e);
String responseXml = String.format("<errorResponse status=\"%s\" statusText=\"Unable to import the specified template: %s\"/>", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
return Response.status(Response.Status.OK).entity(responseXml).type("application/xml").build();
}
// build the response entity
TemplateEntity entity = new TemplateEntity();
entity.setTemplate(template);
if (isReplicateRequest()) {
// convert request accordingly
final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
uriBuilder.segment("process-groups", groupId, "templates", "import");
final URI importUri = uriBuilder.build();
final Map<String, String> headersToOverride = new HashMap<>();
headersToOverride.put("content-type", MediaType.APPLICATION_XML);
// to the cluster nodes themselves.
if (getReplicationTarget() == ReplicationTarget.CLUSTER_NODES) {
return getRequestReplicator().replicate(HttpMethod.POST, importUri, entity, getHeaders(headersToOverride)).awaitMergedResponse().getResponse();
} else {
return getRequestReplicator().forwardToCoordinator(getClusterCoordinatorNode(), HttpMethod.POST, importUri, entity, getHeaders(headersToOverride)).awaitMergedResponse().getResponse();
}
}
// otherwise import the template locally
return importTemplate(httpServletRequest, groupId, entity);
}
use of io.swagger.annotations.ApiImplicitParams in project CzechIdMng by bcvsolutions.
the class SchedulerController method find.
/**
* Finds scheduled tasks
*
* @return all tasks
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@ResponseBody
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.SCHEDULER_READ + "')")
@ApiOperation(value = "Search scheduled tasks", nickname = "searchSchedulerTasks", tags = { SchedulerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCHEDULER_READ, description = "") }) })
@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<Task> find(@RequestParam(required = false) MultiValueMap<String, Object> parameters, @PageableDefault Pageable pageable) {
String text = getParameterConverter().toString(parameters, DataFilter.PARAMETER_TEXT);
List<Task> tasks = schedulerService.getAllTasks().stream().filter(task -> {
// filter - like name or description only
return StringUtils.isEmpty(text) || task.getTaskType().getSimpleName().toLowerCase().contains(text.toLowerCase()) || (task.getDescription() != null && task.getDescription().toLowerCase().contains(text.toLowerCase()));
}).sorted((taskOne, taskTwo) -> {
Sort sort = pageable.getSort();
if (pageable.getSort() == null) {
return 0;
}
int compareAscValue = 0;
boolean asc = true;
// "naive" sort implementation
if (sort.getOrderFor(PROPERTY_TASK_TYPE) != null) {
asc = sort.getOrderFor(PROPERTY_TASK_TYPE).isAscending();
compareAscValue = taskOne.getTaskType().getSimpleName().compareTo(taskTwo.getTaskType().getSimpleName());
}
if (sort.getOrderFor(PROPERTY_DESCRIPTION) != null) {
asc = sort.getOrderFor(PROPERTY_DESCRIPTION).isAscending();
compareAscValue = taskOne.getDescription().compareTo(taskTwo.getDescription());
}
if (sort.getOrderFor(PROPERTY_INSTANCE_ID) != null) {
asc = sort.getOrderFor(PROPERTY_INSTANCE_ID).isAscending();
compareAscValue = taskOne.getInstanceId().compareTo(taskTwo.getInstanceId());
}
return asc ? compareAscValue : compareAscValue * -1;
}).collect(Collectors.toList());
// "naive" pagination
int first = pageable.getPageNumber() * pageable.getPageSize();
int last = pageable.getPageSize() + first;
List<Task> taskPage = tasks.subList(first < tasks.size() ? first : tasks.size() > 0 ? tasks.size() - 1 : 0, last < tasks.size() ? last : tasks.size());
//
return pageToResources(new PageImpl(taskPage, pageable, tasks.size()), Task.class);
}
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;
}
Aggregations