use of javax.ws.rs.PathParam in project kylo by Teradata.
the class FeedCategoryRestController method getAllowedPermissionsChange.
@GET
@Path("{categoryId}/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 category exists with the specified ID.", response = RestResponseStatus.class) })
public Response getAllowedPermissionsChange(@PathParam("categoryId") String categoryIdStr, @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.createCategoryPermissionChange(categoryIdStr, ChangeType.valueOf(changeType.toUpperCase()), Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(p -> Response.ok(p).build()).orElseThrow(() -> new WebApplicationException("A category with the given ID does not exist: " + categoryIdStr, Status.NOT_FOUND));
}
use of javax.ws.rs.PathParam in project kylo by Teradata.
the class FeedRestController method profileSummary.
@GET
@Path("/{feedId}/profile-summary")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets a summary of the feed profiles.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the profile summaries.", response = Map.class, responseContainer = "List"), @ApiResponse(code = 500, message = "The profiles are unavailable.", response = RestResponseStatus.class) })
public Response profileSummary(@PathParam("feedId") String feedId, @QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize) {
if (page == null || page <= 0) {
page = 1;
}
if (pageSize == null || pageSize <= 0) {
pageSize = 10;
}
FeedMetadata feedMetadata = getMetadataService().getFeedById(feedId);
String profileTableName = feedMetadata.getProfileTableName();
QueryResult tablePartitions = hiveService.getTablePartitions(profileTableName);
List<Map<String, Object>> partitions = tablePartitions.getRows();
Stream<Long> sortedPartitions = partitions.stream().map(row -> Long.parseLong(row.get("partition").toString().substring("processing_dttm=".length()))).sorted(Comparator.reverseOrder());
long totalPartitions = partitions.size();
List<String> partitionsPage = sortedPartitions.skip((page - 1) * pageSize).limit(pageSize).map(partition -> "'" + Long.toString(partition) + "'").collect(Collectors.toList());
final String profileTable = HiveUtils.quoteIdentifier(profileTableName);
String query = "SELECT * from " + profileTable + " where columnname = '(ALL)' and processing_dttm in (" + StringUtils.join(partitionsPage, ',') + ")";
List<Map<String, Object>> rows = new ArrayList<>();
try {
QueryResult results = hiveService.query(query);
rows.addAll(results.getRows());
// add in the archive date time fields if applicipable
String ARCHIVE_PROCESSOR_TYPE = "com.thinkbiganalytics.nifi.GetTableData";
if (feedMetadata.getInputProcessorType().equalsIgnoreCase(ARCHIVE_PROCESSOR_TYPE)) {
NifiProperty property = NifiPropertyUtil.findPropertyByProcessorType(feedMetadata.getProperties(), ARCHIVE_PROCESSOR_TYPE, "Date Field");
if (property != null && property.getValue() != null) {
String field = property.getValue();
if (field.contains(".")) {
field = StringUtils.substringAfterLast(field, ".");
}
query = "SELECT * from " + profileTable + " where metrictype IN('MIN_TIMESTAMP','MAX_TIMESTAMP') AND columnname = " + HiveUtils.quoteString(field);
QueryResult dateRows = hiveService.query(query);
if (dateRows != null && !dateRows.isEmpty()) {
rows.addAll(dateRows.getRows());
}
}
}
} catch (DataAccessException e) {
if (e.getCause() instanceof org.apache.hive.service.cli.HiveSQLException && e.getCause().getMessage().contains("Table not found")) {
// this exception is ok to swallow since it just means no profile data exists yet
} else if (e.getCause().getMessage().contains("HiveAccessControlException Permission denied")) {
throw new AccessControlException("You do not have permission to execute this hive query");
} else {
throw e;
}
}
PageImpl<Map<String, Object>> response = new PageImpl<>(rows, null, totalPartitions);
return Response.ok(response).build();
}
use of javax.ws.rs.PathParam 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 javax.ws.rs.PathParam 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 javax.ws.rs.PathParam 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();
}
Aggregations