use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class DataObjectAnnotationValueChangeCommand method execute.
@Override
public void execute() {
Object oldValue = null;
Annotation annotation = dataObject.getAnnotation(annotationClassName);
if (annotation != null) {
oldValue = annotation.getValue(valuePair);
if (newValue != null && !newValue.equals(oldValue)) {
// notify annotation value change
annotation.setValue(valuePair, newValue);
notifyObjectChange(ChangeType.TYPE_ANNOTATION_VALUE_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
} else if (newValue == null && oldValue != null) {
if (removeAnnotationIfValueIsNull) {
dataObject.removeAnnotation(annotationClassName);
// notify annotation removed
notifyObjectChange(ChangeType.TYPE_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
} else {
annotation.setValue(valuePair, newValue);
// notify annotation value change
notifyObjectChange(ChangeType.TYPE_ANNOTATION_VALUE_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
}
}
} else if (newValue != null) {
annotation = new AnnotationImpl(context.getAnnotationDefinitions().get(annotationClassName));
annotation.setValue(valuePair, newValue);
dataObject.addAnnotation(annotation);
// notify annotation added
notifyObjectChange(ChangeType.TYPE_ANNOTATION_ADD_CHANGE, context, source, dataObject, annotationClassName, valuePair, oldValue, newValue);
}
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class FieldAnnotationValueChangeCommand method execute.
@Override
public void execute() {
Object oldValue = null;
Annotation annotation = field.getAnnotation(annotationClassName);
if (annotation != null) {
oldValue = annotation.getValue(valuePair);
if (newValue != null && !newValue.equals(oldValue)) {
// notify annotation value change
annotation.setValue(valuePair, newValue);
notifyFieldChange(ChangeType.FIELD_ANNOTATION_VALUE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
} else if (newValue == null) {
if (removeAnnotationIfValueIsNull) {
field.removeAnnotation(annotationClassName);
// notify annotation removed
notifyFieldChange(ChangeType.FIELD_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
} else {
// annotations do not support nulls for the value paris, so just remove the value pair.
annotation.removeValue(valuePair);
// notify annotation value change
notifyFieldChange(ChangeType.FIELD_ANNOTATION_VALUE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
}
}
} else if (newValue != null) {
annotation = new AnnotationImpl(context.getAnnotationDefinitions().get(annotationClassName));
annotation.setValue(valuePair, newValue);
field.addAnnotation(annotation);
// notify annotation added
notifyFieldChange(ChangeType.FIELD_ANNOTATION_ADD_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
}
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method modelReadTest.
@Test
public void modelReadTest() {
try {
final SourceFilter pojo1Filter = javaType -> false;
final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
FilterHolder filterHolder = mock(FilterHolder.class);
when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, getClass().getClassLoader(), filterHolder);
ModelDriverResult modelDriverResult = javaRoasterModelDriver.loadModel();
DataModel dataModelOriginal = createModel();
assertNotNull(modelDriverResult);
assertNotNull(modelDriverResult.getDataModel());
assertEquals(dataModelOriginal.getDataObjects().size(), modelDriverResult.getDataModel().getDataObjects().size());
for (DataObject dataObject : dataModelOriginal.getDataObjects()) {
DataModelerAssert.assertEqualsDataObject(dataObject, modelDriverResult.getDataModel().getDataObject(dataObject.getClassName()));
}
for (JavaEnum javaEnum : dataModelOriginal.getJavaEnums()) {
DataModelerAssert.assertEqualsJavaEnum(javaEnum, modelDriverResult.getDataModel().getJavaEnum(javaEnum.getClassName()));
}
org.uberfire.backend.vfs.Path errorFile1 = Paths.convert(rootPath.resolve(ERROR_FILE1));
org.uberfire.backend.vfs.Path errorFile2 = Paths.convert(rootPath.resolve(ERROR_FILE2));
verifyErrorFilesWereDetected(modelDriverResult, errorFile1, errorFile2);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed: " + e.getMessage());
}
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method createEnumsAnnotationTest.
private DataObject createEnumsAnnotationTest() {
DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package3", "EnumsAnnotationTest", null);
ObjectProperty field1 = dataObject.addProperty("field1", String.class.getName());
Annotation annotation = createEnumsAnnotation();
dataObject.addAnnotation(annotation);
field1.addAnnotation(annotation);
return dataObject;
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method importsUpdateTest.
@Test
public void importsUpdateTest() throws Exception {
Path importsUpdateTestFilePath = rootPath.resolve("package6").resolve("ImportsUpdateTest.java");
String source = ioService.readAllString(importsUpdateTestFilePath);
JavaClassSource importsUpdateTestJavaClassSource = (JavaClassSource) Roaster.parse(source);
ClassLoader classLoader = getClass().getClassLoader();
ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(importsUpdateTestJavaClassSource, classLoader);
final SourceFilter pojo1Filter = javaType -> false;
final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
FilterHolder filterHolder = mock(FilterHolder.class);
when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, classLoader, filterHolder);
ModelDriverResult result = javaRoasterModelDriver.loadDataObject(source, importsUpdateTestFilePath);
DataObject importsUpdateTest = result.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTest");
importsUpdateTest.addImport(new ImportImpl(List.class.getName()));
importsUpdateTest.addImport(new ImportImpl(ArrayList.class.getName()));
importsUpdateTest.setName("ImportsUpdateTestResult");
Path expectedFilePath = rootPath.resolve("package6").resolve("ImportsUpdateTestResult.java");
String expectedSource = ioService.readAllString(expectedFilePath);
ModelDriverResult expectedResult = javaRoasterModelDriver.loadDataObject(expectedSource, expectedFilePath);
DataObject importsUpdateTestResult = expectedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTestResult");
DataModelerAssert.assertEqualsDataObject(importsUpdateTestResult, importsUpdateTest);
DataModelerAssert.assertEqualsImports(importsUpdateTestResult.getImports(), importsUpdateTest.getImports());
javaRoasterModelDriver.updateSource(importsUpdateTestJavaClassSource, importsUpdateTest, new UpdateInfo(), classTypeResolver);
ModelDriverResult updatedResult = javaRoasterModelDriver.loadDataObject(importsUpdateTestJavaClassSource.toString(), importsUpdateTestFilePath);
DataModelerAssert.assertEqualsDataObject(importsUpdateTestResult, updatedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTestResult"));
DataModelerAssert.assertEqualsImports(importsUpdateTestResult.getImports(), updatedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package6.ImportsUpdateTestResult").getImports());
}
Aggregations