@Override public EdmType getType() { return navigationProperty.getType(); }
@Override public EdmType getType() { return navigationProperty.getType(); }
private void buildExpandGraph(HashSet<String> seen, List<ExpandNode> starExpand, EdmEntityType edmEntityType, int remainingLevels) { for (String name : edmEntityType.getNavigationPropertyNames()) { if (seen != null && seen.contains(name)) { continue; //explicit expand supersedes } EdmNavigationProperty property = edmEntityType.getNavigationProperty(name); ExpandNode en = new ExpandNode(); en.navigationProperty = property; starExpand.add(en); if (remainingLevels > 0) { buildExpandGraph(null, en.children, property.getType(), remainingLevels - 1); } } }
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; }
protected JPAAssociationPath determineAssoziation(final UriResourcePartTyped naviStart, final StringBuilder associationName) throws ODataApplicationException { JPAEntityType naviStartType; try { if (naviStart instanceof UriResourceEntitySet) naviStartType = sd.getEntity(((UriResourceEntitySet) naviStart).getType()); else naviStartType = sd.getEntity(((UriResourceNavigation) naviStart).getProperty().getType()); return naviStartType.getAssociationPath(associationName.toString()); } catch (ODataJPAModelException e) { throw new ODataJPAQueryException(e, HttpStatusCode.BAD_REQUEST); } }
@Override public EdmNavigationProperty getPartner() { if (partnerNavigationProperty == null) { String partner = navigationProperty.getPartner(); if (partner != null) { EdmStructuredType type = getType(); EdmNavigationProperty property = null; final String[] split = partner.split("/"); for (String element : split) { property = type.getNavigationProperty(element); if (property == null) { throw new EdmException("Cannot find navigation property with name: " + element + " at type " + type.getName()); } type = property.getType(); } partnerNavigationProperty = property; } } return partnerNavigationProperty; }
@Override public EdmNavigationProperty getPartner() { if (partnerNavigationProperty == null) { String partner = navigationProperty.getPartner(); if (partner != null) { EdmStructuredType type = getType(); EdmNavigationProperty property = null; final String[] split = partner.split("/"); for (String element : split) { property = type.getNavigationProperty(element); if (property == null) { throw new EdmException("Cannot find navigation property with name: " + element + " at type " + type.getName()); } type = property.getType(); } partnerNavigationProperty = property; } } return partnerNavigationProperty; }
protected static List<UriParameter> parseNavigationKeyPredicate(UriTokenizer tokenizer, final EdmNavigationProperty navigationProperty, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { if (tokenizer.next(TokenKind.OPEN)) { if (navigationProperty.isCollection()) { return parseKeyPredicate(tokenizer, navigationProperty.getType(), navigationProperty.getPartner(), edm, referringType, aliases); } else { throw new UriParserSemanticException("A key is not allowed on non-collection navigation properties.", UriParserSemanticException.MessageKeys.KEY_NOT_ALLOWED); } } return null; }
@Override public void visit(UriResourceNavigation info) { EdmNavigationProperty property = info.getProperty(); this.referenceTable = new ScopedTable(DocumentNode.findTable(property.getType(), this.metadata), property.getType(), info.getKeyPredicates()); if (property.isCollection()) { ForeignKey fk = DocumentNode.joinFK(referenceTable, this.updateTable, property); referenceTable.setFk(fk); ScopedTable temp = this.updateTable; this.updateTable = referenceTable; this.referenceTable = temp; this.collection = true; } else { ForeignKey fk = DocumentNode.joinFK(this.updateTable, referenceTable, property); this.updateTable.setFk(fk); } }
protected static List<UriParameter> parseNavigationKeyPredicate(UriTokenizer tokenizer, final EdmNavigationProperty navigationProperty, final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { if (tokenizer.next(TokenKind.OPEN)) { if (navigationProperty.isCollection()) { return parseKeyPredicate(tokenizer, navigationProperty.getType(), navigationProperty.getPartner(), edm, referringType, aliases); } else { throw new UriParserSemanticException("A key is not allowed on non-collection navigation properties.", UriParserSemanticException.MessageKeys.KEY_NOT_ALLOWED); } } return null; }
public static ExpandDocumentNode buildExpand(EdmNavigationProperty property, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService, DocumentNode context) throws TeiidException { EdmEntityType type = property.getType(); ExpandDocumentNode resource = new ExpandDocumentNode(); build(resource, type, null, metadata, odata, nameGenerator, useAlias, uriInfo, parseService); resource.setNavigationName(property.getName()); resource.setCollection(property.isCollection()); resource.collectionContext = context; return resource; }
protected void writeExpandedNavigationProperty( final ServiceMetadata metadata, final EdmNavigationProperty property, final Link navigationLink, final ExpandOption innerExpand, final SelectOption innerSelect, final CountOption innerCount, final boolean writeOnlyCount, final boolean writeOnlyRef, final String name, final JsonGenerator json) throws IOException, SerializerException { if (property.isCollection()) { if (navigationLink != null && navigationLink.getInlineEntitySet() != null) { json.writeFieldName(property.getName() + Constants.AT + Constants.DELTAVALUE); writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand, innerSelect, writeOnlyRef, name, json); } } else { json.writeFieldName(property.getName()+ Constants.AT + Constants.DELTAVALUE); if (navigationLink != null && navigationLink.getInlineEntity() != null) { if (navigationLink.getInlineEntity() instanceof DeletedEntity) { writeDeletedEntity(navigationLink.getInlineEntity(), json); } else { writeAddedUpdatedEntity(metadata, property.getType(), navigationLink.getInlineEntity(), innerExpand, innerSelect, null, writeOnlyRef, name, json); } } } }
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; }
private static ExpandOptionImpl constructDraftTreeExpand(EdmEntityType rootEntityType,ExpandOptionImpl eO,Map<String,List<String>> draftTree) { if(eO==null) { eO=new ExpandOptionImpl(); } if(rootEntityType.getNavigationPropertyNames()!=null && !rootEntityType.getNavigationPropertyNames().isEmpty()) { for(String navName:rootEntityType.getNavigationPropertyNames()) { EdmNavigationProperty expandNp=rootEntityType.getNavigationProperty(navName); if(draftTree.get(rootEntityType.getName()).contains(expandNp.getType().getName())) { UriResourceNavigationPropertyImpl adminNaVPropImpl=new UriResourceNavigationPropertyImpl(expandNp); UriInfoImpl uriInfoForExpand = new UriInfoImpl().addResourcePart(adminNaVPropImpl); //Recursively set compositions ExpandOption innerExpandoption=constructDraftTreeExpand(expandNp.getType(),(ExpandOptionImpl) uriInfoForExpand.getExpandOption(),draftTree); if(innerExpandoption!=null) { uriInfoForExpand.setSystemQueryOption(innerExpandoption); ExpandItem eI = new ExpandItemImpl().setResourcePath(uriInfoForExpand).setSystemQueryOption(innerExpandoption); eO.addExpandItem(eI); } } } return eO; } return eO; }
@Override public void visit(UriResourceNavigation info) { EdmNavigationProperty property = info.getProperty(); try { DocumentNode joinResource = DocumentNode.build(property.getType(), info.getKeyPredicates(), this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), parseService); this.context.joinTable(joinResource, property, JoinType.JOIN_INNER); // In the context of canonical queries if key predicates are available then do not set the criteria if (joinResource.getCriteria() == null) { joinResource.addCriteria(this.context.getCriteria()); } this.context = joinResource; this.navigation = true; } catch (TeiidException e) { this.exceptions.add(e); } }
private void links(final Linked linked, final EdmEntityType entityType, JsonGenerator json) throws IOException, SerializerException { for (final Link link : linked.getNavigationLinks()) { final String name = link.getTitle(); for (final Annotation annotation : link.getAnnotations()) { valuable(json, annotation, name + '@' + annotation.getTerm(), null, null); } final EdmEntityType targetType = entityType == null || name == null || entityType.getNavigationProperty(name) == null ? null : entityType .getNavigationProperty(name).getType(); if (link.getInlineEntity() != null) { json.writeFieldName(name); doSerialize(targetType, link.getInlineEntity(), null, null, json); } else if (link.getInlineEntitySet() != null) { json.writeArrayFieldStart(name); for (final Entity subEntry : link.getInlineEntitySet().getEntities()) { doSerialize(targetType, subEntry, null, null, json); } json.writeEndArray(); } } }
private void links(final Linked linked, final EdmEntityType entityType, JsonGenerator json) throws IOException, SerializerException { for (final Link link : linked.getNavigationLinks()) { final String name = link.getTitle(); for (final Annotation annotation : link.getAnnotations()) { valuable(json, annotation, name + '@' + annotation.getTerm(), null, null); } final EdmEntityType targetType = entityType == null || name == null || entityType.getNavigationProperty(name) == null ? null : entityType .getNavigationProperty(name).getType(); if (link.getInlineEntity() != null) { json.writeFieldName(name); doSerialize(targetType, link.getInlineEntity(), null, null, json); } else if (link.getInlineEntitySet() != null) { json.writeArrayFieldStart(name); for (final Entity subEntry : link.getInlineEntitySet().getEntities()) { doSerialize(targetType, subEntry, null, null, json); } json.writeEndArray(); } } }
static String getTargetEntitySet(EdmBindingTarget root, LinkedList<UriResourceNavigation> navigations) { EdmEntityType type = root.getEntityType(); EdmBindingTarget targetEntitySet = root; String targetEntitySetName = root.getName(); String name = null; for (UriResourceNavigation nav:navigations) { name = nav.getProperty().getName(); EdmNavigationProperty property = type.getNavigationProperty(name); if (property.containsTarget()) { return root.getName(); } type = nav.getProperty().getType(); for(EdmNavigationPropertyBinding enb:targetEntitySet.getNavigationPropertyBindings()) { if (enb.getPath().equals(name)) { targetEntitySetName = enb.getTarget(); } else if (enb.getPath().endsWith("/"+name)) { targetEntitySetName = enb.getTarget(); } } } return targetEntitySetName; }
static String getTargetEntitySet(EdmBindingTarget root, LinkedList<UriResourceNavigation> navigations) { EdmEntityType type = root.getEntityType(); EdmBindingTarget targetEntitySet = root; String targetEntitySetName = root.getName(); String name = null; for (UriResourceNavigation nav:navigations) { name = nav.getProperty().getName(); EdmNavigationProperty property = type.getNavigationProperty(name); if (property.containsTarget()) { return root.getName(); } type = nav.getProperty().getType(); for(EdmNavigationPropertyBinding enb:targetEntitySet.getNavigationPropertyBindings()) { if (enb.getPath().equals(name)) { targetEntitySetName = enb.getTarget(); } else if (enb.getPath().endsWith("/"+name)) { targetEntitySetName = enb.getTarget(); } } } return targetEntitySetName; }
public static UriInfoDraftHelperV4 getCreateUriInfoForDraftsOneToOneUsingParent(EdmNavigationProperty navPropParent,Entity parentDraftsEntry,EdmEntityContainer entityContainer) throws ODataApplicationException { Entity childPayload=new Entity(); List<EdmReferentialConstraint> refConstraints = null ; refConstraints = navPropParent.getReferentialConstraints(); if( refConstraints == null || refConstraints.isEmpty() ){ throw new ODataApplicationException ("Unable to create with navigation because the corresponding referential constraint is missing.", HttpStatusCode.INTERNAL_SERVER_ERROR .getStatusCode(),Locale.ENGLISH,"Unable to create with navigation because the corresponding referential constraint is missing"); } refConstraints.forEach(refConstraint->{ // Map of <ChildKey , ParentKey> childPayload.addProperty(new Property(null, refConstraint.getReferencedPropertyName(), ValueType.PRIMITIVE, parentDraftsEntry.getProperty(refConstraint.getPropertyName()).getValue())); }); DeserializerResult deserializerResult=DeserializerResultImpl.with().entity(childPayload).build(); EdmEntitySet entSet=entityContainer.getEntitySet(navPropParent.getType().getName()); UriResourceEntitySet entitySetForCreate = new UriResourceEntitySetImpl(entSet); UriInfo uriInfoForCreate = new UriInfoImpl().addResourcePart(entitySetForCreate); UriInfoDraftHelperV4 _uriT=new UriInfoDraftHelperV4(); _uriT.setUriInfo(uriInfoForCreate); _uriT.setDeserializerResult(deserializerResult); _uriT.setUriFunction(UriFunction.CREATE); return _uriT; }