use of io.swagger.annotations.ApiResponse in project API by ca-cwds.
the class IndexQueryResource method searchIndex.
/**
* Endpoint for Intake Person Query Search.
*
* @param index {@link IndexQueryRequest}
* @param req JSON {@link IndexQueryRequest}
* @return web service response
*/
@POST
@Path("/{index}/_search")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Unable to process JSON"), @ApiResponse(code = 401, message = "Not Authorized"), @ApiResponse(code = 406, message = "Accept Header not supported") })
@ApiOperation(value = "Query ElasticSearch Persons on given search terms", code = HttpStatus.SC_OK, response = JSONObject.class)
@Consumes(value = MediaType.APPLICATION_JSON)
public Response searchIndex(@PathParam("index") @ApiParam(required = true, name = "index", value = "The index of the search") String index, @Valid @ApiParam(hidden = false, required = true) Object req) {
Response ret;
try {
IndexQueryRequest personQueryRequest = new IndexQueryRequest(index, req);
IndexQueryResponse personQueryResponse = (IndexQueryResponse) resourceDelegate.handle(personQueryRequest).getEntity();
if (personQueryResponse != null) {
ret = Response.status(Response.Status.OK).entity(personQueryResponse.getPersons()).build();
} else {
ret = null;
}
} catch (Exception e) {
LOGGER.error("Intake Person Query ERROR: {}", e.getMessage(), e);
throw new ApiException("Intake Person Query ERROR. " + e.getMessage(), e);
}
return ret;
}
use of io.swagger.annotations.ApiResponse in project kylo by Teradata.
the class TemplatesRestController method getNiFiTemplateFlowInfo.
/**
* Returns data about the NiFiTemplate and its processors related to the input connections, along with the Datasources in the flow
*/
@POST
@Path("/nifi/{templateId}/flow-info")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the flow for the specified template.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the flow.", response = NiFiTemplateFlowResponse.class), @ApiResponse(code = 500, message = "NiFi is unavailable.", response = RestResponseStatus.class) })
public Response getNiFiTemplateFlowInfo(@PathParam("templateId") String templateId, NiFiTemplateFlowRequest flowRequest) {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
List<TemplateProcessorDatasourceDefinition> templateProcessorDatasourceDefinitions = new ArrayList<>();
NiFiTemplateFlowResponse response = new NiFiTemplateFlowResponse();
response.setRequest(flowRequest);
if (StringUtils.isNotBlank(templateId)) {
List<RegisteredTemplate.FlowProcessor> processors = feedManagerTemplateService.getNiFiTemplateFlowProcessors(templateId, flowRequest.getConnectionInfo());
Set<DatasourceDefinition> defs = datasourceService.getDatasourceDefinitions();
Map<String, DatasourceDefinition> datasourceDefinitionMap = new HashMap<>();
if (defs != null) {
defs.stream().forEach(def -> datasourceDefinitionMap.put(def.getProcessorType(), def));
}
templateProcessorDatasourceDefinitions = processors.stream().filter(processor -> datasourceDefinitionMap.containsKey(processor.getType())).map(p -> {
TemplateProcessorDatasourceDefinition definition = new TemplateProcessorDatasourceDefinition();
definition.setProcessorType(p.getType());
definition.setProcessorName(p.getName());
definition.setProcessorId(p.getId());
definition.setDatasourceDefinition(datasourceDefinitionMap.get(p.getType()));
return definition;
}).collect(Collectors.toList());
response.setProcessors(processors);
response.setTemplateProcessorDatasourceDefinitions(templateProcessorDatasourceDefinitions);
}
return Response.ok(response).build();
}
use of io.swagger.annotations.ApiResponse in project kylo by Teradata.
the class TemplatesRestController method getAllowedPermissionsChange.
@GET
@Path("/registered/{templateId}/actions/change")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Constructs and returns a permission change request for a set of users/groups containing the actions that the requester may permit or revoke.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the change request that may be modified by the client and re-posted.", response = PermissionsChange.class), @ApiResponse(code = 400, message = "The type is not valid.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "No template exists with the specified ID.", response = RestResponseStatus.class) })
public Response getAllowedPermissionsChange(@PathParam("templateId") String templateIdStr, @QueryParam("type") String changeType, @QueryParam("user") Set<String> userNames, @QueryParam("group") Set<String> groupNames) {
if (StringUtils.isBlank(changeType)) {
throw new WebApplicationException("The query parameter \"type\" is required", Status.BAD_REQUEST);
}
Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)).collect(Collectors.toSet());
Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)).collect(Collectors.toSet());
return this.securityService.createTemplatePermissionChange(templateIdStr, ChangeType.valueOf(changeType.toUpperCase()), Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(p -> Response.ok(p).build()).orElseThrow(() -> new WebApplicationException("A template with the given ID does not exist: " + templateIdStr, Status.NOT_FOUND));
}
use of io.swagger.annotations.ApiResponse in project kylo by Teradata.
the class TemplatesRestController method getAllowedActions.
@GET
@Path("/registered/{templateId}/actions/allowed")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the list of actions permitted for the given username and/or groups.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the actions.", response = ActionGroup.class), @ApiResponse(code = 404, message = "A template with the given ID does not exist.", response = RestResponseStatus.class) })
public Response getAllowedActions(@PathParam("templateId") String templateIdStr, @QueryParam("user") Set<String> userNames, @QueryParam("group") Set<String> groupNames) {
log.debug("Get allowed actions for template: {}", templateIdStr);
Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)).collect(Collectors.toSet());
Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)).collect(Collectors.toSet());
return this.securityService.getAllowedTemplateActions(templateIdStr, Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(g -> Response.ok(g).build()).orElseThrow(() -> new WebApplicationException("A template with the given ID does not exist: " + templateIdStr, Status.NOT_FOUND));
}
use of io.swagger.annotations.ApiResponse in project kylo by Teradata.
the class DatasourceController method query.
/**
* Executes a query on the specified datasource.
*
* @param idStr the datasource id
* @param query the SQL query
* @return the SQL result
*/
@GET
@Path("{id}/query")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Executes a query and returns the result.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the result.", response = QueryResult.class), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 400, message = "A JDBC data source with that id does not exist.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "NiFi or the database are unavailable.", response = RestResponseStatus.class) })
public Response query(@PathParam("id") final String idStr, @QueryParam("query") final String query) {
// Verify user has access to data source
final Optional<com.thinkbiganalytics.metadata.api.datasource.Datasource.ID> id = metadata.read(() -> {
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_DATASOURCES);
final com.thinkbiganalytics.metadata.api.datasource.Datasource datasource = datasetProvider.getDatasource(datasetProvider.resolve(idStr));
return Optional.ofNullable(datasource).map(com.thinkbiganalytics.metadata.api.datasource.Datasource::getId);
});
// Execute query
return metadata.read(() -> {
final QueryResult result = id.map(datasetProvider::getDatasource).map(ds -> datasourceTransform.toDatasource(ds, DatasourceModelTransform.Level.ADMIN)).filter(JdbcDatasource.class::isInstance).map(JdbcDatasource.class::cast).map(datasource -> dbcpConnectionPoolTableInfo.executeQueryForDatasource(datasource, query)).orElseThrow(() -> new NotFoundException("No JDBC datasource exists with the given ID: " + idStr));
return Response.ok(result).build();
}, MetadataAccess.SERVICE);
}
Aggregations