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;
}
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;
}
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);
}
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;
}
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());
}
Aggregations