Example usage for org.joda.time LocalDate isAfter

List of usage examples for org.joda.time LocalDate isAfter

Introduction

In this page you can find the example usage for org.joda.time LocalDate isAfter.

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonContractSituationsFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;/*from  w w  w .j a v a2s  . com*/
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }
        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty personProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }

        final String contractSituationGiafId = result.getString("emp_sit");
        final ContractSituation contractSituation = metadata.situation(contractSituationGiafId);
        if (contractSituation == null) {
            logger.debug("Invalid situation: " + contractSituationGiafId);
            importedButInvalid.add(person);
        }

        final String categoryGiafId = result.getString("emp_cat_func");
        final ProfessionalCategory category = metadata.category(categoryGiafId);
        if (category == null && (!Strings.isNullOrEmpty(categoryGiafId))) {
            logger.debug("Empty category: " + categoryGiafId + ". Person number: " + numberString);
            importedButInvalid.add(person);
        }
        if (category == null && (contractSituation == null || contractSituation.getEndSituation() == false)) {
            logger.debug("Empty catefory on a non end situation: " + numberString + " . Situation: "
                    + contractSituationGiafId);
            importedButInvalid.add(person);
        }

        String beginDateString = result.getString("dt_inic");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug("Empty beginDate: " + numberString + " . Situation: " + contractSituationGiafId);
            importedButInvalid.add(person);
        }
        String endDateString = result.getString("dt_fim");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (endDate != null) {
            if (beginDate != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after EndDate: " + numberString + " begin: " + beginDate + " end:"
                        + endDate);
                importedButInvalid.add(person);
            }
        }
        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate: " + numberString + " . Situation: " + contractSituationGiafId);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        final String step = result.getString("emp_escalao");

        if (!hasPersonContractSituation(giafProfessionalData, beginDate, endDate, creationDate, modifiedDate,
                step, contractSituation, contractSituationGiafId, category, categoryGiafId)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonContractSituation(giafProfessionalData, beginDate, endDate, step,
                            contractSituation, contractSituationGiafId, category, categoryGiafId, creationDate,
                            modifiedDate);
                }
            });
            news++;
        }

    }
    result.close();
    preparedStatement.close();

    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (final PersonContractSituation personContractSituation : giafProfessionalData
                .getPersonContractSituationsSet()) {
            if (personContractSituation.getAnulationDate() == null) {
                int countThisPersonContractSituationOnGiaf = countThisPersonContractSituationOnGiaf(
                        oracleConnection, personContractSituation, logger);
                if (countThisPersonContractSituationOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personContractSituation.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonContractSituationOnGiaf > 1) {
                        repeted += countThisPersonContractSituationOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    LocalDate today = new LocalDate();
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        if (giafProfessionalData.getPersonProfessionalData().getPerson() != null) {
            User user = giafProfessionalData.getPersonProfessionalData().getPerson().getUser();
            if (giafProfessionalData.getValidPersonContractSituations().stream()
                    .filter(pcs -> pcs.isActive(today)).count() != 0) {
                modifications.add(new Modification() {
                    @Override
                    public void execute() {
                        user.openLoginPeriod();
                    }
                });
            } else {
                if (!new ActiveStudentsGroup().isMember(user) && !new AllAlumniGroup().isMember(user)
                        && Invitation.getActiveInvitations(user.getPerson()).size() == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            user.closeLoginPeriod();
                        }
                    });
                }
            }
        }
    }
    log.println("-- Contract situations --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));

    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonFunctionsAccumulationsFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;//from w  w w  .j  a v  a  2  s  . c  o  m
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }

        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty personProfessionalData: " + numberString);
            dontExist++;
            continue;
        }

        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }

        final String functionsAccumulationGiafId = result.getString("TIPO");
        final FunctionsAccumulation functionsAccumulation = metadata.accumulation(functionsAccumulationGiafId);
        if (functionsAccumulation == null) {
            logger.debug("Empty FunctionsAccumulation: " + functionsAccumulationGiafId + " for person number: "
                    + numberString);
            importedButInvalid.add(person);
        }
        String beginDateString = result.getString("DATA_INICIO");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug("Empty beginDate: " + numberString + " FunctionsAccumulation: "
                    + functionsAccumulationGiafId);
            importedButInvalid.add(person);
        }

        String endDateString = result.getString("DATA_FIM");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (beginDate != null && endDate != null) {
            if (beginDate != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after EndDate. Person number: " + numberString + ". begin: " + beginDate
                        + " end:" + endDate);
                importedButInvalid.add(person);
            }
        }
        final BigDecimal hours = result.getBigDecimal("horas_sem");

        final String professionalRegimeGiafId = result.getString("EMP_REGIME");
        final ProfessionalRegime professionalRegime = metadata.regime(professionalRegimeGiafId);
        if (professionalRegime == null) {
            logger.debug("Empty regime: " + numberString);
            importedButInvalid.add(person);
        }
        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creation Date. Person number: " + numberString + " FunctionsAccumulation: "
                    + functionsAccumulationGiafId);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonFunctionsAccumulations(giafProfessionalData, beginDate, endDate, hours,
                functionsAccumulation, functionsAccumulationGiafId, professionalRegime,
                professionalRegimeGiafId, creationDate, modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonFunctionsAccumulation(giafProfessionalData, beginDate, endDate, hours,
                            functionsAccumulation, functionsAccumulationGiafId, professionalRegime,
                            professionalRegimeGiafId, creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;

    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (final PersonFunctionsAccumulation personFunctionsAccumulation : giafProfessionalData
                .getPersonFunctionsAccumulationsSet()) {
            if (personFunctionsAccumulation.getAnulationDate() == null) {
                int countThisPersonFunctionsAccumulationOnGiaf = countThisPersonFunctionsAccumulationOnGiaf(
                        oracleConnection, personFunctionsAccumulation, logger);
                if (countThisPersonFunctionsAccumulationOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personFunctionsAccumulation.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonFunctionsAccumulationOnGiaf > 1) {
                        repeted += countThisPersonFunctionsAccumulationOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Function accumuations --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonGrantOwnerEquivalentFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;/*w  w w  .j  a v a2  s.c om*/
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }

        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty personProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final String grantOwnerEquivalentGiafId = result.getString("tipo_equip");
        final GrantOwnerEquivalent grantOwnerEquivalent = metadata
                .grantOwnerEquivalent(grantOwnerEquivalentGiafId);
        if (grantOwnerEquivalent == null) {
            logger.debug("Empty grantOwnerEquivalent: " + grantOwnerEquivalentGiafId + ". Person number: "
                    + numberString);
            importedButInvalid.add(person);
        }
        String beginDateString = result.getString("DATA_INICIO");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug("Empty beginDate. Person number: " + numberString + " ServiceExemption: "
                    + grantOwnerEquivalentGiafId);
            importedButInvalid.add(person);
        }
        String endDateString = result.getString("DATA_FIM");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));

        if (endDate != null) {
            if (beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after EndDate. Person number: " + numberString + " beginDate: "
                        + beginDate + " endDate: " + endDate);
                importedButInvalid.add(person);
            }
        }

        final String motive = result.getString("motivo");
        final String local = result.getString("local");

        final String giafCountryName = result.getString("nac_dsc");
        final Country country = Strings.isNullOrEmpty(giafCountryName) ? null
                : metadata.country(StringNormalizer.normalize(giafCountryName));
        if (country == null) {
            importedButInvalid.add(person);
        }

        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate. Person number: " + numberString + " grantOwnerEquivalent: "
                    + grantOwnerEquivalentGiafId);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonGrantOwnerEquivalent(giafProfessionalData, beginDate, endDate, motive, local,
                giafCountryName, country, grantOwnerEquivalent, grantOwnerEquivalentGiafId, creationDate,
                modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonGrantOwnerEquivalent(giafProfessionalData, beginDate, endDate, motive, local,
                            giafCountryName, country, grantOwnerEquivalent, grantOwnerEquivalentGiafId,
                            creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (PersonProfessionalExemption pesonProfessionalExemption : giafProfessionalData
                .getPersonProfessionalExemptionsSet()) {
            if (pesonProfessionalExemption instanceof PersonGrantOwnerEquivalent
                    && pesonProfessionalExemption.getAnulationDate() == null) {
                final PersonGrantOwnerEquivalent personGrantOwnerEquivalent = (PersonGrantOwnerEquivalent) pesonProfessionalExemption;
                int countThisPersonGrantOwnerEquivalentOnGiaf = countThisPersonGrantOwnerEquivalentOnGiaf(
                        oracleConnection, personGrantOwnerEquivalent, logger);
                if (countThisPersonGrantOwnerEquivalentOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personGrantOwnerEquivalent.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonGrantOwnerEquivalentOnGiaf > 1) {
                        repeted += countThisPersonGrantOwnerEquivalentOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Grant owner equivalences --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonProfessionalCategoriesFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int novos = 0;
    int notImported = 0;
    int dontExist = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;//from w ww  .java2  s.c o  m
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }
        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty employeeProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final String professionalCategoryGiafId = result.getString("emp_cat_func");
        final ProfessionalCategory professionalCategory = metadata.category(professionalCategoryGiafId);
        if (professionalCategory == null) {
            logger.debug(
                    "Empty category : " + professionalCategoryGiafId + " for person number: " + numberString);
            importedButInvalid.add(person);
        }
        String beginDateString = result.getString("emp_dt_inicio");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug("Empty beginDate. Person number: " + numberString + " category: "
                    + professionalCategoryGiafId);
            importedButInvalid.add(person);
        }
        String endDateString = result.getString("emp_dt_fim");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (endDate != null) {
            if (beginDate != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after endDate. Person number: " + numberString + " begin: " + beginDate
                        + " end:" + endDate);
                importedButInvalid.add(person);
            }
        }

        final String step = result.getString("emp_escalao");
        final String level = result.getString("emp_venc_nvl");

        // a.emp_regime, a.emp_vinculo
        final String professionalRegimeGiafId = result.getString("emp_regime");
        final ProfessionalRegime professionalRegime = metadata.regime(professionalRegimeGiafId);
        if (professionalRegime == null && (!Strings.isNullOrEmpty(professionalRegimeGiafId))) {
            logger.debug("Empty regime: " + professionalRegimeGiafId + ". Person number: " + numberString);
            importedButInvalid.add(person);
        }

        final String professionalRelationGiafId = result.getString("emp_vinculo");
        final ProfessionalRelation professionalRelation = metadata.relation(professionalRelationGiafId);
        if (professionalRelation == null && (!Strings.isNullOrEmpty(professionalRelationGiafId))) {
            logger.debug("Empty relation: " + professionalRelationGiafId + ". Person number: " + numberString);
            importedButInvalid.add(person);
        }
        // ,a.data_criacao,a.data_alteracao
        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate. Person number: " + numberString + " Category: "
                    + professionalCategoryGiafId);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonProfessionalCategory(giafProfessionalData, beginDate, endDate, professionalCategory,
                professionalCategoryGiafId, professionalRegime, professionalRegimeGiafId, professionalRelation,
                professionalRelationGiafId, step, level, creationDate, modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonProfessionalCategory(giafProfessionalData, beginDate, endDate,
                            professionalCategory, professionalCategoryGiafId, professionalRegime,
                            professionalRegimeGiafId, professionalRelation, professionalRelationGiafId, step,
                            level, creationDate, modifiedDate);
                }
            });
            novos++;
        }

    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (final PersonProfessionalCategory personProfessionalCategory : giafProfessionalData
                .getPersonProfessionalCategoriesSet()) {
            if (personProfessionalCategory.getAnulationDate() == null) {
                int countThisPersonProfessionalCategoryOnGiaf = countThisPersonProfessionalCategoryOnGiaf(
                        oracleConnection, personProfessionalCategory, logger);
                if (countThisPersonProfessionalCategoryOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personProfessionalCategory.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    if (countThisPersonProfessionalCategoryOnGiaf > 1) {
                        repeted += countThisPersonProfessionalCategoryOnGiaf - 1;
                    }
                    totalInFenix++;
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Professional categories --");
    log.println("Total GIAF: " + count);
    log.println("New: " + novos);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonProfessionalContractsFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;/*w  ww.  j a va 2 s  .co  m*/
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }

        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty employeeProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final String contractSituationGiafId = result.getString("COD_CONTRATO");
        final ContractSituation contractSituation = metadata.situation(contractSituationGiafId);
        if (contractSituation == null) {
            logger.debug("Empty situation: " + contractSituationGiafId + " for person number: " + numberString);
            importedButInvalid.add(person);
        }

        String beginDateString = result.getString("dt_inic");

        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));

        if (beginDate == null) {
            logger.debug("Empty beginDate: " + numberString + " Situation: " + contractSituationGiafId);
            importedButInvalid.add(person);
        }

        String endDateString = result.getString("dt_fim");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (endDate != null) {
            if (beginDate != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after endDate. Person number:" + numberString + " begin: " + beginDate
                        + " end:" + endDate);
                importedButInvalid.add(person);
            }
        }
        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate: " + numberString + " Situation: " + contractSituationGiafId);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonProfessionalContract(giafProfessionalData, beginDate, endDate, creationDate, modifiedDate,
                contractSituation, contractSituationGiafId)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonProfessionalContract(giafProfessionalData, beginDate, endDate, contractSituation,
                            contractSituationGiafId, creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (final PersonProfessionalContract personProfessionalContract : giafProfessionalData
                .getPersonProfessionalContractsSet()) {
            if (personProfessionalContract.getAnulationDate() == null) {
                int countThisPersonProfessionalContractOnGiaf = countThisPersonProfessionalContractOnGiaf(
                        oracleConnection, personProfessionalContract, logger);
                if (countThisPersonProfessionalContractOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personProfessionalContract.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonProfessionalContractOnGiaf > 1) {
                        repeted += countThisPersonProfessionalContractOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Professional Contracts --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonProfessionalRegimesFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;// w ww. j  a v a 2  s  .co  m
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }
        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty personProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final String professionalRegimeGiafId = result.getString("emp_regime");
        final ProfessionalRegime professionalRegime = metadata.regime(professionalRegimeGiafId);
        if (professionalRegime == null) {
            logger.debug("Empty regime: " + professionalRegimeGiafId + " person number" + numberString);
            importedButInvalid.add(person);
        }
        String beginDateString = result.getString("emp_regime_dt");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug(
                    "Empty beginDate. Person number: " + numberString + " Regime: " + professionalRegimeGiafId);
            importedButInvalid.add(person);
        }
        String endDateString = result.getString("emp_regime_dt_fim");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (endDate != null) {
            if (beginDate != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after EndDate. Person number: " + numberString + " begin: " + beginDate
                        + " end:" + endDate);
                importedButInvalid.add(person);
            }
        }
        // ,a.data_criacao,a.data_alteracao
        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate. Person number: " + numberString + " Regime: "
                    + professionalRegimeGiafId);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonProfessionalRegime(giafProfessionalData, beginDate, endDate, professionalRegime,
                professionalRegimeGiafId, creationDate, modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonProfessionalRegime(giafProfessionalData, beginDate, endDate, professionalRegime,
                            professionalRegimeGiafId, creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (final PersonProfessionalRegime personProfessionalRegime : giafProfessionalData
                .getPersonProfessionalRegimesSet()) {
            if (personProfessionalRegime.getAnulationDate() == null) {
                int countThisPersonProfessionalRegimeOnGiaf = countThisPersonProfessionalRegimeOnGiaf(
                        oracleConnection, personProfessionalRegime, logger);
                if (countThisPersonProfessionalRegimeOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personProfessionalRegime.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonProfessionalRegimeOnGiaf > 1) {
                        repeted += countThisPersonProfessionalRegimeOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Professional regimes --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonProfessionalRelationsFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;/*from ww w .  j  av a2  s .  c o m*/
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }

        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty personProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final String professionalRelationGiafId = result.getString("emp_vinculo");
        final ProfessionalRelation professionalRelation = metadata.relation(professionalRelationGiafId);
        if (professionalRelation == null) {
            logger.debug(
                    "Empty relation: " + professionalRelationGiafId + " for person number:" + numberString);
            importedButInvalid.add(person);
        }
        String beginDateString = result.getString("emp_dt_inic");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug("Empty beginDate. Person number: " + numberString + " Relation: "
                    + professionalRelationGiafId);
            importedButInvalid.add(person);
        }
        String endDateString = result.getString("emp_dt_fim");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (endDate != null) {
            if (beginDate != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after endDate. Person number: " + numberString + " begin: " + beginDate
                        + " end:" + endDate);
                importedButInvalid.add(person);
            }
        }

        final String professionalCategoryGiafId = result.getString("emp_cat_func");
        final ProfessionalCategory professionalCategory = metadata.category(professionalCategoryGiafId);
        if ((!Strings.isNullOrEmpty(professionalCategoryGiafId)) && professionalCategory == null) {
            logger.debug("Empty category " + professionalCategoryGiafId + ". Person number: " + numberString);
            importedButInvalid.add(person);
        }

        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate. Person number: " + numberString + " Relation: "
                    + professionalRelationGiafId);
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonProfessionalRelation(giafProfessionalData, beginDate, endDate, professionalRelation,
                professionalRelationGiafId, professionalCategory, professionalCategoryGiafId, creationDate,
                modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonProfessionalRelation(giafProfessionalData, beginDate, endDate,
                            professionalRelation, professionalRelationGiafId, professionalCategory,
                            professionalCategoryGiafId, creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (final PersonProfessionalRelation personProfessionalRelation : giafProfessionalData
                .getPersonProfessionalRelationsSet()) {
            if (personProfessionalRelation.getAnulationDate() == null) {
                int countThisPersonProfessionalRelationOnGiaf = countThisPersonProfessionalRelationOnGiaf(
                        oracleConnection, personProfessionalRelation, logger);
                if (countThisPersonProfessionalRelationOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personProfessionalRelation.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonProfessionalRelationOnGiaf > 1) {
                        repeted += countThisPersonProfessionalRelationOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Professional relations --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonSabbaticalsFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    Set<Person> importedButInvalid = new HashSet<Person>();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    while (result.next()) {
        count++;/*from w w w.ja va2s  . c  o  m*/
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }
        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty personProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        String beginDateString = result.getString("DATA_INICIO");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug("Empty beginDate. Person number: " + numberString);
            importedButInvalid.add(person);
        }
        String endDateString = result.getString("DATA_FIM");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (endDate != null) {
            if (beginDate != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after EndDate. Person number: " + numberString + " begin: " + beginDate
                        + " end: " + endDate);
                importedButInvalid.add(person);
            }
        }
        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate. Person number: " + numberString);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonSabbatical(giafProfessionalData, beginDate, endDate, creationDate, modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonSabbatical(giafProfessionalData, beginDate, endDate, creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (PersonProfessionalExemption personProfessionalExemption : giafProfessionalData
                .getPersonProfessionalExemptionsSet()) {
            if (personProfessionalExemption instanceof PersonSabbatical
                    && personProfessionalExemption.getAnulationDate() == null) {
                final PersonSabbatical personSabbatical = (PersonSabbatical) personProfessionalExemption;
                int countThisPersonSabbaticalOnGiaf = countThisPersonSabbaticalOnGiaf(oracleConnection,
                        personSabbatical, logger);
                if (countThisPersonSabbaticalOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personSabbatical.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonSabbaticalOnGiaf > 1) {
                        repeted += countThisPersonSabbaticalOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Sabbaticals --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonServiceExemptionsFromGiaf.java

License:Open Source License

@Override
public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger)
        throws Exception {
    List<Modification> modifications = new ArrayList<>();
    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery());
    ResultSet result = preparedStatement.executeQuery();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    Set<Person> importedButInvalid = new HashSet<Person>();
    while (result.next()) {
        count++;//from  ww  w  .  j av  a2  s.  co  m
        String numberString = result.getString("emp_num");
        Person person = metadata.getPerson(numberString, logger);
        if (person == null) {
            logger.debug("Invalid person with number: " + numberString);
            dontExist++;
            continue;
        }
        PersonProfessionalData personProfessionalData = person.getPersonProfessionalData();
        if (personProfessionalData == null) {
            logger.debug("Empty personProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final GiafProfessionalData giafProfessionalData = personProfessionalData
                .getGiafProfessionalDataByGiafPersonIdentification(numberString);
        if (giafProfessionalData == null) {
            logger.debug("Empty giafProfessionalData: " + numberString);
            dontExist++;
            continue;
        }
        final String serviceExemptionGiafId = result.getString("tip_disp");
        final ServiceExemption serviceExemption = metadata.exemption(serviceExemptionGiafId);
        if (serviceExemption == null) {
            logger.debug("Empty serviceExemption: " + serviceExemptionGiafId + " for person number: "
                    + numberString);
            importedButInvalid.add(person);

        }
        String beginDateString = result.getString("DATA_INICIO");
        final LocalDate beginDate = Strings.isNullOrEmpty(beginDateString) ? null
                : new LocalDate(Timestamp.valueOf(beginDateString));
        if (beginDate == null) {
            logger.debug("Empty beginDate. Person number: " + numberString + " ServiceExemption: "
                    + serviceExemptionGiafId);
            importedButInvalid.add(person);
        }
        String endDateString = result.getString("DATA_FIM");
        final LocalDate endDate = Strings.isNullOrEmpty(endDateString) ? null
                : new LocalDate(Timestamp.valueOf(endDateString));
        if (beginDate != null && endDate != null) {
            if (beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after endDate. Person number: " + numberString + " begin: " + beginDate
                        + " end: " + endDate);
                importedButInvalid.add(person);
            }
        }
        String creationDateString = result.getString("data_criacao");
        if (Strings.isNullOrEmpty(creationDateString)) {
            logger.debug("Empty creationDate. Person number: " + numberString + " ServiceExemption: "
                    + serviceExemptionGiafId);
            notImported++;
            continue;
        }
        final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString));

        String modifiedDateString = result.getString("data_alteracao");
        final DateTime modifiedDate = Strings.isNullOrEmpty(modifiedDateString) ? null
                : new DateTime(Timestamp.valueOf(modifiedDateString));

        if (!hasPersonServiceExemption(giafProfessionalData, beginDate, endDate, serviceExemption,
                serviceExemptionGiafId, creationDate, modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonServiceExemption(giafProfessionalData, beginDate, endDate, serviceExemption,
                            serviceExemptionGiafId, creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (PersonProfessionalExemption personProfessionalExemption : giafProfessionalData
                .getPersonProfessionalExemptionsSet()) {
            if (personProfessionalExemption instanceof PersonServiceExemption
                    && personProfessionalExemption.getAnulationDate() == null) {
                final PersonServiceExemption personServiceExemption = (PersonServiceExemption) personProfessionalExemption;
                int countThisPersonServiceExemptionOnGiaf = countThisPersonServiceExemptionOnGiaf(
                        oracleConnection, personServiceExemption, logger);
                if (countThisPersonServiceExemptionOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personServiceExemption.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonServiceExemptionOnGiaf > 1) {
                        repeted += countThisPersonServiceExemptionOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Service Exemptions --");
    log.println("Total GIAF: " + count);
    log.println("New: " + news);
    log.println("Deleted: " + deleted);
    log.println("Not imported: " + notImported);
    log.println("Imported with errors: " + importedButInvalid.size());
    log.println("Repeted: " + repeted);
    log.println("Invalid persons: " + dontExist);
    log.println("Total Fnix: " + totalInFenix);
    log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size()));
    log.println("Missing in Fnix: " + (count - totalInFenix));
    return modifications;
}

From source file:pt.ulisboa.tecnico.softeng.car.domain.Renting.java

/**
 * @param begin/*from   ww  w.  jav a 2s.  c o m*/
 * @param end
 * @return <code>true</code> if this Renting conflicts with the given date
 *         range.
 */
public boolean conflict(LocalDate begin, LocalDate end) {
    if (end.isBefore(begin)) {
        throw new CarException("Error: end date is before begin date.");
    } else if ((begin.equals(this.getBegin()) || begin.isAfter(this.getBegin()))
            && (begin.isBefore(this.getEnd()) || begin.equals(this.getEnd()))) {
        return true;
    } else if ((end.equals(this.getEnd()) || end.isBefore(this.getEnd()))
            && (end.isAfter(this.getBegin()) || end.isEqual(this.getBegin()))) {
        return true;
    } else if (begin.isBefore(this.getBegin()) && end.isAfter(this.getEnd())) {
        return true;
    }

    return false;
}