Search in sources :

Example 26 with NetworkUserDTO

use of com.tomasio.projects.trainning.dto.NetworkUserDTO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method findUser.

@Override
public NetworkUserDTO findUser(String uid) {
    NetworkUserDAO dao = factory.getNetworkUserDAO();
    NetworkUserDTO user = null;
    try {
        user = dao.find(uid);
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
    return user;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkUserDAO(com.tomasio.projects.trainning.dao.NetworkUserDAO)

Example 27 with NetworkUserDTO

use of com.tomasio.projects.trainning.dto.NetworkUserDTO in project trainning by fernandotomasio.

the class UserServiceSimpleImpl method updateUser.

@Override
@Transactional(readOnly = true)
public void updateUser(NetworkUserDTO user, String[] roles) {
    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);
            }
        }
        // REMOVER DE TODAS AS ROLES
        List<NetworkGroupDTO> roleGroups = groupDAO.findAllRoles();
        for (NetworkGroupDTO roleGroup : roleGroups) {
            NetworkGroupDTO r = groupDAO.findRole(roleGroup.getNome());
            r.getMembers().remove(oldUser.getId());
            groupDAO.update(r);
        }
        // ADICIONAR NOVAS ROLES
        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) 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 28 with NetworkUserDTO

use of com.tomasio.projects.trainning.dto.NetworkUserDTO in project trainning by fernandotomasio.

the class UsersMailAdvice method updateUserPasswordMethodInterceptor.

@Around("updateUserPassword()")
public Object updateUserPasswordMethodInterceptor(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    String uid = (String) args[1];
    String senha = (String) args[0];
    NetworkUserDTO user = userService.findUser(uid);
    String to = user.getEmail();
    String subject = "Sua senha SGC foi alterada, " + user.getNome();
    String text = "Bom dia, Sr. usuário,\n" + "Informo a Vsa. os dados para acesso ao Sistema de Gerenciamento da Capacitação:\n\n" + "Login: " + user.getLogin() + "\n" + "Senha: " + senha + "\n" + "Atenção, é altamente recomendável atualizar o seu navegador.\n" + "Por favor, altere sua senha após o primeiro acesso.\n\n" + "Em caso de dúvidas entre em contato com o setor de capacitação de sua OM. " + "----------------------------------------------------\n" + "Esse e-mail foi enviado de forma automática para " + to + ", NÃO RESPONDA ESTE E-MAIL.\n" + "Este é um serviço prestado pelo SGC - Sistema de Gerenciamento do Capacitação.\n";
    systemService.sendMail(to, subject, text);
    return joinPoint.proceed();
}
Also used : NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) Around(org.aspectj.lang.annotation.Around)

Example 29 with NetworkUserDTO

use of com.tomasio.projects.trainning.dto.NetworkUserDTO 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

NetworkUserDTO (com.tomasio.projects.trainning.dto.NetworkUserDTO)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 DAOException (com.tomasio.projects.trainning.exception.DAOException)10 ArrayList (java.util.ArrayList)10 NetworkUserDAO (com.tomasio.projects.trainning.dao.NetworkUserDAO)9 NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)9 CoreException (com.tomasio.projects.trainning.exeption.CoreException)9 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)4 NetworkGroupDAO (com.tomasio.projects.trainning.dao.NetworkGroupDAO)3 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)3 CancelamentoMatriculaDTO (com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO)3 MatriculaDTO (com.tomasio.projects.trainning.dto.MatriculaDTO)3 NotificacaoMatriculaDTO (com.tomasio.projects.trainning.dto.NotificacaoMatriculaDTO)3 PreMatriculaDTO (com.tomasio.projects.trainning.dto.PreMatriculaDTO)3 Organizacao (com.tomasio.projects.trainning.model.Organizacao)3 ApresentacaoDTO (com.tomasio.projects.trainning.dto.ApresentacaoDTO)2 CertificadoConclusaoDTO (com.tomasio.projects.trainning.dto.CertificadoConclusaoDTO)2 ConclusaoDTO (com.tomasio.projects.trainning.dto.ConclusaoDTO)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2