Skip to content

Commit

Permalink
PR review comments had been addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshperiyappan committed Jan 22, 2025
1 parent fed61c6 commit dcd9b0c
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"log"
"sync"
gcloud "terraform-provider-genesyscloud/genesyscloud"
"terraform-provider-genesyscloud/genesyscloud/architect_flow"
"terraform-provider-genesyscloud/genesyscloud/architect_schedulegroups"
"terraform-provider-genesyscloud/genesyscloud/architect_schedules"
architectFlow "terraform-provider-genesyscloud/genesyscloud/architect_flow"
architectSchedulegroups "terraform-provider-genesyscloud/genesyscloud/architect_schedulegroups"
architectSchedules "terraform-provider-genesyscloud/genesyscloud/architect_schedules"
authDivision "terraform-provider-genesyscloud/genesyscloud/auth_division"
"terraform-provider-genesyscloud/genesyscloud/journey_outcome"
journeyOutcome "terraform-provider-genesyscloud/genesyscloud/journey_outcome"
"terraform-provider-genesyscloud/genesyscloud/provider"
"testing"

Expand Down Expand Up @@ -44,11 +44,11 @@ func (r *registerTestInstance) registerTestResources() {

providerResources[ResourceType] = ResourceJourneyActionMap()
providerResources[authDivision.ResourceType] = authDivision.ResourceAuthDivision()
providerResources[architect_schedules.ResourceType] = architect_schedules.ResourceArchitectSchedules()
providerResources[architect_schedulegroups.ResourceType] = architect_schedulegroups.ResourceArchitectSchedulegroups()
providerResources[architect_flow.ResourceType] = architect_flow.ResourceArchitectFlow()
providerResources[architectSchedules.ResourceType] = architectSchedules.ResourceArchitectSchedules()
providerResources[architectSchedulegroups.ResourceType] = architectSchedulegroups.ResourceArchitectSchedulegroups()
providerResources[architectFlow.ResourceType] = architectFlow.ResourceArchitectFlow()
providerResources[journeyOutcome.ResourceType] = journeyOutcome.ResourceJourneyOutcome()
providerResources["genesyscloud_journey_segment"] = gcloud.ResourceJourneySegment()
providerResources["genesyscloud_journey_outcome"] = journey_outcome.ResourceJourneyOutcome()
}

// registerTestDataSources registers all data sources used in the tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ import (
"github.com/mypurecloud/platform-client-sdk-go/v150/platformclientv2"
)

// dataSourceJourneyOutcomeRead retrieves a journey outcome by name from the Genesys Cloud Platform
// Parameters:
// - ctx: The context.Context for managing timeouts and cancellation
// - d: The schema.ResourceData containing the resource state
// - m: The provider meta interface containing client configuration
//
// Returns:
// - diag.Diagnostics: Any error diagnostics that occurred during the operation
//
// The function implements a retry mechanism with a 15-second timeout and performs the following:
// 1. Iterates through pages of journey outcomes (100 items per page)
// 2. Searches for an outcome matching the specified name
// 3. Sets the resource ID when a match is found
// 4. Returns an error if no matching outcome is found after checking all pages
func dataSourceJourneyOutcomeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sdkConfig := m.(*provider.ProviderMeta).ClientConfig
journeyApi := platformclientv2.NewJourneyApiWithConfig(sdkConfig)
Expand All @@ -38,11 +52,17 @@ func dataSourceJourneyOutcomeRead(ctx context.Context, d *schema.ResourceData, m

for _, journeyOutcome := range *journeyOutcomes.Entities {
if journeyOutcome.DisplayName != nil && *journeyOutcome.DisplayName == name {
if journeyOutcome.Id == nil {
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, "journey outcome ID is nil", resp))
}
d.SetId(*journeyOutcome.Id)
return nil
}
}

if journeyOutcomes.PageCount == nil {
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, "journey outcomes page count is nil", resp))
}
pageCount = *journeyOutcomes.PageCount
}
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("no journey outcome found with name %s", name), response))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (p *journeyOutcomeProxy) deleteJourneyOutcome(ctx context.Context, id strin
func createJourneyOutcomeFn(ctx context.Context, p *journeyOutcomeProxy, outcome *platformclientv2.Outcomerequest) (*platformclientv2.Outcome, *platformclientv2.APIResponse, error) {
outcomeRes, resp, err := p.journeyApi.PostJourneyOutcomes(*outcome)
if err != nil {
return nil, resp, fmt.Errorf("Failed to create journey outcome: %s", err)
return nil, resp, err
}
return outcomeRes, resp, nil
}
Expand All @@ -133,7 +133,7 @@ func getAllJourneyOutcomesFn(ctx context.Context, p *journeyOutcomeProxy) (*[]pl

outcomes, resp, err := p.journeyApi.GetJourneyOutcomes(1, pageSize, "", nil, nil, "")
if err != nil {
return nil, resp, fmt.Errorf("Failed to get journey outcomes: %s", err)
return nil, resp, err
}

if outcomes == nil || outcomes.Entities == nil || len(*outcomes.Entities) == 0 {
Expand All @@ -145,7 +145,7 @@ func getAllJourneyOutcomesFn(ctx context.Context, p *journeyOutcomeProxy) (*[]pl
for pageNum := 2; pageNum <= *outcomes.PageCount; pageNum++ {
outcomes, resp, err := p.journeyApi.GetJourneyOutcomes(pageNum, pageSize, "", nil, nil, "")
if err != nil {
return nil, resp, fmt.Errorf("Failed to get journey outcomes page %d: %s", pageNum, err)
return nil, resp, err
}
if outcomes == nil || outcomes.Entities == nil || len(*outcomes.Entities) == 0 {
break
Expand Down Expand Up @@ -186,7 +186,7 @@ func getJourneyOutcomeIdByNameFn(ctx context.Context, p *journeyOutcomeProxy, na
func getJourneyOutcomeByIdFn(ctx context.Context, p *journeyOutcomeProxy, id string) (outcome *platformclientv2.Outcome, response *platformclientv2.APIResponse, err error) {
outcome, resp, err := p.journeyApi.GetJourneyOutcome(id)
if err != nil {
return nil, resp, fmt.Errorf("Failed to get journey outcome by id %s: %s", id, err)
return nil, resp, err
}
return outcome, resp, nil
}
Expand All @@ -195,7 +195,7 @@ func getJourneyOutcomeByIdFn(ctx context.Context, p *journeyOutcomeProxy, id str
func updateJourneyOutcomeFn(ctx context.Context, p *journeyOutcomeProxy, id string, outcome *platformclientv2.Patchoutcome) (*platformclientv2.Outcome, *platformclientv2.APIResponse, error) {
outcomeRes, resp, err := p.journeyApi.PatchJourneyOutcome(id, *outcome)
if err != nil {
return nil, resp, fmt.Errorf("Failed to update journey outcome: %s", err)
return nil, resp, err
}
return outcomeRes, resp, nil
}
Expand All @@ -204,7 +204,8 @@ func updateJourneyOutcomeFn(ctx context.Context, p *journeyOutcomeProxy, id stri
func deleteJourneyOutcomeFn(ctx context.Context, p *journeyOutcomeProxy, id string) (*platformclientv2.APIResponse, error) {
resp, err := p.journeyApi.DeleteJourneyOutcome(id)
if err != nil {
return resp, fmt.Errorf("Failed to delete journey outcome: %s", err)
return resp, err
}
rc.DeleteCacheItem(p.outcomeCache, id)
return resp, nil
}
Loading

0 comments on commit dcd9b0c

Please sign in to comment.