@Override
 public void checkPreConditions(DegreeChangeIndividualCandidacyProcess process, User userView) {
   if (!isAllowedToManageProcess(process, userView)) {
     throw new PreConditionNotValidException();
   }
   if (process.hasAnyPaymentForCandidacy() || !process.isCandidacyInStandBy()) {
     throw new PreConditionNotValidException();
   }
 }
    @Override
    public void checkPreConditions(DegreeChangeIndividualCandidacyProcess process, User userView) {
      if (!isAllowedToManageProcess(process, userView)) {
        throw new PreConditionNotValidException();
      }

      if (!process.isCandidacyCancelled() && !process.isCandidacyRejected()) {
        throw new PreConditionNotValidException();
      }
    }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   process.editCandidacyHabilitations((DegreeChangeIndividualCandidacyProcessBean) object);
   process.getCandidacy().editObservations((DegreeChangeIndividualCandidacyProcessBean) object);
   process.editCandidacyInformation((DegreeChangeIndividualCandidacyProcessBean) object);
   process
       .getCandidacy()
       .setUtlStudent(((DegreeChangeIndividualCandidacyProcessBean) object).getUtlStudent());
   return process;
 }
 @Override
 public void checkPreConditions(DegreeChangeIndividualCandidacyProcess process, User userView) {
   if (!isAllowedToManageProcess(process, userView)) {
     throw new PreConditionNotValidException();
   }
   if (process.isCandidacyCancelled()
       || process.isCandidacyAccepted()
       || process.hasRegistrationForCandidacy()) {
     throw new PreConditionNotValidException();
   }
 }
  private static boolean isAllowedToManageProcess(
      DegreeChangeIndividualCandidacyProcess process, User userView) {
    Set<AcademicProgram> programs =
        AcademicAuthorizationGroup.getProgramsForOperation(
            userView.getPerson(), AcademicOperationType.MANAGE_INDIVIDUAL_CANDIDACIES);

    if (process == null || process.getCandidacy() == null) {
      return false;
    }

    return programs.contains(process.getCandidacy().getSelectedDegree());
  }
    @Override
    protected DegreeChangeIndividualCandidacyProcess executeActivity(
        DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
      DegreeChangeIndividualCandidacyProcessBean bean =
          (DegreeChangeIndividualCandidacyProcessBean) object;
      process.editCandidacyHabilitations(bean);
      process.getCandidacy().editSelectedDegree(bean.getSelectedDegree());
      process.getCandidacy().editObservations(bean);

      process.editPrecedentDegreeInformation(bean);

      return process;
    }
    @Override
    public void checkPreConditions(DegreeChangeIndividualCandidacyProcess process, User userView) {
      if (!isAllowedToManageProcess(process, userView)) {
        throw new PreConditionNotValidException();
      }

      if (process.isCandidacyCancelled() || !process.isCandidacyDebtPayed()) {
        throw new PreConditionNotValidException();
      }

      if (!process.isSentToCoordinator()) {
        throw new PreConditionNotValidException();
      }
    }
    @Override
    protected DegreeChangeIndividualCandidacyProcess executeActivity(
        DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
      process.getCandidacy().setState(IndividualCandidacyState.STAND_BY);

      return process;
    }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   CandidacyProcessDocumentUploadBean bean = (CandidacyProcessDocumentUploadBean) object;
   process.bindIndividualCandidacyDocumentFile(bean);
   return process;
 }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   process.editPersonalCandidacyInformation(
       ((DegreeChangeIndividualCandidacyProcessBean) object).getPersonBean());
   return process;
 }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   DegreeChangeIndividualCandidacyResultBean bean =
       (DegreeChangeIndividualCandidacyResultBean) object;
   process.getCandidacy().setState(bean.getState());
   return process;
 }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   process
       .getCandidacy()
       .createRegistration(
           getDegreeCurricularPlan(process), CycleType.FIRST_CYCLE, getIngression(process));
   return process;
 }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   DegreeChangeIndividualCandidacyResultBean bean =
       (DegreeChangeIndividualCandidacyResultBean) object;
   DegreeChangeIndividualCandidacySeriesGrade degreeChangeIndividualCandidacySeriesGrade =
       process
           .getCandidacy()
           .getDegreeChangeIndividualCandidacySeriesGradeForDegree(bean.getDegree());
   degreeChangeIndividualCandidacySeriesGrade.setAffinity(bean.getAffinity());
   degreeChangeIndividualCandidacySeriesGrade.setDegreeNature(bean.getDegreeNature());
   degreeChangeIndividualCandidacySeriesGrade.setApprovedEctsRate(bean.getApprovedEctsRate());
   degreeChangeIndividualCandidacySeriesGrade.setGradeRate(bean.getGradeRate());
   degreeChangeIndividualCandidacySeriesGrade.setSeriesCandidacyGrade(
       bean.getSeriesCandidacyGrade());
   degreeChangeIndividualCandidacySeriesGrade.setState(bean.getSeriesGradeState());
   return process;
 }
 @Override
 public void checkPreConditions(DegreeChangeIndividualCandidacyProcess process, User userView) {
   if (!process.isCandidacyInStandBy()) {
     throw new PreConditionNotValidException();
   }
 }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   process.rejectCandidacy(userView.getPerson());
   return process;
 }
 @Override
 protected DegreeChangeIndividualCandidacyProcess executeActivity(
     DegreeChangeIndividualCandidacyProcess process, User userView, Object object) {
   process.setPaymentChecked(((IndividualCandidacyProcessBean) object).getPaymentChecked());
   return process;
 }
 private DegreeCurricularPlan getDegreeCurricularPlan(
     final DegreeChangeIndividualCandidacyProcess process) {
   return process.getCandidacySelectedDegree().getLastActiveDegreeCurricularPlan();
 }
 private Ingression getIngression(final DegreeChangeIndividualCandidacyProcess process) {
   return process.getPrecedentDegreeInformation().isCandidacyExternal()
       ? Ingression.MCE
       : Ingression.MCI;
 }