use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class WebTokenList method updateMasterRefIfOptionsRefreshed.
/**
* Sets master-entity reference to the value and remove master-entity reference
* from options if they are not in nested container.
*
* @param value value items
*/
protected void updateMasterRefIfOptionsRefreshed(Collection<V> value) {
if (!isRefreshOptionsEnabled()) {
return;
}
if (!(getValueSource() instanceof ContainerValueSource)) {
return;
}
EntityOptions<V> options = (EntityOptions<V>) getOptions();
if (options == null) {
return;
}
ContainerValueSource valueSource = (ContainerValueSource) getValueSource();
MetaPropertyPath mpp = valueSource.getMetaPropertyPath();
MetaProperty inverseProperty = mpp.getMetaProperty().getInverse();
Object masterEntity = valueSource.getItem();
if (inverseProperty == null || masterEntity == null) {
return;
}
List<V> optionItems = getOptions().getOptions().collect(Collectors.toList());
for (V option : optionItems) {
// skip all options that did not load master-reference
if (!entityStates.isLoaded(option, inverseProperty.getName())) {
continue;
}
if (value.contains(option)) {
// reset master-entity reference
EntityValues.setValue(option, inverseProperty.getName(), masterEntity);
} else {
Entity ref = EntityValues.getValue(option, inverseProperty.getName());
if (ref == null) {
continue;
}
// remove ref to the master entity if option is not in value
if (Objects.equals(EntityValues.getId(ref), EntityValues.getId(masterEntity))) {
EntityValues.setValue(option, inverseProperty.getName(), null);
}
}
}
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class PivotScreenBuilder method removeNonExistingProperties.
protected List<String> removeNonExistingProperties(List<String> properties, MetaClass metaClass, FetchPlan fetchPlan) {
if (!metadataTools.isJpaEntity(metaClass)) {
return properties.stream().filter(s -> metaClass.getPropertyPath(s) != null).collect(Collectors.toList());
}
List<String> result = new ArrayList<>();
fetchPlan = fetchPlan == null ? getBaseFetchPlan(metaClass) : fetchPlan;
for (String property : properties) {
MetaPropertyPath mpp = metaClass.getPropertyPath(property);
if (mpp != null && metadataTools.fetchPlanContainsProperty(fetchPlan, mpp)) {
result.add(property);
// simple property
} else if (fetchPlan.containsProperty(property)) {
result.add(property);
// id property
} else if (isIdProperty(property, metaClass)) {
result.add(property);
// EmbeddedId's property
} else if (hasEmbeddedId(metaClass) && isEmbeddedIdProperty(property, metaClass)) {
result.add(property);
// if metaClass contains property path, we need to check nested entities in fetch plan
} else if (mpp != null) {
for (MetaProperty metaProperty : mpp.getMetaProperties()) {
MetaClass propertyMetaClass = getPropertyMetaClass(metaProperty);
if (propertyMetaClass == null) {
propertyMetaClass = metaClass;
}
// EmbeddedId's property
if (isEmbeddedIdProperty(property, propertyMetaClass)) {
result.add(property);
// Id property
} else if (isIdProperty(metaProperty.getName(), propertyMetaClass)) {
result.add(property);
}
}
}
}
return result;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class LookupBuilderProcessor method getFetchPlanForField.
/**
* The method evaluates the fetch plan that is used for the entity in the given {@code field}
* <p>
* If the value for a component (e.g. {@link EntityPicker}) is selected from lookup screen then there may be cases
* when in entities in lookup screen some attributes required in the editor are not loaded.
*
* @return a view or {@code null} if the fetch plan cannot be evaluated
*/
@Nullable
protected FetchPlan getFetchPlanForField(HasValue field) {
if (field instanceof HasValueSource) {
ValueSource valueSource = ((HasValueSource) field).getValueSource();
if (valueSource instanceof ContainerValueSource) {
ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
InstanceContainer container = containerValueSource.getContainer();
FetchPlan fetchPlan = container.getFetchPlan();
if (fetchPlan != null) {
MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
FetchPlan curFetchPlan = fetchPlan;
for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
FetchPlanProperty viewProperty = curFetchPlan.getProperty(metaProperty.getName());
if (viewProperty != null) {
curFetchPlan = viewProperty.getFetchPlan();
}
if (curFetchPlan == null)
break;
}
if (curFetchPlan != fetchPlan) {
return curFetchPlan;
}
}
}
}
return null;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class BaseContainerSorter method createComparator.
protected Comparator<?> createComparator(Sort sort, MetaClass metaClass) {
if (sort.getOrders().size() > 1) {
throw new UnsupportedOperationException("Sort by multiple properties is not supported");
}
MetaPropertyPath propertyPath = metaClass.getPropertyPath(sort.getOrders().get(0).getProperty());
if (propertyPath == null) {
throw new IllegalArgumentException("Property " + sort.getOrders().get(0).getProperty() + " is invalid");
}
boolean asc = sort.getOrders().get(0).getDirection() == Sort.Direction.ASC;
EntityValuesComparator<Object> comparator = new EntityValuesComparator<>(asc, metaClass, beanFactory);
return Comparator.comparing(e -> EntityValues.getValueEx(e, propertyPath), comparator);
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class GroupTableSettingsBinder method applyColumnSettings.
@Override
protected void applyColumnSettings(TableSettings tableSettings, Table table) {
super.applyColumnSettings(tableSettings, table);
GroupTableSettings groupTableSettings = (GroupTableSettings) tableSettings;
List<String> groupProperties = groupTableSettings.getGroupProperties();
if (groupProperties != null) {
MetaClass metaClass = ((EntityTableItems) table.getItems()).getEntityMetaClass();
List<MetaPropertyPath> properties = new ArrayList<>(groupProperties.size());
for (String id : groupProperties) {
MetaPropertyPath property = metadataTools.resolveMetaPropertyPathOrNull(metaClass, id);
if (property != null) {
properties.add(property);
} else {
log.warn("Ignored group property '{}'", id);
}
}
((GroupTable) table).groupBy(properties.toArray());
} else {
((GroupTable) table).ungroup();
}
}
Aggregations