Search in sources :

Example 1 with ClaimData

use of org.thingsboard.server.dao.device.claim.ClaimData in project thingsboard by thingsboard.

the class ClaimDevicesServiceImpl method persistInCache.

private void persistInCache(String secretKey, long durationMs, Cache cache, List<Object> key) {
    ClaimData claimData = new ClaimData(secretKey, System.currentTimeMillis() + validateDurationMs(durationMs));
    cache.putIfAbsent(key, claimData);
}
Also used : ClaimData(org.thingsboard.server.dao.device.claim.ClaimData)

Example 2 with ClaimData

use of org.thingsboard.server.dao.device.claim.ClaimData in project thingsboard by thingsboard.

the class ClaimDevicesServiceImpl method getClaimData.

private ClaimDataInfo getClaimData(Cache cache, Device device) throws ExecutionException, InterruptedException {
    List<Object> key = constructCacheKey(device.getId());
    ClaimData claimDataFromCache = cache.get(key, ClaimData.class);
    if (claimDataFromCache != null) {
        return new ClaimDataInfo(true, key, claimDataFromCache);
    } else {
        Optional<AttributeKvEntry> claimDataAttr = attributesService.find(device.getTenantId(), device.getId(), DataConstants.SERVER_SCOPE, CLAIM_DATA_ATTRIBUTE_NAME).get();
        if (claimDataAttr.isPresent()) {
            try {
                ClaimData claimDataFromAttribute = mapper.readValue(claimDataAttr.get().getValueAsString(), ClaimData.class);
                return new ClaimDataInfo(false, key, claimDataFromAttribute);
            } catch (IOException e) {
                log.warn("Failed to read Claim Data [{}] from attribute!", claimDataAttr, e);
            }
        }
    }
    return null;
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) ClaimData(org.thingsboard.server.dao.device.claim.ClaimData) ClaimDataInfo(org.thingsboard.server.dao.device.ClaimDataInfo) IOException(java.io.IOException)

Aggregations

ClaimData (org.thingsboard.server.dao.device.claim.ClaimData)2 IOException (java.io.IOException)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)1 ClaimDataInfo (org.thingsboard.server.dao.device.ClaimDataInfo)1