java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java | 2300 ++++----- java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java | 2461 +++++----- 2 files changed, 2381 insertions(+), 2380 deletions(-)
New commits: commit 03b7fe7457601a4fc0d31b49895a1fc62b18170e Author: Justin Sherrill jsherril@redhat.com Date: Wed Feb 1 10:45:56 2012 -0500
checkstyle fixes
diff --git a/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java b/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java index 6c4595e..8e81fe6 100644 --- a/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java +++ b/java/code/src/com/redhat/rhn/domain/errata/ErrataFactory.java @@ -72,1156 +72,1156 @@ import com.redhat.rhn.manager.errata.cache.ErrataCacheManager; */ public class ErrataFactory extends HibernateFactory {
- private static ErrataFactory singleton = new ErrataFactory(); - private static Logger log = Logger.getLogger(ErrataFactory.class); - - public static final String ERRATA_TYPE_BUG = "Bug Fix Advisory"; - public static final String ERRATA_TYPE_ENHANCEMENT = "Product Enhancement Advisory"; - public static final String ERRATA_TYPE_SECURITY = "Security Advisory"; - - public static final String ERRATA_TYPE_SECURITY_CRIT = "Security Advisory (Critical)"; - public static final String ERRATA_TYPE_SECURITY_IMP = "Security Advisory (Important)"; - public static final String ERRATA_TYPE_SECURITY_MOD = "Security Advisory (Moderate)"; - public static final String ERRATA_TYPE_SECURITY_LOW = "Security Advisory (Low)"; - - private ErrataFactory() { - super(); - } - - /** - * Get the Logger for the derived class so log messages - * show up on the correct class - */ - @Override - protected Logger getLogger() { - return log; - } - - /** - * List the package ids that were pushed to a channel because of an errata - * @param cid the channel id - * @param eid the errata id - * @return List of package ids - */ - public static List<Long> listErrataChannelPackages(Long cid, Long eid) { - Map params = new HashMap(); - params.put("channel_id", cid); - params.put("errata_id", eid); - DataResult<ErrataPackageFile> dr = executeSelectMode( - "ErrataCache_queries", - "package_associated_to_errata_and_channel", params); - List toReturn = new ArrayList<Long>(); - for (ErrataPackageFile file : dr) { - toReturn.add(file.getPackageId()); - } - return toReturn; - } - - /** - * List the package ids that are associated with an errata - * associated with given channel - * @param channelId channel of interest - * @param errataIds list of errata ids - * @return List of package ids - */ - public static List<Long> listErrataChannelPackages(Long channelId, - Set<Long> errataIds) { - SelectMode m = ModeFactory.getMode("Errata_queries", - "packageids_associated_to_errata"); - Map params = new HashMap(); - params.put("channel_id", channelId); - DataResult<ErrataPackageFile> dr = m.execute(params, new ArrayList(errataIds)); - // make the final list unique - Set toReturn = new HashSet<Long>(); - for (ErrataPackageFile file : dr) { - toReturn.add(file.getPackageId()); - } - return new ArrayList(toReturn); - } - - /** - * Tries to locate errata based on either the errataum's id or the - * CVE/CAN identifier string. - * @param identifier erratum id or CVE/CAN id string - * @return list of erratas found - */ - public static List lookupByIdentifier(String identifier) { - Long eid = null; - List retval = new LinkedList(); - Errata errata = null; - try { - eid = new Long(Long.parseLong(identifier)); - } - catch (NumberFormatException e) { - eid = null; - } - if (eid != null) { - errata = ErrataFactory.lookupPublishedErrataById(eid); - if (errata != null) { - retval.add(errata); - } - } - else if (identifier.length() > 4) { - String prefix = null; - errata = ErrataFactory.lookupByAdvisoryId(identifier); - if (errata != null) { - retval.add(errata); - } - else { - errata = ErrataFactory.lookupByAdvisory(identifier); - if (errata != null) { - retval.add(errata); - } - } - if (errata == null) { - prefix = identifier.substring(0, 4); - if (prefix.matches("RH.A")) { - StringTokenizer strtok = new StringTokenizer(identifier, "-"); - StringBuffer buf = new StringBuffer(); - boolean foundFirst = false; - while (strtok.hasMoreTokens()) { - buf.append(strtok.nextToken()); - if (!foundFirst) { - buf.append("-"); - foundFirst = true; - } - else { - if (strtok.hasMoreTokens()) { - buf.append(":"); - } - } - } - identifier = buf.toString(); - errata = ErrataFactory.lookupByAdvisoryId(identifier); - } - if (errata != null) { - retval.add(errata); - } - } - if (errata == null) { - prefix = identifier.substring(0, 3); - if ((prefix.equals("CVE") || prefix.equals("CAN")) && - identifier.length() > 7 && identifier.indexOf('-') == -1) { - identifier = identifier.substring(0, 3) + "-" + - identifier.substring(3, 7) + "-" + - identifier.substring(7); - } - List erratas = ErrataFactory.lookupByCVE(identifier); - retval.addAll(erratas); - } - } - return retval; - } - - /** - * publish takes an unpublished errata and copies its contents into a Published Errata - * object (and then returns this object). This method also handles removing the old - * Unpublished Errata object and child elements from the db. - * @param unpublished The Errata to publish - * @return Returns a published errata. - */ - public static Errata publish(Errata unpublished) { - //Make sure the errata we're publishing is unpublished - if (unpublished.isPublished()) { - return unpublished; //there is nothing we can do here - } - //Create a published errata using unpublished - - Errata published; - - if (unpublished.isCloned()) { - published = new PublishedClonedErrata(); - ((PublishedClonedErrata)published).setOriginal( - ((UnpublishedClonedErrata)unpublished).getOriginal()); - } - else { - published = ErrataFactory.createPublishedErrata(); - } - - copyDetails(published, unpublished, false); - - //Save the published Errata - save(published); - - //Remove the unpublished Errata from db - try { - Session session = HibernateFactory.getSession(); - session.delete(unpublished); - } - catch (HibernateException e) { - throw new HibernateRuntimeException( - "Errors occurred while publishing errata", e); - } - - //return the published errata - return published; - } - - - /** - * Takes a published or unpublished errata and publishes to a channel, creating - * all of the correct ErrataFile* entries. This method does push packages to - * the appropriate channel. (Appropriate as defined as the channel previously - * having a package with the same name). - * @param errata errataList list of errata to publish - * @param chan channel to publish it into. - * @param user the user doing the pushing - * @param inheritPackages include only original channel packages - * @return the publsihed errata - */ - public static List<Errata> publishToChannel(List<Errata> errataList, Channel chan, - User user, boolean inheritPackages) { - List<com.redhat.rhn.domain.errata.Errata> toReturn = new ArrayList<Errata>(); - for (Errata errata : errataList) { - if (!errata.isPublished()) { - errata = publish(errata); - } - errata.addChannel(chan); - errata.addChannelNotification(chan, new Date()); - - Set<Package> packagesToPush = new HashSet<Package>(); - DataResult<PackageOverview> packs; - if (inheritPackages) { - - if (!chan.isCloned()) { - throw new InvalidChannelException("Cloned channel expected: " + - chan.getLabel()); - } - Channel original = ((ClonedChannel) chan).getOriginal(); - packs = ErrataManager.listErrataChannelPacks(original, errata, user); - } - else { - packs = ErrataManager.lookupPacksFromErrataForChannel(chan, errata, user); - } - - for (PackageOverview packOver : packs) { - //lookup the Package object - Package pack = PackageFactory.lookupByIdAndUser( - packOver.getId().longValue(), user); - packagesToPush.add(pack); - } - - Errata e = publishErrataPackagesToChannel(errata, chan, user, packagesToPush); - toReturn.add(e); - } - postPublishActions(chan, user); - return toReturn; - } - - - - /** - * Publish an errata to a channel but only push a small set of packages - * along with it - * - * @param errata errata to publish - * @param chan channel to publish it into. - * @param user the user doing the pushing - * @param packages the packages to push - * @return the published errata - */ - public static Errata publishToChannel(Errata errata, Channel chan, - User user, Set<Package> packages) { - if (!errata.isPublished()) { - errata = publish(errata); - } - errata.addChannel(chan); - errata = publishErrataPackagesToChannel(errata, chan, user, packages); - postPublishActions(chan, user); - return errata; - } - - - private static void postPublishActions(Channel chan, User user) { - ChannelManager.refreshWithNewestPackages(chan, "web.errata_push"); - ChannelManager.queueChannelChange(chan.getLabel(), - "java::publishErrataPackagesToChannel", user.getLogin()); - } - - - /** - * Private helper method that pushes errata packages to a channel - */ - private static Errata publishErrataPackagesToChannel(Errata errata, - Channel chan, User user, Set<Package> packages) { - // Much quicker to push all packages at once - List<Long> pids = new ArrayList<Long>(); - for (Package pack : packages) { - pids.add(pack.getId()); - } - ChannelManager.addPackages(chan, pids, user); - - for (Package pack : packages) { - List<ErrataFile> publishedFiles = ErrataFactory.lookupErrataFile( - errata, pack); - Map<String, ErrataFile> toAdd = new HashMap(); - if (publishedFiles.size() == 0) { - // Now create the appropriate ErrataFile object - ErrataFile publishedFile = ErrataFactory - .createPublishedErrataFile(ErrataFactory - .lookupErrataFileType("RPM"), pack - .getChecksum().getChecksum(), pack - .getNameEvra()); - publishedFile.addPackage(pack); - publishedFile.setErrata(errata); - publishedFile.setModified(new Date()); - ((PublishedErrataFile) publishedFile).addChannel(chan); - singleton.saveObject(publishedFile); - } - else { - for (ErrataFile publishedFile : publishedFiles) { - String fileName = publishedFile.getFileName().substring( - publishedFile.getFileName().lastIndexOf("/") + 1); - if (!toAdd.containsKey(fileName)) { - toAdd.put(fileName, publishedFile); - ((PublishedErrataFile) publishedFile).addChannel(chan); - singleton.saveObject(publishedFile); - } - } - } - - } - ChannelFactory.save(chan); - List chanList = new ArrayList(); - chanList.add(chan.getId()); - - ErrataCacheManager.insertCacheForChannelErrataAsync(chanList, errata); - - return errata; - } - - /** - * @param org Org performing the cloning - * @param e Errata to be cloned - * @return clone of e - */ - public static Errata createClone(Org org, Errata e) { - - - String baseClonedAdvisoryName = "CL" + e.getAdvisoryName().substring(3); - String baseClonedAdvisory = "CL" + e.getAdvisory().substring(3); - String clonedAdvisory = baseClonedAdvisory; - String clonedAdvisoryName = baseClonedAdvisoryName; - boolean unusedNameFound = false; - - - for (int j = 1; !unusedNameFound; ++j) { - Errata advisoryNameMatch = lookupByAdvisory(clonedAdvisoryName); - Errata advisoryMatch = lookupByAdvisoryId(clonedAdvisory); - - if ((advisoryNameMatch == null) && (advisoryMatch == null)) { - unusedNameFound = true; - } - else { - clonedAdvisoryName = baseClonedAdvisoryName + '-' + j; - clonedAdvisory = baseClonedAdvisory + '-' + j; - } - } - - UnpublishedClonedErrata clone = new UnpublishedClonedErrata(); - - copyDetails(clone, e, true); - - clone.setAdvisoryName(clonedAdvisoryName); - clone.setAdvisory(clonedAdvisory); - clone.setOriginal(e); - clone.setOrg(org); - - save(clone); - return clone; - } - - /** - * Helper method to copy the details for. - * @param copy The object to copy into. - * @param original The object to copy from. - * @param clone set to true if this is a cloned errata, and thus - * things like org or advisory name shouldn't be set - */ - private static void copyDetails(Errata copy, Errata original, boolean clone) { - - //Set the easy things first ;) - - if (!clone) { - copy.setAdvisory(original.getAdvisory()); - copy.setAdvisoryName(original.getAdvisoryName()); - copy.setOrg(original.getOrg()); - } - - copy.setAdvisoryType(original.getAdvisoryType()); - copy.setProduct(original.getProduct()); - copy.setErrataFrom(original.getErrataFrom()); - copy.setDescription(original.getDescription()); - copy.setSynopsis(original.getSynopsis()); - copy.setTopic(original.getTopic()); - copy.setSolution(original.getSolution()); - copy.setIssueDate(original.getIssueDate()); - copy.setUpdateDate(original.getUpdateDate()); - copy.setNotes(original.getNotes()); - copy.setRefersTo(original.getRefersTo()); - copy.setAdvisoryRel(original.getAdvisoryRel()); - copy.setLocallyModified(original.getLocallyModified()); - copy.setLastModified(original.getLastModified()); - - - /* - * Copy the packages - * packages aren't published or unpublished exactly... that is determined - * by the status of the errata... - */ - copy.setPackages(new HashSet(original.getPackages())); - - /* - * Copy the keywords - * if we use the string version of addKeyword, we don't have to worry about - * whether or not the keyword is published. - */ - Iterator keysItr = IteratorUtils.getIterator(original.getKeywords()); - while (keysItr.hasNext()) { - Keyword k = (Keyword) keysItr.next(); - copy.addKeyword(k.getKeyword()); - } - - - /* - * Copy the bugs. If copy is published, then the bugs should be published as well. - * If not, then we want unpublished bugs. - */ - Iterator bugsItr = IteratorUtils.getIterator(original.getBugs()); - while (bugsItr.hasNext()) { - Bug bugIn = (Bug) bugsItr.next(); - Bug cloneB; - if (copy.isPublished()) { //we want published bugs - cloneB = ErrataManager.createNewPublishedBug(bugIn.getId(), - bugIn.getSummary(), - bugIn.getUrl()); - } - else { //we want unpublished bugs - cloneB = ErrataManager.createNewUnpublishedBug(bugIn.getId(), - bugIn.getSummary(), - bugIn.getUrl()); - } - copy.addBug(cloneB); - } - } - - /** - * Create a new PublishedErrata from scratch - * @return the PublishedErrata created - */ - public static Errata createPublishedErrata() { - return new PublishedErrata(); - } - - /** - * Create a new UnpublishedErrata - * @return the UnpublishedErrata created - */ - public static Errata createUnpublishedErrata() { - return new UnpublishedErrata(); - } - - /** - * Creates a new Unpublished Bug object with the given id and summary. - * @param id The id for the new bug - * @param summary The summary for the new bug - * @param url The bug URL - * @return The new unpublished bug. - */ - public static Bug createUnpublishedBug(Long id, String summary, String url) { - Bug bug = new UnpublishedBug(); - bug.setId(id); - bug.setSummary(summary); - bug.setUrl(url); - return bug; - } - - /** - * Creates a new Published Bug object with the given id and summary. - * @param id The id for the new bug - * @param summary The summary for the new bug - * @param url The bug URL - * @return The new published bug. - */ - public static Bug createPublishedBug(Long id, String summary, String url) { - Bug bug = new PublishedBug(); - bug.setId(id); - bug.setSummary(summary); - bug.setUrl(url); - return bug; - } - - /** - * Creates a new Unpublished Errata file with given ErrataFileType, checksum, and name - * @param ft ErrataFileType for the new ErrataFile - * @param cs MD5 Checksum for the new Errata File - * @param name name for the file - * @return new Unpublished Errata File - */ - public static ErrataFile createUnpublishedErrataFile(ErrataFileType ft, - String cs, - String name) { - return createUnpublishedErrataFile(ft, cs, name, new HashSet()); - } - - /** - * Creates a new Unpublished Errata file with given ErrataFileType, checksum, and name - * @param ft ErrataFileType for the new ErrataFile - * @param cs MD5 Checksum for the new Errata File - * @param name name for the file - * @param packages Packages associated with this errata file. - * @return new Unpublished Errata File - */ - public static ErrataFile createUnpublishedErrataFile(ErrataFileType ft, - String cs, - String name, - Set packages) { - ErrataFile file = new UnpublishedErrataFile(); - file.setFileType(ft); - file.setChecksum(ChecksumFactory.safeCreate(cs, "md5")); - file.setFileName(name); - file.setPackages(packages); - return file; - } - - /** - * Creates a new Published Errata file with given ErrataFileType, checksum, and name - * @param ft ErrataFileType for the new ErrataFile - * @param cs MD5 Checksum for the new Errata File - * @param name name for the file - * @return new Published Errata File - */ - public static ErrataFile createPublishedErrataFile(ErrataFileType ft, - String cs, - String name) { - return createPublishedErrataFile(ft, cs, name, new HashSet()); - } - - /** - * Creates a new Published Errata file with given ErrataFileType, checksum, and name - * @param ft ErrataFileType for the new ErrataFile - * @param cs MD5 Checksum for the new Errata File - * @param name name for the file - * @param packages Packages associated with this errata file. - * @return new Published Errata File - */ - public static ErrataFile createPublishedErrataFile(ErrataFileType ft, - String cs, - String name, - Set packages) { - ErrataFile file = new PublishedErrataFile(); - file.setFileType(ft); - file.setChecksum(ChecksumFactory.safeCreate(cs, "md5")); - file.setFileName(name); - file.setPackages(packages); - return file; - } - - /** - * Lookup a ErrataFileType based on a label - * @param label file type label (RPM, IMG, etc) - * @return ErrataFileType instance - */ - public static ErrataFileType lookupErrataFileType(String label) { - Session session = null; - ErrataFileType retval = null; - try { - session = HibernateFactory.getSession(); - retval = (ErrataFileType) session.getNamedQuery("ErrataFileType.findByLabel") - .setString("label", label).setCacheable(true).uniqueResult(); - } - catch (HibernateException e) { - throw new HibernateRuntimeException(e.getMessage(), e); - } - return retval; - } - - /** - * Lookup ErrataFiles by errata and file type - * @param errataId errata id - * @param fileType file type label - * @return list of ErrataFile instances - */ - public static List lookupErrataFilesByErrataAndFileType(Long errataId, - String fileType) { - Session session = null; - List retval = null; - try { - session = HibernateFactory.getSession(); - Query q = session.getNamedQuery("PublishedErrataFile.listByErrataAndFileType"); - q.setLong("errata_id", errataId.longValue()); - q.setString("file_type", fileType.toUpperCase()); - retval = q.list(); - - if (retval == null) { - q = session.getNamedQuery("UnpublishedErrataFile.listByErrataAndFileType"); - q.setLong("errata_id", errataId.longValue()); - q.setString("file_type", fileType.toUpperCase()); - retval = q.list(); - } - } - catch (HibernateException e) { - throw new HibernateRuntimeException(e.getMessage(), e); - } - return retval; - - - } - - - /** - * Lookup a Errata by their id - * @param id the id to search for - * @return the Errata found - */ - public static Errata lookupById(Long id) { - //Look for published Errata first - Session session = HibernateFactory.getSession(); - Errata errata = (Errata) session.get(PublishedErrata.class, id); - - //If we nothing was found, look for it in the Unpublished Errata table... - if (errata == null) { - errata = (Errata) session.get(UnpublishedErrata.class, id); - } - return errata; - } - - /** - * Lookup a Errata by the advisoryType string - * @param advisoryType to search for - * @return the Errata found - */ - public static List lookupErratasByAdvisoryType(String advisoryType) { - Session session = null; - List retval = null; - try { - session = HibernateFactory.getSession(); - retval = session.getNamedQuery("PublishedErrata.findByAdvisoryType") - .setString("type", advisoryType) - //Retrieve from cache if there - .setCacheable(true).list(); - } - catch (HibernateException he) { - log.error("Error loading ActionArchTypes from DB", he); - throw new - HibernateRuntimeException("Error loading ActionArchTypes from db"); - } - return retval; - } - - /** - * Lookup a Security Errata by the synopsis string - * @param synopsis to search for - * @return the Errata found - */ - public static List lookupErratasBySynopsis(String synopsis) { - Session session = null; - List retval = null; - try { - session = HibernateFactory.getSession(); - retval = session.getNamedQuery("PublishedErrata.findSecurityBySynopsis") - .setString("type", ERRATA_TYPE_SECURITY) - .setString("synopsis", synopsis) - //Retrieve from cache if there - .setCacheable(true).list(); - } - catch (HibernateException he) { - log.error("Error loading ActionArchTypes from DB", he); - throw new - HibernateRuntimeException("Error loading ActionArchTypes from db"); - } - return retval; - } - - /** - * Finds published errata by id - * @param id errata id - * @return Errata if found, otherwise null - */ - public static Errata lookupPublishedErrataById(Long id) { - Session session = null; - Errata retval = null; - try { - session = HibernateFactory.getSession(); - retval = (Errata) session.getNamedQuery("PublishedErrata.findById") - .setLong("id", id.longValue()).uniqueResult(); - } - catch (HibernateException he) { - log.error("Error loading ActionArchTypes from DB", he); - throw new - HibernateRuntimeException("Error loading ActionArchTypes from db"); - } - return retval; - } - - /** - * Look up an errata by the advisory name. This is a unique field in the db and this - * method is needed to help us see if a created/edited advisoryName is unique. - * @param advisory The advisory to lookup - * @return Returns the errata corresponding to the passed in advisory name. - */ - public static Errata lookupByAdvisory(String advisory) { - Session session = null; - Errata retval = null; - // try { - //look for a published errata first - session = HibernateFactory.getSession(); - retval = (Errata) session.getNamedQuery("PublishedErrata.findByAdvisoryName") - .setString("advisory", advisory) - .uniqueResult(); - //if nothing was found, check the unpublished errata table - if (retval == null) { - retval = (Errata) - session.getNamedQuery("UnpublishedErrata.findByAdvisoryName") - .setString("advisory", advisory) - .uniqueResult(); - } - // } - // catch (HibernateException e) { - // throw new - // HibernateRuntimeException("Error looking up errata by advisory name"); - // } - return retval; - } - - /** - * Finds errata based on advisory id - * @param advisoryId errata advisory id - * @return Errata if found, otherwise null - */ - public static Errata lookupByAdvisoryId(String advisoryId) { - Session session = null; - Errata retval = null; - try { - //look for a published errata first - session = HibernateFactory.getSession(); - retval = (Errata) session.getNamedQuery("PublishedErrata.findByAdvisory") - .setString("advisory", advisoryId) - .uniqueResult(); - - if (retval == null) { - retval = (Errata) - session.getNamedQuery("UnpublishedErrata.findByAdvisory") - .setString("advisory", advisoryId) - .uniqueResult(); - } - } - catch (HibernateException e) { - - throw new - HibernateRuntimeException("Error looking up errata by advisory name"); - } - return retval; - } - - /** - * Finds errata based on CVE string - * @param cve cve text - * @return Errata if found, otherwise null - */ - public static List lookupByCVE(String cve) { - List retval = new LinkedList(); - SelectMode mode = ModeFactory.getMode("Errata_queries", "erratas_for_cve"); - Map params = new HashMap(); - params.put("cve", cve); - List result = mode.execute(params); - Session session = HibernateFactory.getSession(); - for (Iterator iter = result.iterator(); iter.hasNext();) { - Map row = (Map) iter.next(); - Long rawId = (Long) row.get("id"); - retval.add(session.load(PublishedErrata.class, rawId)); - } - return retval; - } - - /** - * Lookup all the clones of a particular errata - * @param org Org that the clones belongs to - * @param original Original errata that the clones are clones of - * @return list of clones of the errata - */ - public static List lookupByOriginal(Org org, Errata original) { - Session session = null; - List retval = null; - - try { - session = HibernateFactory.getSession(); - retval = session. - getNamedQuery("UnpublishedClonedErrata.findByOriginal") - .setParameter("original", original) - .setParameter("org", org).list(); - - if (retval == null) { - retval = lookupPublishedByOriginal(org, original); - } - - } - catch (HibernateException e) { - throw new - HibernateRuntimeException("Error looking up errata by original errata"); - } - return retval; - } - - /** - * Lookup all the clones of a particular errata - * @param org Org that the clones belongs to - * @param original Original errata that the clones are clones of - * @return list of clones of the errata - */ - public static List lookupPublishedByOriginal(Org org, Errata original) { - Session session = null; - List retval = null; - - try { - session = HibernateFactory.getSession(); - retval = session.getNamedQuery("PublishedClonedErrata.findByOriginal") - .setParameter("original", original) - .setParameter("org", org).list(); - } - catch (HibernateException e) { - throw new - HibernateRuntimeException("Error looking up errata by original errata"); - } - return retval; - } - - /** - * Lists errata present in both channels - * @param org orgaznization - * @param channelFrom channel1 - * @param channelTo channel2 - * @return list of errata - */ - public static List listSamePublishedInChannels(Org org, Channel channelFrom, - Channel channelTo) { - Session session = null; - List retval = null; - - try { - session = HibernateFactory.getSession(); - retval = session.getNamedQuery("PublishedErrata.findSameInChannels") - .setParameter("channel_from", channelFrom) - .setParameter("channel_to", channelTo).list(); - } - catch (HibernateException e) { - throw new - HibernateRuntimeException("Error looking up errata by original errata"); - } - return retval; - } - - /** - * Lists errata from channelFrom, that are cloned from the same original - * as errata in channelTo - * @param org orgaznization - * @param channelFrom channel1 - * @param channelTo channel2 - * @return list of errata - */ - public static List listPublishedBrothersInChannels(Org org, Channel channelFrom, - Channel channelTo) { - Session session = null; - List retval = null; - - try { - session = HibernateFactory.getSession(); - retval = session.getNamedQuery("PublishedClonedErrata.findBrothersInChannel") - .setParameter("channel_from", channelFrom) - .setParameter("channel_to", channelTo).list(); - } - catch (HibernateException e) { - throw new - HibernateRuntimeException("Error looking up errata by original errata"); - } - return retval; - } - - /** - * Lists errata from channelFrom, that have clones in channelTo - * @param org orgaznization - * @param channelFrom channel1 - * @param channelTo channel2 - * @return list of errata - */ - public static List listPublishedClonesInChannels(Org org, Channel channelFrom, - Channel channelTo) { - Session session = null; - List retval = null; - - try { - session = HibernateFactory.getSession(); - retval = session.getNamedQuery("PublishedErrata.findClonesInChannel") - .setParameter("channel_from", channelFrom) - .setParameter("channel_to", channelTo) - .list(); - } - catch (HibernateException e) { - throw new - HibernateRuntimeException("Error looking up errata by original errata"); - } - return retval; - } - - /** - * Insert or Update a Errata. - * @param errataIn Errata to be stored in database. - */ - public static void save(Errata errataIn) { - singleton.saveObject(errataIn); - } - - /** - * Delete a bug - * @param deleteme Bug to delete - */ - public static void removeBug(Bug deleteme) { - singleton.removeObject(deleteme); - } - - /** - * Delete a Keyword - * @param deleteme Keyword to delete - */ - public static void remove(Keyword deleteme) { - singleton.removeObject(deleteme); - } - - - /** - * Remove a file. - * @param deleteme ErrataFile to delete - */ - public static void removeFile(ErrataFile deleteme) { - singleton.removeObject(deleteme); - } - - - /** - * Lists errata assigned to a particular channel, - * sorted by date (from oldest to newest) - * @param org the Org in question - * @param channel the channel you want to get the errata for - * @return A list of Errata objects - */ - public static List lookupByChannelSorted(Org org, Channel channel) { - - return HibernateFactory.getSession(). - getNamedQuery("PublishedErrata.lookupSortedByChannel") - .setParameter("org", org) - .setParameter("channel", channel) - .list(); - } - - /** - * Lists errata assigned to a particular channel between - * the given start and end date. The list is sorted by date - * (from oldest to newest). - * @param org the Org in question - * @param channel the channel you want to get the errata for - * @param startDate the start date - * @param endDate the end date - * @return A list of Errata objects - */ - public static List<Errata> lookupByChannelBetweenDates(Org org, Channel channel, - String startDate, String endDate) { - - return HibernateFactory.getSession(). - getNamedQuery("PublishedErrata.lookupByChannelBetweenDates") - .setParameter("org", org) - .setParameter("channel", channel) - .setParameter("start_date", startDate) - .setParameter("end_date", endDate) - .list(); - } - - /** - * Lookup errata that are in the set "errata_list" - * @param user the user to search the set for - * @param set the set to look in - * @return List of Errata - */ - public static List<Errata> lookupErrataInSet(User user, String set) { - - Map params = new HashMap(); - params.put("uid", user.getId()); - params.put("set", set); - return singleton.listObjectsByNamedQuery( - "PublishedErrata.lookupFromSet", params); - } - - - - /** - * Lookup an errataFile object by it's errata and package - * @param errata the errata associated - * @param pack the package associated - * @return the requested errata file object - */ - public static List<ErrataFile> lookupErrataFile(Errata errata, Package pack) { - Map params = new HashMap(); - params.put("errata", errata); - params.put("package", pack); - return singleton.listObjectsByNamedQuery( - "PublishedErrataFile.lookupByErrataAndPackage", params); - } - - /** - * Returns a list of ErrataOverview that match the given errata ids. - * @param eids Errata ids. - * @param org Organization to match results with - * @return a list of ErrataOverview that match the given errata ids. - */ - public static List<ErrataOverview> search(List eids, Org org) { - Map params = new HashMap(); - params.put("eids", eids); - params.put("org_id", org.getId()); - List results = singleton.listObjectsByNamedQuery( - "PublishedErrata.searchById", params); - List<ErrataOverview> errata = new ArrayList<ErrataOverview>(); - for (Object result : results) { - Object[] values = (Object[]) result; - ErrataOverview eo = new ErrataOverview(); - // e.id, e.advisory, e.advisoryName, e.advisoryType, e.synopsis, e.updateDate - eo.setId((Long)values[0]); - eo.setAdvisory((String)values[1]); - eo.setAdvisoryName((String)values[2]); - eo.setAdvisoryType((String)values[3]); - eo.setAdvisorySynopsis((String)values[4]); - eo.setUpdateDate((Date)values[5]); - eo.setIssueDate((Date)values[6]); - errata.add(eo); - } - - return errata; - } - - /** - * Returns a list of ErrataOverview of Errata that match the given Package - * ids. - * @param pids Package ids whose Errata are being sought. - * @return a list of ErrataOverview of Errata that match the given Package - * ids. - */ - public static List<ErrataOverview> searchByPackageIds(List pids) { - Map params = new HashMap(); - params.put("pids", pids); - if (log.isDebugEnabled()) { - log.debug("pids = " + pids); - } - List results = singleton.listObjectsByNamedQuery( - "PublishedErrata.searchByPackageIds", params); - if (log.isDebugEnabled()) { - log.debug("Query 'PublishedErrata.searchByPackageIds' returned " + - results.size() + " entries"); - } - List<ErrataOverview> errata = new ArrayList<ErrataOverview>(); - Long lastId = null; - ErrataOverview eo = null; - for (Object result : results) { - Object[] values = (Object[]) result; - // e.id, e.advisory, e.advisoryName, e.advisoryType, e.synopsis, e.updateDate - Long curId = (Long)values[0]; - - if (!curId.equals(lastId)) { - eo = new ErrataOverview(); - } - eo.setId((Long)values[0]); - eo.setAdvisory((String)values[1]); - eo.setAdvisoryName((String)values[2]); - eo.setAdvisoryType((String)values[3]); - eo.setAdvisorySynopsis((String)values[4]); - eo.setUpdateDate((Date)values[5]); - eo.setIssueDate((Date)values[6]); - eo.addPackageName((String)values[7]); - if (!curId.equals(lastId)) { - errata.add(eo); - lastId = curId; - } - if (log.isDebugEnabled()) { - log.debug("curId = " + curId + ", lastId = " + lastId); - log.debug("ErrataOverview formed: " + eo.getAdvisoryName() + " for " + - eo.getPackageNames()); - } - } - - return errata; - } - - - /** - * Returns a list of ErrataOverview of Errata that match the given Package - * ids. - * @param pids Package ids whose Errata are being sought. - * @param org Organization to match results with - * @return a list of ErrataOverview of Errata that match the given Package - * ids. - */ - public static List<ErrataOverview> searchByPackageIdsWithOrg(List pids, Org org) { - Map params = new HashMap(); - params.put("pids", pids); - params.put("org_id", org.getId()); - if (log.isDebugEnabled()) { - log.debug("org_id = " + org.getId()); - log.debug("pids = " + pids); - } - List results = singleton.listObjectsByNamedQuery( - "PublishedErrata.searchByPackageIdsWithOrg", params); - if (log.isDebugEnabled()) { - log.debug("Query 'PublishedErrata.searchByPackageIdsWithOrg' returned " + - results.size() + " entries"); - } - List<ErrataOverview> errata = new ArrayList<ErrataOverview>(); - Long lastId = null; - ErrataOverview eo = null; - for (Object result : results) { - Object[] values = (Object[]) result; - // e.id, e.advisory, e.advisoryName, e.advisoryType, e.synopsis, e.updateDate - Long curId = (Long)values[0]; - - if (!curId.equals(lastId)) { - eo = new ErrataOverview(); - } - eo.setId((Long)values[0]); - eo.setAdvisory((String)values[1]); - eo.setAdvisoryName((String)values[2]); - eo.setAdvisoryType((String)values[3]); - eo.setAdvisorySynopsis((String)values[4]); - eo.setUpdateDate((Date)values[5]); - eo.setIssueDate((Date)values[6]); - eo.addPackageName((String)values[7]); - if (!curId.equals(lastId)) { - errata.add(eo); - lastId = curId; - } - if (log.isDebugEnabled()) { - log.debug("curId = " + curId + ", lastId = " + lastId); - log.debug("ErrataOverview formed: " + eo.getAdvisoryName() + " for " + - eo.getPackageNames()); - } - } - - return errata; - } - - - /** - * Sync all the errata details from one errata to another - * @param cloned the cloned errata that needs syncing - */ - public static void syncErrataDetails(PublishedClonedErrata cloned) { - copyDetails(cloned, cloned.getOriginal(), true); - } - - /** - * List errata objects by ID - * @param ids list of ids - * @return List of Errata Objects - */ - public static List<Errata> listErrata(Collection<Long> ids) { - return singleton.listObjectsByNamedQuery("PublishedErrata.listByIds", - new HashMap(), ids, "list"); - } + private static ErrataFactory singleton = new ErrataFactory(); + private static Logger log = Logger.getLogger(ErrataFactory.class); + + public static final String ERRATA_TYPE_BUG = "Bug Fix Advisory"; + public static final String ERRATA_TYPE_ENHANCEMENT = "Product Enhancement Advisory"; + public static final String ERRATA_TYPE_SECURITY = "Security Advisory"; + + public static final String ERRATA_TYPE_SECURITY_CRIT = "Security Advisory (Critical)"; + public static final String ERRATA_TYPE_SECURITY_IMP = "Security Advisory (Important)"; + public static final String ERRATA_TYPE_SECURITY_MOD = "Security Advisory (Moderate)"; + public static final String ERRATA_TYPE_SECURITY_LOW = "Security Advisory (Low)"; + + private ErrataFactory() { + super(); + } + + /** + * Get the Logger for the derived class so log messages + * show up on the correct class + */ + @Override + protected Logger getLogger() { + return log; + } + + /** + * List the package ids that were pushed to a channel because of an errata + * @param cid the channel id + * @param eid the errata id + * @return List of package ids + */ + public static List<Long> listErrataChannelPackages(Long cid, Long eid) { + Map params = new HashMap(); + params.put("channel_id", cid); + params.put("errata_id", eid); + DataResult<ErrataPackageFile> dr = executeSelectMode( + "ErrataCache_queries", + "package_associated_to_errata_and_channel", params); + List toReturn = new ArrayList<Long>(); + for (ErrataPackageFile file : dr) { + toReturn.add(file.getPackageId()); + } + return toReturn; + } + + /** + * List the package ids that are associated with an errata + * associated with given channel + * @param channelId channel of interest + * @param errataIds list of errata ids + * @return List of package ids + */ + public static List<Long> listErrataChannelPackages(Long channelId, + Set<Long> errataIds) { + SelectMode m = ModeFactory.getMode("Errata_queries", + "packageids_associated_to_errata"); + Map params = new HashMap(); + params.put("channel_id", channelId); + DataResult<ErrataPackageFile> dr = m.execute(params, new ArrayList(errataIds)); + // make the final list unique + Set toReturn = new HashSet<Long>(); + for (ErrataPackageFile file : dr) { + toReturn.add(file.getPackageId()); + } + return new ArrayList(toReturn); + } + + /** + * Tries to locate errata based on either the errataum's id or the + * CVE/CAN identifier string. + * @param identifier erratum id or CVE/CAN id string + * @return list of erratas found + */ + public static List lookupByIdentifier(String identifier) { + Long eid = null; + List retval = new LinkedList(); + Errata errata = null; + try { + eid = new Long(Long.parseLong(identifier)); + } + catch (NumberFormatException e) { + eid = null; + } + if (eid != null) { + errata = ErrataFactory.lookupPublishedErrataById(eid); + if (errata != null) { + retval.add(errata); + } + } + else if (identifier.length() > 4) { + String prefix = null; + errata = ErrataFactory.lookupByAdvisoryId(identifier); + if (errata != null) { + retval.add(errata); + } + else { + errata = ErrataFactory.lookupByAdvisory(identifier); + if (errata != null) { + retval.add(errata); + } + } + if (errata == null) { + prefix = identifier.substring(0, 4); + if (prefix.matches("RH.A")) { + StringTokenizer strtok = new StringTokenizer(identifier, "-"); + StringBuffer buf = new StringBuffer(); + boolean foundFirst = false; + while (strtok.hasMoreTokens()) { + buf.append(strtok.nextToken()); + if (!foundFirst) { + buf.append("-"); + foundFirst = true; + } + else { + if (strtok.hasMoreTokens()) { + buf.append(":"); + } + } + } + identifier = buf.toString(); + errata = ErrataFactory.lookupByAdvisoryId(identifier); + } + if (errata != null) { + retval.add(errata); + } + } + if (errata == null) { + prefix = identifier.substring(0, 3); + if ((prefix.equals("CVE") || prefix.equals("CAN")) && + identifier.length() > 7 && identifier.indexOf('-') == -1) { + identifier = identifier.substring(0, 3) + "-" + + identifier.substring(3, 7) + "-" + + identifier.substring(7); + } + List erratas = ErrataFactory.lookupByCVE(identifier); + retval.addAll(erratas); + } + } + return retval; + } + + /** + * publish takes an unpublished errata and copies its contents into a Published Errata + * object (and then returns this object). This method also handles removing the old + * Unpublished Errata object and child elements from the db. + * @param unpublished The Errata to publish + * @return Returns a published errata. + */ + public static Errata publish(Errata unpublished) { + //Make sure the errata we're publishing is unpublished + if (unpublished.isPublished()) { + return unpublished; //there is nothing we can do here + } + //Create a published errata using unpublished + + Errata published; + + if (unpublished.isCloned()) { + published = new PublishedClonedErrata(); + ((PublishedClonedErrata)published).setOriginal( + ((UnpublishedClonedErrata)unpublished).getOriginal()); + } + else { + published = ErrataFactory.createPublishedErrata(); + } + + copyDetails(published, unpublished, false); + + //Save the published Errata + save(published); + + //Remove the unpublished Errata from db + try { + Session session = HibernateFactory.getSession(); + session.delete(unpublished); + } + catch (HibernateException e) { + throw new HibernateRuntimeException( + "Errors occurred while publishing errata", e); + } + + //return the published errata + return published; + } + + + /** + * Takes a published or unpublished errata and publishes to a channel, creating + * all of the correct ErrataFile* entries. This method does push packages to + * the appropriate channel. (Appropriate as defined as the channel previously + * having a package with the same name). + * @param errataList list of errata to publish + * @param chan channel to publish it into. + * @param user the user doing the pushing + * @param inheritPackages include only original channel packages + * @return the publsihed errata + */ + public static List<Errata> publishToChannel(List<Errata> errataList, Channel chan, + User user, boolean inheritPackages) { + List<com.redhat.rhn.domain.errata.Errata> toReturn = new ArrayList<Errata>(); + for (Errata errata : errataList) { + if (!errata.isPublished()) { + errata = publish(errata); + } + errata.addChannel(chan); + errata.addChannelNotification(chan, new Date()); + + Set<Package> packagesToPush = new HashSet<Package>(); + DataResult<PackageOverview> packs; + if (inheritPackages) { + + if (!chan.isCloned()) { + throw new InvalidChannelException("Cloned channel expected: " + + chan.getLabel()); + } + Channel original = ((ClonedChannel) chan).getOriginal(); + packs = ErrataManager.listErrataChannelPacks(original, errata, user); + } + else { + packs = ErrataManager.lookupPacksFromErrataForChannel(chan, errata, user); + } + + for (PackageOverview packOver : packs) { + //lookup the Package object + Package pack = PackageFactory.lookupByIdAndUser( + packOver.getId().longValue(), user); + packagesToPush.add(pack); + } + + Errata e = publishErrataPackagesToChannel(errata, chan, user, packagesToPush); + toReturn.add(e); + } + postPublishActions(chan, user); + return toReturn; + } + + + + /** + * Publish an errata to a channel but only push a small set of packages + * along with it + * + * @param errata errata to publish + * @param chan channel to publish it into. + * @param user the user doing the pushing + * @param packages the packages to push + * @return the published errata + */ + public static Errata publishToChannel(Errata errata, Channel chan, + User user, Set<Package> packages) { + if (!errata.isPublished()) { + errata = publish(errata); + } + errata.addChannel(chan); + errata = publishErrataPackagesToChannel(errata, chan, user, packages); + postPublishActions(chan, user); + return errata; + } + + + private static void postPublishActions(Channel chan, User user) { + ChannelManager.refreshWithNewestPackages(chan, "web.errata_push"); + ChannelManager.queueChannelChange(chan.getLabel(), + "java::publishErrataPackagesToChannel", user.getLogin()); + } + + + /** + * Private helper method that pushes errata packages to a channel + */ + private static Errata publishErrataPackagesToChannel(Errata errata, + Channel chan, User user, Set<Package> packages) { + // Much quicker to push all packages at once + List<Long> pids = new ArrayList<Long>(); + for (Package pack : packages) { + pids.add(pack.getId()); + } + ChannelManager.addPackages(chan, pids, user); + + for (Package pack : packages) { + List<ErrataFile> publishedFiles = ErrataFactory.lookupErrataFile( + errata, pack); + Map<String, ErrataFile> toAdd = new HashMap(); + if (publishedFiles.size() == 0) { + // Now create the appropriate ErrataFile object + ErrataFile publishedFile = ErrataFactory + .createPublishedErrataFile(ErrataFactory + .lookupErrataFileType("RPM"), pack + .getChecksum().getChecksum(), pack + .getNameEvra()); + publishedFile.addPackage(pack); + publishedFile.setErrata(errata); + publishedFile.setModified(new Date()); + ((PublishedErrataFile) publishedFile).addChannel(chan); + singleton.saveObject(publishedFile); + } + else { + for (ErrataFile publishedFile : publishedFiles) { + String fileName = publishedFile.getFileName().substring( + publishedFile.getFileName().lastIndexOf("/") + 1); + if (!toAdd.containsKey(fileName)) { + toAdd.put(fileName, publishedFile); + ((PublishedErrataFile) publishedFile).addChannel(chan); + singleton.saveObject(publishedFile); + } + } + } + + } + ChannelFactory.save(chan); + List chanList = new ArrayList(); + chanList.add(chan.getId()); + + ErrataCacheManager.insertCacheForChannelErrataAsync(chanList, errata); + + return errata; + } + + /** + * @param org Org performing the cloning + * @param e Errata to be cloned + * @return clone of e + */ + public static Errata createClone(Org org, Errata e) { + + + String baseClonedAdvisoryName = "CL" + e.getAdvisoryName().substring(3); + String baseClonedAdvisory = "CL" + e.getAdvisory().substring(3); + String clonedAdvisory = baseClonedAdvisory; + String clonedAdvisoryName = baseClonedAdvisoryName; + boolean unusedNameFound = false; + + + for (int j = 1; !unusedNameFound; ++j) { + Errata advisoryNameMatch = lookupByAdvisory(clonedAdvisoryName); + Errata advisoryMatch = lookupByAdvisoryId(clonedAdvisory); + + if ((advisoryNameMatch == null) && (advisoryMatch == null)) { + unusedNameFound = true; + } + else { + clonedAdvisoryName = baseClonedAdvisoryName + '-' + j; + clonedAdvisory = baseClonedAdvisory + '-' + j; + } + } + + UnpublishedClonedErrata clone = new UnpublishedClonedErrata(); + + copyDetails(clone, e, true); + + clone.setAdvisoryName(clonedAdvisoryName); + clone.setAdvisory(clonedAdvisory); + clone.setOriginal(e); + clone.setOrg(org); + + save(clone); + return clone; + } + + /** + * Helper method to copy the details for. + * @param copy The object to copy into. + * @param original The object to copy from. + * @param clone set to true if this is a cloned errata, and thus + * things like org or advisory name shouldn't be set + */ + private static void copyDetails(Errata copy, Errata original, boolean clone) { + + //Set the easy things first ;) + + if (!clone) { + copy.setAdvisory(original.getAdvisory()); + copy.setAdvisoryName(original.getAdvisoryName()); + copy.setOrg(original.getOrg()); + } + + copy.setAdvisoryType(original.getAdvisoryType()); + copy.setProduct(original.getProduct()); + copy.setErrataFrom(original.getErrataFrom()); + copy.setDescription(original.getDescription()); + copy.setSynopsis(original.getSynopsis()); + copy.setTopic(original.getTopic()); + copy.setSolution(original.getSolution()); + copy.setIssueDate(original.getIssueDate()); + copy.setUpdateDate(original.getUpdateDate()); + copy.setNotes(original.getNotes()); + copy.setRefersTo(original.getRefersTo()); + copy.setAdvisoryRel(original.getAdvisoryRel()); + copy.setLocallyModified(original.getLocallyModified()); + copy.setLastModified(original.getLastModified()); + + + /* + * Copy the packages + * packages aren't published or unpublished exactly... that is determined + * by the status of the errata... + */ + copy.setPackages(new HashSet(original.getPackages())); + + /* + * Copy the keywords + * if we use the string version of addKeyword, we don't have to worry about + * whether or not the keyword is published. + */ + Iterator keysItr = IteratorUtils.getIterator(original.getKeywords()); + while (keysItr.hasNext()) { + Keyword k = (Keyword) keysItr.next(); + copy.addKeyword(k.getKeyword()); + } + + + /* + * Copy the bugs. If copy is published, then the bugs should be published as well. + * If not, then we want unpublished bugs. + */ + Iterator bugsItr = IteratorUtils.getIterator(original.getBugs()); + while (bugsItr.hasNext()) { + Bug bugIn = (Bug) bugsItr.next(); + Bug cloneB; + if (copy.isPublished()) { //we want published bugs + cloneB = ErrataManager.createNewPublishedBug(bugIn.getId(), + bugIn.getSummary(), + bugIn.getUrl()); + } + else { //we want unpublished bugs + cloneB = ErrataManager.createNewUnpublishedBug(bugIn.getId(), + bugIn.getSummary(), + bugIn.getUrl()); + } + copy.addBug(cloneB); + } + } + + /** + * Create a new PublishedErrata from scratch + * @return the PublishedErrata created + */ + public static Errata createPublishedErrata() { + return new PublishedErrata(); + } + + /** + * Create a new UnpublishedErrata + * @return the UnpublishedErrata created + */ + public static Errata createUnpublishedErrata() { + return new UnpublishedErrata(); + } + + /** + * Creates a new Unpublished Bug object with the given id and summary. + * @param id The id for the new bug + * @param summary The summary for the new bug + * @param url The bug URL + * @return The new unpublished bug. + */ + public static Bug createUnpublishedBug(Long id, String summary, String url) { + Bug bug = new UnpublishedBug(); + bug.setId(id); + bug.setSummary(summary); + bug.setUrl(url); + return bug; + } + + /** + * Creates a new Published Bug object with the given id and summary. + * @param id The id for the new bug + * @param summary The summary for the new bug + * @param url The bug URL + * @return The new published bug. + */ + public static Bug createPublishedBug(Long id, String summary, String url) { + Bug bug = new PublishedBug(); + bug.setId(id); + bug.setSummary(summary); + bug.setUrl(url); + return bug; + } + + /** + * Creates a new Unpublished Errata file with given ErrataFileType, checksum, and name + * @param ft ErrataFileType for the new ErrataFile + * @param cs MD5 Checksum for the new Errata File + * @param name name for the file + * @return new Unpublished Errata File + */ + public static ErrataFile createUnpublishedErrataFile(ErrataFileType ft, + String cs, + String name) { + return createUnpublishedErrataFile(ft, cs, name, new HashSet()); + } + + /** + * Creates a new Unpublished Errata file with given ErrataFileType, checksum, and name + * @param ft ErrataFileType for the new ErrataFile + * @param cs MD5 Checksum for the new Errata File + * @param name name for the file + * @param packages Packages associated with this errata file. + * @return new Unpublished Errata File + */ + public static ErrataFile createUnpublishedErrataFile(ErrataFileType ft, + String cs, + String name, + Set packages) { + ErrataFile file = new UnpublishedErrataFile(); + file.setFileType(ft); + file.setChecksum(ChecksumFactory.safeCreate(cs, "md5")); + file.setFileName(name); + file.setPackages(packages); + return file; + } + + /** + * Creates a new Published Errata file with given ErrataFileType, checksum, and name + * @param ft ErrataFileType for the new ErrataFile + * @param cs MD5 Checksum for the new Errata File + * @param name name for the file + * @return new Published Errata File + */ + public static ErrataFile createPublishedErrataFile(ErrataFileType ft, + String cs, + String name) { + return createPublishedErrataFile(ft, cs, name, new HashSet()); + } + + /** + * Creates a new Published Errata file with given ErrataFileType, checksum, and name + * @param ft ErrataFileType for the new ErrataFile + * @param cs MD5 Checksum for the new Errata File + * @param name name for the file + * @param packages Packages associated with this errata file. + * @return new Published Errata File + */ + public static ErrataFile createPublishedErrataFile(ErrataFileType ft, + String cs, + String name, + Set packages) { + ErrataFile file = new PublishedErrataFile(); + file.setFileType(ft); + file.setChecksum(ChecksumFactory.safeCreate(cs, "md5")); + file.setFileName(name); + file.setPackages(packages); + return file; + } + + /** + * Lookup a ErrataFileType based on a label + * @param label file type label (RPM, IMG, etc) + * @return ErrataFileType instance + */ + public static ErrataFileType lookupErrataFileType(String label) { + Session session = null; + ErrataFileType retval = null; + try { + session = HibernateFactory.getSession(); + retval = (ErrataFileType) session.getNamedQuery("ErrataFileType.findByLabel") + .setString("label", label).setCacheable(true).uniqueResult(); + } + catch (HibernateException e) { + throw new HibernateRuntimeException(e.getMessage(), e); + } + return retval; + } + + /** + * Lookup ErrataFiles by errata and file type + * @param errataId errata id + * @param fileType file type label + * @return list of ErrataFile instances + */ + public static List lookupErrataFilesByErrataAndFileType(Long errataId, + String fileType) { + Session session = null; + List retval = null; + try { + session = HibernateFactory.getSession(); + Query q = session.getNamedQuery("PublishedErrataFile.listByErrataAndFileType"); + q.setLong("errata_id", errataId.longValue()); + q.setString("file_type", fileType.toUpperCase()); + retval = q.list(); + + if (retval == null) { + q = session.getNamedQuery("UnpublishedErrataFile.listByErrataAndFileType"); + q.setLong("errata_id", errataId.longValue()); + q.setString("file_type", fileType.toUpperCase()); + retval = q.list(); + } + } + catch (HibernateException e) { + throw new HibernateRuntimeException(e.getMessage(), e); + } + return retval; + + + } + + + /** + * Lookup a Errata by their id + * @param id the id to search for + * @return the Errata found + */ + public static Errata lookupById(Long id) { + //Look for published Errata first + Session session = HibernateFactory.getSession(); + Errata errata = (Errata) session.get(PublishedErrata.class, id); + + //If we nothing was found, look for it in the Unpublished Errata table... + if (errata == null) { + errata = (Errata) session.get(UnpublishedErrata.class, id); + } + return errata; + } + + /** + * Lookup a Errata by the advisoryType string + * @param advisoryType to search for + * @return the Errata found + */ + public static List lookupErratasByAdvisoryType(String advisoryType) { + Session session = null; + List retval = null; + try { + session = HibernateFactory.getSession(); + retval = session.getNamedQuery("PublishedErrata.findByAdvisoryType") + .setString("type", advisoryType) + //Retrieve from cache if there + .setCacheable(true).list(); + } + catch (HibernateException he) { + log.error("Error loading ActionArchTypes from DB", he); + throw new + HibernateRuntimeException("Error loading ActionArchTypes from db"); + } + return retval; + } + + /** + * Lookup a Security Errata by the synopsis string + * @param synopsis to search for + * @return the Errata found + */ + public static List lookupErratasBySynopsis(String synopsis) { + Session session = null; + List retval = null; + try { + session = HibernateFactory.getSession(); + retval = session.getNamedQuery("PublishedErrata.findSecurityBySynopsis") + .setString("type", ERRATA_TYPE_SECURITY) + .setString("synopsis", synopsis) + //Retrieve from cache if there + .setCacheable(true).list(); + } + catch (HibernateException he) { + log.error("Error loading ActionArchTypes from DB", he); + throw new + HibernateRuntimeException("Error loading ActionArchTypes from db"); + } + return retval; + } + + /** + * Finds published errata by id + * @param id errata id + * @return Errata if found, otherwise null + */ + public static Errata lookupPublishedErrataById(Long id) { + Session session = null; + Errata retval = null; + try { + session = HibernateFactory.getSession(); + retval = (Errata) session.getNamedQuery("PublishedErrata.findById") + .setLong("id", id.longValue()).uniqueResult(); + } + catch (HibernateException he) { + log.error("Error loading ActionArchTypes from DB", he); + throw new + HibernateRuntimeException("Error loading ActionArchTypes from db"); + } + return retval; + } + + /** + * Look up an errata by the advisory name. This is a unique field in the db and this + * method is needed to help us see if a created/edited advisoryName is unique. + * @param advisory The advisory to lookup + * @return Returns the errata corresponding to the passed in advisory name. + */ + public static Errata lookupByAdvisory(String advisory) { + Session session = null; + Errata retval = null; + // try { + //look for a published errata first + session = HibernateFactory.getSession(); + retval = (Errata) session.getNamedQuery("PublishedErrata.findByAdvisoryName") + .setString("advisory", advisory) + .uniqueResult(); + //if nothing was found, check the unpublished errata table + if (retval == null) { + retval = (Errata) + session.getNamedQuery("UnpublishedErrata.findByAdvisoryName") + .setString("advisory", advisory) + .uniqueResult(); + } + // } + // catch (HibernateException e) { + // throw new + // HibernateRuntimeException("Error looking up errata by advisory name"); + // } + return retval; + } + + /** + * Finds errata based on advisory id + * @param advisoryId errata advisory id + * @return Errata if found, otherwise null + */ + public static Errata lookupByAdvisoryId(String advisoryId) { + Session session = null; + Errata retval = null; + try { + //look for a published errata first + session = HibernateFactory.getSession(); + retval = (Errata) session.getNamedQuery("PublishedErrata.findByAdvisory") + .setString("advisory", advisoryId) + .uniqueResult(); + + if (retval == null) { + retval = (Errata) + session.getNamedQuery("UnpublishedErrata.findByAdvisory") + .setString("advisory", advisoryId) + .uniqueResult(); + } + } + catch (HibernateException e) { + + throw new + HibernateRuntimeException("Error looking up errata by advisory name"); + } + return retval; + } + + /** + * Finds errata based on CVE string + * @param cve cve text + * @return Errata if found, otherwise null + */ + public static List lookupByCVE(String cve) { + List retval = new LinkedList(); + SelectMode mode = ModeFactory.getMode("Errata_queries", "erratas_for_cve"); + Map params = new HashMap(); + params.put("cve", cve); + List result = mode.execute(params); + Session session = HibernateFactory.getSession(); + for (Iterator iter = result.iterator(); iter.hasNext();) { + Map row = (Map) iter.next(); + Long rawId = (Long) row.get("id"); + retval.add(session.load(PublishedErrata.class, rawId)); + } + return retval; + } + + /** + * Lookup all the clones of a particular errata + * @param org Org that the clones belongs to + * @param original Original errata that the clones are clones of + * @return list of clones of the errata + */ + public static List lookupByOriginal(Org org, Errata original) { + Session session = null; + List retval = null; + + try { + session = HibernateFactory.getSession(); + retval = session. + getNamedQuery("UnpublishedClonedErrata.findByOriginal") + .setParameter("original", original) + .setParameter("org", org).list(); + + if (retval == null) { + retval = lookupPublishedByOriginal(org, original); + } + + } + catch (HibernateException e) { + throw new + HibernateRuntimeException("Error looking up errata by original errata"); + } + return retval; + } + + /** + * Lookup all the clones of a particular errata + * @param org Org that the clones belongs to + * @param original Original errata that the clones are clones of + * @return list of clones of the errata + */ + public static List lookupPublishedByOriginal(Org org, Errata original) { + Session session = null; + List retval = null; + + try { + session = HibernateFactory.getSession(); + retval = session.getNamedQuery("PublishedClonedErrata.findByOriginal") + .setParameter("original", original) + .setParameter("org", org).list(); + } + catch (HibernateException e) { + throw new + HibernateRuntimeException("Error looking up errata by original errata"); + } + return retval; + } + + /** + * Lists errata present in both channels + * @param org orgaznization + * @param channelFrom channel1 + * @param channelTo channel2 + * @return list of errata + */ + public static List listSamePublishedInChannels(Org org, Channel channelFrom, + Channel channelTo) { + Session session = null; + List retval = null; + + try { + session = HibernateFactory.getSession(); + retval = session.getNamedQuery("PublishedErrata.findSameInChannels") + .setParameter("channel_from", channelFrom) + .setParameter("channel_to", channelTo).list(); + } + catch (HibernateException e) { + throw new + HibernateRuntimeException("Error looking up errata by original errata"); + } + return retval; + } + + /** + * Lists errata from channelFrom, that are cloned from the same original + * as errata in channelTo + * @param org orgaznization + * @param channelFrom channel1 + * @param channelTo channel2 + * @return list of errata + */ + public static List listPublishedBrothersInChannels(Org org, Channel channelFrom, + Channel channelTo) { + Session session = null; + List retval = null; + + try { + session = HibernateFactory.getSession(); + retval = session.getNamedQuery("PublishedClonedErrata.findBrothersInChannel") + .setParameter("channel_from", channelFrom) + .setParameter("channel_to", channelTo).list(); + } + catch (HibernateException e) { + throw new + HibernateRuntimeException("Error looking up errata by original errata"); + } + return retval; + } + + /** + * Lists errata from channelFrom, that have clones in channelTo + * @param org orgaznization + * @param channelFrom channel1 + * @param channelTo channel2 + * @return list of errata + */ + public static List listPublishedClonesInChannels(Org org, Channel channelFrom, + Channel channelTo) { + Session session = null; + List retval = null; + + try { + session = HibernateFactory.getSession(); + retval = session.getNamedQuery("PublishedErrata.findClonesInChannel") + .setParameter("channel_from", channelFrom) + .setParameter("channel_to", channelTo) + .list(); + } + catch (HibernateException e) { + throw new + HibernateRuntimeException("Error looking up errata by original errata"); + } + return retval; + } + + /** + * Insert or Update a Errata. + * @param errataIn Errata to be stored in database. + */ + public static void save(Errata errataIn) { + singleton.saveObject(errataIn); + } + + /** + * Delete a bug + * @param deleteme Bug to delete + */ + public static void removeBug(Bug deleteme) { + singleton.removeObject(deleteme); + } + + /** + * Delete a Keyword + * @param deleteme Keyword to delete + */ + public static void remove(Keyword deleteme) { + singleton.removeObject(deleteme); + } + + + /** + * Remove a file. + * @param deleteme ErrataFile to delete + */ + public static void removeFile(ErrataFile deleteme) { + singleton.removeObject(deleteme); + } + + + /** + * Lists errata assigned to a particular channel, + * sorted by date (from oldest to newest) + * @param org the Org in question + * @param channel the channel you want to get the errata for + * @return A list of Errata objects + */ + public static List lookupByChannelSorted(Org org, Channel channel) { + + return HibernateFactory.getSession(). + getNamedQuery("PublishedErrata.lookupSortedByChannel") + .setParameter("org", org) + .setParameter("channel", channel) + .list(); + } + + /** + * Lists errata assigned to a particular channel between + * the given start and end date. The list is sorted by date + * (from oldest to newest). + * @param org the Org in question + * @param channel the channel you want to get the errata for + * @param startDate the start date + * @param endDate the end date + * @return A list of Errata objects + */ + public static List<Errata> lookupByChannelBetweenDates(Org org, Channel channel, + String startDate, String endDate) { + + return HibernateFactory.getSession(). + getNamedQuery("PublishedErrata.lookupByChannelBetweenDates") + .setParameter("org", org) + .setParameter("channel", channel) + .setParameter("start_date", startDate) + .setParameter("end_date", endDate) + .list(); + } + + /** + * Lookup errata that are in the set "errata_list" + * @param user the user to search the set for + * @param set the set to look in + * @return List of Errata + */ + public static List<Errata> lookupErrataInSet(User user, String set) { + + Map params = new HashMap(); + params.put("uid", user.getId()); + params.put("set", set); + return singleton.listObjectsByNamedQuery( + "PublishedErrata.lookupFromSet", params); + } + + + + /** + * Lookup an errataFile object by it's errata and package + * @param errata the errata associated + * @param pack the package associated + * @return the requested errata file object + */ + public static List<ErrataFile> lookupErrataFile(Errata errata, Package pack) { + Map params = new HashMap(); + params.put("errata", errata); + params.put("package", pack); + return singleton.listObjectsByNamedQuery( + "PublishedErrataFile.lookupByErrataAndPackage", params); + } + + /** + * Returns a list of ErrataOverview that match the given errata ids. + * @param eids Errata ids. + * @param org Organization to match results with + * @return a list of ErrataOverview that match the given errata ids. + */ + public static List<ErrataOverview> search(List eids, Org org) { + Map params = new HashMap(); + params.put("eids", eids); + params.put("org_id", org.getId()); + List results = singleton.listObjectsByNamedQuery( + "PublishedErrata.searchById", params); + List<ErrataOverview> errata = new ArrayList<ErrataOverview>(); + for (Object result : results) { + Object[] values = (Object[]) result; + ErrataOverview eo = new ErrataOverview(); + // e.id, e.advisory, e.advisoryName, e.advisoryType, e.synopsis, e.updateDate + eo.setId((Long)values[0]); + eo.setAdvisory((String)values[1]); + eo.setAdvisoryName((String)values[2]); + eo.setAdvisoryType((String)values[3]); + eo.setAdvisorySynopsis((String)values[4]); + eo.setUpdateDate((Date)values[5]); + eo.setIssueDate((Date)values[6]); + errata.add(eo); + } + + return errata; + } + + /** + * Returns a list of ErrataOverview of Errata that match the given Package + * ids. + * @param pids Package ids whose Errata are being sought. + * @return a list of ErrataOverview of Errata that match the given Package + * ids. + */ + public static List<ErrataOverview> searchByPackageIds(List pids) { + Map params = new HashMap(); + params.put("pids", pids); + if (log.isDebugEnabled()) { + log.debug("pids = " + pids); + } + List results = singleton.listObjectsByNamedQuery( + "PublishedErrata.searchByPackageIds", params); + if (log.isDebugEnabled()) { + log.debug("Query 'PublishedErrata.searchByPackageIds' returned " + + results.size() + " entries"); + } + List<ErrataOverview> errata = new ArrayList<ErrataOverview>(); + Long lastId = null; + ErrataOverview eo = null; + for (Object result : results) { + Object[] values = (Object[]) result; + // e.id, e.advisory, e.advisoryName, e.advisoryType, e.synopsis, e.updateDate + Long curId = (Long)values[0]; + + if (!curId.equals(lastId)) { + eo = new ErrataOverview(); + } + eo.setId((Long)values[0]); + eo.setAdvisory((String)values[1]); + eo.setAdvisoryName((String)values[2]); + eo.setAdvisoryType((String)values[3]); + eo.setAdvisorySynopsis((String)values[4]); + eo.setUpdateDate((Date)values[5]); + eo.setIssueDate((Date)values[6]); + eo.addPackageName((String)values[7]); + if (!curId.equals(lastId)) { + errata.add(eo); + lastId = curId; + } + if (log.isDebugEnabled()) { + log.debug("curId = " + curId + ", lastId = " + lastId); + log.debug("ErrataOverview formed: " + eo.getAdvisoryName() + " for " + + eo.getPackageNames()); + } + } + + return errata; + } + + + /** + * Returns a list of ErrataOverview of Errata that match the given Package + * ids. + * @param pids Package ids whose Errata are being sought. + * @param org Organization to match results with + * @return a list of ErrataOverview of Errata that match the given Package + * ids. + */ + public static List<ErrataOverview> searchByPackageIdsWithOrg(List pids, Org org) { + Map params = new HashMap(); + params.put("pids", pids); + params.put("org_id", org.getId()); + if (log.isDebugEnabled()) { + log.debug("org_id = " + org.getId()); + log.debug("pids = " + pids); + } + List results = singleton.listObjectsByNamedQuery( + "PublishedErrata.searchByPackageIdsWithOrg", params); + if (log.isDebugEnabled()) { + log.debug("Query 'PublishedErrata.searchByPackageIdsWithOrg' returned " + + results.size() + " entries"); + } + List<ErrataOverview> errata = new ArrayList<ErrataOverview>(); + Long lastId = null; + ErrataOverview eo = null; + for (Object result : results) { + Object[] values = (Object[]) result; + // e.id, e.advisory, e.advisoryName, e.advisoryType, e.synopsis, e.updateDate + Long curId = (Long)values[0]; + + if (!curId.equals(lastId)) { + eo = new ErrataOverview(); + } + eo.setId((Long)values[0]); + eo.setAdvisory((String)values[1]); + eo.setAdvisoryName((String)values[2]); + eo.setAdvisoryType((String)values[3]); + eo.setAdvisorySynopsis((String)values[4]); + eo.setUpdateDate((Date)values[5]); + eo.setIssueDate((Date)values[6]); + eo.addPackageName((String)values[7]); + if (!curId.equals(lastId)) { + errata.add(eo); + lastId = curId; + } + if (log.isDebugEnabled()) { + log.debug("curId = " + curId + ", lastId = " + lastId); + log.debug("ErrataOverview formed: " + eo.getAdvisoryName() + " for " + + eo.getPackageNames()); + } + } + + return errata; + } + + + /** + * Sync all the errata details from one errata to another + * @param cloned the cloned errata that needs syncing + */ + public static void syncErrataDetails(PublishedClonedErrata cloned) { + copyDetails(cloned, cloned.getOriginal(), true); + } + + /** + * List errata objects by ID + * @param ids list of ids + * @return List of Errata Objects + */ + public static List<Errata> listErrata(Collection<Long> ids) { + return singleton.listObjectsByNamedQuery("PublishedErrata.listByIds", + new HashMap(), ids, "list"); + }
} diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java index 7f568ca..2f67f29 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java @@ -79,32 +79,32 @@ import com.redhat.rhn.manager.user.UserManager; */ public class ErrataHandler extends BaseHandler {
- /** - * Returns an OVAL metadata file for a given errata or CVE - * @param sessionKey The authenticated user's session key - * @param identifier Errata identifier (either id, CVE/CAN, or Advisory name) - * @return Escaped XML representing the OVAL metadata document - * @throws IOException error building XML file - * @throws FaultException general error occurred - * - * @xmlrpc.doc Retrieves the OVAL metadata associated with one or more erratas. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param_desc("string", "identifier", "Can either be an erratum's ID, - * CVE/CAN, or advisory name. In the case of CVE/CAN, all dashes must be - * removed from the name.Numeric advisory IDs and advisory names - * (RHSA-2006:011) can be submitted as they are.") - * @xmlrpc.returntype string - The OVAL metadata document in escaped XML form. - */ - /** - * The getOval method is being commented out due to bugzilla 504054. This bug - * raises an issue of a null exception being generated on execution. The method - * has been updated to address that exception; however, there is a larger issue at - * hand in that the OVAL functionality is not fully supported by the application. - * For example, the OVAL meta data is not synced to the database; therefore, there - * will never be data to return by the method. So it is better to comment it out - * than to have the method that cannot return any data. :) It is, however, - * desirable to support this in the future, so we don't want to lose the logic. - * + /** + * Returns an OVAL metadata file for a given errata or CVE + * @param sessionKey The authenticated user's session key + * @param identifier Errata identifier (either id, CVE/CAN, or Advisory name) + * @return Escaped XML representing the OVAL metadata document + * @throws IOException error building XML file + * @throws FaultException general error occurred + * + * @xmlrpc.doc Retrieves the OVAL metadata associated with one or more erratas. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param_desc("string", "identifier", "Can either be an erratum's ID, + * CVE/CAN, or advisory name. In the case of CVE/CAN, all dashes must be + * removed from the name.Numeric advisory IDs and advisory names + * (RHSA-2006:011) can be submitted as they are.") + * @xmlrpc.returntype string - The OVAL metadata document in escaped XML form. + */ + /** + * The getOval method is being commented out due to bugzilla 504054. This bug + * raises an issue of a null exception being generated on execution. The method + * has been updated to address that exception; however, there is a larger issue at + * hand in that the OVAL functionality is not fully supported by the application. + * For example, the OVAL meta data is not synced to the database; therefore, there + * will never be data to return by the method. So it is better to comment it out + * than to have the method that cannot return any data. :) It is, however, + * desirable to support this in the future, so we don't want to lose the logic. + * public String getOval(String sessionKey, String identifier) throws IOException, FaultException { User loggedInUser = getLoggedInUser(sessionKey); @@ -180,1210 +180,1211 @@ public class ErrataHandler extends BaseHandler { } return retval; } - */ - - /** - * GetDetails - Retrieves the details for a given errata. - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the errata - * @return Returns a map containing the details of the errata - * @throws FaultException A FaultException is thrown if the errata - * corresponding to advisoryName cannot be found. - * - * @xmlrpc.doc Retrieves the details for the erratum matching the given - * advisory name. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype - * #struct("erratum") - * #prop("string", "issue_date") - * #prop("string", "update_date") - * #prop_desc("string", "last_modified_date", "This date is only included for - * published erratum and it represents the last time the erratum was - * modified.") - * #prop("string", "synopsis") - * #prop("int", "release") - * #prop("string", "type") - * #prop("string", "product") - * #prop("string", "errataFrom") - * #prop("string", "topic") - * #prop("string", "description") - * #prop("string", "references") - * #prop("string", "notes") - * #prop("string", "solution") - * #struct_end() - */ - public Map getDetails(String sessionKey, String advisoryName) throws FaultException { - // Get the logged in user. We don't care what roles this user has, we - // just want to make sure the caller is logged in. - User loggedInUser = getLoggedInUser(sessionKey); - - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - Map errataMap = new HashMap(); - - if (errata.getIssueDate() != null) { - errataMap.put("issue_date", - LocalizationService.getInstance() - .formatShortDate(errata.getIssueDate())); - } - if (errata.getUpdateDate() != null) { - errataMap.put("update_date", - LocalizationService.getInstance() - .formatShortDate(errata.getUpdateDate())); - } - if (errata.getLastModified() != null) { - errataMap.put("last_modified_date", errata.getLastModified().toString()); - } - if (errata.getAdvisoryRel() != null) { - errataMap.put("release", errata.getAdvisoryRel()); - } - errataMap.put("product", - StringUtils.defaultString(errata.getProduct())); - errataMap.put("errataFrom", - StringUtils.defaultString(errata.getErrataFrom())); - errataMap.put("solution", - StringUtils.defaultString(errata.getSolution())); - errataMap.put("description", - StringUtils.defaultString(errata.getDescription())); - errataMap.put("synopsis", - StringUtils.defaultString(errata.getSynopsis())); - errataMap.put("topic", - StringUtils.defaultString(errata.getTopic())); - errataMap.put("references", - StringUtils.defaultString(errata.getRefersTo())); - errataMap.put("notes", - StringUtils.defaultString(errata.getNotes())); - errataMap.put("type", - StringUtils.defaultString(errata.getAdvisoryType())); - - - return errataMap; - } - - /** - * Set erratum details. - * - * @param sessionKey User's session key. - * @param advisoryName The advisory name of the errata - * @param details Map of (optional) erratum details to be set. - * @return 1 on success, exception thrown otherwise. - * - * @xmlrpc.doc Set erratum details. All arguments are optional and will only be modified - * if included in the struct. This method will only allow for modification of custom - * errata created either through the UI or API. - * @xmlrpc.param #param("string", "sessionKey") - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.param - * #struct("errata details") - * #prop("string", "synopsis") - * #prop("string", "advisory_name") - * #prop("int", "advisory_release") - * #prop_desc("string", "advisory_type", "Type of advisory (one of the - * following: 'Security Advisory', 'Product Enhancement Advisory', - * or 'Bug Fix Advisory'") - * #prop("string", "product") - * #prop("string", "errataFrom") - * #prop("string", "topic") - * #prop("string", "description") - * #prop("string", "references") - * #prop("string", "notes") - * #prop("string", "solution") - * #prop_desc("array", "bugs", "'bugs' is the key into the struct") - * #array() - * #struct("bug") - * #prop_desc("int", "id", "Bug Id") - * #prop("string", "summary") - * #prop("string", "url") - * #struct_end() - * #array_end() - * #prop_desc("array", "keywords", "'keywords' is the key into the struct") - * #array_single("string", "keyword - List of keywords to associate - * with the errata.") - * #prop_desc("array", "CVEs", "'cves' is the key into the struct") - * #array_single("string", "cves - List of CVEs to associate - * with the errata.") - * #struct_end() - * - * @xmlrpc.returntype #return_int_success() - */ - public Integer setDetails(String sessionKey, String advisoryName, Map details) { - - // confirm that the user only provided valid keys in the map - Set<String> validKeys = new HashSet<String>(); - validKeys.add("synopsis"); - validKeys.add("advisory_name"); - validKeys.add("advisory_release"); - validKeys.add("advisory_type"); - validKeys.add("product"); - validKeys.add("errataFrom"); - validKeys.add("topic"); - validKeys.add("description"); - validKeys.add("references"); - validKeys.add("notes"); - validKeys.add("solution"); - validKeys.add("bugs"); - validKeys.add("keywords"); - validKeys.add("cves"); - validateMap(validKeys, details); - - validKeys.clear(); - validKeys.add("id"); - validKeys.add("summary"); - validKeys.add("url"); - if (details.containsKey("bugs")) { - for (Map<String, Object> bugMap : - (ArrayList<Map<String, Object>>) details.get("bugs")) { - - validateMap(validKeys, bugMap); - } - } - - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - if (errata.getOrg() == null) { - // Errata in the null org should not be modified; therefore, this is - // considered an invalid errata for this request - throw new InvalidErrataException(errata.getAdvisoryName()); - } - - if (details.containsKey("synopsis")) { - errata.setSynopsis((String)details.get("synopsis")); - } - if (details.containsKey("advisory_name")) { - errata.setAdvisoryName((String)details.get("advisory_name")); - } - if (details.containsKey("advisory_release")) { - Long rel = new Long((Integer)details.get("advisory_release")); - if (rel.longValue() > ErrataManager.MAX_ADVISORY_RELEASE) { - throw new InvalidAdvisoryReleaseException(rel.longValue()); - } - errata.setAdvisoryRel(rel); - } - if (details.containsKey("advisory_type")) { - errata.setAdvisoryType((String)details.get("advisory_type")); - } - if (details.containsKey("product")) { - errata.setProduct((String)details.get("product")); - } - if (details.containsKey("errataFrom")) { - errata.setErrataFrom((String)details.get("errataFrom")); - } - if (details.containsKey("topic")) { - errata.setTopic((String)details.get("topic")); - } - if (details.containsKey("description")) { - errata.setDescription((String)details.get("description")); - } - if (details.containsKey("solution")) { - errata.setSolution((String)details.get("solution")); - } - if (details.containsKey("references")) { - errata.setRefersTo((String)details.get("references")); - } - if (details.containsKey("notes")) { - errata.setNotes((String)details.get("notes")); - } - if (details.containsKey("bugs")) { - - if (errata.getBugs() != null) { - errata.getBugs().clear(); - HibernateFactory.getSession().flush(); - } - - for (Map<String, Object> bugMap : - (ArrayList<Map<String, Object>>) details.get("bugs")) { - - if (bugMap.containsKey("id") && bugMap.containsKey("summary")) { - String url = ""; - if (bugMap.containsKey("url")) { - url = (String) bugMap.get("url"); - } - - Bug bug = ErrataFactory.createPublishedBug( - new Long((Integer) bugMap.get("id")), - (String) bugMap.get("summary"), url); - - errata.addBug(bug); - } - } - } - if (details.containsKey("keywords")) { - if (errata.getKeywords() != null) { - errata.getKeywords().clear(); - HibernateFactory.getSession().flush(); - } - for (String keyword : (ArrayList<String>) details.get("keywords")) { - errata.addKeyword(keyword); - } - } - if (details.containsKey("cves")) { - if (errata.getCves() != null) { - errata.getCves().clear(); - HibernateFactory.getSession().flush(); - } - for (String cveName : (ArrayList<String>) details.get("cves")) { - Cve c = CveFactory.lookupByName(cveName); - if (c == null) { - c = new Cve(); - c.setName(cveName); - CveFactory.save(c); - } - errata.getCves().add(c); - } - } - - // ALWAYS change the advisory to match, as we do in the UI. - errata.setAdvisory(errata.getAdvisoryName() + "-" + - errata.getAdvisoryRel().toString()); - - //Save the errata - ErrataManager.storeErrata(errata); - - return 1; - } - - /** - * ListAffectedSystems - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the errata - * @return Returns an object array containing the system ids and system name - * @throws FaultException A FaultException is thrown if the errata corresponding to - * advisoryName cannot be found. - * - * @xmlrpc.doc Return the list of systems affected by the erratum with - * advisory name. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype - * #array() - * $SystemOverviewSerializer - * #array_end() - */ - public Object[] listAffectedSystems(String sessionKey, String advisoryName) - throws FaultException { - - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - DataResult dr = ErrataManager.systemsAffectedXmlRpc(loggedInUser, errata.getId()); - - return dr.toArray(); - } - - /** - * Get the Bugzilla fixes for a given errata - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the errata - * @return Returns a map containing the Bugzilla id and summary for each bug - * @throws FaultException A FaultException is thrown if the errata - * corresponding to the given advisoryName cannot be found. - * - * @xmlrpc.doc Get the Bugzilla fixes for an erratum matching the given - * advisoryName. The bugs will be returned in a struct where the bug id is - * the key. i.e. 208144="errata.bugzillaFixes Method Returns different - * results than docs say" - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype - * #struct("Bugzilla info") - * #prop_desc("string", "bugzilla_id", "actual bug number is the key into the - * struct") - * #prop_desc("string", "bug_summary", "summary who's key is the bug id") - * #struct_end() - */ - public Map bugzillaFixes(String sessionKey, String advisoryName) - throws FaultException { - - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - Set bugs = errata.getBugs(); - Map returnMap = new HashMap(); - - /* - * Loop through and stick the bug ids and summaries into a map. This - * is ok since (afaict) there isn't an unreasonable number of bugs - * attatched to any erratum. - */ - for (Iterator itr = IteratorUtils.getIterator(bugs.iterator()); itr.hasNext();) { - Bug bug = (Bug) itr.next(); - returnMap.put(bug.getId(), bug.getSummary()); - } - - return returnMap; - } - - /** - * Get the keywords for a given erratum - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the erratum - * @return Returns an array of keywords for the erratum - * @throws FaultException A FaultException is thrown if the errata corresponding to the - * given advisoryName cannot be fo - * - * @xmlrpc.doc Get the keywords associated with an erratum matching the - * given advisory name. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype #array_single("string", "Keyword associated with erratum.") - - */ - public Object[] listKeywords(String sessionKey, String advisoryName) - throws FaultException { - - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - Set keywords = errata.getKeywords(); - List returnList = new ArrayList(); - - for (Iterator itr = IteratorUtils.getIterator(keywords); itr.hasNext();) { - Keyword keyword = (Keyword) itr.next(); - returnList.add(keyword.getKeyword()); - } - - return returnList.toArray(); - } - - /** - * Returns a list of channels (represented by a map) that the given erratum is - * applicable to. - * @param sessionKey The sessionKey for the logged in user. - * @param advisoryName The advisory name of the erratum - * @return Returns an array of channels for the erratum - * @throws FaultException A FaultException is thrown if the errata corresponding to the - * given advisoryName cannot be found - * - * @xmlrpc.doc Returns a list of channels applicable to the erratum - * with the given advisory name. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype - * #array() - * #struct("channel") - * #prop("int", "channel_id") - * #prop("string", "label") - * #prop("string", "name") - * #prop("string", "parent_channel_label") - * #struct_end() - * #array_end() - */ - public Object[] applicableToChannels(String sessionKey, String advisoryName) - throws FaultException { - - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - return ErrataManager.applicableChannels(errata.getId(), - loggedInUser.getOrg().getId(), null, Map.class).toArray(); - } - - /** - * Returns a list of unpublished errata for the logged-in user's Org. - * @param sessionKey The sessionKey for the logged in user - * @return Returns an array of errata - * - * @xmlrpc.doc Returns a list of unpublished errata - * @xmlrpc.param #session_key() - * @xmlrpc.returntype - * #array() - * #struct() - * #prop("int", "id") - * #prop("int", "published") - * #prop("string", "advisory") - * #prop("string", "advisory_name") - * #prop("string", "advisory_type") - * #prop("string", "synopsis") - * #prop("dateTime.iso8601", "created") - * #prop("dateTime.iso8601", "update_date") - * #struct_end() - * #array_end() - */ - public Object[] listUnpublishedErrata(String sessionKey) { - User loggedInUser = getLoggedInUser(sessionKey); - Map[] unpub = (Map[])ErrataManager.unpublishedOwnedErrata(loggedInUser, Map.class) - .toArray(new Map[0]); - - for (Map errataItem : unpub) { - // remove items that can be NULL to prevent xmlrpc failure - Iterator<Map.Entry> itr = errataItem.entrySet().iterator(); - for (; itr.hasNext();) { - if (itr.next().getValue() == null) { - itr.remove(); - } - } - } - - return unpub; - } - - /** - * Returns a list of CVEs for a given erratum - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the erratum - * @return Returns a list of CVEs - * @throws FaultException A FaultException is thrown if the errata corresponding to the - * given advisoryName cannot be found + */ + + /** + * GetDetails - Retrieves the details for a given errata. + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the errata + * @return Returns a map containing the details of the errata + * @throws FaultException A FaultException is thrown if the errata + * corresponding to advisoryName cannot be found. + * + * @xmlrpc.doc Retrieves the details for the erratum matching the given + * advisory name. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype + * #struct("erratum") + * #prop("string", "issue_date") + * #prop("string", "update_date") + * #prop_desc("string", "last_modified_date", "This date is only included for + * published erratum and it represents the last time the erratum was + * modified.") + * #prop("string", "synopsis") + * #prop("int", "release") + * #prop("string", "type") + * #prop("string", "product") + * #prop("string", "errataFrom") + * #prop("string", "topic") + * #prop("string", "description") + * #prop("string", "references") + * #prop("string", "notes") + * #prop("string", "solution") + * #struct_end() + */ + public Map getDetails(String sessionKey, String advisoryName) throws FaultException { + // Get the logged in user. We don't care what roles this user has, we + // just want to make sure the caller is logged in. + User loggedInUser = getLoggedInUser(sessionKey); + + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + Map errataMap = new HashMap(); + + if (errata.getIssueDate() != null) { + errataMap.put("issue_date", + LocalizationService.getInstance() + .formatShortDate(errata.getIssueDate())); + } + if (errata.getUpdateDate() != null) { + errataMap.put("update_date", + LocalizationService.getInstance() + .formatShortDate(errata.getUpdateDate())); + } + if (errata.getLastModified() != null) { + errataMap.put("last_modified_date", errata.getLastModified().toString()); + } + if (errata.getAdvisoryRel() != null) { + errataMap.put("release", errata.getAdvisoryRel()); + } + errataMap.put("product", + StringUtils.defaultString(errata.getProduct())); + errataMap.put("errataFrom", + StringUtils.defaultString(errata.getErrataFrom())); + errataMap.put("solution", + StringUtils.defaultString(errata.getSolution())); + errataMap.put("description", + StringUtils.defaultString(errata.getDescription())); + errataMap.put("synopsis", + StringUtils.defaultString(errata.getSynopsis())); + errataMap.put("topic", + StringUtils.defaultString(errata.getTopic())); + errataMap.put("references", + StringUtils.defaultString(errata.getRefersTo())); + errataMap.put("notes", + StringUtils.defaultString(errata.getNotes())); + errataMap.put("type", + StringUtils.defaultString(errata.getAdvisoryType())); + + + return errataMap; + } + + /** + * Set erratum details. + * + * @param sessionKey User's session key. + * @param advisoryName The advisory name of the errata + * @param details Map of (optional) erratum details to be set. + * @return 1 on success, exception thrown otherwise. + * + * @xmlrpc.doc Set erratum details. All arguments are optional and will only be modified + * if included in the struct. This method will only allow for modification of custom + * errata created either through the UI or API. + * @xmlrpc.param #param("string", "sessionKey") + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.param + * #struct("errata details") + * #prop("string", "synopsis") + * #prop("string", "advisory_name") + * #prop("int", "advisory_release") + * #prop_desc("string", "advisory_type", "Type of advisory (one of the + * following: 'Security Advisory', 'Product Enhancement Advisory', + * or 'Bug Fix Advisory'") + * #prop("string", "product") + * #prop("string", "errataFrom") + * #prop("string", "topic") + * #prop("string", "description") + * #prop("string", "references") + * #prop("string", "notes") + * #prop("string", "solution") + * #prop_desc("array", "bugs", "'bugs' is the key into the struct") + * #array() + * #struct("bug") + * #prop_desc("int", "id", "Bug Id") + * #prop("string", "summary") + * #prop("string", "url") + * #struct_end() + * #array_end() + * #prop_desc("array", "keywords", "'keywords' is the key into the struct") + * #array_single("string", "keyword - List of keywords to associate + * with the errata.") + * #prop_desc("array", "CVEs", "'cves' is the key into the struct") + * #array_single("string", "cves - List of CVEs to associate + * with the errata.") + * #struct_end() + * + * @xmlrpc.returntype #return_int_success() + */ + public Integer setDetails(String sessionKey, String advisoryName, Map details) { + + // confirm that the user only provided valid keys in the map + Set<String> validKeys = new HashSet<String>(); + validKeys.add("synopsis"); + validKeys.add("advisory_name"); + validKeys.add("advisory_release"); + validKeys.add("advisory_type"); + validKeys.add("product"); + validKeys.add("errataFrom"); + validKeys.add("topic"); + validKeys.add("description"); + validKeys.add("references"); + validKeys.add("notes"); + validKeys.add("solution"); + validKeys.add("bugs"); + validKeys.add("keywords"); + validKeys.add("cves"); + validateMap(validKeys, details); + + validKeys.clear(); + validKeys.add("id"); + validKeys.add("summary"); + validKeys.add("url"); + if (details.containsKey("bugs")) { + for (Map<String, Object> bugMap : + (ArrayList<Map<String, Object>>) details.get("bugs")) { + + validateMap(validKeys, bugMap); + } + } + + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + if (errata.getOrg() == null) { + // Errata in the null org should not be modified; therefore, this is + // considered an invalid errata for this request + throw new InvalidErrataException(errata.getAdvisoryName()); + } + + if (details.containsKey("synopsis")) { + errata.setSynopsis((String)details.get("synopsis")); + } + if (details.containsKey("advisory_name")) { + errata.setAdvisoryName((String)details.get("advisory_name")); + } + if (details.containsKey("advisory_release")) { + Long rel = new Long((Integer)details.get("advisory_release")); + if (rel.longValue() > ErrataManager.MAX_ADVISORY_RELEASE) { + throw new InvalidAdvisoryReleaseException(rel.longValue()); + } + errata.setAdvisoryRel(rel); + } + if (details.containsKey("advisory_type")) { + errata.setAdvisoryType((String)details.get("advisory_type")); + } + if (details.containsKey("product")) { + errata.setProduct((String)details.get("product")); + } + if (details.containsKey("errataFrom")) { + errata.setErrataFrom((String)details.get("errataFrom")); + } + if (details.containsKey("topic")) { + errata.setTopic((String)details.get("topic")); + } + if (details.containsKey("description")) { + errata.setDescription((String)details.get("description")); + } + if (details.containsKey("solution")) { + errata.setSolution((String)details.get("solution")); + } + if (details.containsKey("references")) { + errata.setRefersTo((String)details.get("references")); + } + if (details.containsKey("notes")) { + errata.setNotes((String)details.get("notes")); + } + if (details.containsKey("bugs")) { + + if (errata.getBugs() != null) { + errata.getBugs().clear(); + HibernateFactory.getSession().flush(); + } + + for (Map<String, Object> bugMap : + (ArrayList<Map<String, Object>>) details.get("bugs")) { + + if (bugMap.containsKey("id") && bugMap.containsKey("summary")) { + String url = ""; + if (bugMap.containsKey("url")) { + url = (String) bugMap.get("url"); + } + + Bug bug = ErrataFactory.createPublishedBug( + new Long((Integer) bugMap.get("id")), + (String) bugMap.get("summary"), url); + + errata.addBug(bug); + } + } + } + if (details.containsKey("keywords")) { + if (errata.getKeywords() != null) { + errata.getKeywords().clear(); + HibernateFactory.getSession().flush(); + } + for (String keyword : (ArrayList<String>) details.get("keywords")) { + errata.addKeyword(keyword); + } + } + if (details.containsKey("cves")) { + if (errata.getCves() != null) { + errata.getCves().clear(); + HibernateFactory.getSession().flush(); + } + for (String cveName : (ArrayList<String>) details.get("cves")) { + Cve c = CveFactory.lookupByName(cveName); + if (c == null) { + c = new Cve(); + c.setName(cveName); + CveFactory.save(c); + } + errata.getCves().add(c); + } + } + + // ALWAYS change the advisory to match, as we do in the UI. + errata.setAdvisory(errata.getAdvisoryName() + "-" + + errata.getAdvisoryRel().toString()); + + //Save the errata + ErrataManager.storeErrata(errata); + + return 1; + } + + /** + * ListAffectedSystems + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the errata + * @return Returns an object array containing the system ids and system name + * @throws FaultException A FaultException is thrown if the errata corresponding to + * advisoryName cannot be found. + * + * @xmlrpc.doc Return the list of systems affected by the erratum with + * advisory name. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype + * #array() + * $SystemOverviewSerializer + * #array_end() + */ + public Object[] listAffectedSystems(String sessionKey, String advisoryName) + throws FaultException { + + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + DataResult dr = ErrataManager.systemsAffectedXmlRpc(loggedInUser, errata.getId()); + + return dr.toArray(); + } + + /** + * Get the Bugzilla fixes for a given errata + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the errata + * @return Returns a map containing the Bugzilla id and summary for each bug + * @throws FaultException A FaultException is thrown if the errata + * corresponding to the given advisoryName cannot be found. + * + * @xmlrpc.doc Get the Bugzilla fixes for an erratum matching the given + * advisoryName. The bugs will be returned in a struct where the bug id is + * the key. i.e. 208144="errata.bugzillaFixes Method Returns different + * results than docs say" + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype + * #struct("Bugzilla info") + * #prop_desc("string", "bugzilla_id", "actual bug number is the key into the + * struct") + * #prop_desc("string", "bug_summary", "summary who's key is the bug id") + * #struct_end() + */ + public Map bugzillaFixes(String sessionKey, String advisoryName) + throws FaultException { + + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + Set bugs = errata.getBugs(); + Map returnMap = new HashMap(); + + /* + * Loop through and stick the bug ids and summaries into a map. This + * is ok since (afaict) there isn't an unreasonable number of bugs + * attatched to any erratum. + */ + for (Iterator itr = IteratorUtils.getIterator(bugs.iterator()); itr.hasNext();) { + Bug bug = (Bug) itr.next(); + returnMap.put(bug.getId(), bug.getSummary()); + } + + return returnMap; + } + + /** + * Get the keywords for a given erratum + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the erratum + * @return Returns an array of keywords for the erratum + * @throws FaultException A FaultException is thrown if the errata corresponding to the + * given advisoryName cannot be fo + * + * @xmlrpc.doc Get the keywords associated with an erratum matching the + * given advisory name. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype #array_single("string", "Keyword associated with erratum.") + + */ + public Object[] listKeywords(String sessionKey, String advisoryName) + throws FaultException { + + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + Set keywords = errata.getKeywords(); + List returnList = new ArrayList(); + + for (Iterator itr = IteratorUtils.getIterator(keywords); itr.hasNext();) { + Keyword keyword = (Keyword) itr.next(); + returnList.add(keyword.getKeyword()); + } + + return returnList.toArray(); + } + + /** + * Returns a list of channels (represented by a map) that the given erratum is + * applicable to. + * @param sessionKey The sessionKey for the logged in user. + * @param advisoryName The advisory name of the erratum + * @return Returns an array of channels for the erratum + * @throws FaultException A FaultException is thrown if the errata corresponding to the + * given advisoryName cannot be found + * + * @xmlrpc.doc Returns a list of channels applicable to the erratum + * with the given advisory name. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype + * #array() + * #struct("channel") + * #prop("int", "channel_id") + * #prop("string", "label") + * #prop("string", "name") + * #prop("string", "parent_channel_label") + * #struct_end() + * #array_end() + */ + public Object[] applicableToChannels(String sessionKey, String advisoryName) + throws FaultException { + + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + return ErrataManager.applicableChannels(errata.getId(), + loggedInUser.getOrg().getId(), null, Map.class).toArray(); + } + + /** + * Returns a list of unpublished errata for the logged-in user's Org. + * @param sessionKey The sessionKey for the logged in user + * @return Returns an array of errata + * + * @xmlrpc.doc Returns a list of unpublished errata + * @xmlrpc.param #session_key() + * @xmlrpc.returntype + * #array() + * #struct() + * #prop("int", "id") + * #prop("int", "published") + * #prop("string", "advisory") + * #prop("string", "advisory_name") + * #prop("string", "advisory_type") + * #prop("string", "synopsis") + * #prop("dateTime.iso8601", "created") + * #prop("dateTime.iso8601", "update_date") + * #struct_end() + * #array_end() + */ + public Object[] listUnpublishedErrata(String sessionKey) { + User loggedInUser = getLoggedInUser(sessionKey); + Map[] unpub = (Map[])ErrataManager.unpublishedOwnedErrata(loggedInUser, Map.class) + .toArray(new Map[0]); + + for (Map errataItem : unpub) { + // remove items that can be NULL to prevent xmlrpc failure + Iterator<Map.Entry> itr = errataItem.entrySet().iterator(); + for (; itr.hasNext();) { + if (itr.next().getValue() == null) { + itr.remove(); + } + } + } + + return unpub; + } + + /** + * Returns a list of CVEs for a given erratum + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the erratum + * @return Returns a list of CVEs + * @throws FaultException A FaultException is thrown if the errata corresponding to the + * given advisoryName cannot be found throws FaultException { - * - * @xmlrpc.doc Returns a list of <a href="http://www.cve.mitre.org/">CVE</a>s - * applicable to the erratum with the given advisory name. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype - * #array_single("string", "cveName") - * - */ - public List listCves(String sessionKey, String advisoryName) throws FaultException { - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - DataResult dr = ErrataManager.errataCVEs(errata.getId()); - List returnList = new ArrayList(); - - //Just return the name of the cve... - for (Iterator itr = dr.iterator(); itr.hasNext();) { - CVE cve = (CVE) itr.next(); - returnList.add(cve.getName()); - } - - return returnList; - } - - /** - * List the packages for a given erratum - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the erratum - * @return Returns an Array of maps representing a package - * @throws FaultException A FaultException is thrown if the errata corresponding to the - * given advisoryName cannot be found - * - * @xmlrpc.doc Returns a list of the packages affected by the erratum - * with the given advisory name. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype - * #array() - * #struct("package") - * #prop("int", "id") - * #prop("string", "name") - * #prop("string", "epoch") - * #prop("string", "version") - * #prop("string", "release") - * #prop("string", "arch_label") - * #prop_array("providing_channels", "string", "- Channel label - * providing this package.") - * #prop("string", "build_host") - * #prop("string", "description") - * #prop("string", "checksum") - * #prop("string", "vendor") - * #prop("string", "summary") - * #prop("string", "cookie") - * #prop("string", "license") - * #prop("string", "path") - * #prop("string", "build_date") - * #prop("string", "last_modified_date") - * #prop("string", "size") - * #prop("string", "payload_size") - * #struct_end() - * #array_end() - */ - public List<Map> listPackages(String sessionKey, String advisoryName) - throws FaultException { - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - List<Map> toRet = new ArrayList<Map>(); - for (PackageDto dto : PackageManager.listPackageDtosForErrata(errata)) { - toRet.add(PackageHelper.packageToMap(dto, loggedInUser)); - } - return toRet; - - } - - /** - * Add a set of packages to an erratum - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the erratum - * @param packageIds The ids for packages to remove - * @return Returns int - representing the number of packages added, exception otherwise - * @throws FaultException A FaultException is thrown if the errata corresponding to the - * given advisoryName cannot be found - * - * @xmlrpc.doc Add a set of packages to an erratum - * with the given advisory name. This method will only allow for modification - * of custom errata created either through the UI or API. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.param #array_single("int", "packageId") - * @xmlrpc.returntype int - representing the number of packages added, - * exception otherwise - */ - public int addPackages(String sessionKey, String advisoryName, - List<Integer> packageIds) throws FaultException { - - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - if (errata.getOrg() == null) { - // Errata in the null org should not be modified; therefore, this is - // considered an invalid errata for this request - throw new InvalidErrataException(errata.getAdvisoryName()); - } - - int packagesAdded = 0; - for (Integer packageId : packageIds) { - - Package pkg = PackageManager.lookupByIdAndUser(new Long(packageId), - loggedInUser); - - if ((pkg != null) && (!errata.getPackages().contains(pkg))) { - errata.addPackage(pkg); - packagesAdded++; - } - } - - //Update Errata Cache - if ((packagesAdded > 0) && errata.isPublished() && - (errata.getChannels() != null)) { - ErrataCacheManager.updateCacheForChannelsAsync( - errata.getChannels()); - } - - //Save the errata - ErrataManager.storeErrata(errata); - - return packagesAdded; - } - - /** - * Remove a set of packages from an erratum - * @param sessionKey The sessionKey for the logged in user - * @param advisoryName The advisory name of the erratum - * @param packageIds The ids for packages to remove - * @return Returns int - representing the number of packages removed, - * exception otherwise - * @throws FaultException A FaultException is thrown if the errata corresponding to the - * given advisoryName cannot be found - * - * @xmlrpc.doc Remove a set of packages from an erratum - * with the given advisory name. This method will only allow for modification - * of custom errata created either through the UI or API. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.param #array_single("int", "packageId") - * @xmlrpc.returntype int - representing the number of packages removed, - * exception otherwise - */ - public int removePackages(String sessionKey, String advisoryName, - List<Integer> packageIds) throws FaultException { - - // Get the logged in user - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - if (errata.getOrg() == null) { - // Errata in the null org should not be modified; therefore, this is - // considered an invalid errata for this request - throw new InvalidErrataException(errata.getAdvisoryName()); - } - - int packagesRemoved = 0; - for (Integer packageId : packageIds) { - - Package pkg = PackageManager.lookupByIdAndUser(new Long(packageId), - loggedInUser); - - if ((pkg != null) && (errata.getPackages().contains(pkg))) { - errata.removePackage(pkg); - packagesRemoved++; - } - } - - //Update Errata Cache - if ((packagesRemoved > 0) && errata.isPublished() && - (errata.getChannels() != null)) { - ErrataCacheManager.updateCacheForChannelsAsync( - errata.getChannels()); - } - - //Save the errata - ErrataManager.storeErrata(errata); - - return packagesRemoved; - } - - /** - * Private helper method to lookup an errata and throw a Fault exception if it isn't - * found - * @param advisoryName The advisory name for the erratum you're looking for - * @return Returns the errata or a Fault Exception - * @throws FaultException Occurs when the erratum is not found - */ - private Errata lookupErrata(String advisoryName, Org org) throws FaultException { - Errata errata = ErrataManager.lookupByAdvisory(advisoryName); - - /* - * ErrataManager.lookupByAdvisory() could return null, so we need to check - * and throw a no_such_errata exception if the errata was not found. - */ - if (errata == null) { - throw new FaultException(-208, "no_such_errata", - "The errata " + advisoryName + " cannot be found."); - } - /** - * errata with org_id of null are public, but ones with an org id of !null are not - * need to make sure here that everything is checked correclty - */ - if (errata.getOrg() != null && !errata.getOrg().equals(org)) { - throw new FaultException(-209, "no_such_errata", - "The errata " + advisoryName + " cannot be found."); - } - - return errata; - } - - /** - * Clones a list of errata into a specified channel - * - * @param sessionKey The sessionKey containing the logged in user - * @param channelLabel the channel's label that we are cloning into - * @param advisoryNames an array of String objects containing the advisory name - * of every errata you want to clone - * @throws InvalidChannelRoleException if the user perms are incorrect - * @return Returns an array of Errata objects, which get serialized into XMLRPC - * - * @xmlrpc.doc Clone a list of errata into the specified channel. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "channel_label") - * @xmlrpc.param - * #array_single("string", " advisory - The advisory name of the errata to clone.") - * @xmlrpc.returntype - * #array() - * $ErrataSerializer - * #array_end() - */ - public Object[] clone(String sessionKey, String channelLabel, - List advisoryNames) throws InvalidChannelRoleException { - return clone(sessionKey, channelLabel, advisoryNames, false); - } - - - private Object[] clone(String sessionKey, String channelLabel, - List<String> advisoryNames, boolean inheritAllPackages){ - User loggedInUser = getLoggedInUser(sessionKey); - - Logger log = Logger.getLogger(ErrataFactory.class); - - Channel channel = ChannelFactory.lookupByLabelAndUser(channelLabel, - loggedInUser); - - if (channel == null) { - throw new NoSuchChannelException(); - } - - if (!channel.isCloned()) { - throw new InvalidChannelException("Cloned channel expected: " + - channel.getLabel()); - } - - Channel original = ChannelFactory.lookupOriginalChannel(channel); - - if (original == null) { - throw new InvalidChannelException("Cannot access original " + - "of the channel: " + channel.getLabel()); - } - - // check access to the original - if (ChannelFactory.lookupByIdAndUser(original.getId(), loggedInUser) == null) { - throw new LookupException("User " + loggedInUser.getLogin() + - " does not have access to channel " + original.getLabel()); - } - - if (!UserManager.verifyChannelAdmin(loggedInUser, channel)) { - throw new PermissionCheckFailureException(); - } - - List<Errata> errataToClone = new ArrayList<Errata>(); - List<Errata> errataToPublish = new ArrayList<Errata>(); - List<Errata> toReturn = new ArrayList<Errata>(); - - //We loop through once, making sure all the errata exist - for (String advisory : advisoryNames) { - Errata toClone = lookupErrata(advisory, loggedInUser.getOrg()); - errataToClone.add(toClone); - } - - //For each errata look up existing clones, or manually clone it - for (Errata toClone : errataToClone) { - List<Errata> clones = ErrataManager.lookupPublishedByOriginal( - loggedInUser, toClone); - if (clones.isEmpty()) { - errataToPublish.add(PublishErrataHelper.cloneErrataFast(toClone, loggedInUser.getOrg())); - } - else { - errataToPublish.add(clones.get(0)); - } - } - - //Now publish them all to the channel in a single shot - List<Errata> published = ErrataFactory.publishToChannel(errataToPublish, channel, - loggedInUser, true); - for (Errata e : published) { - ErrataFactory.save(e); - } - - return toReturn.toArray(); - } - - - /** - * Clones a list of errata into a specified cloned channel - * according the original erratas - * - * @param sessionKey The sessionKey containing the logged in user - * @param channelLabel the cloned channel's label that we are cloning into - * @param advisoryNames an array of String objects containing the advisory name - * of every errata you want to clone - * @throws InvalidChannelRoleException if the user perms are incorrect - * @return Returns an array of Errata objects, which get serialized into XMLRPC - * - * @xmlrpc.doc Clones a list of errata into a specified cloned channel - * according the original erratas - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "channel_label") - * @xmlrpc.param - * #array_single("string", " advisory - The advisory name of the errata to clone.") - * @xmlrpc.returntype - * #array() - * $ErrataSerializer - * #array_end() - */ - public Object[] cloneAsOriginal(String sessionKey, String channelLabel, - List<String> advisoryNames) throws InvalidChannelRoleException { - return clone(sessionKey, channelLabel, advisoryNames, true); - } - - - - - private Object getRequiredAttribute(Map map, String attribute) { - Object value = map.get(attribute); - if (value == null || StringUtils.isEmpty(value.toString())) { - throw new MissingErrataAttributeException(attribute); - } - else { - return value; - } - } - - /** - * creates an errata - * @param sessionKey The sessionKey containing the logged in user - * @param errataInfo map containing the following values: - * String "synopsis" short synopsis of the errata - * String "advisory_name" advisory name of the errata - * Integer "advisory_release" release number of the errata - * String "advisory_type" the type of advisory for the errata (Must be one of the - * following: "Security Advisory", "Product Enhancement Advisory", or - * "Bug Fix Advisory" - * String "product" the product the errata affects - * String "errataFrom" the author of the errata - * String "topic" the topic of the errata - * String "description" the description of the errata - * String "solution" the solution of the errata - * String "references" references of the errata to be created - * String "notes" notes on the errata - * @param bugs a List of maps consisting of 'id' Integers and 'summary' strings - * @param keywords a List of keywords for the errata - * @param packageIds a List of package Id packageId Integers - * @param publish should the errata be published - * @param channelLabels an array of channel labels to publish to if the errata is to - * be published - * @throws InvalidChannelRoleException if the user perms are incorrect - * @return The errata created (whether published or unpublished) - * - * @xmlrpc.doc Create a custom errata. If "publish" is set to true, - * the errata will be published as well - * @xmlrpc.param #session_key() - * @xmlrpc.param - * #struct("errata info") - * #prop("string", "synopsis") - * #prop("string", "advisory_name") - * #prop("int", "advisory_release") - * #prop_desc("string", "advisory_type", "Type of advisory (one of the - * following: 'Security Advisory', 'Product Enhancement Advisory', - * or 'Bug Fix Advisory'") - * #prop("string", "product") - * #prop("string", "errataFrom") - * #prop("string", "topic") - * #prop("string", "description") - * #prop("string", "references") - * #prop("string", "notes") - * #prop("string", "solution") - * #struct_end() - * @xmlrpc.param - * #array() - * #struct("bug") - * #prop_desc("int", "id", "Bug Id") - * #prop("string", "summary") - * #prop("string", "url") - * #struct_end() - * #array_end() - * @xmlrpc.param #array_single("string", "keyword - List of keywords to associate - * with the errata.") - * @xmlrpc.param #array_single("int", "packageId") - * @xmlrpc.param #param_desc("boolean", "publish", "Should the errata be published.") - * @xmlrpc.param - * #array_single("string", "channelLabel - list of channels the errata should be - * published too, ignored if publish is set to false") - * @xmlrpc.returntype - * $ErrataSerializer - */ - public Errata create(String sessionKey, Map errataInfo, - List bugs, List keywords, List packageIds, boolean publish, - List channelLabels) throws InvalidChannelRoleException { - - // confirm that the user only provided valid keys in the map - Set<String> validKeys = new HashSet<String>(); - validKeys.add("synopsis"); - validKeys.add("advisory_name"); - validKeys.add("advisory_release"); - validKeys.add("advisory_type"); - validKeys.add("product"); - validKeys.add("errataFrom"); - validKeys.add("topic"); - validKeys.add("description"); - validKeys.add("references"); - validKeys.add("notes"); - validKeys.add("solution"); - validateMap(validKeys, errataInfo); - - validKeys.clear(); - validKeys.add("id"); - validKeys.add("summary"); - validKeys.add("url"); - for (Map<String, Object> bugMap : (ArrayList<Map<String, Object>>) bugs) { - validateMap(validKeys, bugMap); - } - - User loggedInUser = getLoggedInUser(sessionKey); - - //Don't want them to publish an errata without any channels, - //so check first before creating anything - List channels = null; - if (publish) { - channels = verifyChannelList(channelLabels, loggedInUser); - } - - String synopsis = (String) getRequiredAttribute(errataInfo, "synopsis"); - String advisoryName = (String) getRequiredAttribute(errataInfo, "advisory_name"); - Integer advisoryRelease = (Integer) getRequiredAttribute(errataInfo, - "advisory_release"); - if (advisoryRelease.longValue() > ErrataManager.MAX_ADVISORY_RELEASE) { - throw new InvalidAdvisoryReleaseException(advisoryRelease.longValue()); - } - String advisoryType = (String) getRequiredAttribute(errataInfo, "advisory_type"); - String product = (String) getRequiredAttribute(errataInfo, "product"); - String errataFrom = (String) errataInfo.get("errataFrom"); - String topic = (String) getRequiredAttribute(errataInfo, "topic"); - String description = (String) getRequiredAttribute(errataInfo, "description"); - String solution = (String) getRequiredAttribute(errataInfo, "solution"); - String references = (String) errataInfo.get("references"); - String notes = (String) errataInfo.get("notes"); - - Errata newErrata = ErrataManager.lookupByAdvisory(advisoryName); - if (newErrata != null) { - throw new DuplicateErrataException(advisoryName); - } - newErrata = ErrataManager.createNewErrata(); - newErrata.setOrg(loggedInUser.getOrg()); - - //all required - newErrata.setSynopsis(synopsis); - newErrata.setAdvisory(advisoryName + "-" + advisoryRelease.toString()); - newErrata.setAdvisoryName(advisoryName); - newErrata.setAdvisoryRel(new Long(advisoryRelease.longValue())); - - if (advisoryType.equals("Security Advisory") || - advisoryType.equals("Product Enhancement Advisory") || - advisoryType.equals("Bug Fix Advisory")) { - - newErrata.setAdvisoryType(advisoryType); - } - else { - throw new InvalidAdvisoryTypeException(advisoryType); - } - - newErrata.setProduct(product); - newErrata.setTopic(topic); - newErrata.setDescription(description); - newErrata.setSolution(solution); - newErrata.setIssueDate(new Date()); - newErrata.setUpdateDate(new Date()); - - //not required - newErrata.setErrataFrom(errataFrom); - newErrata.setRefersTo(references); - newErrata.setNotes(notes); - - for (Iterator itr = bugs.iterator(); itr.hasNext();) { - Map bugMap = (Map) itr.next(); - String url = ""; - if (bugMap.containsKey("url")) { - url = (String) bugMap.get("url"); - } - - Bug bug = ErrataFactory.createPublishedBug( - new Long(((Integer)bugMap.get("id")).longValue()), - (String)bugMap.get("summary"), url); - newErrata.addBug(bug); - } - for (Iterator itr = keywords.iterator(); itr.hasNext();) { - String keyword = (String) itr.next(); - newErrata.addKeyword(keyword); - } - - newErrata.setPackages(new HashSet()); - for (Iterator itr = packageIds.iterator(); itr.hasNext();) { - Integer pid = (Integer) itr.next(); - Package pack = PackageFactory.lookupByIdAndOrg(new Long(pid.longValue()), - loggedInUser.getOrg()); - if (pack != null) { - newErrata.addPackage(pack); - } - else { - throw new InvalidPackageException(pid.toString()); - } - } - - ErrataFactory.save(newErrata); - - //if true, channels will not be null, but will be a List of channel objects - if (publish) { - return publish(newErrata, channels, loggedInUser, false); - } - else { - return newErrata; - } - } - - /** - * Delete an erratum. - * @param sessionKey session of the logged in user - * @param advisoryName The advisory Name of the erratum to delete - * @throws FaultException if unknown or invalid erratum is provided. - * @return 1 on success, exception thrown otherwise. - * - * @xmlrpc.doc Delete an erratum. This method will only allow for deletion - * of custom errata created either through the UI or API. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.returntype #return_int_success() - */ - public Integer delete(String sessionKey, String advisoryName) - throws FaultException { - User loggedInUser = getLoggedInUser(sessionKey); - Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); - - if (errata.getOrg() == null) { - // Errata in the null org should not be modified; therefore, this is - // considered an invalid errata for this request - throw new InvalidErrataException(errata.getAdvisoryName()); - } - - ErrataManager.deleteErratum(loggedInUser, errata); - return 1; - } - - /** - * Publishes an existing (unpublished) errata to a set of channels - * @param sessionKey session of the logged in user - * @param advisory The advisory Name of the errata to publish - * @param channelLabels List of channels to publish the errata to - * @throws InvalidChannelRoleException if the user perms are incorrect - * @return the published errata - * - * @xmlrpc.doc Publish an existing (unpublished) errata to a set of channels. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.param - * #array_single("string", "channelLabel - list of channel labels to publish to") - * @xmlrpc.returntype - * $ErrataSerializer - */ - public Errata publish(String sessionKey, String advisory, List channelLabels) - throws InvalidChannelRoleException { - User loggedInUser = getLoggedInUser(sessionKey); - List channels = verifyChannelList(channelLabels, loggedInUser); - Errata toPublish = lookupErrata(advisory, loggedInUser.getOrg()); - return publish(toPublish, channels, loggedInUser, false); - } - - /** - * Publishes an existing (unpublished) cloned errata to a set of cloned channels - * according to its original erratum - * @param sessionKey session of the logged in user - * @param advisory The advisory Name of the errata to publish - * @param channelLabels List of channels to publish the errata to - * @throws InvalidChannelRoleException if the user perms are incorrect - * @return the published errata - * - * @xmlrpc.doc Publishes an existing (unpublished) cloned errata to a set of cloned - * channels according to its original erratum - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "advisoryName") - * @xmlrpc.param - * #array_single("string", "channelLabel - list of channel labels to publish to") - * @xmlrpc.returntype - * $ErrataSerializer - */ - public Errata publishAsOriginal(String sessionKey, String advisory, - List channelLabels) throws InvalidChannelRoleException { - User loggedInUser = getLoggedInUser(sessionKey); - List<Channel> channels = verifyChannelList(channelLabels, loggedInUser); - for (Channel c : channels) { - ClonedChannel cc = null; - try { - cc = (ClonedChannel) c; - } - catch (ClassCastException e) { - // just catch, do not do anything - } - finally { - if (cc == null || !cc.isCloned()) { - throw new InvalidChannelException("Cloned channel " + - "expected: " + c.getLabel()); - } - } - Channel original = ChannelFactory.lookupOriginalChannel(c); - if (original == null) { - throw new InvalidChannelException("Cannot access original " + - "of the channel: " + c.getLabel()); - } - // check access to the original - if (ChannelFactory.lookupByIdAndUser(original.getId(), loggedInUser) == null) { - throw new LookupException("User " + loggedInUser.getLogin() + - " does not have access to channel " + original.getLabel()); - } - } - Errata toPublish = lookupErrata(advisory, loggedInUser.getOrg()); - if (!toPublish.isCloned()) { - throw new InvalidErrataException("Cloned errata expected."); - } - return publish(toPublish, channels, loggedInUser, true); - } - - /** - * Verify a list of channels labels, and populate their corresponding - * Channel objects into a List. This is primarily used before publishing - * to verify all channels are valid before starting the errata creation - * @param channelsLabels the List of channel labels to verify - * @param org the org of the user - * @return a List of channel objects - */ - private List<Channel> verifyChannelList(List channelsLabels, User user) { - if (channelsLabels.size() == 0) { - throw new NoChannelsSelectedException(); - } - - List<Channel> resolvedList = new ArrayList<Channel>(); - for (Iterator itr = channelsLabels.iterator(); itr.hasNext();) { - String channelLabel = (String) itr.next(); - Channel channel = ChannelFactory.lookupByLabelAndUser(channelLabel, user); - if (channel == null) { - throw new InvalidChannelLabelException(); - } - if (!UserManager.verifyChannelAdmin(user, channel)) { - throw new PermissionCheckFailureException(); - } - resolvedList.add(channel); - } - return resolvedList; - } - - /** - * private helper method to publish the errata - * @param errata the Unpublished errata to publish - * @param channels A list of channel objects - * @return The published Errata - */ - private Errata publish(Errata errata, List<Channel> channels, User user, - boolean inheritPackages) { - Errata published = ErrataFactory.publish(errata); - for (Channel chan : channels) { - List<Errata> list = new ArrayList<Errata>(); - list.add(published); - published = ErrataFactory.publishToChannel(list, chan, user, - inheritPackages).get(0); - - } - return published; - } - - - /** - * list errata by date - * @param sessionKey session of the logged in user - * @param channelLabel channel associated with the errata you are interested in. - * @return List of Errata objects - * @deprecated being replaced by channel.software.listErrata(string sessionKey, - * string channelLabel) - * - * @xmlrpc.doc List errata that have been applied to a particular channel by date. - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "channelLabel") - * @xmlrpc.returntype - * #array() - * $ErrataSerializer - * #array_end() - */ - @Deprecated - public List listByDate(String sessionKey, String channelLabel) { - User loggedInUser = getLoggedInUser(sessionKey); - Channel channel = ChannelFactory.lookupByLabel(loggedInUser.getOrg(), - channelLabel); - return ErrataFactory.lookupByChannelSorted(loggedInUser.getOrg(), channel); - } - - /** - * Lookup the details for errata associated with the given CVE. - * @param sessionKey session of the logged in user - * @param cveName name of the CVE - * @return List of Errata objects - * - * @xmlrpc.doc Lookup the details for errata associated with the given CVE - * (e.g. CVE-2008-3270) - * @xmlrpc.param #session_key() - * @xmlrpc.param #param("string", "cveName") - * @xmlrpc.returntype - * #array() - * $ErrataSerializer - * #array_end() - */ - public List<Errata> findByCve(String sessionKey, String cveName) { - // Get the logged in user. We don't care what roles this user has, we - // just want to make sure the caller is logged in. - User loggedInUser = getLoggedInUser(sessionKey); - - List<Errata> erratas = ErrataManager.lookupByCVE(cveName); - for (Errata errata : erratas) { - // Remove errata that do not apply to the user's org - if (errata.getOrg() != null && - !errata.getOrg().equals(loggedInUser.getOrg())) { - erratas.remove(errata); - } - } - return erratas; - } + * + * @xmlrpc.doc Returns a list of <a href="http://www.cve.mitre.org/">CVE</a>s + * applicable to the erratum with the given advisory name. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype + * #array_single("string", "cveName") + * + */ + public List listCves(String sessionKey, String advisoryName) throws FaultException { + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + DataResult dr = ErrataManager.errataCVEs(errata.getId()); + List returnList = new ArrayList(); + + //Just return the name of the cve... + for (Iterator itr = dr.iterator(); itr.hasNext();) { + CVE cve = (CVE) itr.next(); + returnList.add(cve.getName()); + } + + return returnList; + } + + /** + * List the packages for a given erratum + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the erratum + * @return Returns an Array of maps representing a package + * @throws FaultException A FaultException is thrown if the errata corresponding to the + * given advisoryName cannot be found + * + * @xmlrpc.doc Returns a list of the packages affected by the erratum + * with the given advisory name. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype + * #array() + * #struct("package") + * #prop("int", "id") + * #prop("string", "name") + * #prop("string", "epoch") + * #prop("string", "version") + * #prop("string", "release") + * #prop("string", "arch_label") + * #prop_array("providing_channels", "string", "- Channel label + * providing this package.") + * #prop("string", "build_host") + * #prop("string", "description") + * #prop("string", "checksum") + * #prop("string", "vendor") + * #prop("string", "summary") + * #prop("string", "cookie") + * #prop("string", "license") + * #prop("string", "path") + * #prop("string", "build_date") + * #prop("string", "last_modified_date") + * #prop("string", "size") + * #prop("string", "payload_size") + * #struct_end() + * #array_end() + */ + public List<Map> listPackages(String sessionKey, String advisoryName) + throws FaultException { + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + List<Map> toRet = new ArrayList<Map>(); + for (PackageDto dto : PackageManager.listPackageDtosForErrata(errata)) { + toRet.add(PackageHelper.packageToMap(dto, loggedInUser)); + } + return toRet; + + } + + /** + * Add a set of packages to an erratum + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the erratum + * @param packageIds The ids for packages to remove + * @return Returns int - representing the number of packages added, exception otherwise + * @throws FaultException A FaultException is thrown if the errata corresponding to the + * given advisoryName cannot be found + * + * @xmlrpc.doc Add a set of packages to an erratum + * with the given advisory name. This method will only allow for modification + * of custom errata created either through the UI or API. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.param #array_single("int", "packageId") + * @xmlrpc.returntype int - representing the number of packages added, + * exception otherwise + */ + public int addPackages(String sessionKey, String advisoryName, + List<Integer> packageIds) throws FaultException { + + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + if (errata.getOrg() == null) { + // Errata in the null org should not be modified; therefore, this is + // considered an invalid errata for this request + throw new InvalidErrataException(errata.getAdvisoryName()); + } + + int packagesAdded = 0; + for (Integer packageId : packageIds) { + + Package pkg = PackageManager.lookupByIdAndUser(new Long(packageId), + loggedInUser); + + if ((pkg != null) && (!errata.getPackages().contains(pkg))) { + errata.addPackage(pkg); + packagesAdded++; + } + } + + //Update Errata Cache + if ((packagesAdded > 0) && errata.isPublished() && + (errata.getChannels() != null)) { + ErrataCacheManager.updateCacheForChannelsAsync( + errata.getChannels()); + } + + //Save the errata + ErrataManager.storeErrata(errata); + + return packagesAdded; + } + + /** + * Remove a set of packages from an erratum + * @param sessionKey The sessionKey for the logged in user + * @param advisoryName The advisory name of the erratum + * @param packageIds The ids for packages to remove + * @return Returns int - representing the number of packages removed, + * exception otherwise + * @throws FaultException A FaultException is thrown if the errata corresponding to the + * given advisoryName cannot be found + * + * @xmlrpc.doc Remove a set of packages from an erratum + * with the given advisory name. This method will only allow for modification + * of custom errata created either through the UI or API. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.param #array_single("int", "packageId") + * @xmlrpc.returntype int - representing the number of packages removed, + * exception otherwise + */ + public int removePackages(String sessionKey, String advisoryName, + List<Integer> packageIds) throws FaultException { + + // Get the logged in user + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + if (errata.getOrg() == null) { + // Errata in the null org should not be modified; therefore, this is + // considered an invalid errata for this request + throw new InvalidErrataException(errata.getAdvisoryName()); + } + + int packagesRemoved = 0; + for (Integer packageId : packageIds) { + + Package pkg = PackageManager.lookupByIdAndUser(new Long(packageId), + loggedInUser); + + if ((pkg != null) && (errata.getPackages().contains(pkg))) { + errata.removePackage(pkg); + packagesRemoved++; + } + } + + //Update Errata Cache + if ((packagesRemoved > 0) && errata.isPublished() && + (errata.getChannels() != null)) { + ErrataCacheManager.updateCacheForChannelsAsync( + errata.getChannels()); + } + + //Save the errata + ErrataManager.storeErrata(errata); + + return packagesRemoved; + } + + /** + * Private helper method to lookup an errata and throw a Fault exception if it isn't + * found + * @param advisoryName The advisory name for the erratum you're looking for + * @return Returns the errata or a Fault Exception + * @throws FaultException Occurs when the erratum is not found + */ + private Errata lookupErrata(String advisoryName, Org org) throws FaultException { + Errata errata = ErrataManager.lookupByAdvisory(advisoryName); + + /* + * ErrataManager.lookupByAdvisory() could return null, so we need to check + * and throw a no_such_errata exception if the errata was not found. + */ + if (errata == null) { + throw new FaultException(-208, "no_such_errata", + "The errata " + advisoryName + " cannot be found."); + } + /** + * errata with org_id of null are public, but ones with an org id of !null are not + * need to make sure here that everything is checked correclty + */ + if (errata.getOrg() != null && !errata.getOrg().equals(org)) { + throw new FaultException(-209, "no_such_errata", + "The errata " + advisoryName + " cannot be found."); + } + + return errata; + } + + /** + * Clones a list of errata into a specified channel + * + * @param sessionKey The sessionKey containing the logged in user + * @param channelLabel the channel's label that we are cloning into + * @param advisoryNames an array of String objects containing the advisory name + * of every errata you want to clone + * @throws InvalidChannelRoleException if the user perms are incorrect + * @return Returns an array of Errata objects, which get serialized into XMLRPC + * + * @xmlrpc.doc Clone a list of errata into the specified channel. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "channel_label") + * @xmlrpc.param + * #array_single("string", " advisory - The advisory name of the errata to clone.") + * @xmlrpc.returntype + * #array() + * $ErrataSerializer + * #array_end() + */ + public Object[] clone(String sessionKey, String channelLabel, + List advisoryNames) throws InvalidChannelRoleException { + return clone(sessionKey, channelLabel, advisoryNames, false); + } + + + private Object[] clone(String sessionKey, String channelLabel, + List<String> advisoryNames, boolean inheritAllPackages) { + User loggedInUser = getLoggedInUser(sessionKey); + + Logger log = Logger.getLogger(ErrataFactory.class); + + Channel channel = ChannelFactory.lookupByLabelAndUser(channelLabel, + loggedInUser); + + if (channel == null) { + throw new NoSuchChannelException(); + } + + if (!channel.isCloned()) { + throw new InvalidChannelException("Cloned channel expected: " + + channel.getLabel()); + } + + Channel original = ChannelFactory.lookupOriginalChannel(channel); + + if (original == null) { + throw new InvalidChannelException("Cannot access original " + + "of the channel: " + channel.getLabel()); + } + + // check access to the original + if (ChannelFactory.lookupByIdAndUser(original.getId(), loggedInUser) == null) { + throw new LookupException("User " + loggedInUser.getLogin() + + " does not have access to channel " + original.getLabel()); + } + + if (!UserManager.verifyChannelAdmin(loggedInUser, channel)) { + throw new PermissionCheckFailureException(); + } + + List<Errata> errataToClone = new ArrayList<Errata>(); + List<Errata> errataToPublish = new ArrayList<Errata>(); + List<Errata> toReturn = new ArrayList<Errata>(); + + //We loop through once, making sure all the errata exist + for (String advisory : advisoryNames) { + Errata toClone = lookupErrata(advisory, loggedInUser.getOrg()); + errataToClone.add(toClone); + } + + //For each errata look up existing clones, or manually clone it + for (Errata toClone : errataToClone) { + List<Errata> clones = ErrataManager.lookupPublishedByOriginal( + loggedInUser, toClone); + if (clones.isEmpty()) { + errataToPublish.add(PublishErrataHelper.cloneErrataFast(toClone, + loggedInUser.getOrg())); + } + else { + errataToPublish.add(clones.get(0)); + } + } + + //Now publish them all to the channel in a single shot + List<Errata> published = ErrataFactory.publishToChannel(errataToPublish, channel, + loggedInUser, true); + for (Errata e : published) { + ErrataFactory.save(e); + } + + return toReturn.toArray(); + } + + + /** + * Clones a list of errata into a specified cloned channel + * according the original erratas + * + * @param sessionKey The sessionKey containing the logged in user + * @param channelLabel the cloned channel's label that we are cloning into + * @param advisoryNames an array of String objects containing the advisory name + * of every errata you want to clone + * @throws InvalidChannelRoleException if the user perms are incorrect + * @return Returns an array of Errata objects, which get serialized into XMLRPC + * + * @xmlrpc.doc Clones a list of errata into a specified cloned channel + * according the original erratas + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "channel_label") + * @xmlrpc.param + * #array_single("string", " advisory - The advisory name of the errata to clone.") + * @xmlrpc.returntype + * #array() + * $ErrataSerializer + * #array_end() + */ + public Object[] cloneAsOriginal(String sessionKey, String channelLabel, + List<String> advisoryNames) throws InvalidChannelRoleException { + return clone(sessionKey, channelLabel, advisoryNames, true); + } + + + + + private Object getRequiredAttribute(Map map, String attribute) { + Object value = map.get(attribute); + if (value == null || StringUtils.isEmpty(value.toString())) { + throw new MissingErrataAttributeException(attribute); + } + else { + return value; + } + } + + /** + * creates an errata + * @param sessionKey The sessionKey containing the logged in user + * @param errataInfo map containing the following values: + * String "synopsis" short synopsis of the errata + * String "advisory_name" advisory name of the errata + * Integer "advisory_release" release number of the errata + * String "advisory_type" the type of advisory for the errata (Must be one of the + * following: "Security Advisory", "Product Enhancement Advisory", or + * "Bug Fix Advisory" + * String "product" the product the errata affects + * String "errataFrom" the author of the errata + * String "topic" the topic of the errata + * String "description" the description of the errata + * String "solution" the solution of the errata + * String "references" references of the errata to be created + * String "notes" notes on the errata + * @param bugs a List of maps consisting of 'id' Integers and 'summary' strings + * @param keywords a List of keywords for the errata + * @param packageIds a List of package Id packageId Integers + * @param publish should the errata be published + * @param channelLabels an array of channel labels to publish to if the errata is to + * be published + * @throws InvalidChannelRoleException if the user perms are incorrect + * @return The errata created (whether published or unpublished) + * + * @xmlrpc.doc Create a custom errata. If "publish" is set to true, + * the errata will be published as well + * @xmlrpc.param #session_key() + * @xmlrpc.param + * #struct("errata info") + * #prop("string", "synopsis") + * #prop("string", "advisory_name") + * #prop("int", "advisory_release") + * #prop_desc("string", "advisory_type", "Type of advisory (one of the + * following: 'Security Advisory', 'Product Enhancement Advisory', + * or 'Bug Fix Advisory'") + * #prop("string", "product") + * #prop("string", "errataFrom") + * #prop("string", "topic") + * #prop("string", "description") + * #prop("string", "references") + * #prop("string", "notes") + * #prop("string", "solution") + * #struct_end() + * @xmlrpc.param + * #array() + * #struct("bug") + * #prop_desc("int", "id", "Bug Id") + * #prop("string", "summary") + * #prop("string", "url") + * #struct_end() + * #array_end() + * @xmlrpc.param #array_single("string", "keyword - List of keywords to associate + * with the errata.") + * @xmlrpc.param #array_single("int", "packageId") + * @xmlrpc.param #param_desc("boolean", "publish", "Should the errata be published.") + * @xmlrpc.param + * #array_single("string", "channelLabel - list of channels the errata should be + * published too, ignored if publish is set to false") + * @xmlrpc.returntype + * $ErrataSerializer + */ + public Errata create(String sessionKey, Map errataInfo, + List bugs, List keywords, List packageIds, boolean publish, + List channelLabels) throws InvalidChannelRoleException { + + // confirm that the user only provided valid keys in the map + Set<String> validKeys = new HashSet<String>(); + validKeys.add("synopsis"); + validKeys.add("advisory_name"); + validKeys.add("advisory_release"); + validKeys.add("advisory_type"); + validKeys.add("product"); + validKeys.add("errataFrom"); + validKeys.add("topic"); + validKeys.add("description"); + validKeys.add("references"); + validKeys.add("notes"); + validKeys.add("solution"); + validateMap(validKeys, errataInfo); + + validKeys.clear(); + validKeys.add("id"); + validKeys.add("summary"); + validKeys.add("url"); + for (Map<String, Object> bugMap : (ArrayList<Map<String, Object>>) bugs) { + validateMap(validKeys, bugMap); + } + + User loggedInUser = getLoggedInUser(sessionKey); + + //Don't want them to publish an errata without any channels, + //so check first before creating anything + List channels = null; + if (publish) { + channels = verifyChannelList(channelLabels, loggedInUser); + } + + String synopsis = (String) getRequiredAttribute(errataInfo, "synopsis"); + String advisoryName = (String) getRequiredAttribute(errataInfo, "advisory_name"); + Integer advisoryRelease = (Integer) getRequiredAttribute(errataInfo, + "advisory_release"); + if (advisoryRelease.longValue() > ErrataManager.MAX_ADVISORY_RELEASE) { + throw new InvalidAdvisoryReleaseException(advisoryRelease.longValue()); + } + String advisoryType = (String) getRequiredAttribute(errataInfo, "advisory_type"); + String product = (String) getRequiredAttribute(errataInfo, "product"); + String errataFrom = (String) errataInfo.get("errataFrom"); + String topic = (String) getRequiredAttribute(errataInfo, "topic"); + String description = (String) getRequiredAttribute(errataInfo, "description"); + String solution = (String) getRequiredAttribute(errataInfo, "solution"); + String references = (String) errataInfo.get("references"); + String notes = (String) errataInfo.get("notes"); + + Errata newErrata = ErrataManager.lookupByAdvisory(advisoryName); + if (newErrata != null) { + throw new DuplicateErrataException(advisoryName); + } + newErrata = ErrataManager.createNewErrata(); + newErrata.setOrg(loggedInUser.getOrg()); + + //all required + newErrata.setSynopsis(synopsis); + newErrata.setAdvisory(advisoryName + "-" + advisoryRelease.toString()); + newErrata.setAdvisoryName(advisoryName); + newErrata.setAdvisoryRel(new Long(advisoryRelease.longValue())); + + if (advisoryType.equals("Security Advisory") || + advisoryType.equals("Product Enhancement Advisory") || + advisoryType.equals("Bug Fix Advisory")) { + + newErrata.setAdvisoryType(advisoryType); + } + else { + throw new InvalidAdvisoryTypeException(advisoryType); + } + + newErrata.setProduct(product); + newErrata.setTopic(topic); + newErrata.setDescription(description); + newErrata.setSolution(solution); + newErrata.setIssueDate(new Date()); + newErrata.setUpdateDate(new Date()); + + //not required + newErrata.setErrataFrom(errataFrom); + newErrata.setRefersTo(references); + newErrata.setNotes(notes); + + for (Iterator itr = bugs.iterator(); itr.hasNext();) { + Map bugMap = (Map) itr.next(); + String url = ""; + if (bugMap.containsKey("url")) { + url = (String) bugMap.get("url"); + } + + Bug bug = ErrataFactory.createPublishedBug( + new Long(((Integer)bugMap.get("id")).longValue()), + (String)bugMap.get("summary"), url); + newErrata.addBug(bug); + } + for (Iterator itr = keywords.iterator(); itr.hasNext();) { + String keyword = (String) itr.next(); + newErrata.addKeyword(keyword); + } + + newErrata.setPackages(new HashSet()); + for (Iterator itr = packageIds.iterator(); itr.hasNext();) { + Integer pid = (Integer) itr.next(); + Package pack = PackageFactory.lookupByIdAndOrg(new Long(pid.longValue()), + loggedInUser.getOrg()); + if (pack != null) { + newErrata.addPackage(pack); + } + else { + throw new InvalidPackageException(pid.toString()); + } + } + + ErrataFactory.save(newErrata); + + //if true, channels will not be null, but will be a List of channel objects + if (publish) { + return publish(newErrata, channels, loggedInUser, false); + } + else { + return newErrata; + } + } + + /** + * Delete an erratum. + * @param sessionKey session of the logged in user + * @param advisoryName The advisory Name of the erratum to delete + * @throws FaultException if unknown or invalid erratum is provided. + * @return 1 on success, exception thrown otherwise. + * + * @xmlrpc.doc Delete an erratum. This method will only allow for deletion + * of custom errata created either through the UI or API. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.returntype #return_int_success() + */ + public Integer delete(String sessionKey, String advisoryName) + throws FaultException { + User loggedInUser = getLoggedInUser(sessionKey); + Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg()); + + if (errata.getOrg() == null) { + // Errata in the null org should not be modified; therefore, this is + // considered an invalid errata for this request + throw new InvalidErrataException(errata.getAdvisoryName()); + } + + ErrataManager.deleteErratum(loggedInUser, errata); + return 1; + } + + /** + * Publishes an existing (unpublished) errata to a set of channels + * @param sessionKey session of the logged in user + * @param advisory The advisory Name of the errata to publish + * @param channelLabels List of channels to publish the errata to + * @throws InvalidChannelRoleException if the user perms are incorrect + * @return the published errata + * + * @xmlrpc.doc Publish an existing (unpublished) errata to a set of channels. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.param + * #array_single("string", "channelLabel - list of channel labels to publish to") + * @xmlrpc.returntype + * $ErrataSerializer + */ + public Errata publish(String sessionKey, String advisory, List channelLabels) + throws InvalidChannelRoleException { + User loggedInUser = getLoggedInUser(sessionKey); + List channels = verifyChannelList(channelLabels, loggedInUser); + Errata toPublish = lookupErrata(advisory, loggedInUser.getOrg()); + return publish(toPublish, channels, loggedInUser, false); + } + + /** + * Publishes an existing (unpublished) cloned errata to a set of cloned channels + * according to its original erratum + * @param sessionKey session of the logged in user + * @param advisory The advisory Name of the errata to publish + * @param channelLabels List of channels to publish the errata to + * @throws InvalidChannelRoleException if the user perms are incorrect + * @return the published errata + * + * @xmlrpc.doc Publishes an existing (unpublished) cloned errata to a set of cloned + * channels according to its original erratum + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "advisoryName") + * @xmlrpc.param + * #array_single("string", "channelLabel - list of channel labels to publish to") + * @xmlrpc.returntype + * $ErrataSerializer + */ + public Errata publishAsOriginal(String sessionKey, String advisory, + List channelLabels) throws InvalidChannelRoleException { + User loggedInUser = getLoggedInUser(sessionKey); + List<Channel> channels = verifyChannelList(channelLabels, loggedInUser); + for (Channel c : channels) { + ClonedChannel cc = null; + try { + cc = (ClonedChannel) c; + } + catch (ClassCastException e) { + // just catch, do not do anything + } + finally { + if (cc == null || !cc.isCloned()) { + throw new InvalidChannelException("Cloned channel " + + "expected: " + c.getLabel()); + } + } + Channel original = ChannelFactory.lookupOriginalChannel(c); + if (original == null) { + throw new InvalidChannelException("Cannot access original " + + "of the channel: " + c.getLabel()); + } + // check access to the original + if (ChannelFactory.lookupByIdAndUser(original.getId(), loggedInUser) == null) { + throw new LookupException("User " + loggedInUser.getLogin() + + " does not have access to channel " + original.getLabel()); + } + } + Errata toPublish = lookupErrata(advisory, loggedInUser.getOrg()); + if (!toPublish.isCloned()) { + throw new InvalidErrataException("Cloned errata expected."); + } + return publish(toPublish, channels, loggedInUser, true); + } + + /** + * Verify a list of channels labels, and populate their corresponding + * Channel objects into a List. This is primarily used before publishing + * to verify all channels are valid before starting the errata creation + * @param channelsLabels the List of channel labels to verify + * @param org the org of the user + * @return a List of channel objects + */ + private List<Channel> verifyChannelList(List channelsLabels, User user) { + if (channelsLabels.size() == 0) { + throw new NoChannelsSelectedException(); + } + + List<Channel> resolvedList = new ArrayList<Channel>(); + for (Iterator itr = channelsLabels.iterator(); itr.hasNext();) { + String channelLabel = (String) itr.next(); + Channel channel = ChannelFactory.lookupByLabelAndUser(channelLabel, user); + if (channel == null) { + throw new InvalidChannelLabelException(); + } + if (!UserManager.verifyChannelAdmin(user, channel)) { + throw new PermissionCheckFailureException(); + } + resolvedList.add(channel); + } + return resolvedList; + } + + /** + * private helper method to publish the errata + * @param errata the Unpublished errata to publish + * @param channels A list of channel objects + * @return The published Errata + */ + private Errata publish(Errata errata, List<Channel> channels, User user, + boolean inheritPackages) { + Errata published = ErrataFactory.publish(errata); + for (Channel chan : channels) { + List<Errata> list = new ArrayList<Errata>(); + list.add(published); + published = ErrataFactory.publishToChannel(list, chan, user, + inheritPackages).get(0); + + } + return published; + } + + + /** + * list errata by date + * @param sessionKey session of the logged in user + * @param channelLabel channel associated with the errata you are interested in. + * @return List of Errata objects + * @deprecated being replaced by channel.software.listErrata(string sessionKey, + * string channelLabel) + * + * @xmlrpc.doc List errata that have been applied to a particular channel by date. + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "channelLabel") + * @xmlrpc.returntype + * #array() + * $ErrataSerializer + * #array_end() + */ + @Deprecated + public List listByDate(String sessionKey, String channelLabel) { + User loggedInUser = getLoggedInUser(sessionKey); + Channel channel = ChannelFactory.lookupByLabel(loggedInUser.getOrg(), + channelLabel); + return ErrataFactory.lookupByChannelSorted(loggedInUser.getOrg(), channel); + } + + /** + * Lookup the details for errata associated with the given CVE. + * @param sessionKey session of the logged in user + * @param cveName name of the CVE + * @return List of Errata objects + * + * @xmlrpc.doc Lookup the details for errata associated with the given CVE + * (e.g. CVE-2008-3270) + * @xmlrpc.param #session_key() + * @xmlrpc.param #param("string", "cveName") + * @xmlrpc.returntype + * #array() + * $ErrataSerializer + * #array_end() + */ + public List<Errata> findByCve(String sessionKey, String cveName) { + // Get the logged in user. We don't care what roles this user has, we + // just want to make sure the caller is logged in. + User loggedInUser = getLoggedInUser(sessionKey); + + List<Errata> erratas = ErrataManager.lookupByCVE(cveName); + for (Errata errata : erratas) { + // Remove errata that do not apply to the user's org + if (errata.getOrg() != null && + !errata.getOrg().equals(loggedInUser.getOrg())) { + erratas.remove(errata); + } + } + return erratas; + }
}