@Override public Link getLink(final ODataLink link, boolean isXML) { final Link linkResource = new LinkImpl(); linkResource.setRel(link.getRel()); linkResource.setTitle(link.getName()); linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString()); linkResource.setType(link.getType().toString()); linkResource.setMediaETag(link.getMediaETag()); if (link instanceof ODataInlineEntity) { // append inline entity final ODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity(); LOG.debug("Append in-line entity\n{}", inlineEntity); linkResource.setInlineEntry( getEntry(inlineEntity, ResourceFactory.entryClassForFormat(isXML))); } else if (link instanceof ODataInlineEntitySet) { // append inline feed final ODataEntitySet InlineFeed = ((ODataInlineEntitySet) link).getEntitySet(); LOG.debug("Append in-line feed\n{}", InlineFeed); linkResource.setInlineFeed(getFeed(InlineFeed, ResourceFactory.feedClassForFormat(isXML))); } return linkResource; }
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; }
@Override public ODataEntity getODataEntity(final Entry resource, final URI defaultBaseURI) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); client.getSerializer().entry(resource, writer); writer.flush(); LOG.debug("EntryResource -> ODataEntity:\n{}", writer.toString()); } final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI; final ODataEntity entity = resource.getSelfLink() == null ? client.getObjectFactory().newEntity(resource.getType()) : client .getObjectFactory() .newEntity( resource.getType(), URIUtils.getURI(base, resource.getSelfLink().getHref())); if (StringUtils.isNotBlank(resource.getETag())) { entity.setETag(resource.getETag()); } if (resource.getEditLink() != null) { entity.setEditLink(URIUtils.getURI(base, resource.getEditLink().getHref())); } for (Link link : resource.getAssociationLinks()) { entity.addLink( client.getObjectFactory().newAssociationLink(link.getTitle(), base, link.getHref())); } for (Link link : resource.getNavigationLinks()) { final Entry inlineEntry = link.getInlineEntry(); final Feed inlineFeed = link.getInlineFeed(); if (inlineEntry == null && inlineFeed == null) { entity.addLink( client .getObjectFactory() .newEntityNavigationLink(link.getTitle(), base, link.getHref())); } else if (inlineFeed == null) { entity.addLink( client .getObjectFactory() .newInlineEntity( link.getTitle(), base, link.getHref(), getODataEntity( inlineEntry, inlineEntry.getBaseURI() == null ? base : inlineEntry.getBaseURI()))); } else { entity.addLink( client .getObjectFactory() .newInlineEntitySet( link.getTitle(), base, link.getHref(), getODataEntitySet( inlineFeed, inlineFeed.getBaseURI() == null ? base : inlineFeed.getBaseURI()))); } } for (Link link : resource.getMediaEditLinks()) { entity.addLink( client.getObjectFactory().newMediaEditLink(link.getTitle(), base, link.getHref())); } for (ODataOperation operation : resource.getOperations()) { operation.setTarget(URIUtils.getURI(base, operation.getTarget())); entity.getOperations().add(operation); } if (resource.isMediaEntry()) { entity.setMediaEntity(true); entity.setMediaContentSource(resource.getMediaContentSource()); entity.setMediaContentType(resource.getMediaContentType()); } for (Property property : resource.getProperties()) { entity.getProperties().add(getODataProperty(property)); } return entity; }