/** * Gets the action import by the specified name, throw an exception if no action import with the specified name * exists. * * @param entityDataModel The entity data model. * @param actionImportName The name of action import. * @return The instance of action import. */ public static ActionImport getAndCheckActionImport(EntityDataModel entityDataModel, String actionImportName) { ActionImport actionImport = entityDataModel.getEntityContainer().getActionImport(actionImportName); if (actionImport == null) { throw new ODataSystemException("Action import not found in the entity data model: " + actionImportName); } return actionImport; }
/** * Checks if the specified typeName is a collection. * * @param entityDataModel The entity data model. * @param typeName The type name to check. * @return True if the type is a collection, False if not */ public static boolean isCollection(EntityDataModel entityDataModel, String typeName) { EntitySet entitySet = entityDataModel.getEntityContainer().getEntitySet(typeName); if (entitySet != null) { return true; } try { if (Collection.class.isAssignableFrom(Class.forName(typeName)) || COLLECTION_PATTERN.matcher(typeName).matches()) { return true; } } catch (ClassNotFoundException e) { LOG.debug("Not possible to find class for type name: {}", typeName); } return false; }
List<EntitySet> entities = entityDataModel.getEntityContainer().getEntitySets(); for (EntitySet entity : entities) { if (entity.isIncludedInServiceDocument()) { List<Singleton> singletons = entityDataModel.getEntityContainer().getSingletons(); for (Singleton singleton : singletons) { writeObject(jsonGenerator, singleton);
/** * Write the 'Entity Container'. * <p> * Note: The entity container is written only for the 'Schema' which namespace matches the name of the entity * container itself. This entity container contains the types for all the schemas contained by the Entity Data * Model though. * </p> * * @param entityContainer The 'Entity Container' to write. * @throws XMLStreamException */ private void writeEntityContainer(EntityContainer entityContainer) throws XMLStreamException { xmlWriter.writeStartElement(ENTITY_CONTAINER); xmlWriter.writeAttribute(NAME, entityContainer.getName()); for (EntitySet entitySet : entityContainer.getEntitySets()) { entitySetWriter.write(entitySet); } for (Singleton singleton : entityContainer.getSingletons()) { singletonWriter.write(singleton); } xmlWriter.writeEndElement(); }
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; } }
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 singletons in entity data model as collection of "metadata:singleton". * * @param writer which writes to stream. * @throws XMLStreamException in case of any xml errors * @throws ODataRenderException if entity container is null. */ private void writeSingleton(XMLStreamWriter writer) throws XMLStreamException, ODataRenderException { List<Singleton> singletons = getEntityContainer().getSingletons(); LOG.debug("Number of singletons to be written in service document are {}", singletons.size()); for (Singleton singleton : singletons) { writeElement(writer, METADATA, SERVICE_SINGLETON, ODATA_METADATA_NS, singleton.getName(), singleton.getName()); } }
/** * Gets the function import by the specified name, throw an exception if no function import with the specified name * exists. * * @param entityDataModel The entity data model. * @param functionImportName The name of the function import. * @return The function import */ public static FunctionImport getAndCheckFunctionImport(EntityDataModel entityDataModel, String functionImportName) { FunctionImport functionImport = entityDataModel.getEntityContainer().getFunctionImport(functionImportName); if (functionImport == null) { throw new ODataSystemException("Function import not found in the entity data model: " + functionImportName); } return functionImport; }
/** * Gets the singleton with the specified name, throws an exception if no singleton with the specified name exists. * * @param entityDataModel The entity data model. * @param singletonName The name of the singleton. * @return The singleton. * @throws ODataSystemException If the entity data model does not contain a singleton with the specified name. */ public static Singleton getAndCheckSingleton(EntityDataModel entityDataModel, String singletonName) { Singleton singleton = entityDataModel.getEntityContainer().getSingleton(singletonName); if (singleton == null) { throw new ODataSystemException("Singleton not found in the entity data model: " + singletonName); } return singleton; }
/** * Starts "service" document with correct attributes and also writes "workspace", "title" elements. * * @param outputStream stream to write to * @return XMLStreamWriter to which writing happens * @throws XMLStreamException in case of errors * @throws ODataRenderException in case of errors */ private XMLStreamWriter startServiceDocument(ByteArrayOutputStream outputStream) throws XMLStreamException, ODataRenderException { XMLStreamWriter writer = XMLWriterUtil.startDocument(outputStream, null, SERVICE, ODATA_SERVICE_NS); writer.writeNamespace(ATOM, ATOM_NS); writer.writeNamespace(METADATA, ODATA_METADATA_NS); writer.writeNamespace(SERVICE_BASE, oDataUri.serviceRoot()); writer.writeNamespace(ODATA_CONTEXT, getContextURL(oDataUri, entityDataModel)); // WorkSpace element is only child of service document according to specifications. writer.writeStartElement(ODATA_SERVICE_NS, WORKSPACE); writeTitle(writer, getEntityContainer().getName()); return writer; }
/** * Write the 'Entity Container'. * <p> * Note: The entity container is written only for the 'Schema' which namespace matches the name of the entity * container itself. This entity container contains the types for all the schemas contained by the Entity Data * Model though. * </p> * * @param entityContainer The 'Entity Container' to write. * @throws XMLStreamException */ private void writeEntityContainer(EntityContainer entityContainer) throws XMLStreamException { xmlWriter.writeStartElement(ENTITY_CONTAINER); xmlWriter.writeAttribute(NAME, entityContainer.getName()); for (EntitySet entitySet : entityContainer.getEntitySets()) { entitySetWriter.write(entitySet); } for (Singleton singleton : entityContainer.getSingletons()) { singletonWriter.write(singleton); } xmlWriter.writeEndElement(); }
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; } }
/** * 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); }
/** * This writes all singletons in entity data model as collection of "metadata:singleton". * * @param writer which writes to stream. * @throws XMLStreamException in case of any xml errors * @throws ODataRenderException if entity container is null. */ private void writeSingleton(XMLStreamWriter writer) throws XMLStreamException, ODataRenderException { List<Singleton> singletons = getEntityContainer().getSingletons(); LOG.debug("Number of singletons to be written in service document are {}", singletons.size()); for (Singleton singleton : singletons) { writeElement(writer, METADATA, SERVICE_SINGLETON, ODATA_METADATA_NS, singleton.getName(), singleton.getName()); } }
/** * Gets the function import by the specified name, throw an exception if no function import with the specified name * exists. * * @param entityDataModel The entity data model. * @param functionImportName The name of the function import. * @return The function import */ public static FunctionImport getAndCheckFunctionImport(EntityDataModel entityDataModel, String functionImportName) { FunctionImport functionImport = entityDataModel.getEntityContainer().getFunctionImport(functionImportName); if (functionImport == null) { throw new ODataSystemException("Function import not found in the entity data model: " + functionImportName); } return functionImport; }
/** * Gets the singleton with the specified name, throws an exception if no singleton with the specified name exists. * * @param entityDataModel The entity data model. * @param singletonName The name of the singleton. * @return The singleton. * @throws ODataSystemException If the entity data model does not contain a singleton with the specified name. */ public static Singleton getAndCheckSingleton(EntityDataModel entityDataModel, String singletonName) { Singleton singleton = entityDataModel.getEntityContainer().getSingleton(singletonName); if (singleton == null) { throw new ODataSystemException("Singleton not found in the entity data model: " + singletonName); } return singleton; }
/** * Starts "service" document with correct attributes and also writes "workspace", "title" elements. * * @param outputStream stream to write to * @return XMLStreamWriter to which writing happens * @throws XMLStreamException in case of errors * @throws ODataRenderException in case of errors */ private XMLStreamWriter startServiceDocument(ByteArrayOutputStream outputStream) throws XMLStreamException, ODataRenderException { XMLStreamWriter writer = XMLWriterUtil.startDocument(outputStream, null, SERVICE, ODATA_SERVICE_NS); writer.writeNamespace(ATOM, ATOM_NS); writer.writeNamespace(METADATA, ODATA_METADATA_NS); writer.writeNamespace(SERVICE_BASE, oDataUri.serviceRoot()); writer.writeNamespace(ODATA_CONTEXT, getContextURL(oDataUri, entityDataModel)); // WorkSpace element is only child of service document according to specifications. writer.writeStartElement(ODATA_SERVICE_NS, WORKSPACE); writeTitle(writer, getEntityContainer().getName()); return writer; }
List<EntitySet> entities = entityDataModel.getEntityContainer().getEntitySets(); for (EntitySet entity : entities) { if (entity.isIncludedInServiceDocument()) { List<Singleton> singletons = entityDataModel.getEntityContainer().getSingletons(); for (Singleton singleton : singletons) { writeObject(jsonGenerator, singleton);
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; }
/** * Checks if the specified typeName is a collection. * * @param entityDataModel The entity data model. * @param typeName The type name to check. * @return True if the type is a collection, False if not */ public static boolean isCollection(EntityDataModel entityDataModel, String typeName) { EntitySet entitySet = entityDataModel.getEntityContainer().getEntitySet(typeName); if (entitySet != null) { return true; } try { if (Collection.class.isAssignableFrom(Class.forName(typeName)) || COLLECTION_PATTERN.matcher(typeName).matches()) { return true; } } catch (ClassNotFoundException e) { LOG.debug("Not possible to find class for type name: {}", typeName); } return false; }