discontinuedPackage thingsboard_pe_client has been discontinued and replaced by thingsboard_client.

saveEntitiesVersion method

Future<Response<String>> saveEntitiesVersion({
  1. required VersionCreateRequest versionCreateRequest,
  2. CancelToken? cancelToken,
  3. Map<String, dynamic>? headers,
  4. Map<String, dynamic>? extra,
  5. ValidateStatus? validateStatus,
  6. ProgressCallback? onSendProgress,
  7. ProgressCallback? onReceiveProgress,
})

Save entities version (saveEntitiesVersion) Creates a new version of entities (or a single entity) by request. Supported entity types: CUSTOMER, ASSET, RULE_CHAIN, DASHBOARD, DEVICE_PROFILE, DEVICE, ENTITY_VIEW, WIDGETS_BUNDLE, CONVERTER, INTEGRATION, ROLE and USER group. There are two available types of request: `SINGLE_ENTITY` and `COMPLEX`. Each of them contains version name (`versionName`) and name of a branch (`branch`) to create version (commit) in. If specified branch does not exists in a remote repo, then new empty branch will be created. Request of the `SINGLE_ENTITY` type has id of an entity (`entityId`) and additional configuration (`config`) which has following options: - `saveRelations` - whether to add inbound and outbound relations of type COMMON to created entity version; - `saveAttributes` - to save attributes of server scope (and also shared scope for devices); - `saveCredentials` - when saving a version of a device, to add its credentials to the version; - `savePermissions` - when saving a user group - to save group permission list; - `saveGroupEntities` - when saving an entity group - to save its entities as well. An example of a `SINGLE_ENTITY` version create request: ```json { &quot;type&quot;: &quot;SINGLE_ENTITY&quot;, &quot;versionName&quot;: &quot;Version 1.0&quot;, &quot;branch&quot;: &quot;dev&quot;, &quot;entityId&quot;: { &quot;entityType&quot;: &quot;DEVICE&quot;, &quot;id&quot;: &quot;b79448e0-d4f4-11ec-847b-0f432358ab48&quot; }, &quot;config&quot;: { &quot;saveRelations&quot;: true, &quot;saveAttributes&quot;: true, &quot;saveCredentials&quot;: false } } ``` Second request type (`COMPLEX`), additionally to `branch` and `versionName`, contains following properties: - `entityTypes` - a structure with entity types to export and configuration for each entity type; this configuration has all the options available for `SINGLE_ENTITY` and additionally has these ones: - `allEntities` and `entityIds` - if you want to save the version of all entities of the entity type then set `allEntities` param to true, otherwise set it to false and specify `entityIds` - in case entity type is group entity, list of specific entity groups, or if not - list of entities; - `syncStrategy` - synchronization strategy to use for this entity type: when set to `OVERWRITE` then the list of remote entities of this type will be overwritten by newly added entities. If set to `MERGE` - existing remote entities of this entity type will not be removed, new entities will just be added on top (or existing remote entities will be updated). - `syncStrategy` - default synchronization strategy to use when it is not specified for an entity type. Example for this type of request: ```json { &quot;type&quot;: &quot;COMPLEX&quot;, &quot;versionName&quot;: &quot;Devices and profiles: release 2&quot;, &quot;branch&quot;: &quot;master&quot;, &quot;syncStrategy&quot;: &quot;OVERWRITE&quot;, &quot;entityTypes&quot;: { &quot;DEVICE&quot;: { &quot;syncStrategy&quot;: null, &quot;allEntities&quot;: true, &quot;saveRelations&quot;: true, &quot;saveAttributes&quot;: true, &quot;saveCredentials&quot;: true }, &quot;DEVICE_PROFILE&quot;: { &quot;syncStrategy&quot;: &quot;MERGE&quot;, &quot;allEntities&quot;: false, &quot;entityIds&quot;: \&quot;b79448e0-d4f4-11ec-847b-0f432358ab48\&quot; , &quot;saveRelations&quot;: true } } } ``` Response wil contain generated request UUID, that can be then used to retrieve status of operation via `getVersionCreateRequestStatus`. Available for users with 'TENANT_ADMIN' authority.

Parameters:

  • versionCreateRequest
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a String as data Throws DioException if API call or serialization fails

Implementation

Future<Response<String>> saveEntitiesVersion({
  required VersionCreateRequest versionCreateRequest,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _serializers =
      this._serializers ?? apiSerializers(registerVersionCreateRequest);
  final _path = r'/api/entities/vc/version';
  final _options = Options(
    method: r'POST',
    headers: <String, dynamic>{...?headers},
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'apiKey',
          'name': 'ApiKeyForm',
          'keyName': 'X-Authorization',
          'where': 'header',
        },
        {'type': 'http', 'scheme': 'loginPassword', 'name': 'HttpLoginForm'},
      ],
      ...?extra,
    },
    contentType: 'application/json',
    validateStatus: validateStatus,
  );

  dynamic _bodyData;

  try {
    const _type = FullType(VersionCreateRequest);
    _bodyData = _serializers.serialize(
      versionCreateRequest,
      specifiedType: _type,
    );
  } catch (error, stackTrace) {
    throw DioException(
      requestOptions: _options.compose(_dio.options, _path),
      type: DioExceptionType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  final _response = await _dio.request<Object>(
    _path,
    data: _bodyData,
    options: _options,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  String? _responseData;

  try {
    final rawResponse = _response.data;
    _responseData = rawResponse == null
        ? null
        : rawResponse is String
        ? rawResponse
        : jsonEncode(rawResponse);
  } catch (error, stackTrace) {
    throw DioException(
      requestOptions: _response.requestOptions,
      response: _response,
      type: DioExceptionType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  return Response<String>(
    data: _responseData,
    headers: _response.headers,
    isRedirect: _response.isRedirect,
    requestOptions: _response.requestOptions,
    redirects: _response.redirects,
    statusCode: _response.statusCode,
    statusMessage: _response.statusMessage,
    extra: _response.extra,
  );
}