Search in sources :

Example 1 with NetworkGroupDTO

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

the class UsuariosController method showIndex.

@RequestMapping({ "/", "/index", "" })
public String showIndex(Model model, @ModelAttribute("userOrganization") OrganizacaoDTO userOrganization, WebRequest request, UsuarioSearchForm searchForm) {
    // busca todos usuários
    NetworkUserDTO[] usuarios = userService.findAllUsers();
    // jogo no ArrayList para trabalhar
    List<NetworkUserDTO> usuariosFiltrado = new ArrayList();
    usuariosFiltrado.addAll(Arrays.asList(usuarios));
    if (request.isUserInRole("ROLE_ADMINISTRADOR")) {
        model.addAttribute("organizacoes", organizationalService.findAllOrganizacoes());
    } else {
        List<OrganizacaoDTO> organizacoesSubordinadas = new ArrayList();
        organizacoesSubordinadas.addAll(Arrays.asList(organizationalService.findAllOrganizacoesSubordinadas(userOrganization.getId())));
        organizacoesSubordinadas.add(userOrganization);
        List<String> siglasOrganizacoesSubordinadas = new ArrayList<>();
        for (OrganizacaoDTO organizacoesSubordinada : organizacoesSubordinadas) {
            siglasOrganizacoesSubordinadas.add(organizacoesSubordinada.getSigla());
        }
        for (Iterator<NetworkUserDTO> iterator = usuariosFiltrado.iterator(); iterator.hasNext(); ) {
            NetworkUserDTO user = iterator.next();
            if (siglasOrganizacoesSubordinadas.contains(user.getOrganizacao()) == false) {
                iterator.remove();
            }
        }
        model.addAttribute("organizacoes", organizacoesSubordinadas);
    }
    // verificar usuário filtrou por searchForm.getOrganizacaoId (OM)
    if (!(searchForm.getOrganizacao() == null || searchForm.getOrganizacao().equals(""))) {
        // corre os usuários verifcando se a OM igual a FILTRADA
        for (Iterator<NetworkUserDTO> iterator = usuariosFiltrado.iterator(); iterator.hasNext(); ) {
            NetworkUserDTO next = iterator.next();
            String usuarioOM = next.getOrganizacao();
            if (!(searchForm.getOrganizacao().equals(usuarioOM))) {
                // comparar se a OM é igual filtro passado
                iterator.remove();
            }
        }
    }
    // ordenar a lista de usuários
    Collections.sort(usuariosFiltrado, new Comparator<NetworkUserDTO>() {

        @Override
        public int compare(NetworkUserDTO o1, NetworkUserDTO o2) {
            return o1.getNome().compareTo(o2.getNome());
        }
    });
    Collections.sort(usuariosFiltrado, new Comparator<NetworkUserDTO>() {

        @Override
        public int compare(NetworkUserDTO o1, NetworkUserDTO o2) {
            return o1.getOrganizacao().compareTo(o2.getOrganizacao());
        }
    });
    // loop nos usuários para adicionar o perfil
    List usuariosFiltradoComPerfil = new ArrayList();
    for (NetworkUserDTO usuario : usuariosFiltrado) {
        // buscar as roles do usuário
        NetworkGroupDTO[] groups = userService.findAllRoleGroups();
        List<String> rolesAssigned = new ArrayList<>();
        for (NetworkGroupDTO group : groups) {
            if (group.getMembers().contains(usuario.getId())) {
                rolesAssigned.add(group.getDescricao());
            }
        }
        // ordenaçao das permissoes
        Collections.sort(rolesAssigned, new Comparator<String>() {

            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        Map item = new HashMap();
        item.put("nome", usuario.getNome());
        item.put("posto", usuario.getPosto());
        item.put("nomeGuerra", usuario.getNomeGuerra());
        item.put("email", usuario.getEmail());
        item.put("login", usuario.getLogin());
        item.put("organizacao", usuario.getOrganizacao());
        item.put("perfil", rolesAssigned);
        usuariosFiltradoComPerfil.add(item);
    }
    // envia para
    model.addAttribute("total", usuariosFiltradoComPerfil.size());
    model.addAttribute("usuarios", usuariosFiltradoComPerfil);
    model.addAttribute("searchForm", searchForm);
    // enviar para view a lista de OM subordinadas da OM do usuário
    OrganizacaoDTO[] organizacoesSubordinadas = organizationalService.findAllOrganizacoesSubordinadas(userOrganization.getId());
    List listaOrganizacoesSubordinadas = new ArrayList();
    for (OrganizacaoDTO organizacao : organizacoesSubordinadas) {
        String siglaOM = organizacao.getSigla();
        listaOrganizacoesSubordinadas.add(siglaOM);
    }
    model.addAttribute("organizacoesSubordinadas", listaOrganizacoesSubordinadas);
    return "usuarios";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) ArrayList(java.util.ArrayList) List(java.util.List) OrganizacaoDTO(com.tomasio.projects.trainning.dto.OrganizacaoDTO) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NetworkGroupDTO

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

the class GruposController method saveGrupo.

@RequestMapping("/save")
public String saveGrupo(Model model, @Valid GrupoForm grupoForm, BindingResult bindingResult, WebRequest request) {
    NetworkGroupDTO dto = new NetworkGroupDTO();
    if (bindingResult.hasErrors()) {
        return "grupos/form";
    }
    dto.setDescricao(grupoForm.getDescricao());
    dto.setNome(grupoForm.getNome());
    dto.setId(grupoForm.getId());
    if (dto.getId() == null || dto.getId().equals("")) {
        try {
            userService.createRoleGroup(dto);
            model.addAttribute("successMessage", "Grupo criado com sucesso!");
        } catch (CoreException e) {
            model.addAttribute("errorMessage", e.getMessage());
            model.addAttribute("grupos", userService.findAllRoleGroups());
            return "grupos";
        }
    } else {
        try {
            userService.updateGroup(dto);
            model.addAttribute("successMessage", "Grupo salvo com sucesso!");
        } catch (CoreException e) {
            model.addAttribute("errorMessage", e.getMessage());
            model.addAttribute("grupos", userService.findAllRoleGroups());
            return "grupos";
        }
    }
    dto = userService.findRoleGroup(grupoForm.getId());
    model.addAttribute("grupo", dto);
    return "grupos";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with NetworkGroupDTO

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

the class GruposController method showDetails.

@RequestMapping("/detail")
public String showDetails(Model model, WebRequest request) {
    String grupoId = request.getParameter("grupoId");
    NetworkGroupDTO grupo = userService.findRoleGroup(grupoId);
    model.addAttribute("grupo", grupo);
    return "grupos/detail";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with NetworkGroupDTO

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

the class SettingsController method savePassword.

@RequestMapping("/save_password")
public String savePassword(Model model, @Valid PasswordForm passwordForm, BindingResult bindingResult, WebRequest request) {
    if (bindingResult.hasErrors()) {
        return "settings/form_password";
    }
    final InetOrgPerson user = (InetOrgPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String userLogin = user.getUid();
    NetworkUserDTO usuario = userService.findUser(userLogin);
    usuario.setPassword(passwordForm.getPassword());
    userService.updateUser(usuario);
    // buscar as roles do usuário
    NetworkGroupDTO[] groups = userService.findAllRoleGroups();
    List<String> rolesAssigned = new ArrayList<>();
    for (NetworkGroupDTO group : groups) {
        if (group.getMembers().contains(usuario.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", usuario);
    return "settings";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with NetworkGroupDTO

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

the class UserServiceSimpleImpl method findRoleGroup.

@Override
public NetworkGroupDTO findRoleGroup(String id) {
    NetworkGroupDAO dao = factory.getNetworkGroupDAO();
    NetworkGroupDTO group = null;
    try {
        group = dao.findRole(id);
    } catch (DAOException ex) {
        throw new CoreException("Erro de acesso ao serviço de diretórios: " + ex.getMessage());
    }
    return group;
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) NetworkGroupDAO(com.tomasio.projects.trainning.dao.NetworkGroupDAO)

Aggregations

NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)24 DAOException (com.tomasio.projects.trainning.exception.DAOException)11 CoreException (com.tomasio.projects.trainning.exeption.CoreException)11 NetworkGroupDAO (com.tomasio.projects.trainning.dao.NetworkGroupDAO)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 NetworkUserDTO (com.tomasio.projects.trainning.dto.NetworkUserDTO)9 ArrayList (java.util.ArrayList)7 NetworkUserDAO (com.tomasio.projects.trainning.dao.NetworkUserDAO)5 OrganizacaoDAO (com.tomasio.projects.trainning.dao.OrganizacaoDAO)4 Organizacao (com.tomasio.projects.trainning.model.Organizacao)4 DistinguishedName (org.springframework.ldap.core.DistinguishedName)4 Transactional (org.springframework.transaction.annotation.Transactional)4 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)3 UsuarioForm (com.tomasio.projects.trainning.form.UsuarioForm)2 Name (javax.naming.Name)2 AuthenticationException (org.springframework.ldap.AuthenticationException)2 InetOrgPerson (org.springframework.security.ldap.userdetails.InetOrgPerson)2 DAOFactory (com.tomasio.projects.trainning.dao.DAOFactory)1 GrupoForm (com.tomasio.projects.trainning.form.GrupoForm)1 HashMap (java.util.HashMap)1