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

<!-- Insert PR description-->

## Type of change

<!--- Please check the type of change your PR introduces: --->

- [x] 🐹 Trivial/Minor

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Danny 2022-10-17 21:17:13 -04:00 committed by GitHub
parent 48cb751ee0
commit e79051318c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 276 deletions

View File

@ -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
//==========================

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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.