use of org.kie.workbench.common.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method loadModel.
private Pair<DataModel, ModelDriverResult> loadModel(final KieModule module, boolean processErrors) {
if (logger.isDebugEnabled()) {
logger.debug("Loading data model from path: " + module.getRootPath());
}
Long startTime = System.currentTimeMillis();
DataModel dataModel = null;
Path modulePath = null;
Package defaultPackage = null;
try {
modulePath = module.getRootPath();
defaultPackage = moduleService.resolveDefaultPackage(module);
if (logger.isDebugEnabled()) {
logger.debug("Current module path is: " + modulePath);
}
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(module);
ModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(defaultPackage.getPackageMainSrcPath()), classLoader, filterHolder);
ModelDriverResult result = modelDriver.loadModel();
dataModel = result.getDataModel();
if (processErrors && result.hasErrors()) {
processErrors(module, result);
}
// by now we still use the DMO to calculate module external dependencies.
ModuleDataModelOracle moduleDataModelOracle = dataModelService.getModuleDataModel(modulePath);
ModuleDataModelOracleUtils.loadExternalDependencies(dataModel, moduleDataModelOracle, classLoader);
Long endTime = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Time elapsed when loading " + modulePath.getFileName() + ": " + (endTime - startTime) + " ms");
}
return new Pair<DataModel, ModelDriverResult>(dataModel, result);
} catch (Exception e) {
logger.error("Data model couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
throw new ServiceException("Data model couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
}
}
use of org.kie.workbench.common.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method updateDataObject.
/**
* Updates data object provided in the dataObject parameter with the Java code provided in the source parameter.
* This method does not write changes in the file system.
* @param dataObject Data object definition to be updated.
* @param source Java code to use for the update.
* @param path Path to the java file. (used for error messages adf)
* @return returns a GenerationResult object with the updated data object and the source and path parameter as is.
*/
@Override
public GenerationResult updateDataObject(final DataObject dataObject, final String source, final Path path) {
// Resolve the dataobject update in memory
GenerationResult result = new GenerationResult();
KieModule module;
try {
result.setSource(source);
module = moduleService.resolveModule(path);
if (module == null) {
logger.warn("File : " + path.toURI() + " do not belong to a valid module");
result.setSource(source);
return result;
}
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(module);
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(path), classLoader, filterHolder);
ModelDriverResult driverResult = modelDriver.loadDataObject(source, Paths.convert(path));
if (driverResult.hasErrors()) {
result.setErrors(serviceHelper.toDataModelerError(driverResult.getErrors()));
} else {
if (driverResult.getDataModel().getDataObjects().size() > 0) {
result.setDataObject(driverResult.getDataModel().getDataObjects().iterator().next());
}
}
return result;
} catch (Exception e) {
logger.error("Source file for data object: " + dataObject.getClassName() + ", couldn't be parsed", e);
throw new ServiceException("Source file for data object: " + dataObject.getClassName() + ", couldn't be parsed", e);
}
}
use of org.kie.workbench.common.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class FormGenerationIntegrationTest method testNestedFormsGeneration.
@Test
public void testNestedFormsGeneration() {
when(module.getRootPath()).thenReturn(rootPathWithoutNestedForms);
ModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(rootPathWithoutNestedForms), moduleClassLoader, filterHolder);
try {
ModelDriverResult result = modelDriver.loadModel();
dataModel = result.getDataModel();
} catch (ModelDriverException e) {
throw new ServiceException("It was not possible to load model for URI: " + rootPathWithoutNestedForms.toURI(), e);
}
when(dataModelerService.loadModel(module)).thenReturn(dataModel);
when(commentedOptionFactory.makeCommentedOption(any())).thenReturn(commentedOption);
final FormGenerationResult formGenerationResult = generateForm("FormGenerationTest_TwinTasks-taskform.frm", taskFormModels.get(4));
final List<String> expectedDataObjectFormFields = Arrays.asList("nestedObjectForSubform", SUBFORM_FIELDTYPE, "nestedObjectListForMultipleSubform", MULTIPLESUBFORM_FIELDTYPE, "bigDecimalDecimalBox", DECIMALBOX_FIELDTYPE, "bigIntegerIntegerBox", INTEGERBOX_FIELDTYPE, "booleanCheckBox", CHECKBOX_FIELDTYPE, "byteIntegerBox", INTEGERBOX_FIELDTYPE, "charTextBox", TEXTBOX_FIELDTYPE, "dateDatePicker", DATEPICKER_FIELDTYPE, "doubleDecimalBox", DECIMALBOX_FIELDTYPE, "floatDecimalBox", DECIMALBOX_FIELDTYPE, "longIntegerBox", INTEGERBOX_FIELDTYPE, "stringListBox", TEXTBOX_FIELDTYPE, "intIntegerBox", INTEGERBOX_FIELDTYPE, "shortIntegerBox", INTEGERBOX_FIELDTYPE, "bigDecimalRadioGroup", DECIMALBOX_FIELDTYPE, "bigIntegerRadioGroup", INTEGERBOX_FIELDTYPE, "byteRadioGroup", INTEGERBOX_FIELDTYPE, "charRadioGroup", TEXTBOX_FIELDTYPE, "doubleSlider", DECIMALBOX_FIELDTYPE, "doubleRadioGroup", DECIMALBOX_FIELDTYPE, "floatRadioGroup", DECIMALBOX_FIELDTYPE, "intRadioGroup", INTEGERBOX_FIELDTYPE, "intSlider", INTEGERBOX_FIELDTYPE, "longRadioGroup", INTEGERBOX_FIELDTYPE, "stringPicture", TEXTBOX_FIELDTYPE, "stringRadioGroup", TEXTBOX_FIELDTYPE, "stringTextArea", TEXTBOX_FIELDTYPE, "stringTextBox", TEXTBOX_FIELDTYPE, "shortRadioGroup", INTEGERBOX_FIELDTYPE);
final List<String> expectedNestedDataObjectFormFields = Arrays.asList("stringListBox", TEXBOX_FIELDTYPE, "doubleDecimalBox", DECIMALBOX_FIELDTYPE, "booleanCheckBox", CHECKBOX_FIELDTYPE, "dateDatePicker", DATEPICKER_FIELDTYPE, "charRadioGroup", TEXTBOX_FIELDTYPE, "doubleSlider", DECIMALBOX_FIELDTYPE, "intIntegerBox", INTEGERBOX_FIELDTYPE, "stringPicture", TEXBOX_FIELDTYPE, "stringTextArea", TEXTBOX_FIELDTYPE, "stringTextBox", TEXTBOX_FIELDTYPE);
final FormDefinition rootForm = formGenerationResult.getRootForm();
final List<FormDefinition> nestedForms = formGenerationResult.getNestedForms();
final FormDefinition dataObjectForm = nestedForms.get(0);
final FormDefinition nestedDataObjectForm = nestedForms.get(1);
final String dataObjectFormID = dataObjectForm.getId();
testNestedFormsHaveCorrectId(rootForm, "_dataObject1", dataObjectFormID);
testNestedFormsHaveCorrectId(rootForm, "_dataObject2", dataObjectFormID);
testNestedFormsHaveCorrectId(rootForm, "dataObject_", dataObjectFormID);
final String nestedDataObjectFormID = nestedDataObjectForm.getId();
testFormDefinition(dataObjectForm, expectedDataObjectFormFields);
testNestedFormsHaveCorrectId(dataObjectForm, "nestedObjectForSubform", nestedDataObjectFormID);
testFormDefinition(nestedDataObjectForm, expectedNestedDataObjectFormFields);
}
use of org.kie.workbench.common.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method createJavaFile.
@Override
public Path createJavaFile(final Path context, final String fileName, final String comment, final Map<String, Object> options) {
final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName);
final Path newPath = Paths.convert(nioPath);
if (ioService.exists(nioPath)) {
throw new FileAlreadyExistsException(nioPath.toString());
}
try {
final Package currentPackage = moduleService.resolvePackage(context);
String packageName = currentPackage.getPackageName();
String className = fileName.substring(0, fileName.indexOf(".java"));
final KieModule currentModule = moduleService.resolveModule(context);
DataObject dataObject = new DataObjectImpl(packageName, className);
Iterator<DomainHandler> it = domainHandlers != null ? domainHandlers.iterator() : null;
while (it != null && it.hasNext()) {
it.next().setDefaultValues(dataObject, options);
}
String source = createJavaSource(dataObject);
ioService.write(nioPath, source, serviceHelper.makeCommentedOption(comment));
dataObjectCreatedEvent.fire(new DataObjectCreatedEvent(currentModule, dataObject));
return newPath;
} catch (Exception e) {
// uncommon error.
logger.error("It was not possible to create Java file, for path: " + context.toURI() + ", fileName: " + fileName, e);
throw new ServiceException("It was not possible to create Java file, for path: " + context.toURI() + ", fileName: " + fileName, e);
}
}
use of org.kie.workbench.common.screens.datamodeller.service.ServiceException 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);
}
}
Aggregations