Fix for ONOS-5417:Issue with Creating Flows using POST flows REST API

Change-Id: Ie608f2ef0447fc8c2a73f46df0e5b195c333fcbf
(cherry picked from commit 3565ca6f5b2b46ee2fe9b93aa7d0ea4df592830b)
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
index fa5c3c7..e9f88ba 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
@@ -116,13 +116,14 @@
     @Produces(MediaType.APPLICATION_JSON)
     public Response createFlows(@QueryParam("appId") String appId, InputStream stream) {
         try {
+            final ApplicationService appService = get(ApplicationService.class);
+            final ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
             ArrayNode flowsArray = nullIsIllegal((ArrayNode) jsonTree.get(FLOWS),
                                                  FLOW_ARRAY_REQUIRED);
 
-            if (appId != null) {
-                flowsArray.forEach(flowJson -> ((ObjectNode) flowJson).put("appId", appId));
-            }
+            flowsArray.forEach(flowJson -> ((ObjectNode) flowJson).put("appId", idInstant.name()));
+
 
             List<FlowRule> rules = codec(FlowRule.class).decode(flowsArray, this);
 
@@ -253,6 +254,8 @@
                                @QueryParam("appId") String appId,
                                InputStream stream) {
         try {
+            final ApplicationService appService = get(ApplicationService.class);
+            final ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
             JsonNode specifiedDeviceId = jsonTree.get("deviceId");
             if (specifiedDeviceId != null &&
@@ -262,9 +265,7 @@
             }
             jsonTree.put("deviceId", deviceId);
 
-            if (appId != null) {
-                jsonTree.put("appId", appId);
-            }
+            jsonTree.put("appId", idInstant.name());
 
             FlowRule rule = codec(FlowRule.class).decode(jsonTree, this);
             service.applyFlowRules(rule);