if (studentCurricularPlan.getSpecialization().equals(Specialization.SPECIALIZATION)) {
if (studentCurricularPlan.getSpecialization().equals(Specialization.STUDENT_CURRICULAR_PLAN_SPECIALIZATION)) {
    public byte[] run(Integer executionYearID, Date paymentEndDate) throws FenixServiceException,            ExcepcaoPersistencia {        ExecutionYear executionYear = rootDomainObject.readExecutionYearByOID(executionYearID);        InsuranceValue insuranceValue = executionYear.getInsuranceValue();        if (insuranceValue == null) {            throw new InsuranceNotDefinedServiceException("error.insurance.notDefinedForThisYear");        }        // Date insurancePaymentEndDate = Calendar.getInstance().getTime();        String shortYear = executionYear.getYear().split("/")[0].trim().substring(2);        // read master degree and persistentSupportecialization execution        // degrees        List executionDegreeList = ExecutionDegree.getAllByExecutionYearAndDegreeType(executionYear                .getYear(), DegreeType.MASTER_DEGREE);        List gratuityLetterFileEntries = new ArrayList();        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");        NumberFormat numberFormat = NumberFormat.getInstance();        DecimalFormat decimalFormat = (DecimalFormat) numberFormat;        decimalFormat.applyPattern("######.##");        Set<Integer> studentsWithInsuranceChecked = new HashSet<Integer>();        for (Iterator iter = executionDegreeList.iterator(); iter.hasNext();) {            ExecutionDegree executionDegree = (ExecutionDegree) iter.next();            DegreeCurricularPlan degreeCurricularPlan = executionDegree.getDegreeCurricularPlan();            List studentCurricularPlanList = degreeCurricularPlan.getStudentCurricularPlans();            GratuityValues gratuityValues = executionDegree.getGratuityValues();            for (Iterator iterator = studentCurricularPlanList.iterator(); iterator.hasNext();) {                StudentCurricularPlan studentCurricularPlan = (StudentCurricularPlan) iterator.next();                if (studentCurricularPlan.getSpecialization().equals(Specialization.SPECIALIZATION)) {                    if (!executionDegree.isFirstYear()) {                        continue;                    }                }                Registration registration = (studentCurricularPlan.getStudent());                GratuityLetterFileEntry gratuityLetterFileEntryInsurancePart = null;                if (studentsWithInsuranceChecked.contains(registration.getIdInternal()) == false) {                    studentsWithInsuranceChecked.add(registration.getIdInternal());                    List insuranceTransactionList = registration                            .readAllNonReimbursedInsuranceTransactionsByExecutionYear(executionYear);                    if (insuranceTransactionList.size() == 0) {                        // student hasn't payed insurance                        gratuityLetterFileEntryInsurancePart = new GratuityLetterFileEntry(                                studentCurricularPlan);                        gratuityLetterFileEntryInsurancePart.setInsuranceEndDate(simpleDateFormat                                .format(paymentEndDate));                        gratuityLetterFileEntryInsurancePart.setInsuranceFullSibsReference(shortYear                                + addCharToStringUntilMax(SibsOutgoingPaymentFileConstants.ZERO_CHAR,                                        registration.getNumber().toString(),                                        SibsOutgoingPaymentFileConstants.MAX_STUDENT_NUMBER_LENGTH)                                + SibsPaymentCodeFactory.getCode(SibsPaymentType.INSURANCE));                        gratuityLetterFileEntryInsurancePart.setInsuranceValue(decimalFormat                                .format(insuranceValue.getAnnualValue()));                    }                }                GratuityLetterFileEntry gratuityLetterFileEntry = null;                // if ((studentCurricularPlan.getSpecialization().equals(                // Specialization.INTEGRADO_TYPE) == false)                // && (gratuityValues != null)) {                if (gratuityValues != null) {                    GratuitySituation gratuitySituation = studentCurricularPlan                            .getGratuitySituationByGratuityValues(gratuityValues);                    if (gratuitySituation != null) {                        gratuityLetterFileEntry = createGratuityLetterFileEntryForGratuitySituation(                                gratuitySituation, shortYear, paymentEndDate);                    } else {                        System.out.println("Registration " + registration.getNumber()                                + " does not have a gratuity situation for year "                                + executionDegree.getExecutionYear().getYear() + " Degree "                                + executionDegree.getDegreeCurricularPlan().getName());                    }                }                if (gratuityLetterFileEntry == null) {                    // there wasn't gratuity part (only insurance)                    gratuityLetterFileEntry = gratuityLetterFileEntryInsurancePart;                } else {                    if (gratuityLetterFileEntryInsurancePart != null) {                        // insurance part exists                        gratuityLetterFileEntry.setInsuranceEndDate(gratuityLetterFileEntryInsurancePart                                .getInsuranceEndDate());                        gratuityLetterFileEntry                                .setInsuranceFullSibsReference(gratuityLetterFileEntryInsurancePart                                        .getInsuranceFullSibsReference());                        gratuityLetterFileEntry.setInsuranceValue(gratuityLetterFileEntryInsurancePart                                .getInsuranceValue());                    }                }                // this check is required because the insurance part can                // also be null                if (gratuityLetterFileEntry != null) {                    gratuityLetterFileEntries.add(gratuityLetterFileEntry);                }            }        }        byte[] fileContent = writeLetterFiles(gratuityLetterFileEntries, executionYear);        return fileContent;    }