I have these three dto classes :
public class OrganismeDTO {
private Long organismeId;
private String libelle;
private List<RoleDTO> rolesDTO;
}
public class RoleDTO {
private String lib;
private Long roleId;
private List<ProfilDTO> profilsDTO;
}
public class UtilisateurRoleDto {
private String organismeLib;
private String roleLib;
}
And in my DAO I have a function that will return a list of UtilisateurRoleDto.
What I want, is to create a list of OrganismeDTOfrom UtilisateurRoleDto list (Which I can get from my DAO), so for example, if I have a list of UtilisateurRoleDto as following:
"Organisme 1", "Role 1"
"Organisme 1", "Role 2"
"Organisme 2", "Role 1"
"Organisme 2", "Role 3"
"Organisme 3", "Role 3"
I want a list of OrganismeDTO in result as following (where each OrganismeDTO has a list of RoleDTO) :
"Organisme 1" : ["Role 1", "Role 2"]
"Organisme 2" : ["Role 1", "Role 3"]
"Organisme 3" : ["Role 3"]
How can I implement this using Java 8 streams?
Update:
When I construct the RoleDTO I need to inject RoleDTO.profilsDTO by a list I get from a function that takes OrganismeDTO.roleId and returns List<ProfilDTO>.
RoleDTOandroleLibsimilar?RoleDTO.libis the same asUtilisateurRoleDto.roleLib