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;
}
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;
}
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);
}
}
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();
}
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;
}
Aggregations