use of org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException in project kie-wb-common by kiegroup.
the class FormEditorServiceImplTest method testConstructContentWithCheckModelFailure.
@Test
public void testConstructContentWithCheckModelFailure() throws IOException, SourceFormModelNotFoundException {
SourceFormModelNotFoundException exception = new SourceFormModelNotFoundException("exception", null, "exception", null, "model", null);
doThrow(exception).when(dataObjectFormModelHandler).checkSourceModel();
String formContent = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("test.frm")));
when(ioService.readAllString(any())).thenReturn(formContent);
FormModelerContent content = formEditorService.constructContent(path, overview);
verify(modelHandlerManager).getFormModelHandler(any());
verify(dataObjectFormModelHandler).init(any(), any());
verify(dataObjectFormModelHandler).checkSourceModel();
verify(dataObjectFormModelHandler, never()).synchronizeFormModel();
verify(resourceOpenedEvent).fire(any());
assertNotNull(content);
assertNotNull(content.getError());
assertEquals(exception.getShortKey(), content.getError().getShortKey());
assertArrayEquals(exception.getShortKeyParams(), content.getError().getShortKeyParams());
assertEquals(exception.getLongKey(), content.getError().getLongKey());
assertArrayEquals(exception.getLongKeyParams(), content.getError().getLongKeyParams());
}
use of org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException 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;
}
Aggregations