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;
}
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;
}
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;
}
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);
}
});
}
Aggregations