571 changed files with 16631 additions and 4365 deletions
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,37 @@ |
|||
-- |
|||
-- Copyright © 2016-2023 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. |
|||
-- |
|||
|
|||
-- RESOURCES UPDATE START |
|||
|
|||
DO |
|||
$$ |
|||
BEGIN |
|||
IF NOT EXISTS(SELECT 1 FROM information_schema.columns WHERE table_name = 'resource' AND column_name = 'data' AND data_type = 'bytea') THEN |
|||
ALTER TABLE resource RENAME COLUMN data TO base64_data; |
|||
ALTER TABLE resource ADD COLUMN data bytea; |
|||
UPDATE resource SET data = decode(base64_data, 'base64') WHERE base64_data IS NOT NULL; |
|||
ALTER TABLE resource DROP COLUMN base64_data; |
|||
END IF; |
|||
END; |
|||
$$; |
|||
|
|||
ALTER TABLE resource ADD COLUMN IF NOT EXISTS descriptor varchar; |
|||
ALTER TABLE resource ADD COLUMN IF NOT EXISTS preview bytea; |
|||
ALTER TABLE resource ADD COLUMN IF NOT EXISTS external_id uuid; |
|||
|
|||
CREATE INDEX IF NOT EXISTS idx_resource_etag ON resource(tenant_id, etag); |
|||
|
|||
-- RESOURCES UPDATE END |
|||
@ -0,0 +1,44 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.config; |
|||
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
|||
import org.springframework.boot.autoconfigure.security.SecurityProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.core.annotation.Order; |
|||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
|||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
|||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
|||
import org.springframework.security.web.SecurityFilterChain; |
|||
|
|||
@Configuration |
|||
@EnableWebSecurity |
|||
@EnableGlobalMethodSecurity(prePostEnabled = true) |
|||
@Order(SecurityProperties.BASIC_AUTH_ORDER) |
|||
@ConditionalOnExpression("'${service.type:null}'=='tb-rule-engine'") |
|||
public class TbRuleEngineSecurityConfiguration { |
|||
|
|||
@Bean |
|||
SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
|||
http.headers().cacheControl().and().frameOptions().disable() |
|||
.and().cors().and().csrf().disable() |
|||
.authorizeRequests() |
|||
.antMatchers("/actuator/prometheus").permitAll() |
|||
.anyRequest().authenticated(); |
|||
return http.build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,283 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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 com.fasterxml.jackson.core.JsonProcessingException; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.core.io.ByteArrayResource; |
|||
import org.springframework.http.CacheControl; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.util.Base64Utils; |
|||
import org.springframework.web.bind.annotation.DeleteMapping; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.PutMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestHeader; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RequestPart; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
import org.thingsboard.server.common.data.ImageDescriptor; |
|||
import org.thingsboard.server.common.data.ImageExportData; |
|||
import org.thingsboard.server.common.data.ResourceType; |
|||
import org.thingsboard.server.common.data.TbImageDeleteResult; |
|||
import org.thingsboard.server.common.data.TbResource; |
|||
import org.thingsboard.server.common.data.TbResourceInfo; |
|||
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|||
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.security.Authority; |
|||
import org.thingsboard.server.dao.resource.ImageService; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.dao.resource.ImageCacheKey; |
|||
import org.thingsboard.server.service.resource.TbImageService; |
|||
import org.thingsboard.server.service.security.model.SecurityUser; |
|||
import org.thingsboard.server.service.security.permission.Operation; |
|||
import org.thingsboard.server.service.security.permission.Resource; |
|||
|
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
import static org.thingsboard.server.controller.ControllerConstants.PAGE_NUMBER_DESCRIPTION; |
|||
import static org.thingsboard.server.controller.ControllerConstants.PAGE_SIZE_DESCRIPTION; |
|||
import static org.thingsboard.server.controller.ControllerConstants.RESOURCE_INCLUDE_SYSTEM_IMAGES_DESCRIPTION; |
|||
import static org.thingsboard.server.controller.ControllerConstants.RESOURCE_SORT_PROPERTY_ALLOWABLE_VALUES; |
|||
import static org.thingsboard.server.controller.ControllerConstants.RESOURCE_TEXT_SEARCH_DESCRIPTION; |
|||
import static org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_ALLOWABLE_VALUES; |
|||
import static org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_DESCRIPTION; |
|||
import static org.thingsboard.server.controller.ControllerConstants.SORT_PROPERTY_DESCRIPTION; |
|||
|
|||
@Slf4j |
|||
@RestController |
|||
@TbCoreComponent |
|||
@RequiredArgsConstructor |
|||
public class ImageController extends BaseController { |
|||
|
|||
private final ImageService imageService; |
|||
private final TbImageService tbImageService; |
|||
@Value("${cache.image.systemImagesBrowserTtlInMinutes:0}") |
|||
private int systemImagesBrowserTtlInMinutes; |
|||
@Value("${cache.image.tenantImagesBrowserTtlInMinutes:0}") |
|||
private int tenantImagesBrowserTtlInMinutes; |
|||
|
|||
private static final String IMAGE_URL = "/api/images/{type}/{key}"; |
|||
private static final String SYSTEM_IMAGE = "system"; |
|||
private static final String TENANT_IMAGE = "tenant"; |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@PostMapping("/api/image") |
|||
public TbResourceInfo uploadImage(@RequestPart MultipartFile file, |
|||
@RequestPart(required = false) String title) throws Exception { |
|||
SecurityUser user = getCurrentUser(); |
|||
TbResource image = new TbResource(); |
|||
image.setTenantId(user.getTenantId()); |
|||
accessControlService.checkPermission(user, Resource.TB_RESOURCE, Operation.CREATE, null, image); |
|||
|
|||
image.setFileName(file.getOriginalFilename()); |
|||
if (StringUtils.isNotEmpty(title)) { |
|||
image.setTitle(title); |
|||
} else { |
|||
image.setTitle(file.getOriginalFilename()); |
|||
} |
|||
image.setResourceType(ResourceType.IMAGE); |
|||
ImageDescriptor descriptor = new ImageDescriptor(); |
|||
descriptor.setMediaType(file.getContentType()); |
|||
image.setDescriptorValue(descriptor); |
|||
image.setData(file.getBytes()); |
|||
return tbImageService.save(image, user); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@PutMapping(IMAGE_URL) |
|||
public TbResourceInfo updateImage(@PathVariable String type, |
|||
@PathVariable String key, |
|||
@RequestPart MultipartFile file) throws Exception { |
|||
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE); |
|||
TbResource image = new TbResource(imageInfo); |
|||
image.setData(file.getBytes()); |
|||
image.setFileName(file.getOriginalFilename()); |
|||
image.updateDescriptor(ImageDescriptor.class, descriptor -> { |
|||
descriptor.setMediaType(file.getContentType()); |
|||
return descriptor; |
|||
}); |
|||
return tbImageService.save(image, getCurrentUser()); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@PutMapping(IMAGE_URL + "/info") |
|||
public TbResourceInfo updateImageInfo(@PathVariable String type, |
|||
@PathVariable String key, |
|||
@RequestBody TbResourceInfo newImageInfo) throws ThingsboardException { |
|||
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.WRITE); |
|||
imageInfo.setTitle(newImageInfo.getTitle()); |
|||
return tbImageService.save(imageInfo, getCurrentUser()); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|||
@GetMapping(value = IMAGE_URL, produces = "image/*") |
|||
public ResponseEntity<ByteArrayResource> downloadImage(@PathVariable String type, |
|||
@PathVariable String key, |
|||
@RequestHeader(name = HttpHeaders.IF_NONE_MATCH, required = false) String etag) throws Exception { |
|||
return downloadIfChanged(type, key, etag, false); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@GetMapping(value = IMAGE_URL + "/export") |
|||
public ImageExportData exportImage(@PathVariable String type, @PathVariable String key) throws Exception { |
|||
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.READ); |
|||
ImageDescriptor descriptor = imageInfo.getDescriptor(ImageDescriptor.class); |
|||
byte[] data = imageService.getImageData(imageInfo.getTenantId(), imageInfo.getId()); |
|||
return new ImageExportData(descriptor.getMediaType(), imageInfo.getFileName(), imageInfo.getTitle(), imageInfo.getResourceKey(), Base64Utils.encodeToString(data)); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@PutMapping("/api/image/import") |
|||
public TbResourceInfo importImage(@RequestBody ImageExportData imageData) throws Exception { |
|||
SecurityUser user = getCurrentUser(); |
|||
TbResource image = new TbResource(); |
|||
image.setTenantId(user.getTenantId()); |
|||
accessControlService.checkPermission(user, Resource.TB_RESOURCE, Operation.CREATE, null, image); |
|||
|
|||
image.setFileName(imageData.getFileName()); |
|||
if (StringUtils.isNotEmpty(imageData.getTitle())) { |
|||
image.setTitle(imageData.getTitle()); |
|||
} else { |
|||
image.setTitle(imageData.getFileName()); |
|||
} |
|||
image.setResourceKey(imageData.getResourceKey()); |
|||
image.setResourceType(ResourceType.IMAGE); |
|||
ImageDescriptor descriptor = new ImageDescriptor(); |
|||
descriptor.setMediaType(imageData.getMediaType()); |
|||
image.setDescriptorValue(descriptor); |
|||
image.setData(Base64Utils.decodeFromString(imageData.getData())); |
|||
return tbImageService.save(image, user); |
|||
|
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|||
@GetMapping(value = IMAGE_URL + "/preview", produces = "image/png") |
|||
public ResponseEntity<ByteArrayResource> downloadImagePreview(@PathVariable String type, |
|||
@PathVariable String key, |
|||
@RequestHeader(name = HttpHeaders.IF_NONE_MATCH, required = false) String etag) throws Exception { |
|||
return downloadIfChanged(type, key, etag, true); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@GetMapping(IMAGE_URL + "/info") |
|||
public TbResourceInfo getImageInfo(@PathVariable String type, |
|||
@PathVariable String key) throws ThingsboardException { |
|||
return checkImageInfo(type, key, Operation.READ); |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@GetMapping("/api/images") |
|||
public PageData<TbResourceInfo> getImages(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) |
|||
@RequestParam int pageSize, |
|||
@ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) |
|||
@RequestParam int page, |
|||
@ApiParam(value = RESOURCE_INCLUDE_SYSTEM_IMAGES_DESCRIPTION) |
|||
@RequestParam(required = false) boolean includeSystemImages, |
|||
@ApiParam(value = RESOURCE_TEXT_SEARCH_DESCRIPTION) |
|||
@RequestParam(required = false) String textSearch, |
|||
@ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = RESOURCE_SORT_PROPERTY_ALLOWABLE_VALUES) |
|||
@RequestParam(required = false) String sortProperty, |
|||
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES) |
|||
@RequestParam(required = false) String sortOrder) throws ThingsboardException { |
|||
// PE: generic permission
|
|||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
|||
TenantId tenantId = getTenantId(); |
|||
if (getCurrentUser().getAuthority() == Authority.SYS_ADMIN || !includeSystemImages) { |
|||
return checkNotNull(imageService.getImagesByTenantId(tenantId, pageLink)); |
|||
} else { |
|||
return checkNotNull(imageService.getAllImagesByTenantId(tenantId, pageLink)); |
|||
} |
|||
} |
|||
|
|||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
|||
@DeleteMapping(IMAGE_URL) |
|||
public ResponseEntity<TbImageDeleteResult> deleteImage(@PathVariable String type, |
|||
@PathVariable String key, |
|||
@RequestParam(name = "force", required = false) boolean force) throws ThingsboardException { |
|||
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.DELETE); |
|||
TbImageDeleteResult result = tbImageService.delete(imageInfo, getCurrentUser(), force); |
|||
return (result.isSuccess() ? ResponseEntity.ok() : ResponseEntity.badRequest()).body(result); |
|||
} |
|||
|
|||
private ResponseEntity<ByteArrayResource> downloadIfChanged(String type, String key, String etag, boolean preview) throws ThingsboardException, JsonProcessingException { |
|||
ImageCacheKey cacheKey = new ImageCacheKey(getTenantId(type), key, preview); |
|||
if (StringUtils.isNotEmpty(etag)) { |
|||
etag = StringUtils.remove(etag, '\"'); // etag is wrapped in double quotes due to HTTP specification
|
|||
if (etag.equals(tbImageService.getETag(cacheKey))) { |
|||
return ResponseEntity.status(HttpStatus.NOT_MODIFIED).build(); |
|||
} |
|||
} |
|||
TenantId tenantId = getTenantId(); |
|||
TbResourceInfo imageInfo = checkImageInfo(type, key, Operation.READ); |
|||
String fileName = imageInfo.getFileName(); |
|||
ImageDescriptor descriptor = imageInfo.getDescriptor(ImageDescriptor.class); |
|||
byte[] data; |
|||
if (preview) { |
|||
descriptor = descriptor.getPreviewDescriptor(); |
|||
data = imageService.getImagePreview(tenantId, imageInfo.getId()); |
|||
} else { |
|||
data = imageService.getImageData(tenantId, imageInfo.getId()); |
|||
} |
|||
tbImageService.putETag(cacheKey, descriptor.getEtag()); |
|||
var result = ResponseEntity.ok() |
|||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName) |
|||
.header("x-filename", fileName) |
|||
.header("Content-Type", descriptor.getMediaType()) |
|||
.contentLength(data.length) |
|||
.eTag(descriptor.getEtag()); |
|||
if (systemImagesBrowserTtlInMinutes > 0 && imageInfo.getTenantId().isSysTenantId()) { |
|||
result.cacheControl(CacheControl.maxAge(systemImagesBrowserTtlInMinutes, TimeUnit.MINUTES)); |
|||
} else if (tenantImagesBrowserTtlInMinutes > 0 && !imageInfo.getTenantId().isSysTenantId()) { |
|||
result.cacheControl(CacheControl.maxAge(tenantImagesBrowserTtlInMinutes, TimeUnit.MINUTES)); |
|||
} else { |
|||
result.cacheControl(CacheControl.noCache()); |
|||
} |
|||
return result.body(new ByteArrayResource(data)); |
|||
} |
|||
|
|||
private TbResourceInfo checkImageInfo(String imageType, String key, Operation operation) throws ThingsboardException { |
|||
TenantId tenantId = getTenantId(imageType); |
|||
TbResourceInfo imageInfo = imageService.getImageInfoByTenantIdAndKey(tenantId, key); |
|||
checkEntity(getCurrentUser(), checkNotNull(imageInfo), operation); |
|||
return imageInfo; |
|||
} |
|||
|
|||
private TenantId getTenantId(String imageType) throws ThingsboardException { |
|||
TenantId tenantId; |
|||
if (imageType.equals(TENANT_IMAGE)) { |
|||
tenantId = getTenantId(); |
|||
} else if (imageType.equals(SYSTEM_IMAGE)) { |
|||
tenantId = TenantId.SYS_TENANT_ID; |
|||
} else { |
|||
throw new IllegalArgumentException("Invalid image URL"); |
|||
} |
|||
return tenantId; |
|||
} |
|||
|
|||
} |
|||
@ -1,60 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.asset.Asset; |
|||
import org.thingsboard.server.common.data.id.AssetId; |
|||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class AssetMsgConstructor { |
|||
|
|||
public AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset) { |
|||
AssetUpdateMsg.Builder builder = AssetUpdateMsg.newBuilder() |
|||
.setMsgType(msgType) |
|||
.setIdMSB(asset.getUuidId().getMostSignificantBits()) |
|||
.setIdLSB(asset.getUuidId().getLeastSignificantBits()) |
|||
.setName(asset.getName()) |
|||
.setType(asset.getType()); |
|||
if (asset.getLabel() != null) { |
|||
builder.setLabel(asset.getLabel()); |
|||
} |
|||
if (asset.getCustomerId() != null) { |
|||
builder.setCustomerIdMSB(asset.getCustomerId().getId().getMostSignificantBits()); |
|||
builder.setCustomerIdLSB(asset.getCustomerId().getId().getLeastSignificantBits()); |
|||
} |
|||
if (asset.getAssetProfileId() != null) { |
|||
builder.setAssetProfileIdMSB(asset.getAssetProfileId().getId().getMostSignificantBits()); |
|||
builder.setAssetProfileIdLSB(asset.getAssetProfileId().getId().getLeastSignificantBits()); |
|||
} |
|||
if (asset.getAdditionalInfo() != null) { |
|||
builder.setAdditionalInfo(JacksonUtil.toString(asset.getAdditionalInfo())); |
|||
} |
|||
return builder.build(); |
|||
} |
|||
|
|||
public AssetUpdateMsg constructAssetDeleteMsg(AssetId assetId) { |
|||
return AssetUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(assetId.getId().getMostSignificantBits()) |
|||
.setIdLSB(assetId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -1,90 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor; |
|||
|
|||
import com.google.protobuf.ByteString; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.DataDecodingEncodingService; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
import java.nio.charset.StandardCharsets; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class DeviceProfileMsgConstructor { |
|||
|
|||
@Autowired |
|||
private DataDecodingEncodingService dataDecodingEncodingService; |
|||
|
|||
public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) { |
|||
DeviceProfileUpdateMsg.Builder builder = DeviceProfileUpdateMsg.newBuilder() |
|||
.setMsgType(msgType) |
|||
.setIdMSB(deviceProfile.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(deviceProfile.getId().getId().getLeastSignificantBits()) |
|||
.setName(deviceProfile.getName()) |
|||
.setDefault(deviceProfile.isDefault()) |
|||
.setType(deviceProfile.getType().name()) |
|||
.setProfileDataBytes(ByteString.copyFrom(dataDecodingEncodingService.encode(deviceProfile.getProfileData()))); |
|||
if (deviceProfile.getDefaultQueueName() != null) { |
|||
builder.setDefaultQueueName(deviceProfile.getDefaultQueueName()); |
|||
} |
|||
if (deviceProfile.getDescription() != null) { |
|||
builder.setDescription(deviceProfile.getDescription()); |
|||
} |
|||
if (deviceProfile.getTransportType() != null) { |
|||
builder.setTransportType(deviceProfile.getTransportType().name()); |
|||
} |
|||
if (deviceProfile.getProvisionType() != null) { |
|||
builder.setProvisionType(deviceProfile.getProvisionType().name()); |
|||
} |
|||
if (deviceProfile.getProvisionDeviceKey() != null) { |
|||
builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey()); |
|||
} |
|||
if (deviceProfile.getImage() != null) { |
|||
builder.setImage(ByteString.copyFrom(deviceProfile.getImage().getBytes(StandardCharsets.UTF_8))); |
|||
} |
|||
if (deviceProfile.getFirmwareId() != null) { |
|||
builder.setFirmwareIdMSB(deviceProfile.getFirmwareId().getId().getMostSignificantBits()) |
|||
.setFirmwareIdLSB(deviceProfile.getFirmwareId().getId().getLeastSignificantBits()); |
|||
} |
|||
if (deviceProfile.getSoftwareId() != null) { |
|||
builder.setSoftwareIdMSB(deviceProfile.getSoftwareId().getId().getMostSignificantBits()) |
|||
.setSoftwareIdLSB(deviceProfile.getSoftwareId().getId().getLeastSignificantBits()); |
|||
} |
|||
if (deviceProfile.getDefaultEdgeRuleChainId() != null) { |
|||
builder.setDefaultRuleChainIdMSB(deviceProfile.getDefaultEdgeRuleChainId().getId().getMostSignificantBits()) |
|||
.setDefaultRuleChainIdLSB(deviceProfile.getDefaultEdgeRuleChainId().getId().getLeastSignificantBits()); |
|||
} |
|||
if (deviceProfile.getDefaultDashboardId() != null) { |
|||
builder.setDefaultDashboardIdMSB(deviceProfile.getDefaultDashboardId().getId().getMostSignificantBits()) |
|||
.setDefaultDashboardIdLSB(deviceProfile.getDefaultDashboardId().getId().getLeastSignificantBits()); |
|||
} |
|||
return builder.build(); |
|||
} |
|||
|
|||
public DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId) { |
|||
return DeviceProfileUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(deviceProfileId.getId().getMostSignificantBits()) |
|||
.setIdLSB(deviceProfileId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor; |
|||
|
|||
public interface MsgConstructor { |
|||
|
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public abstract class MsgConstructorFactory<T extends MsgConstructor, U extends MsgConstructor> { |
|||
|
|||
@Autowired |
|||
protected T v1Constructor; |
|||
|
|||
@Autowired |
|||
protected U v2Constructor; |
|||
|
|||
public MsgConstructor getMsgConstructorByEdgeVersion(EdgeVersion edgeVersion) { |
|||
switch (edgeVersion) { |
|||
case V_3_3_0: |
|||
case V_3_3_3: |
|||
case V_3_4_0: |
|||
case V_3_6_0: |
|||
case V_3_6_1: |
|||
return v1Constructor; |
|||
case V_3_6_2: |
|||
default: |
|||
return v2Constructor; |
|||
} |
|||
} |
|||
} |
|||
@ -1,52 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor; |
|||
|
|||
import com.google.protobuf.ByteString; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|||
import org.thingsboard.server.gen.edge.v1.TenantProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.DataDecodingEncodingService; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.utils.EdgeVersionUtils; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class TenantProfileMsgConstructor { |
|||
|
|||
@Autowired |
|||
private DataDecodingEncodingService dataDecodingEncodingService; |
|||
|
|||
public TenantProfileUpdateMsg constructTenantProfileUpdateMsg(UpdateMsgType msgType, TenantProfile tenantProfile, EdgeVersion edgeVersion) { |
|||
ByteString profileData = EdgeVersionUtils.isEdgeVersionOlderThan(edgeVersion, EdgeVersion.V_3_6_1) ? |
|||
ByteString.empty() : ByteString.copyFrom(dataDecodingEncodingService.encode(tenantProfile.getProfileData())); |
|||
TenantProfileUpdateMsg.Builder builder = TenantProfileUpdateMsg.newBuilder() |
|||
.setMsgType(msgType) |
|||
.setIdMSB(tenantProfile.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(tenantProfile.getId().getId().getLeastSignificantBits()) |
|||
.setName(tenantProfile.getName()) |
|||
.setDefault(tenantProfile.isDefault()) |
|||
.setIsolatedRuleChain(tenantProfile.isIsolatedTbRuleEngine()) |
|||
.setProfileDataBytes(profileData); |
|||
if (tenantProfile.getDescription() != null) { |
|||
builder.setDescription(tenantProfile.getDescription()); |
|||
} |
|||
return builder.build(); |
|||
} |
|||
} |
|||
@ -1,65 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor; |
|||
|
|||
import com.google.protobuf.ByteString; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.WidgetsBundleId; |
|||
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
import java.nio.charset.StandardCharsets; |
|||
import java.util.List; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class WidgetsBundleMsgConstructor { |
|||
|
|||
public WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle, List<String> widgets) { |
|||
WidgetsBundleUpdateMsg.Builder builder = WidgetsBundleUpdateMsg.newBuilder() |
|||
.setMsgType(msgType) |
|||
.setIdMSB(widgetsBundle.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(widgetsBundle.getId().getId().getLeastSignificantBits()) |
|||
.setTitle(widgetsBundle.getTitle()) |
|||
.setAlias(widgetsBundle.getAlias()); |
|||
if (widgetsBundle.getImage() != null) { |
|||
builder.setImage(ByteString.copyFrom(widgetsBundle.getImage().getBytes(StandardCharsets.UTF_8))); |
|||
} |
|||
if (widgetsBundle.getDescription() != null) { |
|||
builder.setDescription(widgetsBundle.getDescription()); |
|||
} |
|||
if (widgetsBundle.getOrder() != null) { |
|||
builder.setOrder(widgetsBundle.getOrder()); |
|||
} |
|||
if (widgetsBundle.getTenantId().equals(TenantId.SYS_TENANT_ID)) { |
|||
builder.setIsSystem(true); |
|||
} |
|||
builder.setWidgets(JacksonUtil.toString(widgets)); |
|||
return builder.build(); |
|||
} |
|||
|
|||
public WidgetsBundleUpdateMsg constructWidgetsBundleDeleteMsg(WidgetsBundleId widgetsBundleId) { |
|||
return WidgetsBundleUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(widgetsBundleId.getId().getMostSignificantBits()) |
|||
.setIdLSB(widgetsBundleId.getId().getLeastSignificantBits()) |
|||
.build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.alarm; |
|||
|
|||
import org.thingsboard.server.common.data.alarm.Alarm; |
|||
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface AlarmMsgConstructor extends MsgConstructor { |
|||
|
|||
AlarmUpdateMsg constructAlarmUpdatedMsg(UpdateMsgType msgType, Alarm alarm, String entityName); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.alarm; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class AlarmMsgConstructorFactory extends MsgConstructorFactory<AlarmMsgConstructorV1, AlarmMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.alarm; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.alarm.Alarm; |
|||
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class AlarmMsgConstructorV2 implements AlarmMsgConstructor { |
|||
|
|||
@Override |
|||
public AlarmUpdateMsg constructAlarmUpdatedMsg(UpdateMsgType msgType, Alarm alarm, String entityName) { |
|||
return AlarmUpdateMsg.newBuilder().setMsgType(msgType) |
|||
.setEntity(JacksonUtil.toString(alarm)) |
|||
.setIdMSB(alarm.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(alarm.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.asset; |
|||
|
|||
import org.thingsboard.server.common.data.asset.Asset; |
|||
import org.thingsboard.server.common.data.asset.AssetProfile; |
|||
import org.thingsboard.server.common.data.id.AssetId; |
|||
import org.thingsboard.server.common.data.id.AssetProfileId; |
|||
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface AssetMsgConstructor extends MsgConstructor { |
|||
|
|||
AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset); |
|||
|
|||
AssetUpdateMsg constructAssetDeleteMsg(AssetId assetId); |
|||
|
|||
AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile); |
|||
|
|||
AssetProfileUpdateMsg constructAssetProfileDeleteMsg(AssetProfileId assetProfileId); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.asset; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class AssetMsgConstructorFactory extends MsgConstructorFactory<AssetMsgConstructorV1, AssetMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.asset; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.asset.Asset; |
|||
import org.thingsboard.server.common.data.asset.AssetProfile; |
|||
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class AssetMsgConstructorV2 extends BaseAssetMsgConstructor { |
|||
|
|||
@Override |
|||
public AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset) { |
|||
return AssetUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(asset)) |
|||
.setIdMSB(asset.getUuidId().getMostSignificantBits()) |
|||
.setIdLSB(asset.getUuidId().getLeastSignificantBits()).build(); |
|||
} |
|||
|
|||
@Override |
|||
public AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile) { |
|||
return AssetProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(assetProfile)) |
|||
.setIdMSB(assetProfile.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(assetProfile.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.asset; |
|||
|
|||
import org.thingsboard.server.common.data.id.AssetId; |
|||
import org.thingsboard.server.common.data.id.AssetProfileId; |
|||
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
public abstract class BaseAssetMsgConstructor implements AssetMsgConstructor { |
|||
|
|||
@Override |
|||
public AssetUpdateMsg constructAssetDeleteMsg(AssetId assetId) { |
|||
return AssetUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(assetId.getId().getMostSignificantBits()) |
|||
.setIdLSB(assetId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
|
|||
@Override |
|||
public AssetProfileUpdateMsg constructAssetProfileDeleteMsg(AssetProfileId assetProfileId) { |
|||
return AssetProfileUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(assetProfileId.getId().getMostSignificantBits()) |
|||
.setIdLSB(assetProfileId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.customer; |
|||
|
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
public abstract class BaseCustomerMsgConstructor implements CustomerMsgConstructor { |
|||
|
|||
@Override |
|||
public CustomerUpdateMsg constructCustomerDeleteMsg(CustomerId customerId) { |
|||
return CustomerUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(customerId.getId().getMostSignificantBits()) |
|||
.setIdLSB(customerId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.customer; |
|||
|
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface CustomerMsgConstructor extends MsgConstructor { |
|||
|
|||
CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer); |
|||
|
|||
CustomerUpdateMsg constructCustomerDeleteMsg(CustomerId customerId); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.customer; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class CustomerMsgConstructorFactory extends MsgConstructorFactory<CustomerMsgConstructorV1, CustomerMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.customer; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class CustomerMsgConstructorV2 extends BaseCustomerMsgConstructor { |
|||
|
|||
@Override |
|||
public CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer) { |
|||
return CustomerUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(customer)) |
|||
.setIdMSB(customer.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(customer.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.dashboard; |
|||
|
|||
import org.thingsboard.server.common.data.id.DashboardId; |
|||
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
public abstract class BaseDashboardMsgConstructor implements DashboardMsgConstructor { |
|||
|
|||
@Override |
|||
public DashboardUpdateMsg constructDashboardDeleteMsg(DashboardId dashboardId) { |
|||
return DashboardUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(dashboardId.getId().getMostSignificantBits()) |
|||
.setIdLSB(dashboardId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.dashboard; |
|||
|
|||
import org.thingsboard.server.common.data.Dashboard; |
|||
import org.thingsboard.server.common.data.id.DashboardId; |
|||
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface DashboardMsgConstructor extends MsgConstructor { |
|||
|
|||
DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard); |
|||
|
|||
DashboardUpdateMsg constructDashboardDeleteMsg(DashboardId dashboardId); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.dashboard; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class DashboardMsgConstructorFactory extends MsgConstructorFactory<DashboardMsgConstructorV1, DashboardMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.dashboard; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.Dashboard; |
|||
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class DashboardMsgConstructorV2 extends BaseDashboardMsgConstructor { |
|||
|
|||
@Override |
|||
public DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard) { |
|||
return DashboardUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(dashboard)) |
|||
.setIdMSB(dashboard.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(dashboard.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,102 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.device; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.id.DeviceId; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.RpcRequestMsg; |
|||
import org.thingsboard.server.gen.edge.v1.RpcResponseMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public abstract class BaseDeviceMsgConstructor implements DeviceMsgConstructor { |
|||
|
|||
@Override |
|||
public DeviceUpdateMsg constructDeviceDeleteMsg(DeviceId deviceId) { |
|||
return DeviceUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(deviceId.getId().getMostSignificantBits()) |
|||
.setIdLSB(deviceId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId) { |
|||
return DeviceProfileUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(deviceProfileId.getId().getMostSignificantBits()) |
|||
.setIdLSB(deviceProfileId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceRpcCallMsg constructDeviceRpcCallMsg(UUID deviceId, JsonNode body) { |
|||
DeviceRpcCallMsg.Builder builder = constructDeviceRpcMsg(deviceId, body); |
|||
if (body.has("error") || body.has("response")) { |
|||
RpcResponseMsg.Builder responseBuilder = RpcResponseMsg.newBuilder(); |
|||
if (body.has("error")) { |
|||
responseBuilder.setError(body.get("error").asText()); |
|||
} else { |
|||
responseBuilder.setResponse(body.get("response").asText()); |
|||
} |
|||
builder.setResponseMsg(responseBuilder.build()); |
|||
} else { |
|||
RpcRequestMsg.Builder requestBuilder = RpcRequestMsg.newBuilder(); |
|||
requestBuilder.setMethod(body.get("method").asText()); |
|||
requestBuilder.setParams(body.get("params").asText()); |
|||
builder.setRequestMsg(requestBuilder.build()); |
|||
} |
|||
return builder.build(); |
|||
} |
|||
|
|||
private DeviceRpcCallMsg.Builder constructDeviceRpcMsg(UUID deviceId, JsonNode body) { |
|||
DeviceRpcCallMsg.Builder builder = DeviceRpcCallMsg.newBuilder() |
|||
.setDeviceIdMSB(deviceId.getMostSignificantBits()) |
|||
.setDeviceIdLSB(deviceId.getLeastSignificantBits()) |
|||
.setRequestId(body.get("requestId").asInt()); |
|||
if (body.get("oneway") != null) { |
|||
builder.setOneway(body.get("oneway").asBoolean()); |
|||
} |
|||
if (body.get("requestUUID") != null) { |
|||
UUID requestUUID = UUID.fromString(body.get("requestUUID").asText()); |
|||
builder.setRequestUuidMSB(requestUUID.getMostSignificantBits()) |
|||
.setRequestUuidLSB(requestUUID.getLeastSignificantBits()); |
|||
} |
|||
if (body.get("expirationTime") != null) { |
|||
builder.setExpirationTime(body.get("expirationTime").asLong()); |
|||
} |
|||
if (body.get("persisted") != null) { |
|||
builder.setPersisted(body.get("persisted").asBoolean()); |
|||
} |
|||
if (body.get("retries") != null) { |
|||
builder.setRetries(body.get("retries").asInt()); |
|||
} |
|||
if (body.get("additionalInfo") != null) { |
|||
builder.setAdditionalInfo(JacksonUtil.toString(body.get("additionalInfo"))); |
|||
} |
|||
if (body.get("serviceId") != null) { |
|||
builder.setServiceId(body.get("serviceId").asText()); |
|||
} |
|||
if (body.get("sessionId") != null) { |
|||
builder.setSessionId(body.get("sessionId").asText()); |
|||
} |
|||
return builder; |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.device; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import org.thingsboard.server.common.data.Device; |
|||
import org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.id.DeviceId; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface DeviceMsgConstructor extends MsgConstructor { |
|||
|
|||
DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device); |
|||
|
|||
DeviceUpdateMsg constructDeviceDeleteMsg(DeviceId deviceId); |
|||
|
|||
DeviceCredentialsUpdateMsg constructDeviceCredentialsUpdatedMsg(DeviceCredentials deviceCredentials); |
|||
|
|||
DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile); |
|||
|
|||
DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId); |
|||
|
|||
DeviceRpcCallMsg constructDeviceRpcCallMsg(UUID deviceId, JsonNode body); |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.device; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class DeviceMsgConstructorFactory extends MsgConstructorFactory<DeviceMsgConstructorV1, DeviceMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.device; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.Device; |
|||
import org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class DeviceMsgConstructorV2 extends BaseDeviceMsgConstructor { |
|||
|
|||
@Override |
|||
public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device) { |
|||
return DeviceUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(device)) |
|||
.setIdMSB(device.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(device.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceCredentialsUpdateMsg constructDeviceCredentialsUpdatedMsg(DeviceCredentials deviceCredentials) { |
|||
return DeviceCredentialsUpdateMsg.newBuilder().setEntity(JacksonUtil.toString(deviceCredentials)).build(); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) { |
|||
return DeviceProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(deviceProfile)) |
|||
.setIdMSB(deviceProfile.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(deviceProfile.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.entityview; |
|||
|
|||
import org.thingsboard.server.common.data.id.EntityViewId; |
|||
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
public abstract class BaseEntityViewMsgConstructor implements EntityViewMsgConstructor { |
|||
|
|||
@Override |
|||
public EntityViewUpdateMsg constructEntityViewDeleteMsg(EntityViewId entityViewId) { |
|||
return EntityViewUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(entityViewId.getId().getMostSignificantBits()) |
|||
.setIdLSB(entityViewId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.entityview; |
|||
|
|||
import org.thingsboard.server.common.data.EntityView; |
|||
import org.thingsboard.server.common.data.id.EntityViewId; |
|||
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface EntityViewMsgConstructor extends MsgConstructor { |
|||
|
|||
EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView); |
|||
|
|||
EntityViewUpdateMsg constructEntityViewDeleteMsg(EntityViewId entityViewId); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.entityview; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class EntityViewMsgConstructorFactory extends MsgConstructorFactory<EntityViewMsgConstructorV1, EntityViewMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.entityview; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.EntityView; |
|||
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class EntityViewMsgConstructorV2 extends BaseEntityViewMsgConstructor { |
|||
|
|||
@Override |
|||
public EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView) { |
|||
return EntityViewUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(entityView)) |
|||
.setIdMSB(entityView.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(entityView.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.ota; |
|||
|
|||
import org.thingsboard.server.common.data.id.OtaPackageId; |
|||
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
public abstract class BaseOtaPackageMsgConstructor implements OtaPackageMsgConstructor { |
|||
|
|||
@Override |
|||
public OtaPackageUpdateMsg constructOtaPackageDeleteMsg(OtaPackageId otaPackageId) { |
|||
return OtaPackageUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(otaPackageId.getId().getMostSignificantBits()) |
|||
.setIdLSB(otaPackageId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.ota; |
|||
|
|||
import org.thingsboard.server.common.data.OtaPackage; |
|||
import org.thingsboard.server.common.data.id.OtaPackageId; |
|||
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface OtaPackageMsgConstructor extends MsgConstructor { |
|||
|
|||
OtaPackageUpdateMsg constructOtaPackageUpdatedMsg(UpdateMsgType msgType, OtaPackage otaPackage); |
|||
|
|||
OtaPackageUpdateMsg constructOtaPackageDeleteMsg(OtaPackageId otaPackageId); |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.ota; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.customer.CustomerMsgConstructorV1; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.customer.CustomerMsgConstructorV2; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class OtaPackageMsgConstructorFactory extends MsgConstructorFactory<OtaPackageMsgConstructorV1, OtaPackageMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.ota; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.OtaPackage; |
|||
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class OtaPackageMsgConstructorV2 extends BaseOtaPackageMsgConstructor { |
|||
|
|||
@Override |
|||
public OtaPackageUpdateMsg constructOtaPackageUpdatedMsg(UpdateMsgType msgType, OtaPackage otaPackage) { |
|||
return OtaPackageUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(otaPackage)) |
|||
.setIdMSB(otaPackage.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(otaPackage.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.queue; |
|||
|
|||
import org.thingsboard.server.common.data.id.QueueId; |
|||
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
public abstract class BaseQueueMsgConstructor implements QueueMsgConstructor { |
|||
|
|||
@Override |
|||
public QueueUpdateMsg constructQueueDeleteMsg(QueueId queueId) { |
|||
return QueueUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(queueId.getId().getMostSignificantBits()) |
|||
.setIdLSB(queueId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.queue; |
|||
|
|||
import org.thingsboard.server.common.data.id.QueueId; |
|||
import org.thingsboard.server.common.data.queue.Queue; |
|||
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface QueueMsgConstructor extends MsgConstructor { |
|||
|
|||
QueueUpdateMsg constructQueueUpdatedMsg(UpdateMsgType msgType, Queue queue); |
|||
|
|||
QueueUpdateMsg constructQueueDeleteMsg(QueueId queueId); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.queue; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class QueueMsgConstructorFactory extends MsgConstructorFactory<QueueMsgConstructorV1, QueueMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.queue; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.queue.Queue; |
|||
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class QueueMsgConstructorV2 extends BaseQueueMsgConstructor { |
|||
|
|||
@Override |
|||
public QueueUpdateMsg constructQueueUpdatedMsg(UpdateMsgType msgType, Queue queue) { |
|||
return QueueUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(queue)) |
|||
.setIdMSB(queue.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(queue.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.relation; |
|||
|
|||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|||
import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface RelationMsgConstructor extends MsgConstructor { |
|||
|
|||
RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation); |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.relation; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.customer.CustomerMsgConstructorV1; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.customer.CustomerMsgConstructorV2; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class RelationMsgConstructorFactory extends MsgConstructorFactory<RelationMsgConstructorV1, RelationMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.relation; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|||
import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class RelationMsgConstructorV2 implements RelationMsgConstructor { |
|||
|
|||
|
|||
@Override |
|||
public RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation) { |
|||
return RelationUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(entityRelation)).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.resource; |
|||
|
|||
import org.thingsboard.server.common.data.id.TbResourceId; |
|||
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
|
|||
public abstract class BaseResourceMsgConstructor implements ResourceMsgConstructor { |
|||
|
|||
@Override |
|||
public ResourceUpdateMsg constructResourceDeleteMsg(TbResourceId tbResourceId) { |
|||
return ResourceUpdateMsg.newBuilder() |
|||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|||
.setIdMSB(tbResourceId.getId().getMostSignificantBits()) |
|||
.setIdLSB(tbResourceId.getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.resource; |
|||
|
|||
import org.thingsboard.server.common.data.TbResource; |
|||
import org.thingsboard.server.common.data.id.TbResourceId; |
|||
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface ResourceMsgConstructor extends MsgConstructor { |
|||
|
|||
ResourceUpdateMsg constructResourceUpdatedMsg(UpdateMsgType msgType, TbResource tbResource); |
|||
|
|||
ResourceUpdateMsg constructResourceDeleteMsg(TbResourceId tbResourceId); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.resource; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class ResourceMsgConstructorFactory extends MsgConstructorFactory<ResourceMsgConstructorV1, ResourceMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.resource; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.TbResource; |
|||
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class ResourceMsgConstructorV2 extends BaseResourceMsgConstructor { |
|||
|
|||
@Override |
|||
public ResourceUpdateMsg constructResourceUpdatedMsg(UpdateMsgType msgType, TbResource tbResource) { |
|||
return ResourceUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tbResource)) |
|||
.setIdMSB(tbResource.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(tbResource.getId().getId().getLeastSignificantBits()).build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.rule; |
|||
|
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|||
|
|||
public class RuleChainMetadataConstructorV362 extends BaseRuleChainMetadataConstructor { |
|||
|
|||
@Override |
|||
protected void constructRuleChainMetadataUpdatedMsg(TenantId tenantId, RuleChainMetadataUpdateMsg.Builder builder, RuleChainMetaData ruleChainMetaData) { |
|||
builder.setEntity(JacksonUtil.toString(ruleChainMetaData)); |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.rule; |
|||
|
|||
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.gen.edge.v1.EdgeVersion; |
|||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface RuleChainMsgConstructor extends MsgConstructor { |
|||
|
|||
RuleChainUpdateMsg constructRuleChainUpdatedMsg(UpdateMsgType msgType, RuleChain ruleChain, boolean isRoot); |
|||
|
|||
RuleChainUpdateMsg constructRuleChainDeleteMsg(RuleChainId ruleChainId); |
|||
|
|||
RuleChainMetadataUpdateMsg constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|||
UpdateMsgType msgType, |
|||
RuleChainMetaData ruleChainMetaData, |
|||
EdgeVersion edgeVersion); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.rule; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class RuleChainMsgConstructorFactory extends MsgConstructorFactory<RuleChainMsgConstructorV1, RuleChainMsgConstructorV2> { |
|||
|
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.rule; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class RuleChainMsgConstructorV1 extends BaseRuleChainMsgConstructor { |
|||
|
|||
@Override |
|||
public RuleChainUpdateMsg constructRuleChainUpdatedMsg(UpdateMsgType msgType, RuleChain ruleChain, boolean isRoot) { |
|||
RuleChainUpdateMsg.Builder builder = RuleChainUpdateMsg.newBuilder() |
|||
.setMsgType(msgType) |
|||
.setIdMSB(ruleChain.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(ruleChain.getId().getId().getLeastSignificantBits()) |
|||
.setName(ruleChain.getName()) |
|||
.setRoot(isRoot) |
|||
.setDebugMode(ruleChain.isDebugMode()) |
|||
.setConfiguration(JacksonUtil.toString(ruleChain.getConfiguration())); |
|||
if (ruleChain.getFirstRuleNodeId() != null) { |
|||
builder.setFirstRuleNodeIdMSB(ruleChain.getFirstRuleNodeId().getId().getMostSignificantBits()) |
|||
.setFirstRuleNodeIdLSB(ruleChain.getFirstRuleNodeId().getId().getLeastSignificantBits()); |
|||
} |
|||
return builder.build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.rule; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
|||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class RuleChainMsgConstructorV2 extends BaseRuleChainMsgConstructor { |
|||
|
|||
@Override |
|||
public RuleChainUpdateMsg constructRuleChainUpdatedMsg(UpdateMsgType msgType, RuleChain ruleChain, boolean isRoot) { |
|||
boolean isTemplateRoot = ruleChain.isRoot(); |
|||
ruleChain.setRoot(isRoot); |
|||
RuleChainUpdateMsg result = RuleChainUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(ruleChain)) |
|||
.setIdMSB(ruleChain.getId().getId().getMostSignificantBits()) |
|||
.setIdLSB(ruleChain.getId().getId().getLeastSignificantBits()).build(); |
|||
ruleChain.setRoot(isTemplateRoot); |
|||
return result; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.settings; |
|||
|
|||
import org.thingsboard.server.common.data.AdminSettings; |
|||
import org.thingsboard.server.gen.edge.v1.AdminSettingsUpdateMsg; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|||
|
|||
public interface AdminSettingsMsgConstructor extends MsgConstructor { |
|||
|
|||
AdminSettingsUpdateMsg constructAdminSettingsUpdateMsg(AdminSettings adminSettings); |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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.edge.rpc.constructor.settings; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructorFactory; |
|||
|
|||
@Component |
|||
@TbCoreComponent |
|||
public class AdminSettingsMsgConstructorFactory extends MsgConstructorFactory<AdminSettingsMsgConstructorV1, AdminSettingsMsgConstructorV2> { |
|||
|
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue