Fix for ONOS-5406

Change-Id: I932e8efc3cb09b021316950a3104c62fe29e1dbc
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 609b775..bd344db 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
@@ -55,6 +55,8 @@
 import org.onosproject.net.intent.IntentListener;
 import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.MultiPointToSinglePointIntent;
+import org.onosproject.net.intent.IntentState;
+import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.link.LinkEvent;
 import org.onosproject.net.link.LinkListener;
 import org.onosproject.ui.JsonUtils;
@@ -101,6 +103,7 @@
     private static final String UPDATE_META = "updateMeta";
     private static final String ADD_HOST_INTENT = "addHostIntent";
     private static final String REMOVE_INTENT = "removeIntent";
+    private static final String REMOVE_INTENTS = "removeIntents";
     private static final String RESUBMIT_INTENT = "resubmitIntent";
     private static final String ADD_MULTI_SRC_INTENT = "addMultiSourceIntent";
     private static final String REQ_RELATED_INTENTS = "requestRelatedIntents";
@@ -223,6 +226,7 @@
                 new AddMultiSourceIntent(),
                 new RemoveIntent(),
                 new ResubmitIntent(),
+                new RemoveIntents(),
 
                 new ReqAllFlowTraffic(),
                 new ReqAllPortTraffic(),
@@ -507,6 +511,24 @@
         }
     }
 
+    private final class RemoveIntents extends RequestHandler {
+        private RemoveIntents() {
+            super(REMOVE_INTENTS);
+        }
+
+
+        @Override
+        public void process(ObjectNode payload) {
+            IntentService intentService = get(IntentService.class);
+            for (Intent intent : intentService.getIntents()) {
+                if (intentService.getIntentState(intent.key()) == IntentState.WITHDRAWN) {
+                    intentService.purge(intent);
+                }
+            }
+
+        }
+    }
+
     // ========= -----------------------------------------------------------------
 
     private final class ReqAllFlowTraffic extends RequestHandler {