package org.onap.policy.pap.main.comm;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 
         requests.stopPublishing();
 
-        // don't do anything if we don't have a group
-        String name = requests.getLastGroupName();
-        if (name == null) {
-            logger.warn("no group with which to disable {}", requests.getPdpName());
-            return;
+        // remove the PDP from all groups
+        try {
+            removeFromGroups(requests.getPdpName());
+        } catch (PfModelException e) {
+            logger.info("unable to remove PDP {} from subgroup", requests.getPdpName(), e);
         }
 
-        // remove the PDP from the group
-        removeFromGroup(requests.getPdpName(), name);
-
         // send the state change
         PdpStateChange change = new PdpStateChange();
         change.setName(requests.getPdpName());
     }
 
     /**
-     * Removes a PDP from its group.
+     * Removes a PDP from all active groups.
      *
      * @param pdpName name of the PDP to be removed
-     * @param groupName name of the group from which it should be removed
+     * @throws PfModelException if an error occurs
      */
-    private void removeFromGroup(String pdpName, String groupName) {
+    public void removeFromGroups(String pdpName) throws PfModelException {
 
         try (PolicyModelsProvider dao = daoFactory.create()) {
 
-            PdpGroupFilter filter = PdpGroupFilter.builder().name(groupName).groupState(PdpState.ACTIVE)
-                            .version(PdpGroupFilter.LATEST_VERSION).build();
-
+            PdpGroupFilter filter = PdpGroupFilter.builder().groupState(PdpState.ACTIVE).build();
             List<PdpGroup> groups = dao.getFilteredPdpGroups(filter);
-            if (groups.isEmpty()) {
-                return;
-            }
+            List<PdpGroup> updates = new ArrayList<>(1);
 
-            PdpGroup group = groups.get(0);
-
-            for (PdpSubGroup subgrp : group.getPdpSubgroups()) {
-                if (removeFromSubgroup(pdpName, group, subgrp)) {
-                    dao.updatePdpGroups(Collections.singletonList(group));
-                    return;
+            for (PdpGroup group : groups) {
+                if (removeFromGroup(pdpName, group)) {
+                    updates.add(group);
                 }
             }
 
-        } catch (PfModelException e) {
-            logger.info("unable to remove PDP {} from subgroup", pdpName, e);
+            if (!updates.isEmpty()) {
+                dao.updatePdpGroups(updates);
+            }
         }
     }
 
+    /**
+     * Removes a PDP from a group.
+     *
+     * @param pdpName name of the PDP to be removed
+     * @param group group from which it should be removed
+     * @return {@code true} if the PDP was removed from the, {@code false} if it was not
+     *         assigned to the group
+     */
+    private boolean removeFromGroup(String pdpName, PdpGroup group) {
+        for (PdpSubGroup subgrp : group.getPdpSubgroups()) {
+            if (removeFromSubgroup(pdpName, group, subgrp)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /**
      * Removes a PDP from a subgroup.
      *
      * @param subgrp subgroup from which to attempt to remove the PDP
      * @return {@code true} if the PDP was removed, {@code false} if the PDP was not in
      *         the group
-     * @throws PfModelException if a DB error occurs
      */
-    private boolean removeFromSubgroup(String pdpName, PdpGroup group, PdpSubGroup subgrp) throws PfModelException {
+    private boolean removeFromSubgroup(String pdpName, PdpGroup group, PdpSubGroup subgrp) {
 
         Iterator<Pdp> iter = subgrp.getPdpInstances().iterator();
 
 
 
 import lombok.Getter;
 import org.onap.policy.models.pdp.concepts.PdpMessage;
-import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.pap.main.comm.msgdata.Request;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
      */
     private Request[] singletons = new Request[MAX_PRIORITY];
 
-    /**
-     * Last group name to which the associated PDP was assigned.
-     */
-    @Getter
-    private String lastGroupName;
-
 
     /**
      * Constructs the object.
         this.pdpName = pdpName;
     }
 
-    /**
-     * Records the group information from the request.
-     *
-     * @param request the request from which to extract the group information
-     */
-    private void recordGroup(Request request) {
-        PdpMessage message = request.getMessage();
-        if (message instanceof PdpUpdate) {
-            lastGroupName = message.getPdpGroup();
-        }
-    }
-
     /**
      * Adds a singleton request.
      *
             throw new IllegalArgumentException("unexpected broadcast for " + pdpName);
         }
 
-        recordGroup(request);
-
         if (checkExisting(request)) {
             // have an existing request that's similar - discard this request
             return;
 
     public void testDisablePdp() {
         map.addRequest(update);
 
-        when(requests.getLastGroupName()).thenReturn(MY_GROUP);
-
         // indicate failure
         invokeFailureHandler(1);
 
         map.addRequest(change);
         map.stopPublishing(PDP1);
 
-        when(requests.getLastGroupName()).thenReturn(MY_GROUP);
-
         invokeFailureHandler(1);
 
         // should not have stopped publishing a second time
     public void testRemoveFromGroup() throws Exception {
         map.addRequest(change);
 
-        when(requests.getLastGroupName()).thenReturn(MY_GROUP);
-
         PdpGroup group = makeGroup(MY_GROUP, MY_VERSION);
         group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP + "a", PDP1 + "a"),
                         makeSubGroup(MY_SUBGROUP, PDP1), makeSubGroup(MY_SUBGROUP + "c", PDP1 + "c")));
     public void testRemoveFromGroup_DaoEx() throws Exception {
         map.addRequest(change);
 
-        when(requests.getLastGroupName()).thenReturn(MY_GROUP);
-
         when(dao.getFilteredPdpGroups(any())).thenThrow(new PfModelException(Status.BAD_REQUEST, "expected exception"));
 
         invokeFailureHandler(1);
     public void testRemoveFromGroup_NoGroups() throws Exception {
         map.addRequest(change);
 
-        when(requests.getLastGroupName()).thenReturn(MY_GROUP);
-
         invokeFailureHandler(1);
 
         verify(dao, never()).updatePdpGroups(any());
     public void testRemoveFromGroup_NoMatchingSubgroup() throws Exception {
         map.addRequest(change);
 
-        when(requests.getLastGroupName()).thenReturn(MY_GROUP);
-
         PdpGroup group = makeGroup(MY_GROUP, MY_VERSION);
         group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP, DIFFERENT)));
 
     public void testRemoveFromSubgroup() throws Exception {
         map.addRequest(change);
 
-        when(requests.getLastGroupName()).thenReturn(MY_GROUP);
-
         PdpGroup group = makeGroup(MY_GROUP, MY_VERSION);
         group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP, PDP1, PDP1 + "x", PDP1 + "y")));
 
 
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.never;
         assertEquals(PDP1, data.getPdpName());
     }
 
-    @Test
-    public void testRecordGroup_testGetLatestGroupXxx() {
-        assertNull(data.getLastGroupName());
-
-        data.addSingleton(update);
-        assertEquals(MY_GROUP, data.getLastGroupName());
-
-        UpdateReq req = makeUpdateReq(PDP1, MY_GROUP, MY_SUBGROUP);
-        req.getMessage().setPdpGroup(DIFFERENT);
-        data.addSingleton(req);
-        assertEquals(DIFFERENT, data.getLastGroupName());
-
-        // doesn't record info from other message types
-        StateChangeReq req2 = change;
-        req2.getMessage().setPdpGroup(MY_GROUP);
-        data.addSingleton(req2);
-
-        // should be unchanged
-        assertEquals(DIFFERENT, data.getLastGroupName());
-    }
-
     @Test
     public void testAddSingleton() {
         data.addSingleton(update);