diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index 6230d3b5a..18520a037 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -303,6 +303,8 @@ func (gc *GraphConnector) RestoreDataCollections( status, err = exchange.RestoreExchangeDataCollections(ctx, gc.graphService, dest, dcs, deets) case selectors.ServiceOneDrive: status, err = onedrive.RestoreCollections(ctx, gc, dest, dcs, deets) + case selectors.ServiceSharePoint: + status, err = sharepoint.RestoreCollections(ctx, gc, dest, dcs, deets) default: err = errors.Errorf("restore data from service %s not supported", selector.Service.String()) } diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index f5f11385d..e2935244f 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -134,7 +134,20 @@ func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() { Service: selectors.ServiceOneDrive, }, }, - // TODO: SharePoint + { + name: "SharePointNil", + col: nil, + sel: selectors.Selector{ + Service: selectors.ServiceSharePoint, + }, + }, + { + name: "SharePointEmpty", + col: []data.Collection{}, + sel: selectors.Selector{ + Service: selectors.ServiceSharePoint, + }, + }, } for _, test := range table { diff --git a/src/internal/connector/onedrive/restore.go b/src/internal/connector/onedrive/restore.go index 4aca460ac..65843129c 100644 --- a/src/internal/connector/onedrive/restore.go +++ b/src/internal/connector/onedrive/restore.go @@ -66,7 +66,7 @@ func RestoreCollections( // Iterate through the data collections and restore the contents of each for _, dc := range dcs { - temp, canceled := restoreCollection(ctx, service, dc, dest.ContainerName, deets, errUpdater) + temp, canceled := RestoreCollection(ctx, service, dc, dest.ContainerName, deets, errUpdater) restoreMetrics.Combine(temp) @@ -85,10 +85,11 @@ func RestoreCollections( nil } -// restoreCollection handles restoration of an individual collection. -// @returns Integer representing totalItems, restoredItems, and the -// amount of bytes restored. The bool represents whether the context was cancelled -func restoreCollection( +// RestoreCollection handles restoration of an individual collection. +// returns: +// - the collection's item and byte count metrics +// - the context cancellation state (true if the context is cancelled) +func RestoreCollection( ctx context.Context, service graph.Service, dc data.Collection, diff --git a/src/internal/connector/sharepoint/restore.go b/src/internal/connector/sharepoint/restore.go new file mode 100644 index 000000000..f86c9ea03 --- /dev/null +++ b/src/internal/connector/sharepoint/restore.go @@ -0,0 +1,63 @@ +package sharepoint + +import ( + "context" + + "github.com/pkg/errors" + + "github.com/alcionai/corso/src/internal/connector/graph" + "github.com/alcionai/corso/src/internal/connector/onedrive" + "github.com/alcionai/corso/src/internal/connector/support" + "github.com/alcionai/corso/src/internal/data" + "github.com/alcionai/corso/src/pkg/backup/details" + "github.com/alcionai/corso/src/pkg/control" + "github.com/alcionai/corso/src/pkg/path" +) + +// RestoreCollections will restore the specified data collections into OneDrive +func RestoreCollections( + ctx context.Context, + service graph.Service, + dest control.RestoreDestination, + dcs []data.Collection, + deets *details.Details, +) (*support.ConnectorOperationStatus, error) { + var ( + restoreMetrics support.CollectionMetrics + restoreErrors error + ) + + errUpdater := func(id string, err error) { + restoreErrors = support.WrapAndAppend(id, err, restoreErrors) + } + + // Iterate through the data collections and restore the contents of each + for _, dc := range dcs { + var ( + metrics support.CollectionMetrics + canceled bool + ) + + switch dc.FullPath().Category() { + case path.LibrariesCategory: + metrics, canceled = onedrive.RestoreCollection(ctx, service, dc, dest.ContainerName, deets, errUpdater) + default: + return nil, errors.Errorf("category %s not supported", dc.FullPath().Category()) + } + + restoreMetrics.Combine(metrics) + + if canceled { + break + } + } + + return support.CreateStatus( + ctx, + support.Restore, + len(dcs), + restoreMetrics, + restoreErrors, + dest.ContainerName), + nil +}