use of org.apache.olingo.commons.api.data.Link 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.Link 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;
}
use of org.apache.olingo.commons.api.data.Link in project teiid by teiid.
the class EntityCollectionResponse method buildStreamLink.
private static void buildStreamLink(LinkedHashMap<String, Link> streamProperties, Object value, String propName) {
if (value != null) {
// read link
Link streamLink = new Link();
streamLink.setTitle(propName);
if (value instanceof SQLXML) {
streamLink.setType("application/xml");
} else if (value instanceof Clob) {
streamLink.setType("application/json");
} else if (value instanceof Blob) {
streamLink.setType("application/octet-stream");
}
streamLink.setRel("http://docs.oasis-open.org/odata/ns/mediaresource/" + propName);
streamProperties.put(propName, streamLink);
}
}
use of org.apache.olingo.commons.api.data.Link 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;
}
use of org.apache.olingo.commons.api.data.Link in project teiid by teiid.
the class EntityCollectionResponse method processExpands.
private void processExpands(Row vals, Entity entity, DocumentNode node) throws SQLException {
if (node.getExpands() == null || node.getExpands().isEmpty()) {
return;
}
for (ExpandDocumentNode expandNode : node.getExpands()) {
Object[] expandedVals = vals.getArray(expandNode.getColumnIndex());
if (expandedVals == null) {
continue;
}
for (Object o : expandedVals) {
Object[] expandedVal = (Object[]) o;
Entity expandEntity = createEntity(expandedVal, expandNode, this.baseURL, this);
Link link = entity.getNavigationLink(expandNode.getNavigationName());
if (expandNode.isCollection()) {
if (link.getInlineEntitySet() == null) {
link.setInlineEntitySet(new EntityCollectionResponse());
}
EntityCollectionResponse expandResponse = (EntityCollectionResponse) link.getInlineEntitySet();
boolean addEntity = expandResponse.processOptions(expandNode.getSkip(), expandNode.getTop(), expandEntity);
if (addEntity) {
link.getInlineEntitySet().getEntities().add(expandEntity);
}
} else {
link.setInlineEntity(expandEntity);
}
processExpands(asRow(expandedVal), expandEntity, expandNode);
}
}
}
Aggregations