use of software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class SiteWiseClientTest method testIsAssetInheritedFromAssetModel.
/**
******IsAssetInheritedFromAssetModel API tests**********
*/
@Test
public void testIsAssetInheritedFromAssetModel() {
// when
when(ioTSiteWiseClient.describeAsset((DescribeAssetRequest) any())).thenReturn(describeAssetResponse);
when(ioTSiteWiseClient.describeAssetModel((DescribeAssetModelRequest) any())).thenReturn(describeAssetModelResponse);
// then
boolean result = siteWiseClient.isAssetInheritedFromAssetModel(SITE_WISE_ASSET_ID, SITE_WISE_ASSET_MODEL_NAME_PREFIX);
// verify
assertTrue(result);
// then
result = siteWiseClient.isAssetInheritedFromAssetModel(SITE_WISE_ASSET_ID, SITE_WISE_ASSET_MODEL_NAME_PREFIX_WRONG);
// verify
assertFalse(result);
when(ioTSiteWiseClient.describeAsset((DescribeAssetRequest) any())).thenReturn(describeAssetResponse);
// then
DescribeAssetResponse describeAssetResponse = siteWiseClient.describeAsset(SITE_WISE_ASSET_ID);
// verify
assertEquals(describeAssetResponse.assetModelId(), SITE_WISE_ASSET_MODEL_ID);
}
use of software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class SiteWiseClient method getAssetHierarchiesIdList.
/**
* Return all AssetHierarchies Id as String list
* @param siteWiseAssetId siteWiseAssetId
* @return List which contains asset hierarchiesId
* @throws EdgeConnectorForKVSException - EdgeConnectorForKVS generic exception
*/
public List<String> getAssetHierarchiesIdList(@NonNull String siteWiseAssetId) throws EdgeConnectorForKVSException {
DescribeAssetResponse describeAssetResponse = describeAsset(siteWiseAssetId);
if (describeAssetResponse.hasAssetHierarchies()) {
return describeAssetResponse.assetHierarchies().stream().map(AssetHierarchy::id).collect(Collectors.toList());
} else {
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);
}
}
use of software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class SiteWiseManager method buildEdgeConnectorForKVSConfiguration.
private EdgeConnectorForKVSConfiguration buildEdgeConnectorForKVSConfiguration(String cameraSiteWiseAssetId) throws IllegalAccessException {
DescribeAssetResponse assetResponse = siteWiseClient.describeAsset(cameraSiteWiseAssetId);
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = new EdgeConnectorForKVSConfiguration();
edgeConnectorForKVSConfiguration.setSiteWiseAssetId(cameraSiteWiseAssetId);
for (AssetProperty assetProperty : assetResponse.assetProperties()) {
GetAssetPropertyValueResponse result;
Field[] fields = edgeConnectorForKVSConfiguration.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getName().equalsIgnoreCase(assetProperty.name())) {
result = siteWiseClient.getAssetPropertyValue(cameraSiteWiseAssetId, assetProperty.id());
if (result != null && result.propertyValue() != null) {
if (field.getType() == String.class) {
field.set(edgeConnectorForKVSConfiguration, result.propertyValue().value().stringValue());
break;
} else if (field.getType() == Integer.TYPE || field.getType() == Integer.class) {
field.set(edgeConnectorForKVSConfiguration, result.propertyValue().value().integerValue());
break;
}
}
}
}
if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_VIDEO_UPLOADED_TIME_RANGE_MEASUREMENT_NAME)) {
edgeConnectorForKVSConfiguration.setVideoUploadedTimeRangePropertyId(assetProperty.id());
}
if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_VIDEO_RECORDED_TIME_RANGE_MEASUREMENT_NAME)) {
edgeConnectorForKVSConfiguration.setVideoRecordedTimeRangePropertyId(assetProperty.id());
}
if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_CACHED_VIDEO_AGE_OUT_ON_EDGE_MEASUREMENT_NAME)) {
edgeConnectorForKVSConfiguration.setCachedVideoAgeOutOnEdgePropertyId(assetProperty.id());
}
if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_VIDEO_UPLOAD_REQUEST_MEASUREMENT_NAME)) {
if (assetProperty.notification().state() == PropertyNotificationState.ENABLED) {
edgeConnectorForKVSConfiguration.setVideoUploadRequestMqttTopic(assetProperty.notification().topic());
} else {
log.warn("Video Upload Request MQTT Notification Disabled for Asset Id " + cameraSiteWiseAssetId);
}
}
}
return edgeConnectorForKVSConfiguration;
}
use of software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class SiteWiseClientTest method testDescribeAsset.
/**
******DescribeAsset API tests**********
*/
@Test
public void testDescribeAsset() {
// when
when(ioTSiteWiseClient.describeAsset((DescribeAssetRequest) any())).thenReturn(describeAssetResponse);
// then
DescribeAssetResponse describeAssetResponse = siteWiseClient.describeAsset(SITE_WISE_ASSET_ID);
// verify
assertEquals(describeAssetResponse.assetModelId(), SITE_WISE_ASSET_MODEL_ID);
}
use of software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse 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);
}
}
Aggregations