use of org.kie.workbench.common.screens.datamodeller.model.EditorModelContent in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method loadContent.
@Override
public EditorModelContent loadContent(final Path path, boolean includeTypesInfo) {
EditorModelContent editorModelContent = super.loadContent(path);
if (includeTypesInfo) {
editorModelContent.setPropertyTypes(getBasePropertyTypes());
editorModelContent.setAnnotationDefinitions(getAnnotationDefinitions());
}
return editorModelContent;
}
use of org.kie.workbench.common.screens.datamodeller.model.EditorModelContent in project kie-wb-common by kiegroup.
the class DataModelerScreenPresenterTest method loadFileUnSuccessfulTest.
/**
* Tests that a java file with parse errors was successfully loaded.
* @param loadTypesInfo indicates if the types and annotations definitions loading should be simulated.
*/
private void loadFileUnSuccessfulTest(boolean loadTypesInfo) {
EditorModelContent content = createContent(loadTypesInfo, true);
// when there are parse errors the returned data object is null.
content.setDataObject(null);
when(versionRecordManager.getCurrentPath()).thenReturn(path);
when(modelerService.loadContent(path, loadTypesInfo)).thenReturn(content);
when(javaSourceEditor.getContent()).thenReturn(content.getSource());
if (loadTypesInfo) {
// types info is not loaded into the DataModelerWBContext.
when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(false);
} else {
// types info is already into the DataModelerWBContext.
when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(true);
}
// just for convenience, since the DataModelerContext is initialized by taking this definitions from the DMWC.
when(dataModelerWBContext.getAnnotationDefinitions()).thenReturn(testAnnotationDefs);
when(dataModelerWBContext.getPropertyTypes()).thenReturn(testTypeDefs);
presenter.onStartup(path, placeRequest);
// Verifications during and after model loading.
verify(view, times(1)).showLoading();
verify(view, times(1)).hideBusyIndicator();
// presenter should ask the DataModelerWBContext if the types info is already loaded.
verify(dataModelerWBContext, times(1)).isTypesInfoLoaded();
if (loadTypesInfo) {
// the types info should have been set into the DataModelerWBContext as part of the presenter loading.
verify(dataModelerWBContext, times(1)).setPropertyTypes(testTypeDefs);
verify(dataModelerWBContext, times(1)).setAnnotationDefinitions(testAnnotationDefs);
} else {
// the types info shouldn't have been set into the DataModelerWBContext as part of the presenter loading.
verify(dataModelerWBContext, times(0)).setPropertyTypes(testTypeDefs);
verify(dataModelerWBContext, times(0)).setAnnotationDefinitions(testAnnotationDefs);
}
// presenter should clear the system messages related to this editor.
verify(unpublishMessagesEvent, times(1)).fire(any(UnpublishMessagesEvent.class));
// presenter should read the expected path.
verify(modelerService, times(1)).loadContent(path, loadTypesInfo);
// parse errors should have been published.
verify(publishBatchMessagesEvent, times(1)).fire(any(PublishBatchMessagesEvent.class));
// parse errors dialog should have been raised.
verify(view, times(1)).showParseErrorsDialog(anyString(), anyString(), any(Command.class));
// at this point the parse errors popup is raised and waiting for the user to press the ok button.
// emulate the user click on the button.
presenter.getOnLoadParseErrorCommand().execute();
// verify that the context created by the presenter was properly initialized.
DataModelerContext context = presenter.context;
assertEquals(testModel, context.getDataModel());
assertEquals(null, context.getDataObject());
assertEquals(kieModule, context.getCurrentProject());
assertEquals(testPackages, context.getCurrentProjectPackages());
assertEquals(testAnnotationDefs, context.getAnnotationDefinitions());
assertEquals(content, context.getEditorModelContent());
// parse errors wherer produced on server so the status should be PARSE_ERRORS
assertEquals(DataModelerContext.ParseStatus.PARSE_ERRORS, context.getParseStatus());
// the file wasn't parsed the editor should go to the source tab.
assertEquals(DataModelerContext.EditionMode.SOURCE_MODE, context.getEditionMode());
// file was just read, so the status should be NO_CHANGES.
assertEquals(DataModelerContext.EditionStatus.NO_CHANGES, context.getEditionStatus());
// context wasn't set on the view since there aren't a data object to show.
verify(view, times(0)).setContext(context);
// the source editor should have been initialized with the source returned form server.
verify(javaSourceEditor, times(2)).setContent(testSource);
// current context should have been activated
verify(dataModelerWBContext, times(1)).setActiveContext(context);
// and notifications should have been sent.
verify(dataModelerFocusEvent, times(1)).fire(any(DataModelerWorkbenchFocusEvent.class));
}
use of org.kie.workbench.common.screens.datamodeller.model.EditorModelContent in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method constructContent.
@Override
protected EditorModelContent constructContent(Path path, Overview overview) {
if (logger.isDebugEnabled()) {
logger.debug("Loading editor model from path: " + path.toURI());
}
Long startTime = System.currentTimeMillis();
EditorModelContent editorModelContent = new EditorModelContent();
try {
KieModule module = moduleService.resolveModule(path);
if (module == null) {
logger.warn("File : " + path.toURI() + " do not belong to a valid module");
return editorModelContent;
}
Pair<DataModel, ModelDriverResult> resultPair = loadModel(module, false);
String className = calculateClassName(module, path);
editorModelContent.setCurrentModule(module);
editorModelContent.setPath(path);
editorModelContent.setCurrentModulePackages(serviceHelper.resolvePackages(module));
editorModelContent.setDataModel(resultPair.getK1());
editorModelContent.setDataObject(resultPair.getK1().getDataObject(className));
editorModelContent.setDataObjectPaths(resultPair.getK2().getClassPaths());
editorModelContent.setOriginalClassName(className);
editorModelContent.setOriginalPackageName(NamingUtils.extractPackageName(className));
// Read the sources for the file being edited.
if (ioService.exists(Paths.convert(path))) {
String source = ioService.readAllString(Paths.convert(path));
editorModelContent.setSource(source);
}
if (resultPair.getK2().hasErrors()) {
editorModelContent.setErrors(serviceHelper.toDataModelerError(resultPair.getK2().getErrors()));
}
editorModelContent.setOverview(overview);
editorModelContent.setElapsedTime(System.currentTimeMillis() - startTime);
if (logger.isDebugEnabled()) {
logger.debug("Time elapsed when loading editor model from:" + path + " : " + editorModelContent.getElapsedTime() + " ms");
}
return editorModelContent;
} catch (Exception e) {
logger.error("Editor model couldn't be loaded from path: " + (path != null ? path.toURI() : path) + ".", e);
throw new ServiceException("Editor model couldn't be loaded from path: " + (path != null ? path.toURI() : path) + ".", e);
}
}
use of org.kie.workbench.common.screens.datamodeller.model.EditorModelContent in project kie-wb-common by kiegroup.
the class DataModelerScreenPresenterObserversTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
// expected title when testObject1 is selected.
testObject1Title = "'TestObject1Label (TestObject1)'" + Constants.INSTANCE.modelEditor_general_properties_label();
// expected tooltip when testObject1 is selected.
testObject1Tooltip = "org.test.TestObject1";
// not relevant for this test.
boolean loadTypesInfo = true;
EditorModelContent content = createContent(loadTypesInfo, false);
when(versionRecordManager.getCurrentPath()).thenReturn(path);
when(modelerService.loadContent(path, loadTypesInfo)).thenReturn(content);
when(javaSourceEditor.getContent()).thenReturn(content.getSource());
// types info is not loaded into the DataModelerWBContext.
when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(false);
// just for convenience, since the DataModelerContext is initialized by taking this definitions from the DMWC.
when(dataModelerWBContext.getAnnotationDefinitions()).thenReturn(testAnnotationDefs);
when(dataModelerWBContext.getPropertyTypes()).thenReturn(testTypeDefs);
// let's the presenter to be initialized properly.
presenter.onStartup(path, placeRequest);
// emulate current editor context is the one loaded into de DataModelerWBContext at this moment.
when(dataModelerWBContext.getActiveContext()).thenReturn(presenter.context);
}
use of org.kie.workbench.common.screens.datamodeller.model.EditorModelContent in project kie-wb-common by kiegroup.
the class DataModelerScreenPresenterTest method loadFileSuccessfulTest.
/**
* Tests that a java file without parse errors was successfully loaded.
* @param loadTypesInfo indicates if the types and annotations definitions loading should be simulated.
*/
private void loadFileSuccessfulTest(boolean loadTypesInfo) {
EditorModelContent content = createContent(loadTypesInfo, false);
when(versionRecordManager.getCurrentPath()).thenReturn(path);
when(modelerService.loadContent(path, loadTypesInfo)).thenReturn(content);
when(javaSourceEditor.getContent()).thenReturn(content.getSource());
if (loadTypesInfo) {
// types info is not loaded into the DataModelerWBContext.
when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(false);
} else {
// types info is already into the DataModelerWBContext.
when(dataModelerWBContext.isTypesInfoLoaded()).thenReturn(true);
}
// just for convenience, since the DataModelerContext is initialized by taking this definitions from the DMWC.
when(dataModelerWBContext.getAnnotationDefinitions()).thenReturn(testAnnotationDefs);
when(dataModelerWBContext.getPropertyTypes()).thenReturn(testTypeDefs);
presenter.onStartup(path, placeRequest);
// Verifications during and after model loading.
verify(view, times(1)).showLoading();
verify(view, times(1)).hideBusyIndicator();
// presenter should ask the DataModelerWBContext if the types info is already loaded.
verify(dataModelerWBContext, times(1)).isTypesInfoLoaded();
if (loadTypesInfo) {
// the types info should have been set into the DataModelerWBContext as part of the presenter loading.
verify(dataModelerWBContext, times(1)).setPropertyTypes(testTypeDefs);
verify(dataModelerWBContext, times(1)).setAnnotationDefinitions(testAnnotationDefs);
} else {
// the types info shouldn't have been set into the DataModelerWBContext as part of the presenter loading.
verify(dataModelerWBContext, times(0)).setPropertyTypes(testTypeDefs);
verify(dataModelerWBContext, times(0)).setAnnotationDefinitions(testAnnotationDefs);
}
// presenter should clear the system messages related to this editor.
verify(unpublishMessagesEvent, times(1)).fire(any(UnpublishMessagesEvent.class));
// presenter should read the expected path.
verify(modelerService, times(1)).loadContent(path, loadTypesInfo);
// verify that the context created by the presenter was properly initialized.
DataModelerContext context = presenter.context;
assertEquals(testModel, context.getDataModel());
assertEquals(testObject1, context.getDataObject());
assertEquals(kieModule, context.getCurrentProject());
assertEquals(testPackages, context.getCurrentProjectPackages());
assertEquals(testAnnotationDefs, context.getAnnotationDefinitions());
assertEquals(content, context.getEditorModelContent());
// the file was read successfully, so the status should be PARSED
assertEquals(DataModelerContext.ParseStatus.PARSED, context.getParseStatus());
// the file was read and parsed successfully, so the editor should be now in the editor tab.
assertEquals(DataModelerContext.EditionMode.GRAPHICAL_MODE, context.getEditionMode());
// file was just read, so the status should be NO_CHANGES.
assertEquals(DataModelerContext.EditionStatus.NO_CHANGES, context.getEditionStatus());
// the view should have been initialized with the context.
verify(view, times(1)).setContext(context);
// the source editor should have been initialized with the source returned form server.
verify(javaSourceEditor, times(1)).setContent(testSource);
// current context should have been activated
verify(dataModelerWBContext, times(1)).setActiveContext(context);
// and notifications should have been sent.
verify(dataModelerFocusEvent, times(1)).fire(any(DataModelerWorkbenchFocusEvent.class));
}
Aggregations