writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(navigationProperty.getType(), navigationProperty .isCollection())); if (!navigationProperty.isNullable()) { writer.writeAttribute(XML_NULLABLE, "" + navigationProperty.isNullable()); if (navigationProperty.getPartner() != null) { EdmNavigationProperty partner = navigationProperty.getPartner(); writer.writeAttribute(XML_PARTNER, partner.getName()); if (navigationProperty.containsTarget()) { writer.writeAttribute(XML_CONTAINS_TARGET, "" + navigationProperty.containsTarget()); if (navigationProperty.getReferentialConstraints() != null) { for (EdmReferentialConstraint constraint : navigationProperty.getReferentialConstraints()) { writer.writeStartElement("ReferentialConstraint"); writer.writeAttribute(XML_PROPERTY, constraint.getPropertyName());
/** * Check if jsonNode is not null or if null but nullable or collection navigationProperty * * @param jsonNode related json node * @param edmNavigationProperty related navigation property * @throws DeserializerException if jsonNode is not null or if null but nullable or collection navigationProperty */ private void checkNotNullOrValidNull(final JsonNode jsonNode, final EdmNavigationProperty edmNavigationProperty) throws DeserializerException { boolean isNullable = edmNavigationProperty.isNullable(); if ((jsonNode.isNull() && !isNullable) || (jsonNode.isNull() && edmNavigationProperty.isCollection())) { throw new DeserializerException("Property: " + edmNavigationProperty.getName() + " must not be null.", MessageKeys.INVALID_NULL_PROPERTY, edmNavigationProperty.getName()); } }
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; }
@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); } }
EdmEntityType type = rootType; for (UriResourceNavigation nav:navigations) { String name = nav.getProperty().getName(); EdmNavigationProperty property = type.getNavigationProperty(name); if (property.containsTarget()) { containsTarget = true; type = nav.getProperty().getType(); sb.append("/"); sb.append(nav.getProperty().getName());
@Override public EdmType getType() { return navigationProperty.getType(); }
@Override public String getSegmentValue() { return navigationProperty.getName(); } }
private static KeyInfo joinFK(Table currentTable, Table referenceTable, EdmNavigationProperty property) { for (ForeignKey fk : currentTable.getForeignKeys()) { String refSchemaName = fk.getReferenceKey().getParent().getParent().getName(); if (!referenceTable.getParent().getName().equals(refSchemaName) || !referenceTable.getName().equals(fk.getReferenceTableName())) { continue; } if (!property.isCollection() && property.getName().equals(fk.getName())) { return new KeyInfo(false, fk); } if (property.getName().equals(currentTable.getName() + "_" + fk.getName())) { //$NON-NLS-1$ return new KeyInfo(true, fk); } } return null; }
(UriResourceNavigation) resourcePaths.get(navigationCount); blockTypeFilters(uriResourceNavigation); if (uriResourceNavigation.getProperty().containsTarget()) { throw new ODataApplicationException("Containment navigation is not supported.", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); .getName()); if (target != null) { if (target instanceof EdmEntitySet) {
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; }
bindingLink.setTitle(navigationPropertyName); if (edmNavigationProperty.isCollection()) { assertIsNullNode(key, jsonNode); if (!jsonNode.isArray()) { DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE, key); if (edmNavigationProperty.isNullable() && jsonNode.isNull()) { bindingLink.setBindingLink(null); } else {
@Override public boolean isCollection() { return navigationProperty.isCollection() && keyPredicates == null; }
/** * @param sourceEntityType * @param targetEntityType * @param navProperty */ private void validateReferentialConstraint(EdmEntityType sourceEntityType, EdmEntityType targetEntityType, EdmNavigationProperty navProperty) { if (!navProperty.getReferentialConstraints().isEmpty()) { String propertyName = navProperty.getReferentialConstraints().get(0).getPropertyName(); if (sourceEntityType.getProperty(propertyName) == null) { throw new RuntimeException("Property name "+ propertyName + " not part of the source entity."); } String referencedPropertyName = navProperty.getReferentialConstraints().get(0).getReferencedPropertyName(); if (targetEntityType.getProperty(referencedPropertyName) == null) { throw new RuntimeException("Property name " + referencedPropertyName + " not part of the target entity."); } } }
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); } } } }
if (inline != null) { if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(inline.getName())) { if (navigationProperty.isCollection()) { throw new DeserializerException("Navigation Property " + link.getTitle() + " must be collection entities", link.setInlineEntity(entity(reader, inline, navigationProperty.getType())); if (!navigationProperty.isCollection()) { throw new DeserializerException("Navigation Property " + link.getTitle() + " must be single entity", DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE, link.getTitle()); link.setInlineEntitySet(entitySet(reader, inline, navigationProperty.getType())); if (navigationProperty.isCollection()) { throw new DeserializerException("Binding annotation: " + link.getTitle() + " must be collection of entity references", link.setType(Constants.ENTITY_BINDING_LINK_TYPE); } else if (Constants.QNAME_ATOM_ELEM_FEED.equals(event.asStartElement().getName())) { if (navigationProperty.isCollection()) { throw new DeserializerException("Binding annotation: " + link.getTitle() + " must be single entity references",
EdmEntityType type = rootType; for (UriResourceNavigation nav:navigations) { String name = nav.getProperty().getName(); EdmNavigationProperty property = type.getNavigationProperty(name); if (property.containsTarget()) { containsTarget = true; type = nav.getProperty().getType(); sb.append("/"); sb.append(nav.getProperty().getName());
@Override public EdmType getType() { return navigationProperty.getType(); }
@Override public String getSegmentValue() { return navigationProperty.getName(); } }
/** * Check if jsonNode is not null or if null but nullable or collection navigationProperty * * @param jsonNode related json node * @param edmNavigationProperty related navigation property * @throws DeserializerException if jsonNode is not null or if null but nullable or collection navigationProperty */ private void checkNotNullOrValidNull(final JsonNode jsonNode, final EdmNavigationProperty edmNavigationProperty) throws DeserializerException { boolean isNullable = edmNavigationProperty.isNullable(); if ((jsonNode.isNull() && !isNullable) || (jsonNode.isNull() && edmNavigationProperty.isCollection())) { throw new DeserializerException("Property: " + edmNavigationProperty.getName() + " must not be null.", MessageKeys.INVALID_NULL_PROPERTY, edmNavigationProperty.getName()); } }