use of org.kie.workbench.common.forms.editor.service.backend.FormModelHandler in project kie-wb-common by kiegroup.
the class BPMNVFSFormDefinitionGeneratorService method extractModelFields.
@Override
protected List<FieldDefinition> extractModelFields(JavaFormModel formModel, GenerationContext<Path> context) {
FormModelHandler handler = formModelHandlerManager.getFormModelHandler(formModel.getClass());
handler.init(formModel, context.getSource());
handler.synchronizeFormModel();
return formModel.getProperties().stream().map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toList());
}
use of org.kie.workbench.common.forms.editor.service.backend.FormModelHandler 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.editor.service.backend.FormModelHandler in project kie-wb-common by kiegroup.
the class FormEditorServiceImpl method constructContent.
@Override
protected FormModelerContent constructContent(Path path, Overview overview) {
FormModelerContent formModelConent = new FormModelerContent();
try {
org.uberfire.java.nio.file.Path kiePath = Paths.convert(path);
FormDefinition form = findForm(kiePath);
formModelConent.setDefinition(form);
formModelConent.setPath(path);
formModelConent.setOverview(overview);
FormEditorRenderingContext context = createRenderingContext(form, path);
formModelConent.setRenderingContext(context);
if (Optional.ofNullable(form.getModel()).isPresent()) {
FormModel formModel = form.getModel();
Optional<FormModelHandler> modelHandlerOptional = getHandlerForForm(form);
if (modelHandlerOptional.isPresent()) {
try {
FormModelHandler formModelHandler = modelHandlerOptional.get();
formModelHandler.init(formModel, path);
formModelHandler.checkSourceModel();
FormModelSynchronizationResult synchronizationResult = formModelHandler.synchronizeFormModel();
formModel.getProperties().forEach(property -> {
Optional<FieldDefinition> fieldOptional = Optional.ofNullable(form.getFieldByBinding(property.getName()));
if (!fieldOptional.isPresent()) {
synchronizationResult.resolveConflict(property.getName());
}
});
formModelConent.setSynchronizationResult(synchronizationResult);
} catch (SourceFormModelNotFoundException ex) {
formModelConent.setError(new FormModelerContentError(ex.getShortKey(), ex.getShortKeyParams(), ex.getLongKey(), ex.getLongKeyParams(), ex.getModelSourceKey()));
}
}
}
} catch (Exception e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
formModelConent.setError(new FormModelerContentError(SHORT_KEY, null, LONG_KEY, new String[] { writer.toString() }, null));
log.warn("Error loading form " + path.toURI(), e);
}
resourceOpenedEvent.fire(new ResourceOpenedEvent(path, sessionInfo));
return formModelConent;
}
use of org.kie.workbench.common.forms.editor.service.backend.FormModelHandler in project kie-wb-common by kiegroup.
the class FormEditorServiceImplTest method init.
@Before
public void init() {
Instance<FormModelHandler<? extends FormModel>> instances = mock(Instance.class);
when(dataObjectFormModelHandler.getModelType()).thenReturn(DataObjectFormModel.class);
when(dataObjectFormModelHandler.newInstance()).thenReturn(dataObjectFormModelHandler);
List<FormModelHandler> handlers = Arrays.asList(dataObjectFormModelHandler);
when(instances.iterator()).then(invocationOnMock -> handlers.iterator());
modelHandlerManager = spy(new FormModelHandlerManagerImpl(instances));
formDefinitionSerializer = spy(new FormDefinitionSerializerImpl(new FieldSerializer(), new FormModelSerializer(), new TestMetaDataEntryManager()));
formEditorService = spy(new FormEditorServiceImpl(ioService, sessionInfo, resourceOpenedEvent, fieldManager, modelHandlerManager, moduleService, formDefinitionSerializer, moduleFormFinderService, deleteService, commentedOptionFactory, renameService, copyService));
when(path.toURI()).thenReturn("file:///src/main/resources/test.frm");
when(moduleService.resolveModule(any())).thenReturn(module);
}
Aggregations