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