@Override
 public DataSaveResult createCopyCourse(String originalCluId) throws Exception {
   try {
     return copyCourseService.createCopyCourse(originalCluId, ContextUtils.getContextInfo());
   } catch (Exception e) {
     LOG.error(String.format("Error copying course with id: %s", originalCluId), e);
     throw e;
   }
 }
 @Override
 public StatusInfo deleteLoCategory(String loCategoryId) {
   try {
     return loService.deleteLoCategory(loCategoryId, ContextUtils.getContextInfo());
   } catch (Exception e) {
     LOG.error("Exception occurred", e);
   }
   return null;
 }
  /**
   * This overridden method ...
   *
   * @see
   *     org.kuali.student.lum.common.client.lo.rpc.LoCategoryRpcService#getLoCategoryType(java.lang.String)
   */
  @Override
  public TypeInfo getLoCategoryType(String loCategoryTypeKey) {
    try {
      return loService.getLoCategoryType(loCategoryTypeKey, ContextUtils.getContextInfo());

    } catch (Exception e) {
      LOG.error("Exception occurred", e);
    }
    return null;
  }
  @Override
  public List<LoCategoryInfo> getLoCategories(String loRepositoryKey) {
    try {
      return loService.getLoCategoriesByLoRepository(
          loRepositoryKey, ContextUtils.getContextInfo());

    } catch (Exception e) {
      LOG.error("Exception occurred", e);
    }
    return null;
  }
 @Override
 public DataSaveResult createCopyCourseProposal(String originalProposalId, String documentType)
     throws Exception {
   try {
     return copyCourseService.createCopyCourseProposal(
         originalProposalId, documentType, ContextUtils.getContextInfo());
   } catch (Exception e) {
     LOG.error(String.format("Error copying proposal with id: %s", originalProposalId), e);
     throw e;
   }
 }
  private String getCredentialId() throws Exception {

    List<String> credIds =
        cluService.getCluIdsByLuType(
            ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM,
            DtoConstants.STATE_ACTIVE,
            ContextUtils.getContextInfo());
    if (null == credIds || credIds.size() != 1) {
      throw new OperationFailedException(
          "A single credential program of type "
              + ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM
              + " is required; database contains "
              + (null == credIds ? "0" : credIds.size() + "."));
    }
    return credIds.get(0);
  }
  public CourseOfferingInfo testCRUDCourseOffering()
      throws DoesNotExistException, DataValidationErrorException, InvalidParameterException,
          MissingParameterException, OperationFailedException, PermissionDeniedException,
          ReadOnlyException, VersionMismatchException {
    // get course
    CourseInfo course;
    course = courseService.getCourse("COURSE1", ContextUtils.getContextInfo());
    // create co from course
    List<String> optionKeys = new ArrayList<String>();
    CourseOfferingInfo orig = new CourseOfferingInfo();
    orig.setCourseId(course.getId());
    orig.setTermId("testAtpId1");
    orig.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
    orig.setStateKey(LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY);
    orig.setCourseOfferingTitle("my name");
    orig.setWaitlistLevelTypeKey("waitlist key");
    orig.setHasWaitlist(true);
    orig.setFinalExamType(FinalExam.STANDARD.toString());
    orig.setIsEvaluated(true);
    orig.setIsFeeAtActivityOffering(false);
    orig.setFundingSource("funding source");
    orig.setCourseOfferingCode("CODE");
    orig.setCourseNumberSuffix("");
    orig.setCourseOfferingTitle("Title");
    orig.getStudentRegistrationGradingOptions()
        .add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
    orig.getStudentRegistrationGradingOptions()
        .add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
    orig.setGradingOptionId(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);

    CourseOfferingInfo info =
        courseOfferingService.createCourseOffering(
            orig.getCourseId(), orig.getTermId(), orig.getTypeKey(), orig, optionKeys, callContext);
    assertNotNull(info);
    assertNotNull(info.getId());
    assertEquals(orig.getCourseId(), info.getCourseId());
    assertEquals(orig.getTermId(), info.getTermId());
    assertEquals(orig.getStateKey(), info.getStateKey());
    assertEquals(orig.getTypeKey(), info.getTypeKey());
    assertEquals(orig.getWaitlistLevelTypeKey(), info.getWaitlistLevelTypeKey());
    assertEquals(orig.getHasWaitlist(), info.getHasWaitlist());
    assertEquals(orig.getFinalExamType(), info.getFinalExamType());
    assertEquals(orig.getIsFeeAtActivityOffering(), info.getIsFeeAtActivityOffering());
    assertEquals(orig.getFundingSource(), info.getFundingSource());
    assertEquals(course.getCode() + info.getCourseNumberSuffix(), info.getCourseOfferingCode());
    assertEquals(orig.getCourseNumberSuffix(), info.getCourseNumberSuffix());
    assertEquals(course.getSubjectArea(), info.getSubjectArea());
    if (course.getDescr() != null) {
      assertEquals(course.getDescr().getPlain(), info.getDescr().getPlain());
      assertEquals(course.getDescr().getFormatted(), info.getDescr().getFormatted());
    }
    //        assertEquals(2,info.getStudentRegistrationOptionIds().size());
    //
    // assertTrue(info.getStudentRegistrationOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT));
    //
    // assertTrue(info.getStudentRegistrationOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL));
    //
    //        assertEquals(2,info.getGradingOptionIds().size());
    //
    // assertTrue(info.getGradingOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER));
    //
    // assertTrue(info.getGradingOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PERCENTAGE));

    // TODO: test for these things
    //        assertEquals(course.getUnitsContentOwnerOrgIds(), info.getUnitsContentOwnerOrgIds());
    //        assertEquals(course.getUnitsDeploymentOrgIds(), info.getUnitsDeploymentOrgIds());
    //        assertEquals(course.getGradingOptions(), info.getGradingOptionIds());
    //        assertEquals(course.getCreditOptionIds(), info.getCreditOptionIds());

    // refetch co
    orig = info;
    info = courseOfferingService.getCourseOffering(orig.getId(), callContext);
    assertNotNull(info);
    assertEquals(orig.getId(), info.getId());
    assertEquals(orig.getCourseId(), info.getCourseId());
    assertEquals(orig.getTermId(), info.getTermId());
    assertEquals(orig.getStateKey(), info.getStateKey());
    assertEquals(orig.getTypeKey(), info.getTypeKey());

    // update co
    orig = info;
    orig.setIsHonorsOffering(true);
    orig.setMaximumEnrollment(40);
    orig.setMinimumEnrollment(10);
    List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
    //        OfferingInstructorInfo instructor = new OfferingInstructorInfo();
    //        instructor.setPersonId("Pers-1");
    //        instructor.setPercentageEffort(Float.valueOf("60"));
    //        instructor.setTypeKey(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY);
    //        instructor.setStateKey(LprServiceConstants.ASSIGNED_STATE_KEY);
    // TODO: add this back in and test for it
    //        instructors.add(instructor);
    orig.setInstructors(instructors);
    info = courseOfferingService.updateCourseOffering(orig.getId(), orig, callContext);
    assertNotNull(info);
    assertEquals(orig.getId(), info.getId());
    assertEquals(orig.getCourseId(), info.getCourseId());
    assertEquals(orig.getTermId(), info.getTermId());
    assertEquals(orig.getStateKey(), info.getStateKey());
    assertEquals(orig.getTypeKey(), info.getTypeKey());
    assertEquals(orig.getIsHonorsOffering(), info.getIsHonorsOffering());
    assertEquals(orig.getMaximumEnrollment(), info.getMaximumEnrollment());
    assertEquals(orig.getMinimumEnrollment(), info.getMinimumEnrollment());
    assertEquals(orig.getInstructors().size(), info.getInstructors().size());
    //        OfferingInstructorInfo origInst1 = orig.getInstructors().get(0);
    //        OfferingInstructorInfo infoInst1 = info.getInstructors().get(0);
    //        assertEquals(origInst1.getPersonId(), infoInst1.getPersonId());
    //        assertEquals(origInst1.getPercentageEffort(), infoInst1.getPercentageEffort());
    //        assertEquals(origInst1.getTypeKey(), infoInst1.getTypeKey());
    //        assertEquals(origInst1.getStateKey(), infoInst1.getStateKey());
    return info;
  }
  @Override
  protected Object save(Object dto, Map<String, Object> properties, ContextInfo contextInfo)
      throws Exception {
    if (dto instanceof MajorDisciplineInfo) {
      MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto;
      if (mdInfo.getId() == null && mdInfo.getVersion() != null) {

        String majorVersionIndId = mdInfo.getVersion().getVersionIndId();

        // Get the current Major Dicipline from the service
        VersionDisplayInfo mdVersionInfo =
            programService.getCurrentVersion(
                ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI,
                majorVersionIndId,
                ContextUtils.getContextInfo());
        mdInfo =
            programService.getMajorDiscipline(mdVersionInfo.getId(), ContextUtils.getContextInfo());

        // set the prev start term to be the most recent of the major and all variations
        AtpInfo latestStartAtp = atpService.getAtp(mdInfo.getStartTerm(), contextInfo);
        for (ProgramVariationInfo variation : mdInfo.getVariations()) {
          AtpInfo variationAtp = atpService.getAtp(variation.getStartTerm(), contextInfo);
          if (variationAtp != null
              && variationAtp.getStartDate() != null
              && variationAtp.getStartDate().compareTo(latestStartAtp.getStartDate()) > 0) {
            latestStartAtp = variationAtp;
          }
        }

        // Save the start and end terms from the old version and put into filter properties
        String startTerm = latestStartAtp.getId();
        String endTerm = mdInfo.getEndTerm();
        String endProgramEntryTerm = mdInfo.getEndProgramEntryTerm();
        String endInstAdmitTerm =
            mdInfo.getAttributeValue(ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM);

        //
        Map<String, String> proposalAttributes = new HashMap<String, String>();
        if (startTerm != null) proposalAttributes.put("prevStartTerm", startTerm);
        if (endTerm != null) proposalAttributes.put("prevEndTerm", endTerm);
        if (endProgramEntryTerm != null)
          proposalAttributes.put("prevEndProgramEntryTerm", endProgramEntryTerm);
        if (endInstAdmitTerm != null)
          proposalAttributes.put("prevEndInstAdmitTerm", endInstAdmitTerm);
        properties.put(ProposalWorkflowFilter.PROPOSAL_ATTRIBUTES, proposalAttributes);

        mdInfo =
            programService.createNewMajorDisciplineVersion(
                majorVersionIndId, "New major discipline version", ContextUtils.getContextInfo());
      } else if (mdInfo.getId() == null) {
        mdInfo =
            programService.createMajorDiscipline(
                mdInfo.getId(), mdInfo, ContextUtils.getContextInfo());
      } else {
        mdInfo = programService.updateMajorDiscipline(null, mdInfo, ContextUtils.getContextInfo());
      }
      return mdInfo;
    } else {
      throw new InvalidParameterException(
          "Only persistence of MajorDiscipline is supported by this DataService implementation.");
    }
  }
 @Override
 protected List<ValidationResultInfo> validate(Object dto, ContextInfo contextInfo)
     throws Exception {
   return programService.validateMajorDiscipline(
       "OBJECT", (MajorDisciplineInfo) dto, ContextUtils.getContextInfo());
 }