Search in sources :

Example 1 with OrganizacaoDAO

use of com.tomasio.projects.trainning.dao.OrganizacaoDAO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method updateUser.

@Override
@Transactional(readOnly = true)
public void updateUser(NetworkUserDTO user) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        NetworkUserDTO oldUser = userDAO.find(user.getLogin());
        userDAO.update(user);
        if (!oldUser.getOrganizacao().equals(user.getOrganizacao())) {
            // REMOVER DO GRUPO DA ORGANIZAÇÃO ANTIGA
            NetworkGroupDTO oldOrganizationGroup = groupDAO.findOrganization(oldUser.getOrganizacao());
            if (oldOrganizationGroup != null) {
                oldOrganizationGroup.getMembers().remove(oldUser.getId());
                if (oldOrganizationGroup.getMembers().size() > 0) {
                    groupDAO.update(oldOrganizationGroup);
                } else {
                    groupDAO.removeOrganization(oldUser.getOrganizacao());
                }
            }
            // ADICIONAR AO GRUPO DA ORGANIZAÇÃO NOVA
            Organizacao organizacao = organizacaoDAO.findBySigla(user.getOrganizacao());
            NetworkGroupDTO organizationGroup = groupDAO.findOrganization(organizacao.getSigla());
            if (organizationGroup == null) {
                organizationGroup = new NetworkGroupDTO();
                organizationGroup.setNome(organizacao.getSigla());
                organizationGroup.setDescricao(organizacao.getNome());
                organizationGroup.getMembers().add(user.getId());
                groupDAO.createOrganization(organizationGroup);
            } else {
                organizationGroup.getMembers().add(user.getId());
                groupDAO.update(organizationGroup);
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OrganizacaoDAO

use of com.tomasio.projects.trainning.dao.OrganizacaoDAO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method createUser.

@Override
@Transactional(readOnly = true)
public void createUser(NetworkUserDTO user) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        userDAO.create(user);
        user = userDAO.find(user.getLogin());
        NetworkGroupDTO roleGroup = groupDAO.findRole("OperadorLocal");
        Organizacao organizacao = organizacaoDAO.findBySigla(user.getOrganizacao());
        NetworkGroupDTO organizationGroup = groupDAO.findOrganization(organizacao.getSigla());
        if (organizationGroup == null) {
            organizationGroup = new NetworkGroupDTO();
            organizationGroup.setNome(organizacao.getSigla());
            organizationGroup.setDescricao(organizacao.getNome());
            organizationGroup.getMembers().add(user.getId());
            groupDAO.createOrganization(organizationGroup);
        } else {
            organizationGroup.getMembers().add(user.getId());
            groupDAO.update(organizationGroup);
        }
        roleGroup.getMembers().add(user.getId());
        groupDAO.update(roleGroup);
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OrganizacaoDAO

use of com.tomasio.projects.trainning.dao.OrganizacaoDAO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method createUser.

@Override
@Transactional(readOnly = true)
public void createUser(NetworkUserDTO user, String[] roles) {
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    NetworkGroupDAO groupDAO = factory.getNetworkGroupDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    try {
        userDAO.create(user);
        user = userDAO.find(user.getLogin());
        Organizacao organizacao = organizacaoDAO.findBySigla(user.getOrganizacao());
        NetworkGroupDTO organizationGroup = groupDAO.findOrganization(organizacao.getSigla());
        if (organizationGroup == null) {
            organizationGroup = new NetworkGroupDTO();
            organizationGroup.setNome(organizacao.getSigla());
            organizationGroup.setDescricao(organizacao.getNome());
            organizationGroup.getMembers().add(user.getId());
            groupDAO.createOrganization(organizationGroup);
        } else {
            organizationGroup.getMembers().add(user.getId());
            groupDAO.update(organizationGroup);
        }
        if (roles != null) {
            for (String role : roles) {
                NetworkGroupDTO roleGroup = groupDAO.findRole(role);
                roleGroup.getMembers().add(user.getId());
                groupDAO.update(roleGroup);
            }
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with OrganizacaoDAO

use of com.tomasio.projects.trainning.dao.OrganizacaoDAO in project trainning by fernandotomasio.

the class AtividadesEnsinoServiceSimpleImpl method calculateCustoRealizadoInstrutores.

@Override
@Transactional(readOnly = true)
public Map<String, BigDecimal> calculateCustoRealizadoInstrutores(TurmaEfetivaDTO[] turmas) {
    Map<String, BigDecimal> result = new HashMap();
    MatriculaDAO matriculaDAO = factory.getMatriculaDAO();
    PessoaDAO pessoaDAO = factory.getPessoaDAO();
    String parameterDiaria = ConfigHelper.getValue("custos.diaria");
    String parameterPassagem = ConfigHelper.getValue("custos.passagem");
    BigDecimal diaria = new BigDecimal(parameterDiaria);
    BigDecimal passagem = new BigDecimal(parameterPassagem);
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    BigDecimal transporteRealizado = new BigDecimal(0.00);
    BigDecimal diariasRealizado = new BigDecimal(0.00);
    try {
        for (TurmaEfetivaDTO turma : turmas) {
            if (turma.isCancelado()) {
                continue;
            }
            List<Matricula> instrucoes = matriculaDAO.findAllInstrutores(turma.getId());
            for (Matricula matricula : instrucoes) {
                if (matricula.isCancelada()) {
                    continue;
                }
                matricula.getIndicacao().getId();
                IndicacaoInstrutorDTO indicacao = (IndicacaoInstrutorDTO) matricula.getIndicacao().createDTO();
                int intervalo = 0;
                Interval instrucaoInterval = null;
                if (indicacao.getPeriodo() != null && indicacao.getPeriodo().getDataInicio() != null && indicacao.getPeriodo().getDataTermino() != null) {
                    DateTime dataInicioInstrucao = new DateTime(indicacao.getPeriodo().getDataInicio().getTime());
                    DateTime dataTerminoInstrucao = new DateTime(indicacao.getPeriodo().getDataTermino().getTime());
                    if (dataInicioInstrucao.isAfter(dataTerminoInstrucao)) {
                        continue;
                    }
                    instrucaoInterval = new Interval(dataInicioInstrucao, dataTerminoInstrucao);
                    Days d = Days.daysBetween(dataInicioInstrucao, dataTerminoInstrucao);
                    intervalo = d.getDays() + 2;
                }
                if (intervalo <= 0) {
                    continue;
                }
                if (intervalo > 50) {
                    intervalo = 50;
                }
                Pessoa pessoa = pessoaDAO.find(indicacao.getPessoa().getId());
                if (pessoa.getOrganizacao() != null) {
                    Organizacao organizacaoInstrutor = organizacaoDAO.find(pessoa.getOrganizacao().getId());
                    if (organizacaoInstrutor.createDTO() instanceof ExternoDTO) {
                        continue;
                    }
                    FaseDTO[] fases = turma.getFases();
                    for (FaseDTO fase : fases) {
                        if (fase.getDataInicio() != null && fase.getDataTermino() != null) {
                            DateTime dataInicioFase = new DateTime(fase.getDataInicio().getTime());
                            DateTime dataTerminoFase = new DateTime(fase.getDataTermino().getTime());
                            if (dataTerminoFase.isBefore(dataInicioFase)) {
                                continue;
                            }
                            Interval faseInterval = new Interval(dataInicioFase, dataTerminoFase);
                            if (faseInterval.contains(instrucaoInterval) || instrucaoInterval.contains(faseInterval)) {
                                Organizacao organizacaoLocal = organizacaoDAO.find(fase.getLocal().getId());
                                if (!organizacaoInstrutor.getCidade().getId().equals(organizacaoLocal.getCidade().getId())) {
                                    diariasRealizado = diariasRealizado.add(diaria.multiply(new BigDecimal(intervalo)));
                                    transporteRealizado = transporteRealizado.add(passagem);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (DAOException ex) {
        Logger.getLogger(AtividadesEnsinoServiceSimpleImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
    result.put("transporte", transporteRealizado);
    result.put("diarias", diariasRealizado);
    result.put("total", transporteRealizado.add(diariasRealizado));
    return result;
}
Also used : HashMap(java.util.HashMap) PessoaDAO(com.tomasio.projects.trainning.dao.PessoaDAO) CancelamentoMatricula(com.tomasio.projects.trainning.model.CancelamentoMatricula) Matricula(com.tomasio.projects.trainning.model.Matricula) NotificacaoMatricula(com.tomasio.projects.trainning.model.NotificacaoMatricula) PreMatricula(com.tomasio.projects.trainning.model.PreMatricula) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) Pessoa(com.tomasio.projects.trainning.model.Pessoa) 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) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CancelamentoMatriculaDAO(com.tomasio.projects.trainning.dao.CancelamentoMatriculaDAO) MatriculaDAO(com.tomasio.projects.trainning.dao.MatriculaDAO) NotificacaoMatriculaDAO(com.tomasio.projects.trainning.dao.NotificacaoMatriculaDAO) PreMatriculaDAO(com.tomasio.projects.trainning.dao.PreMatriculaDAO) Days(org.joda.time.Days) ExternoDTO(com.tomasio.projects.trainning.dto.ExternoDTO) IndicacaoInstrutorDTO(com.tomasio.projects.trainning.dto.IndicacaoInstrutorDTO) Interval(org.joda.time.Interval) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OrganizacaoDAO

use of com.tomasio.projects.trainning.dao.OrganizacaoDAO in project trainning by fernandotomasio.

the class AtividadesEnsinoServiceSimpleImpl method createIndicacao.

@Override
@Transactional
public Long createIndicacao(IndicacaoDTO indicacao) {
    IndicacaoDAO dao = factory.getIndicacaoDAO();
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    TurmaDAO turmaDAO = factory.getTurmaDAO();
    Indicacao _indicacao = null;
    if (indicacao != null) {
        if (indicacao instanceof IndicacaoAlunoDTO) {
            _indicacao = new IndicacaoAluno((IndicacaoAlunoDTO) indicacao);
        } else {
            _indicacao = new IndicacaoInstrutor((IndicacaoInstrutorDTO) indicacao);
        }
    }
    Long id = null;
    try {
        id = dao.create(_indicacao);
        updateWorkflowActors(_indicacao.getId());
    } catch (DAOException ex) {
        throw new CoreException(ex.getMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new CoreException("Erro em tempo de execução: " + ex.getMessage());
    }
    return id;
}
Also used : IndicacaoDAO(com.tomasio.projects.trainning.dao.IndicacaoDAO) IndicacaoAlunoDTO(com.tomasio.projects.trainning.dto.IndicacaoAlunoDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) IndicacaoAluno(com.tomasio.projects.trainning.model.IndicacaoAluno) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Indicacao(com.tomasio.projects.trainning.model.Indicacao) IndicacaoInstrutor(com.tomasio.projects.trainning.model.IndicacaoInstrutor) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) IndicacaoInstrutorDTO(com.tomasio.projects.trainning.dto.IndicacaoInstrutorDTO) 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

OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)26 DAOException (com.tomasio.projects.trainning.exception.DAOException)25 Organizacao (com.tomasio.projects.trainning.model.Organizacao)19 HibernateOrganizacaoDAO (com.tomasio.projects.trainning.dao.HibernateOrganizacaoDAO)13 PessoaDAO (com.tomasio.projects.trainning.dao.PessoaDAO)11 Transactional (org.springframework.transaction.annotation.Transactional)10 HibernatePessoaDAO (com.tomasio.projects.trainning.dao.HibernatePessoaDAO)9 IndicacaoDAO (com.tomasio.projects.trainning.dao.IndicacaoDAO)8 Pessoa (com.tomasio.projects.trainning.model.Pessoa)8 HibernateIndicacaoDAO (com.tomasio.projects.trainning.dao.HibernateIndicacaoDAO)6 MatriculaDAO (com.tomasio.projects.trainning.dao.MatriculaDAO)6 NetworkUserDAO (com.tomasio.projects.trainning.dao.NetworkUserDAO)5 TurmaEfetivaDTO (com.tomasio.projects.trainning.dto.TurmaEfetivaDTO)5 CoreException (com.tomasio.projects.trainning.exeption.CoreException)5 Date (java.util.Date)5 HibernateMatriculaDAO (com.tomasio.projects.trainning.dao.HibernateMatriculaDAO)4 NetworkGroupDAO (com.tomasio.projects.trainning.dao.NetworkGroupDAO)4 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)4 NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)4 BigDecimal (java.math.BigDecimal)4