Search in sources :

Example 1 with FieldRuleProperty

use of com.thinkbiganalytics.policy.rest.model.FieldRuleProperty in project kylo by Teradata.

the class BasePolicyAnnotationTransformer method fromUiModel.

/**
 * Trasform a user interface object back to the domain policy class
 *
 * @param rule the ui object
 * @return the domain policy transformed
 */
@Override
public P fromUiModel(U rule) throws PolicyTransformException {
    try {
        P domainPolicy = createClass(rule);
        if (hasConstructor(domainPolicy.getClass())) {
            for (FieldRuleProperty property : rule.getProperties()) {
                String field = property.getObjectProperty();
                String value = property.getStringValue();
                Field f = FieldUtils.getField(domainPolicy.getClass(), field, true);
                Object objectValue = convertStringToObject(value, f.getType());
                f.set(domainPolicy, objectValue);
            }
        }
        afterFromUiModel(domainPolicy, rule);
        return domainPolicy;
    } catch (Exception e) {
        throw new PolicyTransformException(e);
    }
}
Also used : Field(java.lang.reflect.Field) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with FieldRuleProperty

use of com.thinkbiganalytics.policy.rest.model.FieldRuleProperty 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())).addAdditionalProperties(convertToLabelValue(prop.additionalProperties())).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 FieldRuleProperty

use of com.thinkbiganalytics.policy.rest.model.FieldRuleProperty in project kylo by Teradata.

the class BasePolicyAnnotationTransformer method getPropertyValue.

private Object getPropertyValue(BaseUiPolicyRule rule, Class<P> domainPolicyClass, PolicyPropertyRef reference) {
    for (FieldRuleProperty property : rule.getProperties()) {
        String name = property.getName();
        if (name.equalsIgnoreCase(reference.name())) {
            String field = property.getObjectProperty();
            String value = property.getStringValue();
            Field f = FieldUtils.getField(domainPolicyClass, field, true);
            Object objectValue = convertStringToObject(value, f.getType());
            return objectValue;
        }
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty)

Example 4 with FieldRuleProperty

use of com.thinkbiganalytics.policy.rest.model.FieldRuleProperty 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())).addAdditionalProperties(convertToLabelValue(prop.additionalProperties())).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 5 with FieldRuleProperty

use of com.thinkbiganalytics.policy.rest.model.FieldRuleProperty in project kylo by Teradata.

the class DefaultFeedManagerFeedService method applyFeedSelectOptions.

@Override
public /**
 * Applies new LableValue array to the FieldProperty.selectableValues {label = Category.Display Feed Name, value=category.system_feed_name}
 */
void applyFeedSelectOptions(List<FieldRuleProperty> properties) {
    if (properties != null && !properties.isEmpty()) {
        List<FeedSummary> feedSummaries = getFeedSummaryData();
        List<LabelValue> feedSelection = new ArrayList<>();
        for (FeedSummary feedSummary : feedSummaries) {
            boolean isDisabled = feedSummary.getState() == Feed.State.DISABLED.name();
            boolean canEditDetails = accessController.isEntityAccessControlled() ? feedSummary.hasAction(FeedAccessControl.EDIT_DETAILS.getSystemName()) : accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_FEEDS);
            Map<String, Object> labelValueProperties = new HashMap<>();
            labelValueProperties.put("feed:disabled", isDisabled);
            labelValueProperties.put("feed:editDetails", canEditDetails);
            feedSelection.add(new LabelValue(feedSummary.getCategoryAndFeedDisplayName() + (isDisabled ? " (DISABLED) " : ""), feedSummary.getCategoryAndFeedSystemName(), isDisabled ? "This feed is currently disabled" : "", labelValueProperties));
        }
        feedSelection.sort(Comparator.comparing(LabelValue::getLabel, String.CASE_INSENSITIVE_ORDER));
        for (FieldRuleProperty property : properties) {
            property.setSelectableValues(feedSelection);
            if (property.getValues() == null) {
                // reset the intial values to be an empty arraylist
                property.setValues(new ArrayList<>());
            }
        }
    }
}
Also used : LabelValue(com.thinkbiganalytics.rest.model.LabelValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)

Aggregations

FieldRuleProperty (com.thinkbiganalytics.policy.rest.model.FieldRuleProperty)14 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)3 AnnotatedFieldProperty (com.thinkbiganalytics.annotations.AnnotatedFieldProperty)2 AnnotationFieldNameResolver (com.thinkbiganalytics.annotations.AnnotationFieldNameResolver)2 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)2 FieldRulePropertyBuilder (com.thinkbiganalytics.policy.rest.model.FieldRulePropertyBuilder)2 FieldValidationRule (com.thinkbiganalytics.policy.rest.model.FieldValidationRule)2 LabelValue (com.thinkbiganalytics.rest.model.LabelValue)2 Field (java.lang.reflect.Field)2 List (java.util.List)2 SchemaParserDescriptor (com.thinkbiganalytics.discovery.model.SchemaParserDescriptor)1 ServiceLevelAgreementActionConfig (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfig)1 ServiceLevelAgreementMetric (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementMetric)1 FieldStandardizationRule (com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule)1 FieldStandardizationRuleBuilder (com.thinkbiganalytics.policy.rest.model.FieldStandardizationRuleBuilder)1 FieldValidationRuleBuilder (com.thinkbiganalytics.policy.rest.model.FieldValidationRuleBuilder)1 Standardizer (com.thinkbiganalytics.policy.standardization.Standardizer)1 Validator (com.thinkbiganalytics.policy.validation.Validator)1 Annotation (java.lang.annotation.Annotation)1