Search in sources :

Example 11 with Annotation

use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.

the class PackageDataModelFactFieldsAnnotationsTest method testIncorrectPackageDMOZeroAnnotationAttributes.

@Test
public void testIncorrectPackageDMOZeroAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Product.class, false, TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO. Defaults to defaultpkg
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator());
    packageBuilder.setModuleOracle(moduleLoader);
    final PackageDataModelOracle packageLoader = packageBuilder.build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
    dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(0, oracle.getFactTypes().length);
    oracle.getTypeFieldsAnnotations("Product", new Callback<Map<String, Set<Annotation>>>() {

        @Override
        public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
            assertNotNull(fieldsAnnotations);
            assertEquals(0, fieldsAnnotations.size());
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) Set(java.util.Set) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Map(java.util.Map) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 12 with Annotation

use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.

the class PackageDataModelFactFieldsAnnotationsTest method testCorrectPackageDMOZeroAnnotationAttributes.

@Test
public void testCorrectPackageDMOZeroAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Product.class, false, TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
    packageBuilder.setModuleOracle(moduleLoader);
    final PackageDataModelOracle packageLoader = packageBuilder.build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
    dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("Product", oracle.getFactTypes()[0]);
    oracle.getTypeFieldsAnnotations("Product", new Callback<Map<String, Set<Annotation>>>() {

        @Override
        public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
            assertNotNull(fieldsAnnotations);
            assertEquals(0, fieldsAnnotations.size());
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) Set(java.util.Set) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Map(java.util.Map) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 13 with Annotation

use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.

the class ClassFactBuilder method loadClassFields.

private void loadClassFields(final Class<?> clazz, final Map<String, FactBuilder> discoveredFieldFactBuilders) throws IOException {
    if (clazz == null) {
        return;
    }
    final String factType = getType();
    // Get all getters and setters for the class. This does not handle delegated properties
    // - FIELDS need a getter ("getXXX", "isXXX") or setter ("setXXX") or are public properties
    // - METHODS are any accessor that does not have a getter or setter
    final ClassFieldInspector inspector = new ClassFieldInspector(clazz);
    final Set<String> fieldNames = inspector.getFieldNames();
    for (final String fieldName : fieldNames) {
        final ClassFieldInspector.FieldInfo f = inspector.getFieldTypesFieldInfo().get(fieldName);
        addParametricTypeForField(factType, fieldName, f.getGenericType());
        final Class<?> returnType = f.getReturnType();
        final String genericReturnType = typeSystemConverter.translateClassToGenericType(returnType);
        addField(new ModelField(fieldName, returnType.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, f.getOrigin(), f.getAccessorAndMutator(), genericReturnType));
        addEnumsForField(factType, fieldName, returnType);
        // To prevent recursion we keep track of all ClassFactBuilder's created and re-use where applicable
        if (BlackLists.isReturnTypeBlackListed(returnType)) {
            continue;
        }
        discoverFieldFactBuilder(genericReturnType, returnType, discoveredFieldFactBuilders);
        // Check types on generic arguments
        if (f.getGenericType() instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) f.getGenericType();
            for (Type parameterType : parameterizedType.getActualTypeArguments()) {
                if (discoveredFieldFactBuilders.containsKey(parameterType.getTypeName())) {
                    continue;
                }
                if (parameterType instanceof Class) {
                    Class<?> parameterClazz = (Class<?>) parameterType;
                    discoverFieldFactBuilder(parameterClazz.getName(), parameterClazz, discoveredFieldFactBuilders);
                }
            }
        }
        Set<Annotation> fieldAnnotations = f.getAnnotations();
        if (fieldAnnotations != null && !fieldAnnotations.isEmpty()) {
            this.fieldAnnotations.put(fieldName, f.getAnnotations());
        }
    }
    // Methods for use in Expressions and ActionCallMethod's
    ClassMethodInspector methodInspector = new ClassMethodInspector(clazz, typeSystemConverter);
    final List<MethodInfo> methodInformation = methodInspector.getMethodInfos();
    for (final MethodInfo mi : methodInformation) {
        final String genericType = mi.getParametricReturnType();
        if (genericType != null) {
            final String qualifiedFactFieldName = factType + "#" + mi.getNameWithParameters();
            this.fieldParametersType.put(qualifiedFactFieldName, genericType);
        }
    }
    this.methodInformation.put(factType, methodInformation);
}
Also used : Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo)

Example 14 with Annotation

use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.

the class ModuleDataModelFactAnnotationsTest method testModuleDMOZeroAnnotationAttributes.

@Test
public void testModuleDMOZeroAnnotationAttributes() throws Exception {
    final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(builder, Product.class, false, TypeSource.JAVA_PROJECT);
    cb.build(oracle);
    assertEquals(1, oracle.getModuleModelFields().size());
    assertContains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product", oracle.getModuleModelFields().keySet());
    final Set<Annotation> annotations = oracle.getModuleTypeAnnotations().get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product");
    assertNotNull(annotations);
    assertEquals(0, annotations.size());
}
Also used : RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) Test(org.junit.Test)

Example 15 with Annotation

use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.

the class ModuleDataModelFactAnnotationsTest method annotationsWithMemberOfTypeClass.

@Test
public void annotationsWithMemberOfTypeClass() throws Exception {
    final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(builder, JAXBSmurf.class, false, TypeSource.JAVA_PROJECT);
    cb.build(oracle);
    assertEquals(1, oracle.getModuleModelFields().size());
    assertContains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.JAXBSmurf", oracle.getModuleModelFields().keySet());
    final Set<Annotation> annotations = oracle.getModuleTypeAnnotations().get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.JAXBSmurf");
    assertNotNull(annotations);
    assertEquals(1, annotations.size());
    final Annotation annotation = annotations.iterator().next();
    assertEquals("javax.xml.bind.annotation.XmlType", annotation.getQualifiedTypeName());
    assertEquals(5, annotation.getParameters().size());
    assertEquals("smurf-namespace", annotation.getParameters().get("namespace"));
    assertEquals("smurf-xsd", annotation.getParameters().get("name"));
    assertArraysEqual(new String[] { "name", "colour" }, (String[]) annotation.getParameters().get("propOrder"));
    assertTrue(annotation.getParameters().get("factoryClass").toString().contains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.JAXBSmurfFactory"));
}
Also used : RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) Test(org.junit.Test)

Aggregations

Annotation (org.kie.soup.project.datamodel.oracle.Annotation)18 Test (org.junit.Test)14 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)14 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)14 ClassFactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)14 ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)14 Set (java.util.Set)11 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)9 PackageDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)9 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)9 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)9 Path (org.uberfire.backend.vfs.Path)9 Map (java.util.Map)5 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 ConstraintViolation (javax.validation.ConstraintViolation)1