[ONOS-6547] Add method to obtain intent's installables in REST API.
Change-Id: I80bbb25ecda292bb4f658d0d76fd49d7fabe8732
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
index 20b59f7..34b6864 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
@@ -98,6 +98,35 @@
}
/**
+ * Gets intent intallables by application ID and key.
+ * @param appId application identifier
+ * @param key intent key
+ *
+ * @return 200 OK with array of the intent installables
+ * @onos.rsModel Intents
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("installables/{appId}/{key}")
+ public Response getIntentWithInstallable(@PathParam("appId") String appId,
+ @PathParam("key") String key) {
+ final IntentService intentService = get(IntentService.class);
+ final ApplicationId app = get(CoreService.class).getAppId(appId);
+ nullIsNotFound(app, APP_ID_NOT_FOUND);
+
+ Intent intent = intentService.getIntent(Key.of(key, app));
+ if (intent == null) {
+ long numericalKey = Long.decode(key);
+ intent = intentService.getIntent(Key.of(numericalKey, app));
+ }
+ nullIsNotFound(intent, INTENT_NOT_FOUND);
+
+ final Iterable<Intent> installables = intentService.getInstallableIntents(intent.key());
+ final ObjectNode root = encodeArray(Intent.class, "installables", installables);
+ return ok(root).build();
+ }
+
+ /**
* Gets intent by application and key.
* Returns details of the specified intent.
*