[onos-5251] This changeset contains implementation of purging intents from ONOS UI
[onos-5251] Addressed review comments from patchset-1
addressed review comments from patchset-2

Change-Id: I93ebe7798b5324fb18738540d3ef6cef6ada395e
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
index d48a089..fdfdd1b 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
@@ -150,6 +150,7 @@
     private static final String NAMES = "names";
     private static final String ACTIVATE = "activate";
     private static final String DEACTIVATE = "deactivate";
+    private static final String PURGE = "purge";
 
 
     private static final String MY_APP_ID = "org.onosproject.gui";
@@ -438,9 +439,7 @@
         Key key = Key.of(intentKey, applicId);
         log.debug("Attempting to select intent by key={}", key);
 
-        Intent intent = intentService.getIntent(key);
-
-        return intent;
+        return intentService.getIntent(key);
     }
 
     private final class RemoveIntent extends RequestHandler {
@@ -448,14 +447,22 @@
             super(REMOVE_INTENT);
         }
 
+        private boolean isIntentToBePurged(ObjectNode payload) {
+            return bool(payload, PURGE);
+        }
+
         @Override
         public void process(long sid, ObjectNode payload) {
             Intent intent = findIntentByPayload(payload);
             if (intent == null) {
                 log.warn("Unable to find intent from payload {}", payload);
             } else {
-                log.debug("Removing intent {}", intent.key());
-                intentService.withdraw(intent);
+                log.debug("Withdrawing / Purging intent {}", intent.key());
+                if (isIntentToBePurged(payload)) {
+                    intentService.purge(intent);
+                } else {
+                    intentService.withdraw(intent);
+                }
             }
         }
     }
diff --git a/web/gui/src/main/webapp/app/view/intent/intent.html b/web/gui/src/main/webapp/app/view/intent/intent.html
index 9c025f6..3fa441a 100644
--- a/web/gui/src/main/webapp/app/view/intent/intent.html
+++ b/web/gui/src/main/webapp/app/view/intent/intent.html
@@ -37,6 +37,11 @@
                  tooltip tt-msg="deactivateTip"
                  ng-click="(!!selId && isIntentInstalled()) ? deactivateIntent():''"></div>
 
+            <div ng-class="{'active': !!selId && isIntentWithdrawn()}"
+                 icon icon-id="garbage" icon-size="42"
+                 tooltip tt-msg="purgeTip"
+                 ng-click="(!!selId && isIntentWithdrawn()) ? purgeIntent():''"></div>
+
 
         </div>
     </div>
diff --git a/web/gui/src/main/webapp/app/view/intent/intent.js b/web/gui/src/main/webapp/app/view/intent/intent.js
index f241c83..1b49a98 100644
--- a/web/gui/src/main/webapp/app/view/intent/intent.js
+++ b/web/gui/src/main/webapp/app/view/intent/intent.js
@@ -72,6 +72,7 @@
 
             $scope.topoTip = 'Show selected intent on topology view';
             $scope.deactivateTip = 'Remove selected intent';
+            $scope.purgeTip = 'Purge selected intent';
 
             $scope.showIntent = function () {
                 var d = $scope.intentData;
@@ -82,14 +83,23 @@
                 return $scope.intentState === 'Installed';
             };
 
-            $scope.deactivateIntent = function () {
-                var content = ds.createDiv();
+            $scope.isIntentWithdrawn = function () {
+                return $scope.intentState === 'Withdrawn';
+            };
 
-                content.append('p')
-                    .text('Are you sure you want to remove the selected intent?');
+            function executeAction(bPurge) {
+                var content = ds.createDiv(),
+                    txt = bPurge ? 'purge' : 'withdraw' ;
+
+                $scope.intentData.intentPurge = bPurge;
+
+                content.append('p').
+                        text('Are you sure you want to '+ txt +
+                        ' the selected intent?');
 
                 function dOk() {
                     var d = $scope.intentData;
+                    $log.debug(d);
                     d && tts.removeIntent(d);
                     $scope.fired = true;
                 }
@@ -105,6 +115,14 @@
                     .addOk(dOk)
                     .addCancel(dCancel)
                     .bindKeys();
+            }
+
+            $scope.deactivateIntent = function () {
+                executeAction(false);
+            };
+
+            $scope.purgeIntent = function () {
+                executeAction(true);
             };
 
             $scope.briefToggle = function () {
diff --git a/web/gui/src/main/webapp/app/view/topo/topoTraffic.js b/web/gui/src/main/webapp/app/view/topo/topoTraffic.js
index 8b6085c..1836e1e 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoTraffic.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoTraffic.js
@@ -181,11 +181,13 @@
         wss.sendEvent('removeIntent', {
             appId: d.appId,
             appName: d.appName,
-            key: d.key
+            key: d.key,
+            purge: d.intentPurge
         });
         trafficMode = 'intents';
         hoverMode = null;
-        flash.flash('Intent removed');
+        var txt = d.intentPurge ? 'purged' : 'withdrawn';
+        flash.flash('Intent ' + txt);
     }
 
     function addMultiSourceIntent () {