Search in sources :

Example 16 with Organizacao

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

the class OrganizationalServiceSimpleImpl method findOrganizacao.

@Override
@Transactional(readOnly = true)
public OrganizacaoDTO findOrganizacao(Long id) {
    OrganizacaoDAO dao = factory.getOrganizacaoDAO();
    Organizacao organizacao = null;
    try {
        organizacao = dao.find(id);
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    }
    if (organizacao != null) {
        return organizacao.createDTO();
    } else {
        return null;
    }
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) Organizacao(com.tomasio.projects.trainning.model.Organizacao) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Organizacao

use of com.tomasio.projects.trainning.model.Organizacao 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 18 with Organizacao

use of com.tomasio.projects.trainning.model.Organizacao 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 19 with Organizacao

use of com.tomasio.projects.trainning.model.Organizacao 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 20 with Organizacao

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

the class PlanningServiceSimpleImpl method arrangeStripItemPlanejamento.

private List<StripItemPlanejamentoDTO> arrangeStripItemPlanejamento(ItemPlanejamentoDTO itemPlanejamento, Map<String, TreinamentoSolicitadoDTO> treinamentosSolicitadosMap, Map<String, Map<String, AnaliseDTO>> analisesMap, Map<String, TreinamentoPlanejadoDTO> treinamentosPlanejadosMap, Long organizacaoId) {
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    List<StripItemPlanejamentoDTO> result = new ArrayList<StripItemPlanejamentoDTO>();
    Set<String> organizacoesIds = new HashSet<String>();
    if (!(organizacaoId == null)) {
        organizacoesIds.add(organizacaoId.toString());
    } else {
        organizacoesIds.addAll(treinamentosSolicitadosMap.keySet());
        organizacoesIds.addAll(analisesMap.keySet());
        organizacoesIds.addAll(treinamentosPlanejadosMap.keySet());
    }
    boolean setCompleto;
    String[] organizacoesIdsStringArray;
    Long[] organizacoesIdsLongArray;
    List<Organizacao> organizacoes = new ArrayList<Organizacao>();
    do {
        setCompleto = true;
        organizacoesIdsStringArray = organizacoesIds.toArray(new String[organizacoesIds.size()]);
        organizacoesIdsLongArray = new Long[organizacoesIdsStringArray.length];
        for (int i = 0; i < organizacoesIdsStringArray.length; i++) {
            organizacoesIdsLongArray[i] = Long.valueOf(organizacoesIdsStringArray[i]);
        }
        try {
            organizacoes = organizacaoDAO.findAll(organizacoesIdsLongArray);
        } catch (DAOException ex) {
            Logger.getLogger(PlanningServiceSimpleImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (organizacaoId == null) {
            // Adicionar os pais
            for (Organizacao organizacao : organizacoes) {
                List<Organizacao> parentList = organizacao.getParentList();
                for (Organizacao parent : parentList) {
                    organizacoesIds.add(parent.getId().toString());
                }
            // organizacao.getSigla();
            // if (organizacao instanceof Unidade) {
            // Unidade orgAtual = (Unidade) organizacao;
            // Organizacao parent = orgAtual.getParent();
            // while ((!(parent == null))
            // && (parent instanceof Comando == false)
            // && organizacoesIds.contains(parent.getId().toString()) == false) {
            // orgAtual = (Unidade) parent;
            // parent = orgAtual.getParent();
            // organizacoesIds.add(orgAtual.getId().toString());
            // setCompleto = false;
            // }
            // }
            }
        }
    } while (!setCompleto);
    for (Organizacao organizacao : organizacoes) {
        StripItemPlanejamentoDTO newStrip = new StripItemPlanejamentoDTO();
        newStrip.setItemPlanejamento(itemPlanejamento);
        newStrip.setOrganizacao(organizacao.createDTO());
        newStrip.setTreinamentoSolicitado(treinamentosSolicitadosMap.get(organizacao.getId().toString()));
        newStrip.setAnalises(analisesMap.get(organizacao.getId().toString()));
        newStrip.setTreinamentoPlanejado(treinamentosPlanejadosMap.get(organizacao.getId().toString()));
        IndicadorDTO indicador = findIndicador(itemPlanejamento.getCurso().getId(), organizacao.getId());
        if (indicador.getUpdatedAt() != null) {
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            newStrip.setLastUpdateIndicador(df.format(indicador.getUpdatedAt().getTime()));
        }
        if (indicador != null) {
            newStrip.setIndicadorMinimo(indicador.getMinimo());
            newStrip.setIndicadorIdeal(indicador.getIdeal());
            newStrip.setIndicadorExistente(indicador.getExistente());
            int gapIdeal = indicador.getIdeal() - indicador.getExistente();
            // if (gapIdeal < 0) {
            // gapIdeal = 0;
            // }
            int gapMinimo = indicador.getMinimo() - indicador.getExistente();
            if (gapMinimo < 0) {
                gapMinimo = 0;
            }
            newStrip.setGapIdeal(gapIdeal);
            newStrip.setGapMinimo(gapMinimo);
        } else {
            newStrip.setGapIdeal(0);
            newStrip.setGapMinimo(0);
        }
        result.add(newStrip);
    }
    Collections.sort(result, new Comparator<StripItemPlanejamentoDTO>() {

        @Override
        public int compare(StripItemPlanejamentoDTO o1, StripItemPlanejamentoDTO o2) {
            return o1.getOrganizacao().getNome().compareTo(o2.getOrganizacao().getNome());
        }
    });
    return result;
}
Also used : ArrayList(java.util.ArrayList) DAOException(com.tomasio.projects.trainning.exception.DAOException) Organizacao(com.tomasio.projects.trainning.model.Organizacao) TreinamentoSolicitadoConsolidadoSortByOrganizacao(com.tomasio.projects.trainning.sorts.TreinamentoSolicitadoConsolidadoSortByOrganizacao) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet)

Aggregations

Organizacao (com.tomasio.projects.trainning.model.Organizacao)80 DAOException (com.tomasio.projects.trainning.exception.DAOException)77 Transactional (org.springframework.transaction.annotation.Transactional)45 CoreException (com.tomasio.projects.trainning.exeption.CoreException)41 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)35 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)19 Pessoa (com.tomasio.projects.trainning.model.Pessoa)19 PessoaDAO (com.tomasio.projects.trainning.dao.PessoaDAO)17 HibernatePessoaDAO (com.tomasio.projects.trainning.dao.HibernatePessoaDAO)15 ImportTurmasImplEfetivasFromTabelao (com.tomasio.projects.trainning.migration.ImportTurmasImplEfetivasFromTabelao)10 ResultSet (java.sql.ResultSet)10 SQLException (java.sql.SQLException)10 Statement (java.sql.Statement)10 HibernateOrganizacaoDAO (com.tomasio.projects.trainning.dao.HibernateOrganizacaoDAO)9 ArrayList (java.util.ArrayList)9 Date (java.sql.Date)8 NetworkUserDAO (com.tomasio.projects.trainning.dao.NetworkUserDAO)5 Session (org.hibernate.Session)5 MatriculaDAO (com.tomasio.projects.trainning.dao.MatriculaDAO)4 NetworkGroupDAO (com.tomasio.projects.trainning.dao.NetworkGroupDAO)4