|
|
@ -69,22 +69,40 @@ public class EntityStateSourcingListener { |
|
|
boolean isCreated = event.getAdded() != null && event.getAdded(); |
|
|
boolean isCreated = event.getAdded() != null && event.getAdded(); |
|
|
ComponentLifecycleEvent lifecycleEvent = isCreated ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED; |
|
|
ComponentLifecycleEvent lifecycleEvent = isCreated ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED; |
|
|
|
|
|
|
|
|
if (isCommonEntityStateUpdated(entityId)) { |
|
|
switch (entityType) { |
|
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, entityId, lifecycleEvent); |
|
|
case ASSET: |
|
|
} else if (EntityType.TENANT.equals(entityType)) { |
|
|
case ASSET_PROFILE: |
|
|
onTenantUpdate((Tenant) event.getEntity(), isCreated); |
|
|
case ENTITY_VIEW: |
|
|
} else if (EntityType.TENANT_PROFILE.equals(entityType)) { |
|
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, entityId, lifecycleEvent); |
|
|
onTenantProfileUpdate((TenantProfile) event.getEntity(), isCreated); |
|
|
break; |
|
|
} else if (EntityType.DEVICE.equals(entityType)) { |
|
|
case TENANT: |
|
|
onDeviceUpdate(event.getEntity(), event.getOldEntity()); |
|
|
Tenant tenant = (Tenant) event.getEntity(); |
|
|
} else if (EntityType.DEVICE_PROFILE.equals(entityType)) { |
|
|
onTenantUpdate(tenant, isCreated); |
|
|
onDeviceProfileUpdate((DeviceProfile) event.getEntity(), event.getOldEntity(), isCreated); |
|
|
break; |
|
|
} else if (EntityType.EDGE.equals(entityType)) { |
|
|
case TENANT_PROFILE: |
|
|
handleEdgeEvent(tenantId, entityId, event.getEntity(), lifecycleEvent); |
|
|
TenantProfile tenantProfile = (TenantProfile) event.getEntity(); |
|
|
} else if (EntityType.TB_RESOURCE.equals(entityType)) { |
|
|
onTenantProfileUpdate(tenantProfile, isCreated); |
|
|
tbClusterService.onResourceChange((TbResource) event.getEntity(), null); |
|
|
break; |
|
|
} else if (EntityType.API_USAGE_STATE.equals(entityType) && !event.getAdded()) { |
|
|
case DEVICE: |
|
|
tbClusterService.onApiStateChange((ApiUsageState) event.getEntity(), null); |
|
|
onDeviceUpdate(event.getEntity(), event.getOldEntity()); |
|
|
|
|
|
break; |
|
|
|
|
|
case DEVICE_PROFILE: |
|
|
|
|
|
DeviceProfile deviceProfile = (DeviceProfile) event.getEntity(); |
|
|
|
|
|
onDeviceProfileUpdate(deviceProfile, event.getOldEntity(), isCreated); |
|
|
|
|
|
break; |
|
|
|
|
|
case EDGE: |
|
|
|
|
|
handleEdgeEvent(tenantId, entityId, event.getEntity(), lifecycleEvent); |
|
|
|
|
|
break; |
|
|
|
|
|
case TB_RESOURCE: |
|
|
|
|
|
TbResource tbResource = (TbResource) event.getEntity(); |
|
|
|
|
|
tbClusterService.onResourceChange(tbResource, null); |
|
|
|
|
|
break; |
|
|
|
|
|
case API_USAGE_STATE: |
|
|
|
|
|
ApiUsageState apiUsageState = (ApiUsageState) event.getEntity(); |
|
|
|
|
|
tbClusterService.onApiStateChange(apiUsageState, null); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -95,20 +113,38 @@ public class EntityStateSourcingListener { |
|
|
EntityId entityId = event.getEntityId(); |
|
|
EntityId entityId = event.getEntityId(); |
|
|
EntityType entityType = entityId.getEntityType(); |
|
|
EntityType entityType = entityId.getEntityType(); |
|
|
|
|
|
|
|
|
if (isCommonEntityStateUpdated(entityId) || EntityType.CUSTOMER.equals(entityType)) { |
|
|
switch (entityType) { |
|
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, entityId, ComponentLifecycleEvent.DELETED); |
|
|
case ASSET: |
|
|
} else if (EntityType.TENANT.equals(event.getEntityId().getEntityType())) { |
|
|
case ASSET_PROFILE: |
|
|
onTenantDeleted((Tenant) event.getEntity()); |
|
|
case ENTITY_VIEW: |
|
|
} else if (EntityType.TENANT_PROFILE.equals(entityType)) { |
|
|
case CUSTOMER: |
|
|
tbClusterService.onTenantProfileDelete((TenantProfile) event.getEntity(), null); |
|
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, entityId, ComponentLifecycleEvent.DELETED); |
|
|
} else if (EntityType.DEVICE.equals(entityType)) { |
|
|
break; |
|
|
tbClusterService.onDeviceDeleted((Device) event.getEntity(), null); |
|
|
case TENANT: |
|
|
} else if (EntityType.DEVICE_PROFILE.equals(entityType)) { |
|
|
Tenant tenant = (Tenant) event.getEntity(); |
|
|
onDeviceProfileDelete(event.getTenantId(), event.getEntityId(), (DeviceProfile) event.getEntity()); |
|
|
onTenantDeleted(tenant); |
|
|
} else if (EntityType.EDGE.equals(entityType)) { |
|
|
break; |
|
|
tbClusterService.broadcastEntityStateChangeEvent(event.getTenantId(), event.getEntityId(), ComponentLifecycleEvent.DELETED); |
|
|
case TENANT_PROFILE: |
|
|
} else if (EntityType.TB_RESOURCE.equals(entityType)) { |
|
|
TenantProfile tenantProfile = (TenantProfile) event.getEntity(); |
|
|
tbClusterService.onResourceDeleted((TbResource) event.getEntity(), null); |
|
|
tbClusterService.onTenantProfileDelete(tenantProfile, null); |
|
|
|
|
|
break; |
|
|
|
|
|
case DEVICE: |
|
|
|
|
|
Device device = (Device) event.getEntity(); |
|
|
|
|
|
tbClusterService.onDeviceDeleted(device, null); |
|
|
|
|
|
break; |
|
|
|
|
|
case DEVICE_PROFILE: |
|
|
|
|
|
DeviceProfile deviceProfile = (DeviceProfile) event.getEntity(); |
|
|
|
|
|
onDeviceProfileDelete(event.getTenantId(), event.getEntityId(), deviceProfile); |
|
|
|
|
|
break; |
|
|
|
|
|
case EDGE: |
|
|
|
|
|
tbClusterService.broadcastEntityStateChangeEvent(event.getTenantId(), event.getEntityId(), ComponentLifecycleEvent.DELETED); |
|
|
|
|
|
break; |
|
|
|
|
|
case TB_RESOURCE: |
|
|
|
|
|
TbResource tbResource = (TbResource) event.getEntity(); |
|
|
|
|
|
tbClusterService.onResourceDeleted(tbResource, null); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|