Search in sources :

Example 21 with NetworkUserDTO

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

the class UsuariosController method saveUsuario.

@RequestMapping("/save")
public String saveUsuario(Model model, @ModelAttribute("userOrganization") OrganizacaoDTO userOrganization, @Valid UsuarioForm usuarioForm, BindingResult bindingResult, WebRequest request) {
    String[] permissions = request.getParameterValues("permissions");
    if (permissions != null) {
        for (String permission : permissions) {
            System.out.println("permission: " + permission);
        }
    }
    if (usuarioForm.getSourceButton() != null && usuarioForm.getSourceButton().equals("resetPassword")) {
        userService.updateUserPassword(generatePassword(), usuarioForm.getLogin());
        NetworkGroupDTO[] groups = userService.findAllRoleGroups();
        // jogo no ArrayList para trabalhar
        List<NetworkGroupDTO> roles = new ArrayList();
        roles.addAll(Arrays.asList(groups));
        // ordenar a lista de roles
        Collections.sort(roles, new Comparator<NetworkGroupDTO>() {

            @Override
            public int compare(NetworkGroupDTO o1, NetworkGroupDTO o2) {
                return o1.getDescricao().compareTo(o2.getDescricao());
            }
        });
        model.addAttribute("roles", roles);
        // buscar as roles do marcadas
        if (permissions != null) {
            List<String> rolesAssigned = new ArrayList<>();
            for (NetworkGroupDTO group : groups) {
                for (String permission : permissions) {
                    if (permission.equals(group.getNome())) {
                        rolesAssigned.add(group.getNome());
                    }
                }
            }
            model.addAttribute("rolesAssigned", rolesAssigned);
        }
        model.addAttribute("organizacoes", organizationalService.findAllOrganizacoes());
        model.addAttribute("successMessage", "Senha reinicializada com sucesso!<br/> Um email automático foi enviado para o usuário");
        return "usuarios/form";
    }
    if (bindingResult.hasErrors()) {
        model.addAttribute("organizacoes", initializeSelectableOrganizacoes(request, userOrganization));
        NetworkGroupDTO[] groups = userService.findAllRoleGroups();
        // jogo no ArrayList para trabalhar
        List<NetworkGroupDTO> roles = new ArrayList();
        roles.addAll(Arrays.asList(groups));
        // ordenar a lista de roles
        Collections.sort(roles, new Comparator<NetworkGroupDTO>() {

            @Override
            public int compare(NetworkGroupDTO o1, NetworkGroupDTO o2) {
                return o1.getDescricao().compareTo(o2.getDescricao());
            }
        });
        model.addAttribute("roles", roles);
        // buscar as roles do marcadas
        if (permissions != null) {
            List<String> rolesAssigned = new ArrayList<>();
            for (NetworkGroupDTO group : groups) {
                for (String permission : permissions) {
                    if (permission.equals(group.getNome())) {
                        rolesAssigned.add(group.getNome());
                    }
                }
            }
            model.addAttribute("rolesAssigned", rolesAssigned);
        }
        return "usuarios/form";
    }
    NetworkUserDTO dto;
    if (usuarioForm.getOp().equals("NEW")) {
        dto = new NetworkUserDTO();
        dto.setPassword(generatePassword());
    } else {
        dto = userService.findUser(usuarioForm.getLogin());
    }
    if (usuarioForm.getOrganizacaoId() > 0) {
        OrganizacaoDTO organizacao = organizationalService.findOrganizacao(usuarioForm.getOrganizacaoId());
        dto.setOrganizacao(organizacao.getSigla());
    }
    // Inserção do campo SENHA como solução do problema do PROXY
    if (usuarioForm.getPassword() != null && !usuarioForm.getPassword().equals("")) {
        dto.setPassword(usuarioForm.getPassword());
    }
    dto.setLogin(usuarioForm.getLogin());
    dto.setNome(usuarioForm.getNome());
    dto.setNomeGuerra(usuarioForm.getNomeGuerra());
    dto.setPosto(usuarioForm.getPosto());
    dto.setTarjeta(usuarioForm.getPosto() + " " + usuarioForm.getNomeGuerra());
    dto.setTelefone(usuarioForm.getTelefone());
    dto.setEmail(usuarioForm.getEmail());
    if (usuarioForm.getOp().equals("NEW")) {
        try {
            userService.createUser(dto, permissions);
            // Inserção do campo SENHA como solução do problema do PROXY
            if (usuarioForm.getPassword() != null && !usuarioForm.getPassword().equals("")) {
                model.addAttribute("successMessage", "Usuário criado com sucesso!");
                model.addAttribute("errorMessage", "Faz-se necessário contato com o usuário para informar a senha definida!");
            } else {
                model.addAttribute("successMessage", "Usuário criado com sucesso!<br/> Um email automático foi enviado para o usuário");
            }
        } catch (CoreException e) {
            model.addAttribute("errorMessage", e.getMessage());
            model.addAttribute("usuarios", userService.findAllUsers());
            return "usuarios";
        }
    } else {
        userService.updateUser(dto, permissions);
        if (usuarioForm.getPassword() != null && !usuarioForm.getPassword().equals("")) {
            model.addAttribute("successMessage", "Usuário atualizado com sucesso!");
            model.addAttribute("errorMessage", "Faz-se necessário contato com o usuário para informar a nova senha definida!");
        } else {
            model.addAttribute("successMessage", "Usuário atualizado com sucesso!");
        }
    }
    // buscar usuário pelo login
    dto = userService.findUser(usuarioForm.getLogin());
    // buscar as roles do usuário
    NetworkGroupDTO[] groups = userService.findAllRoleGroups();
    List<String> rolesAssigned = new ArrayList<>();
    for (NetworkGroupDTO group : groups) {
        if (group.getMembers().contains(dto.getId())) {
            rolesAssigned.add(group.getNome());
        }
    }
    // jogo no ArrayList para trabalhar
    List<NetworkGroupDTO> roles = new ArrayList();
    roles.addAll(Arrays.asList(groups));
    // ordenar a lista de roles
    Collections.sort(roles, new Comparator<NetworkGroupDTO>() {

        @Override
        public int compare(NetworkGroupDTO o1, NetworkGroupDTO o2) {
            return o1.getDescricao().compareTo(o2.getDescricao());
        }
    });
    model.addAttribute("roles", roles);
    model.addAttribute("rolesAssigned", rolesAssigned);
    model.addAttribute("usuario", dto);
    return "usuarios/detail";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) ArrayList(java.util.ArrayList) OrganizacaoDTO(com.tomasio.projects.trainning.dto.OrganizacaoDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with NetworkUserDTO

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

the class UsuariosController method showPhoto.

@RequestMapping("/photo")
public void showPhoto(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ServletContext servletContext = request.getServletContext();
    response.setContentType("image/jpeg");
    response.addHeader("Content-Disposition", "attachment; filename=" + "photo.jpg");
    OutputStream responseOutputStream = response.getOutputStream();
    String usuarioId = request.getParameter("uid");
    NetworkUserDTO user = null;
    byte[] photo = null;
    if (usuarioId != null) {
        user = userService.findUser(usuarioId);
    }
    if (user != null) {
        photo = user.getPhoto();
    }
    if (photo == null) {
        InputStream in = servletContext.getResourceAsStream("/WEB-INF/assets/avatars/avatar2.png");
        photo = IOUtils.toByteArray(in);
    }
    responseOutputStream.write(photo);
}
Also used : NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ServletContext(javax.servlet.ServletContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with NetworkUserDTO

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

the class LDAPNetworkUserDAO method search.

@Override
public List<NetworkUserDTO> search(String uid) throws DAOException {
    OrFilter filter = new OrFilter();
    filter.or(new LikeFilter("uid", uid));
    // AndFilter filter = new AndFilter();
    // filter.and(new EqualsFilter("objectclass", "inetOrgPerson"));
    // filter.and(new LikeFilter("uid", uid));
    System.out.println(filter.toString());
    @SuppressWarnings({ "unchecked" }) List<NetworkUserDTO> users = ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.toString(), new UserAttributesMapper());
    return users;
}
Also used : LikeFilter(org.springframework.ldap.filter.LikeFilter) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) OrFilter(org.springframework.ldap.filter.OrFilter)

Example 24 with NetworkUserDTO

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

the class UserServiceSimpleImpl method searchUsers.

@Override
public NetworkUserDTO[] searchUsers(String term) {
    NetworkUserDAO dao = factory.getNetworkUserDAO();
    NetworkUserDTO[] usersArray = null;
    try {
        List<NetworkUserDTO> users = dao.search(term);
        if (users != null) {
            usersArray = new NetworkUserDTO[users.size()];
            users.toArray(usersArray);
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
    return usersArray;
}
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 25 with NetworkUserDTO

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

the class UserServiceSimpleImpl method updateUserPassword.

@Override
public void updateUserPassword(String password, String uid) {
    NetworkUserDAO dao = factory.getNetworkUserDAO();
    try {
        NetworkUserDTO user = dao.find(uid);
        user.setPassword(password);
        dao.update(user);
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
}
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)

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