Search in sources :

Example 16 with FormDefinition

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

the class BPMNVFSFormDefinitionGeneratorService method createRootFormDefinition.

public FormDefinition createRootFormDefinition(GenerationContext<Path> context) {
    FormModelHandler modelHandler = formModelHandlerManager.getFormModelHandler(context.getFormModel().getClass());
    modelHandler.init(context.getFormModel(), context.getSource());
    final FormDefinition form;
    org.uberfire.java.nio.file.Path kiePath = Paths.convert(context.getSource());
    logger.info("Started form generation for '{}'", kiePath);
    if (ioService.exists(kiePath)) {
        form = formSerializer.deserialize(ioService.readAllString(kiePath));
        logger.warn("Already exists form '{}'. Synchronizing form fields:", kiePath);
        // If the form exists on the VFS let's synchronize form fields
        FormModelSynchronizationResult synchronizationResult = modelHandler.synchronizeFormModelProperties(form.getModel(), context.getFormModel().getProperties());
        formModelSynchronizationUtil.init(form, synchronizationResult);
        if (synchronizationResult.hasRemovedProperties()) {
            logger.warn("Process/Task has removed variables, checking fields:");
            formModelSynchronizationUtil.fixRemovedFields();
        }
        if (synchronizationResult.hasConflicts()) {
            logger.warn("Process/Task has some variables which type has changed. Checking fields:");
            formModelSynchronizationUtil.resolveConflicts();
        }
        if (synchronizationResult.hasNewProperties()) {
            logger.warn("Process/Task has new variables. Adding them to form:");
            formModelSynchronizationUtil.addNewFields(fieldManager::getDefinitionByModelProperty);
        }
        form.setModel(context.getFormModel());
    } else {
        form = new FormDefinition(context.getFormModel());
        form.setId(UIDGenerator.generateUID());
        form.setName(context.getSource().getFileName());
        form.getFields().addAll(context.getFormModel().getProperties().stream().map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toList()));
    }
    form.setModel(context.getFormModel());
    return form;
}
Also used : FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 17 with FormDefinition

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

the class BPMNRuntimeFormGeneratorService method createRootFormDefinition.

@Override
protected FormDefinition createRootFormDefinition(GenerationContext<ClassLoader> context) {
    FormDefinition form = new FormDefinition(context.getFormModel());
    form.setId(context.getFormModel().getFormName());
    form.setName(context.getFormModel().getFormName());
    context.getFormModel().getProperties().forEach(property -> {
        if (!BPMNVariableUtils.isValidInputName(property.getName())) {
            return;
        }
        FieldDefinition field = generateFieldDefinition(property, context);
        if (field != null) {
            form.getFields().add(field);
        }
    });
    return form;
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 18 with FormDefinition

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

the class FormDefinitionSerializerImpl method deserialize.

@Override
public FormDefinition deserialize(String serializedForm) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(FormModel.class, formModelSerializer);
    builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer);
    builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class));
    builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class));
    builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class));
    builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> {
        JsonObject jsonField = json.getAsJsonObject();
        JsonElement jsonName = jsonField.get("name");
        return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString()));
    });
    Gson gson = builder.create();
    return gson.fromJson(serializedForm, FormDefinition.class);
}
Also used : JsonObject(com.google.gson.JsonObject) ModelMetaData(org.kie.workbench.common.forms.model.ModelMetaData) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) GsonBuilder(com.google.gson.GsonBuilder) MetaDataEntryManager(org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryManager) Inject(javax.inject.Inject) JsonElement(com.google.gson.JsonElement) FormModel(org.kie.workbench.common.forms.model.FormModel) Dependent(javax.enterprise.context.Dependent) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Gson(com.google.gson.Gson) JsonDeserializer(com.google.gson.JsonDeserializer) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry) ModelMetaDataImpl(org.kie.workbench.common.forms.model.impl.meta.ModelMetaDataImpl) GsonBuilder(com.google.gson.GsonBuilder) JsonElement(com.google.gson.JsonElement) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) ModelMetaData(org.kie.workbench.common.forms.model.ModelMetaData) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Example 19 with FormDefinition

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

the class AbstractFormGenerator method generateFormDefinition.

protected FormDefinition generateFormDefinition(FormDefinitionSettings settings, Object model, FormElementFilter... filters) {
    FormGenerationContext context = new FormGenerationContext(model, settings, getI18nHelper(settings.getI18nSettings()), filters);
    context.setFieldStatusModifierReferences(fieldModifierReferences);
    context.setFieldStatusModifiers(fieldModifiers);
    if (settings.getLayout() == null || settings.getLayout().getColumns() == null || settings.getLayout().getColumns().length == 0) {
        settings.setLayout(new LayoutDefinition(new LayoutColumnDefinition()));
    }
    layoutGenerator.init(settings.getLayout().getColumns());
    processElements(context);
    FormDefinition form = context.getFormDefinition();
    form.setLayoutTemplate(layoutGenerator.build());
    return form;
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutDefinition) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 20 with FormDefinition

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

the class FormGeneratorTest method testGenerateFormForClass.

@Test
public void testGenerateFormForClass() {
    FormDefinition form = generator.generateFormForClass(Person.class);
    testGeneratedForm(form, Person.class.getName());
}
Also used : FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Person(org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Person) Test(org.junit.Test) AbstractFormGenerationTest(org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)

Aggregations

FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)89 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)30 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)16 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)14 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)14 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)13 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)12 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)12 AbstractFormGenerationTest (org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)10 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)10 List (java.util.List)9 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)8 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)8 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)8 Person (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Person)7 FormModel (org.kie.workbench.common.forms.model.FormModel)7 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)7 Date (java.util.Date)6