API Reference
Overview
The Beaver IoT platform provides a set of common service interfaces for integration developers to implement their business logic. These services include integration services, device services, entity services, and entity value services.
DeviceServiceProvider API Documentation
The Beaver IoT platform offers the DeviceServiceProvider
interface, which provides common methods for device operations.
save
Save a device (including the entities under the device).
Method Signature
void save(Device device);
deleteById
Delete a device by its ID.
Method Signature
void deleteById(Long id);
findById
Find a device by its ID.
Method Signature
Device findById(Long id);
findByKey
Find a device by its key.
Method Signature
Device findByKey(String deviceKey);
findByIdentifier
Find a device by its identifier.
Method Signature
Device findByIdentifier(String identifier, String integrationId);
findAll
Find all devices by integration ID.
Method Signature
List<Device> findAll(String integrationId);
EntityServiceProvider API Documentation
The Beaver IoT platform offers the EntityServiceProvider
interface, which provides common methods for entity operations.
findByTargetId
Find a list of entities by target type and target ID.
Target includes Device AttachTargetType.DEVICE
and Integration AttachTargetType.INTEGRATION
.
Method Signature
List<Entity> findByTargetId(AttachTargetType targetType, String targetId);
findByTargetIds
Find a list of entities by target type and a list of target IDs.
Method Signature
List<Entity> findByTargetIds(AttachTargetType targetType, List<String> targetIds);
save
Save an entity.
Method Signature
void save(Entity entity);
batchSave
Save a list of entities in batch.
Method Signature
void batchSave(List<Entity> entityList);
deleteByTargetId
Delete entities by target ID.
Method Signature
void deleteByTargetId(String targetId);
findByKey
Find an entity by its key.
Method Signature
Entity findByKey(String entityKey);
findByKeys
Find entities by a list of keys.
Method Signature
Map<String, Entity> findByKeys(String... entityKeys);
findById
Find an entity by its ID.
Method Signature
Entity findById(Long entityId);
findByIds
Find entities by a list of IDs.
Method Signature
List<Entity> findByIds(List<Long> ids);
EntityValueServiceProvider API Documentation
The Beaver IoT platform offers the EntityValueServiceProvider
interface, which provides common methods for operating on the latest and historical values of entities.
saveValuesAndPublishSync
Save entity values and publish events synchronously.
Method Signature
Using default event type:
EventResponse saveValuesAndPublishSync(ExchangePayload exchangePayload);
Custom event type:
EventResponse saveValuesAndPublishSync(ExchangePayload exchangePayload, String eventType);
saveValuesAndPublishAsync
Save entity values and publish events asynchronously.
Method Signature
Using default event type:
EventResponse saveValuesAndPublishAsync(ExchangePayload exchangePayload);
Custom event type:
EventResponse saveValuesAndPublishAsync(ExchangePayload exchangePayload, String eventType);
saveValues
Save the latest values of entities.
Method Signature
void saveValues(Map<String, Object> values, long timestamp);
saveValues
Save the latest values of entities (with the current time as the reporting time).
Method Signature
void saveValues(Map<String, Object> values);
saveHistoryRecord
Save historical values of entities.
Method Signature
void saveHistoryRecord(Map<String, Object> recordValues, long timestamp);
saveHistoryRecord
Save historical values of entities (with the current time as the reporting time).
Method Signature
void saveHistoryRecord(Map<String, Object> recordValues);
findValueByKey
Retrieve the current value based on the entity key
Method Signature
Object findValueByKey(String key);
findValuesByKeys
Retrieve the current values based on a collection of entity keys
Method Signature
Map<String, Object> findValuesByKeys(List<String> keys);
findValuesByKey
Retrieve the current values of child entities under a parent entity based on the entity key
Method Signature
@NonNull <T extends ExchangePayload> T findValuesByKey(String key, Class<T> entitiesClazz);
IntegrationServiceProvider API Documentation
The IntegrationServiceProvider
interface defines operations related to integration configurations.
save
Save an integration (including the entities under the integration).
Method Signature
void save(Integration integrationConfig);
batchSave
Save integrations in batch.
Method Signature
void batchSave(Collection<Integration> integrationConfig);
getIntegration
Get an integration instance by its ID (including disabled instances).
Method Signature
Integration getIntegration(String integrationId);
getActiveIntegration
Get an active integration instance by its ID.
Method Signature
Integration getActiveIntegration(String integrationId);
findIntegrations
Find all integration instances.
Method Signature
Collection<Integration> findIntegrations();
findActiveIntegrations
Find all active integration instances.
Method Signature
List<Integration> findActiveIntegrations();
findIntegrationsWithPredicate
Find integration instances based on a condition.
Method Signature
List<Integration> findIntegrations(Predicate<Integration> predicate);
Code Example
Find all integrations that can add devices:
List<Integration> integrations = integrationServiceProvider.findIntegrations(f -> StringUtils.hasText(f.getEntityKeyAddDevice()));