throws Exception {
if (null == name || "".equals(name.trim())) {
throw new IllegalArgumentException("Invalid bundleName: " + name);
}
BundleType bundleType = entityManager.find(BundleType.class, bundleTypeId);
if (null == bundleType) {
throw new IllegalArgumentException("Invalid bundleTypeId: " + bundleTypeId);
}
bundleGroupIds = (null != bundleGroupIds) ? bundleGroupIds : new int[0];
List<BundleGroup> bundleGroups = new ArrayList<BundleGroup>(bundleGroupIds.length);
for (int bundleGroupId : bundleGroupIds) {
BundleGroup bundleGroup = entityManager.find(BundleGroup.class, bundleGroupId);
if (null == bundleGroup) {
throw new IllegalArgumentException("Invalid bundleGroupId: " + bundleGroupId);
}
bundleGroups.add(bundleGroup);
}
checkCreateInitialBundleVersionAuthz(subject, bundleGroupIds);
// create and add the required Repo. the Repo is a detached object which helps in its eventual removal.
Repo repo = new Repo(name);
repo.setCandidate(false);
repo.setSyncSchedule(null);
// create the repo as overlord, this allows users without MANAGE_INVENTORY permission to create bundles
repo = repoManager.createRepo(subjectManager.getOverlord(), repo);
// add the required PackageType. the PackageType is an attached object which helps in cascade removal
// of packages in the bundle's repo.
ResourceType resourceType = entityManager.find(ResourceType.class, bundleType.getResourceType().getId());
PackageType packageType = new PackageType(name, resourceType);
packageType.setDescription("Package type for content of bundle " + name);
packageType.setCategory(PackageCategory.BUNDLE);
packageType.setSupportsArchitecture(false);
packageType.setDisplayName(StringUtils.deCamelCase(name));