/** @param gratuitySituation */
  private void updateGratuitySituation(GratuitySituation gratuitySituation) {

    // check if there isnt any persistentSupportecialization for a 2nd year
    if (gratuitySituation
        .getStudentCurricularPlan()
        .getSpecialization()
        .equals(Specialization.STUDENT_CURRICULAR_PLAN_SPECIALIZATION)) {

      if (this.firstYear == null) {
        this.firstYear = gratuitySituation.getGratuityValues().getExecutionDegree().isFirstYear();
      }

      if (!this.firstYear) {
        // TODO: check if this is right (sana)
        removeWrongGratuitySituation(gratuitySituation);
        return;
      }
    }

    gratuitySituation.updateValues();
  }
  protected void run(String year) {

    gratuitySituationsToDelete = new HashSet<GratuitySituation>();

    ExecutionYear executionYear = readExecutionYear(year);

    // read master degree and persistentSupportecialization execution
    // degrees
    Collection<ExecutionDegree> executionDegrees =
        executionYear.getExecutionDegreesByType(DegreeType.MASTER_DEGREE);

    for (ExecutionDegree executionDegree : executionDegrees) {

      GratuityValues gratuityValues = executionDegree.getGratuityValues();

      if (gratuityValues == null) {
        continue;
      }

      this.firstYear = executionDegree.isFirstYear();

      Collection<StudentCurricularPlan> studentCurricularPlans =
          executionDegree.getDegreeCurricularPlan().getStudentCurricularPlans();
      for (StudentCurricularPlan studentCurricularPlan : studentCurricularPlans) {

        GratuitySituation gratuitySituation =
            studentCurricularPlan.getGratuitySituationByGratuityValues(gratuityValues);

        if (year.equals("2002/2003") && gratuitySituation.getTransactionListSet().size() == 0) {
          gratuitySituation.setEmployee(null);
          gratuitySituation.setGratuityValues(null);
          gratuitySituation.setStudentCurricularPlan(null);
          this.gratuitySituationsToDelete.add(gratuitySituation);
          continue;
        }

        if (gratuitySituation == null) {
          createGratuitySituation(gratuityValues, studentCurricularPlan);
        } else {
          updateGratuitySituation(gratuitySituation);
        }
      }
    }

    for (GratuitySituation gratuitySituationToDelete : this.gratuitySituationsToDelete) {
      gratuitySituationToDelete.delete();
    }
  }
  private void removeWrongGratuitySituation(GratuitySituation gratuitySituation) {

    // find gratuity situation of first persistentSupportecialization year
    for (GratuitySituation correctSituation :
        gratuitySituation.getStudentCurricularPlan().getGratuitySituations()) {
      if (correctSituation.getGratuityValues().getExecutionDegree().isFirstYear()) {

        // transfer transactions from wrong to correct gratuity
        // situation
        for (GratuityTransaction gratuityTransaction : gratuitySituation.getTransactionList()) {
          correctSituation.addTransactionList(gratuityTransaction);
        }

        break;
      }
    }

    gratuitySituation.setEmployee(null);
    gratuitySituation.setGratuityValues(null);
    gratuitySituation.setStudentCurricularPlan(null);
    this.gratuitySituationsToDelete.add(gratuitySituation);
  }