Search in sources :

Example 81 with PathParam

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));
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) ChangeType(com.thinkbiganalytics.security.rest.model.PermissionsChange.ChangeType) DELETE(javax.ws.rs.DELETE) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) PermissionsChange(com.thinkbiganalytics.security.rest.model.PermissionsChange) Collection(java.util.Collection) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) List(java.util.List) RoleMembership(com.thinkbiganalytics.security.rest.model.RoleMembership) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) InvalidOperationException(com.thinkbiganalytics.feedmgr.InvalidOperationException) PathParam(javax.ws.rs.PathParam) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) GET(javax.ws.rs.GET) ApiResponses(io.swagger.annotations.ApiResponses) UserProperty(com.thinkbiganalytics.feedmgr.rest.model.UserProperty) UUID(com.thinkbiganalytics.rest.model.beanvalidation.UUID) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) Inject(javax.inject.Inject) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) Nonnull(javax.annotation.Nonnull) Status(javax.ws.rs.core.Response.Status) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) NewFeedCategory(com.thinkbiganalytics.feedmgr.rest.beanvalidation.NewFeedCategory) Component(org.springframework.stereotype.Component) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 82 with PathParam

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();
}
Also used : Arrays(java.util.Arrays) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Produces(javax.ws.rs.Produces) DatasourceDefinitions(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinitions) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) StringUtils(org.apache.commons.lang3.StringUtils) FeedModelTransform(com.thinkbiganalytics.feedmgr.service.feed.FeedModelTransform) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) MediaType(javax.ws.rs.core.MediaType) HiveService(com.thinkbiganalytics.hive.service.HiveService) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiFeed(com.thinkbiganalytics.feedmgr.rest.model.NifiFeed) Sort(org.springframework.data.domain.Sort) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) FeedCleanupTimeoutException(com.thinkbiganalytics.feedmgr.service.FeedCleanupTimeoutException) EnumSet(java.util.EnumSet) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) PermissionsChange(com.thinkbiganalytics.security.rest.model.PermissionsChange) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) FeedCleanupFailedException(com.thinkbiganalytics.feedmgr.service.FeedCleanupFailedException) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) MetadataAccessControl(com.thinkbiganalytics.metadata.api.security.MetadataAccessControl) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) Page(org.springframework.data.domain.Page) EntityVersionDifference(com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference) FeedPropertyType(com.thinkbiganalytics.metadata.FeedPropertyType) Stream(java.util.stream.Stream) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) BodyPartEntity(org.glassfish.jersey.media.multipart.BodyPartEntity) AccessDeniedException(java.nio.file.AccessDeniedException) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) GET(javax.ws.rs.GET) FeedPropertySection(com.thinkbiganalytics.metadata.FeedPropertySection) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) HiveUtils(com.thinkbiganalytics.hive.util.HiveUtils) AnnotationFieldNameResolver(com.thinkbiganalytics.annotations.AnnotationFieldNameResolver) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) ResourceBundle(java.util.ResourceBundle) DeployFeedException(com.thinkbiganalytics.feedmgr.service.feed.DeployFeedException) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) Api(io.swagger.annotations.Api) DuplicateFeedNameException(com.thinkbiganalytics.feedmgr.service.feed.DuplicateFeedNameException) Files(java.nio.file.Files) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) IOException(java.io.IOException) Pair(com.thinkbiganalytics.search.rest.model.Pair) SearchResult(com.thinkbiganalytics.rest.model.search.SearchResult) FeedCurrentlyRunningException(com.thinkbiganalytics.feedmgr.service.feed.reindexing.FeedCurrentlyRunningException) File(java.io.File) Paths(java.nio.file.Paths) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) Strings(org.apache.directory.api.util.Strings) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ClientErrorException(javax.ws.rs.ClientErrorException) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) JDBCException(org.hibernate.JDBCException) BodyPart(org.glassfish.jersey.media.multipart.BodyPart) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) DefaultValue(javax.ws.rs.DefaultValue) ChangeType(com.thinkbiganalytics.security.rest.model.PermissionsChange.ChangeType) DELETE(javax.ws.rs.DELETE) FeedVersions(com.thinkbiganalytics.feedmgr.rest.model.FeedVersions) DeployResponseEntityVersion(com.thinkbiganalytics.feedmgr.rest.model.DeployResponseEntityVersion) FeedHistoryDataReindexingNotEnabledException(com.thinkbiganalytics.feedmgr.service.feed.reindexing.FeedHistoryDataReindexingNotEnabledException) Collection(java.util.Collection) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) EditFeedEntity(com.thinkbiganalytics.feedmgr.rest.model.EditFeedEntity) NotFoundException(javax.ws.rs.NotFoundException) AnnotatedFieldProperty(com.thinkbiganalytics.annotations.AnnotatedFieldProperty) EntityVersion(com.thinkbiganalytics.feedmgr.rest.model.EntityVersion) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) List(java.util.List) Generex(com.mifmif.common.regex.Generex) Principal(java.security.Principal) Response(javax.ws.rs.core.Response) AccessControlException(java.security.AccessControlException) PageImpl(org.springframework.data.domain.PageImpl) PreconditionRule(com.thinkbiganalytics.policy.rest.model.PreconditionRule) DataAccessException(org.springframework.dao.DataAccessException) PathParam(javax.ws.rs.PathParam) VersionNotFoundException(com.thinkbiganalytics.metadata.api.versioning.VersionNotFoundException) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed) FeedManagerPreconditionService(com.thinkbiganalytics.feedmgr.service.feed.FeedManagerPreconditionService) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) ServiceLevelAgreementService(com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementService) Tag(io.swagger.annotations.Tag) Nonnull(javax.annotation.Nonnull) Status(javax.ws.rs.core.Response.Status) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) FormParam(javax.ws.rs.FormParam) DatasourceService(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService) NifiConnectionException(com.thinkbiganalytics.nifi.rest.client.NifiConnectionException) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) FeedLineageStyle(com.thinkbiganalytics.metadata.rest.model.feed.FeedLineageStyle) FeedServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement) Component(org.springframework.stereotype.Component) Comparator(java.util.Comparator) QueryResult(com.thinkbiganalytics.discovery.schema.QueryResult) InputStream(java.io.InputStream) PageImpl(org.springframework.data.domain.PageImpl) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) ArrayList(java.util.ArrayList) AccessControlException(java.security.AccessControlException) QueryResult(com.thinkbiganalytics.discovery.schema.QueryResult) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Map(java.util.Map) DataAccessException(org.springframework.dao.DataAccessException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 83 with PathParam

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));
}
Also used : Arrays(java.util.Arrays) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) StringUtils(org.apache.commons.lang3.StringUtils) ApiOperation(io.swagger.annotations.ApiOperation) NiFiTemplateFlowResponse(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowResponse) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) AboutDTO(org.apache.nifi.web.api.dto.AboutDTO) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) DefaultValue(javax.ws.rs.DefaultValue) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) ChangeType(com.thinkbiganalytics.security.rest.model.PermissionsChange.ChangeType) FeedManagerTemplateService(com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService) DELETE(javax.ws.rs.DELETE) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) PermissionsChange(com.thinkbiganalytics.security.rest.model.PermissionsChange) ImmutableMap(com.google.common.collect.ImmutableMap) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Predicate(com.google.common.base.Predicate) TemplateOrder(com.thinkbiganalytics.feedmgr.rest.model.TemplateOrder) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) NiFiTemplateFlowRequest(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowRequest) Iterables(com.google.common.collect.Iterables) PathParam(javax.ws.rs.PathParam) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Status(javax.ws.rs.core.Response.Status) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) DatasourceService(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) TemplateDtoWrapper(com.thinkbiganalytics.feedmgr.rest.model.TemplateDtoWrapper) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) Cache(com.google.common.cache.Cache) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 84 with PathParam

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));
}
Also used : Arrays(java.util.Arrays) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) StringUtils(org.apache.commons.lang3.StringUtils) ApiOperation(io.swagger.annotations.ApiOperation) NiFiTemplateFlowResponse(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowResponse) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) AboutDTO(org.apache.nifi.web.api.dto.AboutDTO) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) DefaultValue(javax.ws.rs.DefaultValue) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) ChangeType(com.thinkbiganalytics.security.rest.model.PermissionsChange.ChangeType) FeedManagerTemplateService(com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService) DELETE(javax.ws.rs.DELETE) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) PermissionsChange(com.thinkbiganalytics.security.rest.model.PermissionsChange) ImmutableMap(com.google.common.collect.ImmutableMap) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Predicate(com.google.common.base.Predicate) TemplateOrder(com.thinkbiganalytics.feedmgr.rest.model.TemplateOrder) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) NiFiTemplateFlowRequest(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowRequest) Iterables(com.google.common.collect.Iterables) PathParam(javax.ws.rs.PathParam) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Status(javax.ws.rs.core.Response.Status) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) DatasourceService(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) TemplateDtoWrapper(com.thinkbiganalytics.feedmgr.rest.model.TemplateDtoWrapper) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) Cache(com.google.common.cache.Cache) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 85 with PathParam

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();
}
Also used : Arrays(java.util.Arrays) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) StringUtils(org.apache.commons.lang3.StringUtils) ApiOperation(io.swagger.annotations.ApiOperation) NiFiTemplateFlowResponse(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowResponse) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) AboutDTO(org.apache.nifi.web.api.dto.AboutDTO) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) DefaultValue(javax.ws.rs.DefaultValue) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) ChangeType(com.thinkbiganalytics.security.rest.model.PermissionsChange.ChangeType) FeedManagerTemplateService(com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService) DELETE(javax.ws.rs.DELETE) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) PermissionsChange(com.thinkbiganalytics.security.rest.model.PermissionsChange) ImmutableMap(com.google.common.collect.ImmutableMap) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Predicate(com.google.common.base.Predicate) TemplateOrder(com.thinkbiganalytics.feedmgr.rest.model.TemplateOrder) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) NiFiTemplateFlowRequest(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowRequest) Iterables(com.google.common.collect.Iterables) PathParam(javax.ws.rs.PathParam) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Status(javax.ws.rs.core.Response.Status) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) DatasourceService(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) TemplateDtoWrapper(com.thinkbiganalytics.feedmgr.rest.model.TemplateDtoWrapper) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) Cache(com.google.common.cache.Cache) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) NiFiTemplateFlowResponse(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowResponse) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) 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)

Aggregations

PathParam (javax.ws.rs.PathParam)127 Path (javax.ws.rs.Path)105 GET (javax.ws.rs.GET)96 Produces (javax.ws.rs.Produces)96 Response (javax.ws.rs.core.Response)93 QueryParam (javax.ws.rs.QueryParam)82 List (java.util.List)72 MediaType (javax.ws.rs.core.MediaType)72 POST (javax.ws.rs.POST)71 DELETE (javax.ws.rs.DELETE)70 Consumes (javax.ws.rs.Consumes)66 Inject (javax.inject.Inject)62 Api (io.swagger.annotations.Api)60 ApiOperation (io.swagger.annotations.ApiOperation)59 Map (java.util.Map)59 ApiResponse (io.swagger.annotations.ApiResponse)58 ApiResponses (io.swagger.annotations.ApiResponses)57 Collectors (java.util.stream.Collectors)57 Logger (org.slf4j.Logger)52 LoggerFactory (org.slf4j.LoggerFactory)52