// Check authorization
checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId());
// Create the PackageVersion the BundleFile is tied to. This implicitly creates the
// Package for the PackageVersion.
Bundle bundle = bundleVersion.getBundle();
PackageType packageType = bundle.getPackageType();
architecture = (null == architecture) ? contentManager.getNoArchitecture() : architecture;
if (architecture.getId() == 0) {
Query q = entityManager.createNamedQuery(Architecture.QUERY_FIND_BY_NAME);
q.setParameter("name", architecture.getName());
architecture = (Architecture) q.getSingleResult();
}
PackageVersion packageVersion = contentManager.createPackageVersionWithDisplayVersion(subject, name,
packageType.getId(), version, null, architecture.getId(), fileStream);
// set the PackageVersion's filename to the bundleFile name, it's left null by default
packageVersion.setFileName(name);
packageVersion = entityManager.merge(packageVersion);
// Create the mapping between the Bundle's Repo and the BundleFile's PackageVersion
Repo repo = bundle.getRepo();
// add the packageVersion as overlord, this allows users without MANAGE_INVENTORY permission to add bundle files
repoManager.addPackageVersionsToRepo(subjectManager.getOverlord(), repo.getId(),
new int[] { packageVersion.getId() });
// Classify the Package with the Bundle name in order to distinguish it from the same package name for
// a different bundle.
Package generalPackage = packageVersion.getGeneralPackage();
generalPackage.setClassification(bundle.getName());
// With all the plumbing in place, create and persist the BundleFile. Tie it to the Package if the caller
// wants this BundleFile pinned to themost recent version.
BundleFile bundleFile = new BundleFile();
bundleFile.setBundleVersion(bundleVersion);