2022-05-20 17:50:35 +03:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
|
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { EntityId } from '@shared/models/id/entity-id';
|
2022-05-26 13:50:50 +03:00
|
|
|
import { EntityType } from '@shared/models/entity-type.models';
|
2022-05-27 19:34:55 +03:00
|
|
|
import { ExportableEntity } from '@shared/models/base-data';
|
|
|
|
|
import { EntityRelation } from '@shared/models/relation.models';
|
|
|
|
|
import { Device, DeviceCredentials } from '@shared/models/device.models';
|
|
|
|
|
import { RuleChain, RuleChainMetaData } from '@shared/models/rule-chain.models';
|
2022-05-20 17:50:35 +03:00
|
|
|
|
2022-05-30 19:05:17 +03:00
|
|
|
export const exportableEntityTypes: Array<EntityType> = [
|
|
|
|
|
EntityType.ASSET,
|
|
|
|
|
EntityType.DEVICE,
|
|
|
|
|
EntityType.DASHBOARD,
|
|
|
|
|
EntityType.CUSTOMER,
|
|
|
|
|
EntityType.DEVICE_PROFILE,
|
|
|
|
|
EntityType.RULE_CHAIN
|
|
|
|
|
];
|
|
|
|
|
|
2022-05-20 17:50:35 +03:00
|
|
|
export interface VersionCreateConfig {
|
|
|
|
|
saveRelations: boolean;
|
2022-05-31 16:16:24 +03:00
|
|
|
saveAttributes: boolean;
|
2022-06-02 12:32:10 +03:00
|
|
|
saveCredentials: boolean;
|
2022-05-20 17:50:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum VersionCreateRequestType {
|
|
|
|
|
SINGLE_ENTITY = 'SINGLE_ENTITY',
|
|
|
|
|
COMPLEX = 'COMPLEX'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface VersionCreateRequest {
|
|
|
|
|
versionName: string;
|
|
|
|
|
branch: string;
|
|
|
|
|
type: VersionCreateRequestType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SingleEntityVersionCreateRequest extends VersionCreateRequest {
|
|
|
|
|
entityId: EntityId;
|
|
|
|
|
config: VersionCreateConfig;
|
|
|
|
|
type: VersionCreateRequestType.SINGLE_ENTITY;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 19:05:17 +03:00
|
|
|
export enum SyncStrategy {
|
|
|
|
|
MERGE = 'MERGE',
|
|
|
|
|
OVERWRITE = 'OVERWRITE'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const syncStrategyTranslationMap = new Map<SyncStrategy, string>(
|
|
|
|
|
[
|
|
|
|
|
[SyncStrategy.MERGE, 'version-control.sync-strategy-merge'],
|
|
|
|
|
[SyncStrategy.OVERWRITE, 'version-control.sync-strategy-overwrite']
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
2022-06-01 16:35:20 +03:00
|
|
|
export const syncStrategyHintMap = new Map<SyncStrategy, string>(
|
|
|
|
|
[
|
|
|
|
|
[SyncStrategy.MERGE, 'version-control.sync-strategy-merge-hint'],
|
|
|
|
|
[SyncStrategy.OVERWRITE, 'version-control.sync-strategy-overwrite-hint']
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
2022-05-30 19:05:17 +03:00
|
|
|
export interface EntityTypeVersionCreateConfig extends VersionCreateConfig {
|
|
|
|
|
syncStrategy: SyncStrategy;
|
|
|
|
|
entityIds: string[];
|
|
|
|
|
allEntities: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ComplexVersionCreateRequest extends VersionCreateRequest {
|
|
|
|
|
syncStrategy: SyncStrategy;
|
|
|
|
|
entityTypes: {[entityType: string]: EntityTypeVersionCreateConfig};
|
|
|
|
|
type: VersionCreateRequestType.COMPLEX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createDefaultEntityTypesVersionCreate(): {[entityType: string]: EntityTypeVersionCreateConfig} {
|
|
|
|
|
const res: {[entityType: string]: EntityTypeVersionCreateConfig} = {};
|
|
|
|
|
for (const entityType of exportableEntityTypes) {
|
|
|
|
|
res[entityType] = {
|
|
|
|
|
syncStrategy: null,
|
2022-06-01 16:35:20 +03:00
|
|
|
saveAttributes: true,
|
|
|
|
|
saveRelations: true,
|
2022-06-02 12:32:10 +03:00
|
|
|
saveCredentials: true,
|
2022-05-30 19:05:17 +03:00
|
|
|
allEntities: true,
|
|
|
|
|
entityIds: []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 11:33:49 +03:00
|
|
|
export interface VersionLoadConfig {
|
|
|
|
|
loadRelations: boolean;
|
2022-05-31 16:16:24 +03:00
|
|
|
loadAttributes: boolean;
|
2022-06-02 12:32:10 +03:00
|
|
|
loadCredentials: boolean;
|
2022-05-31 11:33:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum VersionLoadRequestType {
|
|
|
|
|
SINGLE_ENTITY = 'SINGLE_ENTITY',
|
|
|
|
|
ENTITY_TYPE = 'ENTITY_TYPE'
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 13:50:50 +03:00
|
|
|
export interface VersionLoadRequest {
|
|
|
|
|
branch: string;
|
|
|
|
|
versionId: string;
|
|
|
|
|
type: VersionLoadRequestType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SingleEntityVersionLoadRequest extends VersionLoadRequest {
|
|
|
|
|
externalEntityId: EntityId;
|
|
|
|
|
config: VersionLoadConfig;
|
|
|
|
|
type: VersionLoadRequestType.SINGLE_ENTITY;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 11:33:49 +03:00
|
|
|
export interface EntityTypeVersionLoadConfig extends VersionLoadConfig {
|
|
|
|
|
removeOtherEntities: boolean;
|
2022-05-31 16:16:24 +03:00
|
|
|
findExistingEntityByName: boolean;
|
2022-05-31 11:33:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface EntityTypeVersionLoadRequest extends VersionLoadRequest {
|
|
|
|
|
entityTypes: {[entityType: string]: EntityTypeVersionLoadConfig};
|
|
|
|
|
type: VersionLoadRequestType.ENTITY_TYPE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createDefaultEntityTypesVersionLoad(): {[entityType: string]: EntityTypeVersionLoadConfig} {
|
|
|
|
|
const res: {[entityType: string]: EntityTypeVersionLoadConfig} = {};
|
|
|
|
|
for (const entityType of exportableEntityTypes) {
|
|
|
|
|
res[entityType] = {
|
2022-06-01 16:35:20 +03:00
|
|
|
loadAttributes: true,
|
|
|
|
|
loadRelations: true,
|
2022-06-02 12:32:10 +03:00
|
|
|
loadCredentials: true,
|
2022-05-31 16:16:24 +03:00
|
|
|
removeOtherEntities: false,
|
2022-06-01 16:35:20 +03:00
|
|
|
findExistingEntityByName: true
|
2022-05-31 11:33:49 +03:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2022-05-30 19:05:17 +03:00
|
|
|
|
2022-05-20 17:50:35 +03:00
|
|
|
export interface BranchInfo {
|
|
|
|
|
name: string;
|
|
|
|
|
default: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface EntityVersion {
|
2022-05-25 12:26:23 +03:00
|
|
|
timestamp: number;
|
2022-05-20 17:50:35 +03:00
|
|
|
id: string;
|
|
|
|
|
name: string;
|
2022-05-31 13:09:47 +03:00
|
|
|
author: string;
|
2022-05-20 17:50:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface VersionCreationResult {
|
|
|
|
|
version: EntityVersion;
|
|
|
|
|
added: number;
|
|
|
|
|
modified: number;
|
|
|
|
|
removed: number;
|
|
|
|
|
}
|
2022-05-26 13:50:50 +03:00
|
|
|
|
2022-06-02 12:32:10 +03:00
|
|
|
export interface EntityTypeLoadResult {
|
2022-05-26 13:50:50 +03:00
|
|
|
entityType: EntityType;
|
|
|
|
|
created: number;
|
|
|
|
|
updated: number;
|
|
|
|
|
deleted: number;
|
|
|
|
|
}
|
2022-05-27 19:34:55 +03:00
|
|
|
|
2022-06-02 12:32:10 +03:00
|
|
|
export enum EntityLoadErrorType {
|
|
|
|
|
DEVICE_CREDENTIALS_CONFLICT = 'DEVICE_CREDENTIALS_CONFLICT',
|
|
|
|
|
MISSING_REFERENCED_ENTITY = 'MISSING_REFERENCED_ENTITY'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const entityLoadErrorTranslationMap = new Map<EntityLoadErrorType, string>(
|
|
|
|
|
[
|
|
|
|
|
[EntityLoadErrorType.DEVICE_CREDENTIALS_CONFLICT, 'version-control.device-credentials-conflict'],
|
|
|
|
|
[EntityLoadErrorType.MISSING_REFERENCED_ENTITY, 'version-control.missing-referenced-entity']
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export interface EntityLoadError {
|
|
|
|
|
type: EntityLoadErrorType;
|
|
|
|
|
source: EntityId;
|
|
|
|
|
target: EntityId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface VersionLoadResult {
|
|
|
|
|
result: Array<EntityTypeLoadResult>;
|
|
|
|
|
error: EntityLoadError;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 19:34:55 +03:00
|
|
|
export interface EntityExportData<E extends ExportableEntity<EntityId>> {
|
|
|
|
|
entity: E;
|
|
|
|
|
entityType: EntityType;
|
|
|
|
|
relations: Array<EntityRelation>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DeviceExportData extends EntityExportData<Device> {
|
|
|
|
|
credentials: DeviceCredentials;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RuleChainExportData extends EntityExportData<RuleChain> {
|
|
|
|
|
metaData: RuleChainMetaData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface EntityDataDiff {
|
|
|
|
|
currentVersion: EntityExportData<any>;
|
|
|
|
|
otherVersion: EntityExportData<any>;
|
|
|
|
|
rawDiff: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function entityExportDataToJsonString(data: EntityExportData<any>): string {
|
2022-05-31 16:16:24 +03:00
|
|
|
return JSON.stringify(data, null, 4);
|
2022-05-27 19:34:55 +03:00
|
|
|
}
|
2022-06-01 13:10:32 +03:00
|
|
|
|
|
|
|
|
export interface EntityDataInfo {
|
|
|
|
|
hasRelations: boolean;
|
|
|
|
|
hasAttributes: boolean;
|
2022-06-02 12:32:10 +03:00
|
|
|
hasCredentials: boolean;
|
2022-06-01 13:10:32 +03:00
|
|
|
}
|