@ -491,13 +491,13 @@ public class DeviceController extends BaseController {
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@RequestMapping ( value = "/tenant/{tenantId}/device/{deviceId}" , method = RequestMethod . POST )
@ResponseBody
public Device swapDevice ( @PathVariable ( TENANT_ID ) String strTenantId ,
@PathVariable ( DEVICE_ID ) String strDeviceId ) throws ThingsboardException {
public Device assignDeviceToTenant ( @PathVariable ( TENANT_ID ) String strTenantId ,
@PathVariable ( DEVICE_ID ) String strDeviceId ) throws ThingsboardException {
checkParameter ( TENANT_ID , strTenantId ) ;
checkParameter ( DEVICE_ID , strDeviceId ) ;
try {
DeviceId deviceId = new DeviceId ( toUUID ( strDeviceId ) ) ;
Device device = checkDeviceId ( deviceId , Operation . WRITE ) ;
Device device = checkDeviceId ( deviceId , Operation . ASSIGN_TO_TENANT ) ;
TenantId newTenantId = new TenantId ( toUUID ( strTenantId ) ) ;
Tenant newTenant = tenantService . findTenantById ( newTenantId ) ;
@ -505,36 +505,36 @@ public class DeviceController extends BaseController {
throw new ThingsboardException ( "Could not find the specified Tenant!" , ThingsboardErrorCode . BAD_REQUEST_PARAMS ) ;
}
Device swapp edDevice = deviceService . swapDevice ( newTenantId , device ) ;
Device assign edDevice = deviceService . assignDeviceToTenant ( newTenantId , device ) ;
logEntityAction ( getCurrentUser ( ) , deviceId , swapp edDevice,
swapp edDevice. getCustomerId ( ) ,
ActionType . SWAPP ED_TO_TENANT, null , strTenantId , newTenant . getName ( ) ) ;
logEntityAction ( getCurrentUser ( ) , deviceId , assign edDevice,
assign edDevice. getCustomerId ( ) ,
ActionType . ASSIGN ED_TO_TENANT, null , strTenantId , newTenant . getName ( ) ) ;
Tenant currentTenant = tenantService . findTenantById ( getTenantId ( ) ) ;
pushSwapp edFromNotification ( currentTenant , newTenantId , swapp edDevice) ;
pushAssign edFromNotification ( currentTenant , newTenantId , assign edDevice) ;
return swapp edDevice;
return assign edDevice;
} catch ( Exception e ) {
logEntityAction ( getCurrentUser ( ) , emptyId ( EntityType . DEVICE ) , null ,
null ,
ActionType . SWAPP ED_TO_TENANT, e , strTenantId ) ;
ActionType . ASSIGN ED_TO_TENANT, e , strTenantId ) ;
throw handleException ( e ) ;
}
}
private void pushSwapp edFromNotification ( Tenant currentTenant , TenantId newTenantId , Device swapp edDevice) {
String data = entityToStr ( swapp edDevice) ;
private void pushAssign edFromNotification ( Tenant currentTenant , TenantId newTenantId , Device assign edDevice) {
String data = entityToStr ( assign edDevice) ;
if ( data ! = null ) {
TbMsg tbMsg = TbMsg . newMsg ( DataConstants . ENTITY_SWAPPED_FROM , swapp edDevice . getId ( ) , getMetaDataForSwapp edFrom ( currentTenant ) , TbMsgDataType . JSON , data ) ;
tbClusterService . pushMsgToRuleEngine ( newTenantId , swapp edDevice. getId ( ) , tbMsg , null ) ;
TbMsg tbMsg = TbMsg . newMsg ( DataConstants . ENTITY_ASSIGNED_FROM_TENANT , assign edDevice . getId ( ) , getMetaDataForAssign edFrom ( currentTenant ) , TbMsgDataType . JSON , data ) ;
tbClusterService . pushMsgToRuleEngine ( newTenantId , assign edDevice. getId ( ) , tbMsg , null ) ;
}
}
private TbMsgMetaData getMetaDataForSwapp edFrom ( Tenant tenant ) {
private TbMsgMetaData getMetaDataForAssign edFrom ( Tenant tenant ) {
TbMsgMetaData metaData = new TbMsgMetaData ( ) ;
metaData . putValue ( "swapp edFromTenantId" , tenant . getId ( ) . getId ( ) . toString ( ) ) ;
metaData . putValue ( "swapp edFromTenantName" , tenant . getName ( ) ) ;
metaData . putValue ( "assign edFromTenantId" , tenant . getId ( ) . getId ( ) . toString ( ) ) ;
metaData . putValue ( "assign edFromTenantName" , tenant . getName ( ) ) ;
return metaData ;
}
}