Browse Source

Initial export/import API for devices, device profiles, assets, rule chains, dashboards and customers

pull/6357/head
Viacheslav Klimov 5 years ago
parent
commit
4062dc70fb
  1. 28
      application/src/main/data/upgrade/3.4/schema_update.sql
  2. 99
      application/src/main/java/org/thingsboard/server/controller/EntitiesExportImportController.java
  3. 86
      application/src/main/java/org/thingsboard/server/service/expimp/DefaultEntitiesExportImportService.java
  4. 29
      application/src/main/java/org/thingsboard/server/service/expimp/EntitiesExportImportService.java
  5. 32
      application/src/main/java/org/thingsboard/server/service/expimp/exp/EntityExportService.java
  6. 50
      application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/AssetExportService.java
  7. 50
      application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/CustomerExportService.java
  8. 50
      application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/DashboardExportService.java
  9. 53
      application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/DeviceExportService.java
  10. 50
      application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/DeviceProfileExportService.java
  11. 51
      application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/RuleChainExportService.java
  12. 30
      application/src/main/java/org/thingsboard/server/service/expimp/imp/EntityImportService.java
  13. 73
      application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/AbstractEntityImportService.java
  14. 62
      application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/AssetImportService.java
  15. 60
      application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/CustomerImportService.java
  16. 62
      application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/DashboardImportService.java
  17. 81
      application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/DeviceImportService.java
  18. 65
      application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/DeviceProfileImportService.java
  19. 80
      application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/RuleChainImportService.java
  20. 3
      common/dao-api/src/main/java/org/thingsboard/server/dao/rule/RuleChainService.java
  21. 6
      common/data/src/main/java/org/thingsboard/server/common/data/Customer.java
  22. 10
      common/data/src/main/java/org/thingsboard/server/common/data/Dashboard.java
  23. 7
      common/data/src/main/java/org/thingsboard/server/common/data/Device.java
  24. 3
      common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java
  25. 7
      common/data/src/main/java/org/thingsboard/server/common/data/asset/Asset.java
  26. 29
      common/data/src/main/java/org/thingsboard/server/common/data/export/EntitiesExportRequest.java
  27. 29
      common/data/src/main/java/org/thingsboard/server/common/data/export/EntitiesExportResponse.java
  28. 48
      common/data/src/main/java/org/thingsboard/server/common/data/export/EntityExportData.java
  29. 33
      common/data/src/main/java/org/thingsboard/server/common/data/export/impl/AssetExportData.java
  30. 33
      common/data/src/main/java/org/thingsboard/server/common/data/export/impl/CustomerExportData.java
  31. 33
      common/data/src/main/java/org/thingsboard/server/common/data/export/impl/DashboardExportData.java
  32. 35
      common/data/src/main/java/org/thingsboard/server/common/data/export/impl/DeviceExportData.java
  33. 33
      common/data/src/main/java/org/thingsboard/server/common/data/export/impl/DeviceProfileExportData.java
  34. 35
      common/data/src/main/java/org/thingsboard/server/common/data/export/impl/RuleChainExportData.java
  35. 3
      common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChain.java
  36. 36
      dao/src/main/java/org/thingsboard/server/dao/ExportableEntityDao.java
  37. 26
      dao/src/main/java/org/thingsboard/server/dao/ExportableEntityRepository.java
  38. 4
      dao/src/main/java/org/thingsboard/server/dao/asset/AssetDao.java
  39. 5
      dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDao.java
  40. 3
      dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardDao.java
  41. 3
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java
  42. 3
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileDao.java
  43. 2
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  44. 11
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractAssetEntity.java
  45. 10
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractDeviceEntity.java
  46. 9
      dao/src/main/java/org/thingsboard/server/dao/model/sql/CustomerEntity.java
  47. 9
      dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardEntity.java
  48. 9
      dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceProfileEntity.java
  49. 9
      dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleChainEntity.java
  50. 5
      dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java
  51. 7
      dao/src/main/java/org/thingsboard/server/dao/rule/RuleChainDao.java
  52. 3
      dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetRepository.java
  53. 16
      dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetDao.java
  54. 3
      dao/src/main/java/org/thingsboard/server/dao/sql/customer/CustomerRepository.java
  55. 17
      dao/src/main/java/org/thingsboard/server/dao/sql/customer/JpaCustomerDao.java
  56. 4
      dao/src/main/java/org/thingsboard/server/dao/sql/dashboard/DashboardRepository.java
  57. 18
      dao/src/main/java/org/thingsboard/server/dao/sql/dashboard/JpaDashboardDao.java
  58. 4
      dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java
  59. 3
      dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java
  60. 16
      dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java
  61. 17
      dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceProfileDao.java
  62. 16
      dao/src/main/java/org/thingsboard/server/dao/sql/rule/JpaRuleChainDao.java
  63. 3
      dao/src/main/java/org/thingsboard/server/dao/sql/rule/RuleChainRepository.java
  64. 188
      dao/src/main/resources/sql/schema-entities.sql

28
application/src/main/data/upgrade/3.4/schema_update.sql

@ -0,0 +1,28 @@
--
-- 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.
--
ALTER TABLE device
ADD COLUMN IF NOT EXISTS external_id UUID;
ALTER TABLE device_profile
ADD COLUMN IF NOT EXISTS external_id UUID;
ALTER TABLE asset
ADD COLUMN IF NOT EXISTS external_id UUID;
ALTER TABLE rule_chain
ADD COLUMN IF NOT EXISTS external_id UUID;
ALTER TABLE dashboard
ADD COLUMN IF NOT EXISTS external_id UUID;
ALTER TABLE customer
ADD COLUMN IF NOT EXISTS external_id UUID;

99
application/src/main/java/org/thingsboard/server/controller/EntitiesExportImportController.java

@ -0,0 +1,99 @@
/**
* 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.
*/
package org.thingsboard.server.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.export.EntitiesExportRequest;
import org.thingsboard.server.common.data.export.EntitiesExportResponse;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityIdFactory;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.EntitiesExportImportService;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping("/api/entities")
@TbCoreComponent
@RequiredArgsConstructor
public class EntitiesExportImportController extends BaseController {
private final EntitiesExportImportService exportImportService;
@PostMapping("/export/{entityType}/{entityId}")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
public EntityExportData<?> exportEntity(@PathVariable EntityType entityType,
@PathVariable("entityId") UUID entityUuid) throws ThingsboardException {
EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, entityUuid);
try {
return exportImportService.exportEntity(getTenantId(), entityId);
} catch (Exception e) {
throw handleException(e);
}
}
@PostMapping("/export/batch")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
public EntitiesExportResponse exportEntities(@RequestBody EntitiesExportRequest exportRequest) throws ThingsboardException {
TenantId tenantId = getTenantId();
EntitiesExportResponse exportResponse = new EntitiesExportResponse();
Map<EntityType, List<EntityExportData<HasId<EntityId>>>> result = new HashMap<>();
exportRequest.getEntities().forEach((entityType, entityIds) -> {
List<EntityExportData<HasId<EntityId>>> exportDataForEntityType = new LinkedList<>();
entityIds.forEach(entityId -> {
EntityExportData<HasId<EntityId>> exportData = exportImportService.exportEntity(tenantId, entityId);
exportDataForEntityType.add(exportData);
});
result.put(entityType, exportDataForEntityType);
});
exportResponse.setExportData(result);
return exportResponse;
}
// TODO: api to export and import whole customer, whole tenant
@PostMapping("/import")
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
public <E extends HasId<I>, I extends EntityId, D extends EntityExportData<E>> E importEntity(@RequestBody D exportData) throws ThingsboardException {
try {
return exportImportService.importEntity(getTenantId(), exportData);
} catch (Exception e) {
throw handleException(e);
}
}
// public void importEntities(@RequestBody )
}

86
application/src/main/java/org/thingsboard/server/service/expimp/DefaultEntitiesExportImportService.java

@ -0,0 +1,86 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.exp.EntityExportService;
import org.thingsboard.server.service.expimp.imp.EntityImportService;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Map;
// FIXME: review packages and classes naming
@Service
@TbCoreComponent
public class DefaultEntitiesExportImportService implements EntitiesExportImportService {
private final Map<EntityType, EntityExportService<?, ?>> exportServices = new EnumMap<>(EntityType.class);
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new EnumMap<>(EntityType.class);
// TODO: export and import of the whole tenant
// TODO: export and import of the whole customer ?
// TODO: relations export and import
@Override
public <E extends HasId<I>, I extends EntityId> EntityExportData<E> exportEntity(TenantId tenantId, I entityId) {
EntityType entityType = entityId.getEntityType();
EntityExportService<I, E> exportService = getExportService(entityType);
return exportService.getExportData(tenantId, entityId);
}
// FIXME: somehow validate export data
// FIXME: validate permissions for create or update
// FIXME: send entity lifecycle event
@Override
public <E extends HasId<I>, I extends EntityId, D extends EntityExportData<E>> E importEntity(TenantId tenantId, D exportData) {
EntityType entityType = exportData.getEntityType();
EntityImportService<I, E, D> importService = getImportService(entityType);
return importService.importEntity(tenantId, exportData);
}
@SuppressWarnings("unchecked")
private <I extends EntityId, E extends HasId<I>> EntityExportService<I, E> getExportService(EntityType entityType) {
return (EntityExportService<I, E>) exportServices.get(entityType);
}
@SuppressWarnings("unchecked")
private <I extends EntityId, E extends HasId<I>, D extends EntityExportData<E>> EntityImportService<I, E, D> getImportService(EntityType entityType) {
return (EntityImportService<I, E, D>) importServices.get(entityType);
}
@Autowired
private void setExportImportServices(Collection<EntityExportService<?, ?>> exportServices,
Collection<EntityImportService<?, ?, ?>> importServices) {
exportServices.forEach(entityExportService -> {
this.exportServices.put(entityExportService.getEntityType(), entityExportService);
});
importServices.forEach(entityImportService -> {
this.importServices.put(entityImportService.getEntityType(), entityImportService);
});
}
}

29
application/src/main/java/org/thingsboard/server/service/expimp/EntitiesExportImportService.java

@ -0,0 +1,29 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
public interface EntitiesExportImportService {
<E extends HasId<I>, I extends EntityId> EntityExportData<E> exportEntity(TenantId tenantId, I entityId);
<E extends HasId<I>, I extends EntityId, D extends EntityExportData<E>> E importEntity(TenantId tenantId, D exportData);
}

32
application/src/main/java/org/thingsboard/server/service/expimp/exp/EntityExportService.java

@ -0,0 +1,32 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.exp;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
public interface EntityExportService<I extends EntityId, E extends HasId<I>> {
// FIXME: export relations
// FIXME: get rid of boilerplate
EntityExportData<E> getExportData(TenantId tenantId, I entityId);
EntityType getEntityType();
}

50
application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/AssetExportService.java

@ -0,0 +1,50 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.exp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.export.impl.AssetExportData;
import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.exp.EntityExportService;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class AssetExportService implements EntityExportService<AssetId, Asset> {
private final AssetService assetService;
@Override
public EntityExportData<Asset> getExportData(TenantId tenantId, AssetId assetId) {
AssetExportData exportData = new AssetExportData();
exportData.setAsset(assetService.findAssetById(tenantId, assetId));
return exportData;
}
@Override
public EntityType getEntityType() {
return EntityType.ASSET;
}
}

50
application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/CustomerExportService.java

@ -0,0 +1,50 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.exp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.export.impl.CustomerExportData;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.exp.EntityExportService;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class CustomerExportService implements EntityExportService<CustomerId, Customer> {
private final CustomerService customerService;
@Override
public EntityExportData<Customer> getExportData(TenantId tenantId, CustomerId customerId) {
CustomerExportData exportData = new CustomerExportData();
exportData.setCustomer(customerService.findCustomerById(tenantId, customerId));
return exportData;
}
@Override
public EntityType getEntityType() {
return EntityType.CUSTOMER;
}
}

50
application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/DashboardExportService.java

@ -0,0 +1,50 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.exp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.export.impl.DashboardExportData;
import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.exp.EntityExportService;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DashboardExportService implements EntityExportService<DashboardId, Dashboard> {
private final DashboardService dashboardService;
@Override
public EntityExportData<Dashboard> getExportData(TenantId tenantId, DashboardId dashboardId) {
DashboardExportData exportData = new DashboardExportData();
exportData.setDashboard(dashboardService.findDashboardById(tenantId, dashboardId));
return exportData;
}
@Override
public EntityType getEntityType() {
return EntityType.DASHBOARD;
}
}

53
application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/DeviceExportService.java

@ -0,0 +1,53 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.exp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.export.impl.DeviceExportData;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.exp.EntityExportService;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DeviceExportService implements EntityExportService<DeviceId, Device> {
private final DeviceService deviceService;
private final DeviceCredentialsService deviceCredentialsService;
@Override
public EntityExportData<Device> getExportData(TenantId tenantId, DeviceId deviceId) {
DeviceExportData exportData = new DeviceExportData();
exportData.setDevice(deviceService.findDeviceById(tenantId, deviceId));
exportData.setCredentials(deviceCredentialsService.findDeviceCredentialsByDeviceId(TenantId.SYS_TENANT_ID, deviceId));
return exportData;
}
@Override
public EntityType getEntityType() {
return EntityType.DEVICE;
}
}

50
application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/DeviceProfileExportService.java

@ -0,0 +1,50 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.exp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.export.impl.DeviceProfileExportData;
import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.exp.EntityExportService;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DeviceProfileExportService implements EntityExportService<DeviceProfileId, DeviceProfile> {
private final DeviceProfileService deviceProfileService;
@Override
public EntityExportData<DeviceProfile> getExportData(TenantId tenantId, DeviceProfileId deviceProfileId) {
DeviceProfileExportData exportData = new DeviceProfileExportData();
exportData.setDeviceProfile(deviceProfileService.findDeviceProfileById(tenantId, deviceProfileId));
return exportData;
}
@Override
public EntityType getEntityType() {
return EntityType.DEVICE_PROFILE;
}
}

51
application/src/main/java/org/thingsboard/server/service/expimp/exp/impl/RuleChainExportService.java

@ -0,0 +1,51 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.exp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.export.impl.RuleChainExportData;
import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.expimp.exp.EntityExportService;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class RuleChainExportService implements EntityExportService<RuleChainId, RuleChain> {
private final RuleChainService ruleChainService;
@Override
public EntityExportData<RuleChain> getExportData(TenantId tenantId, RuleChainId ruleChainId) {
RuleChainExportData exportData = new RuleChainExportData();
exportData.setRuleChain(ruleChainService.findRuleChainById(tenantId, ruleChainId));
exportData.setMetaData(ruleChainService.loadRuleChainMetaData(tenantId, ruleChainId));
return exportData;
}
@Override
public EntityType getEntityType() {
return EntityType.RULE_CHAIN;
}
}

30
application/src/main/java/org/thingsboard/server/service/expimp/imp/EntityImportService.java

@ -0,0 +1,30 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
public interface EntityImportService<I extends EntityId, E extends HasId<I>, D extends EntityExportData<E>> {
E importEntity(TenantId tenantId, D exportData);
EntityType getEntityType();
}

73
application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/AbstractEntityImportService.java

@ -0,0 +1,73 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.ExportableEntityDao;
import org.thingsboard.server.service.expimp.imp.EntityImportService;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
public abstract class AbstractEntityImportService<I extends EntityId, E extends HasId<I>, D extends EntityExportData<E>> implements EntityImportService<I, E, D> {
private final Map<EntityType, ExportableEntityDao<?>> daos = new EnumMap<>(EntityType.class);
public final E findByExternalId(TenantId tenantId, I externalId) {
return findByExternalOrInternalId(tenantId, externalId);
}
protected final <ID extends EntityId> ID getInternalId(TenantId tenantId, ID externalId) {
if (externalId == null) {
return null;
}
HasId<ID> entity = findByExternalOrInternalId(tenantId, externalId);
if (entity == null) {
throw new IllegalStateException("Cannot find " + externalId.getEntityType() + " by external id " + externalId);
}
return entity.getId();
}
private <T extends HasId<ID>, ID extends EntityId> T findByExternalOrInternalId(TenantId tenantId, ID externalOrInternalId) {
ExportableEntityDao<T> dao = getDao(externalOrInternalId.getEntityType());
return Optional.ofNullable(dao.findByTenantIdAndExternalId(tenantId.getId(), externalOrInternalId.getId()))
.orElseGet(() -> dao.findByTenantIdAndId(tenantId.getId(), externalOrInternalId.getId()));
}
@SuppressWarnings("unchecked")
private <T> ExportableEntityDao<T> getDao(EntityType entityType) {
return (ExportableEntityDao<T>) daos.get(entityType);
}
@Autowired
private void setDaos(Collection<ExportableEntityDao<?>> daos) {
daos.forEach(dao -> this.daos.put(dao.getEntityType(), dao));
if (!this.daos.containsKey(getEntityType())) {
throw new IllegalStateException(getClass().getSimpleName() + " requires ExportableEntityDao for entity type " + getEntityType());
}
}
}

62
application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/AssetImportService.java

@ -0,0 +1,62 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.export.impl.AssetExportData;
import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.queue.util.TbCoreComponent;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class AssetImportService extends AbstractEntityImportService<AssetId, Asset, AssetExportData> {
private final AssetService assetService;
@Override
public Asset importEntity(TenantId tenantId, AssetExportData exportData) {
Asset asset = exportData.getAsset();
Asset existingAsset = findByExternalId(tenantId, asset.getId()); // TODO: extract boiler plate to abstract class ...
asset.setExternalId(asset.getId());
asset.setTenantId(tenantId);
if (existingAsset == null) {
asset.setId(null);
} else {
asset.setId(existingAsset.getId());
}
asset.setCustomerId(getInternalId(tenantId, asset.getCustomerId()));
Asset savedAsset = assetService.saveAsset(asset);
return savedAsset;
}
@Override
public EntityType getEntityType() {
return EntityType.ASSET;
}
}

60
application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/CustomerImportService.java

@ -0,0 +1,60 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.impl.CustomerExportData;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.queue.util.TbCoreComponent;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class CustomerImportService extends AbstractEntityImportService<CustomerId, Customer, CustomerExportData> {
private final CustomerService customerService;
@Override
public Customer importEntity(TenantId tenantId, CustomerExportData exportData) {
Customer customer = exportData.getCustomer();
Customer existingCustomer = findByExternalId(tenantId, customer.getId());
customer.setExternalId(customer.getId());
customer.setTenantId(tenantId);
if (existingCustomer == null) {
customer.setId(null);
} else {
customer.setId(existingCustomer.getId());
}
Customer savedCustomer = customerService.saveCustomer(customer);
return savedCustomer;
}
@Override
public EntityType getEntityType() {
return EntityType.CUSTOMER;
}
}

62
application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/DashboardImportService.java

@ -0,0 +1,62 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.impl.DashboardExportData;
import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.queue.util.TbCoreComponent;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DashboardImportService extends AbstractEntityImportService<DashboardId, Dashboard, DashboardExportData> {
private final DashboardService dashboardService;
@Override
public Dashboard importEntity(TenantId tenantId, DashboardExportData exportData) {
Dashboard dashboard = exportData.getDashboard();
Dashboard existingDashboard = findByExternalId(tenantId, dashboard.getId());
dashboard.setExternalId(dashboard.getId());
dashboard.setTenantId(tenantId);
if (existingDashboard == null) {
dashboard.setId(null);
dashboard.setAssignedCustomers(null); // FIXME: need to assign dashboard to customers ?
} else {
dashboard.setId(existingDashboard.getId());
dashboard.setAssignedCustomers(existingDashboard.getAssignedCustomers()); // we left them untouched (FIXME)
}
Dashboard savedDashboard = dashboardService.saveDashboard(dashboard);
return savedDashboard;
}
@Override
public EntityType getEntityType() {
return EntityType.DASHBOARD;
}
}

81
application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/DeviceImportService.java

@ -0,0 +1,81 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thingsboard.server.cluster.TbClusterService;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.impl.DeviceExportData;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.action.EntityActionService;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DeviceImportService extends AbstractEntityImportService<DeviceId, Device, DeviceExportData> {
private final DeviceService deviceService;
@Transactional
@Override
public Device importEntity(TenantId tenantId, DeviceExportData exportData) {
Device device = exportData.getDevice();
Device existingDevice = findByExternalId(tenantId, device.getId()); // FIXME: !!!
// what if exporting and importing back already exported entity ? (save version and then load it back)
/*
* export entity -> id from env1 -> import this entity -> ...
*
* maybe find not only by external id but by internal too ? but then what if we will try
* */
device.setExternalId(device.getId());
device.setTenantId(tenantId);
if (existingDevice == null) {
device.setId(null);
device.setCustomerId(null); // FIXME: find and set customer
} else {
device.setId(existingDevice.getId());
device.setCustomerId(existingDevice.getCustomerId());
}
// TODO or maybe set as additional config whether to update related entities when device already exists ?
// TODO: or also whether to ignore not found internal ids
// FIXME: review use cases for version controlling: in the same tenant, between tenants, between environments and different tenants
device.setDeviceProfileId(getInternalId(tenantId, device.getDeviceProfileId()));
device.setFirmwareId(getInternalId(tenantId, device.getFirmwareId()));
device.setSoftwareId(getInternalId(tenantId, device.getSoftwareId()));
Device savedDevice = deviceService.saveDeviceWithCredentials(device, exportData.getCredentials());
return savedDevice;
}
@Override
public EntityType getEntityType() {
return EntityType.DEVICE;
}
}

65
application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/DeviceProfileImportService.java

@ -0,0 +1,65 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.impl.DeviceProfileExportData;
import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.queue.util.TbCoreComponent;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DeviceProfileImportService extends AbstractEntityImportService<DeviceProfileId, DeviceProfile, DeviceProfileExportData> {
private final DeviceProfileService deviceProfileService;
@Override
public DeviceProfile importEntity(TenantId tenantId, DeviceProfileExportData exportData) {
DeviceProfile deviceProfile = exportData.getDeviceProfile();
DeviceProfile existingDeviceProfile = findByExternalId(tenantId, deviceProfile.getId());
deviceProfile.setExternalId(deviceProfile.getId());
deviceProfile.setTenantId(tenantId);
if (existingDeviceProfile == null) {
deviceProfile.setId(null);
} else {
deviceProfile.setId(existingDeviceProfile.getId());
}
deviceProfile.setDefaultRuleChainId(getInternalId(tenantId, deviceProfile.getDefaultRuleChainId()));
deviceProfile.setDefaultDashboardId(getInternalId(tenantId, deviceProfile.getDefaultDashboardId()));
deviceProfile.setFirmwareId(getInternalId(tenantId, deviceProfile.getFirmwareId()));
deviceProfile.setSoftwareId(getInternalId(tenantId, deviceProfile.getSoftwareId()));
DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
return savedDeviceProfile;
}
@Override
public EntityType getEntityType() {
return EntityType.DEVICE_PROFILE;
}
}

80
application/src/main/java/org/thingsboard/server/service/expimp/imp/impl/RuleChainImportService.java

@ -0,0 +1,80 @@
/**
* 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.
*/
package org.thingsboard.server.service.expimp.imp.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.impl.RuleChainExportData;
import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainMetaData;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.queue.util.TbCoreComponent;
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class RuleChainImportService extends AbstractEntityImportService<RuleChainId, RuleChain, RuleChainExportData> {
private final RuleChainService ruleChainService;
@Transactional
@Override
public RuleChain importEntity(TenantId tenantId, RuleChainExportData exportData) {
RuleChain ruleChain = exportData.getRuleChain();
RuleChain existingRuleChain = findByExternalId(tenantId, ruleChain.getId());
ruleChain.setExternalId(ruleChain.getId());
ruleChain.setTenantId(tenantId);
ruleChain.setFirstRuleNodeId(null); // will be set during metadata persisting
if (existingRuleChain == null) {
ruleChain.setId(null);
} else {
ruleChain.setId(existingRuleChain.getId());
}
RuleChain savedRuleChain = ruleChainService.saveRuleChain(ruleChain);
if (ruleChain.getId() != null) {
ruleChainService.deleteRuleNodes(tenantId, ruleChain.getId());
}
RuleChainMetaData metaData = exportData.getMetaData();
metaData.setRuleChainId(savedRuleChain.getId());
metaData.getNodes().forEach(ruleNode -> {
ruleNode.setId(null);
ruleNode.setRuleChainId(null);
});
metaData.getRuleChainConnections().forEach(ruleChainConnectionInfo -> {
// ruleChainConnectionInfo.setTargetRuleChainId();
// TODO: check if this thing is needed for "Other Rule Chain Node"
// TODO: and check import of tenant rule chains
});
ruleChainService.saveRuleChainMetaData(tenantId, metaData);
return savedRuleChain;
}
@Override
public EntityType getEntityType() {
return EntityType.RULE_CHAIN;
}
}

3
common/dao-api/src/main/java/org/thingsboard/server/dao/rule/RuleChainService.java

@ -28,7 +28,6 @@ import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainData;
import org.thingsboard.server.common.data.rule.RuleChainImportResult;
import org.thingsboard.server.common.data.rule.RuleChainMetaData;
import org.thingsboard.server.common.data.rule.RuleChainOutputLabelsUsage;
import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.common.data.rule.RuleChainUpdateResult;
import org.thingsboard.server.common.data.rule.RuleNode;
@ -93,4 +92,6 @@ public interface RuleChainService {
List<RuleNode> findRuleNodesByTenantIdAndType(TenantId tenantId, String name, String toString);
RuleNode saveRuleNode(TenantId tenantId, RuleNode ruleNode);
void deleteRuleNodes(TenantId tenantId, RuleChainId ruleChainId);
}

6
common/data/src/main/java/org/thingsboard/server/common/data/Customer.java

@ -20,6 +20,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.validation.Length;
@ -36,6 +38,9 @@ public class Customer extends ContactBased<CustomerId> implements HasTenantId {
@ApiModelProperty(position = 5, required = true, value = "JSON object with Tenant Id")
private TenantId tenantId;
@Getter @Setter
private CustomerId externalId; // FIXME: add to hashcode, equals, etc
public Customer() {
super();
}
@ -48,6 +53,7 @@ public class Customer extends ContactBased<CustomerId> implements HasTenantId {
super(customer);
this.tenantId = customer.getTenantId();
this.title = customer.getTitle();
this.externalId = customer.getExternalId();
}
public TenantId getTenantId() {

10
common/data/src/main/java/org/thingsboard/server/common/data/Dashboard.java

@ -17,14 +17,19 @@ package org.thingsboard.server.common.data;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.thingsboard.server.common.data.id.DashboardId;
public class Dashboard extends DashboardInfo {
private static final long serialVersionUID = 872682138346187503L;
private transient JsonNode configuration;
@Getter @Setter
private DashboardId externalId;
public Dashboard() {
super();
}
@ -40,6 +45,7 @@ public class Dashboard extends DashboardInfo {
public Dashboard(Dashboard dashboard) {
super(dashboard);
this.configuration = dashboard.getConfiguration();
this.externalId = dashboard.getExternalId();
}
@ApiModelProperty(position = 9, value = "JSON object with main configuration of the dashboard: layouts, widgets, aliases, etc. " +

7
common/data/src/main/java/org/thingsboard/server/common/data/Device.java

@ -21,6 +21,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.thingsboard.server.common.data.device.data.DeviceData;
import org.thingsboard.server.common.data.id.CustomerId;
@ -61,6 +63,9 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
private OtaPackageId firmwareId;
private OtaPackageId softwareId;
@Getter @Setter
private DeviceId externalId;
public Device() {
super();
}
@ -80,6 +85,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
this.setDeviceData(device.getDeviceData());
this.firmwareId = device.getFirmwareId();
this.softwareId = device.getSoftwareId();
this.externalId = device.getExternalId();
}
public Device updateDevice(Device device) {
@ -93,6 +99,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
this.setFirmwareId(device.getFirmwareId());
this.setSoftwareId(device.getSoftwareId());
Optional.ofNullable(device.getAdditionalInfo()).ifPresent(this::setAdditionalInfo);
this.setExternalId(device.getExternalId());
return this;
}

3
common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java

@ -90,6 +90,8 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H
@ApiModelProperty(position = 10, value = "Reference to the software OTA package. If present, the specified package will be used as default device software. ")
private OtaPackageId softwareId;
private DeviceProfileId externalId;
public DeviceProfile() {
super();
}
@ -112,6 +114,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H
this.provisionDeviceKey = deviceProfile.getProvisionDeviceKey();
this.firmwareId = deviceProfile.getFirmwareId();
this.softwareId = deviceProfile.getSoftwareId();
this.externalId = deviceProfile.getExternalId();
}
@ApiModelProperty(position = 1, value = "JSON object with the device profile Id. " +

7
common/data/src/main/java/org/thingsboard/server/common/data/asset/Asset.java

@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.thingsboard.server.common.data.HasCustomerId;
import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.HasTenantId;
@ -49,6 +51,9 @@ public class Asset extends SearchTextBasedWithAdditionalInfo<AssetId> implements
@Length(fieldName = "label")
private String label;
@Getter @Setter
private AssetId externalId;
public Asset() {
super();
}
@ -64,6 +69,7 @@ public class Asset extends SearchTextBasedWithAdditionalInfo<AssetId> implements
this.name = asset.getName();
this.type = asset.getType();
this.label = asset.getLabel();
this.externalId = asset.getExternalId();
}
public void update(Asset asset) {
@ -73,6 +79,7 @@ public class Asset extends SearchTextBasedWithAdditionalInfo<AssetId> implements
this.type = asset.getType();
this.label = asset.getLabel();
Optional.ofNullable(asset.getAdditionalInfo()).ifPresent(this::setAdditionalInfo);
this.externalId = asset.getExternalId();
}
@ApiModelProperty(position = 1, value = "JSON object with the asset Id. " +

29
common/data/src/main/java/org/thingsboard/server/common/data/export/EntitiesExportRequest.java

@ -0,0 +1,29 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export;
import lombok.Data;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.EntityId;
import java.util.List;
import java.util.Map;
@Data
public class EntitiesExportRequest {
// todo: should be processed in a specific order, e.g. device profiles, then devices, then relations, etc.
private Map<EntityType, List<EntityId>> entities;
}

29
common/data/src/main/java/org/thingsboard/server/common/data/export/EntitiesExportResponse.java

@ -0,0 +1,29 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export;
import lombok.Data;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import java.util.List;
import java.util.Map;
@Data
public class EntitiesExportResponse {
private Map<EntityType, List<EntityExportData<HasId<EntityId>>>> exportData;
}

48
common/data/src/main/java/org/thingsboard/server/common/data/export/EntityExportData.java

@ -0,0 +1,48 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.impl.AssetExportData;
import org.thingsboard.server.common.data.export.impl.CustomerExportData;
import org.thingsboard.server.common.data.export.impl.DashboardExportData;
import org.thingsboard.server.common.data.export.impl.DeviceExportData;
import org.thingsboard.server.common.data.export.impl.DeviceProfileExportData;
import org.thingsboard.server.common.data.export.impl.RuleChainExportData;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(property = "entityType", use = JsonTypeInfo.Id.NAME)
@JsonSubTypes({
@Type(name = "DEVICE", value = DeviceExportData.class),
@Type(name = "DEVICE_PROFILE", value = DeviceProfileExportData.class),
@Type(name = "ASSET", value = AssetExportData.class),
@Type(name = "RULE_CHAIN", value = RuleChainExportData.class),
@Type(name = "DASHBOARD", value = DashboardExportData.class),
@Type(name = "CUSTOMER", value = CustomerExportData.class)
})
public interface EntityExportData<E extends HasId<? extends EntityId>> {
@JsonIgnore
EntityType getEntityType(); // fixme: maybe remove if not needed, as well as generic
}

33
common/data/src/main/java/org/thingsboard/server/common/data/export/impl/AssetExportData.java

@ -0,0 +1,33 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export.impl;
import lombok.Data;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.export.EntityExportData;
@Data
public class AssetExportData implements EntityExportData<Asset> {
private Asset asset;
@Override
public EntityType getEntityType() {
return EntityType.ASSET;
}
}

33
common/data/src/main/java/org/thingsboard/server/common/data/export/impl/CustomerExportData.java

@ -0,0 +1,33 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export.impl;
import lombok.Data;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
@Data
public class CustomerExportData implements EntityExportData<Customer> {
private Customer customer;
@Override
public EntityType getEntityType() {
return EntityType.CUSTOMER;
}
}

33
common/data/src/main/java/org/thingsboard/server/common/data/export/impl/DashboardExportData.java

@ -0,0 +1,33 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export.impl;
import lombok.Data;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
@Data
public class DashboardExportData implements EntityExportData<Dashboard> {
private Dashboard dashboard;
@Override
public EntityType getEntityType() {
return EntityType.DASHBOARD;
}
}

35
common/data/src/main/java/org/thingsboard/server/common/data/export/impl/DeviceExportData.java

@ -0,0 +1,35 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export.impl;
import lombok.Data;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.security.DeviceCredentials;
@Data
public class DeviceExportData implements EntityExportData<Device> {
private Device device;
private DeviceCredentials credentials;
@Override
public EntityType getEntityType() {
return EntityType.DEVICE;
}
}

33
common/data/src/main/java/org/thingsboard/server/common/data/export/impl/DeviceProfileExportData.java

@ -0,0 +1,33 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export.impl;
import lombok.Data;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
@Data
public class DeviceProfileExportData implements EntityExportData<DeviceProfile> {
private DeviceProfile deviceProfile;
@Override
public EntityType getEntityType() {
return EntityType.DEVICE_PROFILE;
}
}

35
common/data/src/main/java/org/thingsboard/server/common/data/export/impl/RuleChainExportData.java

@ -0,0 +1,35 @@
/**
* 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.
*/
package org.thingsboard.server.common.data.export.impl;
import lombok.Data;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.export.EntityExportData;
import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainMetaData;
@Data
public class RuleChainExportData implements EntityExportData<RuleChain> {
private RuleChain ruleChain;
private RuleChainMetaData metaData;
@Override
public EntityType getEntityType() {
return EntityType.RULE_CHAIN;
}
}

3
common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChain.java

@ -59,6 +59,8 @@ public class RuleChain extends SearchTextBasedWithAdditionalInfo<RuleChainId> im
@JsonIgnore
private byte[] configurationBytes;
private RuleChainId externalId;
public RuleChain() {
super();
}
@ -75,6 +77,7 @@ public class RuleChain extends SearchTextBasedWithAdditionalInfo<RuleChainId> im
this.firstRuleNodeId = ruleChain.getFirstRuleNodeId();
this.root = ruleChain.isRoot();
this.setConfiguration(ruleChain.getConfiguration());
this.setExternalId(ruleChain.getExternalId());
}
@Override

36
dao/src/main/java/org/thingsboard/server/dao/ExportableEntityDao.java

@ -0,0 +1,36 @@
/**
* 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.
*/
package org.thingsboard.server.dao;
import org.thingsboard.server.common.data.EntityType;
import java.util.UUID;
public interface ExportableEntityDao<T> {
T findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
T findByTenantIdAndId(UUID tenantId, UUID id);
// fixme: get rid of boilerplate ?
EntityType getEntityType();
/*
* default <D extends BaseEntity<T>> ExportableEntityRepository<D> getExportableEntityRepository() {
* ((ExportableEntityRepository) getJpaRepository).find...
* */
}

26
dao/src/main/java/org/thingsboard/server/dao/ExportableEntityRepository.java

@ -0,0 +1,26 @@
/**
* 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.
*/
package org.thingsboard.server.dao;
import java.util.UUID;
public interface ExportableEntityRepository<D> {
D findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
D findByTenantIdAndId(UUID tenantId, UUID id);
}

4
dao/src/main/java/org/thingsboard/server/dao/asset/AssetDao.java

@ -22,8 +22,8 @@ import org.thingsboard.server.common.data.asset.AssetInfo;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.dao.Dao;
import org.thingsboard.server.dao.ExportableEntityDao;
import org.thingsboard.server.dao.TenantEntityDao;
import java.util.List;
@ -34,7 +34,7 @@ import java.util.UUID;
* The Interface AssetDao.
*
*/
public interface AssetDao extends Dao<Asset>, TenantEntityDao {
public interface AssetDao extends Dao<Asset>, TenantEntityDao, ExportableEntityDao<Asset> {
/**
* Find asset info by id.

5
dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDao.java

@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.Dao;
import org.thingsboard.server.dao.ExportableEntityDao;
import org.thingsboard.server.dao.TenantEntityDao;
import java.util.Optional;
@ -28,7 +29,7 @@ import java.util.UUID;
/**
* The Interface CustomerDao.
*/
public interface CustomerDao extends Dao<Customer>, TenantEntityDao {
public interface CustomerDao extends Dao<Customer>, TenantEntityDao, ExportableEntityDao<Customer> {
/**
* Save or update customer object
@ -37,7 +38,7 @@ public interface CustomerDao extends Dao<Customer>, TenantEntityDao {
* @return saved customer object
*/
Customer save(TenantId tenantId, Customer customer);
/**
* Find customers by tenant id and page link.
*

3
dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardDao.java

@ -18,12 +18,13 @@ package org.thingsboard.server.dao.dashboard;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.Dao;
import org.thingsboard.server.dao.ExportableEntityDao;
import org.thingsboard.server.dao.TenantEntityDao;
/**
* The Interface DashboardDao.
*/
public interface DashboardDao extends Dao<Dashboard>, TenantEntityDao {
public interface DashboardDao extends Dao<Dashboard>, TenantEntityDao, ExportableEntityDao<Dashboard> {
/**
* Save or update dashboard object

3
dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java

@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.ota.OtaPackageType;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.Dao;
import org.thingsboard.server.dao.ExportableEntityDao;
import org.thingsboard.server.dao.TenantEntityDao;
import java.util.List;
@ -35,7 +36,7 @@ import java.util.UUID;
* The Interface DeviceDao.
*
*/
public interface DeviceDao extends Dao<Device>, TenantEntityDao {
public interface DeviceDao extends Dao<Device>, TenantEntityDao, ExportableEntityDao<Device> {
/**
* Find device info by id.

3
dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileDao.java

@ -21,10 +21,11 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.Dao;
import org.thingsboard.server.dao.ExportableEntityDao;
import java.util.UUID;
public interface DeviceProfileDao extends Dao<DeviceProfile> {
public interface DeviceProfileDao extends Dao<DeviceProfile>, ExportableEntityDao<DeviceProfile> {
DeviceProfileInfo findDeviceProfileInfoById(TenantId tenantId, UUID deviceProfileId);

2
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -559,6 +559,8 @@ public class ModelConstants {
public static final String EDGE_EVENT_BY_ID_VIEW_NAME = "edge_event_by_id";
public static final String EXTERNAL_ID_PROPERTY = "external_id";
/**
* Cassandra attributes and timeseries constants.
*/

11
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractAssetEntity.java

@ -38,6 +38,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ASSET_LABEL_PROPER
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_NAME_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TENANT_ID_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TYPE_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.EXTERNAL_ID_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;
@Data
@ -68,6 +69,9 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
@Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY)
private JsonNode additionalInfo;
@Column(name = EXTERNAL_ID_PROPERTY)
private UUID externalId;
public AbstractAssetEntity() {
super();
}
@ -87,6 +91,9 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
this.type = asset.getType();
this.label = asset.getLabel();
this.additionalInfo = asset.getAdditionalInfo();
if (asset.getExternalId() != null) {
this.externalId = asset.getExternalId().getId();
}
}
public AbstractAssetEntity(AssetEntity assetEntity) {
@ -99,6 +106,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
this.label = assetEntity.getLabel();
this.searchText = assetEntity.getSearchText();
this.additionalInfo = assetEntity.getAdditionalInfo();
this.externalId = assetEntity.getExternalId();
}
@Override
@ -128,6 +136,9 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
asset.setType(type);
asset.setLabel(label);
asset.setAdditionalInfo(additionalInfo);
if (externalId != null) {
asset.setExternalId(new AssetId(externalId));
}
return asset;
}

10
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractDeviceEntity.java

@ -84,6 +84,9 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
@Column(name = ModelConstants.DEVICE_DEVICE_DATA_PROPERTY, columnDefinition = "jsonb")
private JsonNode deviceData;
@Column(name = ModelConstants.EXTERNAL_ID_PROPERTY, columnDefinition = "uuid")
private UUID externalId;
public AbstractDeviceEntity() {
super();
}
@ -113,6 +116,9 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
this.type = device.getType();
this.label = device.getLabel();
this.additionalInfo = device.getAdditionalInfo();
if (device.getExternalId() != null) {
this.externalId = device.getExternalId().getId();
}
}
public AbstractDeviceEntity(DeviceEntity deviceEntity) {
@ -129,6 +135,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
this.additionalInfo = deviceEntity.getAdditionalInfo();
this.firmwareId = deviceEntity.getFirmwareId();
this.softwareId = deviceEntity.getSoftwareId();
this.externalId = deviceEntity.getExternalId();
}
@Override
@ -164,6 +171,9 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
device.setType(type);
device.setLabel(label);
device.setAdditionalInfo(additionalInfo);
if (externalId != null) {
device.setExternalId(new DeviceId(externalId));
}
return device;
}

9
dao/src/main/java/org/thingsboard/server/dao/model/sql/CustomerEntity.java

@ -77,6 +77,9 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
@Column(name = ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY)
private JsonNode additionalInfo;
@Column(name = ModelConstants.EXTERNAL_ID_PROPERTY)
private UUID externalId;
public CustomerEntity() {
super();
}
@ -97,6 +100,9 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
this.phone = customer.getPhone();
this.email = customer.getEmail();
this.additionalInfo = customer.getAdditionalInfo();
if (customer.getExternalId() != null) {
this.externalId = customer.getExternalId().getId();
}
}
@Override
@ -124,6 +130,9 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
customer.setPhone(phone);
customer.setEmail(email);
customer.setAdditionalInfo(additionalInfo);
if (externalId != null) {
customer.setExternalId(new CustomerId(externalId));
}
return customer;
}

9
dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardEntity.java

@ -78,6 +78,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
@Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY)
private JsonNode configuration;
@Column(name = ModelConstants.EXTERNAL_ID_PROPERTY)
private UUID externalId;
public DashboardEntity() {
super();
}
@ -102,6 +105,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
this.mobileHide = dashboard.isMobileHide();
this.mobileOrder = dashboard.getMobileOrder();
this.configuration = dashboard.getConfiguration();
if (dashboard.getExternalId() != null) {
this.externalId = dashboard.getExternalId().getId();
}
}
@Override
@ -133,6 +139,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
dashboard.setMobileHide(mobileHide);
dashboard.setMobileOrder(mobileOrder);
dashboard.setConfiguration(configuration);
if (externalId != null) {
dashboard.setExternalId(new DashboardId(externalId));
}
return dashboard;
}
}

9
dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceProfileEntity.java

@ -103,6 +103,9 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl
@Column(name = ModelConstants.DEVICE_PROFILE_SOFTWARE_ID_PROPERTY)
private UUID softwareId;
@Column(name = ModelConstants.EXTERNAL_ID_PROPERTY)
private UUID externalId;
public DeviceProfileEntity() {
super();
}
@ -137,6 +140,9 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl
if (deviceProfile.getSoftwareId() != null) {
this.softwareId = deviceProfile.getSoftwareId().getId();
}
if (deviceProfile.getExternalId() != null) {
this.externalId = deviceProfile.getExternalId().getId();
}
}
@Override
@ -184,6 +190,9 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl
if (softwareId != null) {
deviceProfile.setSoftwareId(new OtaPackageId(softwareId));
}
if (externalId != null) {
deviceProfile.setExternalId(new DeviceProfileId(externalId));
}
return deviceProfile;
}

9
dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleChainEntity.java

@ -75,6 +75,9 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
@Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY)
private JsonNode additionalInfo;
@Column(name = ModelConstants.EXTERNAL_ID_PROPERTY)
private UUID externalId;
public RuleChainEntity() {
}
@ -94,6 +97,9 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
this.debugMode = ruleChain.isDebugMode();
this.configuration = ruleChain.getConfiguration();
this.additionalInfo = ruleChain.getAdditionalInfo();
if (ruleChain.getExternalId() != null) {
this.externalId = ruleChain.getExternalId().getId();
}
}
@Override
@ -120,6 +126,9 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
ruleChain.setDebugMode(debugMode);
ruleChain.setConfiguration(configuration);
ruleChain.setAdditionalInfo(additionalInfo);
if (externalId != null) {
ruleChain.setExternalId(new RuleChainId(externalId));
}
return ruleChain;
}
}

5
dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java

@ -684,6 +684,11 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
throw t;
}
}
deleteRuleNodes(tenantId, ruleChainId);
}
@Override
public void deleteRuleNodes(TenantId tenantId, RuleChainId ruleChainId) {
List<EntityRelation> nodeRelations = getRuleChainToNodeRelations(tenantId, ruleChainId);
for (EntityRelation relation : nodeRelations) {
deleteRuleNode(tenantId, relation.getTo());

7
dao/src/main/java/org/thingsboard/server/dao/rule/RuleChainDao.java

@ -19,19 +19,18 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainOutputLabelsUsage;
import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.dao.Dao;
import org.thingsboard.server.dao.ExportableEntityDao;
import org.thingsboard.server.dao.TenantEntityDao;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
/**
* Created by igor on 3/12/18.
*/
public interface RuleChainDao extends Dao<RuleChain>, TenantEntityDao {
public interface RuleChainDao extends Dao<RuleChain>, TenantEntityDao, ExportableEntityDao<RuleChain> {
/**
* Find rule chains by tenantId and page link.
@ -81,4 +80,6 @@ public interface RuleChainDao extends Dao<RuleChain>, TenantEntityDao {
Collection<RuleChain> findByTenantIdAndTypeAndName(TenantId tenantId, RuleChainType type, String name);
RuleChain findByTenantIdAndExternalId(UUID tenantId, UUID externalId);
}

3
dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetRepository.java

@ -20,6 +20,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.thingsboard.server.dao.ExportableEntityRepository;
import org.thingsboard.server.dao.model.sql.AssetEntity;
import org.thingsboard.server.dao.model.sql.AssetInfoEntity;
@ -29,7 +30,7 @@ import java.util.UUID;
/**
* Created by Valerii Sosliuk on 5/21/2017.
*/
public interface AssetRepository extends JpaRepository<AssetEntity, UUID> {
public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, ExportableEntityRepository<AssetEntity> {
@Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
"FROM AssetEntity a " +

16
dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetDao.java

@ -208,4 +208,20 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
public Long countByTenantId(TenantId tenantId) {
return assetRepository.countByTenantIdAndTypeIsNot(tenantId.getId(), TB_SERVICE_QUEUE);
}
@Override
public Asset findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
return DaoUtil.getData(assetRepository.findByTenantIdAndExternalId(tenantId, externalId));
}
@Override
public Asset findByTenantIdAndId(UUID tenantId, UUID id) {
return DaoUtil.getData(assetRepository.findByTenantIdAndId(tenantId, id));
}
@Override
public EntityType getEntityType() {
return EntityType.ASSET;
}
}

3
dao/src/main/java/org/thingsboard/server/dao/sql/customer/CustomerRepository.java

@ -20,6 +20,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.thingsboard.server.dao.ExportableEntityRepository;
import org.thingsboard.server.dao.model.sql.CustomerEntity;
import java.util.UUID;
@ -27,7 +28,7 @@ import java.util.UUID;
/**
* Created by Valerii Sosliuk on 5/6/2017.
*/
public interface CustomerRepository extends JpaRepository<CustomerEntity, UUID> {
public interface CustomerRepository extends JpaRepository<CustomerEntity, UUID>, ExportableEntityRepository<CustomerEntity> {
@Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " +
"AND LOWER(c.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%'))")

17
dao/src/main/java/org/thingsboard/server/dao/sql/customer/JpaCustomerDao.java

@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
@ -68,4 +69,20 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus
public Long countByTenantId(TenantId tenantId) {
return customerRepository.countByTenantId(tenantId.getId());
}
@Override
public Customer findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
return DaoUtil.getData(customerRepository.findByTenantIdAndExternalId(tenantId, externalId));
}
@Override
public Customer findByTenantIdAndId(UUID tenantId, UUID id) {
return DaoUtil.getData(customerRepository.findByTenantIdAndId(tenantId, id));
}
@Override
public EntityType getEntityType() {
return EntityType.CUSTOMER;
}
}

4
dao/src/main/java/org/thingsboard/server/dao/sql/dashboard/DashboardRepository.java

@ -16,6 +16,7 @@
package org.thingsboard.server.dao.sql.dashboard;
import org.springframework.data.jpa.repository.JpaRepository;
import org.thingsboard.server.dao.ExportableEntityRepository;
import org.thingsboard.server.dao.model.sql.DashboardEntity;
import java.util.UUID;
@ -23,7 +24,8 @@ import java.util.UUID;
/**
* Created by Valerii Sosliuk on 5/6/2017.
*/
public interface DashboardRepository extends JpaRepository<DashboardEntity, UUID> {
public interface DashboardRepository extends JpaRepository<DashboardEntity, UUID>, ExportableEntityRepository<DashboardEntity> {
Long countByTenantId(UUID tenantId);
}

18
dao/src/main/java/org/thingsboard/server/dao/sql/dashboard/JpaDashboardDao.java

@ -19,7 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.DaoUtil;
import org.thingsboard.server.dao.dashboard.DashboardDao;
import org.thingsboard.server.dao.model.sql.DashboardEntity;
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
@ -49,4 +51,20 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D
public Long countByTenantId(TenantId tenantId) {
return dashboardRepository.countByTenantId(tenantId.getId());
}
@Override
public Dashboard findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
return DaoUtil.getData(dashboardRepository.findByTenantIdAndExternalId(tenantId, externalId));
}
@Override
public Dashboard findByTenantIdAndId(UUID tenantId, UUID id) {
return DaoUtil.getData(dashboardRepository.findByTenantIdAndId(tenantId, id));
}
@Override
public EntityType getEntityType() {
return EntityType.DASHBOARD;
}
}

4
dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java

@ -19,15 +19,15 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.thingsboard.server.common.data.DeviceProfileInfo;
import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.dao.ExportableEntityRepository;
import org.thingsboard.server.dao.model.sql.DeviceProfileEntity;
import java.util.UUID;
public interface DeviceProfileRepository extends JpaRepository<DeviceProfileEntity, UUID> {
public interface DeviceProfileRepository extends JpaRepository<DeviceProfileEntity, UUID>, ExportableEntityRepository<DeviceProfileEntity> {
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
"FROM DeviceProfileEntity d " +

3
dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java

@ -21,6 +21,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.dao.ExportableEntityRepository;
import org.thingsboard.server.dao.model.sql.DeviceEntity;
import org.thingsboard.server.dao.model.sql.DeviceInfoEntity;
@ -30,7 +31,7 @@ import java.util.UUID;
/**
* Created by Valerii Sosliuk on 5/6/2017.
*/
public interface DeviceRepository extends JpaRepository<DeviceEntity, UUID> {
public interface DeviceRepository extends JpaRepository<DeviceEntity, UUID>, ExportableEntityRepository<DeviceEntity> {
@Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo, p.name) " +
"FROM DeviceEntity d " +

16
dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java

@ -302,4 +302,20 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
Objects.toString(pageLink.getTextSearch(), ""),
DaoUtil.toPageable(pageLink)));
}
@Override
public Device findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
return DaoUtil.getData(deviceRepository.findByTenantIdAndExternalId(tenantId, externalId));
}
@Override
public Device findByTenantIdAndId(UUID tenantId, UUID id) {
return findDeviceByTenantIdAndId(TenantId.fromUUID(tenantId), id);
}
@Override
public EntityType getEntityType() {
return EntityType.DEVICE;
}
}

17
dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceProfileDao.java

@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.DeviceProfileInfo;
import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
@ -109,4 +110,20 @@ public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileE
public DeviceProfile findByName(TenantId tenantId, String profileName) {
return DaoUtil.getData(deviceProfileRepository.findByTenantIdAndName(tenantId.getId(), profileName));
}
@Override
public DeviceProfile findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
return DaoUtil.getData(deviceProfileRepository.findByTenantIdAndExternalId(tenantId, externalId));
}
@Override
public DeviceProfile findByTenantIdAndId(UUID tenantId, UUID id) {
return DaoUtil.getData(deviceProfileRepository.findByTenantIdAndId(tenantId, id));
}
@Override
public EntityType getEntityType() {
return EntityType.DEVICE_PROFILE;
}
}

16
dao/src/main/java/org/thingsboard/server/dao/sql/rule/JpaRuleChainDao.java

@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
@ -108,4 +109,19 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R
return ruleChainRepository.countByTenantId(tenantId.getId());
}
@Override
public RuleChain findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
return DaoUtil.getData(ruleChainRepository.findByTenantIdAndExternalId(tenantId, externalId));
}
@Override
public RuleChain findByTenantIdAndId(UUID tenantId, UUID id) {
return DaoUtil.getData(ruleChainRepository.findByTenantIdAndId(tenantId, id));
}
@Override
public EntityType getEntityType() {
return EntityType.RULE_CHAIN;
}
}

3
dao/src/main/java/org/thingsboard/server/dao/sql/rule/RuleChainRepository.java

@ -21,12 +21,13 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.dao.ExportableEntityRepository;
import org.thingsboard.server.dao.model.sql.RuleChainEntity;
import java.util.List;
import java.util.UUID;
public interface RuleChainRepository extends JpaRepository<RuleChainEntity, UUID> {
public interface RuleChainRepository extends JpaRepository<RuleChainEntity, UUID>, ExportableEntityRepository<RuleChainEntity> {
@Query("SELECT rc FROM RuleChainEntity rc WHERE rc.tenantId = :tenantId " +
"AND LOWER(rc.searchText) LIKE LOWER(CONCAT('%', :searchText, '%'))")

188
dao/src/main/resources/sql/schema-entities.sql

@ -72,17 +72,19 @@ CREATE TABLE IF NOT EXISTS entity_alarm (
CONSTRAINT fk_entity_alarm_id FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS asset (
id uuid NOT NULL CONSTRAINT asset_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
customer_id uuid,
name varchar(255),
label varchar(255),
search_text varchar(255),
tenant_id uuid,
type varchar(255),
CONSTRAINT asset_name_unq_key UNIQUE (tenant_id, name)
CREATE TABLE IF NOT EXISTS asset(
id uuid NOT NULL
CONSTRAINT asset_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
customer_id uuid,
name varchar(255),
label varchar(255),
search_text varchar(255),
tenant_id uuid,
type varchar(255),
external_id uuid,
CONSTRAINT asset_name_unq_key UNIQUE (tenant_id, name)
);
CREATE TABLE IF NOT EXISTS audit_log (
@ -128,47 +130,53 @@ CREATE TABLE IF NOT EXISTS component_descriptor (
);
CREATE TABLE IF NOT EXISTS customer (
id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
address varchar,
address2 varchar,
city varchar(255),
country varchar(255),
email varchar(255),
phone varchar(255),
search_text varchar(255),
state varchar(255),
tenant_id uuid,
title varchar(255),
zip varchar(255)
);
CREATE TABLE IF NOT EXISTS dashboard (
id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY,
created_time bigint NOT NULL,
configuration varchar,
id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
address varchar,
address2 varchar,
city varchar(255),
country varchar(255),
email varchar(255),
phone varchar(255),
search_text varchar(255),
state varchar(255),
tenant_id uuid,
title varchar(255),
zip varchar(255),
external_id uuid
);
CREATE TABLE IF NOT EXISTS dashboard
(
id uuid NOT NULL
CONSTRAINT dashboard_pkey PRIMARY KEY,
created_time bigint NOT NULL,
configuration varchar,
assigned_customers varchar(1000000),
search_text varchar(255),
tenant_id uuid,
title varchar(255),
mobile_hide boolean DEFAULT false,
mobile_order int,
image varchar(1000000)
search_text varchar(255),
tenant_id uuid,
title varchar(255),
mobile_hide boolean DEFAULT false,
mobile_order int,
image varchar(1000000),
external_id uuid
);
CREATE TABLE IF NOT EXISTS rule_chain (
id uuid NOT NULL CONSTRAINT rule_chain_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
configuration varchar(10000000),
name varchar(255),
type varchar(255),
first_rule_node_id uuid,
root boolean,
debug_mode boolean,
search_text varchar(255),
tenant_id uuid
id uuid NOT NULL
CONSTRAINT rule_chain_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
configuration varchar(10000000),
name varchar(255),
type varchar(255),
first_rule_node_id uuid,
root boolean,
debug_mode boolean,
search_text varchar(255),
tenant_id uuid,
external_id uuid
);
CREATE TABLE IF NOT EXISTS rule_node (
@ -216,30 +224,31 @@ CREATE TABLE IF NOT EXISTS ota_package (
);
CREATE TABLE IF NOT EXISTS device_profile (
id uuid NOT NULL CONSTRAINT device_profile_pkey PRIMARY KEY,
created_time bigint NOT NULL,
name varchar(255),
type varchar(255),
image varchar(1000000),
transport_type varchar(255),
provision_type varchar(255),
profile_data jsonb,
description varchar,
search_text varchar(255),
is_default boolean,
tenant_id uuid,
firmware_id uuid,
software_id uuid,
default_rule_chain_id uuid,
default_dashboard_id uuid,
default_queue_name varchar(255),
provision_device_key varchar,
CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key),
CONSTRAINT fk_default_rule_chain_device_profile FOREIGN KEY (default_rule_chain_id) REFERENCES rule_chain(id),
CONSTRAINT fk_default_dashboard_device_profile FOREIGN KEY (default_dashboard_id) REFERENCES dashboard(id),
CONSTRAINT fk_firmware_device_profile FOREIGN KEY (firmware_id) REFERENCES ota_package(id),
CONSTRAINT fk_software_device_profile FOREIGN KEY (software_id) REFERENCES ota_package(id)
id uuid NOT NULL CONSTRAINT device_profile_pkey PRIMARY KEY,
created_time bigint NOT NULL,
name varchar(255),
type varchar(255),
image varchar(1000000),
transport_type varchar(255),
provision_type varchar(255),
profile_data jsonb,
description varchar,
search_text varchar(255),
is_default boolean,
tenant_id uuid,
firmware_id uuid,
software_id uuid,
default_rule_chain_id uuid,
default_dashboard_id uuid,
default_queue_name varchar(255),
provision_device_key varchar,
external_id uuid,
CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key),
CONSTRAINT fk_default_rule_chain_device_profile FOREIGN KEY (default_rule_chain_id) REFERENCES rule_chain (id),
CONSTRAINT fk_default_dashboard_device_profile FOREIGN KEY (default_dashboard_id) REFERENCES dashboard (id),
CONSTRAINT fk_firmware_device_profile FOREIGN KEY (firmware_id) REFERENCES ota_package (id),
CONSTRAINT fk_software_device_profile FOREIGN KEY (software_id) REFERENCES ota_package (id)
);
ALTER TABLE ota_package
@ -257,23 +266,24 @@ ALTER TABLE ota_package
-- );
CREATE TABLE IF NOT EXISTS device (
id uuid NOT NULL CONSTRAINT device_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
customer_id uuid,
device_profile_id uuid NOT NULL,
device_data jsonb,
type varchar(255),
name varchar(255),
label varchar(255),
search_text varchar(255),
tenant_id uuid,
firmware_id uuid,
software_id uuid,
CONSTRAINT device_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT fk_device_profile FOREIGN KEY (device_profile_id) REFERENCES device_profile(id),
CONSTRAINT fk_firmware_device FOREIGN KEY (firmware_id) REFERENCES ota_package(id),
CONSTRAINT fk_software_device FOREIGN KEY (software_id) REFERENCES ota_package(id)
id uuid NOT NULL CONSTRAINT device_pkey PRIMARY KEY,
created_time bigint NOT NULL,
additional_info varchar,
customer_id uuid,
device_profile_id uuid NOT NULL,
device_data jsonb,
type varchar(255),
name varchar(255),
label varchar(255),
search_text varchar(255),
tenant_id uuid,
firmware_id uuid,
software_id uuid,
external_id uuid,
CONSTRAINT device_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT fk_device_profile FOREIGN KEY (device_profile_id) REFERENCES device_profile (id),
CONSTRAINT fk_firmware_device FOREIGN KEY (firmware_id) REFERENCES ota_package (id),
CONSTRAINT fk_software_device FOREIGN KEY (software_id) REFERENCES ota_package (id)
);
CREATE TABLE IF NOT EXISTS device_credentials (

Loading…
Cancel
Save