Skip to content

Commit

Permalink
Bug/devtooling 707 - Worktype status independent resource (MyPureClou…
Browse files Browse the repository at this point in the history
…d#1164)

* Refactored code

* Removed statuses from worktype resource

* Finished worktype status resource

* Added reponse assets stuff back

* Fixed workitems tests

* Updated docs

* Updated docs

* Made requested changes

* Added caching
  • Loading branch information
dginty4 authored Jul 29, 2024
1 parent c4182e3 commit b437ad7
Show file tree
Hide file tree
Showing 36 changed files with 1,422 additions and 1,580 deletions.
15 changes: 11 additions & 4 deletions docs/data-sources/task_management_worktype_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
page_title: "genesyscloud_task_management_worktype_status Data Source - terraform-provider-genesyscloud"
subcategory: ""
description: |-
Genesys Cloud task management worktype_status data source. Select a status by worktype name and status name
Genesys Cloud task management worktype status data source. Select an task management worktype status by name
---

# genesyscloud_task_management_worktype_status (Data Source)

Genesys Cloud task management worktype_status data source. Select a status by worktype name and status name
Genesys Cloud task management worktype status data source. Select an task management worktype status by name

## Example Usage

```terraform
data "genesyscloud_task_management_worktype_status" "status_sample" {
worktype_id = genesyscloud_task_management_worktype.example.id
name = "Worktype status"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `worktype_name` (String) Task management worktype name
- `worktype_status_name` (String) Task management worktype status name
- `name` (String) Task management worktype status name
- `worktype_id` (String) The id of the worktype the status belongs to

### Read-Only

Expand Down
58 changes: 0 additions & 58 deletions docs/resources/task_management_worktype.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ The following Genesys Cloud APIs are used by this resource. Ensure your OAuth Cl
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId-)
* [POST /api/v2/taskmanagement/worktypes/query](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes-query)
* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)



## Example Usage

Expand All @@ -45,36 +39,6 @@ resource "genesyscloud_task_management_worktype" "worktype_1" {
default_skills_ids = [genesyscloud_routing_skill.skill_1.id, genesyscloud_routing_skill.skill_2.id]
assignment_enabled = true
defaultStatusName = "Open Status"
statuses {
name = "Open Status"
description = "Description of open status"
category = "Open"
destination_status_names = ["WIP", "Waiting Status"]
default_destination_status_name = "WIP"
status_transition_delay_seconds = 86500
status_transition_time = "04:20:00"
}
statuses {
name = "WIP"
description = "Description of WIP status"
category = "InProgress"
}
statuses {
name = "Waiting Status"
description = "Description of waiting status"
category = "Waiting"
}
statuses {
name = "Close Status"
description = "Description of close status"
category = "Closed"
}
}
```

Expand All @@ -97,34 +61,12 @@ resource "genesyscloud_task_management_worktype" "worktype_1" {
- `default_priority` (Number) The default priority for Workitems created from the Worktype. The valid range is between -25,000,000 and 25,000,000.
- `default_queue_id` (String) The default queue for Workitems created from the Worktype.
- `default_skills_ids` (List of String) The default skills for Workitems created from the Worktype.
- `default_status_name` (String) The name of the default status for Workitems created from the Worktype. This status should be defined in 'statuses'.
- `default_ttl_seconds` (Number) The default time to time to live in seconds for Workitems created from the Worktype.
- `description` (String) The description of the Worktype.
- `division_id` (String) The division to which this entity belongs.
- `schema_version` (Number) Version of the workitem schema to use. If not provided, the worktype will use the latest version.
- `statuses` (Block Set) The list of possible statuses for Workitems created from the Worktype. (see [below for nested schema](#nestedblock--statuses))

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--statuses"></a>
### Nested Schema for `statuses`

Required:

- `category` (String) The Category of the Status.
- `name` (String) Name of the status

Optional:

- `default_destination_status_name` (String) Name of the default destination status to which this Status will transition to if auto status transition enabled.
- `description` (String) The description of the Status.
- `destination_status_names` (List of String) The names of the Statuses the Status can transition to. If null, the status can transition to any other status.
- `status_transition_delay_seconds` (Number) Delay in seconds for auto status transition
- `status_transition_time` (String) Time (HH:MM:SS format) at which auto status transition will occur after statusTransitionDelaySeconds delay. To set Time, the statusTransitionDelaySeconds must be equal to or greater than 86400 i.e. a day

Read-Only:

- `id` (String) Read-only identifier of the workitem status

59 changes: 59 additions & 0 deletions docs/resources/task_management_worktype_status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
page_title: "genesyscloud_task_management_worktype_status Resource - terraform-provider-genesyscloud"
subcategory: ""
description: |-
Genesys Cloud task management worktype status
---
# genesyscloud_task_management_worktype_status (Resource)

Genesys Cloud task management worktype status

## API Usage
The following Genesys Cloud APIs are used by this resource. Ensure your OAuth Client has been granted the necessary scopes and permissions to perform these operations:

* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses)
* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)



## Example Usage

```terraform
resource "genesyscloud_task_management_worktype_status" "worktype_status" {
worktype_id = genesyscloud_task_management_worktype.example.id
name = "Open Status"
description = "Description of open status"
category = "Open"
destination_status_ids = [genesyscloud_task_management_worktype_status.status1.id, genesyscloud_task_management_worktype_status.status2.id]
default_destination_status_id = genesyscloud_task_management_worktype_status.status1.id
status_transition_delay_seconds = 86500
status_transition_time = "04:20:00"
default = false
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `category` (String) The Category of the Status. Changing the category will cause the resource to be dropped and recreated with a new id.
- `name` (String) Name of the status.
- `worktype_id` (String) The id of the worktype this status belongs to. Changing this attribute will cause the status to be dropped and recreated.

### Optional

- `default` (Boolean) This status is the default status for Workitems created from this Worktype. Only one status can be set as the default status at a time.
- `default_destination_status_id` (String) Default destination status to which this Status will transition to if auto status transition enabled.
- `description` (String) The description of the Status.
- `destination_status_ids` (List of String) A list of destination Statuses where a Workitem with this Status can transition to. If the list is empty Workitems with this Status can transition to all other Statuses defined on the Worktype. A Status can have a maximum of 24 destinations.
- `status_transition_delay_seconds` (Number) Delay in seconds for auto status transition. Required if default_destination_status_id is provided.
- `status_transition_time` (String) Time is represented as an ISO-8601 string without a timezone. For example: HH:mm:ss

### Read-Only

- `id` (String) The ID of this resource.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "genesyscloud_task_management_worktype_status" "status_sample" {
worktype_id = genesyscloud_task_management_worktype.example.id
name = "Worktype status"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@
* [GET /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#get-api-v2-taskmanagement-worktypes--worktypeId-)
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId-)
* [POST /api/v2/taskmanagement/worktypes/query](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes-query)
* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/platform/preview-apis#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)

* [POST /api/v2/taskmanagement/worktypes/query](https://developer.genesys.cloud/platform/preview-apis#post-api-v2-taskmanagement-worktypes-query)
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,4 @@ resource "genesyscloud_task_management_worktype" "worktype_1" {
default_skills_ids = [genesyscloud_routing_skill.skill_1.id, genesyscloud_routing_skill.skill_2.id]

assignment_enabled = true

defaultStatusName = "Open Status"

statuses {
name = "Open Status"
description = "Description of open status"
category = "Open"
destination_status_names = ["WIP", "Waiting Status"]
default_destination_status_name = "WIP"
status_transition_delay_seconds = 86500
status_transition_time = "04:20:00"
}

statuses {
name = "WIP"
description = "Description of WIP status"
category = "InProgress"
}

statuses {
name = "Waiting Status"
description = "Description of waiting status"
category = "Waiting"
}

statuses {
name = "Close Status"
description = "Description of close status"
category = "Closed"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses)
* [POST /api/v2/taskmanagement/worktypes/{worktypeId}/statuses](https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-taskmanagement-worktypes--worktypeId--statuses)
* [GET /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [PATCH /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#patch-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)
* [DELETE /api/v2/taskmanagement/worktypes/{worktypeId}/statuses/{statusId}](https://developer.genesys.cloud/devapps/api-explorer#delete-api-v2-taskmanagement-worktypes--worktypeId--statuses--statusId-)

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "genesyscloud_task_management_worktype_status" "worktype_status" {
worktype_id = genesyscloud_task_management_worktype.example.id
name = "Open Status"
description = "Description of open status"
category = "Open"
destination_status_ids = [genesyscloud_task_management_worktype_status.status1.id, genesyscloud_task_management_worktype_status.status2.id]
default_destination_status_id = genesyscloud_task_management_worktype_status.status1.id
status_transition_delay_seconds = 86500
status_transition_time = "04:20:00"
default = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"terraform-provider-genesyscloud/genesyscloud/provider"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
"terraform-provider-genesyscloud/genesyscloud/validators"

registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
"terraform-provider-genesyscloud/genesyscloud/validators"
)

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"

"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)

Expand Down Expand Up @@ -34,11 +36,13 @@ type taskManagementWorkbinProxy struct {
getTaskManagementWorkbinByIdAttr getTaskManagementWorkbinByIdFunc
updateTaskManagementWorkbinAttr updateTaskManagementWorkbinFunc
deleteTaskManagementWorkbinAttr deleteTaskManagementWorkbinFunc
workbinCache rc.CacheInterface[platformclientv2.Workbin]
}

// newTaskManagementWorkbinProxy initializes the task management workbin proxy with all of the data needed to communicate with Genesys Cloud
func newTaskManagementWorkbinProxy(clientConfig *platformclientv2.Configuration) *taskManagementWorkbinProxy {
api := platformclientv2.NewTaskManagementApiWithConfig(clientConfig)
workbinCache := rc.NewResourceCache[platformclientv2.Workbin]()
return &taskManagementWorkbinProxy{
clientConfig: clientConfig,
taskManagementApi: api,
Expand All @@ -48,6 +52,7 @@ func newTaskManagementWorkbinProxy(clientConfig *platformclientv2.Configuration)
getTaskManagementWorkbinByIdAttr: getTaskManagementWorkbinByIdFn,
updateTaskManagementWorkbinAttr: updateTaskManagementWorkbinFn,
deleteTaskManagementWorkbinAttr: deleteTaskManagementWorkbinFn,
workbinCache: workbinCache,
}
}

Expand Down Expand Up @@ -143,11 +148,12 @@ func getTaskManagementWorkbinIdByNameFn(ctx context.Context, p *taskManagementWo

// getTaskManagementWorkbinByIdFn is an implementation of the function to get a Genesys Cloud task management workbin by Id
func getTaskManagementWorkbinByIdFn(ctx context.Context, p *taskManagementWorkbinProxy, id string) (taskManagementWorkbin *platformclientv2.Workbin, resp *platformclientv2.APIResponse, err error) {
workbin, resp, err := p.taskManagementApi.GetTaskmanagementWorkbin(id)
if err != nil {
return nil, resp, fmt.Errorf("failed to retrieve task management workbin by id %s: %s", id, err)
workbin := rc.GetCacheItem(p.workbinCache, id)
if workbin != nil {
return workbin, nil, nil
}
return workbin, resp, nil

return p.taskManagementApi.GetTaskmanagementWorkbin(id)
}

// updateTaskManagementWorkbinFn is an implementation of the function to update a Genesys Cloud task management workbin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"

worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
Expand Down Expand Up @@ -39,12 +40,16 @@ func TestAccDataSourceTaskManagementWorkitem(t *testing.T) {
wtResName = "tf_worktype_1"
wtName = "tf-worktype" + uuid.NewString()
wtDescription = "tf-worktype-description"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"

// Worktype statuses
statusResourceOpen = "open-status"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
statusResourceClosed = "closed-status"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"

// basic workitem
workitemRes = "workitem_1"
Expand All @@ -64,22 +69,25 @@ func TestAccDataSourceTaskManagementWorkitem(t *testing.T) {
wtDescription,
fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
// Needs both an open and closed status or workitems cannot be created for worktype.
fmt.Sprintf(`
statuses {
name = "%s"
description = "%s"
category = "%s"
}
statuses {
name = "%s"
description = "%s"
category = "%s"
}
default_status_name = "%s"
`, wtOStatusName, wtOStatusDesc, wtOStatusCategory,
wtCStatusName, wtCStatusDesc, wtCStatusCategory,
wtOStatusName),
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceOpen,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtOStatusName,
wtOStatusCategory,
wtOStatusDesc,
util.NullValue,
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceClosed,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtCStatusName,
wtCStatusCategory,
wtCStatusDesc,
util.NullValue,
"",
)
)
resource.Test(t, resource.TestCase{
Expand Down
Loading

0 comments on commit b437ad7

Please sign in to comment.