Search in sources :

Example 1 with Entity

use of org.apache.olingo.commons.api.data.Entity in project cxf by apache.

the class DemoEntityCollectionProcessor method getData.

/**
 * Helper method for providing some sample data
 * @param edmEntitySet for which the data is requested
 * @return data of requested entity set
 */
private EntityCollection getData(EdmEntitySet edmEntitySet) {
    EntityCollection productsCollection = new EntityCollection();
    // check for which EdmEntitySet the data is requested
    if (DemoEdmProvider.ES_PRODUCTS_NAME.equals(edmEntitySet.getName())) {
        List<Entity> productList = productsCollection.getEntities();
        // add some sample product entities
        final Entity e1 = new Entity().addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1)).addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15")).addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
        e1.setId(createId("Products", 1));
        productList.add(e1);
        final Entity e2 = new Entity().addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2)).addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA")).addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
        e2.setId(createId("Products", 1));
        productList.add(e2);
        final Entity e3 = new Entity().addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3)).addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen")).addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
        e3.setId(createId("Products", 1));
        productList.add(e3);
    }
    return productsCollection;
}
Also used : Entity(org.apache.olingo.commons.api.data.Entity) EntityCollection(org.apache.olingo.commons.api.data.EntityCollection) Property(org.apache.olingo.commons.api.data.Property)

Example 2 with Entity

use of org.apache.olingo.commons.api.data.Entity in project teiid by teiid.

the class TeiidServiceHandler method performDeepInsert.

private UpdateResponse performDeepInsert(String rawURI, UriInfo uriInfo, EdmEntityType entityType, Entity entity, List<ExpandNode> expandNodes) throws SQLException, TeiidException {
    UpdateResponse response = performInsert(rawURI, uriInfo, entityType, entity);
    for (String navigationName : entityType.getNavigationPropertyNames()) {
        EdmNavigationProperty navProperty = entityType.getNavigationProperty(navigationName);
        Link navLink = entity.getNavigationLink(navigationName);
        if (navLink != null && navLink.getInlineEntity() != null) {
            ExpandNode node = new ExpandNode();
            node.navigationProperty = navProperty;
            expandNodes.add(node);
            performDeepInsert(rawURI, uriInfo, navProperty.getType(), navLink.getInlineEntity(), node.children);
        } else if (navLink != null && navLink.getInlineEntitySet() != null && !navLink.getInlineEntitySet().getEntities().isEmpty()) {
            ExpandNode node = new ExpandNode();
            node.navigationProperty = navProperty;
            expandNodes.add(node);
            for (Entity inlineEntity : navLink.getInlineEntitySet().getEntities()) {
                performDeepInsert(rawURI, uriInfo, navProperty.getType(), inlineEntity, node.children);
            }
        }
    }
    return response;
}
Also used : UpdateResponse(org.teiid.odata.api.UpdateResponse) Entity(org.apache.olingo.commons.api.data.Entity) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) Link(org.apache.olingo.commons.api.data.Link)

Example 3 with Entity

use of org.apache.olingo.commons.api.data.Entity in project teiid by teiid.

the class ODataResponse method parsePayload.

private Iterator<ODataDocument> parsePayload(InputStream payload) throws TranslatorException {
    try {
        JsonDeserializer parser = new JsonDeserializer(false);
        if (this.resultsType == ODataType.ENTITY) {
            Entity entity = parser.toEntity(payload).getPayload();
            ODataDocument document = ODataDocument.createDocument(entity);
            return Arrays.asList(document).iterator();
        } else if (this.resultsType == ODataType.ENTITY_COLLECTION) {
            EntityCollection entityCollection = parser.toEntitySet(payload).getPayload();
            this.nextUri = entityCollection.getNext();
            ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
            for (Entity entity : entityCollection.getEntities()) {
                documents.add(ODataDocument.createDocument(entity));
            }
            return documents.iterator();
        } else {
            // complex
            Property property = parser.toProperty(payload).getPayload();
            if (property.isCollection()) {
                ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
                for (Object obj : property.asCollection()) {
                    ComplexValue complexValue = (ComplexValue) obj;
                    documents.add(ODataDocument.createDocument(complexValue));
                }
                return documents.iterator();
            } else {
                ODataDocument document = ODataDocument.createDocument(property.asComplex());
                return Arrays.asList(document).iterator();
            }
        }
    } catch (ODataDeserializerException e) {
        throw new TranslatorException(e);
    }
}
Also used : Entity(org.apache.olingo.commons.api.data.Entity) ComplexValue(org.apache.olingo.commons.api.data.ComplexValue) EntityCollection(org.apache.olingo.commons.api.data.EntityCollection) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) ODataDeserializerException(org.apache.olingo.client.api.serialization.ODataDeserializerException) JsonDeserializer(org.apache.olingo.client.core.serialization.JsonDeserializer) Property(org.apache.olingo.commons.api.data.Property)

Example 4 with Entity

use of org.apache.olingo.commons.api.data.Entity in project teiid by teiid.

the class ODataUpdateQuery method getPayload.

public String getPayload(Entity parentEntity) throws TranslatorException {
    JsonSerializer serializer = new JsonSerializer(false, ContentType.APPLICATION_JSON);
    StringWriter writer = new StringWriter();
    try {
        if (!this.complexTables.isEmpty()) {
            Table table = this.complexTables.get(0).getTable();
            Property complexProperty = new Property();
            complexProperty.setName(getName(table));
            complexProperty.setType(table.getProperty(ODataMetadataProcessor.NAME_IN_SCHEMA, false));
            ComplexValue value = new ComplexValue();
            for (Property p : this.payloadProperties) {
                value.getValue().add(p);
            }
            if (this.complexTables.get(0).isCollection()) {
                complexProperty.setValue(ValueType.COLLECTION_COMPLEX, Arrays.asList(value));
            } else {
                complexProperty.setValue(ValueType.COMPLEX, value);
            }
            serializer.write(writer, complexProperty);
        } else if (!this.expandTables.isEmpty()) {
            Table table = this.expandTables.get(0).getTable();
            Entity entity = new Entity();
            entity.setType(table.getProperty(ODataMetadataProcessor.NAME_IN_SCHEMA, false));
            for (Property p : this.payloadProperties) {
                entity.addProperty(p);
            }
            serializer.write(writer, entity);
        } else {
            Entity entity = new Entity();
            entity.setType(this.rootDocument.getTable().getProperty(ODataMetadataProcessor.NAME_IN_SCHEMA, false));
            for (Property p : this.payloadProperties) {
                entity.addProperty(p);
            }
            // for updates
            if (parentEntity != null) {
                // add all the key properties.
                List<Column> keys = this.rootDocument.getTable().getPrimaryKey().getColumns();
                for (Column key : keys) {
                    entity.addProperty(parentEntity.getProperty(key.getName()));
                }
            }
            serializer.write(writer, entity);
        }
    } catch (ODataSerializerException e) {
        throw new TranslatorException(e);
    }
    return writer.toString();
}
Also used : ComplexValue(org.apache.olingo.commons.api.data.ComplexValue) Entity(org.apache.olingo.commons.api.data.Entity) ODataSerializerException(org.apache.olingo.client.api.serialization.ODataSerializerException) Table(org.teiid.metadata.Table) StringWriter(java.io.StringWriter) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException) JsonSerializer(org.apache.olingo.client.core.serialization.JsonSerializer) Property(org.apache.olingo.commons.api.data.Property)

Example 5 with Entity

use of org.apache.olingo.commons.api.data.Entity in project teiid by teiid.

the class TeiidServiceHandler method insertDepth.

private int insertDepth(EdmEntityType entityType, Entity entity) throws SQLException, TeiidException {
    int depth = 1;
    int childDepth = 0;
    for (String navigationName : entityType.getNavigationPropertyNames()) {
        EdmNavigationProperty navProperty = entityType.getNavigationProperty(navigationName);
        Link navLink = entity.getNavigationLink(navigationName);
        if (navLink != null && navLink.getInlineEntity() != null) {
            childDepth = Math.max(childDepth, insertDepth(navProperty.getType(), navLink.getInlineEntity()));
        } else if (navLink != null && navLink.getInlineEntitySet() != null && !navLink.getInlineEntitySet().getEntities().isEmpty()) {
            for (Entity inlineEntity : navLink.getInlineEntitySet().getEntities()) {
                childDepth = Math.max(childDepth, insertDepth(navProperty.getType(), inlineEntity));
            }
        }
    }
    return depth + childDepth;
}
Also used : Entity(org.apache.olingo.commons.api.data.Entity) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) Link(org.apache.olingo.commons.api.data.Link)

Aggregations

Entity (org.apache.olingo.commons.api.data.Entity)11 Property (org.apache.olingo.commons.api.data.Property)5 Link (org.apache.olingo.commons.api.data.Link)4 ArrayList (java.util.ArrayList)3 EntityCollection (org.apache.olingo.commons.api.data.EntityCollection)3 EdmNavigationProperty (org.apache.olingo.commons.api.edm.EdmNavigationProperty)3 StringWriter (java.io.StringWriter)2 SQLException (java.sql.SQLException)2 ComplexValue (org.apache.olingo.commons.api.data.ComplexValue)2 TranslatorException (org.teiid.translator.TranslatorException)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Olingo4Component (org.apache.camel.component.olingo4.Olingo4Component)1 Olingo4Configuration (org.apache.camel.component.olingo4.Olingo4Configuration)1 ClientEntity (org.apache.olingo.client.api.domain.ClientEntity)1 ODataDeserializerException (org.apache.olingo.client.api.serialization.ODataDeserializerException)1 ODataSerializer (org.apache.olingo.client.api.serialization.ODataSerializer)1