GratuitySituation gratuitySituation = gratuitySituationDAO .readGratuitySituatuionByStudentCurricularPlanAndGratuityValues( studentCurricularPlan.getIdInternal(), executionDegree .getGratuityValues().getIdInternal());
GratuityValues gratuityValues = executionDegree.getGratuityValues();
    public void run(Integer executionYearID, Date paymentEndDate) throws FenixServiceException,            ExcepcaoPersistencia {		StringBuilder outgoingSibsPaymentFile = new StringBuilder();		ExecutionYear executionYear = (ExecutionYear) persistentObject.readByOID(				ExecutionYear.class, executionYearID);        IPersistentGratuitySituation gratuitySituationDAO = persistentSupport                .getIPersistentGratuitySituation();		IPersistentInsuranceTransaction insuranceTransactionDAO = persistentSupport				.getIPersistentInsuranceTransaction();        InsuranceValue insuranceValue = persistentSupport.getIPersistentInsuranceValue()                .readByExecutionYear(executionYear.getIdInternal());		if (insuranceValue == null) {			throw new InsuranceNotDefinedServiceException("error.insurance.notDefinedForThisYear");		}        Date insurancePaymentStartDate = Calendar.getInstance().getTime();        Date insurancePaymentEndDate = paymentEndDate;		String shortYear = executionYear.getYear().split("/")[0].trim().substring(2);        // read master degree and persistentSupportecialization execution        // degrees        List executionDegreeList = persistentSupport.getIPersistentExecutionDegree()                .readByExecutionYearAndDegreeType(executionYear.getYear(), DegreeType.MASTER_DEGREE);		int totalLines = 0;        Set<Integer> studentsWithInsuranceChecked = new HashSet<Integer>();		// add file header		addHeader(outgoingSibsPaymentFile);		// add lines gratuity		for (Iterator iter = executionDegreeList.iterator(); iter.hasNext();) {			ExecutionDegree executionDegree = (ExecutionDegree) iter.next();			DegreeCurricularPlan degreeCurricularPlan = executionDegree.getDegreeCurricularPlan();			List studentCurricularPlanList = degreeCurricularPlan.getStudentCurricularPlans();			// add insurance lines			for (Iterator iterator = studentCurricularPlanList.iterator(); iterator.hasNext();) {				StudentCurricularPlan studentCurricularPlan = (StudentCurricularPlan) iterator.next();                if (studentCurricularPlan.getSpecialization().equals(Specialization.SPECIALIZATION)) {                    if (!executionDegree.isFirstYear()) {					continue;				}                }                Student student = studentCurricularPlan.getStudent();                if (studentsWithInsuranceChecked.contains(student.getIdInternal()) == false) {                    studentsWithInsuranceChecked.add(student.getIdInternal());				List insuranceTransactionList = insuranceTransactionDAO                            .readAllNonReimbursedByExecutionYearAndStudent(                                    executionYear.getIdInternal(), student.getIdInternal());				if (insuranceTransactionList.size() == 0) {                        // the student hasn't payed the insurance for this                        // year					// yet					addLine(outgoingSibsPaymentFile,							SibsOutgoingPaymentFileConstants.LINE_REGISTER_TYPE,                                SibsOutgoingPaymentFileConstants.LINE_PROCESSING_CODE, shortYear,                                student.getNumber(), SibsPaymentCodeFactory									.getCode(SibsPaymentType.INSURANCE)                                        + "", insurancePaymentStartDate, insurancePaymentEndDate,                                insuranceValue.getAnnualValue(), insuranceValue.getAnnualValue());					totalLines++;				}			}                // Add gratuity lines                GratuitySituation gratuitySituation = gratuitySituationDAO                        .readGratuitySituatuionByStudentCurricularPlanAndGratuityValues(                                studentCurricularPlan.getIdInternal(), executionDegree                                        .getGratuityValues().getIdInternal());                if (gratuitySituation != null) {                    totalLines += addGratuityLines(outgoingSibsPaymentFile, gratuitySituation,                            shortYear, paymentEndDate);                } else {                    System.out.println("Student " + student.getNumber()                            + " does not have a gratuity situation for year "                            + executionDegree.getExecutionYear().getYear() + " Degree "                            + executionDegree.getDegreeCurricularPlan().getName());			}		}        }		// add file footer		addFooter(outgoingSibsPaymentFile, totalLines);		writeOutgoingSibsPaymentFile(executionYear, outgoingSibsPaymentFile);	}