From b29cedfb34b7c6684872e42aafab044b5365c525 Mon Sep 17 00:00:00 2001 From: Vaibhav Kamra Date: Fri, 3 Jun 2022 14:44:23 -0700 Subject: [PATCH] Introduce DataCollection and DataStream (#125) This commit does the following: - Renames DataStream to DataCollection since that describes better the interface - Introduces DataStream as a streamable item within this collection --- .../connector/exchange_data_collection.go | 34 ++++++++++++++++--- src/internal/connector/graph_connector.go | 6 ++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/internal/connector/exchange_data_collection.go b/src/internal/connector/exchange_data_collection.go index 8e6fecd10..b27d78bde 100644 --- a/src/internal/connector/exchange_data_collection.go +++ b/src/internal/connector/exchange_data_collection.go @@ -1,12 +1,36 @@ package connector -// A DataStream provides an iterator to consume a -// collection of graph data of the same type (e.g. mail) -type DataStream interface{} +import "io" + +// A DataCollection represents a collection of data of the +// same type (e.g. mail) +type DataCollection interface { + // Returns either the next item in the collection or an error if one occurred. + // If not more items are available in the collection, returns (nil, nil). + NextItem() (DataStream, error) +} + +// DataStream represents a single item within a DataCollection +// that can be consumed as a stream +type DataStream interface { + // ToReader returns a reader for the data stream + ToReader() io.Reader + // Provides a unique identifier for this data + UUID() string +} // ExchangeDataCollection represents exchange mailbox -// data for a single user. It implements the DataStream -// interface which allows reading data in the collection +// data for a single user. +// +// It implements the DataCollection interface type ExchangeDataCollection struct { user string } + +// NextItem returns either the next item in the collection or an error if one occurred. +// If not more items are available in the collection, returns (nil, nil). +func (*ExchangeDataCollection) NextItem() (DataStream, error) { + // TODO: Return the next "to be read" item in the collection as a + // DataStream + return nil, nil +} diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index bff8f3f04..4fddda740 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -120,8 +120,8 @@ func (gc *GraphConnector) GetUsersIds() []string { return values } -// ExchangeDataStream returns a DataStream that the caller can -// use to stream mailbox data out for the specified user -func (gc *GraphConnector) ExchangeDataStream(user string) DataStream { +// ExchangeDataStream returns a DataCollection that the caller can +// use to read mailbox data out for the specified user +func (gc *GraphConnector) ExchangeDataCollection(user string) DataCollection { return &ExchangeDataCollection{user: user} }