Search in sources :

Example 91 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class EntityCollectionResponse method createEntity.

static Entity createEntity(Row row, DocumentNode node, String baseURL, EntityCollectionResponse response) throws SQLException {
    List<ProjectedColumn> projected = node.getAllProjectedColumns();
    EdmEntityType entityType = node.getEdmEntityType();
    LinkedHashMap<String, Link> streamProperties = new LinkedHashMap<String, Link>();
    Entity entity = new Entity();
    entity.setType(entityType.getFullQualifiedName().getFullQualifiedNameAsString());
    boolean allNulls = true;
    for (ProjectedColumn column : projected) {
        /*
            if (!column.isVisible()) {
                continue;
            }*/
        String propertyName = Symbol.getShortName(column.getExpression());
        Object value = row.getObject(column.getOrdinal());
        if (value != null) {
            allNulls = false;
        }
        try {
            SingletonPrimitiveType type = (SingletonPrimitiveType) column.getEdmType();
            if (type instanceof EdmStream) {
                buildStreamLink(streamProperties, value, propertyName);
                if (response != null) {
                    // this will only be used for a stream response off of the first entity. In all other scenarios it will be ignored.
                    response.setStream(propertyName, value);
                }
            } else {
                Property property = buildPropery(propertyName, type, column.getPrecision(), column.getScale(), column.isCollection(), value);
                entity.addProperty(property);
            }
        } catch (IOException e) {
            throw new SQLException(e);
        } catch (TeiidProcessingException e) {
            throw new SQLException(e);
        }
    }
    if (allNulls) {
        return null;
    }
    // Build the navigation and Stream Links
    try {
        String id = EntityResponse.buildLocation(baseURL, entity, entityType.getName(), entityType);
        entity.setId(new URI(id));
        // build stream properties
        for (String name : streamProperties.keySet()) {
            Link link = streamProperties.get(name);
            link.setHref(id + "/" + name);
            entity.getMediaEditLinks().add(link);
            entity.addProperty(createPrimitive(name, EdmStream.getInstance(), new URI(link.getHref())));
        }
        // build navigations
        for (String name : entityType.getNavigationPropertyNames()) {
            Link navLink = new Link();
            navLink.setTitle(name);
            navLink.setHref(id + "/" + name);
            navLink.setRel("http://docs.oasis-open.org/odata/ns/related/" + name);
            entity.getNavigationLinks().add(navLink);
            Link assosiationLink = new Link();
            assosiationLink.setTitle(name);
            assosiationLink.setHref(id + "/" + name + "/$ref");
            assosiationLink.setRel("http://docs.oasis-open.org/odata/ns/relatedlinks/" + name);
            entity.getAssociationLinks().add(assosiationLink);
        }
    } catch (URISyntaxException e) {
        throw new SQLException(e);
    } catch (EdmPrimitiveTypeException e) {
        throw new SQLException(e);
    }
    return entity;
}
Also used : Entity(org.apache.olingo.commons.api.data.Entity) SQLException(java.sql.SQLException) EdmStream(org.apache.olingo.commons.core.edm.primitivetype.EdmStream) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) URI(java.net.URI) ProjectedColumn(org.teiid.olingo.ProjectedColumn) LinkedHashMap(java.util.LinkedHashMap) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) Property(org.apache.olingo.commons.api.data.Property) Link(org.apache.olingo.commons.api.data.Link)

Example 92 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class StaticContentServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String pathInfo = request.getPathInfo();
    try {
        if (// $NON-NLS-1$
        pathInfo.endsWith(".xml") && // $NON-NLS-1$
        !pathInfo.endsWith("pom.xml") && // $NON-NLS-1$
        !pathInfo.contains("META-INF") && // $NON-NLS-1$
        !pathInfo.contains("WEB-INF") && !pathInfo.substring(1).contains("/")) {
            // $NON-NLS-1$
            InputStream contents = getClass().getResourceAsStream(pathInfo);
            if (contents != null) {
                writeContent(response, contents);
                response.flushBuffer();
                return;
            }
        }
        throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16055, pathInfo));
    } catch (TeiidProcessingException e) {
        ODataFilter.writeError(request, e, response, 404);
    }
}
Also used : InputStream(java.io.InputStream) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6