Search in sources :

Example 1 with AssociatedAssetsSummary

use of software.amazon.awssdk.services.iotsitewise.model.AssociatedAssetsSummary in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class SiteWiseClient method listAssociatedAssets.

/**
 * Return all Associated asset Id as String list
 * @param siteWiseAssetId siteWiseAssetId
 * @return List which contains associated asset id
 * @throws EdgeConnectorForKVSException - EdgeConnectorForKVS generic exception
 */
public List<String> listAssociatedAssets(@NonNull String siteWiseAssetId) throws EdgeConnectorForKVSException {
    try {
        List<String> assetHierarchiesIdList = getAssetHierarchiesIdList(siteWiseAssetId);
        List<String> result = new ArrayList<>();
        for (String hierarchiesId : assetHierarchiesIdList) {
            final ListAssociatedAssetsRequest listAssociatedAssetsRequest = ListAssociatedAssetsRequest.builder().assetId(siteWiseAssetId).hierarchyId(hierarchiesId).build();
            ListAssociatedAssetsResponse listAssociatedAssetsResponse = siteWiseClient.listAssociatedAssets(listAssociatedAssetsRequest);
            result.addAll(listAssociatedAssetsResponse.assetSummaries().stream().map(AssociatedAssetsSummary::id).collect(Collectors.toList()));
        }
        return result;
    } catch (Exception e) {
        final String errorMessage = String.format("Failed to getAssetHierarchiesIdList from given siteWiseAssetId, " + "please check EdgeConnectorForKVS configuration and ensure given provide SiteWise property " + "generated from EdgeConnectorForKVSHubDeviceModel. siteWiseAssetId : %s", siteWiseAssetId);
        log.error(errorMessage);
        throw new EdgeConnectorForKVSException(errorMessage);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) ArrayList(java.util.ArrayList) ListAssociatedAssetsRequest(software.amazon.awssdk.services.iotsitewise.model.ListAssociatedAssetsRequest) AssociatedAssetsSummary(software.amazon.awssdk.services.iotsitewise.model.AssociatedAssetsSummary) EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) ListAssociatedAssetsResponse(software.amazon.awssdk.services.iotsitewise.model.ListAssociatedAssetsResponse)

Aggregations

EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)1 ArrayList (java.util.ArrayList)1 AssociatedAssetsSummary (software.amazon.awssdk.services.iotsitewise.model.AssociatedAssetsSummary)1 ListAssociatedAssetsRequest (software.amazon.awssdk.services.iotsitewise.model.ListAssociatedAssetsRequest)1 ListAssociatedAssetsResponse (software.amazon.awssdk.services.iotsitewise.model.ListAssociatedAssetsResponse)1