use of com.haulmont.cuba.core.entity.EmbeddableEntity in project cuba by cuba-platform.
the class EntityFetcher method fetch.
@SuppressWarnings("unchecked")
protected void fetch(Entity entity, View view, Map<Instance, Set<View>> visited, boolean optimizeForDetached) {
Set<View> views = visited.get(entity);
if (views == null) {
views = new HashSet<>();
visited.put(entity, views);
} else if (views.contains(view)) {
return;
}
views.add(view);
if (log.isTraceEnabled())
log.trace("Fetching instance " + entity);
MetaClass metaClass = metadata.getClassNN(entity.getClass());
for (ViewProperty property : view.getProperties()) {
MetaProperty metaProperty = metaClass.getPropertyNN(property.getName());
if (!metaProperty.getRange().isClass() && !metadata.getTools().isLazyFetchedLocalAttribute(metaProperty) || metadata.getTools().isNotPersistent(metaClass, metaProperty))
continue;
if (log.isTraceEnabled())
log.trace("Fetching property " + property.getName());
Object value = entity.getValue(property.getName());
View propertyView = property.getView();
if (value != null && propertyView != null) {
if (value instanceof Collection) {
for (Object item : new ArrayList(((Collection) value))) {
if (item instanceof Entity) {
Entity e = (Entity) item;
if (entityStates.isDetached(e)) {
fetchReloaded(e, propertyView, visited, optimizeForDetached, managed -> {
if (value instanceof List) {
List list = (List) value;
list.set(list.indexOf(e), managed);
} else {
Collection collection = (Collection) value;
collection.remove(e);
collection.add(managed);
}
});
} else {
fetch((Entity) item, propertyView, visited, optimizeForDetached);
}
}
}
} else if (value instanceof Entity) {
Entity e = (Entity) value;
if (!metaProperty.isReadOnly() && entityStates.isDetached(e) && !(e instanceof EmbeddableEntity)) {
fetchReloaded(e, propertyView, visited, optimizeForDetached, managed -> {
entity.setValue(property.getName(), managed);
});
} else {
fetch(e, propertyView, visited, optimizeForDetached);
}
}
}
}
}
use of com.haulmont.cuba.core.entity.EmbeddableEntity in project cuba by cuba-platform.
the class AttributeAccessSupportTest method getEmbeddableEntitySecurityStateTest.
@Test
public void getEmbeddableEntitySecurityStateTest() {
EmbeddableEntity entity = new TestEmbeddableEntity();
SecurityState securityState = BaseEntityInternalAccess.getOrCreateSecurityState(entity);
BaseEntityInternalAccess.setSecurityState(entity, securityState);
AttributeAccessSupport attributeAccessSupport = new AttributeAccessSupport();
Assertions.assertNotNull(attributeAccessSupport.getSecurityState(entity), "com.haulmont.cuba.gui.AttributeAccessSupport#getSecurityState returns null");
}
Aggregations