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";
}
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";
}
Aggregations