From e79051318c3a5f43fdb94471feaef4004f0177e1 Mon Sep 17 00:00:00 2001 From: Danny Date: Mon, 17 Oct 2022 21:17:13 -0400 Subject: [PATCH] GC: Deprecated functions removed. (#1179) Removal of deprecated functions from code base. - GetRestoreContainer no longer used for restore workflow - GetContainerID no longer used to find the M365ID of container objects. ## Description ## Type of change - [x] :hamster: Trivial/Minor ## Issue(s) * # ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- .../exchange/exchange_service_test.go | 66 ----------------- .../connector/exchange/mail_folder_cache.go | 34 +-------- .../connector/exchange/service_functions.go | 74 ------------------- .../connector/exchange/service_iterators.go | 53 ------------- .../connector/exchange/service_restore.go | 50 ------------- 5 files changed, 1 insertion(+), 276 deletions(-) diff --git a/src/internal/connector/exchange/exchange_service_test.go b/src/internal/connector/exchange/exchange_service_test.go index c7389618f..5a899916e 100644 --- a/src/internal/connector/exchange/exchange_service_test.go +++ b/src/internal/connector/exchange/exchange_service_test.go @@ -314,72 +314,6 @@ func (suite *ExchangeServiceSuite) TestGraphQueryFunctions() { } } -// TestGetMailFolderID verifies the ability to retrieve folder ID of folders -// at the top level of the file tree -func (suite *ExchangeServiceSuite) TestGetContainerID() { - userID := tester.M365UserID(suite.T()) - ctx, flush := tester.NewContext() - - defer flush() - - tests := []struct { - name string - containerName string - // category references the current optionId :: TODO --> use selector fields - category optionIdentifier - checkError assert.ErrorAssertionFunc - }{ - { - name: "Mail Valid", - containerName: DefaultMailFolder, - category: messages, - checkError: assert.NoError, - }, - { - name: "Mail Invalid", - containerName: "FolderThatIsNotHere", - category: messages, - checkError: assert.Error, - }, - { - name: "Contact Invalid", - containerName: "FolderThatIsNotHereContacts", - category: contacts, - checkError: assert.Error, - }, - { - name: "Contact Valid", - containerName: "TrialFolder", - category: contacts, - checkError: assert.NoError, - }, - { - name: "Event Invalid", - containerName: "NotAValid?@V'vCalendar", - category: events, - checkError: assert.Error, - }, - { - name: "Event Valid", - containerName: DefaultCalendar, - category: events, - checkError: assert.NoError, - }, - } - - for _, test := range tests { - suite.T().Run(test.name, func(t *testing.T) { - _, err := GetContainerID( - ctx, - suite.es, - test.containerName, - userID, - test.category) - test.checkError(t, err, "error with container: "+test.containerName) - }) - } -} - //========================== // Restore Functions //========================== diff --git a/src/internal/connector/exchange/mail_folder_cache.go b/src/internal/connector/exchange/mail_folder_cache.go index 79e0c20a1..752dddd45 100644 --- a/src/internal/connector/exchange/mail_folder_cache.go +++ b/src/internal/connector/exchange/mail_folder_cache.go @@ -12,39 +12,7 @@ import ( "github.com/alcionai/corso/src/pkg/path" ) -var _ graph.CachedContainer = &mailFolder{} - -// mailFolder structure that implements the graph.CachedContainer interface -type mailFolder struct { - folder graph.Container - p *path.Builder -} - -//========================================= -// Required Functions to satisfy interfaces -//===================================== - -func (mf mailFolder) Path() *path.Builder { - return mf.p -} - -func (mf *mailFolder) SetPath(newPath *path.Builder) { - mf.p = newPath -} - -func (mf *mailFolder) GetDisplayName() *string { - return mf.folder.GetDisplayName() -} - -//nolint:revive -func (mf *mailFolder) GetId() *string { - return mf.folder.GetId() -} - -//nolint:revive -func (mf *mailFolder) GetParentFolderId() *string { - return mf.folder.GetParentFolderId() -} +var _ graph.ContainerResolver = &mailFolderCache{} // mailFolderCache struct used to improve lookup of directories within exchange.Mail // cache map of cachedContainers where the key = M365ID diff --git a/src/internal/connector/exchange/service_functions.go b/src/internal/connector/exchange/service_functions.go index e1ba50e63..c184224c5 100644 --- a/src/internal/connector/exchange/service_functions.go +++ b/src/internal/connector/exchange/service_functions.go @@ -271,80 +271,6 @@ func GetAllContactFolders( return containers, err } -// GetContainerID query function to retrieve a container's M365 ID. -// @param containerName is the target's name, user-readable and case sensitive -// @param category switches query and iteration to support multiple exchange applications -// @returns a *string if the folder exists. If the folder does not exist returns nil, error-> folder not found -func GetContainerID( - ctx context.Context, - service graph.Service, - containerName, - user string, - category optionIdentifier, -) (*string, error) { - var ( - errs error - targetID *string - query GraphQuery - transform absser.ParsableFactory - isCalendar bool - errUpdater = func(id string, err error) { - errs = support.WrapAndAppend(id, err, errs) - } - ) - - switch category { - case messages: - query = GetAllFolderNamesForUser - transform = models.CreateMailFolderCollectionResponseFromDiscriminatorValue - case contacts: - query = GetAllContactFolderNamesForUser - transform = models.CreateContactFolderCollectionResponseFromDiscriminatorValue - case events: - query = GetAllCalendarNamesForUser - transform = models.CreateCalendarCollectionResponseFromDiscriminatorValue - isCalendar = true - default: - return nil, fmt.Errorf("unsupported category %s for GetContainerID()", category) - } - - response, err := query(ctx, service, user) - if err != nil { - return nil, errors.Wrapf( - err, - "user %s M365 query: %s", - user, support.ConnectorStackErrorTrace(err), - ) - } - - pageIterator, err := msgraphgocore.NewPageIterator( - response, - service.Adapter(), - transform, - ) - if err != nil { - return nil, err - } - - callbackFunc := iterateFindContainerID( - &targetID, - containerName, - service.Adapter().GetBaseUrl(), - isCalendar, - errUpdater, - ) - - if err := pageIterator.Iterate(ctx, callbackFunc); err != nil { - return nil, support.WrapAndAppend(service.Adapter().GetBaseUrl(), err, errs) - } - - if targetID == nil { - return nil, ErrFolderNotFound - } - - return targetID, errs -} - // SetupExchangeCollectionVars is a helper function returns a sets // Exchange.Type specific functions based on scope. // The []GraphQuery slice provides fallback queries in the event that diff --git a/src/internal/connector/exchange/service_iterators.go b/src/internal/connector/exchange/service_iterators.go index 7301143bc..f497f0877 100644 --- a/src/internal/connector/exchange/service_iterators.go +++ b/src/internal/connector/exchange/service_iterators.go @@ -567,59 +567,6 @@ func IterateSelectAllContactsForCollections( } } -// iterateFindContainerID is a utility function that supports finding -// M365 folders objects that matches the folderName. Iterator callback function -// will work on folderCollection responses whose objects implement -// the Displayable interface. If folder exists, the function updates the -// containerID memory address that was passed in. -// @param containerName is the string representation of the folder, directory or calendar holds -// the underlying M365 objects -func iterateFindContainerID( - containerID **string, - containerName, errorIdentifier string, - isCalendar bool, - errUpdater func(string, error), -) func(any) bool { - return func(entry any) bool { - if isCalendar { - entry = CreateCalendarDisplayable(entry) - } - - // True when pagination needs more time to get additional responses or - // when entry is not able to be converted into a Displayable - if entry == nil { - return true - } - - folder, ok := entry.(graph.Displayable) - if !ok { - errUpdater( - errorIdentifier, - errors.New("struct does not implement Displayable"), - ) - - return true - } - - // Display name not set on folder - if folder.GetDisplayName() == nil { - return true - } - - if containerName == *folder.GetDisplayName() { - if folder.GetId() == nil { - return true // invalid folder - } - - *containerID = folder.GetId() - - return false - } - - return true - } -} - // IDistFunc collection of helper functions which return a list of strings // from a response. type IDListFunc func(ctx context.Context, gs graph.Service, user, m365ID string) ([]string, error) diff --git a/src/internal/connector/exchange/service_restore.go b/src/internal/connector/exchange/service_restore.go index 4aa64ee5b..07e1c7480 100644 --- a/src/internal/connector/exchange/service_restore.go +++ b/src/internal/connector/exchange/service_restore.go @@ -20,56 +20,6 @@ import ( "github.com/alcionai/corso/src/pkg/path" ) -// GetRestoreContainer utility function to create -// an unique folder for the restore process -// -// @param category: input from fullPath()[2] -// that defines the application the folder is created in. -func GetRestoreContainer( - ctx context.Context, - service graph.Service, - user string, - category path.CategoryType, - name string, -) (string, error) { - option := categoryToOptionIdentifier(category) - - folderID, err := GetContainerID(ctx, service, name, user, option) - if err == nil { - return *folderID, nil - } - // Experienced error other than folder does not exist - if !errors.Is(err, ErrFolderNotFound) { - return "", support.WrapAndAppend(user+": lookup failue during GetContainerID", err, err) - } - - switch option { - case messages: - fold, err := CreateMailFolder(ctx, service, user, name) - if err != nil { - return "", support.WrapAndAppend(fmt.Sprintf("creating folder %s for user %s", name, user), err, err) - } - - return *fold.GetId(), nil - case contacts: - fold, err := CreateContactFolder(ctx, service, user, name) - if err != nil { - return "", support.WrapAndAppend(user+"failure during CreateContactFolder during restore Contact", err, err) - } - - return *fold.GetId(), nil - case events: - calendar, err := CreateCalendar(ctx, service, user, name) - if err != nil { - return "", support.WrapAndAppend(user+"failure during CreateCalendar during restore Event", err, err) - } - - return *calendar.GetId(), nil - default: - return "", fmt.Errorf("category: %s not supported for folder creation: GetRestoreContainer", option) - } -} - // RestoreExchangeObject directs restore pipeline towards restore function // based on the path.CategoryType. All input params are necessary to perform // the type-specific restore function.