Author: shawkins
Date: 2012-05-07 16:10:17 -0400 (Mon, 07 May 2012)
New Revision: 4073
Added:
trunk/admin/src/test/resources/model-not-unique-vdb.xml
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetadataParser.java
trunk/admin/src/test/resources/parser-test-vdb.xml
trunk/client/src/main/resources/vdb-deployer.xsd
trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
Log:
TEIID-2024 adding various validations
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2012-05-07
19:02:20 UTC (rev 4072)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2012-05-07
20:10:17 UTC (rev 4073)
@@ -144,6 +144,7 @@
}
public void setSourceMappings(List<SourceMappingMetadata> sources){
+ this.sources.getMap().clear();
for (SourceMappingMetadata source: sources) {
addSourceMapping(source.getName(), source.getTranslatorName(),
source.getConnectionJndiName());
}
@@ -172,12 +173,12 @@
return s.getTranslatorName();
}
- public void addSourceMapping(String name, String translatorName, String connJndiName) {
- this.sources.getMap().put(name, new SourceMappingMetadata(name, translatorName,
connJndiName));
+ public SourceMappingMetadata addSourceMapping(String name, String translatorName, String
connJndiName) {
+ return this.sources.getMap().put(name, new SourceMappingMetadata(name, translatorName,
connJndiName));
}
public void addSourceMapping(SourceMappingMetadata source) {
- this.sources.getMap().put(source.getName(), new SourceMappingMetadata(source.getName(),
source.getTranslatorName(), source.getConnectionJndiName()));
+ this.addSourceMapping(source.getName(), source.getTranslatorName(),
source.getConnectionJndiName());
}
public List<ValidationError> getErrors(){
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-05-07 19:02:20
UTC (rev 4072)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-05-07 20:10:17
UTC (rev 4073)
@@ -22,7 +22,11 @@
package org.teiid.adminapi.impl;
import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.teiid.adminapi.DataPolicy;
import org.teiid.adminapi.Model;
@@ -179,14 +183,15 @@
* @param models
*/
public void setModels(List<Model> models) {
+ this.models.getMap().clear();
for (Model obj : models) {
ModelMetaData model = (ModelMetaData) obj;
addModel(model);
}
}
- public void addModel(ModelMetaData m) {
- this.models.getMap().put(m.getName(), m);
+ public ModelMetaData addModel(ModelMetaData m) {
+ return this.models.getMap().put(m.getName(), m);
}
@Override
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-05-07
19:02:20 UTC (rev 4072)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-05-07
20:10:17 UTC (rev 4073)
@@ -30,12 +30,17 @@
import java.util.Map;
import java.util.Properties;
+import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.stax.StAXSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
import org.teiid.adminapi.AdminPlugin;
import org.teiid.adminapi.DataPolicy;
@@ -43,6 +48,7 @@
import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
import org.teiid.core.types.XMLType;
+import org.xml.sax.SAXException;
@SuppressWarnings("nls")
public class VDBMetadataParser {
@@ -50,25 +56,47 @@
public static VDBMetaData unmarshell(InputStream content) throws XMLStreamException {
XMLInputFactory inputFactory=XMLType.getXmlInputFactory();
XMLStreamReader reader = inputFactory.createXMLStreamReader(content);
-
- // elements
- while (reader.hasNext() && (reader.nextTag() !=
XMLStreamConstants.END_ELEMENT)) {
- Element element = Element.forName(reader.getLocalName());
- switch (element) {
- case VDB:
- VDBMetaData vdb = new VDBMetaData();
- Properties props = getAttributes(reader);
- vdb.setName(props.getProperty(Element.NAME.getLocalName()));
- vdb.setVersion(Integer.parseInt(props.getProperty(Element.VERSION.getLocalName())));
- parseVDB(reader, vdb);
- return vdb;
- default:
- throw new
XMLStreamException(AdminPlugin.Util.gs("unexpected_element1",reader.getName(),
Element.VDB.getLocalName()), reader.getLocation());
- }
- }
+ try {
+ // elements
+ while (reader.hasNext() && (reader.nextTag() !=
XMLStreamConstants.END_ELEMENT)) {
+ Element element = Element.forName(reader.getLocalName());
+ switch (element) {
+ case VDB:
+ VDBMetaData vdb = new VDBMetaData();
+ Properties props = getAttributes(reader);
+ vdb.setName(props.getProperty(Element.NAME.getLocalName()));
+ vdb.setVersion(Integer.parseInt(props.getProperty(Element.VERSION.getLocalName())));
+ parseVDB(reader, vdb);
+ return vdb;
+ default:
+ throw new
XMLStreamException(AdminPlugin.Util.gs("unexpected_element1",reader.getName(),
Element.VDB.getLocalName()), reader.getLocation());
+ }
+ }
+ } finally {
+ try {
+ content.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
return null;
}
+ public static void validate(InputStream content) throws SAXException,
+ IOException, XMLStreamException {
+ try {
+ XMLInputFactory inputFactory = XMLType.getXmlInputFactory();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(content);
+ SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema schema =
schemaFactory.newSchema(VDBMetaData.class.getResource("/vdb-deployer.xsd"));
//$NON-NLS-1$
+ Validator v = schema.newValidator();
+ v.validate(new StAXSource(reader));
+ } finally {
+ content.close();
+ }
+ }
+
private static void parseVDB(XMLStreamReader reader, VDBMetaData vdb) throws
XMLStreamException {
while (reader.hasNext() && (reader.nextTag() !=
XMLStreamConstants.END_ELEMENT)) {
Element element = Element.forName(reader.getLocalName());
Modified: trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetadataParser.java
===================================================================
---
trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetadataParser.java 2012-05-07
19:02:20 UTC (rev 4072)
+++
trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetadataParser.java 2012-05-07
20:10:17 UTC (rev 4073)
@@ -1,3 +1,24 @@
+/*
+ * 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.FileInputStream;
@@ -4,14 +25,23 @@
import org.junit.Test;
import org.teiid.core.util.UnitTestUtil;
+import org.xml.sax.SAXException;
@SuppressWarnings("nls")
public class TestVDBMetadataParser {
@Test
- public void testparseVDB() throws Exception {
+ public void testParseVDB() throws Exception {
FileInputStream in = new FileInputStream(UnitTestUtil.getTestDataPath() +
"/parser-test-vdb.xml");
+ VDBMetadataParser.validate(in);
+ in = new FileInputStream(UnitTestUtil.getTestDataPath() +
"/parser-test-vdb.xml");
VDBMetaData vdb = VDBMetadataParser.unmarshell(in);
TestVDBMetaData.validateVDB(vdb);
}
+
+ @Test(expected=SAXException.class) public void testModelNameUniqueness() throws
Exception {
+ FileInputStream in = new FileInputStream(UnitTestUtil.getTestDataPath() +
"/model-not-unique-vdb.xml");
+ VDBMetadataParser.validate(in);
+ }
+
}
Added: trunk/admin/src/test/resources/model-not-unique-vdb.xml
===================================================================
--- trunk/admin/src/test/resources/model-not-unique-vdb.xml (rev
0)
+++ trunk/admin/src/test/resources/model-not-unique-vdb.xml 2012-05-07 20:10:17 UTC (rev
4073)
@@ -0,0 +1,39 @@
+<vdb name="myVDB" version="1">
+ <description>vdb description</description>
+ <property name="vdb-property2"
value="vdb-value2"></property>
+ <property name="vdb-property"
value="vdb-value"></property>
+ <model name="model-one" type="PHYSICAL"
visible="false">
+ <description>model description</description>
+ <property name="model-prop"
value="model-value-override"></property>
+ <source name="s1" translator-name="translator"
connection-jndi-name="java:mybinding"></source>
+ <validation-error severity="ERROR">There is an error in
VDB</validation-error>
+ </model>
+ <model name="model-one" type="VIRTUAL"
visible="true">
+ <property name="model-prop"
value="model-value"></property>
+ <source name="s1" translator-name="translator"
connection-jndi-name="java:binding-one"></source>
+ <source name="s2" translator-name="translator"
connection-jndi-name="java:binding-two"></source>
+ <metadata type="DDL"><![CDATA[DDL Here]]></metadata>
+ </model>
+ <translator name="oracleOverride" type="oracle"
description="hello world">
+ <property name="my-property"
value="my-value"></property>
+ </translator>
+ <data-role name="roleOne" any-authenticated="false"
allow-create-temporary-tables="true">
+ <description>roleOne described</description>
+ <permission>
+ <resource-name>myTable.T1</resource-name>
+ <allow-read>true</allow-read>
+ </permission>
+ <permission>
+ <resource-name>myTable.T2</resource-name>
+ <allow-create>true</allow-create>
+ <allow-read>false</allow-read>
+ <allow-update>true</allow-update>
+ <allow-delete>true</allow-delete>
+ <allow-execute>true</allow-execute>
+ <allow-alter>true</allow-alter>
+ </permission>
+ <mapped-role-name>ROLE1</mapped-role-name>
+ <mapped-role-name>ROLE2</mapped-role-name>
+ </data-role>
+</vdb>
+
Property changes on: trunk/admin/src/test/resources/model-not-unique-vdb.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/admin/src/test/resources/parser-test-vdb.xml
===================================================================
--- trunk/admin/src/test/resources/parser-test-vdb.xml 2012-05-07 19:02:20 UTC (rev 4072)
+++ trunk/admin/src/test/resources/parser-test-vdb.xml 2012-05-07 20:10:17 UTC (rev 4073)
@@ -25,12 +25,12 @@
</permission>
<permission>
<resource-name>myTable.T2</resource-name>
+ <allow-create>true</allow-create>
<allow-read>false</allow-read>
+ <allow-update>true</allow-update>
<allow-delete>true</allow-delete>
+ <allow-execute>true</allow-execute>
<allow-alter>true</allow-alter>
- <allow-create>true</allow-create>
- <allow-update>true</allow-update>
- <allow-execute>true</allow-execute>
</permission>
<mapped-role-name>ROLE1</mapped-role-name>
<mapped-role-name>ROLE2</mapped-role-name>
Modified: trunk/client/src/main/resources/vdb-deployer.xsd
===================================================================
--- trunk/client/src/main/resources/vdb-deployer.xsd 2012-05-07 19:02:20 UTC (rev 4072)
+++ trunk/client/src/main/resources/vdb-deployer.xsd 2012-05-07 20:10:17 UTC (rev 4073)
@@ -40,8 +40,12 @@
</xs:documentation>
</xs:annotation>
<xs:complexType>
- <xs:attribute name="type"
type="xs:string" default="DDL"/>
- </xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="type"
type="xs:string" default="DDL"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
</xs:element>
<xs:element name="validation-error" minOccurs="0"
maxOccurs="unbounded">
<xs:annotation>
@@ -70,6 +74,10 @@
<xs:attribute name="visible" type="xs:boolean"
default="true"/>
<xs:attribute name="path"
type="xs:string"/>
</xs:complexType>
+ <xs:unique name="sourceNameUnique">
+ <xs:selector xpath="source"/>
+ <xs:field xpath="@name"/>
+ </xs:unique>
</xs:element>
<xs:element name="translator"
maxOccurs="unbounded" minOccurs="0">
<xs:annotation>
@@ -133,6 +141,10 @@
<xs:attribute name="name" type="xs:string"
use="required"/>
<xs:attribute name="version" type="xs:int"
use="required"/>
</xs:complexType>
+ <xs:unique name="modelNameUnique">
+ <xs:selector xpath="model"/>
+ <xs:field xpath="@name"/>
+ </xs:unique>
</xs:element>
<xs:complexType name="property">
<xs:annotation>
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java 2012-05-07
19:02:20 UTC (rev 4072)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java 2012-05-07
20:10:17 UTC (rev 4073)
@@ -66,6 +66,7 @@
TEIID50026, // VDB undeployed
TEIID50029, // dynamic metadata loaded
TEIID50030,
+ TEIID50031, // multiple sources, non-multisource
TEIID50032, // duplicate VDB
TEIID50033, // duplicate source name in vdb
TEIID50034, // Source name mismatch
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java 2012-05-07
19:02:20 UTC (rev 4072)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java 2012-05-07
20:10:17 UTC (rev 4073)
@@ -43,6 +43,7 @@
import org.teiid.logging.LogManager;
import org.teiid.metadata.VdbConstants;
import org.teiid.metadata.index.IndexMetadataStore;
+import org.xml.sax.SAXException;
/**
@@ -107,6 +108,7 @@
private VDBMetaData parseVDBXML(VirtualFile file, DeploymentUnit deploymentUnit,
DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
try {
+ VDBMetadataParser.validate(file.openStream());
VDBMetaData vdb = VDBMetadataParser.unmarshell(file.openStream());
ServiceController<?> sc =
phaseContext.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER);
ObjectSerializer serializer = ObjectSerializer.class.cast(sc.getValue());
@@ -120,6 +122,8 @@
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(),
e);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(),
e);
+ } catch (SAXException e) {
+ throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(),
e);
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-05-07
19:02:20 UTC (rev 4072)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-05-07
20:10:17 UTC (rev 4073)
@@ -219,6 +219,9 @@
if (sourceNames.size() != new HashSet<String>(sourceNames).size()) {
throw new
StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50033,
model.getName(), deployment.getName(), deployment.getVersion()));
}
+ if (sourceNames.size() > 1 && !model.isSupportsMultiSourceBindings()) {
+ throw new
StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50031,
model.getName(), deployment.getName(), deployment.getVersion()));
+ }
for (String source:sourceNames) {
ConnectorManager cm = cmr.getConnectorManager(source);
String name = model.getSourceTranslatorName(source);
Modified: trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2012-05-07
19:02:20 UTC (rev 4072)
+++ trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2012-05-07
20:10:17 UTC (rev 4073)
@@ -67,6 +67,7 @@
TEIID50036=VDB {0}.{1} model "{2}" metadata failed to load. Reason:{3}
TEIID50042=error setting state {0}
TEIID50033=Source names are not unique for model {0} in {1}.{2}
+TEIID50031=Multiple sources on non multi-source model {0} in {1}.{2}
TEIID50034=There are different sources with the name {0} in {1}.{2}
TEIID50043=Invalid metadata file found at {0}; delete this file and restart server.
TEIID50069=Failed to load module {0}