Skip to content

Commit

Permalink
Merge pull request #674 from rareddy/TEIID-3520
Browse files Browse the repository at this point in the history
TEIID-3520
  • Loading branch information
rareddy committed Apr 21, 2016
2 parents 7ec4035 + d38a504 commit 9f47c6e
Show file tree
Hide file tree
Showing 51 changed files with 5,973 additions and 110 deletions.
4 changes: 3 additions & 1 deletion api/src/main/java/org/teiid/metadata/MetadataFactory.java
Expand Up @@ -70,6 +70,7 @@ public class MetadataFactory implements Serializable {
private static final String TEIID_HBASE = "teiid_hbase"; //$NON-NLS-1$
private static final String TEIID_SPATIAL = "teiid_spatial"; //$NON-NLS-1$
private static final String TEIID_LDAP = "teiid_ldap"; //$NON-NLS-1$
private static final String TEIID_REST = "teiid_rest"; //$NON-NLS-1$

private static final long serialVersionUID = 8590341087771685630L;

Expand Down Expand Up @@ -100,7 +101,7 @@ public class MetadataFactory implements Serializable {
public static final String HBASE_URI = "{http://www.teiid.org/translator/hbase/2014}"; //$NON-NLS-1$
public static final String SPATIAL_URI = "{http://www.teiid.org/translator/spatial/2015}"; //$NON-NLS-1$
public static final String LDAP_URI = "{http://www.teiid.org/translator/ldap/2015}"; //$NON-NLS-1$

public static final String REST_URI = "{http://teiid.org/rest}"; //$NON-NLS-1$

public static final Map<String, String> BUILTIN_NAMESPACES;
static {
Expand All @@ -116,6 +117,7 @@ public class MetadataFactory implements Serializable {
map.put(TEIID_HBASE, HBASE_URI.substring(1, HBASE_URI.length()-1));
map.put(TEIID_SPATIAL, SPATIAL_URI.substring(1, SPATIAL_URI.length()-1));
map.put(TEIID_LDAP, LDAP_URI.substring(1, LDAP_URI.length()-1));
map.put(TEIID_REST, REST_URI.substring(1, REST_URI.length()-1));
BUILTIN_NAMESPACES = Collections.unmodifiableMap(map);
}

Expand Down
9 changes: 9 additions & 0 deletions api/src/main/java/org/teiid/metadata/Procedure.java
Expand Up @@ -84,6 +84,15 @@ public int getUpdateCount() {
public List<ProcedureParameter> getParameters() {
return parameters;
}

public ProcedureParameter getParameterByName(String param) {
for(ProcedureParameter p: this.parameters) {
if (p.getName().equals(param)) {
return p;
}
}
return null;
}

public void setParameters(List<ProcedureParameter> parameters) {
this.parameters = parameters;
Expand Down
38 changes: 38 additions & 0 deletions api/src/main/java/org/teiid/metadata/RestMetadataExtension.java
@@ -0,0 +1,38 @@
/*
* 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.metadata;


public class RestMetadataExtension {
public enum ParameterType {
PATH,QUERY,FORM,FORMDATA,BODY,HEADER;
}

public final static String URI = "teiid_rest:URI";
public final static String METHOD = "teiid_rest:METHOD";
public final static String SCHEME = "teiid_rest:SCHEME";
public final static String PRODUCES = "teiid_rest:PRODUCES";
public final static String CONSUMES = "teiid_rest:CONSUMES";
public final static String CHARSET = "teiid_rest:CHARSET";
public final static String PARAMETER_TYPE = "teiid_rest:PARAMETER_TYPE";
public final static String COLLECION_FORMAT = "teiid_rest:COLLECION_FORMAT";
}
28 changes: 28 additions & 0 deletions connectors/document-api/pom.xml
@@ -0,0 +1,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
<version>9.0.0.Alpha2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>document-api</artifactId>
<groupId>org.jboss.teiid.connectors</groupId>
<name>Document API</name>
<description>The java API for dealing with object types</description>
<packaging>bundle</packaging>

<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.resource</groupId>
<artifactId>jboss-connector-api_1.7_spec</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-common-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-api</artifactId>
</dependency>
</dependencies>
</project>
Expand Up @@ -22,37 +22,38 @@
package org.teiid.translator.document;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Property;

/**
* TODO: need to back this up with something like MapDB, to avoid OOM
* Also need to write our own JSONPaser that returns this object directly.
*/
public class ODataDocument {
public class Document {
private String name;
private Map<String, Object> properties;
private Map<String, List<ODataDocument>> children;
private ODataDocument parent;
private Map<String, Object> properties = new LinkedHashMap<String, Object>();
private Map<String, List<Document>> children = new LinkedHashMap<String, List<Document>>();
private boolean array;
private Document parent;

public ODataDocument() {
public Document() {
}

ODataDocument(String name, ODataDocument parent) {
public Document(String name, boolean array, Document parent) {
this.name = name;
this.parent = parent;
this.array = array;
}

public boolean isArray() {
return array;
}

static List<Map<String, Object>> crossjoinWith(
List<Map<String, Object>> left, List<ODataDocument> rightDocuments) {
List<Map<String, Object>> left, List<? extends Document> rightDocuments) {
ArrayList<Map<String, Object>> joined = new ArrayList<Map<String,Object>>();
for (ODataDocument right : rightDocuments) {
for (Document right : rightDocuments) {
List<Map<String,Object>> rightRows = right.flatten();
for (Map<String, Object> outer : left) {
for (Map<String, Object> inner : rightRows) {
Expand All @@ -74,18 +75,22 @@ public List<Map<String, Object>> flatten(){
}
joined.add(row);
if (this.children != null && !this.children.isEmpty()) {
for (List<ODataDocument> childDoc:this.children.values()) {
for (List<? extends Document> childDoc:this.children.values()) {
joined = crossjoinWith(joined, childDoc);
}
}
return joined;
}

Map<String, Object> getProperties(){
public Map<String, Object> getProperties(){
return this.properties;
}

List<ODataDocument> getChildDocuments(String path) {
public Map<String, List<Document>> getChildren() {
return children;
}

public List<? extends Document> getChildDocuments(String path) {
if (this.children != null) {
int index = path.indexOf('/');
if (index != -1) {
Expand All @@ -97,7 +102,7 @@ List<ODataDocument> getChildDocuments(String path) {
return this.parent.getChildDocuments(parentName);
}
}
List<ODataDocument> children = this.children.get(path);
List<? extends Document> children = this.children.get(path);
if (children == null && this.parent != null) {
children = this.parent.getChildDocuments(path);
}
Expand All @@ -124,80 +129,51 @@ public String getName() {
}

public void addProperty(String key, Object value) {
if (this.properties == null) {
this.properties = new LinkedHashMap<String, Object>();
}
if (this.parent == null) {
this.properties.put(key, value);
} else {
this.properties.put(name(getName(), key), value);
}
}

public void addChildDocuments(String path, List<ODataDocument> child) {
if (this.children == null) {
this.children = new LinkedHashMap<String, List<ODataDocument>>();
}
this.children.put(path, child);
}


public static ODataDocument createDocument(Entity entity) {
ODataDocument document = new ODataDocument();
List<Property> properties = entity.getProperties();
for (Property property : properties) {
populateDocument(property, document);
public void addArrayProperty(String key, Object value) {
if (this.properties == null) {
this.properties = new LinkedHashMap<String, Object>();
}
return document;
}

public static ODataDocument createDocument(ComplexValue complex) {
ODataDocument document = new ODataDocument();
List<Property> properties = complex.getValue();
for (Property property : properties) {
populateDocument(property, document);

String propkey = this.parent == null?key:name(getName(), key);
@SuppressWarnings("unchecked")
List<Object> propValue = (List<Object>)this.properties.get(propkey);

if (propValue == null) {
propValue = new ArrayList<Object>();
propValue.add(value);
} else {
propValue.add(value);
}
return document;
this.properties.put(propkey, propValue);
}

private static ODataDocument createDocument(String name,
ComplexValue complex, ODataDocument parent) {
ODataDocument document = new ODataDocument(name, parent);
List<Property> properties = complex.getValue();
for (Property property : properties) {
populateDocument(property, document);
}
return document;
public void addChildDocuments(String path, List<Document> child) {
this.children.put(path, child);
}

@SuppressWarnings("unchecked")
private static void populateDocument(Property property, ODataDocument document) {
if (property.isCollection()) {
if (property.isPrimitive()) {
document.addProperty(property.getName(), property.asCollection());
} else {
List<ComplexValue> complexRows = (List<ComplexValue>)property.asCollection();
ArrayList<ODataDocument> rows = new ArrayList<ODataDocument>();
for (ComplexValue complexRow : complexRows) {
rows.add(createDocument(property.getName(), complexRow, document));
}
document.addChildDocuments(property.getName(), rows);
}
} else {
if (property.isPrimitive()) {
document.addProperty(property.getName(), property.asPrimitive());
} else if (property.isComplex()) {
document.addChildDocuments(property.getName(), Arrays.asList(createDocument(
property.getName(), property.asComplex(), document)));
} else if (property.isGeospatial()) {
document.addProperty(property.getName(), property.asGeospatial());
} else {
throw new AssertionError(property.getType() + " not supported"); //$NON-NLS-1$
}
public List<Document> addChildDocument(String path, Document child) {
if (this.children == null) {
this.children = new LinkedHashMap<String, List<Document>>();
}
}

if (children.get(path) == null) {
children.put(path, new ArrayList<Document>());
}
this.children.get(path).add(child);
return this.children.get(path);
}

public String toString() {
return this.name;
}

public Document getParent() {
return this.parent;
}
}
Expand Up @@ -7,7 +7,7 @@

import org.teiid.language.Join.JoinType;

public class DocumentJoinNode extends DocumentNode {
class DocumentJoinNode extends DocumentNode {
private DocumentNode left;
private DocumentNode right;
private JoinType type;
Expand All @@ -19,9 +19,9 @@ public DocumentJoinNode(DocumentNode left, JoinType joinType, DocumentNode right
}

public List<Map<String, Object>> mergeTuples(List<Map<String, Object>> leftRows,
ODataDocument parentDocument) {
Document parentDocument) {
List<Map<String, Object>> joinedRows = new ArrayList<Map<String,Object>>();
List<ODataDocument> rightDocuments = parentDocument
List<? extends Document> rightDocuments = parentDocument
.getChildDocuments(this.right.getName());
if (rightDocuments == null) {
if (this.type.equals(JoinType.LEFT_OUTER_JOIN)) {
Expand All @@ -38,7 +38,7 @@ public List<Map<String, Object>> mergeTuples(List<Map<String, Object>> leftRows,
}
} else {
for (Map<String, Object> leftRow:leftRows) {
for (ODataDocument rightDocument : rightDocuments) {
for (Document rightDocument : rightDocuments) {
Map<String, Object> rightRow = rightDocument.getProperties();
LinkedHashMap<String, Object> row = new LinkedHashMap<String, Object>();
if (this.type.equals(JoinType.INNER_JOIN)) {
Expand All @@ -57,7 +57,7 @@ public List<Map<String, Object>> mergeTuples(List<Map<String, Object>> leftRows,

if (this.joinNode != null) {
// do further joins, only span up to sibiling or child
for (ODataDocument rightDocument : rightDocuments) {
for (Document rightDocument : rightDocuments) {
joinedRows = this.joinNode.mergeTuples(joinedRows, rightDocument);
}
}
Expand Down
Expand Up @@ -29,10 +29,6 @@ public DocumentJoinNode joinWith(JoinType joinType, DocumentNode right) {
return this.joinNode;
}

public DocumentJoinNode getJoinNode() {
return this.joinNode;
}

public Table getTable() {
return this.table;
}
Expand All @@ -59,7 +55,7 @@ public List<String> getIdentityColumns(){
return keys;
}

public List<Map<String, Object>> tuples(ODataDocument document) {
public List<Map<String, Object>> tuples(Document document) {
List<Map<String, Object>> joined = new ArrayList<Map<String, Object>>();

Map<String, Object> row = new LinkedHashMap<String, Object>();
Expand Down
@@ -0,0 +1,4 @@
login_error=Error when attempting Client Login
missing_authkey=Authkey read from server is null
authkey_read_error=Error reading Client Login response
metadata_error=Error getting metadata about Spreadsheets worksheet

0 comments on commit 9f47c6e

Please sign in to comment.