3636import software .amazon .awssdk .services .iotsitewise .model .DescribePortalRequest ;
3737import software .amazon .awssdk .services .iotsitewise .model .GatewayPlatform ;
3838import software .amazon .awssdk .services .iotsitewise .model .GetAssetPropertyValueRequest ;
39- import software .amazon .awssdk .services .iotsitewise .model .GetAssetPropertyValueResponse ;
4039import software .amazon .awssdk .services .iotsitewise .model .GreengrassV2 ;
4140import software .amazon .awssdk .services .iotsitewise .model .ListAssetModelPropertiesRequest ;
4241import software .amazon .awssdk .services .iotsitewise .model .ListAssetModelsRequest ;
@@ -123,7 +122,7 @@ public CompletableFuture<CreateAssetModelResponse> createAssetModelAsync(String
123122 return getAsyncClient ().createAssetModel (createAssetModelRequest )
124123 .whenComplete ((response , exception ) -> {
125124 if (exception != null ) {
126- throw new RuntimeException ("Failed to create asset model: " + exception .getMessage (), exception );
125+ logger . error ("Failed to create asset model: {} " , exception .getMessage ());
127126 }
128127 });
129128 }
@@ -148,7 +147,7 @@ public CompletableFuture<CreateAssetResponse> createAssetAsync(String assetName,
148147 return getAsyncClient ().createAsset (createAssetRequest )
149148 .whenComplete ((response , exception ) -> {
150149 if (exception != null ) {
151- throw new RuntimeException ("Failed to create asset: " + exception .getMessage (), exception );
150+ logger . error ("Failed to create asset: {}" , exception .getMessage ());
152151 }
153152 });
154153 }
@@ -218,22 +217,24 @@ public CompletableFuture<BatchPutAssetPropertyValueResponse> sendDataToSiteWiseA
218217 /**
219218 * Fetches the value of an asset property.
220219 *
221- * @param propId the ID of the asset property to fetch.
222- * @param assetId the ID of the asset to fetch the property value for.
220+ * @param propId the ID of the asset property to fetch.
221+ * @param assetId the ID of the asset to fetch the property value for.
223222 * @throws RuntimeException if an error occurs while fetching the property value.
224223 */
225- public CompletableFuture <String > getAssetPropValueAsync (String propId , String assetId ) {
224+ public CompletableFuture <Double > getAssetPropValueAsync (String propId , String assetId ) {
226225 GetAssetPropertyValueRequest assetPropertyValueRequest = GetAssetPropertyValueRequest .builder ()
227226 .propertyId (propId )
228227 .assetId (assetId )
229228 .build ();
230229
231- CompletableFuture < GetAssetPropertyValueResponse > futureResponse = getAsyncClient ().getAssetPropertyValue (assetPropertyValueRequest );
232- return futureResponse . whenComplete ((response , exception ) -> {
230+ return getAsyncClient ().getAssetPropertyValue (assetPropertyValueRequest )
231+ . handle ((response , exception ) -> {
233232 if (exception != null ) {
234- throw new RuntimeException ("Error occurred while fetching property value: " + exception .getMessage (), exception );
233+ logger .error ("Error occurred while fetching property value: " + exception .getMessage (), exception );
234+ throw (RuntimeException ) exception ;
235235 }
236- }).thenApply (response -> String .valueOf (response .propertyValue ().value ().doubleValue ()));
236+ return response .propertyValue ().value ().doubleValue ();
237+ });
237238 }
238239 // snippet-end:[sitewise.java2_get_property.main]
239240
@@ -300,7 +301,7 @@ public CompletableFuture<DeleteAssetModelResponse> deleteAssetModelAsync(String
300301 return getAsyncClient ().deleteAssetModel (deleteAssetModelRequest )
301302 .whenComplete ((response , exception ) -> {
302303 if (exception != null ) {
303- throw new RuntimeException ("Failed to delete asset model with ID: " + assetModelId + ". Error: " + exception .getMessage (), exception );
304+ logger . error ("Failed to delete asset model with ID:{}." , exception .getMessage ());
304305 }
305306 });
306307 }
@@ -327,7 +328,7 @@ public CompletableFuture<String> createPortalAsync(String portalName, String iam
327328 .handle ((response , exception ) -> {
328329 if (exception != null ) {
329330 logger .error ("Failed to create portal: {} " , exception .getCause ().getMessage ());
330- throw (CompletionException ) exception ;
331+ throw (RuntimeException ) exception ;
331332 }
332333 return response .portalId ();
333334 });
@@ -350,7 +351,7 @@ public CompletableFuture<DeletePortalResponse> deletePortalAsync(String portalId
350351 return getAsyncClient ().deletePortal (deletePortalRequest )
351352 .whenComplete ((response , exception ) -> {
352353 if (exception != null ) {
353- throw new RuntimeException ("Failed to delete portal with ID: " + portalId + ". Error: " + exception .getMessage (), exception );
354+ logger . error ("Failed to delete portal with ID: " + portalId + ". Error: " + exception .getMessage (), exception );
354355 }
355356 });
356357 }
@@ -382,7 +383,7 @@ public CompletableFuture<String> getAssetModelIdAsync(String assetModelName) {
382383
383384 // snippet-start:[sitewise.java2.describe.portal.main]
384385 /**
385- * Asynchronously describes a portal.
386+ * Describes a portal.
386387 *
387388 * @param portalId the ID of the portal to describe.
388389 * @return a {@link CompletableFuture} that, when completed, will contain the URL of the described portal.
@@ -434,15 +435,15 @@ public CompletableFuture<String> createGatewayAsync(String gatewayName, String m
434435 logger .error ("Error creating the gateway." );
435436 throw (RuntimeException ) exception ;
436437 }
437- System . out . println ("The ARN of the gateway is " + response .gatewayArn ());
438+ logger . info ("The ARN of the gateway is {}" , response .gatewayArn ());
438439 return response .gatewayId ();
439440 });
440441 }
441442 // snippet-end:[sitewise.java2.create.gateway.main]
442443
443444 // snippet-start:[sitewise.java2.delete.gateway.main]
444445 /**
445- * Deletes the specified gateway asynchronously .
446+ * Deletes the specified gateway.
446447 *
447448 * @param gatewayARN the ARN of the gateway to delete.
448449 * @return a CompletableFuture containing the response of the delete operation.
@@ -456,7 +457,7 @@ public CompletableFuture<DeleteGatewayResponse> deleteGatewayAsync(String gatewa
456457 return getAsyncClient ().deleteGateway (deleteGatewayRequest )
457458 .whenComplete ((response , exception ) -> {
458459 if (exception != null ) {
459- throw new RuntimeException ("Failed to delete gateway: " + exception .getMessage (), exception );
460+ logger . error ("Failed to delete gateway: " + exception .getMessage (), exception );
460461 } else {
461462 logger .info ("The Gateway was deleted successfully." );
462463 }
@@ -466,7 +467,7 @@ public CompletableFuture<DeleteGatewayResponse> deleteGatewayAsync(String gatewa
466467
467468 // snippet-start:[sitewise.java2.describe.gateway.main]
468469 /**
469- * Asynchronously describes the specified gateway.
470+ * Describes the specified gateway.
470471 *
471472 * @param gatewayId the ID of the gateway to describe.
472473 * @return a {@link CompletableFuture} that represents the asynchronous operation
@@ -485,7 +486,6 @@ public CompletableFuture<DescribeGatewayResponse> describeGatewayAsync(String ga
485486 }
486487 });
487488 }
488-
489489 // snippet-end:[sitewise.java2.describe.gateway.main]
490490
491491 private static Map <String , Double > generateSampleData () {
0 commit comments