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);
}
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;
}
Aggregations