Search in sources :

Example 1 with TypeSource

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

the class AsyncPackageDataModelOracleImpl method getTypeSource.

/**
 * Return where a given FactType was defined
 * @param factType
 * @return
 */
@Override
public void getTypeSource(final String factType, final Callback<TypeSource> callback) {
    final TypeSource typeSource = filteredTypeSources.get(factType);
    // Load incremental content
    if (typeSource == null) {
        service.call(new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {

            @Override
            public void callback(final PackageDataModelOracleIncrementalPayload dataModel) {
                AsyncPackageDataModelOracleUtilities.populateDataModelOracle(AsyncPackageDataModelOracleImpl.this, dataModel);
                final TypeSource typeSource = filteredTypeSources.get(factType);
                callback.callback(typeSource);
            }
        }).getUpdates(resourcePath, imports, factType);
    } else {
        callback.callback(typeSource);
    }
}
Also used : PackageDataModelOracleIncrementalPayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleIncrementalPayload) TypeSource(org.kie.soup.project.datamodel.oracle.TypeSource) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Example 2 with TypeSource

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

the class PackageDataModelDeclaredTypesTest method testPackageDeclaredTypes.

@Test
public void testPackageDeclaredTypes() throws Exception {
    final Bean dataModelServiceBean = (Bean) beanManager.getBeans(DataModelService.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(dataModelServiceBean);
    final DataModelService dataModelService = (DataModelService) beanManager.getReference(dataModelServiceBean, DataModelService.class, cc);
    final URL packageUrl = this.getClass().getResource("/DataModelBackendDeclaredTypesTest1/src/main/java/t1p1");
    final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
    final Path packagePath = paths.convert(nioPackagePath);
    final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
    // 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("t1p1");
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setTypeSources(new HashMap<String, TypeSource>() {

        {
            put("t1p1.Bean1", TypeSource.JAVA_PROJECT);
            put("t1p1.DRLBean", TypeSource.DECLARED);
            put("t1p2.Bean2", TypeSource.JAVA_PROJECT);
            put("java.lang.String", TypeSource.JAVA_PROJECT);
            put("int", TypeSource.JAVA_PROJECT);
        }
    });
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertNotNull(dataModel);
    assertEquals(2, oracle.getFactTypes().length);
    PackageDataModelOracleTestUtils.assertContains("Bean1", oracle.getFactTypes());
    PackageDataModelOracleTestUtils.assertContains("DRLBean", oracle.getFactTypes());
    assertEquals(2, oracle.getExternalFactTypes().length);
    PackageDataModelOracleTestUtils.assertContains("t1p2.Bean2", oracle.getExternalFactTypes());
    PackageDataModelOracleTestUtils.assertContains("java.lang.String", oracle.getExternalFactTypes());
    oracle.getTypeSource("Bean1", new Callback<TypeSource>() {

        @Override
        public void callback(final TypeSource result) {
            assertEquals(TypeSource.JAVA_PROJECT, result);
        }
    });
    oracle.getTypeSource("DRLBean", new Callback<TypeSource>() {

        @Override
        public void callback(final TypeSource result) {
            assertEquals(TypeSource.DECLARED, result);
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) TypeSource(org.kie.soup.project.datamodel.oracle.TypeSource) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) CreationalContext(javax.enterprise.context.spi.CreationalContext) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) DataModelService(org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) Test(org.junit.Test)

Aggregations

TypeSource (org.kie.soup.project.datamodel.oracle.TypeSource)2 URL (java.net.URL)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 Bean (javax.enterprise.inject.spi.Bean)1 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1 Test (org.junit.Test)1 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)1 DataModelService (org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService)1 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)1 PackageDataModelOracleIncrementalPayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleIncrementalPayload)1 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)1 Path (org.uberfire.backend.vfs.Path)1