use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityImportExport method importOneToManyCollectionAttribute.
protected void importOneToManyCollectionAttribute(Entity srcEntity, Entity dstEntity, SecurityState srcSecurityState, EntityImportViewProperty viewProperty, View regularView, CommitContext commitContext, Collection<ReferenceInfo> referenceInfoList) {
Collection<Entity> collectionValue = srcEntity.getValue(viewProperty.getName());
Collection<Entity> prevCollectionValue = dstEntity.getValue(viewProperty.getName());
MetaProperty metaProperty = srcEntity.getMetaClass().getPropertyNN(viewProperty.getName());
MetaProperty inverseMetaProperty = metaProperty.getInverse();
Collection dstFilteredIds = getFilteredIds(dstEntity, metaProperty.getName());
Collection srcFilteredIds = getFilteredIds(srcSecurityState, metaProperty.getName());
Collection<Entity> newCollectionValue = createNewCollection(metaProperty);
CollectionCompare.with().onCreate(e -> {
if (!dstFilteredIds.contains(referenceToEntitySupport.getReferenceId(e))) {
Entity result = importEntity(e, null, viewProperty.getView(), regularView, commitContext, referenceInfoList);
if (inverseMetaProperty != null) {
result.setValue(inverseMetaProperty.getName(), dstEntity);
}
newCollectionValue.add(result);
}
}).onUpdate((src, dst) -> {
if (!dstFilteredIds.contains(referenceToEntitySupport.getReferenceId(src))) {
Entity result = importEntity(src, dst, viewProperty.getView(), regularView, commitContext, referenceInfoList);
if (inverseMetaProperty != null) {
result.setValue(inverseMetaProperty.getName(), dstEntity);
}
newCollectionValue.add(result);
}
}).onDelete(e -> {
Object refId = referenceToEntitySupport.getReferenceId(e);
if (viewProperty.getCollectionImportPolicy() == CollectionImportPolicy.REMOVE_ABSENT_ITEMS) {
if (!dstFilteredIds.contains(refId) && !srcFilteredIds.contains(refId)) {
commitContext.addInstanceToRemove(e);
}
}
if (srcFilteredIds.contains(refId)) {
newCollectionValue.add(e);
}
}).compare(collectionValue, prevCollectionValue);
dstEntity.setValue(metaProperty.getName(), newCollectionValue);
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityImportExport method buildViewFromImportView.
/**
* Method builds a regular {@link View} from the {@link EntityImportView}. The regular view will include all
* properties defined in the import view.
*/
protected View buildViewFromImportView(EntityImportView importView) {
View regularView = new View(importView.getEntityClass());
MetaClass metaClass = metadata.getClassNN(importView.getEntityClass());
for (EntityImportViewProperty importViewProperty : importView.getProperties()) {
EntityImportView importViewPropertyView = importViewProperty.getView();
if (importViewPropertyView == null) {
MetaProperty metaProperty = metaClass.getPropertyNN(importViewProperty.getName());
if (metaProperty.getRange().isClass()) {
MetaClass propertyMetaClass = metaProperty.getRange().asClass();
regularView.addProperty(importViewProperty.getName(), viewRepository.getView(propertyMetaClass, View.MINIMAL));
} else {
regularView.addProperty(importViewProperty.getName());
}
} else {
regularView.addProperty(importViewProperty.getName(), buildViewFromImportView(importViewPropertyView));
}
}
return regularView;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityImportExport method importEmbeddedAttribute.
protected Entity importEmbeddedAttribute(Entity srcEntity, Entity dstEntity, boolean createOp, EntityImportViewProperty importViewProperty, View regularView, CommitContext commitContext, Collection<ReferenceInfo> referenceInfoList) {
String propertyName = importViewProperty.getName();
MetaProperty metaProperty = srcEntity.getMetaClass().getPropertyNN(propertyName);
Entity srcEmbeddedEntity = srcEntity.getValue(propertyName);
if (srcEmbeddedEntity == null) {
return null;
}
Entity dstEmbeddedEntity = dstEntity.getValue(propertyName);
MetaClass embeddedAttrMetaClass = metaProperty.getRange().asClass();
if (dstEmbeddedEntity == null) {
dstEmbeddedEntity = metadata.create(embeddedAttrMetaClass);
}
SecurityState dstSecurityState = null;
SecurityState srcSecurityState = null;
if (dstEntity instanceof BaseGenericIdEntity && !createOp) {
String storeName = metadata.getTools().getStoreName(dstEntity.getMetaClass());
DataStore dataStore = storeFactory.get(storeName);
// row-level security works only for entities from RdbmsStore
if (dataStore instanceof RdbmsStore) {
if (useSecurityToken()) {
persistenceSecurity.assertTokenForREST(srcEmbeddedEntity, regularView);
persistenceSecurity.restoreSecurityState(srcEmbeddedEntity);
srcSecurityState = BaseEntityInternalAccess.getSecurityState(srcEmbeddedEntity);
}
persistenceSecurity.restoreSecurityState(dstEmbeddedEntity);
dstSecurityState = BaseEntityInternalAccess.getSecurityState(dstEmbeddedEntity);
}
}
for (EntityImportViewProperty vp : importViewProperty.getView().getProperties()) {
MetaProperty mp = embeddedAttrMetaClass.getPropertyNN(vp.getName());
if (BaseEntityInternalAccess.isHiddenOrReadOnly(dstSecurityState, mp.getName())) {
continue;
}
if (BaseEntityInternalAccess.isRequired(dstSecurityState, mp.getName()) && srcEmbeddedEntity.getValue(mp.getName()) == null) {
throw new CustomValidationException(format("Attribute [%s] is required for entity %s", mp.getName(), srcEmbeddedEntity));
}
if ((mp.getRange().isDatatype() && !"version".equals(mp.getName())) || mp.getRange().isEnum()) {
dstEmbeddedEntity.setValue(vp.getName(), srcEmbeddedEntity.getValue(vp.getName()));
} else if (mp.getRange().isClass()) {
View propertyRegularView = regularView.getProperty(propertyName) != null ? regularView.getProperty(propertyName).getView() : null;
if (metaProperty.getRange().getCardinality() == Range.Cardinality.ONE_TO_MANY) {
importOneToManyCollectionAttribute(srcEmbeddedEntity, dstEmbeddedEntity, srcSecurityState, vp, propertyRegularView, commitContext, referenceInfoList);
} else if (metaProperty.getRange().getCardinality() == Range.Cardinality.MANY_TO_MANY) {
importManyToManyCollectionAttribute(srcEmbeddedEntity, dstEmbeddedEntity, srcSecurityState, vp, propertyRegularView, commitContext, referenceInfoList);
} else {
importReference(srcEmbeddedEntity, dstEmbeddedEntity, vp, propertyRegularView, commitContext, referenceInfoList);
}
}
}
return dstEmbeddedEntity;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class WebAbstractField method initRequired.
protected void initRequired(MetaPropertyPath metaPropertyPath) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
boolean newRequired = metaProperty.isMandatory();
Object notNullUiComponent = metaProperty.getAnnotations().get(NotNull.class.getName() + "_notnull_ui_component");
if (Boolean.TRUE.equals(notNullUiComponent)) {
newRequired = true;
}
setRequired(newRequired);
if (StringUtils.isEmpty(getRequiredMessage())) {
MessageTools messageTools = AppBeans.get(MessageTools.NAME);
setRequiredMessage(messageTools.getDefaultRequiredMessage(metaPropertyPath.getMetaClass(), metaPropertyPath.toString()));
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class WebAbstractTable method addColumn.
@Override
public void addColumn(Table.Column column) {
checkNotNullArgument(column, "Column must be non null");
Object columnId = column.getId();
component.addContainerProperty(columnId, column.getType(), null);
if (StringUtils.isNotBlank(column.getDescription())) {
component.setColumnDescription(columnId, column.getDescription());
}
if (StringUtils.isNotBlank(column.getValueDescription())) {
component.setAggregationDescription(columnId, column.getValueDescription());
} else if (column.getAggregation() != null && column.getAggregation().getType() != AggregationInfo.Type.CUSTOM) {
Messages messages = AppBeans.get(Messages.NAME);
String aggregationTypeLabel;
switch(column.getAggregation().getType()) {
case AVG:
aggregationTypeLabel = "aggreagtion.avg";
break;
case COUNT:
aggregationTypeLabel = "aggreagtion.count";
break;
case SUM:
aggregationTypeLabel = "aggreagtion.sum";
break;
case MIN:
aggregationTypeLabel = "aggreagtion.min";
break;
case MAX:
aggregationTypeLabel = "aggreagtion.max";
break;
default:
throw new IllegalArgumentException(String.format("AggregationType %s is not supported", column.getAggregation().getType().toString()));
}
component.setAggregationDescription(columnId, messages.getMainMessage(aggregationTypeLabel));
}
if (!column.isSortable()) {
component.setColumnSortable(columnId, column.isSortable());
}
columns.put(columnId, column);
columnsOrder.add(column);
if (column.getWidth() != null) {
component.setColumnWidth(columnId, column.getWidth());
}
if (column.getAlignment() != null) {
component.setColumnAlignment(columnId, WebComponentsHelper.convertColumnAlignment(column.getAlignment()));
}
final String caption = getColumnCaption(columnId, column);
setColumnHeader(columnId, caption);
column.setOwner(this);
if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
final Formatter collectionFormatter = new CollectionFormatter();
column.setFormatter(collectionFormatter);
}
}
if (columnId instanceof MetaPropertyPath) {
PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
MetaPropertyPath propertyPath = (MetaPropertyPath) columnId;
MetaProperty metaProperty = propertyPath.getMetaProperty();
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
String storeName = metadataTools.getStoreName(propertyMetaClass);
if (metadataTools.isLob(metaProperty) && !persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
component.setColumnSortable(columnId, false);
}
}
}
Aggregations