Search in sources :

Example 1 with Distribuicao

use of com.tomasio.projects.trainning.model.Distribuicao in project trainning by fernandotomasio.

the class PlanningServiceSimpleImpl method findDistribuicao.

@Override
@Transactional(readOnly = true)
public DistribuicaoDTO findDistribuicao(Long turmaId, Long organizacaoId) {
    DistribuicaoDAO dao = factory.getDistribuicaoDAO();
    Distribuicao distribuicao = null;
    try {
        distribuicao = dao.find(turmaId, organizacaoId);
        if (distribuicao != null) {
            return distribuicao.createDTO();
        } else {
            return null;
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Distribuicao(com.tomasio.projects.trainning.model.Distribuicao) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Distribuicao

use of com.tomasio.projects.trainning.model.Distribuicao in project trainning by fernandotomasio.

the class PlanningServiceSimpleImpl method findAllDistribuicoes.

@Override
@Transactional(readOnly = true)
public DistribuicaoDTO[] findAllDistribuicoes(Long turmaId) {
    DistribuicaoDAO dao = factory.getDistribuicaoDAO();
    DistribuicaoDTO[] distribuicoesArray = null;
    try {
        List<Distribuicao> distribuicoes = dao.findAll(turmaId);
        if (distribuicoes != null) {
            distribuicoesArray = new DistribuicaoDTO[distribuicoes.size()];
            for (int i = 0; i < distribuicoes.size(); i++) {
                distribuicoesArray[i] = distribuicoes.get(i).createDTOWithoutDependencies();
            }
        }
    } catch (DAOException ex) {
        ex.printStackTrace();
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
    return distribuicoesArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Distribuicao(com.tomasio.projects.trainning.model.Distribuicao) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Distribuicao

use of com.tomasio.projects.trainning.model.Distribuicao in project trainning by fernandotomasio.

the class PlanningServiceSimpleImpl method updateDistribuicao.

@Override
@Transactional
public void updateDistribuicao(DistribuicaoDTO distribuicao) {
    DistribuicaoDAO dao = factory.getDistribuicaoDAO();
    Distribuicao _distribuicao = new Distribuicao(distribuicao);
    Long id = null;
    try {
        dao.update(_distribuicao);
    } catch (DAOException ex) {
        ex.printStackTrace();
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Distribuicao(com.tomasio.projects.trainning.model.Distribuicao) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Distribuicao

use of com.tomasio.projects.trainning.model.Distribuicao in project trainning by fernandotomasio.

the class AtividadesEnsinoServiceSimpleImpl method calculateCustoPrevistoAdministrativo.

@Override
@Transactional(readOnly = true)
public BigDecimal calculateCustoPrevistoAdministrativo(TurmaEfetivaDTO[] turmas) {
    BigDecimal result = new BigDecimal(0);
    DistribuicaoDAO distribuicaoDAO = factory.getDistribuicaoDAO();
    String parameterIcea = ConfigHelper.getValue("custos.icea");
    BigDecimal custoIndividualIcea = new BigDecimal(parameterIcea);
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        for (TurmaEfetivaDTO turma : turmas) {
            List<Distribuicao> vagas = distribuicaoDAO.findAll(turma.getId());
            FaseDTO[] fases = turma.getFases();
            for (FaseDTO fase : fases) {
                if ("PRESENCIAL".equals(fase.getTipoFase())) {
                    int intervalo = 0;
                    if (fase.getDataInicio() != null && fase.getDataTermino() != null) {
                        DateTime dataInicio = new DateTime(fase.getDataInicio().getTime());
                        DateTime dataTermino = new DateTime(fase.getDataTermino().getTime());
                        Days d = Days.daysBetween(dataInicio, dataTermino);
                        intervalo = d.getDays() + 2;
                    }
                    if (intervalo <= 0) {
                        continue;
                    }
                    int countVagas = 0;
                    for (Distribuicao vaga : vagas) {
                        if (vaga.isReserva()) {
                            continue;
                        }
                        countVagas++;
                    }
                    BigDecimal custoTurma = custoIndividualIcea.multiply(new BigDecimal(intervalo)).multiply(new BigDecimal(countVagas));
                    result = result.add(custoTurma);
                }
            }
        }
    } catch (DAOException ex) {
        Logger.getLogger(AtividadesEnsinoServiceSimpleImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
}
Also used : DistribuicaoDAO(com.tomasio.projects.trainning.dao.DistribuicaoDAO) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) FaseDTO(com.tomasio.projects.trainning.dto.FaseDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) TurmaEfetivaDTO(com.tomasio.projects.trainning.dto.TurmaEfetivaDTO) Distribuicao(com.tomasio.projects.trainning.model.Distribuicao) Days(org.joda.time.Days) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Distribuicao

use of com.tomasio.projects.trainning.model.Distribuicao in project trainning by fernandotomasio.

the class AtividadesEnsinoServiceSimpleImpl method findAllDistribuicoes.

@Override
@Transactional(readOnly = true)
public DistribuicaoDTO[] findAllDistribuicoes() {
    DistribuicaoDAO dao = factory.getDistribuicaoDAO();
    DistribuicaoDTO[] distribuicoesArray = null;
    try {
        List<Distribuicao> distribuicoes = dao.findAll();
        if (distribuicoes != null) {
            distribuicoesArray = new DistribuicaoDTO[distribuicoes.size()];
            for (int i = 0; i < distribuicoes.size(); i++) {
                distribuicoesArray[i] = distribuicoes.get(i).createDTOWithoutDependencies();
            }
        }
    } catch (DAOException ex) {
        ex.printStackTrace();
        throw new CoreException(ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
    return distribuicoesArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) DistribuicaoDTO(com.tomasio.projects.trainning.dto.DistribuicaoDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Distribuicao(com.tomasio.projects.trainning.model.Distribuicao) DistribuicaoDAO(com.tomasio.projects.trainning.dao.DistribuicaoDAO) DAOException(com.tomasio.projects.trainning.exception.DAOException) ParseException(java.text.ParseException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DAOException (com.tomasio.projects.trainning.exception.DAOException)14 Distribuicao (com.tomasio.projects.trainning.model.Distribuicao)14 Transactional (org.springframework.transaction.annotation.Transactional)12 CoreException (com.tomasio.projects.trainning.exeption.CoreException)10 DistribuicaoDAO (com.tomasio.projects.trainning.dao.DistribuicaoDAO)9 ParseException (java.text.ParseException)9 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)3 DistribuicaoDTO (com.tomasio.projects.trainning.dto.DistribuicaoDTO)3 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)2 TurmaEfetivaDTO (com.tomasio.projects.trainning.dto.TurmaEfetivaDTO)2 Organizacao (com.tomasio.projects.trainning.model.Organizacao)2 BigDecimal (java.math.BigDecimal)2 DateTime (org.joda.time.DateTime)2 Days (org.joda.time.Days)2 HibernateDistribuicaoDAO (com.tomasio.projects.trainning.dao.HibernateDistribuicaoDAO)1 HibernateOrganizacaoDAO (com.tomasio.projects.trainning.dao.HibernateOrganizacaoDAO)1 ExternoDTO (com.tomasio.projects.trainning.dto.ExternoDTO)1 HashMap (java.util.HashMap)1 HibernateException (org.hibernate.HibernateException)1 Session (org.hibernate.Session)1