use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormGenerationWithSynchronizationTest method testModelPropertiesConflict.
@Test
public void testModelPropertiesConflict() {
List<ModelProperty> modelProperties = new ArrayList<>();
modelProperties.add(new ModelPropertyImpl(NAME_PROPERTY, new TypeInfoImpl(Integer.class.getName())));
modelProperties.add(new ModelPropertyImpl(LASTNAME_PROPERTY, new TypeInfoImpl(Integer.class.getName())));
modelProperties.add(new ModelPropertyImpl(AGE_PROPERTY, new TypeInfoImpl(String.class.getName())));
modelProperties.add(new ModelPropertyImpl(MARRIED_PROPERTY, new TypeInfoImpl(Integer.class.getName())));
modelProperties.add(new ModelPropertyImpl(ADDRESS_PROPERTY, new TypeInfoImpl(Boolean.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(), Integer.class.getName());
assertTrue(field instanceof IntegerBoxFieldDefinition);
field = formDefinition.getFieldByBinding(LASTNAME_PROPERTY);
assertNotNull(field);
assertEquals(field.getStandaloneClassName(), Integer.class.getName());
assertTrue(field instanceof IntegerBoxFieldDefinition);
field = formDefinition.getFieldByBinding(AGE_PROPERTY);
assertEquals(field.getStandaloneClassName(), String.class.getName());
assertTrue(field instanceof TextBoxFieldDefinition);
field = formDefinition.getFieldByBinding(MARRIED_PROPERTY);
assertNotNull(field);
assertEquals(field.getStandaloneClassName(), Integer.class.getName());
assertTrue(field instanceof IntegerBoxFieldDefinition);
field = formDefinition.getFieldByBinding(ADDRESS_PROPERTY);
assertNotNull(field);
assertEquals(field.getStandaloneClassName(), Boolean.class.getName());
assertTrue(field instanceof CheckBoxFieldDefinition);
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class BPMNFormGenerationTest method checkPersonForm.
private void checkPersonForm(FormDefinition form, Map<String, FormDefinition> allForms) {
assertNotNull(form);
assertTrue(form.getModel() instanceof JavaFormModel);
assertEquals(4, form.getFields().size());
FieldDefinition field = form.getFieldByBinding("name");
assertFieldStatus(field, "name", String.class.getName());
field = form.getFieldByBinding("type");
assertFieldStatus(field, "type", PersonType.class.getName());
assertTrue(field instanceof EnumListBoxFieldDefinition);
field = form.getFieldByBinding("personalData");
assertFieldStatus(field, "personalData", PersonalData.class.getName());
assertTrue(field instanceof SubFormFieldDefinition);
SubFormFieldDefinition subForm = (SubFormFieldDefinition) field;
assertNotNull(subForm.getNestedForm());
assertNotNull(allForms.get(subForm.getNestedForm()));
field = form.getFieldByBinding("log");
assertFieldStatus(field, "log", LogEntry.class.getName());
assertTrue(field instanceof MultipleSubFormFieldDefinition);
MultipleSubFormFieldDefinition multipleSubForm = (MultipleSubFormFieldDefinition) field;
assertNotNull(multipleSubForm.getCreationForm());
assertEquals(multipleSubForm.getCreationForm(), multipleSubForm.getEditionForm());
FormDefinition nestedForm = allForms.get(multipleSubForm.getCreationForm());
assertNotNull(nestedForm);
assertNotNull(multipleSubForm.getColumnMetas());
assertEquals(nestedForm.getFields().size(), multipleSubForm.getColumnMetas().size());
multipleSubForm.getColumnMetas().forEach(columnMeta -> {
FieldDefinition nestedField = nestedForm.getFieldByBinding(columnMeta.getProperty());
assertNotNull(nestedField);
assertEquals(nestedField.getLabel(), columnMeta.getLabel());
});
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class BPMNFormGenerationTest method testSimpleVariables.
@Test
public void testSimpleVariables() {
List<ModelProperty> variables = new ArrayList<>();
variables.add(new ModelPropertyImpl("employee", new TypeInfoImpl(String.class.getName())));
variables.add(new ModelPropertyImpl("manager", new TypeInfoImpl(String.class.getName())));
variables.add(new ModelPropertyImpl("performance", new TypeInfoImpl(Integer.class.getName())));
variables.add(new ModelPropertyImpl("approved", new TypeInfoImpl(Boolean.class.getName())));
model = getModel(getModelId(), variables);
Collection<FormDefinition> forms = getModelForms(model, classLoader);
try {
verify(classLoader, never()).loadClass(anyString());
} catch (ClassNotFoundException e) {
fail("We shouldn't be here: " + e.getMessage());
}
assertNotNull("There should one form", forms);
assertEquals("There should one form", 1, forms.size());
FormDefinition form = forms.iterator().next();
assertEquals(getModelId() + BPMNVariableUtils.TASK_FORM_SUFFIX, form.getId());
assertEquals(getModelId() + BPMNVariableUtils.TASK_FORM_SUFFIX, form.getName());
assertEquals(form.getModel(), model);
assertEquals("There should be 4 fields", 4, form.getFields().size());
variables.forEach(variable -> {
FieldDefinition field = form.getFieldByBinding(variable.getName());
assertFieldStatus(field, variable);
});
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class VFSSelectorFormProvider method getSelectorData.
@Override
public SelectorData getSelectorData(FormRenderingContext context) {
Map<String, String> values = new TreeMap<>();
if (context.getModel() instanceof EntityRelationField) {
FormEditorRenderingContext editorContext = (FormEditorRenderingContext) context;
FieldDefinition field = (FieldDefinition) context.getModel();
List<FormDefinition> forms;
if (field != null) {
forms = vfsFormFinderService.findFormsForType(field.getStandaloneClassName(), editorContext.getFormPath());
} else {
forms = vfsFormFinderService.findAllForms(editorContext.getFormPath());
}
for (FormDefinition form : forms) {
values.put(form.getId(), form.getName());
}
}
return new SelectorData(values, null);
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionIndexer method fillIndexBuilder.
@Override
protected DefaultIndexBuilder fillIndexBuilder(Path path) throws Exception {
final DefaultIndexBuilder builder = getIndexBuilder(path);
if (builder == null) {
return null;
}
String formContent = ioService.readAllString(path);
FormDefinition formDefinition = formDefinitionSerializer.deserialize(formContent);
if (formDefinition != null) {
Resource resParts = new Resource(formDefinition.getName(), ResourceType.FORM);
FormDefinitionVisitor visitor = new FormDefinitionVisitor(resParts);
visitor.visit(formDefinition);
addReferencedResourcesToIndexBuilder(builder, visitor);
FormModel model = formDefinition.getModel();
if (model != null) {
FormModelVisitorProvider provider = getProviderForModel(model.getClass());
if (provider != null) {
FormModelVisitor modelVisitor = provider.getVisitor();
modelVisitor.index(formDefinition, model);
addReferencedResourcesToIndexBuilder(builder, modelVisitor);
}
}
} else {
logger.error("Unable to read FormDefinition on " + path.toUri().toString() + ".");
return null;
}
return builder;
}
Aggregations