use of com.thinkbiganalytics.policy.rest.model.FieldRulePropertyBuilder 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;
}
use of com.thinkbiganalytics.policy.rest.model.FieldRulePropertyBuilder 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;
}
Aggregations