use of com.haulmont.chile.core.model.MetadataObject in project cuba by cuba-platform.
the class ComponentsHelper method handleFilteredAttributes.
/**
* Set field's "required" flag to false if the value has been filtered by Row Level Security
* This is necessary to allow user to submit form with filtered attribute even if attribute is required
*/
public static void handleFilteredAttributes(Field component, Datasource datasource, MetaPropertyPath mpp) {
if (component.isRequired() && datasource.getState() == Datasource.State.VALID && datasource.getItem() != null && mpp.getMetaProperty().getRange().isClass()) {
Entity targetItem = datasource.getItem();
MetaProperty[] propertiesChain = mpp.getMetaProperties();
if (propertiesChain.length > 1) {
String basePropertyItem = Arrays.stream(propertiesChain).limit(propertiesChain.length - 1).map(MetadataObject::getName).collect(Collectors.joining("."));
targetItem = datasource.getItem().getValueEx(basePropertyItem);
}
if (targetItem instanceof BaseGenericIdEntity) {
String metaPropertyName = mpp.getMetaProperty().getName();
Object value = targetItem.getValue(metaPropertyName);
BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) targetItem;
String[] filteredAttributes = getFilteredAttributes(baseGenericIdEntity);
if (value == null && filteredAttributes != null && ArrayUtils.contains(filteredAttributes, metaPropertyName)) {
component.setRequired(false);
}
}
}
}
Aggregations