Search in sources :

Example 21 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TranslatorUtil method buildTranslatorMetadata.

public static VDBTranslatorMetaData buildTranslatorMetadata(ExecutionFactory factory, String moduleName) {
    org.teiid.translator.Translator translator = factory.getClass().getAnnotation(org.teiid.translator.Translator.class);
    if (translator == null) {
        return null;
    }
    VDBTranslatorMetaData metadata = new VDBTranslatorMetaData();
    String see = translator.deprecated();
    if (see != null && see.length() > 0) {
        // $NON-NLS-1$
        metadata.addProperty("deprecated", see);
    }
    metadata.setName(translator.name());
    metadata.setDescription(translator.description());
    metadata.setExecutionFactoryClass(factory.getClass());
    metadata.setModuleName(moduleName);
    ExtendedPropertyMetadataList propertyDefns = new ExtendedPropertyMetadataList();
    try {
        Object instance = factory.getClass().newInstance();
        buildTranslatorProperties(factory, metadata, propertyDefns, instance);
        buildExtensionMetadataProperties(factory, metadata, propertyDefns, instance);
    } catch (InstantiationException e) {
    // ignore
    } catch (IllegalAccessException e) {
    // ignore
    }
    metadata.addAttchment(ExtendedPropertyMetadataList.class, propertyDefns);
    return metadata;
}
Also used : VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 22 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TestTranslatorUtil method testBuildExecutionFactory.

@Test
public void testBuildExecutionFactory() throws Exception {
    VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
    tm.addProperty("MyProperty", "correctly-assigned");
    tm.setExecutionFactoryClass(MyTranslator.class);
    MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
    assertEquals("correctly-assigned", my.getMyProperty());
    assertNull(my.other());
    tm.addProperty("other", "foo");
    tm.setExecutionFactoryClass(MyTranslator.class);
    my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
    assertEquals("foo", my.other());
}
Also used : VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) Test(org.junit.Test)

Example 23 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TestTranslatorUtil method testImportProperties.

@Test
public void testImportProperties() throws Exception {
    VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
    tm.setExecutionFactoryClass(MyTranslator.class);
    tm.addProperty("MyProperty", "correctly-assigned");
    MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
    VDBTranslatorMetaData translator = TranslatorUtil.buildTranslatorMetadata(my, "my-module");
    ExtendedPropertyMetadataList props = translator.getAttachment(ExtendedPropertyMetadataList.class);
    ArrayList<ExtendedPropertyMetadata> importProperties = new ArrayList<ExtendedPropertyMetadata>();
    for (ExtendedPropertyMetadata prop : props) {
        if (prop.category().equals(PropertyType.IMPORT.name())) {
            importProperties.add(prop);
        }
    }
    assertEquals(1, importProperties.size());
    assertEquals("importer.ImportProperty", importProperties.get(0).name);
    assertEquals("java.lang.String", importProperties.get(0).dataType);
    assertEquals(false, importProperties.get(0).required);
    assertEquals(false, importProperties.get(0).advanced);
    assertEquals("", importProperties.get(0).description);
    assertEquals("Import Property", importProperties.get(0).displayName);
    assertEquals(true, importProperties.get(0).editable);
    assertEquals(false, importProperties.get(0).masked);
    assertEquals("default-import-property", importProperties.get(0).defaultValue);
}
Also used : ArrayList(java.util.ArrayList) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) Test(org.junit.Test)

Example 24 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TestTranslatorUtil method testBuildExecutionFactoryWithDefaults.

@Test
public void testBuildExecutionFactoryWithDefaults() throws Exception {
    VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
    VDBTranslatorMetaData parent = new VDBTranslatorMetaData();
    parent.addProperty("myProperty", "default");
    parent.setExecutionFactoryClass(MyTranslator.class);
    tm.setParent(parent);
    tm.addProperty("MyProperty", "correctly-assigned");
    MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
    assertEquals("correctly-assigned", my.getMyProperty());
}
Also used : VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) Test(org.junit.Test)

Example 25 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TestTranslatorUtil method testBuildExecutionFactoryCaseInsensitive.

@Test
public void testBuildExecutionFactoryCaseInsensitive() throws Exception {
    VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
    tm.addProperty("myproperty", "correctly-assigned");
    tm.setExecutionFactoryClass(MyTranslator.class);
    MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
    assertEquals("correctly-assigned", my.getMyProperty());
}
Also used : VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) Test(org.junit.Test)

Aggregations

VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)27 Test (org.junit.Test)13 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)6 ExecutionFactory (org.teiid.translator.ExecutionFactory)6 ModelNode (org.jboss.dmr.ModelNode)4 Translator (org.teiid.adminapi.Translator)4 ArrayList (java.util.ArrayList)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)3 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)3 TranslatorException (org.teiid.translator.TranslatorException)3 Properties (java.util.Properties)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 Module (org.jboss.modules.Module)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 TeiidException (org.teiid.core.TeiidException)2 UDFMetaData (org.teiid.deployers.UDFMetaData)2 TeiidConstants.asString (org.teiid.jboss.TeiidConstants.asString)2 IndexMetadataRepository (org.teiid.metadata.index.IndexMetadataRepository)2