Search in sources :

Example 1 with MemberDto

use of org.collectiveone.modules.initiatives.dto.MemberDto 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;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) MemberDto(org.collectiveone.modules.initiatives.dto.MemberDto) InitiativeMembersDto(org.collectiveone.modules.initiatives.dto.InitiativeMembersDto) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker)

Example 2 with MemberDto

use of org.collectiveone.modules.initiatives.dto.MemberDto in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getMember.

@Transactional
public MemberDto getMember(UUID initiativeId, UUID userId) {
    if (userId == null) {
        return null;
    }
    /* check in this initiative */
    Initiative initiative = initiativeRepository.findById(initiativeId);
    Member member = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, userId);
    MemberDto memberDto = new MemberDto();
    if (member != null) {
        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());
        }
    } else {
        memberDto.setId("");
        memberDto.setUser(appUserRepository.findByC1Id(userId).toDtoLight());
        memberDto.setRole(DecisionMakerRole.ALIEN.toString());
    }
    return memberDto;
}
Also used : MemberDto(org.collectiveone.modules.initiatives.dto.MemberDto) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker) Transactional(javax.transaction.Transactional)

Aggregations

DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)2 MemberDto (org.collectiveone.modules.initiatives.dto.MemberDto)2 Transactional (javax.transaction.Transactional)1 InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)1 InitiativeMembersDto (org.collectiveone.modules.initiatives.dto.InitiativeMembersDto)1 NewInitiativeDto (org.collectiveone.modules.initiatives.dto.NewInitiativeDto)1 TokenType (org.collectiveone.modules.tokens.TokenType)1