[teiid-commits] teiid SVN: r1972 - in trunk/client/src: main/java/org/teiid/adminapi/impl and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Mar 17 12:46:00 EDT 2010


Author: rareddy
Date: 2010-03-17 12:45:58 -0400 (Wed, 17 Mar 2010)
New Revision: 1972

Added:
   trunk/client/src/main/java/org/teiid/adminapi/DataRole.java
Removed:
   trunk/client/src/main/java/org/teiid/adminapi/impl/ReferenceMappingMetadata.java
Modified:
   trunk/client/src/main/java/org/teiid/adminapi/VDB.java
   trunk/client/src/main/java/org/teiid/adminapi/impl/DataRoleMetadata.java
   trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
   trunk/client/src/main/resources/vdb-deployer.xsd
   trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
Log:
TEIID-1017: Step :1 Adding support to read data roles from VDB.xml file.

Added: trunk/client/src/main/java/org/teiid/adminapi/DataRole.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/DataRole.java	                        (rev 0)
+++ trunk/client/src/main/java/org/teiid/adminapi/DataRole.java	2010-03-17 16:45:58 UTC (rev 1972)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.adminapi;
+
+import java.util.List;
+
+public interface DataRole {
+	/**
+	 * Get the Name of the Data Role
+	 * @return
+	 */
+	String getName();
+	
+	/**
+	 * Get the description of the Data Role
+	 * @return
+	 */
+	String getDescription();
+	
+	/**
+	 * Get the List of Permissions for this Data Role.
+	 * @return
+	 */
+	List<Permission> getPermissions();
+	
+	/**
+	 * Mapped Container Role names for this Data Role
+	 * @return
+	 */
+	List<String> getMappedRoleNames();
+	
+	
+	interface Permission {
+		/**
+		 * Get the Resource Name that Data Role representing
+		 * @return
+		 */
+		String getResourceName();
+		
+		/**
+		 * Is "CREATE" allowed?
+		 * @return
+		 */
+		boolean isAllowCreate();
+		
+		/**
+		 * Is "SELECT" allowed?
+		 * @return
+		 */
+		boolean isAllowRead();
+		
+		/**
+		 * Is "INSERT/UPDATE" allowed?
+		 * @return
+		 */
+		boolean isAllowUpdate();
+		
+		/**
+		 * Is "DELETE" allowed?
+		 * @return
+		 */
+		boolean isAllowDelete();		
+	}
+}


Property changes on: trunk/client/src/main/java/org/teiid/adminapi/DataRole.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/client/src/main/java/org/teiid/adminapi/VDB.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/VDB.java	2010-03-16 21:55:06 UTC (rev 1971)
+++ trunk/client/src/main/java/org/teiid/adminapi/VDB.java	2010-03-17 16:45:58 UTC (rev 1972)
@@ -88,4 +88,10 @@
      * @return
      */
     public boolean isValid();
+    
+    /**
+     * Get the data roles defined on this VDB
+     * @return
+     */
+    public List<DataRole> getDataRoles();
 }

Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/DataRoleMetadata.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/DataRoleMetadata.java	2010-03-16 21:55:06 UTC (rev 1971)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/DataRoleMetadata.java	2010-03-17 16:45:58 UTC (rev 1972)
@@ -22,6 +22,8 @@
 package org.teiid.adminapi.impl;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -30,55 +32,41 @@
 import javax.xml.bind.annotation.XmlType;
 
 import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperties;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.teiid.adminapi.DataRole;
 
 
-/**
- * <pre>
- * &lt;complexType>
- *   &lt;complexContent>
- *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       &lt;sequence>
- *         &lt;element name="description" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *         &lt;element name="resource-name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         &lt;element name="allow-create" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
- *         &lt;element name="allow-read" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
- *         &lt;element name="allow-update" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
- *         &lt;element name="allow-delete" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
- *       &lt;/sequence>
- *       &lt;attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *     &lt;/restriction>
- *   &lt;/complexContent>
- * &lt;/complexType>
- * </pre>
- * 
- */
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {
     "description",
-    "resourceName",
-    "allowCreate",
-    "allowRead",
-    "allowUpdate",
-    "allowDelete"
+    "permissions",
+    "mappedRoleNames"
 })
- at ManagementObject
-public class DataRoleMetadata implements Serializable {
-
-    @XmlAttribute(name = "name", required = true)
+ at ManagementObject(properties=ManagementProperties.EXPLICIT)
+public class DataRoleMetadata implements DataRole, Serializable {
+	private static final long serialVersionUID = -4119646357275977190L;
+	
+	@XmlAttribute(name = "name", required = true)
     protected String name;
 	@XmlElement(name = "description")
     protected String description;
-    @XmlElement(name = "resource-name", required = true)
-    protected String resourceName;
-    @XmlElement(name = "allow-create")
-    protected Boolean allowCreate;
-    @XmlElement(name = "allow-read")
-    protected Boolean allowRead;
-    @XmlElement(name = "allow-update")
-    protected Boolean allowUpdate;
-    @XmlElement(name = "allow-delete")
-    protected Boolean allowDelete;
 
+    @XmlElement(name = "permission")
+    protected ListOverMap<PermissionMetaData> permissions = new ListOverMap<PermissionMetaData>(new KeyBuilder<PermissionMetaData>() {
+		@Override
+		public String getKey(PermissionMetaData entry) {
+			return entry.getResourceName();
+		}
+	});	
+    
+    @XmlElement(name = "mapped-role-name")
+    protected List<String> mappedRoleNames;
+
+	@Override
+	@ManagementProperty(description="Role Name")
+	@ManagementObjectID(type="role")
     public String getName() {
         return name;
     }
@@ -87,6 +75,8 @@
         this.name = value;
     }
     
+    @Override
+    @ManagementProperty(description="Role Description")
     public String getDescription() {
         return description;
     }
@@ -95,43 +85,120 @@
         this.description = value;
     }
 
-    public String getResourceName() {
-        return resourceName;
-    }
+	@Override
+	@ManagementProperty(description="Permissions in a Data Role", managed=true)
+	public List<Permission> getPermissions() {
+		return new ArrayList<Permission>(this.permissions.getMap().values());
+	}
+	
+	public void setPermissions(List<Permission> permissions) {
+		this.permissions.getMap().clear();
+		for (Permission permission:permissions) {
+			this.permissions.getMap().put(permission.getResourceName(), (PermissionMetaData)permission);
+		}
+	}	
+	
+	public PermissionMetaData getPermission(String resourceName) {
+		return this.permissions.getMap().get(resourceName);
+	}
+	
+	public void addPermission(PermissionMetaData permission) {
+		this.permissions.getMap().put(permission.getResourceName(), permission);
+	}
+	
+    @Override
+    @ManagementProperty(description="Mapped Container role names mapped to this role")    
+    public List<String> getMappedRoleNames() {
+		return mappedRoleNames;
+	}
 
-    public void setResourceName(String value) {
-        this.resourceName = value;
-    }
+	public void setMappedRoleNames(List<String> names) {
+		this.mappedRoleNames = names;
+	}    
+	
+	
+    @XmlAccessorType(XmlAccessType.FIELD)
+    @XmlType(name = "", propOrder = {
+        "resourceName",
+        "allowCreate",
+        "allowRead",
+        "allowUpdate",
+        "allowDelete"
+    })	
+    @ManagementObject(properties=ManagementProperties.EXPLICIT)
+	public static class PermissionMetaData implements Permission{
+        @XmlElement(name = "resource-name", required = true)
+        protected String resourceName;
+        @XmlElement(name = "allow-create")
+        protected Boolean allowCreate;
+        @XmlElement(name = "allow-read")
+        protected Boolean allowRead;
+        @XmlElement(name = "allow-update")
+        protected Boolean allowUpdate;
+        @XmlElement(name = "allow-delete")
+        protected Boolean allowDelete;
+        
+        @Override
+        @ManagementProperty(description="Resource Name, for which role defined")
+        @ManagementObjectID(type="permission")
+        public String getResourceName() {
+            return resourceName;
+        }
 
-    public Boolean isAllowCreate() {
-        return allowCreate;
-    }
+        public void setResourceName(String value) {
+            this.resourceName = value;
+        }
 
-    public void setAllowCreate(Boolean value) {
-        this.allowCreate = value;
-    }
+        @Override
+        @ManagementProperty(description="Allows Create")
+        public boolean isAllowCreate() {
+        	if (allowCreate == null) {
+        		return false;
+        	}
+            return allowCreate;
+        }
 
-    public Boolean isAllowRead() {
-        return allowRead;
-    }
+        public void setAllowCreate(Boolean value) {
+            this.allowCreate = value;
+        }
 
-    public void setAllowRead(Boolean value) {
-        this.allowRead = value;
-    }
+        @Override
+        @ManagementProperty(description="Allows Read")
+        public boolean isAllowRead() {
+        	if (allowRead == null) {
+        		return false;
+        	}
+            return allowRead;
+        }
 
-    public Boolean isAllowUpdate() {
-        return allowUpdate;
-    }
+        public void setAllowRead(Boolean value) {
+            this.allowRead = value;
+        }
 
-    public void setAllowUpdate(Boolean value) {
-        this.allowUpdate = value;
-    }
+        @Override
+        @ManagementProperty(description="Allows Update")
+        public boolean isAllowUpdate() {
+        	if (allowUpdate == null) {
+        		return false;
+        	}
+            return allowUpdate;
+        }
 
-    public Boolean isAllowDelete() {
-        return allowDelete;
-    }
+        public void setAllowUpdate(Boolean value) {
+            this.allowUpdate = value;
+        }
 
-    public void setAllowDelete(Boolean value) {
-        this.allowDelete = value;
-    }
+        @Override
+        @ManagementProperty(description="Allows Delete")
+        public boolean isAllowDelete() {
+        	if (allowDelete == null) {
+        		return false;
+        	}
+            return allowDelete;
+        }
+
+        public void setAllowDelete(Boolean value) {
+            this.allowDelete = value;
+        }        
+	}
 }

Deleted: trunk/client/src/main/java/org/teiid/adminapi/impl/ReferenceMappingMetadata.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/ReferenceMappingMetadata.java	2010-03-16 21:55:06 UTC (rev 1971)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/ReferenceMappingMetadata.java	2010-03-17 16:45:58 UTC (rev 1972)
@@ -1,130 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.adminapi.impl;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-
-/**
- * <pre>
- * &lt;complexType name="reference-mapping">
- *   &lt;complexContent>
- *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       &lt;sequence>
- *         &lt;element name="ref-name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         &lt;element name="resource-name" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
- *       &lt;/sequence>
- *     &lt;/restriction>
- *   &lt;/complexContent>
- * &lt;/complexType>
- * </pre>
- * 
- * 
- */
- at XmlAccessorType(XmlAccessType.NONE)
- at XmlType(name = "reference-mapping", propOrder = {
-    "refName",
-    "resourceNames"
-})
- at ManagementObject
-public class ReferenceMappingMetadata implements Serializable {
-
-    @XmlElement(name = "ref-name", required = true)
-    protected String refName;
- 
-    @XmlElement(name = "resource-name", required = true)
-    protected List<String> resourceNames;
-
-    public ReferenceMappingMetadata() {
-    }
-    
-    public ReferenceMappingMetadata(String refName, String resourceName) {
-    	setRefName(refName);
-    	addResourceName(resourceName);
-    }
-    
-    public ReferenceMappingMetadata(String refName, List<String> resourceNames) {
-    	setRefName(refName);
-    	this.resourceNames = new ArrayList<String>(resourceNames);
-    }    
-    
-    @ManagementProperty(description="Reference Name", readOnly=true)
-    public String getRefName() {
-        return refName;
-    }
-
-    public void setRefName(String value) {
-        this.refName = value;
-    }
-
-    @ManagementProperty(description="Resource Names")
-    public List<String> getResourceNames() {
-        if (this.resourceNames == null) {
-            this.resourceNames = new ArrayList<String>();
-        }
-        return this.resourceNames;
-    }
-    
-    public void setResourceNames(List<String> names) {
-    	this.resourceNames = new ArrayList<String>(names);
-    }
-    
-    public void addResourceName(String name) {
-    	getResourceNames().add(name);
-    }
-
-	@Override
-	public int hashCode() {
-		final int prime = 31;
-		int result = 1;
-		result = prime * result + ((refName == null) ? 0 : refName.hashCode());
-		return result;
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (this == obj)
-			return true;
-		if (obj == null)
-			return false;
-		if (getClass() != obj.getClass())
-			return false;
-		ReferenceMappingMetadata other = (ReferenceMappingMetadata) obj;
-		if (refName == null) {
-			if (other.refName != null)
-				return false;
-		} else if (!refName.equals(other.refName))
-			return false;
-		return true;
-	}
-    
-  
-}

Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2010-03-16 21:55:06 UTC (rev 1971)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2010-03-17 16:45:58 UTC (rev 1972)
@@ -39,6 +39,7 @@
 import org.jboss.managed.api.annotation.ManagementObjectID;
 import org.jboss.managed.api.annotation.ManagementProperties;
 import org.jboss.managed.api.annotation.ManagementProperty;
+import org.teiid.adminapi.DataRole;
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.VDB;
 import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
@@ -50,7 +51,7 @@
     "description",
     "JAXBProperties",
     "models",
-    "securityRoleMappings"
+    "roles"
 })
 @XmlRootElement(name = "vdb")
 public class VDBMetaData extends AdminObjectImpl implements VDB {
@@ -70,26 +71,23 @@
 		}
 	});
 	
+	@XmlElement(name = "role", required = true, type = DataRoleMetadata.class)
+	protected ListOverMap<DataRoleMetadata> roles = new ListOverMap<DataRoleMetadata>(new KeyBuilder<DataRoleMetadata>() {
+		@Override
+		public String getKey(DataRoleMetadata entry) {
+			return entry.getName();
+		}
+	});	
+	
 	@XmlAttribute(name = "version", required = true)
 	private int version = 1;
 	
 	@XmlElement(name = "description")
 	protected String description;
 	
-    @XmlElement(name = "role-mapping")
-    protected ListOverMap<ReferenceMappingMetadata> securityRoleMappings = new ListOverMap<ReferenceMappingMetadata>(new KeyBuilder<ReferenceMappingMetadata>() {
-			@Override
-			public String getKey(ReferenceMappingMetadata entry) {
-				return entry.getRefName();
-			}
-	});
-    
 	private String fileUrl = null;
 	private boolean dynamic = false;
 	
-	public VDBMetaData() {
-		// auto add sytem model.
-	}
 
 	@ManagementProperty(description="Name of the VDB")
 	@ManagementObjectID(type="vdb")
@@ -230,15 +228,6 @@
 		return list;
 	}
 	
-    @ManagementProperty(description="Security refrence mappings", managed=true)
-	public List<ReferenceMappingMetadata> getSecurityRoleMappings() {
-		return new ArrayList<ReferenceMappingMetadata>(this.securityRoleMappings);
-	}    
-	
-	public void addSecurityRoleMapping(ReferenceMappingMetadata data) {
-		this.securityRoleMappings.getMap().put(data.getRefName(), data);
-	}
-	
 	@Override
     public Properties getProperties() {
         return super.getProperties();
@@ -260,4 +249,29 @@
 	public void setDynamic(boolean dynamic) {
 		this.dynamic = dynamic;
 	}	
+	
+	@Override
+	@ManagementProperty(description="Data Roles in a VDB", managed=true)
+	public List<DataRole> getDataRoles(){
+		return new ArrayList<DataRole>(this.roles.getMap().values());
+	}	
+	
+	/**
+	 * This method is required by the Management framework to write the mappings.
+	 * @param roles
+	 */
+	public void setDataRoles(List<DataRole> roles){
+		this.roles.getMap().clear();
+		for (DataRole role:roles) {
+			this.roles.getMap().put(role.getName(), (DataRoleMetadata)role);
+		}
+	}	
+	
+	public void addDataRole(DataRoleMetadata role){
+		this.roles.getMap().put(role.getName(), role);
+	}
+	
+	public DataRoleMetadata getDataRole(String roleName) {
+		return this.roles.getMap().get(roleName);
+	}
 }

Modified: trunk/client/src/main/resources/vdb-deployer.xsd
===================================================================
--- trunk/client/src/main/resources/vdb-deployer.xsd	2010-03-16 21:55:06 UTC (rev 1971)
+++ trunk/client/src/main/resources/vdb-deployer.xsd	2010-03-17 16:45:58 UTC (rev 1972)
@@ -53,11 +53,18 @@
 					<xs:complexType>
 						<xs:sequence>
 							<xs:element name="description" type="xs:string" minOccurs="0"/>
-							<xs:element name="resource-name" type="xs:string"/>
-							<xs:element name="allow-create" type="xs:boolean" minOccurs="0"/>
-							<xs:element name="allow-read" type="xs:boolean" minOccurs="0"/>
-							<xs:element name="allow-update" type="xs:boolean" minOccurs="0"/>
-							<xs:element name="allow-delete" type="xs:boolean" minOccurs="0"/>
+                            <xs:element name="permission" minOccurs="1" maxOccurs="unbounded">
+                                <xs:complexType>
+                                    <xs:sequence>                            
+							             <xs:element name="resource-name" type="xs:string"/>
+							             <xs:element name="allow-create" type="xs:boolean" minOccurs="0"/>
+							             <xs:element name="allow-read" type="xs:boolean" minOccurs="0"/>
+							             <xs:element name="allow-update" type="xs:boolean" minOccurs="0"/>
+							             <xs:element name="allow-delete" type="xs:boolean" minOccurs="0"/>
+                                   </xs:sequence>      
+                                </xs:complexType>
+                            </xs:element>                                                                      
+                            <xs:element name="mapped-role-name" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
 						</xs:sequence>
 						<xs:attribute name="name" type="xs:string" use="required"/>
 					</xs:complexType>
@@ -71,7 +78,6 @@
                         <xs:attribute name="path" type="xs:string" use="required"/>
                     </xs:complexType>
                 </xs:element>
-				<xs:element name="role-mapping" type="reference-mapping" minOccurs="0" maxOccurs="unbounded"/>
 			</xs:sequence>
 			<xs:attribute name="name" type="xs:string" use="required"/>
 			<xs:attribute name="version" type="xs:int" use="required"/>
@@ -84,10 +90,4 @@
 		<xs:attribute name="name" type="xs:string" use="required"/>
 		<xs:attribute name="value" type="xs:string" use="required"/>
 	</xs:complexType>
-	<xs:complexType name="reference-mapping">
-		<xs:sequence>
-			<xs:element name="ref-name" type="xs:string"/>
-			<xs:element name="resource-name" type="xs:string" maxOccurs="unbounded"/>
-		</xs:sequence>
-	</xs:complexType>
 </xs:schema>

Modified: trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
--- trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java	2010-03-16 21:55:06 UTC (rev 1971)
+++ trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java	2010-03-17 16:45:58 UTC (rev 1972)
@@ -25,6 +25,8 @@
 
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
@@ -34,7 +36,9 @@
 import javax.xml.validation.SchemaFactory;
 
 import org.junit.Test;
+import org.teiid.adminapi.DataRole;
 import org.teiid.adminapi.Model;
+import org.teiid.adminapi.impl.DataRoleMetadata.PermissionMetaData;
 
 
 public class TestVDBMetaData {
@@ -43,34 +47,53 @@
 	public void testMarshellUnmarshell() throws Exception {
 		
 		VDBMetaData vdb = new VDBMetaData();
-		vdb.setName("myVDB");
-		vdb.setDescription("vdb description");
+		vdb.setName("myVDB"); //$NON-NLS-1$
+		vdb.setDescription("vdb description"); //$NON-NLS-1$
 		vdb.setVersion(1);
-		vdb.addProperty("vdb-property", "vdb-value");
+		vdb.addProperty("vdb-property", "vdb-value"); //$NON-NLS-1$ //$NON-NLS-2$
 		
 		ModelMetaData modelOne = new ModelMetaData();
-		modelOne.setName("model-one");
-		modelOne.addSourceMapping("s1", "java:mybinding");
-		modelOne.setModelType("PHYSICAL");
-		modelOne.addProperty("model-prop", "model-value");
-		modelOne.addProperty("model-prop", "model-value-override");
+		modelOne.setName("model-one"); //$NON-NLS-1$
+		modelOne.addSourceMapping("s1", "java:mybinding"); //$NON-NLS-1$ //$NON-NLS-2$
+		modelOne.setModelType("PHYSICAL"); //$NON-NLS-1$
+		modelOne.addProperty("model-prop", "model-value"); //$NON-NLS-1$ //$NON-NLS-2$
+		modelOne.addProperty("model-prop", "model-value-override"); //$NON-NLS-1$ //$NON-NLS-2$
 		modelOne.setVisible(false);
-		modelOne.addError("ERROR", "There is an error in VDB");
+		modelOne.addError("ERROR", "There is an error in VDB"); //$NON-NLS-1$ //$NON-NLS-2$
 		
 		vdb.addModel(modelOne);
 		
 		ModelMetaData modelTwo = new ModelMetaData();
-		modelTwo.setName("model-two");
-		modelTwo.addSourceMapping("s1", "java:binding-one");
-		modelTwo.addSourceMapping("s2", "java:binding-two");
-		modelTwo.setModelType("VIRTUAL");
-		modelTwo.addProperty("model-prop", "model-value");
+		modelTwo.setName("model-two"); //$NON-NLS-1$
+		modelTwo.addSourceMapping("s1", "java:binding-one"); //$NON-NLS-1$ //$NON-NLS-2$
+		modelTwo.addSourceMapping("s2", "java:binding-two"); //$NON-NLS-1$ //$NON-NLS-2$
+		modelTwo.setModelType("VIRTUAL"); //$NON-NLS-1$
+		modelTwo.addProperty("model-prop", "model-value"); //$NON-NLS-1$ //$NON-NLS-2$
 		
 		vdb.addModel(modelTwo);
 		
+		DataRoleMetadata roleOne = new DataRoleMetadata();
+		roleOne.setName("roleOne"); //$NON-NLS-1$
+		roleOne.setDescription("roleOne described"); //$NON-NLS-1$
+		
+		PermissionMetaData perm1 = new PermissionMetaData();
+		perm1.setResourceName("myTable.T1"); //$NON-NLS-1$
+		perm1.setAllowRead(true);
+		roleOne.addPermission(perm1);
+		
+		PermissionMetaData perm2 = new PermissionMetaData();
+		perm2.setResourceName("myTable.T2"); //$NON-NLS-1$
+		perm2.setAllowRead(false);
+		perm2.setAllowDelete(true);
+		roleOne.addPermission(perm2);
+		
+		roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2")); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		vdb.addDataRole(roleOne);
+		
 
 		SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-        Schema schema = schemaFactory.newSchema(VDBMetaData.class.getResource("/vdb-deployer.xsd")); 		
+        Schema schema = schemaFactory.newSchema(VDBMetaData.class.getResource("/vdb-deployer.xsd")); 		 //$NON-NLS-1$
 		JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {VDBMetaData.class});
 		Marshaller marshell = jc.createMarshaller();
 		marshell.setSchema(schema);
@@ -86,31 +109,51 @@
 		un.setSchema(schema);
 		vdb = (VDBMetaData)un.unmarshal(new StringReader(sw.toString()));
 		
-		assertEquals("myVDB", vdb.getName());
-		assertEquals("vdb description", vdb.getDescription());
+		assertEquals("myVDB", vdb.getName()); //$NON-NLS-1$
+		assertEquals("vdb description", vdb.getDescription()); //$NON-NLS-1$
 		assertEquals(1, vdb.getVersion());
-		assertEquals("vdb-value", vdb.getPropertyValue("vdb-property"));
+		assertEquals("vdb-value", vdb.getPropertyValue("vdb-property")); //$NON-NLS-1$ //$NON-NLS-2$
 		
-		assertNotNull(vdb.getModel("model-one"));
-		assertNotNull(vdb.getModel("model-two"));
-		assertNull(vdb.getModel("model-unknown"));
+		assertNotNull(vdb.getModel("model-one")); //$NON-NLS-1$
+		assertNotNull(vdb.getModel("model-two")); //$NON-NLS-1$
+		assertNull(vdb.getModel("model-unknown")); //$NON-NLS-1$
 		
-		modelOne = vdb.getModel("model-one");
-		assertEquals("model-one", modelOne.getName());
-		assertEquals("s1", modelOne.getSourceNames().get(0));
+		modelOne = vdb.getModel("model-one"); //$NON-NLS-1$
+		assertEquals("model-one", modelOne.getName()); //$NON-NLS-1$
+		assertEquals("s1", modelOne.getSourceNames().get(0)); //$NON-NLS-1$
 		assertEquals(Model.Type.PHYSICAL, modelOne.getModelType()); 
-		assertEquals("model-value-override", modelOne.getPropertyValue("model-prop"));
+		assertEquals("model-value-override", modelOne.getPropertyValue("model-prop")); //$NON-NLS-1$ //$NON-NLS-2$
 		assertFalse(modelOne.isVisible());
 
 		
-		modelTwo = vdb.getModel("model-two");
-		assertEquals("model-two", modelTwo.getName());
-		assertTrue(modelTwo.getSourceNames().contains("s1"));
-		assertTrue(modelTwo.getSourceNames().contains("s2"));
+		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")); //$NON-NLS-1$
 		assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType()); // this is not persisted in the XML
-		assertEquals("model-value", modelTwo.getPropertyValue("model-prop"));
+		assertEquals("model-value", modelTwo.getPropertyValue("model-prop")); //$NON-NLS-1$ //$NON-NLS-2$
 		
 		
-		assertTrue(vdb.getValidityErrors().contains("There is an error in VDB"));
+		assertTrue(vdb.getValidityErrors().contains("There is an error in VDB")); //$NON-NLS-1$
+		
+		List<DataRole> roles = vdb.getDataRoles();
+		
+		assertTrue(roles.size() == 1);
+		
+		DataRoleMetadata role = vdb.getDataRole("roleOne"); //$NON-NLS-1$
+		assertEquals("roleOne described", role.getDescription()); //$NON-NLS-1$
+		assertNotNull(role.getMappedRoleNames());
+		assertTrue(role.getMappedRoleNames().contains("ROLE1")); //$NON-NLS-1$
+		assertTrue(role.getMappedRoleNames().contains("ROLE2")); //$NON-NLS-1$
+		
+		assertEquals(2, role.getPermissions().size());
+		PermissionMetaData p1 = role.getPermission("myTable.T1"); //$NON-NLS-1$
+		
+		assertTrue(p1.isAllowRead());
+		assertFalse(p1.isAllowDelete());
+		
+		PermissionMetaData p2 = role.getPermission("myTable.T2"); //$NON-NLS-1$
+		assertFalse(p2.isAllowRead());
+		assertTrue(p2.isAllowDelete());
 	}
 }



More information about the teiid-commits mailing list