use of org.teiid.adminapi.DataPolicy 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.DataPolicy in project teiid by teiid.
the class CompositeVDB method buildCompositeState.
private void buildCompositeState(VDBRepository vdbRepository) throws VirtualDatabaseException {
if (vdb.getVDBImports().isEmpty()) {
this.vdb.addAttchment(ConnectorManagerRepository.class, this.cmr);
return;
}
VDBMetaData newMergedVDB = this.vdb.clone();
ConnectorManagerRepository mergedRepo = this.cmr;
if (!this.cmr.isShared()) {
mergedRepo = new ConnectorManagerRepository();
mergedRepo.getConnectorManagers().putAll(this.cmr.getConnectorManagers());
}
newMergedVDB.addAttchment(ConnectorManagerRepository.class, mergedRepo);
ClassLoader[] toSearch = new ClassLoader[vdb.getVDBImports().size() + 1];
toSearch[0] = this.vdb.getAttachment(ClassLoader.class);
this.children = new LinkedHashMap<VDBKey, CompositeVDB>();
newMergedVDB.setImportedModels(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER));
int i = 1;
for (VDBImport vdbImport : vdb.getVDBImports()) {
VDBKey key = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
if (key.isAtMost()) {
// TODO: could allow partial versions
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, vdbKey, key));
}
CompositeVDB importedVDB = vdbRepository.getCompositeVDB(key);
if (importedVDB == null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40083, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40083, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion()));
}
VDBMetaData childVDB = importedVDB.getVDB();
newMergedVDB.getVisibilityOverrides().putAll(childVDB.getVisibilityOverrides());
toSearch[i++] = childVDB.getAttachment(ClassLoader.class);
this.children.put(importedVDB.getVDBKey(), importedVDB);
if (vdbImport.isImportDataPolicies()) {
for (DataPolicy dp : importedVDB.getVDB().getDataPolicies()) {
DataPolicyMetadata role = (DataPolicyMetadata) dp;
if (newMergedVDB.addDataPolicy(role) != null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40084, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40084, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), role.getName()));
}
if (role.isGrantAll()) {
role.setSchemas(childVDB.getModelMetaDatas().keySet());
}
}
}
// add models
for (ModelMetaData m : childVDB.getModelMetaDatas().values()) {
if (newMergedVDB.addModel(m) != null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40085, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40085, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), m.getName()));
}
newMergedVDB.getImportedModels().add(m.getName());
// $NON-NLS-1$
String visibilityOverride = newMergedVDB.getPropertyValue(m.getName() + ".visible");
if (visibilityOverride != null) {
boolean visible = Boolean.valueOf(visibilityOverride);
newMergedVDB.setVisibilityOverride(m.getName(), visible);
}
}
ConnectorManagerRepository childCmr = childVDB.getAttachment(ConnectorManagerRepository.class);
if (childCmr == null) {
// $NON-NLS-1$
throw new AssertionError("childVdb does not have a connector manager repository");
}
if (!this.cmr.isShared()) {
for (Map.Entry<String, ConnectorManager> entry : childCmr.getConnectorManagers().entrySet()) {
if (mergedRepo.getConnectorManagers().put(entry.getKey(), entry.getValue()) != null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40086, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40086, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), entry.getKey()));
}
}
}
}
if (toSearch[0] != null) {
CombinedClassLoader ccl = new CombinedClassLoader(toSearch[0].getParent(), toSearch);
this.mergedVDB.addAttchment(ClassLoader.class, ccl);
}
this.mergedVDB = newMergedVDB;
}
Aggregations