How to Copy Dataset

Warning: Beta software This API is in beta stage and may be subject to change. Therefore, we do not recommend using this in production.

Interested in this feature? Please reach out to mobility-services-developer@cisco.com

CopyDataset is a method that allows you to copy a dataset in the IR21 database. You can specify a destination UUID or let the system generate one.

When you copy a dataset, all the organisations in the source dataset are copied to the new destination dataset.

This method is part of the IR21 API and belongs to the Ir21Service.

Prerequisites

  1. An OAuth 2.0 client
  2. A client access token

Code Dependencies

<dependency>
  <groupId>com.wgtwo.api.v1.grpc</groupId>
  <artifactId>ir21</artifactId>
  <version>1.16.3</version>
</dependency>

Code

The examples below demonstrate how to use the CopyDataset function.

You can test our APIs without authorization by targeting sandbox.api.shamrock.wgtwo.com instead of api.{region}.wgtwo.com and removing any authorization from the request/code sample.


#!/usr/bin/env bash
grpcurl \
  -d '
  {
    "sourceUuid": "rM/IlHhOSQiHoQFiUHv6ww==",
    "comment": "Copy of example dataset"
  }
  ' \
  sandbox.api.shamrock.wgtwo.com:443 \
  wgtwo.ir21.v1.Ir21Service/CopyDataset

package com.example.ir21

import com.google.protobuf.ByteString
import com.wgtwo.api.v1.ir21.Ir21ServiceGrpcKt
import com.wgtwo.api.v1.ir21.copyDatasetRequest
import io.grpc.ManagedChannelBuilder
import io.grpc.Status
import io.grpc.StatusException
import kotlinx.coroutines.runBlocking
import kotlin.test.assertFailsWith

private val channel = ManagedChannelBuilder.forAddress("sandbox.api.shamrock.wgtwo.com", 443).build()
private val stub = Ir21ServiceGrpcKt.Ir21ServiceCoroutineStub(channel)

fun main() = runBlocking {
    // First create a dataset to copy
    val createRequest = com.wgtwo.api.v1.ir21.createDatasetRequest {
        comment = "Original dataset to be copied"
    }
    val createResponse = stub.createDataset(createRequest)
    val createdDatasetUuid = createResponse.uuid

    val copyDatasetRequest = copyDatasetRequest {
        sourceUuid = createdDatasetUuid
        comment = "Copy of example dataset"
    }
    println("copyDatasetRequest:
$copyDatasetRequest")

    val copyDatasetResponse = stub.copyDataset(copyDatasetRequest)
    println("copyDatasetResponse:
$copyDatasetResponse")

    // Test error case - empty source UUID
    val copyDatasetRequestWithEmptySource = copyDatasetRequest {
        sourceUuid = ByteString.EMPTY
        comment = "This should fail"
    }

    val exception = assertFailsWith<StatusException>("exception is not a StatusException") {
        stub.copyDataset(copyDatasetRequestWithEmptySource)
    }

    assert(exception.status.code == Status.INVALID_ARGUMENT.code) {
        "status code is not INVALID_ARGUMENT: ${exception.status.code}"
    }
}

Example Results Success

{
  "uuid": "3Gm4Vz8XRl3NX5ntSHQ1YB=="
}
uuid: "3Gm4Vz8XRl3NX5ntSHQ1YB=="

Example Results Error

ERROR:
  Code: InvalidArgument
  Message: source_uuid is required
Status code: INVALID_ARGUMENT
Status description: source_uuid is required

Read More