Search in sources :

Example 1 with EdmEntitySet

use of org.apache.olingo.commons.api.edm.EdmEntitySet in project cxf by apache.

the class DemoEntityCollectionProcessor method readEntityCollection.

// CHECKSTYLE:ON
// the only method that is declared in the EntityCollectionProcessor interface
// this method is called, when the user fires a request to an EntitySet
// in our example, the URL would be:
// http://localhost:8080/ExampleService1/ExampleServlet1.svc/Products
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat) throws ODataApplicationException, SerializerException {
    // 1st we have retrieve the requested EntitySet from the uriInfo object
    // (representation of the parsed service URI)
    List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
    // In our example, the first segment is the EntitySet
    UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
    EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
    // 2nd: fetch the data from backend for this requested EntitySetName
    // it has to be delivered as EntitySet object
    EntityCollection entitySet = getData(edmEntitySet);
    // 3rd: create a serializer based on the requested format (json)
    ODataSerializer serializer = odata.createSerializer(responseFormat);
    // 4th: Now serialize the content: transform from the EntitySet object to InputStream
    EdmEntityType edmEntityType = edmEntitySet.getEntityType();
    ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
    final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
    EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
    SerializerResult serializedContent = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);
    // Finally: configure the response object: set the body, headers and status code
    response.setContent(serializedContent.getContent());
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
Also used : UriResource(org.apache.olingo.server.api.uri.UriResource) ODataSerializer(org.apache.olingo.server.api.serializer.ODataSerializer) ContextURL(org.apache.olingo.commons.api.data.ContextURL) EntityCollection(org.apache.olingo.commons.api.data.EntityCollection) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) EdmEntitySet(org.apache.olingo.commons.api.edm.EdmEntitySet) SerializerResult(org.apache.olingo.server.api.serializer.SerializerResult) EntityCollectionSerializerOptions(org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions) UriResourceEntitySet(org.apache.olingo.server.api.uri.UriResourceEntitySet)

Example 2 with EdmEntitySet

use of org.apache.olingo.commons.api.edm.EdmEntitySet in project teiid by teiid.

the class ODataSQLBuilder method visit.

@Override
public void visit(UriInfoCrossjoin info) {
    for (String name : info.getEntitySetNames()) {
        EdmEntitySet entitySet = this.serviceMetadata.getEdm().getEntityContainer().getEntitySet(name);
        EdmEntityType entityType = entitySet.getEntityType();
        CrossJoinNode resource = null;
        try {
            boolean hasExpand = hasExpand(entitySet.getName(), info.getExpandOption());
            resource = CrossJoinNode.buildCrossJoin(entityType, null, this.metadata, this.odata, this.nameGenerator, this.aliasedGroups, getUriInfo(), this.parseService, hasExpand);
            resource.addAllColumns(!hasExpand);
            if (this.context == null) {
                this.context = resource;
                this.orderBy = this.context.addDefaultOrderBy();
            } else {
                this.context.addSibiling(resource);
                OrderBy orderby = resource.addDefaultOrderBy();
                int index = orderby.getVariableCount();
                for (int i = 0; i < index; i++) {
                    this.orderBy.addVariable(orderby.getVariable(i));
                }
            }
        } catch (TeiidException e) {
            this.exceptions.add(e);
        }
    }
    super.visit(info);
    // the expand behavior is handled above with selection of the columns
    this.expandOption = null;
}
Also used : EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) EdmEntitySet(org.apache.olingo.commons.api.edm.EdmEntitySet) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidException(org.teiid.core.TeiidException)

Aggregations

EdmEntitySet (org.apache.olingo.commons.api.edm.EdmEntitySet)2 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)2 ContextURL (org.apache.olingo.commons.api.data.ContextURL)1 EntityCollection (org.apache.olingo.commons.api.data.EntityCollection)1 EntityCollectionSerializerOptions (org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions)1 ODataSerializer (org.apache.olingo.server.api.serializer.ODataSerializer)1 SerializerResult (org.apache.olingo.server.api.serializer.SerializerResult)1 UriResource (org.apache.olingo.server.api.uri.UriResource)1 UriResourceEntitySet (org.apache.olingo.server.api.uri.UriResourceEntitySet)1 TeiidException (org.teiid.core.TeiidException)1 SubqueryHint (org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)1