Search in sources :

Example 1 with UsuarioForm

use of com.tomasio.projects.trainning.form.UsuarioForm in project trainning by fernandotomasio.

the class UsuariosController method editUsuario.

@RequestMapping("/edit")
public String editUsuario(Model model, @ModelAttribute("userOrganization") OrganizacaoDTO userOrganization, WebRequest request) {
    String usuarioId = request.getParameter("usuarioId");
    // buscar usuário pelo ID
    NetworkUserDTO dto = userService.findUser(usuarioId);
    // 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());
        }
    });
    UsuarioForm usuarioForm = new UsuarioForm();
    usuarioForm.setOp("EDIT");
    usuarioForm.setEmail(dto.getEmail());
    usuarioForm.setLogin(dto.getLogin());
    usuarioForm.setNome(dto.getNome());
    usuarioForm.setNomeGuerra(dto.getNomeGuerra());
    OrganizacaoDTO organizacao = organizationalService.findOrganizacaoBySigla(dto.getOrganizacao());
    usuarioForm.setOrganizacaoId(organizacao.getId());
    usuarioForm.setPosto(dto.getPosto());
    usuarioForm.setTelefone(dto.getTelefone());
    model.addAttribute(usuarioForm);
    model.addAttribute("organizacoes", initializeSelectableOrganizacoes(request, userOrganization));
    model.addAttribute("roles", roles);
    model.addAttribute("rolesAssigned", rolesAssigned);
    return "usuarios/form";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) NetworkUserDTO(com.tomasio.projects.trainning.dto.NetworkUserDTO) UsuarioForm(com.tomasio.projects.trainning.form.UsuarioForm) ArrayList(java.util.ArrayList) OrganizacaoDTO(com.tomasio.projects.trainning.dto.OrganizacaoDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UsuarioForm

use of com.tomasio.projects.trainning.form.UsuarioForm in project trainning by fernandotomasio.

the class UsuariosController method newUsuário.

@RequestMapping("/new")
public String newUsuário(Model model, @ModelAttribute("userOrganization") OrganizacaoDTO userOrganization, WebRequest request) {
    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);
    UsuarioForm usuarioForm = new UsuarioForm();
    usuarioForm.setOp("NEW");
    model.addAttribute(usuarioForm);
    model.addAttribute("organizacoes", initializeSelectableOrganizacoes(request, userOrganization));
    return "usuarios/form";
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) UsuarioForm(com.tomasio.projects.trainning.form.UsuarioForm) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)2 UsuarioForm (com.tomasio.projects.trainning.form.UsuarioForm)2 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 NetworkUserDTO (com.tomasio.projects.trainning.dto.NetworkUserDTO)1 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)1