Search in sources :

Example 1 with AnnotatedFieldProperty

use of com.thinkbiganalytics.annotations.AnnotatedFieldProperty in project kylo by Teradata.

the class BasePolicyAnnotationTransformer method getUiProperties.

/**
 * For a given domain policy class extract the user interface {@link FieldRuleProperty} classes parsing the fields annotated with the {@link PolicyProperty}
 *
 * @param policyClass the domain policy class to parse
 * @return a list of user interface fields annotated with the {@link PolicyProperty}
 */
public List<FieldRuleProperty> getUiProperties(Class<P> policyClass) {
    AnnotationFieldNameResolver annotationFieldNameResolver = new AnnotationFieldNameResolver(PolicyProperty.class);
    List<AnnotatedFieldProperty> list = annotationFieldNameResolver.getProperties(policyClass);
    List<FieldRuleProperty> properties = new ArrayList<>();
    Map<String, List<FieldRuleProperty>> groupedProperties = new HashMap<>();
    if (hasConstructor(policyClass)) {
        Map<String, Integer> groupOrder = new HashMap<>();
        for (AnnotatedFieldProperty<PolicyProperty> annotatedFieldProperty : list) {
            PolicyProperty prop = annotatedFieldProperty.getAnnotation();
            String value = StringUtils.isBlank(prop.value()) ? null : prop.value();
            String group = prop.group();
            Integer order = 0;
            if (!groupOrder.containsKey(group)) {
                groupOrder.put(group, order);
            }
            order = groupOrder.get(group);
            order++;
            groupOrder.put(group, order);
            FieldRuleProperty rule = new FieldRulePropertyBuilder(prop.name()).displayName(StringUtils.isNotBlank(prop.displayName()) ? prop.displayName() : prop.name()).hint(prop.hint()).type(PolicyPropertyTypes.PROPERTY_TYPE.valueOf(prop.type().name())).objectProperty(annotatedFieldProperty.getName()).placeholder(prop.placeholder()).value(value).required(prop.required()).group(group).groupOrder(order).hidden(prop.hidden()).pattern(prop.pattern()).patternInvalidMessage(prop.patternInvalidMessage()).addSelectableValues(convertToLabelValue(prop.selectableValues())).addSelectableValues(convertToLabelValue(prop.labelValues())).build();
            properties.add(rule);
            if (!group.equals("")) {
                if (!groupedProperties.containsKey(group)) {
                    groupedProperties.put(group, new ArrayList<FieldRuleProperty>());
                }
                groupedProperties.get(group).add(rule);
            }
        }
        // update layout property
        for (Collection<FieldRuleProperty> groupProps : groupedProperties.values()) {
            for (FieldRuleProperty property : groupProps) {
                property.setLayout("row");
            }
        }
    }
    return properties;
}
Also used : HashMap(java.util.HashMap) FieldRulePropertyBuilder(com.thinkbiganalytics.policy.rest.model.FieldRulePropertyBuilder) ArrayList(java.util.ArrayList) AnnotationFieldNameResolver(com.thinkbiganalytics.annotations.AnnotationFieldNameResolver) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) AnnotatedFieldProperty(com.thinkbiganalytics.annotations.AnnotatedFieldProperty) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with AnnotatedFieldProperty

use of com.thinkbiganalytics.annotations.AnnotatedFieldProperty in project kylo by Teradata.

the class BasePolicyAnnotationTransformer method getUiProperties.

/**
 * For a given domain policy class extract the user interface {@link FieldRuleProperty} classes parsing the fields annotated with the {@link PolicyProperty}
 *
 * @param policy the domain policy object to parse
 * @return a list of user interface fields annotated with the {@link PolicyProperty}
 */
private List<FieldRuleProperty> getUiProperties(P policy) {
    AnnotationFieldNameResolver annotationFieldNameResolver = new AnnotationFieldNameResolver(PolicyProperty.class);
    List<AnnotatedFieldProperty> list = annotationFieldNameResolver.getProperties(policy.getClass());
    List<FieldRuleProperty> properties = new ArrayList<>();
    Map<String, Integer> groupOrder = new HashMap<>();
    Map<String, List<FieldRuleProperty>> groupedProperties = new HashMap<>();
    if (hasConstructor(policy.getClass())) {
        for (AnnotatedFieldProperty<PolicyProperty> annotatedFieldProperty : list) {
            PolicyProperty prop = annotatedFieldProperty.getAnnotation();
            String value = null;
            try {
                Object fieldValue = FieldUtils.readField(annotatedFieldProperty.getField(), policy, true);
                if (fieldValue != null) {
                    value = fieldValue.toString();
                }
            } catch (IllegalAccessException e) {
            }
            String group = prop.group();
            Integer order = 0;
            if (!groupOrder.containsKey(group)) {
                groupOrder.put(group, order);
            }
            order = groupOrder.get(group);
            order++;
            groupOrder.put(group, order);
            FieldRuleProperty rule = new FieldRulePropertyBuilder(prop.name()).displayName(StringUtils.isNotBlank(prop.displayName()) ? prop.displayName() : prop.name()).hint(prop.hint()).type(PolicyPropertyTypes.PROPERTY_TYPE.valueOf(prop.type().name())).objectProperty(annotatedFieldProperty.getName()).placeholder(prop.placeholder()).value(value).required(prop.required()).group(group).groupOrder(order).pattern(prop.pattern()).patternInvalidMessage(prop.patternInvalidMessage()).hidden(prop.hidden()).addSelectableValues(convertToLabelValue(prop.selectableValues())).addSelectableValues(convertToLabelValue(prop.labelValues())).build();
            properties.add(rule);
            if (!group.equals("")) {
                if (!groupedProperties.containsKey(group)) {
                    groupedProperties.put(group, new ArrayList<FieldRuleProperty>());
                }
                groupedProperties.get(group).add(rule);
            }
        }
        // update layout property
        for (Collection<FieldRuleProperty> groupProps : groupedProperties.values()) {
            for (FieldRuleProperty property : groupProps) {
                property.setLayout("row");
            }
        }
    }
    return properties;
}
Also used : HashMap(java.util.HashMap) FieldRulePropertyBuilder(com.thinkbiganalytics.policy.rest.model.FieldRulePropertyBuilder) ArrayList(java.util.ArrayList) AnnotationFieldNameResolver(com.thinkbiganalytics.annotations.AnnotationFieldNameResolver) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) AnnotatedFieldProperty(com.thinkbiganalytics.annotations.AnnotatedFieldProperty) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with AnnotatedFieldProperty

use of com.thinkbiganalytics.annotations.AnnotatedFieldProperty in project kylo by Teradata.

the class AnnotatedFieldPropertyListDeserializer method deserialize.

@Override
public List<AnnotatedFieldProperty> deserialize(JsonParser jsonParser, DeserializationContext arg1) throws IOException, JsonProcessingException {
    List<AnnotatedFieldProperty> list = new ArrayList<>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    if (node.isArray()) {
        for (JsonNode node1 : node) {
            String name = findStringValue(node1, "name", "");
            String description = findStringValue(node1, "description", "");
            AnnotatedFieldProperty annotatedFieldProperty = new AnnotatedFieldProperty();
            annotatedFieldProperty.setName(name);
            annotatedFieldProperty.setDescription(description);
            list.add(annotatedFieldProperty);
        }
    }
    return list;
}
Also used : AnnotatedFieldProperty(com.thinkbiganalytics.annotations.AnnotatedFieldProperty) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec)

Example 4 with AnnotatedFieldProperty

use of com.thinkbiganalytics.annotations.AnnotatedFieldProperty in project kylo by Teradata.

the class FeedRestController method updateFeedMetadata.

private void updateFeedMetadata(FeedMetadata targetFeedMetadata, FeedMetadata modifiedFeedMetadata, FeedPropertySection feedPropertySection) {
    AnnotationFieldNameResolver annotationFieldNameResolver = new AnnotationFieldNameResolver(FeedPropertyType.class);
    List<AnnotatedFieldProperty> list = annotationFieldNameResolver.getProperties(FeedMetadata.class);
    List<AnnotatedFieldProperty> sectionList = list.stream().filter(annotatedFieldProperty -> feedPropertySection.equals(((FeedPropertyType) annotatedFieldProperty.getAnnotation()).section())).collect(Collectors.toList());
    sectionList.forEach(annotatedFieldProperty -> {
        try {
            Object value = FieldUtils.readField(annotatedFieldProperty.getField(), modifiedFeedMetadata);
            FieldUtils.writeField(annotatedFieldProperty.getField(), targetFeedMetadata, value);
        } catch (IllegalAccessException e) {
            log.warn("Unable to update FeedMetadata field: {}.  Exception: {} ", annotatedFieldProperty.getField(), e.getMessage(), e);
        }
    });
}
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) 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) VersionNotFoundException(com.thinkbiganalytics.metadata.modeshape.versioning.VersionNotFoundException) 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) 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) 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) 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) PreconditionRule(com.thinkbiganalytics.policy.rest.model.PreconditionRule) DataAccessException(org.springframework.dao.DataAccessException) PathParam(javax.ws.rs.PathParam) 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) DatasourceService(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService) 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) QueryResult(com.thinkbiganalytics.discovery.schema.QueryResult) InputStream(java.io.InputStream) AnnotatedFieldProperty(com.thinkbiganalytics.annotations.AnnotatedFieldProperty) AnnotationFieldNameResolver(com.thinkbiganalytics.annotations.AnnotationFieldNameResolver)

Aggregations

AnnotatedFieldProperty (com.thinkbiganalytics.annotations.AnnotatedFieldProperty)4 ArrayList (java.util.ArrayList)4 AnnotationFieldNameResolver (com.thinkbiganalytics.annotations.AnnotationFieldNameResolver)3 List (java.util.List)3 FieldRuleProperty (com.thinkbiganalytics.policy.rest.model.FieldRuleProperty)2 FieldRulePropertyBuilder (com.thinkbiganalytics.policy.rest.model.FieldRulePropertyBuilder)2 HashMap (java.util.HashMap)2 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Lists (com.google.common.collect.Lists)1 Generex (com.mifmif.common.regex.Generex)1 QueryResult (com.thinkbiganalytics.discovery.schema.QueryResult)1 PropertyExpressionResolver (com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver)1 EditFeedEntity (com.thinkbiganalytics.feedmgr.rest.model.EditFeedEntity)1 EntityVersionDifference (com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference)1 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)1 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)1 FeedVersions (com.thinkbiganalytics.feedmgr.rest.model.FeedVersions)1 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)1 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)1