/** * Creates ListEditor component. * * @param valueSource value source * @param categoryAttribute category attribute * @return list editor component or null */ @Nullable public Component generateComponent(ValueSource valueSource, CategoryAttribute categoryAttribute) { ListEditor listEditor = uiComponents.create(ListEditor.NAME); listEditor.setEntityJoinClause(categoryAttribute.getJoinClause()); listEditor.setEntityWhereClause(categoryAttribute.getWhereClause()); ListEditor.ItemType itemType = getListEditorItemType(categoryAttribute.getDataType()); listEditor.setItemType(itemType); if (!Strings.isNullOrEmpty(categoryAttribute.getEntityClass())) { Class<?> clazz = scripting.loadClass(categoryAttribute.getEntityClass()); if (clazz == null) { log.error("Unable to find class of entity {} for dynamic attribute {}", categoryAttribute.getEntityClass(), categoryAttribute.getCode()); return null; } MetaClass metaClass = metadata.getClassNN(clazz); listEditor.setEntityName(metaClass.getName()); listEditor.setUseLookupField(BooleanUtils.isTrue(categoryAttribute.getLookup())); } //noinspection unchecked listEditor.setValueSource(valueSource); return listEditor; }
protected void fillAttributeCode() { CategoryAttribute attribute = getItem(); if (StringUtils.isBlank(attribute.getCode()) && StringUtils.isNotBlank(attribute.getName())) { String categoryName = StringUtils.EMPTY; if (attribute.getCategory() != null) { categoryName = StringUtils.defaultString(attribute.getCategory().getName()); } attribute.setCode(StringUtils.deleteWhitespace(categoryName + attribute.getName())); } }
/** * For collection dynamic attributes the method returns a list of formatted collection items joined with the comma, * for non-collection dynamic attribute a formatted value is returned */ @SuppressWarnings("unchecked") public String getDynamicAttributeValueAsString(MetaProperty metaProperty, Object value) { CategoryAttribute categoryAttribute = getCategoryAttribute(metaProperty); if (categoryAttribute.getIsCollection()) { if (value instanceof Collection) { List<String> valuesList = ((Collection<Object>) value).stream() .map(item -> metadataTools.format(item, metaProperty)) .collect(Collectors.toList()); return Joiner.on(", ").join(valuesList); } } return metadataTools.format(value, metaProperty); } }
protected void setCategoryEntityType(CategoryAttribute entity) { if (entity.getCategory() != null) { entity.setCategoryEntityType(entity.getCategory().getEntityType()); } } }
/** * Resolve attribute value's Java class */ public static Class getAttributeClass(CategoryAttribute attribute) { PropertyType propertyType = attribute.getDataType(); switch (propertyType) { case STRING: return String.class; case INTEGER: return Integer.class; case DOUBLE: return Double.class; case BOOLEAN: return Boolean.class; case DATE: return Date.class; case ENUMERATION: return String.class; case ENTITY: return attribute.getJavaClassForEntity(); } return String.class; }
DynamicAttributesUtils.encodeAttributeCode(attribute.getCode())); field.setProperty(DynamicAttributesUtils.encodeAttributeCode(attribute.getCode())); field.setCaption(attribute.getLocaleName()); field.setDatasource(ds); field.setRequired(attribute.getRequired()); field.setRequiredMessage(getMessages().formatMainMessage( "validation.required.defaultMsg", attribute.getLocaleName())); loadWidth(field, attribute.getWidth()); if (BooleanUtils.isTrue(attribute.getIsCollection())) { CustomFieldGenerator fieldGenerator = new DynamicAttributeCustomFieldGenerator(); Component fieldComponent = fieldGenerator.generateField(ds, DynamicAttributesUtils.encodeAttributeCode(attribute.getCode())); field.setCustom(true); field.setComponent(fieldComponent);
String code = DynamicAttributesUtils.encodeAttributeCode(categoryAttribute.getCode()); if (entityIsCategorized && !categoryAttribute.getCategory().equals(((Categorized) item).getCategory())) { if (categoryAttribute.getDefaultValue() != null) { if (BooleanUtils.isTrue(categoryAttribute.getIsEntity())) { MetaClass entityMetaClass = metadata.getClassNN(categoryAttribute.getJavaClassForEntity()); LoadContext<Entity> lc = new LoadContext<>(entityMetaClass).setView(View.MINIMAL); String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(entityMetaClass); lc.setQueryString(format("select e from %s e where e.%s = :entityId", entityMetaClass.getName(), pkName)) .setParameter("entityId", categoryAttribute.getDefaultValue()); Entity defaultEntity = dataManager.load(lc); item.setValue(code, defaultEntity); } else if (Boolean.TRUE.equals(categoryAttribute.getIsCollection())) { List<Object> list = new ArrayList<>(); list.add(categoryAttribute.getDefaultValue()); item.setValue(code, list); } else { item.setValue(code, categoryAttribute.getDefaultValue()); } else if (Boolean.TRUE.equals(categoryAttribute.getDefaultDateIsCurrent())) { item.setValue(code, currentTimestamp);
column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName())); if (attribute.getDataType().equals(PropertyType.STRING)) { ClientConfig clientConfig = getConfiguration().getConfig(ClientConfig.class); column.setMaxTextLength(clientConfig.getDynamicAttributesTableColumnMaxTextLength()); if (attribute.getDataType().equals(PropertyType.ENUMERATION)) { column.setFormatter(value -> LocaleHelper.getEnumLocalizedValue((String) value, attribute.getEnumerationLocales()) );
protected String getColumnCaption(Object columnId, Column column) { String caption = column.getCaption(); if (caption != null) { return caption; } if (!(columnId instanceof MetaPropertyPath)) { return StringUtils.capitalize(getColumnCaption(columnId)); } MetaPropertyPath mpp = (MetaPropertyPath) columnId; MetaProperty metaProperty = mpp.getMetaProperty(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) { return categoryAttribute.getLocaleName(); } caption = StringUtils.capitalize(categoryAttribute.getName()); } else { caption = StringUtils.capitalize(getColumnCaption(columnId)); } return caption; }
Collection<String> componentIds = FIELDS_VISIBLE_FOR_DATATYPES.get(attribute.getDataType()); if (componentIds != null) { for (String componentId : componentIds) { if (attribute.getDataType() == PropertyType.ENTITY) { if (StringUtils.isNotBlank(attribute.getEntityClass())) { defaultEntityField.setEditable(true); whereField.setEnabled(true); joinField.setEnabled(true); Class entityClass = attribute.getJavaClassForEntity(); MetaClass metaClass = metadata.getClass(entityClass); defaultEntityField.setMetaClass(metaClass); if (Boolean.TRUE.equals(attribute.getLookup())) { attributeFieldGroup.setVisible("screen", false); } else { if (attribute.getDataType() == PropertyType.DATE) { if (Boolean.TRUE.equals(attribute.getDefaultDateIsCurrent())) { attributeFieldGroup.setVisible("defaultDate", false); attributeFieldGroup.setFieldValue("defaultDate", null); if (attribute.getDataType() == PropertyType.BOOLEAN || attribute.getDataType() == PropertyType.ENUMERATION) { attributeFieldGroup.setFieldValue("isCollection", null);
@SuppressWarnings("unchecked") @Override protected void valueBindingConnected(ValueSource<V> valueSource) { super.valueBindingConnected(valueSource); if (valueSource instanceof EntityValueSource) { MetaPropertyPath propertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath(); MetaProperty metaProperty = propertyPath.getMetaProperty(); if (metaProperty.getRange().isEnum()) { //noinspection unchecked setOptions(new EnumOptions(metaProperty.getJavaType())); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsMap((Map<String, V>) categoryAttribute.getLocalizedEnumerationMap()); } } } }
.filter(cav -> cav.getCategoryAttribute().getIsCollection()) .collect(Collectors.toList()); .filter(cav -> cav.getCategoryAttribute().getDataType() == PropertyType.ENTITY && cav.getChildValues() != null) .forEach(cav -> cavsOfEntityType.addAll(cav.getChildValues()));
public Boolean getIsEntity() { return getDataType() == PropertyType.ENTITY; }
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(property); if (categoryAttribute.getDataType().equals(PropertyType.ENUMERATION)) { return LocaleHelper.getEnumLocalizedValue((String) value, categoryAttribute.getEnumerationLocales()); if (categoryAttribute.getIsCollection() && value instanceof Collection) { return dynamicAttributesTools.getDynamicAttributeValueAsString(property, value);
attribute = getItem(); Set<String> targetScreens = attribute.targetScreensSet(); for (String targetScreen : targetScreens) { if (targetScreen.contains("#")) { MetaClass categorizedEntityMetaClass = metadata.getClass(attribute.getCategory().getEntityType()); Map<String, String> optionsMap = categorizedEntityMetaClass != null ? new HashMap<>(screensHelper.getAvailableScreens(categorizedEntityMetaClass.getJavaClass())) : String enumeration = attribute.getEnumeration(); if (!Strings.isNullOrEmpty(enumeration)) { Iterable<String> items = Splitter.on(",").omitEmptyStrings().split(enumeration); localizedFrame.setValue(attribute.getLocaleNames());
propertyPath + ".id and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))"; } else { String valueFieldName = "stringValue"; if (!attribute.getIsCollection()) { condition.setJoin(", sys$CategoryAttributeValue " + cavAlias + " "); operation + (op.isUnary() ? " " : paramStr) + "and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'"; where = where.replace("?", ":" + paramName); } else { " where " + cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + "." + valueFieldName + " = :" + paramName + " and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))"; .setInExpr(condition.getInExpr()) .setRequired(condition.getRequired()) .setCategoryAttrId(attribute.getId()) .build(); condition.setCategoryAttributeId(attributeLookup.getValue().getId()); condition.setIsCollection(BooleanUtils.isTrue(attributeLookup.getValue().getIsCollection())); condition.setLocCaption(attribute.getLocaleName()); condition.setCaption(caption.getValue());
public void openConstraintWizard() { Class entityClass = attribute.getJavaClassForEntity(); FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(attribute.getFilterXml()); ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity); new com.haulmont.cuba.core.global.filter.FilterParser(element); String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot()); attribute.setWhereClause(jpql); Set<String> joins = filterParser.getRoot().getJoins(); if (!joins.isEmpty()) { String joinsStr = new TextStringBuilder().appendWithSeparators(joins, " ").toString(); attribute.setJoinClause(joinsStr); attribute.setFilterXml(filterEntity.getXml());
@Override public void postValidate(ValidationErrors errors) { @SuppressWarnings("unchecked") CollectionDatasource<CategoryAttribute, UUID> parent = (CollectionDatasource<CategoryAttribute, UUID>) ((DatasourceImplementation) attributeDs).getParent(); if (parent != null) { CategoryAttribute categoryAttribute = getItem(); for (UUID id : parent.getItemIds()) { CategoryAttribute ca = parent.getItemNN(id); if (ca.getName().equals(categoryAttribute.getName()) && (!ca.equals(categoryAttribute))) { errors.add(getMessage("uniqueName")); return; } else if (ca.getCode() != null && ca.getCode().equals(categoryAttribute.getCode()) && (!ca.equals(categoryAttribute))) { errors.add(getMessage("uniqueCode")); return; } } } }
if (attribute != null && metaClass.getJavaClass().getName().equals(attribute.getEntityClass())) { entityType = metaClass; Entity entity = e.getValue(); if (entity != null) { attribute.setObjectDefaultEntityId(referenceToEntitySupport.getReferenceId(entity)); } else { attribute.setObjectDefaultEntityId(null); enumerationListEditor.addValueChangeListener(e -> { List<?> list = e.getValue() != null ? e.getValue() : Collections.emptyList(); attribute.setEnumeration(Joiner.on(",").join(list)); }); enumerationListEditor.setEditorWindowId("localizedEnumerationWindow"); enumerationListEditor.setEditorParamsSupplier(() -> ParamsMap.of("enumerationLocales", attribute.getEnumerationLocales())); enumerationListEditor.addEditorCloseListener(closeEvent -> { if (closeEvent.getActionId().equals(COMMIT_ACTION_ID)) { LocalizedEnumerationWindow enumerationWindow = (LocalizedEnumerationWindow) closeEvent.getWindow(); attribute.setEnumerationLocales(enumerationWindow.getLocalizedValues());
Class javaClass = categoryAttribute.getJavaClassForEntity(); if (javaClass == null) { throw new IllegalArgumentException("Entity type is not specified in category attribute"); if (!Strings.isNullOrEmpty(categoryAttribute.getJoinClause()) || !Strings.isNullOrEmpty(categoryAttribute.getWhereClause())) { lookupAction = createLookupAction(pickerField, categoryAttribute.getJoinClause(), categoryAttribute.getWhereClause()); pickerField.addAction(lookupAction); String screen = categoryAttribute.getScreen(); if (StringUtils.isNotBlank(screen)) { lookupAction.setLookupScreen(screen);