diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index a819f0553..94c60967f 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -125,11 +125,11 @@ func buildFromMap(isKey bool, mapping map[string]string) []string { // Assumption: User exists // TODO: https://github.com/alcionai/corso/issues/135 // Add iota to this call -> mail, contacts, calendar, etc. -func (gc *GraphConnector) ExchangeDataCollection(user string) (DataCollection, error) { +func (gc *GraphConnector) ExchangeDataCollection(user string) ([]DataCollection, error) { // TODO replace with completion of Issue 124: - collection := NewExchangeDataCollection(user, []string{gc.tenant, user}) + //TODO: Retry handler to convert return: (DataCollection, error) - return gc.serializeMessages(user, collection) + return gc.serializeMessages(user) } // optionsForMailFolders creates transforms the 'select' into a more dynamic call for MailFolders. @@ -201,7 +201,7 @@ func (gc *GraphConnector) restoreMessages(dc DataCollection) error { // serializeMessages: Temp Function as place Holder until Collections have been added // to the GraphConnector struct. -func (gc *GraphConnector) serializeMessages(user string, dc ExchangeDataCollection) (DataCollection, error) { +func (gc *GraphConnector) serializeMessages(user string) ([]DataCollection, error) { options := optionsForMailFolders([]string{}) response, err := gc.client.UsersById(user).MailFolders().GetWithRequestConfigurationAndResponseHandler(options, nil) if err != nil { @@ -216,8 +216,10 @@ func (gc *GraphConnector) serializeMessages(user string, dc ExchangeDataCollecti } // Time to create Exchange data Holder var byteArray []byte + collections := make([]DataCollection, 0) var errs error for _, aFolder := range folderList { + result, err := gc.client.UsersById(user).MailFoldersById(aFolder).Messages().Get() if err != nil { errs = WrapAndAppend(user, err, errs) @@ -233,6 +235,7 @@ func (gc *GraphConnector) serializeMessages(user string, dc ExchangeDataCollecti continue } objectWriter := kw.NewJsonSerializationWriter() + edc := NewExchangeDataCollection(user, []string{gc.tenant, user, aFolder}) callbackFunc := func(messageItem interface{}) bool { message, ok := messageItem.(models.Messageable) @@ -261,7 +264,7 @@ func (gc *GraphConnector) serializeMessages(user string, dc ExchangeDataCollecti return true } if byteArray != nil { - dc.PopulateCollection(ExchangeData{id: *message.GetId(), message: byteArray}) + edc.PopulateCollection(ExchangeData{id: *message.GetId(), message: byteArray}) } return true } @@ -270,11 +273,11 @@ func (gc *GraphConnector) serializeMessages(user string, dc ExchangeDataCollecti if err != nil { errs = WrapAndAppend(user, err, errs) } + + // Todo Retry Handler to be implemented + edc.FinishPopulation() + //fmt.Printf("Storing ExchangeDataColection with %d items\n", edc.Length()) + collections = append(collections, &edc) } - fmt.Printf("Returning ExchangeDataColection with %d items\n", dc.Length()) - if errs != nil { - fmt.Printf("Errors: \n%s\n", errs.Error()) - } - dc.FinishPopulation() - return &dc, errs + return collections, errs } diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index ad4a8e1c4..0996d12f2 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -63,12 +63,13 @@ func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_ExchangeDataColl if err := ctesting.RunOnAny(ctesting.CorsoCITests); err != nil { suite.T().Skip(err) } - exchangeData, err := suite.connector.ExchangeDataCollection("lidiah@8qzvrj.onmicrosoft.com") - assert.NotNil(suite.T(), exchangeData) + collectionList, err := suite.connector.ExchangeDataCollection("lidiah@8qzvrj.onmicrosoft.com") + assert.NotNil(suite.T(), collectionList) assert.Error(suite.T(), err) // TODO Remove after https://github.com/alcionai/corso/issues/140 if err != nil { suite.T().Logf("Missing Data: %s\n", err.Error()) } + exchangeData := collectionList[0] suite.T().Logf("Full PathData: %s\n", exchangeData.FullPath()) } diff --git a/src/internal/operations/backup.go b/src/internal/operations/backup.go index 42e717eb8..549197cc5 100644 --- a/src/internal/operations/backup.go +++ b/src/internal/operations/backup.go @@ -57,13 +57,13 @@ func (bo *BackupOperation) Run(ctx context.Context) (*kopia.BackupStats, error) return nil, errors.Wrap(err, "connecting to graph api") } - c, err := gc.ExchangeDataCollection(bo.Targets[0]) + cs, err := gc.ExchangeDataCollection(bo.Targets[0]) if err != nil { return nil, errors.Wrap(err, "retrieving application data") } // todo: utilize stats - stats, err := bo.kopia.BackupCollections(ctx, []connector.DataCollection{c}) + stats, err := bo.kopia.BackupCollections(ctx, cs) if err != nil { return nil, errors.Wrap(err, "backing up application data") }