/** * @param pName Package name to check if Kickstart Data contains * @return if package name is in this kickstart data */ public boolean hasKsPackage(PackageName pName) { for (KickstartPackage pack : ksPackages) { if (pName.equals(pack.getPackageName())) { return true; } } return false; }
/** * Create a package with the given name and add it to the given channel. If a package by that name * already exists, this simply returns that package. * * @param packageName The name of the package to create. * @param c The channel to which to add the package * @return The package with that name in the channel. * @throws Exception */ public static Package addPackageToChannel(String packageName, Channel c) throws Exception { PackageName pn = PackageFactory.lookupOrCreatePackageByName(packageName); if (pn == null) { pn = PackageNameTest.createTestPackageName(); pn.setName(packageName); } Long existingId = ChannelManager.getLatestPackageEqual(c.getId(), packageName); if (existingId != null) { return PackageFactory.lookupByIdAndOrg(existingId, c.getOrg()); } // existingId = Session session = HibernateFactory.getSession(); Query query = session.createQuery( "from Package as " + "package where package.org.id = " + c.getOrg().getId() + " and package.packageName.id = " + pn.getId()); List packages = query.list(); Package retval = null; if (packages != null && packages.size() > 0) { retval = (Package) packages.get(0); } else { retval = PackageTest.createTestPackage(c.getOrg()); } retval.setPackageName(pn); TestUtils.saveAndFlush(retval); PackageTest.addPackageToChannelNewestPackage(retval, c); return retval; }
/** * This method inserts a record into the rhnServerPackage mapping table to associate a given * Server with a particular Package. The web code doesn't actually create any of these records, * but this will be needed by the backend code. * * @param srvr Server to associate with the packages * @param pn The package name to associate * @param pe The package evr (version and release). */ public static void associateSystemToPackage(Server srvr, PackageName pn, PackageEvr pe) { try { WriteMode m = ModeFactory.getWriteMode("test_queries", "insert_into_rhnServerPackage"); Map params = new HashMap(); params.put("server_id", srvr.getId()); params.put("pn_id", pn.getId()); params.put("p_epoch", pe.getEpoch()); params.put("p_version", pe.getVersion()); params.put("p_release", pe.getRelease()); m.executeUpdate(params); } catch (Exception e) { e.printStackTrace(); } }