private PackageAction syncToVictim(
      RequestContext requestContext, Long sid, Set pkgIdCombos, String option) {

    PackageAction pa = null;
    Date time = new Date(requestContext.getParamAsLong("time"));

    if (isProfileSync(requestContext)) {
      Long prid = requestContext.getRequiredParam("prid");

      pa =
          ProfileManager.syncToProfile(
              requestContext.getCurrentUser(), sid, prid, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(
          ProfileManager.lookupByIdAndOrg(prid, requestContext.getCurrentUser().getOrg())
              .getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    } else if (isSystemSync(requestContext)) {
      Long sid1 = requestContext.getRequiredParam("sid_1");
      pa =
          ProfileManager.syncToSystem(
              requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(SystemManager.lookupByIdAndUser(sid1, requestContext.getCurrentUser()).getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    }

    addHardwareMessage(pa, requestContext);

    return pa;
  }
 /**
  * Get the DataResult list of com.redhat.rhn.frontend.dto.ProfileDto that are compatible with the
  * BaseChannel for the selected KickstartData object.
  *
  * @return DataResult list
  */
 public List<ProfileDto> getProfiles() {
   if (!isCobblerOnly()) {
     List<ProfileDto> profiles =
         ProfileManager.compatibleWithChannel(
             this.ksdata.getKickstartDefaults().getKstree().getChannel(), user.getOrg(), null);
     return profiles;
   }
   return Collections.EMPTY_LIST;
 }
  /** {@inheritDoc} */
  protected DataResult getDataResult(User user, ActionForm formIn, HttpServletRequest request) {
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    Set<String> pkgIdCombos = SessionSetHelper.lookupAndBind(request, getDecl(requestContext, sid));

    if (isProfileSync(requestContext)) {
      Long prid = requestContext.getRequiredParam("prid");

      return ProfileManager.getMissingProfilePackages(
          requestContext.getCurrentUser(), sid, prid, pkgIdCombos, null);
    } else if (isSystemSync(requestContext)) {
      Long sid1 = requestContext.getRequiredParam("sid_1");

      return ProfileManager.getMissingSystemPackages(
          requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, null);
    }

    return null;
  }
  private Profile processProfileType(String profileTypeIn) {
    log.debug("PROFILE_TYPE=" + profileTypeIn);

    if (profileTypeIn == null
        || profileTypeIn.length() == 0
        || // TODO: fix this hack
        profileTypeIn.equals(TARGET_PROFILE_TYPE_NONE)) {
      return null;
    }
    Profile retval = null;
    // Profile of this existing system's packages
    String pname =
        LocalizationService.getInstance()
            .getMessage("kickstart.session.newprofile", this.kickstartSession.getId().toString());
    if (profileTypeIn.equals(TARGET_PROFILE_TYPE_EXISTING)) {
      log.debug("    TARGET_PROFILE_TYPE_EXISTING");
      // "Profile for kickstart session "
      retval =
          ProfileManager.createProfile(
              ProfileFactory.TYPE_SYNC_PROFILE,
              this.user,
              getTargetServer().getBaseChannel(),
              pname,
              pname);
      ProfileManager.copyFrom(this.server, retval);
    }
    // Profile of 'stored profile'
    else if (profileTypeIn.equals(TARGET_PROFILE_TYPE_PACKAGE)) {
      log.debug("    TARGET_PROFILE_TYPE_PACKAGE");
      if (this.profileId == null) {
        throw new UnsupportedOperationException(
            "You specified a target profile type"
                + TARGET_PROFILE_TYPE_PACKAGE
                + " but this.profileId is null");
      }
      retval = ProfileManager.lookupByIdAndOrg(this.profileId, this.user.getOrg());
    }
    // Some other system's profile
    else if (profileTypeIn.equals(TARGET_PROFILE_TYPE_SYSTEM)) {
      Server otherServer = ServerFactory.lookupById(this.serverProfileId);
      log.debug("    TARGET_PROFILE_TYPE_SYSTEM");
      log.debug("    this.serverProfileId      : " + this.serverProfileId);
      log.debug("    otherServer               : " + otherServer);
      if (otherServer != null) {
        log.debug("otherServer.Id            : " + otherServer.getId());
        log.debug("otherServer.getBaseChannel: " + otherServer.getBaseChannel());
      }

      retval =
          ProfileManager.createProfile(
              ProfileFactory.TYPE_SYNC_PROFILE,
              this.user,
              otherServer.getBaseChannel(),
              pname,
              pname);
      ProfileManager.copyFrom(otherServer, retval);
    }
    this.kickstartSession.setServerProfile(retval);
    KickstartFactory.saveKickstartSession(this.kickstartSession);

    if (getTargetServer() != null) {
      HibernateFactory.getSession().refresh(getTargetServer());
    }

    // TODO: Compute missing packages and forward user to the missing page

    return retval;
  }