saveEntitiesVersion method
- required VersionCreateRequest versionCreateRequest,
- CancelToken? cancelToken,
- Map<
String, dynamic> ? headers, - Map<
String, dynamic> ? extra, - ValidateStatus? validateStatus,
- ProgressCallback? onSendProgress,
- 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 { "type": "SINGLE_ENTITY", "versionName": "Version 1.0", "branch": "dev", "entityId": { "entityType": "DEVICE", "id": "b79448e0-d4f4-11ec-847b-0f432358ab48" }, "config": { "saveRelations": true, "saveAttributes": true, "saveCredentials": 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 { "type": "COMPLEX", "versionName": "Devices and profiles: release 2", "branch": "master", "syncStrategy": "OVERWRITE", "entityTypes": { "DEVICE": { "syncStrategy": null, "allEntities": true, "saveRelations": true, "saveAttributes": true, "saveCredentials": true }, "DEVICE_PROFILE": { "syncStrategy": "MERGE", "allEntities": false, "entityIds": \"b79448e0-d4f4-11ec-847b-0f432358ab48\" , "saveRelations": 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:
versionCreateRequestcancelToken- ACancelTokenthat can be used to cancel the operationheaders- Can be used to add additional headers to the requestextras- Can be used to add flags to the requestvalidateStatus- AValidateStatuscallback that can be used to determine request success based on the HTTP status of the responseonSendProgress- AProgressCallbackthat can be used to get the send progressonReceiveProgress- AProgressCallbackthat 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,
);
}