use of org.apache.olingo.commons.api.data.ComplexValue 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.ComplexValue 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();
}
Aggregations