Search in sources :

Example 1 with DescribeAssetModelResponse

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

the class SiteWiseClientTest method testDescribeAssetModel.

/**
 ******DescribeAssetModel API tests**********
 */
@Test
public void testDescribeAssetModel() {
    // when
    when(ioTSiteWiseClient.describeAssetModel((DescribeAssetModelRequest) any())).thenReturn(describeAssetModelResponse);
    // then
    DescribeAssetModelResponse describeAssetModelResponse = siteWiseClient.describeAssetModel(SITE_WISE_ASSET_MODEL_ID);
    // verify
    assertEquals(describeAssetModelResponse.assetModelName(), SITE_WISE_ASSET_MODEL_NAME);
}
Also used : DescribeAssetModelResponse(software.amazon.awssdk.services.iotsitewise.model.DescribeAssetModelResponse) Test(org.junit.jupiter.api.Test)

Example 2 with DescribeAssetModelResponse

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

the class SiteWiseClient method isAssetInheritedFromAssetModel.

/**
 * Check whether given siteWiseAssetId belongs to given siteWiseAssetModel. Return true if asset's model contains
 * given siteWiseAssetModelPrefix, otherwise return false.
 * @param siteWiseAssetId siteWiseAssetId
 * @param siteWiseAssetModelPrefix siteWiseAssetModelPrefix
 * @return true|false
 * @throws EdgeConnectorForKVSException - EdgeConnectorForKVS generic exception
 */
public boolean isAssetInheritedFromAssetModel(@NonNull String siteWiseAssetId, @NonNull String siteWiseAssetModelPrefix) throws EdgeConnectorForKVSException {
    final DescribeAssetResponse describeAssetResponse;
    final String assetModelId;
    try {
        describeAssetResponse = describeAsset(siteWiseAssetId);
        assetModelId = describeAssetResponse.assetModelId();
        if (assetModelId != null) {
            DescribeAssetModelResponse describeAssetModelResponse = describeAssetModel(assetModelId);
            if (describeAssetModelResponse.assetModelName() != null) {
                return describeAssetModelResponse.assetModelName().startsWith(siteWiseAssetModelPrefix);
            } else {
                log.error(String.format("Could not find the model name for given siteWise assetId and siteWise " + "assetModel Id. Return false. siteWiseAssetId : %s, siteWiseAssetModelId : %s", siteWiseAssetId, assetModelId));
                return false;
            }
        } else {
            final String errorMessage = String.format("Could not find the model ID for given siteWiseAssetId. " + "Return false. siteWiseAssetId : %s", siteWiseAssetId);
            log.error(errorMessage);
            return false;
        }
    } catch (Exception e) {
        final String errorMessage = String.format("Failed to in isAssetBelongsAssetModel API call." + " siteWiseAssetId: %s, siteWiseAssetModelPrefix : %s", siteWiseAssetId, siteWiseAssetModelPrefix);
        log.error(errorMessage, e);
        throw new EdgeConnectorForKVSException(errorMessage, e);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) DescribeAssetResponse(software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse) DescribeAssetModelResponse(software.amazon.awssdk.services.iotsitewise.model.DescribeAssetModelResponse) EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)

Aggregations

DescribeAssetModelResponse (software.amazon.awssdk.services.iotsitewise.model.DescribeAssetModelResponse)2 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)1 Test (org.junit.jupiter.api.Test)1 DescribeAssetResponse (software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse)1