@Override public boolean isCollection() { return navigationProperty.isCollection() && keyPredicates == null; }
@Override public boolean isCollection() { return navigationProperty.isCollection() && keyPredicates == null; }
/** * 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()); } }
/** * 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()); } }
/** * 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; }
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; }
writer.writeAttribute(XML_NAME, navigationPropertyName); writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(navigationProperty.getType(), navigationProperty .isCollection())); if (!navigationProperty.isNullable()) { writer.writeAttribute(XML_NULLABLE, "" + navigationProperty.isNullable());
writer.writeAttribute(XML_NAME, navigationPropertyName); writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(navigationProperty.getType(), navigationProperty .isCollection())); if (!navigationProperty.isNullable()) { writer.writeAttribute(XML_NULLABLE, "" + navigationProperty.isNullable());
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; }
private Link createLink(final ExpandTreeBuilder expandBuilder, final String navigationPropertyName, final JsonNode jsonNode, final EdmNavigationProperty edmNavigationProperty) throws DeserializerException { Link link = new Link(); link.setTitle(navigationPropertyName); final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ? expandBuilder.expand(edmNavigationProperty) : null; EdmEntityType derivedEdmEntityType = (EdmEntityType) getDerivedType( edmNavigationProperty.getType(), jsonNode); if (jsonNode.isArray() && edmNavigationProperty.isCollection()) { link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE); EntityCollection inlineEntitySet = new EntityCollection(); inlineEntitySet.getEntities().addAll( consumeEntitySetArray(derivedEdmEntityType, jsonNode, childExpandBuilder)); link.setInlineEntitySet(inlineEntitySet); } else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull()) && !edmNavigationProperty.isCollection()) { link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE); if (!jsonNode.isNull()) { Entity inlineEntity = consumeEntityNode(derivedEdmEntityType, (ObjectNode) jsonNode, childExpandBuilder); link.setInlineEntity(inlineEntity); } } else { throw new DeserializerException("Invalid value: " + jsonNode.getNodeType() + " for expanded navigation property: " + navigationPropertyName, MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY, navigationPropertyName); } return link; }
private Link createLink(final ExpandTreeBuilder expandBuilder, final String navigationPropertyName, final JsonNode jsonNode, final EdmNavigationProperty edmNavigationProperty) throws DeserializerException { Link link = new Link(); link.setTitle(navigationPropertyName); final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ? expandBuilder.expand(edmNavigationProperty) : null; EdmEntityType derivedEdmEntityType = (EdmEntityType) getDerivedType( edmNavigationProperty.getType(), jsonNode); if (jsonNode.isArray() && edmNavigationProperty.isCollection()) { link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE); EntityCollection inlineEntitySet = new EntityCollection(); inlineEntitySet.getEntities().addAll( consumeEntitySetArray(derivedEdmEntityType, jsonNode, childExpandBuilder)); link.setInlineEntitySet(inlineEntitySet); } else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull()) && !edmNavigationProperty.isCollection()) { link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE); if (!jsonNode.isNull()) { Entity inlineEntity = consumeEntityNode(derivedEdmEntityType, (ObjectNode) jsonNode, childExpandBuilder); link.setInlineEntity(inlineEntity); } } else { throw new DeserializerException("Invalid value: " + jsonNode.getNodeType() + " for expanded navigation property: " + navigationPropertyName, MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY, navigationPropertyName); } return link; }
private Link createLink(final ExpandTreeBuilder expandBuilder, final String navigationPropertyName, final JsonNode jsonNode, final EdmNavigationProperty edmNavigationProperty) throws DeserializerException { Link link = new Link(); link.setTitle(navigationPropertyName); final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ? expandBuilder.expand(edmNavigationProperty) : null; EdmEntityType derivedEdmEntityType = (EdmEntityType) getDerivedType(edmNavigationProperty.getType(), jsonNode); if (jsonNode.isArray() && edmNavigationProperty.isCollection()) { link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE); EntityCollection inlineEntitySet = new EntityCollection(); inlineEntitySet.getEntities() .addAll(consumeEntitySetArray(derivedEdmEntityType, jsonNode, childExpandBuilder)); link.setInlineEntitySet(inlineEntitySet); } else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull()) && !edmNavigationProperty.isCollection()) { link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE); if (!jsonNode.isNull()) { Entity inlineEntity = consumeEntityNode(derivedEdmEntityType, (ObjectNode) jsonNode, childExpandBuilder); link.setInlineEntity(inlineEntity); } } else { throw new DeserializerException( "Invalid value: " + jsonNode.getNodeType() + " for expanded navigation property: " + navigationPropertyName, MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY, navigationPropertyName); } return link; }
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; }
if (navigationProperty.isCollection()) { json.writeBooleanField(COLLECTION, navigationProperty.isCollection());
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); } } } }
protected void writeExpandedNavigationProperty(final ServiceMetadata metadata, final EdmNavigationProperty property, final Link navigationLink, final ExpandOption innerExpand, final Integer toDepth, final SelectOption innerSelect, final CountOption coutOption, final boolean writeNavigationCount, final boolean writeOnlyRef,final String xml10InvalidCharReplacement, final Set<String> ancestors, String name, final XMLStreamWriter writer) throws XMLStreamException, SerializerException { if (property.isCollection()) { if (navigationLink != null && navigationLink.getInlineEntitySet() != null) { writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM); if (writeNavigationCount) { writeCount(navigationLink.getInlineEntitySet(), writer); } else { if (coutOption != null && coutOption.getValue()) { writeCount(navigationLink.getInlineEntitySet(), writer); } writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, writeOnlyRef, name, ancestors); } writer.writeEndElement(); } } else { if (navigationLink != null && navigationLink.getInlineEntity() != null) { writeEntity(metadata, property.getType(), navigationLink.getInlineEntity(), null, innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, false, writeOnlyRef, name, ancestors); } } }
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); } } } }
protected void writeExpandedNavigationProperty(final ServiceMetadata metadata, final EdmNavigationProperty property, final Link navigationLink, final ExpandOption innerExpand, final Integer toDepth, final SelectOption innerSelect, final CountOption coutOption, final boolean writeNavigationCount, final boolean writeOnlyRef,final String xml10InvalidCharReplacement, final Set<String> ancestors, String name, final XMLStreamWriter writer) throws XMLStreamException, SerializerException { if (property.isCollection()) { if (navigationLink != null && navigationLink.getInlineEntitySet() != null) { writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM); if (writeNavigationCount) { writeCount(navigationLink.getInlineEntitySet(), writer); } else { if (coutOption != null && coutOption.getValue()) { writeCount(navigationLink.getInlineEntitySet(), writer); } writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, writeOnlyRef, name, ancestors); } writer.writeEndElement(); } } else { if (navigationLink != null && navigationLink.getInlineEntity() != null) { writeEntity(metadata, property.getType(), navigationLink.getInlineEntity(), null, innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, false, writeOnlyRef, name, ancestors); } } }
@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); } }