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