gt:         Map<String, Object> params = new HashMap<String, Object>();
context: /**
   * Copyright (c) 2009--2014 Red Hat, Inc.
   *
   * This software is licensed to you under the GNU General Public License,
   * version 2 (GPLv2). There is NO WARRANTY for this software, express or
   * implied, including the implied warranties of MERCHANTABILITY or FITNESS
   * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
   * along with this software; if not, see
   * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
   *
   * Red Hat trademarks are not licensed under GPLv2. No permission is
   * granted to use or replicate Red Hat trademarks that are incorporated
   * in this software or its documentation.
   */
  package com.redhat.rhn.manager.rhnpackage;
  
  import com.redhat.rhn.common.conf.Config;
  import com.redhat.rhn.common.conf.ConfigDefaults;
  import com.redhat.rhn.common.db.datasource.DataResult;
  import com.redhat.rhn.common.db.datasource.ModeFactory;
  import com.redhat.rhn.common.db.datasource.SelectMode;
  import com.redhat.rhn.common.db.datasource.WriteMode;
  import com.redhat.rhn.common.hibernate.HibernateFactory;
  import com.redhat.rhn.common.localization.LocalizationService;
  import com.redhat.rhn.common.security.PermissionException;
  import com.redhat.rhn.common.util.CompressionUtil;
  import com.redhat.rhn.common.util.RpmVersionComparator;
  import com.redhat.rhn.domain.channel.Channel;
  import com.redhat.rhn.domain.channel.ChannelFactory;
  import com.redhat.rhn.domain.channel.DistChannelMap;
  import com.redhat.rhn.domain.errata.Errata;
  import com.redhat.rhn.domain.org.Org;
  import com.redhat.rhn.domain.org.OrgFactory;
  import com.redhat.rhn.domain.rhnpackage.Package;
  import com.redhat.rhn.domain.rhnpackage.PackageArch;
  import com.redhat.rhn.domain.rhnpackage.PackageEvr;
  import com.redhat.rhn.domain.rhnpackage.PackageEvrFactory;
  import com.redhat.rhn.domain.rhnpackage.PackageFactory;
  import com.redhat.rhn.domain.rhnpackage.PackageName;
  import com.redhat.rhn.domain.rhnset.RhnSet;
  import com.redhat.rhn.domain.role.RoleFactory;
  import com.redhat.rhn.domain.server.Server;
  import com.redhat.rhn.domain.user.User;
  import com.redhat.rhn.frontend.dto.PackageComparison;
  import com.redhat.rhn.frontend.dto.PackageFileDto;
  import com.redhat.rhn.frontend.dto.UpgradablePackageListItem;
  import com.redhat.rhn.frontend.listview.PageControl;
  import com.redhat.rhn.frontend.xmlrpc.PermissionCheckFailureException;
  import com.redhat.rhn.manager.BaseManager;
  import com.redhat.rhn.manager.channel.ChannelManager;
  import com.redhat.rhn.manager.errata.cache.ErrataCacheManager;
  import com.redhat.rhn.manager.rhnset.RhnSetDecl;
  import com.redhat.rhn.manager.rhnset.RhnSetManager;
  import com.redhat.rhn.manager.satellite.SystemCommandExecutor;
  import com.redhat.rhn.manager.system.IncompatibleArchException;
  
  import org.apache.commons.lang.StringUtils;
  import org.apache.log4j.Logger;
  import org.hibernate.HibernateException;
  import org.hibernate.Session;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  /**
   * PackageManager
   * @version $Rev$
   */
  public class PackageManager extends BaseManager {
      private static final Logger LOG = Logger.getLogger(PackageManager.class);
      public static final String RHNCFG = "rhncfg";
      public static final String RHNCFG_CLIENT = "rhncfg-client";
      public static final String RHNCFG_ACTIONS = "rhncfg-actions";
  
      // Valid dependency types
      public static final String[]
          DEPENDENCY_TYPES = {"requires", "conflicts", "obsoletes", "provides",
              "recommends", "suggests", "supplements", "enhances"};
  
  
      private static final String[]
          CLEANUP_QUERIES = {"requires", "provides", "conflicts", "obsoletes",
              "recommends", "suggests", "supplements", "enhances",
              "channels", "files", "caps", "changelogs"};
  
      /**
       * Runs Package_queries.package_obsoletes query, which returns dependencies of the
       * obsolete type.
       * @param pid The package in question
       * @return Returns dependencies of type obsolete.
       */
      public static DataResult packageObsoletes(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_obsoletes",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Runs Package_queries.package_conflicts query, which returns dependencies of the
       * conflicts type.
       * @param pid The package in question
       * @return Returns dependencies of type conflicts.
       */
      public static DataResult packageConflicts(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_conflicts",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Runs Package_queries.package_provides query, which returns dependencies of the
       * provides type.
       * @param pid The package in question
       * @return Returns dependencies of type provides.
       */
      public static DataResult packageProvides(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_provides",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Runs Package_queries.package_requires query, which returns dependencies of the
       * requires type.
       * @param pid The package in question
       * @return Returns dependencies of type requires.
       */
      public static DataResult packageRequires(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_requires",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Runs Package_queries.package_recommends query, which returns dependencies of the
       * recommends type.
       * @param pid The package in question
       * @return Returns dependencies of type recommends.
       */
      public static DataResult packageRecommends(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_recommends",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Runs Package_queries.package_suggests query, which returns dependencies of the
       * suggests type.
       * @param pid The package in question
       * @return Returns dependencies of type suggests.
       */
      public static DataResult packageSuggests(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_suggests",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Runs Package_queries.package_supplements query, which returns dependencies of the
       * supplements type.
       * @param pid The package in question
       * @return Returns dependencies of type supplements.
       */
      public static DataResult packageSupplements(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_supplements",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Runs Package_queries.package_enhances query, which returns dependencies of the
       * enhances type.
       * @param pid The package in question
       * @return Returns dependencies of type enhances.
       */
      public static DataResult packageEnhances(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_enhances",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * List the package in a channel (for the web UI lists)
       * @param cid the channel id
       * @return the list of packages
       */
      public static DataResult listPackagesInChannelForList(Long cid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "packages_in_channel");
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("cid", cid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
  
      /**
       * Runs Channel_queries.org_pkg_channels query.
       * @param orgId The id of the org for the logged in user
       * @param pid The id of the package in question
       * @return Returns a list of channels that provide the given package
       */
      public static DataResult orgPackageChannels(Long orgId, Long pid) {
          SelectMode m = ModeFactory.getMode("Channel_queries", "org_pkg_channels",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          params.put("org_id", orgId);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Returns the erratas providing a given package
       * @param orgId The id of the org for the logged in user
       * @param pid The package id for the package in question
       * @return Returns a list of errata that provide the given package
       */
      public static DataResult providingErrata(Long orgId, Long pid) {
          SelectMode m = ModeFactory.getMode("Errata_queries", "org_pkg_errata", Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          params.put("org_id", orgId);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Returns the files associated with a given package
       * @param pid The package id for the package in question
       * @return Returns a list of files associated with the package
       */
      public static DataResult<PackageFileDto> packageFiles(Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "package_files");
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Return information related to packages that are udpates to this one
       * @param user The user in question
       * @param pid The package in question
       * @return A map of updating package information
       */
      public static DataResult<Map<String, Object>> obsoletingPackages(User user, Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "obsoleting_packages");
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          params.put("org_id", user.getOrg().getId());
          return m.execute(params);
      }
  
      /**
       * Returns the providing channels for a package that the given user has access to
       * @param user The user requesting the channels
       * @param pid The package in question
       * @return Returns a list of providing channels (id, name, label) for a package
       */
      public static DataResult providingChannels(User user, Long pid) {
          SelectMode m = ModeFactory.getMode("Package_queries", "providing_channels",
                                             Map.class);
          Map<String, Object> params = new HashMap<String, Object>();
          params.put("pid", pid);
          params.put("org_id", user.getOrg().getId());
          DataResult dr = m.execute(params);
          return dr;
      }
  
      /**
       * Returns list of package for given server
       * @param sid Server Id
       * @param pc PageControl can also be null.
       * @return list of packages for given server
       */
      public static DataResult systemPackageList(Long sid, PageControl pc) {
  
          SelectMode m = ModeFactory.getMode("Package_queries", "system_package_list");
  