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

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Jul 25 15:40:00 EDT 2012


Author: rareddy
Date: 2012-07-25 15:39:59 -0400 (Wed, 25 Jul 2012)
New Revision: 4270

Added:
   trunk/admin/src/main/java/org/teiid/adminapi/Entry.java
   trunk/admin/src/main/java/org/teiid/adminapi/impl/EntryMetaData.java
Modified:
   trunk/admin/src/main/java/org/teiid/adminapi/VDB.java
   trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
   trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
   trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
   trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
   trunk/admin/src/test/resources/parser-test-vdb.xml
Log:
TEIID-2114: adding entries concept into Teiid proper to support tooling. There is couple times question of adding additional artifacts with dynamic vdb and allowing it deploy as archive, so it should be helpful. 

Added: trunk/admin/src/main/java/org/teiid/adminapi/Entry.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/Entry.java	                        (rev 0)
+++ trunk/admin/src/main/java/org/teiid/adminapi/Entry.java	2012-07-25 19:39:59 UTC (rev 4270)
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+public interface Entry extends AdminObject {
+	/**
+	 * Get Path to the entry
+	 * @return
+	 */
+	String getPath();
+	
+	/**
+	 * Description
+	 * @return
+	 */
+	String getDescription();
+}


Property changes on: trunk/admin/src/main/java/org/teiid/adminapi/Entry.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/admin/src/main/java/org/teiid/adminapi/VDB.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/VDB.java	2012-07-25 18:29:23 UTC (rev 4269)
+++ trunk/admin/src/main/java/org/teiid/adminapi/VDB.java	2012-07-25 19:39:59 UTC (rev 4270)
@@ -113,4 +113,10 @@
      * @return
      */
     public List<? extends VDBImport> getVDBImports();
+    
+    /**
+     * Get the list of other resources included in the VDB
+     * @return
+     */
+    public List<? extends Entry> getEntries();
 }

Added: trunk/admin/src/main/java/org/teiid/adminapi/impl/EntryMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/EntryMetaData.java	                        (rev 0)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/EntryMetaData.java	2012-07-25 19:39:59 UTC (rev 4270)
@@ -0,0 +1,49 @@
+/*
+ * 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 org.teiid.adminapi.Entry;
+
+public class EntryMetaData extends AdminObjectImpl implements Entry {
+	private static final long serialVersionUID = -3602627159192411780L;
+	
+	private String path;
+	private String description;
+	
+	@Override
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	@Override
+	public String getPath() {
+		return this.path;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	}
+}


Property changes on: trunk/admin/src/main/java/org/teiid/adminapi/impl/EntryMetaData.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2012-07-25 18:29:23 UTC (rev 4269)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2012-07-25 19:39:59 UTC (rev 4270)
@@ -47,6 +47,8 @@
 	private LinkedHashMap<String, VDBTranslatorMetaData> translators = new LinkedHashMap<String, VDBTranslatorMetaData>(); 
 	private LinkedHashMap<String, DataPolicyMetadata> dataPolicies = new LinkedHashMap<String, DataPolicyMetadata>(); 
 	private List<VDBImportMetadata> imports = new ArrayList<VDBImportMetadata>(2);
+	private List<EntryMetaData> entries = new ArrayList<EntryMetaData>(2);
+	
 	private int version = 1;
 	private String description;
 	private boolean dynamic = false;
@@ -262,4 +264,13 @@
 	public void setImportedModels(Set<String> importedModels) {
 		this.importedModels = importedModels;
 	}
+
+	@Override
+	public List<EntryMetaData> getEntries() {
+		return this.entries;
+	}
+	
+	public void setEntries(List<EntryMetaData> entries) {
+		this.entries = entries;
+	}
 }

Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java	2012-07-25 18:29:23 UTC (rev 4269)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java	2012-07-25 19:39:59 UTC (rev 4270)
@@ -52,6 +52,7 @@
 	private static final String DYNAMIC = "dynamic"; //$NON-NLS-1$
 	private static final String DATA_POLICIES = "data-policies"; //$NON-NLS-1$
 	private static final String DESCRIPTION = "description"; //$NON-NLS-1$
+	private static final String ENTRIES = "entries"; //$NON-NLS-1$
 	
 	public static VDBMetadataMapper INSTANCE = new VDBMetadataMapper();
 	
@@ -87,6 +88,15 @@
 			}
 		}
 		
+		// ENTRIES
+		List<EntryMetaData> entries = vdb.getEntries();
+		if (entries != null && !entries.isEmpty()) {
+			ModelNode entryNodes = node.get(ENTRIES);		
+			for(EntryMetaData entry:entries) {
+				entryNodes.add(EntryMapper.INSTANCE.wrap(entry, new ModelNode()));
+			}
+		}		
+		
 		// MODELS
 		Map<String, ModelMetaData> models = vdb.getModelMetaDatas();
 		if (models != null && !models.isEmpty()) {
@@ -164,6 +174,17 @@
 			}
 		}
 		
+		// ENTRIES
+		if (node.get(ENTRIES).isDefined()) {
+			List<ModelNode> modelNodes = node.get(ENTRIES).asList();
+			for(ModelNode modelNode:modelNodes) {
+				EntryMetaData entry = EntryMapper.INSTANCE.unwrap(modelNode);
+				if (entry != null) {
+					vdb.getEntries().add(entry);	
+				}
+			}
+		}		
+		
 		// MODELS
 		if (node.get(MODELS).isDefined()) {
 			List<ModelNode> modelNodes = node.get(MODELS).asList();
@@ -679,7 +700,76 @@
 		}
 	}		
 	
+	
 	/**
+	 * Entry Mapper
+	 */
+	public static class EntryMapper implements MetadataMapper<EntryMetaData>{
+		private static final String PATH = "path"; //$NON-NLS-1$
+		
+		public static EntryMapper INSTANCE = new EntryMapper();
+		
+		@Override
+		public ModelNode wrap(EntryMetaData obj, ModelNode node) {
+			if (obj == null) {
+				return null;
+			}
+			
+			node.get(PATH).set(obj.getPath());
+			if (obj.getDescription() != null) {
+				node.get(DESCRIPTION).set(obj.getDescription());
+			}
+			
+			//PROPERTIES
+			Properties properties = obj.getProperties();
+			if (properties!= null && !properties.isEmpty()) {
+				ModelNode propsNode = node.get(PROPERTIES);
+				for (String key:properties.stringPropertyNames()) {
+					propsNode.add(PropertyMetaDataMapper.INSTANCE.wrap(key, properties.getProperty(key), new ModelNode()));
+				}
+			}
+			return node;
+		}
+		
+		public EntryMetaData unwrap(ModelNode node) {
+			if (node == null) {
+				return null;
+			}
+			
+			EntryMetaData entry = new EntryMetaData();
+			if (node.has(PATH)) {
+				entry.setPath(node.get(PATH).asString());
+			}
+			
+			if (node.has(DESCRIPTION)) {
+				entry.setDescription(node.get(DESCRIPTION).asString());
+			}
+			
+			//PROPERTIES
+			if (node.get(PROPERTIES).isDefined()) {
+				List<ModelNode> propNodes = node.get(PROPERTIES).asList();
+				for (ModelNode propNode:propNodes) {
+					String[] prop = PropertyMetaDataMapper.INSTANCE.unwrap(propNode);
+					if (prop != null) {
+						entry.addProperty(prop[0], prop[1]);
+					}
+				}
+			}
+			return entry;
+		}
+		
+		public ModelNode describe(ModelNode node) {
+			addAttribute(node, PATH, ModelType.STRING, true);
+			
+			ModelNode props = node.get(PROPERTIES);
+			props.get(TYPE).set(ModelType.LIST);
+			props.get(DESCRIPTION).set(AdminPlugin.Util.getString(PROPERTIES+DOT_DESC));
+			PropertyMetaDataMapper.INSTANCE.describe(props.get(VALUE_TYPE));
+			return node; 
+		}
+	}		
+	
+	/**
 	 * DataPolicy Metadata mapper
 	 */
 	public static class DataPolicyMetadataMapper implements MetadataMapper<DataPolicyMetadata>{

Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java	2012-07-25 18:29:23 UTC (rev 4269)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java	2012-07-25 19:39:59 UTC (rev 4270)
@@ -132,7 +132,9 @@
 				ignoreTillEnd(reader);
 				break;
 			case ENTRY:
-				// this is designer specific.
+				EntryMetaData entry = new EntryMetaData();
+				parseEntry(reader, entry);
+				vdb.getEntries().add(entry);
 				break;
              default: 
             	 throw new XMLStreamException(AdminPlugin.Util.gs("unexpected_element5",reader.getName(), 
@@ -256,6 +258,26 @@
             }
         }		
 	}	
+
+	private static void parseEntry(XMLStreamReader reader, EntryMetaData entry) throws XMLStreamException {
+		Properties props = getAttributes(reader);
+		entry.setPath(props.getProperty(Element.PATH.getLocalName()));
+        while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
+            Element element = Element.forName(reader.getLocalName());
+            switch (element) {
+			case DESCRIPTION:
+				entry.setDescription(reader.getElementText());
+				break;
+			case PROPERTY:
+				parseProperty(reader, entry);
+				break;
+            default: 
+           	 throw new XMLStreamException(AdminPlugin.Util.gs("unexpected_element2",reader.getName(), 
+           			 Element.DESCRIPTION.getLocalName(),
+           			 Element.PROPERTY.getLocalName())); 
+           }
+       }		
+	}	
 	
 	private static void parseModel(XMLStreamReader reader, ModelMetaData model) throws XMLStreamException {
 		Properties props = getAttributes(reader);
@@ -428,6 +450,15 @@
 		
 		// entry
 		// designer only 
+		for (EntryMetaData em:vdb.getEntries()) {
+			writer.writeStartElement(Element.ENTRY.getLocalName());
+			writeAttribute(writer, Element.PATH.getLocalName(), em.getPath());
+			if (em.getDescription() != null) {
+				writeElement(writer, Element.DESCRIPTION, em.getDescription());
+			}
+			writeProperties(writer, em.getProperties());			
+			writer.writeEndElement();
+		}
 		
 		writer.writeEndElement();
 		writer.writeEndDocument();

Modified: trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
--- trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java	2012-07-25 18:29:23 UTC (rev 4269)
+++ trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java	2012-07-25 19:39:59 UTC (rev 4270)
@@ -194,6 +194,16 @@
 		roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2")); //$NON-NLS-1$ //$NON-NLS-2$
 		
 		vdb.addDataPolicy(roleOne);
+		
+		EntryMetaData em = new EntryMetaData();
+		em.setPath("/path-one");
+		em.setDescription("entry one");
+		em.addProperty("entryone", "1");
+		vdb.getEntries().add(em);
+		
+		EntryMetaData em2 = new EntryMetaData();
+		em2.setPath("/path-two");
+		vdb.getEntries().add(em2);
 		return vdb;
 	}
 	

Modified: trunk/admin/src/test/resources/parser-test-vdb.xml
===================================================================
--- trunk/admin/src/test/resources/parser-test-vdb.xml	2012-07-25 18:29:23 UTC (rev 4269)
+++ trunk/admin/src/test/resources/parser-test-vdb.xml	2012-07-25 19:39:59 UTC (rev 4270)
@@ -36,5 +36,10 @@
         <mapped-role-name>ROLE1</mapped-role-name>
         <mapped-role-name>ROLE2</mapped-role-name>
     </data-role>
+    <entry path="/path-one">
+        <description>path one description</description>
+        <property name="entryone" value="1"></property>
+    </entry>
+    <entry path="/path-two"/>
 </vdb>
 



More information about the teiid-commits mailing list