/** * This methods write @odata.type of complex type. * If complex type has root-level, @odata.type won't be written. * * @param structuredType structuredType */ private void writeODataType(StructuredType structuredType) throws IOException { if (entitySet != null) { String typeName = entitySet.getTypeName(); String type = typeName.substring(typeName.lastIndexOf(".") + 1, typeName.length()); if (!type.equals(structuredType.getName())) { jsonGenerator.writeStringField(TYPE, String.format("#%s.%s", structuredType.getNamespace(), structuredType.getName())); } else { LOG.trace("{} has root level. {} won't be written here", entitySet.getName(), TYPE); } } }
/** * Write an {@code <EntitySet>} element for a given {@code EntitySet}. * * @param entitySet The given {@code EntitySet}. It can not be {@code null}. * @throws javax.xml.stream.XMLStreamException If unable to write to stream */ public void write(EntitySet entitySet) throws XMLStreamException { LOG.debug("Writing entity set {} of type {}", entitySet.getName(), entitySet.getTypeName()); xmlWriter.writeStartElement(ENTITY_SET); xmlWriter.writeAttribute(NAME, entitySet.getName()); xmlWriter.writeAttribute(ENTITY_TYPE, entitySet.getTypeName()); for (NavigationPropertyBinding navPropertyBinding : entitySet.getNavigationPropertyBindings()) { xmlWriter.writeStartElement(NAVIGATION_PROPERTY_BINDING); xmlWriter.writeAttribute(PATH, navPropertyBinding.getPath()); xmlWriter.writeAttribute(TARGET, navPropertyBinding.getTarget()); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } }
/** * This writes all entity sets in entity data model as collection of elements. * * @param writer which writes to stream. * @throws XMLStreamException in case of any xml errors * @throws ODataRenderException if entity container is null. */ private void writeEntitySets(XMLStreamWriter writer) throws XMLStreamException, ODataRenderException { List<EntitySet> entitySets = getEntityContainer().getEntitySets(); LOG.debug("Number of entity sets to be written in service document are {}", entitySets.size()); for (EntitySet entitySet : entitySets) { if (entitySet.isIncludedInServiceDocument()) { writeElement(writer, null, SERVICE_COLLECTION, null, entitySet.getName(), entitySet.getName()); } } }
public Builder addEntitySet(EntitySet entitySet) { this.entitySetsBuilder.put(entitySet.getName(), entitySet); return this; }
/** * Get the Entity Set for a given Entity Type name through the Entity Data Model. * * @param entityDataModel The Entity Data Model. * @param entityTypeName The Entity Type name. * @return The Entity Set. * @throws ODataEdmException if unable to get entity set in entity data model */ public static EntitySet getEntitySetByEntityTypeName(EntityDataModel entityDataModel, String entityTypeName) throws ODataEdmException { for (EntitySet entitySet : entityDataModel.getEntityContainer().getEntitySets()) { if (entitySet.getTypeName().equals(entityTypeName)) { return entitySet; } } throw new ODataSystemException("Entity set not found in the entity data model for type: " + entityTypeName); }
if (entity.isIncludedInServiceDocument()) { writeObject(jsonGenerator, entity);
public Builder addEntitySet(EntitySet entitySet) { this.entitySetsBuilder.put(entitySet.getName(), entitySet); return this; }
/** * Get the Entity Set for a given Entity Type name through the Entity Data Model. * * @param entityDataModel The Entity Data Model. * @param entityTypeName The Entity Type name. * @return The Entity Set. * @throws ODataEdmException if unable to get entity set in entity data model */ public static EntitySet getEntitySetByEntityTypeName(EntityDataModel entityDataModel, String entityTypeName) throws ODataEdmException { for (EntitySet entitySet : entityDataModel.getEntityContainer().getEntitySets()) { if (entitySet.getTypeName().equals(entityTypeName)) { return entitySet; } } throw new ODataSystemException("Entity set not found in the entity data model for type: " + entityTypeName); }
if (entity.isIncludedInServiceDocument()) { writeObject(jsonGenerator, entity);
/** * This methods write @odata.type of complex type. * If complex type has root-level, @odata.type won't be written. * * @param structuredType structuredType */ private void writeODataType(StructuredType structuredType) throws IOException { if (entitySet != null) { String typeName = entitySet.getTypeName(); String type = typeName.substring(typeName.lastIndexOf(".") + 1, typeName.length()); if (!type.equals(structuredType.getName())) { jsonGenerator.writeStringField(TYPE, String.format("#%s.%s", structuredType.getNamespace(), structuredType.getName())); } else { LOG.trace("{} has root level. {} won't be written here", entitySet.getName(), TYPE); } } }
@Override public EntitySet getEntitySet(final String entitySetName) { List<EntitySet> internalEntityList = new LinkedList<>(); Predicate<EntitySet> predicate = entitySet -> entitySet.getName().equals(entitySetName); entitySets.stream().filter(predicate).forEach(internalEntityList::add); return internalEntityList.isEmpty() ? null : internalEntityList.get(0); } };
/** * Write an {@code <EntitySet>} element for a given {@code EntitySet}. * * @param entitySet The given {@code EntitySet}. It can not be {@code null}. * @throws javax.xml.stream.XMLStreamException If unable to write to stream */ public void write(EntitySet entitySet) throws XMLStreamException { LOG.debug("Writing entity set {} of type {}", entitySet.getName(), entitySet.getTypeName()); xmlWriter.writeStartElement(ENTITY_SET); xmlWriter.writeAttribute(NAME, entitySet.getName()); xmlWriter.writeAttribute(ENTITY_TYPE, entitySet.getTypeName()); for (NavigationPropertyBinding navPropertyBinding : entitySet.getNavigationPropertyBindings()) { xmlWriter.writeStartElement(NAVIGATION_PROPERTY_BINDING); xmlWriter.writeAttribute(PATH, navPropertyBinding.getPath()); xmlWriter.writeAttribute(TARGET, navPropertyBinding.getTarget()); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } }
private EntitySet getEntitySet(Object entity) { String entityTypeName = getEntityType(entity).getFullyQualifiedName(); for (EntitySet eSet : entityDataModel.getEntityContainer().getEntitySets()) { if (eSet.getTypeName().equals(entityTypeName)) { return eSet; } } return null; }
/** * This writes all entity sets in entity data model as collection of elements. * * @param writer which writes to stream. * @throws XMLStreamException in case of any xml errors * @throws ODataRenderException if entity container is null. */ private void writeEntitySets(XMLStreamWriter writer) throws XMLStreamException, ODataRenderException { List<EntitySet> entitySets = getEntityContainer().getEntitySets(); LOG.debug("Number of entity sets to be written in service document are {}", entitySets.size()); for (EntitySet entitySet : entitySets) { if (entitySet.isIncludedInServiceDocument()) { writeElement(writer, null, SERVICE_COLLECTION, null, entitySet.getName(), entitySet.getName()); } } }
/** * Get the Entity Name for a given Entity Type name through the Entity Data Model. * This looks for entity in both EntitySets and Singletons in the container * * @param entityDataModel The Entity Data Model. * @param entityTypeName The Entity Type name. * @return The Entity name * @throws ODataEdmException if unable to find entity name in entity data model */ public static String getEntityNameByEntityTypeName(EntityDataModel entityDataModel, String entityTypeName) throws ODataEdmException { for (EntitySet entitySet : entityDataModel.getEntityContainer().getEntitySets()) { if (entitySet.getTypeName().equals(entityTypeName)) { return entitySet.getName(); } } //If not found in EntitySet, try to find in Singletons for (Singleton singleton : entityDataModel.getEntityContainer().getSingletons()) { if (singleton.getTypeName().equals(entityTypeName)) { return singleton.getName(); } } throw new ODataSystemException("Entity name not found in the entity data model for type: " + entityTypeName); }
@Override public EntitySet getEntitySet(final String entitySetName) { List<EntitySet> internalEntityList = new LinkedList<>(); Predicate<EntitySet> predicate = entitySet -> entitySet.getName().equals(entitySetName); entitySets.stream().filter(predicate).forEach(internalEntityList::add); return internalEntityList.isEmpty() ? null : internalEntityList.get(0); } };
private EntitySet getEntitySet(Object entity) { String entityTypeName = getEntityType(entity).getFullyQualifiedName(); for (EntitySet eSet : entityDataModel.getEntityContainer().getEntitySets()) { if (eSet.getTypeName().equals(entityTypeName)) { return eSet; } } return null; }
/** * Get the Entity Name for a given Entity Type name through the Entity Data Model. * This looks for entity in both EntitySets and Singletons in the container * * @param entityDataModel The Entity Data Model. * @param entityTypeName The Entity Type name. * @return The Entity name * @throws ODataEdmException if unable to find entity name in entity data model */ public static String getEntityNameByEntityTypeName(EntityDataModel entityDataModel, String entityTypeName) throws ODataEdmException { for (EntitySet entitySet : entityDataModel.getEntityContainer().getEntitySets()) { if (entitySet.getTypeName().equals(entityTypeName)) { return entitySet.getName(); } } //If not found in EntitySet, try to find in Singletons for (Singleton singleton : entityDataModel.getEntityContainer().getSingletons()) { if (singleton.getTypeName().equals(entityTypeName)) { return singleton.getName(); } } throw new ODataSystemException("Entity name not found in the entity data model for type: " + entityTypeName); }
/** * Writes the name of the entity * It is a MUST element. * * @param jsonGenerator jsonGenerator * @param entity entity from the container */ private void writeName(JsonGenerator jsonGenerator, Object entity) throws IOException { jsonGenerator.writeFieldName(NAME); if (entity instanceof EntitySet) { jsonGenerator.writeObject(((EntitySet) entity).getName()); } else { jsonGenerator.writeObject(((Singleton) entity).getName()); } }
private String getEntityTypeName(QueryOperation operation, EntityDataModel entityDataModel) { EntitySet entitySet = entityDataModel.getEntityContainer().getEntitySet(operation.entitySetName()); // If the supplied entity is an EntitySet, return entity set type. Else check for Singleton if (entitySet != null) { return entitySet.getTypeName(); } else { Singleton singleton = entityDataModel.getEntityContainer().getSingleton(operation.entitySetName()); if (singleton != null) { return singleton.getTypeName(); } } return null; } }