use of org.teiid.adminapi.Translator in project teiid by teiid.
the class TestVDBUtility method validateVDB.
public static void validateVDB(VDBMetaData vdb) {
ModelMetaData modelOne;
ModelMetaData modelTwo;
// $NON-NLS-1$
assertEquals("myVDB", vdb.getName());
// $NON-NLS-1$
assertEquals("vdb description", vdb.getDescription());
assertEquals("connection-type", "NONE", vdb.getConnectionType().name());
assertEquals("1", vdb.getVersion());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("vdb-value", vdb.getPropertyValue("vdb-property"));
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("vdb-value2", vdb.getPropertyValue("vdb-property2"));
// $NON-NLS-1$
assertNotNull(vdb.getModel("model-one"));
// $NON-NLS-1$
assertNotNull(vdb.getModel("model-two"));
// $NON-NLS-1$
assertNull(vdb.getModel("model-unknown"));
assertEquals(1, vdb.getVDBImports().size());
VDBImport vdbImport = vdb.getVDBImports().get(0);
assertEquals("x", vdbImport.getName());
assertEquals("2", vdbImport.getVersion());
// $NON-NLS-1$
modelOne = vdb.getModel("model-one");
// $NON-NLS-1$
assertEquals("model-one", modelOne.getName());
// $NON-NLS-1$
assertEquals("s1", modelOne.getSourceNames().get(0));
assertEquals(Model.Type.PHYSICAL, modelOne.getModelType());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("model-value-override", modelOne.getPropertyValue("model-prop"));
assertFalse(modelOne.isVisible());
assertEquals("model description", modelOne.getDescription());
assertEquals("DDL", modelOne.getSourceMetadataType().get(0));
assertEquals("DDL Here", modelOne.getSourceMetadataText().get(0));
assertEquals("OTHER", modelOne.getSourceMetadataType().get(1));
assertEquals("other text", modelOne.getSourceMetadataText().get(1));
// $NON-NLS-1$
modelTwo = vdb.getModel("model-two");
// $NON-NLS-1$
assertEquals("model-two", modelTwo.getName());
// $NON-NLS-1$
assertTrue(modelTwo.getSourceNames().contains("s1"));
// $NON-NLS-1$
assertTrue(modelTwo.getSourceNames().contains("s2"));
// this is not persisted in the XML
assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("model-value", modelTwo.getPropertyValue("model-prop"));
assertEquals("DDL", modelTwo.getSourceMetadataType().get(0));
assertEquals("DDL Here", modelTwo.getSourceMetadataText().get(0));
// $NON-NLS-1$
assertTrue(vdb.getValidityErrors().contains("There is an error in VDB"));
List<Translator> translators = vdb.getOverrideTranslators();
assertTrue(translators.size() == 1);
Translator translator = translators.get(0);
assertEquals("oracleOverride", translator.getName());
assertEquals("oracle", translator.getType());
assertEquals("my-value", translator.getPropertyValue("my-property"));
assertEquals("hello world", translator.getDescription());
List<DataPolicy> roles = vdb.getDataPolicies();
assertTrue(roles.size() == 1);
// $NON-NLS-1$
DataPolicyMetadata role = vdb.getDataPolicyMap().get("roleOne");
assertTrue(role.isGrantAll());
assertTrue(role.isAllowCreateTemporaryTables());
// $NON-NLS-1$
assertEquals("roleOne described", role.getDescription());
assertNotNull(role.getMappedRoleNames());
// $NON-NLS-1$
assertTrue(role.getMappedRoleNames().contains("ROLE1"));
// $NON-NLS-1$
assertTrue(role.getMappedRoleNames().contains("ROLE2"));
List<DataPolicy.DataPermission> permissions = role.getPermissions();
assertEquals(4, permissions.size());
boolean lang = false;
for (DataPolicy.DataPermission p : permissions) {
if (p.getAllowLanguage() != null) {
assertTrue(p.getAllowLanguage());
assertEquals("javascript", p.getResourceName());
lang = true;
continue;
}
if (p.getResourceName().equalsIgnoreCase("myTable.T1")) {
// $NON-NLS-1$
assertTrue(p.getAllowRead());
assertNull(p.getAllowDelete());
continue;
}
if (p.getResourceName().equalsIgnoreCase("myTable.T2.col1")) {
// $NON-NLS-1$
assertEquals("col2", p.getMask());
assertEquals(1, p.getOrder().intValue());
continue;
}
assertFalse(p.getAllowRead());
assertTrue(p.getAllowDelete());
assertEquals("col1 = user()", p.getCondition());
assertFalse(p.getConstraint());
}
assertTrue(lang);
}
use of org.teiid.adminapi.Translator in project teiid by teiid.
the class VDBService method createConnectorManagers.
private void createConnectorManagers(ConnectorManagerRepository cmr, final TranslatorRepository repo, final VDBMetaData deployment) throws StartException {
final IdentityHashMap<Translator, ExecutionFactory<Object, Object>> map = new IdentityHashMap<Translator, ExecutionFactory<Object, Object>>();
try {
ConnectorManagerRepository.ExecutionFactoryProvider provider = new ConnectorManagerRepository.ExecutionFactoryProvider() {
@Override
public ExecutionFactory<Object, Object> getExecutionFactory(String name) throws ConnectorManagerException {
return TranslatorUtil.getExecutionFactory(name, repo, getTranslatorRepository(), deployment, map, new HashSet<String>());
}
};
cmr.setProvider(provider);
cmr.createConnectorManagers(deployment, provider);
} catch (ConnectorManagerException e) {
if (e.getCause() != null) {
// $NON-NLS-1$
throw new StartException(IntegrationPlugin.Event.TEIID50035.name() + " " + e.getMessage(), e.getCause());
}
throw new StartException(e.getMessage());
}
}
use of org.teiid.adminapi.Translator in project teiid by teiid.
the class TestAdminObjectBuilder method testVDB.
@Test
public void testVDB() {
VDBMetaData vdb = new VDBMetaData();
vdb.setName("myVDB");
vdb.setDescription("vdb description");
vdb.setVersion(1);
vdb.addProperty("vdb-property", "vdb-value");
ModelMetaData modelOne = new ModelMetaData();
modelOne.setName("model-one");
modelOne.addSourceMapping("s1", "translator", "java:mybinding");
modelOne.setModelType(Model.Type.PHYSICAL);
modelOne.addProperty("model-prop", "model-value");
modelOne.addProperty("model-prop", "model-value-override");
modelOne.setVisible(false);
modelOne.addMessage("ERROR", "There is an error in VDB");
modelOne.setDescription("model description");
vdb.addModel(modelOne);
ModelMetaData modelTwo = new ModelMetaData();
modelTwo.setName("model-two");
modelTwo.addSourceMapping("s1", "translator", "java:binding-one");
modelTwo.addSourceMapping("s2", "translator", "java:binding-two");
modelTwo.setModelType(Model.Type.VIRTUAL);
modelTwo.addProperty("model-prop", "model-value");
vdb.addModel(modelTwo);
VDBTranslatorMetaData t1 = new VDBTranslatorMetaData();
t1.setName("oracleOverride");
t1.setType("oracle");
t1.addProperty("my-property", "my-value");
List<Translator> list = new ArrayList<Translator>();
list.add(t1);
vdb.setOverrideTranslators(list);
DataPolicyMetadata roleOne = new DataPolicyMetadata();
roleOne.setName("roleOne");
roleOne.setDescription("roleOne described");
PermissionMetaData perm1 = new PermissionMetaData();
perm1.setResourceName("myTable.T1");
perm1.setAllowRead(true);
roleOne.addPermission(perm1);
PermissionMetaData perm2 = new PermissionMetaData();
perm2.setResourceName("myTable.T2");
perm2.setAllowRead(false);
perm2.setAllowDelete(true);
roleOne.addPermission(perm2);
roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2"));
vdb.addDataPolicy(roleOne);
// convert to managed object and build the VDB out of MO
ModelNode node = VDBMetadataMapper.INSTANCE.wrap(vdb, new ModelNode());
vdb = VDBMetadataMapper.INSTANCE.unwrap(node);
assertEquals("myVDB", vdb.getName());
assertEquals("vdb description", vdb.getDescription());
assertEquals("1", vdb.getVersion());
assertEquals("vdb-value", vdb.getPropertyValue("vdb-property"));
assertNotNull(vdb.getModel("model-one"));
assertNotNull(vdb.getModel("model-two"));
assertNull(vdb.getModel("model-unknown"));
modelOne = vdb.getModel("model-one");
assertEquals("model-one", modelOne.getName());
assertEquals("s1", modelOne.getSourceNames().get(0));
assertEquals(Model.Type.PHYSICAL, modelOne.getModelType());
assertEquals("model-value-override", modelOne.getPropertyValue("model-prop"));
assertFalse(modelOne.isVisible());
assertEquals("model description", modelOne.getDescription());
modelTwo = vdb.getModel("model-two");
assertEquals("model-two", modelTwo.getName());
assertTrue(modelTwo.getSourceNames().contains("s1"));
assertTrue(modelTwo.getSourceNames().contains("s2"));
// this is not persisted in the XML
assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType());
assertEquals("model-value", modelTwo.getPropertyValue("model-prop"));
assertTrue(vdb.getValidityErrors().contains("There is an error in VDB"));
List<Translator> translators = vdb.getOverrideTranslators();
assertTrue(translators.size() == 1);
Translator translator = translators.get(0);
assertEquals("oracleOverride", translator.getName());
assertEquals("oracle", translator.getType());
assertEquals("my-value", translator.getPropertyValue("my-property"));
List<DataPolicy> roles = vdb.getDataPolicies();
assertTrue(roles.size() == 1);
DataPolicyMetadata role = vdb.getDataPolicyMap().get("roleOne");
assertEquals("roleOne described", role.getDescription());
assertNotNull(role.getMappedRoleNames());
assertTrue(role.getMappedRoleNames().contains("ROLE1"));
assertTrue(role.getMappedRoleNames().contains("ROLE2"));
List<DataPolicy.DataPermission> permissions = role.getPermissions();
assertEquals(2, permissions.size());
for (DataPolicy.DataPermission p : permissions) {
if (p.getResourceName().equalsIgnoreCase("myTable.T1")) {
assertTrue(p.getAllowRead());
assertNull(p.getAllowDelete());
} else {
assertFalse(p.getAllowRead());
assertTrue(p.getAllowDelete());
}
}
}
use of org.teiid.adminapi.Translator in project teiid by teiid.
the class TestVDBService method testMissingDelegate.
@Test(expected = ConnectorManagerException.class)
public void testMissingDelegate() throws ConnectorManagerException {
TranslatorRepository repo = new TranslatorRepository();
VDBTranslatorMetaData tmd = new VDBTranslatorMetaData();
Properties props = new Properties();
props.put("delegateName", "y");
tmd.setProperties(props);
tmd.setExecutionFactoryClass(SampleExecutionFactory.class);
repo.addTranslatorMetadata("x", tmd);
TranslatorUtil.getExecutionFactory("x", repo, repo, new VDBMetaData(), new IdentityHashMap<Translator, ExecutionFactory<Object, Object>>(), new HashSet<String>());
}
Aggregations