Search in sources :

Example 11 with ModelPropertyImpl

use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.

the class JBPMFormModelCreationPresenterTest method initFormModels.

protected void initFormModels() {
    List<ModelProperty> processVariables = new ArrayList<>();
    processVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("twitter", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("offering", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("skills", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("hr_score", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("tech_score", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("signed", new TypeInfoImpl(Boolean.class.getName())));
    BusinessProcessFormModel processFormModel = new BusinessProcessFormModel("hiring", "hiring", processVariables);
    TaskFormModel taskFormModel;
    List<TaskFormModel> processTasks = new ArrayList<>();
    List<ModelProperty> taskVariables = new ArrayList<>();
    taskVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
    taskVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("hr_score", new TypeInfoImpl(String.class.getName())));
    taskFormModel = new TaskFormModel("hiring", "HRInterview", taskVariables);
    processTasks.add(taskFormModel);
    taskVariables = new ArrayList<>();
    taskVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
    taskVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("skills", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("tech_score", new TypeInfoImpl(Integer.class.getName())));
    taskVariables.add(new ModelPropertyImpl("twitter", new TypeInfoImpl(String.class.getName())));
    taskFormModel = new TaskFormModel("hiring", "TechInterview", taskVariables);
    processTasks.add(taskFormModel);
    JBPMProcessModel model = new JBPMProcessModel(processFormModel, processTasks);
    formModels.add(model);
}
Also used : JBPMProcessModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMProcessModel) ArrayList(java.util.ArrayList) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl)

Example 12 with ModelPropertyImpl

use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.

the class ModelPropertiesGenerator method createModelProperty.

public static ModelProperty createModelProperty(String name, String className, boolean isMultiple, ClassLoader classLoader) {
    if (FormModelPropertiesUtil.isBaseType(className)) {
        // Dealing with basic type properties (String, Integer...)
        return new ModelPropertyImpl(name, new TypeInfoImpl(className, isMultiple));
    } else {
        // Dealing with complex types.
        if (FormModelPropertiesUtil.isListType(className)) {
            // If className is a List let's create a model for Object...
            return createModelProperty(name, Object.class.getName(), true);
        }
        try {
            Class clazz = classLoader.loadClass(className);
            TypeKind typeKind = clazz.isEnum() ? TypeKind.ENUM : TypeKind.OBJECT;
            return new ModelPropertyImpl(name, new TypeInfoImpl(typeKind, className, isMultiple));
        } catch (ClassNotFoundException e) {
            logger.warn("Unable to create property '" + name + "' for class '" + className + "':", e);
        }
    }
    return null;
}
Also used : TypeKind(org.kie.workbench.common.forms.model.TypeKind) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl)

Example 13 with ModelPropertyImpl

use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.

the class FormDefinitionSerializerImplTest method initTest.

@Before
public void initTest() {
    fieldManager = new TestFieldManager();
    definitionSerializer = new FormDefinitionSerializerImpl(new FieldSerializer(), new FormModelSerializer(), new TestMetaDataEntryManager());
    JavaFormModel model = new PortableJavaModel("org.test.MyParentModel");
    formDefinition = new FormDefinition(model);
    formDefinition.setId("testForm");
    formDefinition.setName("testForm");
    formDefinition.setLayoutTemplate(new LayoutTemplate());
    for (BasicTypeFieldProvider provider : fieldManager.getAllBasicTypeProviders()) {
        for (String type : provider.getSupportedTypes()) {
            FieldDefinition field = provider.getFieldByType(new TypeInfoImpl(type));
            assertNotNull(field);
            String fieldDescription = provider.getFieldTypeName() + "_" + type;
            field.setName(fieldDescription);
            field.setLabel(fieldDescription);
            field.setStandaloneClassName(type);
            field.setBinding(fieldDescription);
            model.getProperties().add(new ModelPropertyImpl(fieldDescription, new TypeInfoImpl(type)));
            formDefinition.getFields().add(field);
        }
    }
    SubFormFieldDefinition subForm = new SubFormFieldDefinition();
    subForm.setLabel("SubForm");
    subForm.setNestedForm("");
    subForm.setBinding("model");
    subForm.setStandaloneClassName("org.test.MyTestModel");
    subForm.setBinding("SubForm");
    formDefinition.getFields().add(subForm);
    model.getProperties().add(new ModelPropertyImpl(subForm.getBinding(), new TypeInfoImpl(TypeKind.OBJECT, subForm.getStandaloneClassName(), false)));
    MultipleSubFormFieldDefinition multipleSubForm = new MultipleSubFormFieldDefinition();
    multipleSubForm.setLabel("MultipleSubForm");
    multipleSubForm.setCreationForm("");
    multipleSubForm.setEditionForm("");
    multipleSubForm.setStandaloneClassName("org.test.MyTestModel");
    multipleSubForm.setBinding("MultipleSubForm");
    formDefinition.getFields().add(multipleSubForm);
    model.getProperties().add(new ModelPropertyImpl(multipleSubForm.getBinding(), new TypeInfoImpl(TypeKind.OBJECT, multipleSubForm.getStandaloneClassName(), true)));
    EnumListBoxFieldDefinition enumListBox = new EnumListBoxFieldDefinition();
    enumListBox.setLabel("EnumListBox");
    enumListBox.setBinding("EnumListBox");
    enumListBox.setStandaloneClassName("org.test.MyTestModel");
    formDefinition.getFields().add(enumListBox);
    model.getProperties().add(new ModelPropertyImpl(enumListBox.getBinding(), new TypeInfoImpl(TypeKind.ENUM, enumListBox.getStandaloneClassName(), false)));
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) EnumListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TestMetaDataEntryManager(org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) EnumListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) TestFieldManager(org.kie.workbench.common.forms.fields.test.TestFieldManager) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider) Before(org.junit.Before)

Example 14 with ModelPropertyImpl

use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.

the class FormDefinitionGenerator method updateNestedFormsModelProperties.

private void updateNestedFormsModelProperties(FormDefinition newFormDefinition, FieldDefinition nestedFormField, Form nestedForm) {
    nestedFormField.setStandaloneClassName(nestedForm.getHolders().iterator().next().getClassName());
    FormModel model = newFormDefinition.getModel();
    ModelProperty modelProperty = model.getProperty(nestedFormField.getBinding());
    if (modelProperty != null) {
        model.getProperties().remove(modelProperty);
        ModelPropertyImpl newProperty = new ModelPropertyImpl(nestedFormField.getBinding(), nestedFormField.getFieldTypeInfo());
        newProperty.getMetaData().getEntries().addAll(modelProperty.getMetaData().getEntries());
        model.getProperties().add(newProperty);
    }
}
Also used : FormModel(org.kie.workbench.common.forms.model.FormModel) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)

Example 15 with ModelPropertyImpl

use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.

the class AbstractFieldAdapter method parseField.

@Override
public void parseField(Field originalField, FormMigrationSummary formSummary, FormDefinition newFormDefinition, Consumer<LayoutComponent> layoutElementConsumer) {
    FieldDefinition fieldDefinition = getFieldDefinition(originalField);
    fieldDefinition.setId(String.valueOf(originalField.getId()));
    fieldDefinition.setName(originalField.getFieldName());
    fieldDefinition.setLabel(lookupI18nValue(originalField.getLabel()));
    fieldDefinition.setHelpMessage(lookupI18nValue(originalField.getTitle()));
    fieldDefinition.setStandaloneClassName(StringUtils.defaultIfBlank(originalField.getBag(), originalField.getFieldType().getFieldClass()));
    fieldDefinition.setReadOnly(originalField.getReadonly());
    fieldDefinition.setRequired(originalField.getFieldRequired());
    String binding = StringUtils.defaultString(StringUtils.defaultIfBlank(originalField.getInputBinding(), originalField.getOutputBinding()));
    if (!StringUtils.isEmpty(binding)) {
        if (binding.contains("/")) {
            binding = binding.substring(binding.indexOf("/") + 1);
        }
        ModelPropertyImpl property = new ModelPropertyImpl(binding, fieldDefinition.getFieldTypeInfo());
        newFormDefinition.getModel().getProperties().add(property);
    }
    fieldDefinition.setBinding(binding);
    newFormDefinition.getFields().add(fieldDefinition);
    LayoutComponent component = new LayoutComponent(DRAGGABLE_TYPE);
    component.addProperty(FormLayoutComponent.FORM_ID, newFormDefinition.getId());
    component.addProperty(FormLayoutComponent.FIELD_ID, fieldDefinition.getId());
    layoutElementConsumer.accept(component);
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent)

Aggregations

ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)15 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)13 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)10 ArrayList (java.util.ArrayList)9 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)7 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)6 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)5 Test (org.junit.Test)4 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)4 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)4 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)4 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)4 BusinessProcessFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)3 Mockito.anyString (org.mockito.Mockito.anyString)3 Date (java.util.Date)2 Before (org.junit.Before)2 EnumListBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition)2 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)2 TestFieldManager (org.kie.workbench.common.forms.fields.test.TestFieldManager)2