public FieldRulePropertyBuilder(String name) { this.name = name; this.displayName = name; this.type = PolicyPropertyTypes.PROPERTY_TYPE.string.name(); this.placeholder = ""; this.hint = ""; }
/** * Find all the user interface properies for a given render type */ public List<FieldRuleProperty> findPropertiesMatchingRenderType(List<FieldRuleProperty> properties, final String type) { if (StringUtils.isNotBlank(type)) { return findPropertiesMatchingRenderTypes(properties, new String[]{type}); } return null; }
/** * Transform a domain policy rule to a user interface object * * @param policyRule the domain object * @return the user interface object */ @Override public U toUIModel(P policyRule) { Annotation annotation = policyRule.getClass().getAnnotation(getAnnotationClass()); List<FieldRuleProperty> properties = getUiProperties(policyRule); U rule = buildUiModel((A) annotation, policyRule, properties); return rule; }
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)) { 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("")) {
@JsonIgnore public void buildValueDisplayString() { StringBuffer sb = null; if (getProperties() != null) { for (FieldRuleProperty property : getProperties()) { if (!PolicyPropertyTypes.PROPERTY_TYPE.currentFeed.name().equalsIgnoreCase(property.getType())) { //get the values String value = property.getStringValue(); if (sb == null) { sb = new StringBuffer(); } else { sb.append(";"); } sb.append(property.getName() + ": " + value); } } } if (sb != null) { setPropertyValuesDisplayString(sb.toString()); } }
/** * 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); } }
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; }
public List<FieldRuleProperty> findPropertiesForRulesMatchingDefaultValue(List<? extends BaseUiPolicyRule> rules, final String value) { List<FieldRuleProperty> properties = new ArrayList<>(); for (BaseUiPolicyRule rule : rules) { properties.addAll(rule.getProperties()); } return findPropertiesMatchingDefaultValue(properties, value); }
public List<FieldRuleProperty> findPropertiesForRulesetMatchingRenderType(List<? extends BaseUiPolicyRule> rules, final String type) { List<FieldRuleProperty> properties = new ArrayList<>(); for (BaseUiPolicyRule rule : rules) { properties.addAll(rule.getProperties()); } return findPropertiesMatchingRenderType(properties, type); }
public List<FieldRuleProperty> findPropertiesForRulesetMatchingRenderTypes(List<? extends BaseUiPolicyRule> rules, final String[] types) { List<FieldRuleProperty> properties = new ArrayList<>(); for (BaseUiPolicyRule rule : rules) { properties.addAll(rule.getProperties()); } return findPropertiesMatchingRenderTypes(properties, types); }
IllegalAccessException { P domainPolicy = null; String classType = rule.getObjectClassType(); Class<P> domainPolicyClass = (Class<P>) Class.forName(classType); paramValue = getPropertyValue(rule, domainPolicyClass, (PolicyPropertyRef) a);
private List<LabelValue> convertToLabelValue(PropertyLabelValue[] propertyLabelValues) { List<LabelValue> labelValues = null; if (propertyLabelValues != null) { for (PropertyLabelValue propertyLabelValue : propertyLabelValues) { if (labelValues == null) { labelValues = new ArrayList<>(); } LabelValue labelValue = convertToLabelValue((propertyLabelValue)); if (labelValue != null) { labelValues.add(labelValue); } } } return labelValues; }
public void loadRegistry() { Set<Class<?>> classes = ReflectionPolicyAnnotationDiscoverer.getTypesAnnotatedWith(ClassNameChange.class); if (classes != null && !classes.isEmpty()) { for (Class clazz : classes) { ClassNameChange classNameChange = (ClassNameChange) clazz.getAnnotation(ClassNameChange.class); for (String oldClassName : classNameChange.classNames()) { classRegistry.put(oldClassName, clazz); } } } }
Map<String, Integer> groupOrder = new HashMap<>(); Map<String, List<FieldRuleProperty>> groupedProperties = new HashMap<>(); if (hasConstructor(policy.getClass())) { String group = prop.group(); Integer order = 0; if (!groupOrder.containsKey(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("")) { property.setLayout("row");
public FieldRulePropertyBuilder type(PolicyPropertyTypes.PROPERTY_TYPE type) { this.type = type.name(); return this; }
public List<FieldRuleProperty> findPropertiesMatchingDefaultValue(List<FieldRuleProperty> properties, final String value) { if (StringUtils.isNotBlank(value)) { return findPropertiesMatchingRenderTypes(properties, new String[]{value}); } return null; }