Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1206084] Delete all the BundleDestinations before removing Resour…
Browse files Browse the repository at this point in the history
…ceGroup
  • Loading branch information
Michael Burman committed Oct 14, 2015
1 parent aa79ebd commit a7fc733
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -59,6 +59,7 @@
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.authz.Role;
import org.rhq.core.domain.bundle.BundleDestination;
import org.rhq.core.domain.configuration.PluginConfigurationUpdate;
import org.rhq.core.domain.configuration.ResourceConfigurationUpdate;
import org.rhq.core.domain.criteria.GroupOperationHistoryCriteria;
Expand Down Expand Up @@ -88,6 +89,7 @@
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.authz.PermissionException;
import org.rhq.enterprise.server.authz.RequiredPermission;
import org.rhq.enterprise.server.bundle.BundleManagerLocal;
import org.rhq.enterprise.server.operation.OperationManagerLocal;
import org.rhq.enterprise.server.resource.ResourceManagerLocal;
import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal;
Expand All @@ -109,6 +111,8 @@ public class ResourceGroupManagerBean implements ResourceGroupManagerLocal, Reso
@PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME)
private EntityManager entityManager;

@EJB
private BundleManagerLocal bundleManager;
@EJB
//@IgnoreDependency
private OperationManagerLocal operationManager;
Expand Down Expand Up @@ -314,6 +318,15 @@ public void deleteResourceGroup(Subject subject, int groupId) throws ResourceGro
q.setParameter("groupId", group.getId());
q.executeUpdate();

// Delete all the bundleDestinations to avoid FK issues
for (BundleDestination bundleDestination : group.getBundleDestinations()) {
try {
bundleManager.deleteBundleDestination(subject, bundleDestination.getId());
} catch (Exception e) {
throw new RuntimeException("Could not delete bundle destination " + bundleDestination.toString(), e);
}
}

entityManager.remove(group);
}

Expand Down

0 comments on commit a7fc733

Please sign in to comment.