Search in sources :

Example 6 with Document

use of org.teiid.translator.document.Document in project teiid by teiid.

the class SwaggerBodyInputDocument method addArgument.

private void addArgument(Document document, String nis, Object payload) {
    int index = nis.indexOf('/');
    if (index == -1) {
        if (payload instanceof Object[]) {
            Object[] array = (Object[]) payload;
            for (Object anObj : array) {
                document.addArrayProperty(nis, anObj);
            }
        } else {
            document.addProperty(nis, payload);
        }
    } else {
        String childPath = nis.substring(0, index);
        List<? extends Document> child = document.getChildDocuments(childPath);
        String propertyName = nis.substring(index + 1);
        if (child == null) {
            boolean array = false;
            if (childPath.endsWith("[]")) {
                childPath = childPath.substring(0, childPath.length() - 2);
                propertyName = nis.substring(nis.indexOf("/", index + 1) + 1);
                array = true;
            }
            Document d = new Document(childPath, array, this);
            child = document.addChildDocument(childPath, d);
        }
        addArgument(child.get(0), propertyName, payload);
    }
}
Also used : Document(org.teiid.translator.document.Document)

Example 7 with Document

use of org.teiid.translator.document.Document in project teiid by teiid.

the class SwaggerResponse method getNext.

public Map<String, Object> getNext() throws TranslatorException {
    if (this.currentDocumentRows != null && !this.currentDocumentRows.isEmpty()) {
        return this.currentDocumentRows.remove(0);
    }
    if (this.results.hasNext()) {
        Document d = this.results.next();
        List<Map<String, Object>> rows = d.flatten();
        List<Map<String, Object>> mapResults = new ArrayList<Map<String, Object>>();
        if (this.mapResponse && !rows.isEmpty()) {
            for (String key : rows.get(0).keySet()) {
                Map<String, Object> map = new LinkedHashMap<String, Object>();
                map.put(key, rows.get(0).get(key));
                mapResults.add(map);
            }
            rows = mapResults;
        }
        this.currentDocumentRows = rows;
        return getNext();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Document(org.teiid.translator.document.Document) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Document (org.teiid.translator.document.Document)7 List (java.util.List)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 RawProtoStreamWriter (org.infinispan.protostream.RawProtoStreamWriter)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 Stack (java.util.Stack)1 RawProtoStreamReader (org.infinispan.protostream.RawProtoStreamReader)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 ByteArrayOutputStreamEx (org.infinispan.protostream.impl.ByteArrayOutputStreamEx)1 Test (org.junit.Test)1 InfinispanDocument (org.teiid.infinispan.api.InfinispanDocument)1 TeiidTableMarsheller (org.teiid.infinispan.api.TeiidTableMarsheller)1 Expression (org.teiid.language.Expression)1 TranslatorException (org.teiid.translator.TranslatorException)1