use of org.collectiveone.modules.initiatives.dto.InitiativeMembersDto in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method getMembersAndSubmembers.
public InitiativeMembersDto getMembersAndSubmembers(UUID initiativeId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
InitiativeMembersDto initiativeMembers = new InitiativeMembersDto();
initiativeMembers.setInitiativeId(initiative.getId().toString());
initiativeMembers.setInitiativeName(initiative.getMeta().getName());
List<TokenType> tokenTypes = tokenService.getTokenTypesHeldBy(initiative.getId());
/* add members of this initiative */
for (Member member : initiative.getMembers()) {
MemberDto memberDto = new MemberDto();
memberDto.setId(member.getId().toString());
memberDto.setUser(member.getUser().toDtoLight());
/* governance related data */
DecisionMaker decisionMaker = governanceService.getDecisionMaker(initiative.getGovernance().getId(), member.getUser().getC1Id());
if (decisionMaker != null) {
memberDto.setRole(decisionMaker.getRole().toString());
} else {
memberDto.setRole(DecisionMakerRole.MEMBER.toString());
}
/* assets related data */
for (TokenType token : tokenTypes) {
memberDto.getReceivedAssets().add(tokenService.getTokensOfHolderDtoLight(token.getId(), member.getUser().getC1Id()));
}
initiativeMembers.getMembers().add(memberDto);
}
/* add the members of all sub-initiatives too */
for (InitiativeDto subInitiative : getSubinitiativesTree(initiative.getId(), null)) {
/* recursively call with subinitiatives */
initiativeMembers.getSubinitiativesMembers().add(getMembersAndSubmembers(UUID.fromString(subInitiative.getId())));
}
return initiativeMembers;
}
Aggregations