Search in sources :

Example 26 with OrganizacaoDAO

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

the class ImportUsersFromCSV method execute.

@Override
public void execute() {
    OrganizacaoDAO organizacaoDAO = factory.getOrganizacaoDAO();
    NetworkUserDAO userDAO = factory.getNetworkUserDAO();
    String csvFile = "/com/tomasio/projects/trainning/migration/usuarios.csv";
    BufferedReader br = null;
    String line = "";
    String cvsSplitBy = ";";
    try {
        br = new BufferedReader(new FileReader(new ClassPathResource("usuarios.csv").getFile()));
        List<String> members = new ArrayList<String>();
        while ((line = br.readLine()) != null) {
            // use comma as separator
            String[] userData = line.split(cvsSplitBy);
            String posto = userData[0];
            String nome = userData[3];
            String sigla = userData[2];
            String nomeGuerra = userData[4];
            String email = userData[5];
            String telefone = userData[6];
            String login = userData[7];
            String senha = userData[8];
            Organizacao organizacao = organizacaoDAO.findBySigla(sigla);
            if (organizacao != null) {
                System.out.println(organizacao.getSigla());
            } else {
                System.out.println("ERRO : " + sigla);
                System.exit(0);
            }
            NetworkUserDTO user = new NetworkUserDTO();
            user.setEmail(email);
            user.setLogin(login);
            user.setPosto(posto);
            user.setOrganizacao(organizacao.getSigla());
            user.setTarjeta(posto + " " + nomeGuerra);
            user.setNomeGuerra(nomeGuerra);
            user.setPassword(senha);
            if (telefone == null || telefone.equals("")) {
                telefone = "9999-9999";
            }
            user.setTelefone(telefone);
            user.setNome(nome);
            if (userDAO.find(user.getLogin()) == null) {
                userDAO.create(user);
                System.out.println("criado usuário " + user.getLogin());
            } else {
                System.out.println("usuário já existe " + user.getLogin());
            }
            members.add("member: uid=" + user.getLogin() + ",ou=people,dc=decea,dc=intraer");
        }
        for (String member : members) {
            System.out.println(member);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DAOException ex) {
        Logger.getLogger(ImportUsersFromCSV.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    System.out.println("Done");
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO) ClassPathResource(org.springframework.core.io.ClassPathResource) DAOException(com.tomasio.projects.trainning.exception.DAOException) OrganizacaoDAO(com.tomasio.projects.trainning.dao.OrganizacaoDAO) Organizacao(com.tomasio.projects.trainning.model.Organizacao) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

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