use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes in project cuba by cuba-platform.
the class ConverterHelper method getActualMetaProperties.
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;
}
use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes in project cuba by cuba-platform.
the class DynamicAttributesConditionFrame method fillCategorySelect.
protected void fillCategorySelect() {
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
MetaClass metaClass = condition.getEntityMetaClass();
if (!Strings.isNullOrEmpty(condition.getPropertyPath())) {
MetaPropertyPath propertyPath = metaClass.getPropertyPath(condition.getPropertyPath());
if (propertyPath == null) {
throw new RuntimeException("Property path " + condition.getPropertyPath() + " doesn't exist");
}
metaClass = propertyPath.getRange().asClass();
}
Collection<Category> categories = dynamicAttributes.getCategoriesForMetaClass(metaClass);
UUID catId = condition.getCategoryId();
Category selectedCategory = null;
Map<String, Category> categoriesMap = new TreeMap<>();
if (categories.size() == 1 && (catId == null || Objects.equals(catId, categories.iterator().next().getId()))) {
Category category = categories.iterator().next();
categoryLookup.setVisible(false);
categoryLabel.setVisible(false);
attributeLookup.focus();
categoriesMap.put(category.getName(), category);
categoryLookup.setOptionsMap(categoriesMap);
categoryLookup.setValue(category);
fillAttributeSelect(category);
} else {
categoryLookup.setVisible(true);
categoryLabel.setVisible(true);
for (Category category : categories) {
categoriesMap.put(category.getName(), category);
if (category.getId().equals(catId)) {
selectedCategory = category;
}
}
categoryLookup.setOptionsMap(categoriesMap);
categoryLookup.setValue(selectedCategory);
}
}
use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes in project cuba by cuba-platform.
the class DynamicAttributesGuiTools method collectEntityClassesWithDynamicAttributes.
protected Set<Class> collectEntityClassesWithDynamicAttributes(@Nullable View view) {
if (view == null) {
return Collections.emptySet();
}
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.class);
Metadata metadata = AppBeans.get(Metadata.class);
return collectEntityClasses(view, new HashSet<>()).stream().filter(BaseGenericIdEntity.class::isAssignableFrom).filter(aClass -> !dynamicAttributes.getAttributesForMetaClass(metadata.getClassNN(aClass)).isEmpty()).collect(Collectors.toSet());
}
use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes in project cuba by cuba-platform.
the class BaseGenericIdEntityTest method setUp.
@BeforeEach
public void setUp() throws Exception {
dynamicAttributes = new DynamicAttributes() {
@Override
public Collection<Category> getCategoriesForMetaClass(MetaClass metaClass) {
return null;
}
@Override
public Collection<CategoryAttribute> getAttributesForMetaClass(MetaClass metaClass) {
return null;
}
@Nullable
@Override
public CategoryAttribute getAttributeForMetaClass(MetaClass metaClass, String code) {
CategoryAttribute categoryAttribute = new CategoryAttribute();
categoryAttribute.setCode(code);
return categoryAttribute;
}
};
metadata = new Metadata() {
@Override
public Session getSession() {
return new SessionImpl() {
@Override
public MetaClass getClassNN(String name) {
return new MetaClassImpl(new MetaModelImpl(this, name), name);
}
@Override
public MetaClass getClassNN(Class clazz) {
return new MetaClassImpl(new MetaModelImpl(this, clazz.getName()), clazz.getName());
}
};
}
@Override
public ViewRepository getViewRepository() {
return null;
}
@Override
public ExtendedEntities getExtendedEntities() {
return null;
}
@Override
public MetadataTools getTools() {
return null;
}
@Override
public DatatypeRegistry getDatatypes() {
return null;
}
@Override
public <T extends Entity> T create(Class<T> entityClass) {
if (User.class.equals(entityClass)) {
return (T) new User();
}
if (CategoryAttributeValue.class.equals(entityClass)) {
CategoryAttributeValue attributeValue = new CategoryAttributeValue();
attributeValue.setEntity(new ReferenceToEntity());
return (T) attributeValue;
}
throw new IllegalArgumentException("Add support for " + entityClass.getSimpleName() + " to Mock");
}
@Override
public Entity create(MetaClass metaClass) {
return null;
}
@Override
public Entity create(String entityName) {
return null;
}
@Override
public List<String> getRootPackages() {
return null;
}
@Override
public MetaModel getModel(String name) {
return null;
}
@Override
public Collection<MetaModel> getModels() {
return null;
}
@Nullable
@Override
public MetaClass getClass(String name) {
return null;
}
@Override
public MetaClass getClassNN(String name) {
return null;
}
@Nullable
@Override
public MetaClass getClass(Class<?> clazz) {
return null;
}
@Override
public MetaClass getClassNN(Class<?> clazz) {
return null;
}
@Override
public Collection<MetaClass> getClasses() {
return null;
}
};
new Expectations() {
{
AppBeans.get(DynamicAttributes.NAME);
result = dynamicAttributes;
minTimes = 0;
AppBeans.get(Metadata.NAME);
result = metadata;
minTimes = 0;
AppBeans.get(ReferenceToEntitySupport.class);
result = referenceToEntitySupport;
minTimes = 0;
}
};
}
use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes in project cuba by cuba-platform.
the class RuntimePropsDatasourceImpl method getDefaultCategory.
@Nullable
public Category getDefaultCategory() {
MetaClass metaClass = resolveCategorizedEntityClass();
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.class);
Collection<Category> categoriesForMetaClass = dynamicAttributes.getCategoriesForMetaClass(metaClass);
for (Category category : categoriesForMetaClass) {
if (Boolean.TRUE.equals(category.getIsDefault())) {
return category;
}
}
return null;
}
Aggregations