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);
      }
    }
  }
  private static void setTermPropertiesOnFormObject(
      CourseOfferingEditWrapper formObject, String termId, ContextInfo contextInfo)
      throws Exception {

    TermInfo termInfo =
        CourseOfferingManagementUtil.getAcademicCalendarService().getTerm(termId, contextInfo);
    formObject.setTerm(termInfo);
    formObject.setTermName(termInfo.getName());

    // Setting term string: Fall 2012 (09/28/2012 to 12/15/2012)
    String termStartDate =
        DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(termInfo.getStartDate());
    String termEndDate = DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(termInfo.getEndDate());
    StringBuilder termStartEnd = new StringBuilder();
    termStartEnd.append(termInfo.getName());
    termStartEnd.append(" (");
    termStartEnd.append(termStartDate);
    termStartEnd.append(" to ");
    termStartEnd.append(termEndDate);
    termStartEnd.append(")");
    formObject.setTermStartEnd(termStartEnd.toString());
  }
  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);
    }
  }