Search in sources :

Example 6 with StringUtils.substringAfterLast

use of org.apache.commons.lang3.StringUtils.substringAfterLast in project cas by apereo.

the class ConfigurationMetadataGenerator method removeNestedConfigurationPropertyGroups.

private static void removeNestedConfigurationPropertyGroups(final Set<ConfigurationMetadataProperty> properties, final Set<ConfigurationMetadataProperty> groups) {
    var it = properties.iterator();
    while (it.hasNext()) {
        var entry = it.next();
        try {
            val propName = StringUtils.substringAfterLast(entry.getName(), ".");
            val groupName = StringUtils.substringBeforeLast(entry.getName(), ".");
            val res = groups.stream().filter(g -> g.getName().equalsIgnoreCase(groupName)).findFirst();
            if (res.isPresent()) {
                var grp = res.get();
                val className = grp.getType();
                val clazz = ClassUtils.getClass(className);
                val names = RelaxedPropertyNames.forCamelCase(propName);
                names.getValues().forEach(Unchecked.consumer(name -> {
                    val f = ReflectionUtils.findField(clazz, name);
                    if (f != null && f.isAnnotationPresent(NestedConfigurationProperty.class)) {
                        it.remove();
                    }
                }));
            }
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : lombok.val(lombok.val) RequiresModule(org.apereo.cas.configuration.support.RequiresModule) NestedConfigurationProperty(org.springframework.boot.context.properties.NestedConfigurationProperty) Arrays(java.util.Arrays) MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DurationCapable(org.apereo.cas.configuration.support.DurationCapable) StringUtils(org.apache.commons.lang3.StringUtils) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) LiteralStringValueExpr(com.github.javaparser.ast.expr.LiteralStringValueExpr) HashSet(java.util.HashSet) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) ClassUtils(org.apache.commons.lang3.ClassUtils) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LinkedHashSet(java.util.LinkedHashSet) ValueHint(org.springframework.boot.configurationmetadata.ValueHint) Unchecked(org.jooq.lambda.Unchecked) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) Deprecation(org.springframework.boot.configurationmetadata.Deprecation) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) Set(java.util.Set) RequiredProperty(org.apereo.cas.configuration.support.RequiredProperty) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) ExpressionLanguageCapable(org.apereo.cas.configuration.support.ExpressionLanguageCapable) StaticJavaParser(com.github.javaparser.StaticJavaParser) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ReflectionUtils(org.springframework.util.ReflectionUtils) PropertyOwner(org.apereo.cas.configuration.support.PropertyOwner) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) Pattern(java.util.regex.Pattern) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) RelaxedPropertyNames(org.apereo.cas.configuration.support.RelaxedPropertyNames)

Example 7 with StringUtils.substringAfterLast

use of org.apache.commons.lang3.StringUtils.substringAfterLast 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)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)7 List (java.util.List)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 Map (java.util.Map)5 File (java.io.File)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 MinimalPrettyPrinter (com.fasterxml.jackson.core.util.MinimalPrettyPrinter)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)2 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 StaticJavaParser (com.github.javaparser.StaticJavaParser)2 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)2 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)2