use of org.kie.workbench.common.forms.model.impl.meta.entries.FieldPlaceHolderEntry in project kie-wb-common by kiegroup.
the class DMOModelResolver method resolveModelForType.
private static DataObjectFormModel resolveModelForType(final ModuleDataModelOracle oracle, final String modelType, final Predicate<TypeSource> sourcePredicate) {
PortablePreconditions.checkNotNull("oracle", oracle);
PortablePreconditions.checkNotNull("modelType", modelType);
PortablePreconditions.checkNotNull("sourcePredicate", sourcePredicate);
if (FormModelPropertiesUtil.isBaseType(modelType)) {
throw new IllegalArgumentException("Cannot extract FormModel for type '" + modelType + "'.");
}
final String modelName = modelType.substring(modelType.lastIndexOf(".") + 1);
final DataObjectFormModel formModel = new DataObjectFormModel(modelName, modelType);
TypeSource typeSource = oracle.getModuleTypeSources().get(modelType);
if (typeSource == null || !sourcePredicate.test(typeSource)) {
return null;
}
if (typeSource.equals(TypeSource.JAVA_DEPENDENCY)) {
formModel.setSource(Source.EXTERNAL);
}
ModelField[] fields = oracle.getModuleModelFields().get(modelType);
Map<String, Set<Annotation>> fieldAnnotations = oracle.getModuleTypeFieldsAnnotations().getOrDefault(modelType, Collections.emptyMap());
Arrays.stream(fields).forEach(modelField -> {
if (modelField.getName().equals("this")) {
return;
}
if (!FieldAccessorsAndMutators.BOTH.equals(modelField.getAccessorsAndMutators())) {
return;
}
Set<Annotation> annotations = Optional.ofNullable(fieldAnnotations.get(modelField.getName())).orElse(Collections.EMPTY_SET);
if (!isValidModelProperty(modelField, annotations)) {
return;
}
try {
String fieldType = modelField.getClassName();
boolean isEnum = oracle.getModuleJavaEnumDefinitions().get(modelType + "#" + modelField.getName()) != null;
boolean isList = DataType.TYPE_COLLECTION.equals(modelField.getType());
if (isList) {
fieldType = oracle.getModuleFieldParametersType().get(modelType + "#" + modelField.getName());
}
TypeKind typeKind = isEnum ? TypeKind.ENUM : FormModelPropertiesUtil.isBaseType(fieldType) ? TypeKind.BASE : TypeKind.OBJECT;
TypeInfo info = new TypeInfoImpl(typeKind, fieldType, isList);
ModelProperty modelProperty = new ModelPropertyImpl(modelField.getName(), info);
annotations.stream().filter(annotation -> annotation.getQualifiedTypeName().equalsIgnoreCase(LABEL_ANNOTATION)).findAny().ifPresent(annotation -> {
String label = (String) annotation.getParameters().get(LABEL_ANNOTATION_VALUE_PARAM);
modelProperty.getMetaData().addEntry(new FieldLabelEntry(label));
modelProperty.getMetaData().addEntry(new FieldPlaceHolderEntry(label));
});
formModel.addProperty(modelProperty);
} catch (Exception ex) {
logger.warn("Error processing model '" + modelType + "' impossible generate FieldDefinition for model field '" + modelField.getName() + "' (" + modelField.getType() + ")");
}
});
return formModel;
}
use of org.kie.workbench.common.forms.model.impl.meta.entries.FieldPlaceHolderEntry in project kie-wb-common by kiegroup.
the class FieldManagerTest method testGetDefinitionByModelPropertyWithMetaData.
@Test
public void testGetDefinitionByModelPropertyWithMetaData() {
property.getMetaData().addEntry(new FieldTypeEntry(TextAreaFieldType.NAME));
property.getMetaData().addEntry(new FieldLabelEntry(METADATA_LABEL));
property.getMetaData().addEntry(new FieldPlaceHolderEntry(METADATA_PLACEHOLDER));
property.getMetaData().addEntry(new FieldReadOnlyEntry(METADATA_READONLY));
property.getMetaData().addEntry(new FieldRequiredEntry(METADATA_REQUIRED));
FieldDefinition fieldDefinition = fieldManager.getDefinitionByModelProperty(property);
Assertions.assertThat(fieldDefinition).isNotNull().isInstanceOf(TextAreaFieldDefinition.class).hasFieldOrPropertyWithValue("name", PROPERTY_NAME).hasFieldOrPropertyWithValue("label", METADATA_LABEL).hasFieldOrPropertyWithValue("placeHolder", METADATA_PLACEHOLDER).hasFieldOrPropertyWithValue("required", METADATA_REQUIRED).hasFieldOrPropertyWithValue("readOnly", METADATA_READONLY).hasFieldOrPropertyWithValue("binding", PROPERTY_NAME);
}
Aggregations