protected boolean entityHasDynamicAttributes(Entity entity) { return entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null; }
protected boolean entityHasDynamicAttributes(Entity entity) { return entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null; }
private boolean entityHasDynamicAttributes(Entity entity) { return entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null; }
public static List<MetaProperty> getActualMetaProperties(MetaClass metaClass, Entity entity) { List<MetaProperty> result = new ArrayList<MetaProperty>(metaClass.getProperties()); if (entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null) { Collection<CategoryAttribute> dynamicAttributes = AppBeans.get(DynamicAttributes.NAME, DynamicAttributes.class).getAttributesForMetaClass(metaClass); for (CategoryAttribute dynamicAttribute : dynamicAttributes) { result.add(DynamicAttributesUtils.getMetaPropertyPath(metaClass, dynamicAttribute).getMetaProperty()); } } Collections.sort(result, PROPERTY_COMPARATOR); return result; }
@Override @SuppressWarnings("unchecked") public void setValue(String name, Object value) { mainItem.setValue(name, value); //if we set an attribute from another type of entity, we need to set reference to CategoryAttribute manually //this is workaround to make #PL-5770 logic works with modern RuntimePropertiesDatasource String attributeCode = DynamicAttributesUtils.decodeAttributeCode(name); Map<String, CategoryAttributeValue> dynamicAttributes = mainItem.getDynamicAttributes(); if (dynamicAttributes != null) { CategoryAttributeValue categoryAttributeValue = dynamicAttributes.get(attributeCode); if (categoryAttributeValue != null && categoryAttributeValue.getCategoryAttribute() == null) { categoryAttributeValue.setCategoryAttribute(attributesMap.get(attributeCode)); } } }
protected void fetchDynamicAttributes(Entity entity) { if (entity instanceof BaseGenericIdEntity) { LoadContext<BaseGenericIdEntity> loadContext = new LoadContext<>(entity.getMetaClass()); loadContext.setId(entity.getId()).setLoadDynamicAttributes(true); DataService dataService = AppBeans.get(DataService.NAME, DataService.class); BaseGenericIdEntity reloaded = dataService.load(loadContext); if (reloaded != null) { ((BaseGenericIdEntity) entity).setDynamicAttributes(reloaded.getDynamicAttributes()); } else { ((BaseGenericIdEntity) entity).setDynamicAttributes(new HashMap<>()); } } } }
public static void fetchDynamicAttributes(Entity entity){ if (entity instanceof BaseGenericIdEntity) { LoadContext<BaseGenericIdEntity> loadContext = new LoadContext<>(entity.getMetaClass()); loadContext.setId(entity.getId()).setLoadDynamicAttributes(true); DataService dataService = AppBeans.get(DataService.NAME, DataService.class); BaseGenericIdEntity reloaded = dataService.load(loadContext); if (reloaded != null) { ((BaseGenericIdEntity) entity).setDynamicAttributes(reloaded.getDynamicAttributes()); } else { ((BaseGenericIdEntity) entity).setDynamicAttributes(new HashMap<>()); } } } }
/** * Returns an entity reloaded with the view of the target datasource if it is wider than the set of attributes * that is loaded in the given entity instance. The entity is also reloaded if the target datasource requires * dynamic attributes and the entity instance does not contain them. */ public Entity reloadEntityIfNeeded(Entity entity, Datasource targetDatasource) { boolean needDynamicAttributes = false; boolean dynamicAttributesAreLoaded = true; if (entity instanceof BaseGenericIdEntity) { BaseGenericIdEntity e = (BaseGenericIdEntity) entity; dynamicAttributesAreLoaded = e.getDynamicAttributes() != null; needDynamicAttributes = targetDatasource.getLoadDynamicAttributes(); } View view = targetDatasource.getView(); if (view == null) { view = viewRepository.getView(entity.getClass(), View.LOCAL); } if (!entityStates.isLoadedWithView(entity, view)) { entity = targetDatasource.getDsContext().getDataSupplier().reload(entity, view, null, needDynamicAttributes); } else if (needDynamicAttributes && !dynamicAttributesAreLoaded) { dynamicAttributesGuiTools.reloadDynamicAttributes((BaseGenericIdEntity) entity); } return entity; }
protected void writeFields(Entity entity, JsonObject jsonObject, @Nullable View view, Set<Entity> cyclicReferences) { Collection<MetaProperty> properties = new ArrayList<>(entity.getMetaClass().getProperties()); if (entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null) { List<MetaProperty> dynamicProperties = dynamicAttributes.getAttributesForMetaClass(entity.getMetaClass()).stream() .map(categoryAttribute -> DynamicAttributesUtils.getMetaPropertyPath(entity.getMetaClass(), categoryAttribute).getMetaProperty())
if (entity instanceof BaseGenericIdEntity && DynamicAttributesUtils.isDynamicAttribute(propertyName) && ((BaseGenericIdEntity) entity).getDynamicAttributes() == null) { fetchDynamicAttributes(entity);
@SuppressWarnings("unchecked") Map<String, CategoryAttributeValue> entityDynamicAttributes = ((BaseGenericIdEntity) entity).getDynamicAttributes();
&& ((BaseGenericIdEntity) entity).getDynamicAttributes() == null) { ConverterHelper.fetchDynamicAttributes(entity);
if (PersistenceHelper.isNew(baseGenericIdEntity) && baseGenericIdEntity.getDynamicAttributes() == null) { baseGenericIdEntity.setDynamicAttributes(new HashMap<>()); Map<String, CategoryAttributeValue> dynamicAttributes = baseGenericIdEntity.getDynamicAttributes(); checkNotNullArgument(dynamicAttributes, "Dynamic attributes should be loaded explicitly");
((BaseGenericIdEntity) dest).setDynamicAttributes(((BaseGenericIdEntity<?>) source).getDynamicAttributes());
Collection<CategoryAttribute> attributes = dynamicAttributes.getAttributesForMetaClass(metaClass); if (item.getDynamicAttributes() == null) { item.setDynamicAttributes(new HashMap<>());
@SuppressWarnings("unchecked") protected void doStoreDynamicAttributes(BaseGenericIdEntity entity) { final EntityManager em = persistence.getEntityManager(); Map<String, CategoryAttributeValue> dynamicAttributes = entity.getDynamicAttributes(); if (dynamicAttributes != null) { Map<String, CategoryAttributeValue> mergedDynamicAttributes = new HashMap<>();
@SuppressWarnings("unchecked") private void addDynamicAttributeChanges(@Nullable Entity entity, Set<AttributeChanges.Change> changes, boolean deleted) { if (entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null) { Map<String, CategoryAttributeValue> dynamicAttributes = ((BaseGenericIdEntity) entity).getDynamicAttributes(); for (CategoryAttributeValue cav : dynamicAttributes.values()) { if (BaseEntityInternalAccess.isNew(cav)) {
((BaseGenericIdEntity) destination).setDynamicAttributes(((BaseGenericIdEntity<?>) source).getDynamicAttributes());
/** * Reload dynamic attributes on the entity */ @SuppressWarnings("unchecked") public void reloadDynamicAttributes(BaseGenericIdEntity entity) { MetaClass metaClass = entity.getMetaClass(); View view = new View(metaClass.getJavaClass(), false) .addProperty(metadata.getTools().getPrimaryKeyName(metaClass)); LoadContext loadContext = new LoadContext(metaClass) .setView(view) .setLoadDynamicAttributes(true) .setId(entity.getId()); BaseGenericIdEntity reloadedEntity = (BaseGenericIdEntity) dataManager.load(loadContext); if (reloadedEntity != null) { entity.setDynamicAttributes(reloadedEntity.getDynamicAttributes()); } } }
destGenericEntity.setDynamicAttributes(sourceGenericEntity.getDynamicAttributes());