use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class FieldManagerTest method initTest.
@Before
public void initTest() {
fieldManager = new TestFieldManager();
Assertions.assertThat(fieldManager.getBaseFieldTypes()).isNotNull().isNotEmpty();
property = new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName()));
}
use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class FormGenerationWithSynchronizationTest method testRemoveModelProperties.
@Test
public void testRemoveModelProperties() {
List<ModelProperty> modelProperties = new ArrayList<>();
modelProperties.add(new ModelPropertyImpl(NAME_PROPERTY, new TypeInfoImpl(String.class.getName())));
modelProperties.add(new ModelPropertyImpl(LASTNAME_PROPERTY, new TypeInfoImpl(String.class.getName())));
newFormModel = new TaskFormModel(PROCESS_ID, TASK_NAME, modelProperties);
FormGenerationResult generationResult = service.generateForms(newFormModel, source);
assertNotNull(generationResult);
assertNotNull(generationResult.getRootForm());
FormDefinition formDefinition = generationResult.getRootForm();
assertEquals(newFormModel, formDefinition.getModel());
assertEquals(ORIGINAL_FORM_FIELDS, Integer.valueOf(formDefinition.getFields().size()));
FieldDefinition field = formDefinition.getFieldByBinding(NAME_PROPERTY);
assertNotNull(field);
assertEquals(field.getStandaloneClassName(), String.class.getName());
field = formDefinition.getFieldByBinding(LASTNAME_PROPERTY);
assertNotNull(field);
assertEquals(field.getStandaloneClassName(), String.class.getName());
assertNull(formDefinition.getFieldByBinding(AGE_PROPERTY));
assertNull(formDefinition.getFieldByBinding(MARRIED_PROPERTY));
assertNull(formDefinition.getFieldByBinding(ADDRESS_PROPERTY));
assertNotNull(formDefinition.getFieldByName(AGE_PROPERTY));
assertNotNull(formDefinition.getFieldByName(MARRIED_PROPERTY));
assertNotNull(formDefinition.getFieldByName(ADDRESS_PROPERTY));
}
use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class BPMNFormGenerationTest method testComplexFields.
protected void testComplexFields(boolean fromClassLoader) {
if (fromClassLoader) {
try {
when(classLoader.loadClass(Person.class.getName())).then(new Answer<Class<?>>() {
@Override
public Class<?> answer(InvocationOnMock invocationOnMock) throws Throwable {
return Person.class;
}
});
} catch (ClassNotFoundException e) {
fail("We shouldn't be here: " + e.getMessage());
}
}
List<ModelProperty> properties = new ArrayList<>();
properties.add(new ModelPropertyImpl("person", new TypeInfoImpl(TypeKind.OBJECT, Person.class.getName(), false)));
model = getModel(getModelId(), properties);
Collection<FormDefinition> forms = getModelForms(model, classLoader);
Map<String, FormDefinition> allForms = new HashMap<>();
forms.forEach(form -> allForms.put(form.getId(), form));
try {
verify(classLoader, times(3)).loadClass(anyString());
} catch (ClassNotFoundException e) {
fail(e.getMessage());
}
assertNotNull("There should some forms", forms);
assertEquals("There should 4 forms", 4, forms.size());
FormDefinition form = allForms.get(getModelId() + BPMNVariableUtils.TASK_FORM_SUFFIX);
checkBPMForm(form, allForms);
form = findFormForModel(Person.class.getName(), allForms);
checkPersonForm(form, allForms);
form = findFormForModel(PersonalData.class.getName(), allForms);
checkPersonalDataForm(form, allForms);
form = findFormForModel(LogEntry.class.getName(), allForms);
checkLogEntryForm(form);
}
use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class FormEditorHelperTest method initFields.
private void initFields() {
TextBoxFieldDefinition name = new TextBoxFieldDefinition();
name.setId("name");
name.setName("name");
name.setLabel("Name");
name.setPlaceHolder("Name");
name.setBinding("name");
name.setStandaloneClassName(String.class.getName());
nameField = name;
TextBoxFieldDefinition lastName = new TextBoxFieldDefinition();
lastName.setId("lastName");
lastName.setName("lastName");
lastName.setLabel("Last Name");
lastName.setPlaceHolder("Last Name");
lastName.setBinding("lastName");
lastName.setStandaloneClassName(String.class.getName());
lastNameField = lastName;
DatePickerFieldDefinition birthday = new DatePickerFieldDefinition();
birthday.setId("birthday");
birthday.setName("birthday");
birthday.setLabel("Birthday");
birthday.setBinding("birthday");
birthday.setStandaloneClassName(Date.class.getName());
CheckBoxFieldDefinition married = new CheckBoxFieldDefinition();
married.setId("married");
married.setName("married");
married.setLabel("Married");
married.setBinding("married");
married.setStandaloneClassName(Boolean.class.getName());
marriedField = married;
IntegerBoxFieldDefinition age = new IntegerBoxFieldDefinition();
age.setId("age");
age.setName("age");
age.setLabel("Age");
age.setBinding("age");
ageField = age;
DecimalBoxFieldDefinition weight = new DecimalBoxFieldDefinition();
weight.setId("weight");
weight.setName("weight");
weight.setLabel("Weight");
weight.setBinding("weight");
weightField = weight;
employeeFields = new ArrayList<>();
employeeFields.add(name);
employeeFields.add(lastName);
employeeFields.add(birthday);
employeeFields.add(married);
employeeFields.add(age);
employeeFields.add(weight);
modelProperties = new ArrayList<>();
employeeFields.forEach(fieldDefinition -> modelProperties.add(new ModelPropertyImpl(fieldDefinition.getBinding(), new TypeInfoImpl(fieldDefinition.getStandaloneClassName()))));
}
use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class BPMNRuntimeFormGeneratorService method extractModelFields.
@Override
protected List<FieldDefinition> extractModelFields(JavaFormModel formModel, GenerationContext<ClassLoader> context) {
Class clazz;
String modelType = formModel.getType();
try {
clazz = context.getSource().loadClass(modelType);
if (clazz == null) {
clazz = getClass().forName(modelType);
}
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Unable to extract Form Fields for class '" + modelType + "'");
}
if (clazz == null) {
throw new IllegalArgumentException("Unable to extract Form Fields for class '" + modelType + "'");
}
ModuleDataModelOracle oracle = getModuleOracle(clazz);
if (oracle != null) {
List<FieldDefinition> formFields = new ArrayList<>();
ModelField[] fields = oracle.getModuleModelFields().get(modelType);
Arrays.stream(fields).forEach(modelField -> {
if (modelField.getName().equals("this")) {
return;
}
String fieldType = modelField.getClassName();
boolean isEnunm = 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 = isEnunm ? TypeKind.ENUM : FormModelPropertiesUtil.isBaseType(fieldType) ? TypeKind.BASE : TypeKind.OBJECT;
TypeInfo info = new TypeInfoImpl(typeKind, fieldType, isList);
ModelProperty modelProperty = new ModelPropertyImpl(modelField.getName(), info);
formModel.getProperties().add(modelProperty);
FieldDefinition field = generateFieldDefinition(modelProperty, context);
if (field != null) {
formFields.add(field);
}
});
return formFields;
}
return null;
}
Aggregations