use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver 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.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method updateJavaClassSource.
private void updateJavaClassSource(DataObject dataObject, JavaClassSource javaClassSource, Map<String, String> renames, List<String> deletions, ClassTypeResolver classTypeResolver) throws Exception {
if (javaClassSource == null || !javaClassSource.isClass()) {
logger.warn("A null javaClassSource or javaClassSouce is not a Class, no processing will be done. javaClassSource: " + javaClassSource + " className: " + (javaClassSource != null ? javaClassSource.getName() : null));
return;
}
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver(filterHolder);
UpdateInfo updateInfo = new UpdateInfo();
if (renames != null) {
for (Map.Entry<String, String> entry : renames.entrySet()) {
updateInfo.addClassRename(entry.getKey(), entry.getValue());
}
}
if (deletions != null) {
for (String deletion : deletions) {
updateInfo.addDeletedClass(deletion);
}
}
modelDriver.updateSource(javaClassSource, dataObject, updateInfo, classTypeResolver);
}
use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method resolveParseRequest.
@Override
public AnnotationParseResponse resolveParseRequest(AnnotationParseRequest parseRequest, KieModule kieModule) {
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
Pair<Annotation, List<DriverError>> driverResult = modelDriver.parseAnnotationWithValuePair(parseRequest.getAnnotationClassName(), parseRequest.getTarget(), parseRequest.getValuePairName(), parseRequest.getValuePairLiteralValue(), classLoaderHelper.getModuleClassLoader(kieModule));
AnnotationParseResponse response = new AnnotationParseResponse(driverResult.getK1());
response.withErrors(driverResult.getK2());
return response;
}
use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method getAnnotationDefinitions.
@Override
public Map<String, AnnotationDefinition> getAnnotationDefinitions() {
Map<String, AnnotationDefinition> annotations = new HashMap<String, AnnotationDefinition>();
// add additional annotations configured by external domains
Iterator<DomainHandler> it = domainHandlers != null ? domainHandlers.iterator() : null;
DomainHandler domainHandler;
List<List<AnnotationDefinition>> allDomainsAnnotations = new ArrayList<List<AnnotationDefinition>>();
while (it != null && it.hasNext()) {
domainHandler = it.next();
allDomainsAnnotations.add(domainHandler.getManagedAnnotations());
}
List<AnnotationDefinition> coreAnnotationDefinitions = (new JavaRoasterModelDriver()).getConfiguredAnnotations();
allDomainsAnnotations.add(coreAnnotationDefinitions);
for (List<AnnotationDefinition> annotationDefinitionList : allDomainsAnnotations) {
if (annotationDefinitionList != null) {
for (AnnotationDefinition annotationDefinition : annotationDefinitionList) {
annotations.put(annotationDefinition.getClassName(), annotationDefinition);
}
}
}
return annotations;
}
use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method resolveSaveSource.
private GenerationResult resolveSaveSource(final String source, final Path path, final DataObject dataObject) {
GenerationResult result = new GenerationResult();
KieModule module;
String updatedSource;
try {
module = moduleService.resolveModule(path);
if (module == null) {
logger.warn("File : " + path.toURI() + " do not belong to a valid module");
result.setSource(source);
return result;
}
if (dataObject != null) {
// the source needs to be updated with the DataObject definition prior to save
result = updateSource(source, path, dataObject);
updatedSource = result.getSource();
} else {
// if the dataObject wasn't provided the source is already prepared to be saved and likely
// it's not parsed at the ui. So we will save the provided source and try to parse the data object
updatedSource = source;
}
if (dataObject == null) {
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());
}
}
}
result.setSource(updatedSource);
return result;
} catch (Exception e) {
logger.error("Source file couldn't be updated, path: " + path.toURI() + ", dataObject: " + (dataObject != null ? dataObject.getClassName() : null) + ".", e);
throw new ServiceException("Source file couldn't be updated, path: " + path.toURI() + ", dataObject: " + (dataObject != null ? dataObject.getClassName() : null) + ".", e);
}
}
Aggregations