Search in sources :

Example 21 with DeviceProfileId

use of org.thingsboard.server.common.data.id.DeviceProfileId in project thingsboard by thingsboard.

the class DefaultEdgeRequestsService method processDeviceProfileDevicesRequestMsg.

@Override
public ListenableFuture<Void> processDeviceProfileDevicesRequestMsg(TenantId tenantId, Edge edge, DeviceProfileDevicesRequestMsg deviceProfileDevicesRequestMsg) {
    log.trace("[{}] processDeviceProfileDevicesRequestMsg [{}][{}]", tenantId, edge.getName(), deviceProfileDevicesRequestMsg);
    if (deviceProfileDevicesRequestMsg.getDeviceProfileIdMSB() != 0 && deviceProfileDevicesRequestMsg.getDeviceProfileIdLSB() != 0) {
        DeviceProfileId deviceProfileId = new DeviceProfileId(new UUID(deviceProfileDevicesRequestMsg.getDeviceProfileIdMSB(), deviceProfileDevicesRequestMsg.getDeviceProfileIdLSB()));
        DeviceProfile deviceProfileById = deviceProfileService.findDeviceProfileById(tenantId, deviceProfileId);
        if (deviceProfileById != null) {
            syncDevices(tenantId, edge, deviceProfileById.getName());
        }
    }
    return Futures.immediateFuture(null);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) UUID(java.util.UUID)

Example 22 with DeviceProfileId

use of org.thingsboard.server.common.data.id.DeviceProfileId in project thingsboard by thingsboard.

the class DeviceProfileEdgeProcessor method processDeviceProfileToEdge.

public DownlinkMsg processDeviceProfileToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    DeviceProfileId deviceProfileId = new DeviceProfileId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
            DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(edgeEvent.getTenantId(), deviceProfileId);
            if (deviceProfile != null) {
                DeviceProfileUpdateMsg deviceProfileUpdateMsg = deviceProfileMsgConstructor.constructDeviceProfileUpdatedMsg(msgType, deviceProfile);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceProfileUpdateMsg(deviceProfileUpdateMsg).build();
            }
            break;
        case DELETED:
            DeviceProfileUpdateMsg deviceProfileUpdateMsg = deviceProfileMsgConstructor.constructDeviceProfileDeleteMsg(deviceProfileId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceProfileUpdateMsg(deviceProfileUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId)

Example 23 with DeviceProfileId

use of org.thingsboard.server.common.data.id.DeviceProfileId in project thingsboard by thingsboard.

the class DeviceController method countByDeviceProfileAndEmptyOtaPackage.

@ApiOperation(value = "Count devices by device profile  (countByDeviceProfileAndEmptyOtaPackage)", notes = "The platform gives an ability to load OTA (over-the-air) packages to devices. " + "It can be done in two different ways: device scope or device profile scope." + "In the response you will find the number of devices with specified device profile, but without previously defined device scope OTA package. " + "It can be useful when you want to define number of devices that will be affected with future OTA package" + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/devices/count/{otaPackageType}/{deviceProfileId}", method = RequestMethod.GET)
@ResponseBody
public Long countByDeviceProfileAndEmptyOtaPackage(@ApiParam(value = "OTA package type", allowableValues = "FIRMWARE, SOFTWARE") @PathVariable("otaPackageType") String otaPackageType, @ApiParam(value = "Device Profile Id. I.g. '784f394c-42b6-435a-983c-b7beff2784f9'") @PathVariable("deviceProfileId") String deviceProfileId) throws ThingsboardException {
    checkParameter("OtaPackageType", otaPackageType);
    checkParameter("DeviceProfileId", deviceProfileId);
    try {
        return deviceService.countDevicesByTenantIdAndDeviceProfileIdAndEmptyOtaPackage(getTenantId(), new DeviceProfileId(UUID.fromString(deviceProfileId)), OtaPackageType.valueOf(otaPackageType));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) IOException(java.io.IOException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with DeviceProfileId

use of org.thingsboard.server.common.data.id.DeviceProfileId in project thingsboard by thingsboard.

the class DeviceController method getTenantDeviceInfos.

@ApiOperation(value = "Get Tenant Device Infos (getTenantDeviceInfos)", notes = "Returns a page of devices info objects owned by tenant. " + PAGE_DATA_PARAMETERS + DEVICE_INFO_DESCRIPTION + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/tenant/deviceInfos", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<DeviceInfo> getTenantDeviceInfos(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize, @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page, @ApiParam(value = DEVICE_TYPE_DESCRIPTION) @RequestParam(required = false) String type, @ApiParam(value = DEVICE_PROFILE_ID_PARAM_DESCRIPTION) @RequestParam(required = false) String deviceProfileId, @ApiParam(value = DEVICE_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = DEVICE_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 {
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
        if (type != null && type.trim().length() > 0) {
            return checkNotNull(deviceService.findDeviceInfosByTenantIdAndType(tenantId, type, pageLink));
        } else if (deviceProfileId != null && deviceProfileId.length() > 0) {
            DeviceProfileId profileId = new DeviceProfileId(toUUID(deviceProfileId));
            return checkNotNull(deviceService.findDeviceInfosByTenantIdAndDeviceProfileId(tenantId, profileId, pageLink));
        } else {
            return checkNotNull(deviceService.findDeviceInfosByTenantId(tenantId, pageLink));
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) PageLink(org.thingsboard.server.common.data.page.PageLink) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) IOException(java.io.IOException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with DeviceProfileId

use of org.thingsboard.server.common.data.id.DeviceProfileId in project thingsboard by thingsboard.

the class DeviceProfileController method getAttributesKeys.

@ApiOperation(value = "Get attribute keys (getAttributesKeys)", notes = "Get a set of unique attribute keys used by devices that belong to specified profile. " + "If profile is not set returns a list of unique keys among all profiles. " + "The call is used for auto-complete in the UI forms. " + "The implementation limits the number of devices that participate in search to 100 as a trade of between accurate results and time-consuming queries. " + TENANT_AUTHORITY_PARAGRAPH, produces = "application/json")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/deviceProfile/devices/keys/attributes", method = RequestMethod.GET)
@ResponseBody
public List<String> getAttributesKeys(@ApiParam(value = DEVICE_PROFILE_ID_PARAM_DESCRIPTION) @RequestParam(name = DEVICE_PROFILE_ID, required = false) String deviceProfileIdStr) throws ThingsboardException {
    DeviceProfileId deviceProfileId;
    if (StringUtils.isNotEmpty(deviceProfileIdStr)) {
        deviceProfileId = new DeviceProfileId(UUID.fromString(deviceProfileIdStr));
        checkDeviceProfileId(deviceProfileId, Operation.READ);
    } else {
        deviceProfileId = null;
    }
    try {
        return attributesService.findAllKeysByDeviceProfileId(getTenantId(), deviceProfileId);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)33 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)12 UUID (java.util.UUID)9 DeviceId (org.thingsboard.server.common.data.id.DeviceId)9 ApiOperation (io.swagger.annotations.ApiOperation)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Device (org.thingsboard.server.common.data.Device)8 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 OtaPackageId (org.thingsboard.server.common.data.id.OtaPackageId)4 TenantId (org.thingsboard.server.common.data.id.TenantId)4 IOException (java.io.IOException)3 EntityType (org.thingsboard.server.common.data.EntityType)3 PageLink (org.thingsboard.server.common.data.page.PageLink)3 TransportDeviceInfo (org.thingsboard.server.common.transport.auth.TransportDeviceInfo)3 ByteString (com.google.protobuf.ByteString)2 ExecutionException (java.util.concurrent.ExecutionException)2 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2