protected static void copyCourseOfferingInfo(
      CourseOfferingCreateWrapper coCreateWrapper,
      String targetTermCode,
      String catalogCourseCode,
      String coId) {
    ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();

    if (targetTermCode != null) {
      coCreateWrapper.setTargetTermCode(targetTermCode);
      TermInfo term = CourseOfferingManagementUtil.getTerm(targetTermCode);
      coCreateWrapper.setTerm(term);
    }

    if (catalogCourseCode != null) {
      coCreateWrapper.setCatalogCourseCode(catalogCourseCode);
    }

    if (coId != null) {
      try {
        // configure context bar
        SocInfo soc =
            CourseOfferingSetUtil.getMainSocForTermId(
                coCreateWrapper.getTerm().getId(), contextInfo);
        coCreateWrapper.setSocInfo(soc);
        coCreateWrapper.setContextBar(
            CourseOfferingContextBar.NEW_INSTANCE(
                coCreateWrapper.getTerm(),
                coCreateWrapper.getSocInfo(),
                CourseOfferingManagementUtil.getStateService(),
                CourseOfferingManagementUtil.getAcademicCalendarService(),
                contextInfo));

        CourseOfferingInfo theCO =
            CourseOfferingManagementUtil.getCourseOfferingService()
                .getCourseOffering(coId, contextInfo);
        CourseOfferingEditWrapper coEditWrapper = new CourseOfferingEditWrapper(theCO);
        TermInfo termInfo =
            CourseOfferingManagementUtil.getAcademicCalendarService()
                .getTerm(theCO.getTermId(), contextInfo);
        coEditWrapper.setTerm(termInfo);
        coEditWrapper.setGradingOption(
            CourseOfferingManagementUtil.getGradingOption(theCO.getGradingOptionId()));
        // To prevent showing the same row twice in the table. It can be caused by pressing F5 key.
        if (coCreateWrapper.getExistingTermOfferings().size() == 0) {
          coCreateWrapper.getExistingTermOfferings().add(coEditWrapper);
        }
      } catch (Exception e) {
        throw new RuntimeException(
            "An Exception occurred while trying to copy course to new onw. ", e);
      }
    }
  }
  protected static List<String> getOptionKeys(
      CourseOfferingCreateWrapper createWrapper, CourseOfferingInfo existingCO) {

    List<String> optionKeys =
        getDefaultOptionKeysService().getDefaultOptionKeysForCopySingleCourseOffering();

    if (createWrapper.isExcludeInstructorInformation()) {
      optionKeys.add(CourseOfferingSetServiceConstants.NO_INSTRUCTORS_OPTION_KEY);
    }

    if (createWrapper.isExcludeSchedulingInformation()) {
      optionKeys.add(CourseOfferingSetServiceConstants.NO_SCHEDULE_OPTION_KEY);
    }

    if (createWrapper.isExcludeCancelledActivityOfferings()) {
      optionKeys.add(CourseOfferingSetServiceConstants.IGNORE_CANCELLED_AO_OPTION_KEY);
    }

    ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();

    try {
      // if source term differs from target term determine if add suffix or not
      if (StringUtils.equals(existingCO.getTermId(), createWrapper.getTerm().getId())) {
        optionKeys.add(CourseOfferingServiceConstants.APPEND_COURSE_OFFERING_IN_SUFFIX_OPTION_KEY);
      } else {
        QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
        qbcBuilder.setPredicates(
            PredicateFactory.and(
                PredicateFactory.like(
                    "courseOfferingCode", existingCO.getCourseOfferingCode() + "%"),
                PredicateFactory.equalIgnoreCase("atpId", createWrapper.getTerm().getId())));
        QueryByCriteria criteria = qbcBuilder.build();
        List<String> courseOfferingIds =
            CourseOfferingManagementUtil.getCourseOfferingService()
                .searchForCourseOfferingIds(criteria, contextInfo);

        if (courseOfferingIds.size() > 0) {
          optionKeys.add(
              CourseOfferingServiceConstants.APPEND_COURSE_OFFERING_IN_SUFFIX_OPTION_KEY);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    //  According to Jira 4353 copy the title from CO instead of CLU. So set the property not to
    // copy from CLU
    optionKeys.add(CourseOfferingSetServiceConstants.NOT_COURSE_TITLE_OPTION_KEY);
    return optionKeys;
  }
  protected static void continueFromCreateCopyCourseOfferingInfo(
      CourseOfferingCreateWrapper coWrapper, CourseInfo course, TermInfo term) {

    ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
    int firstValue = 0;

    try {
      List<CourseOfferingInfo> courseOfferingInfos =
          CourseOfferingManagementUtil.getCourseOfferingService()
              .getCourseOfferingsByCourseAndTerm(course.getId(), term.getId(), contextInfo);

      coWrapper.setCourse(course);
      coWrapper.setCreditCount(
          CourseOfferingViewHelperUtil.trimTrailing0(
              CourseOfferingManagementUtil.getLrcService()
                  .getResultValue(
                      course
                          .getCreditOptions()
                          .get(firstValue)
                          .getResultValueKeys()
                          .get(firstValue),
                      contextInfo)
                  .getValue()));
      coWrapper.setShowAllSections(true);
      coWrapper.setShowCopyCourseOffering(false);
      coWrapper.setShowTermOfferingLink(true);

      coWrapper.setContextBar(
          CourseOfferingContextBar.NEW_INSTANCE(
              coWrapper.getTerm(),
              coWrapper.getSocInfo(),
              CourseOfferingManagementUtil.getStateService(),
              CourseOfferingManagementUtil.getAcademicCalendarService(),
              contextInfo));

      coWrapper.getExistingTermOfferings().clear();
      coWrapper.getExistingOfferingsInCurrentTerm().clear();

      for (CourseOfferingInfo courseOfferingInfo : courseOfferingInfos) {
        if (StringUtils.equals(
            courseOfferingInfo.getStateKey(), LuiServiceConstants.LUI_CO_STATE_OFFERED_KEY)) {
          CourseOfferingEditWrapper co = new CourseOfferingEditWrapper(courseOfferingInfo);
          co.setGradingOption(
              CourseOfferingManagementUtil.getGradingOption(
                  courseOfferingInfo.getGradingOptionId()));
          coWrapper.getExistingOfferingsInCurrentTerm().add(co);
        }
      }

      // Get past 5 years CO
      Calendar termStart = Calendar.getInstance();
      termStart.setTime(term.getStartDate());
      String termYear = Integer.toString(termStart.get(Calendar.YEAR));
      String termMonth = Integer.toString((termStart.get(Calendar.MONTH) + 1));
      String termDayOfMonth = Integer.toString((termStart.getActualMaximum(Calendar.DAY_OF_MONTH)));

      org.kuali.student.r2.core.search.dto.SearchRequestInfo searchRequest =
          new org.kuali.student.r2.core.search.dto.SearchRequestInfo(
              CourseOfferingHistorySearchImpl.PAST_CO_SEARCH.getKey());
      searchRequest.addParam(
          CourseOfferingHistorySearchImpl.COURSE_ID, coWrapper.getCourse().getId());

      searchRequest.addParam(
          CourseOfferingHistorySearchImpl.TARGET_DAY_OF_MONTH_PARAM, termDayOfMonth);
      searchRequest.addParam(CourseOfferingHistorySearchImpl.TARGET_MONTH_PARAM, termMonth);
      searchRequest.addParam(CourseOfferingHistorySearchImpl.TARGET_YEAR_PARAM, termYear);
      searchRequest.addParam(
          CourseOfferingHistorySearchImpl.SearchParameters.CROSS_LIST_SEARCH_ENABLED,
          BooleanUtils.toStringTrueFalse(true));
      org.kuali.student.r2.core.search.dto.SearchResultInfo searchResult =
          CourseOfferingManagementUtil.getSearchService().search(searchRequest, null);

      List<String> courseOfferingIds = new ArrayList<String>(searchResult.getTotalResults());

      /* Checks whether the course is cross-listed and Set the codes that are cross listed to the cross-listed list */

      for (org.kuali.student.r2.core.search.dto.SearchResultRowInfo row : searchResult.getRows()) {
        for (SearchResultCellInfo cellInfo : row.getCells()) {
          String value = StringUtils.EMPTY;
          if (cellInfo.getValue() != null) {
            value = cellInfo.getValue();
          }
          if (CourseOfferingHistorySearchImpl.SearchResultColumns.CO_ID.equals(cellInfo.getKey())) {
            courseOfferingIds.add(value);
          } else if (CourseOfferingHistorySearchImpl.SearchResultColumns.IS_CROSS_LISTED.equals(
              cellInfo.getValue())) {
            coWrapper.setCrossListedCo(BooleanUtils.toBoolean(value));
          } else if (CourseOfferingHistorySearchImpl.SearchResultColumns.CROSS_LISTED_COURSES
              .equals(cellInfo.getKey())) {
            coWrapper.setAlternateCOCodes(Arrays.asList(StringUtils.split(value, ",")));
          }
        }
      }

      /*
       * Avoid duplicates in case there is a cross Listed
       */
      HashSet hs = new HashSet();
      hs.addAll(courseOfferingIds);
      courseOfferingIds.clear();
      courseOfferingIds.addAll(hs);

      courseOfferingInfos =
          CourseOfferingManagementUtil.getCourseOfferingService()
              .getCourseOfferingsByIds(courseOfferingIds, contextInfo);

      for (CourseOfferingInfo courseOfferingInfo : courseOfferingInfos) {
        CourseOfferingEditWrapper co = new CourseOfferingEditWrapper(courseOfferingInfo);
        TermInfo termInfo =
            CourseOfferingManagementUtil.getAcademicCalendarService()
                .getTerm(courseOfferingInfo.getTermId(), contextInfo);
        co.setTerm(termInfo);
        co.setGradingOption(
            CourseOfferingManagementUtil.getGradingOption(courseOfferingInfo.getGradingOptionId()));
        co.setAlternateCOCodes(coWrapper.getAlternateCOCodes());
        coWrapper.getExistingTermOfferings().add(co);
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }