use of org.kie.workbench.common.forms.model.ModelProperty in project kie-wb-common by kiegroup.
the class BPMNFormModelGeneratorImpl method createModelProperty.
protected ModelProperty createModelProperty(Variable variable, ClassLoader classLoader) {
ModelProperty property = ModelPropertiesGenerator.createModelProperty(variable.getName(), variable.getType(), FormModelPropertiesUtil.isListType(variable.getType()), classLoader);
property.getMetaData().addEntry(new FieldReadOnlyEntry(variable.isInput() && !variable.isOutput()));
if (!property.getTypeInfo().isMultiple() && property.getTypeInfo().getClassName().equals(Object.class.getName())) {
property.getMetaData().addEntry(new FieldTypeEntry(TextAreaFieldDefinition.FIELD_TYPE.getTypeName()));
}
return property;
}
use of org.kie.workbench.common.forms.model.ModelProperty in project kie-wb-common by kiegroup.
the class BPMNFormModelGeneratorImpl method generateProcessFormModel.
@Override
public BusinessProcessFormModel generateProcessFormModel(Definitions source, Path path) {
Process process = getProcess(source);
if (process != null) {
final ClassLoader projectClassLoader = projectClassLoaderHelper.getModuleClassLoader(moduleService.resolveModule(path));
List<ModelProperty> properties = process.getProperties().stream().map(property -> {
String varName = property.getId();
String varType = BPMNVariableUtils.getRealTypeForInput(property.getItemSubjectRef().getStructureRef());
Variable variable = new Variable(varName, varType);
variable.setInput(true);
variable.setOutput(true);
return createModelProperty(variable, projectClassLoader);
}).sorted((property1, property2) -> property1.getName().compareToIgnoreCase(property2.getName())).collect(Collectors.toList());
return new BusinessProcessFormModel(process.getId(), process.getName(), properties);
}
return null;
}
use of org.kie.workbench.common.forms.model.ModelProperty 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.ModelProperty 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.ModelProperty in project kie-wb-common by kiegroup.
the class BPMNFormModelGeneratorImplTest method checkExpectedMergedFormVariables.
protected void checkExpectedMergedFormVariables(TaskFormModel formModel) {
final Map<String, String> EXPECTED_TYPES = new HashMap<>();
EXPECTED_TYPES.put("name", String.class.getName());
EXPECTED_TYPES.put("lastName", String.class.getName());
EXPECTED_TYPES.put("age", Integer.class.getName());
EXPECTED_TYPES.put("married", Boolean.class.getName());
assertEquals(EXPECTED_TYPES.size(), formModel.getProperties().size());
for (ModelProperty property : formModel.getProperties()) {
assertNotNull(EXPECTED_TYPES.get(property.getName()));
assertEquals(EXPECTED_TYPES.get(property.getName()), property.getTypeInfo().getClassName());
}
}
Aggregations