/** * This does not set the inverse relationship. You may want {@link BundleGroup#addBundle(Bundle)}. * @param bundleGroup */ public void addBundleGroup(BundleGroup bundleGroup) { getBundleGroups().add(bundleGroup); }
/** * This does not set the inverse relationship. You may want {@link BundleGroup#removeBundle(Bundle)}. * @param bundleGroup * @return true if bundle group is removed, otherwise false */ public boolean removeBundleGroup(BundleGroup bundleGroup) { return getBundleGroups().remove(bundleGroup); }
private Map<BundleGroup, Boolean> populateBundleGroupMap(List<BundleGroup> bundleGroups, Bundle bundle) { Map<BundleGroup, Boolean> result = new HashMap<BundleGroup, Boolean>(bundleGroups.size()); for (BundleGroup bundleGroup : bundleGroups) { Boolean assigned = ((null != bundle) && bundle.getBundleGroups().contains(bundleGroup)) ? Boolean.TRUE : Boolean.FALSE; result.put(bundleGroup, assigned); } return result; } }
@Override @SuppressWarnings("unchecked") public void deleteBundle(Subject subject, int bundleId) throws Exception { Bundle bundle = this.entityManager.find(Bundle.class, bundleId); if (null == bundle) { return; } checkDeleteBundleAuthz(subject, bundleId); Query q = entityManager.createNamedQuery(BundleVersion.QUERY_FIND_BY_BUNDLE_ID); q.setParameter("bundleId", bundleId); List<BundleVersion> bvs = q.getResultList(); for (BundleVersion bv : bvs) { bundleManager.deleteBundleVersion(subject, bv.getId(), false); entityManager.flush(); } // remove bundle from any assigned bundle groups // wrap in new HashSet to avoid ConcurrentModificationExceptions. Set<BundleGroup> BundleGroupsToRemove = new HashSet<BundleGroup>(bundle.getBundleGroups()); for (BundleGroup bg : BundleGroupsToRemove) { bg.removeBundle(bundle); } // we need to whack the Repo once the Bundle no longer refers to it Repo bundleRepo = bundle.getRepo(); this.entityManager.remove(bundle); this.entityManager.flush(); // delete the repo as overlord, this allows users without MANAGE_INVENTORY permission to delete bundles repoManager.deleteRepo(subjectManager.getOverlord(), bundleRepo.getId()); }