Search in sources :

Example 1 with InitiativeDto

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

the class InitiativeService method getOfUser.

@Transactional
public GetResult<List<InitiativeDto>> getOfUser(UUID userC1Id) {
    /* return all super-initiatives (initiatives without parent initiatives) 
		 * and include all sub-initiativespf each of them */
    AppUser user = appUserRepository.findByC1Id(userC1Id);
    /* get all initiatives in which the user is a contributor */
    List<Initiative> superInitiatives = getSuperInitiativesOfMember(user.getC1Id());
    List<InitiativeDto> initiativesDtos = new ArrayList<InitiativeDto>();
    for (Initiative initiative : superInitiatives) {
        if (initiative.getStatus() == InitiativeStatus.ENABLED) {
            InitiativeDto dto = initiative.toDto();
            dto.setLoggedMembership(getMemberAndInParent(initiative.getId(), user.getC1Id()));
            /* look for the full sub-initiative tree of each super initiative */
            List<InitiativeDto> subInitiatives = getSubinitiativesTree(initiative.getId(), user.getC1Id());
            dto.setSubInitiatives(subInitiatives);
            initiativesDtos.add(dto);
        }
    }
    return new GetResult<List<InitiativeDto>>("success", "initiatives retrieved", initiativesDtos);
}
Also used : NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 2 with InitiativeDto

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

the class InitiativeService method searchBy.

@Transactional
public GetResult<List<InitiativeDto>> searchBy(SearchFiltersDto searchFilters) {
    List<UUID> tagIds = new ArrayList<UUID>();
    for (InitiativeTagDto tag : searchFilters.getTags()) {
        tagIds.add(UUID.fromString(tag.getId()));
    }
    List<Initiative> initiatives = null;
    if (tagIds.size() > 0) {
        initiatives = initiativeRepository.searchByTagIdAndVisibility(tagIds, InitiativeVisibility.PUBLIC);
    } else {
        initiatives = initiativeRepository.findByVisibility(InitiativeVisibility.PUBLIC);
    }
    List<Initiative> superInitiatives = onlySuperInitiatives(initiatives);
    List<InitiativeDto> initiativesDtos = new ArrayList<InitiativeDto>();
    for (Initiative initiative : superInitiatives) {
        initiativesDtos.add(initiative.toDto());
    }
    return new GetResult<List<InitiativeDto>>("succes", "initiatives returned", initiativesDtos);
}
Also used : InitiativeTagDto(org.collectiveone.modules.initiatives.dto.InitiativeTagDto) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Transactional(javax.transaction.Transactional)

Example 3 with InitiativeDto

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

the class Initiative method toDto.

public InitiativeDto toDto() {
    InitiativeDto dto = new InitiativeDto();
    dto.setId(id.toString());
    dto.setCreator(creator.toDtoLight());
    dto.setStatus(status.toString());
    dto.setMeta(meta.toDto());
    if (tokenTypes != null) {
        for (TokenType tokenType : tokenTypes) {
            dto.getOwnAssetsIds().add(tokenType.getId().toString());
        }
    }
    return dto;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto)

Example 4 with InitiativeDto

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

the class InitiativeService method getActivityUnderInitiative.

@Transactional
public GetResult<Page<ActivityDto>> getActivityUnderInitiative(UUID initiativeId, PageRequest page, Boolean onlyMessages) {
    List<InitiativeDto> subinitiativesTree = getSubinitiativesTree(initiativeId, null);
    List<UUID> allInitiativesIds = new ArrayList<UUID>();
    allInitiativesIds.add(initiativeId);
    allInitiativesIds.addAll(extractAllIdsFromInitiativesTree(subinitiativesTree, new ArrayList<UUID>()));
    Page<Activity> activities = null;
    if (!onlyMessages) {
        activities = activityRepository.findOfInitiatives(allInitiativesIds, page);
    } else {
        activities = activityRepository.findOfInitiativesAndType(allInitiativesIds, ActivityType.MESSAGE_POSTED, page);
    }
    List<ActivityDto> activityDtos = new ArrayList<ActivityDto>();
    for (Activity activity : activities.getContent()) {
        activityDtos.add(activity.toDto());
    }
    Page<ActivityDto> dtosPage = new PageImpl<ActivityDto>(activityDtos, page, activities.getNumberOfElements());
    return new GetResult<Page<ActivityDto>>("succes", "actvity returned", dtosPage);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) Activity(org.collectiveone.modules.activity.Activity) UUID(java.util.UUID) ActivityDto(org.collectiveone.modules.activity.dto.ActivityDto) Transactional(javax.transaction.Transactional)

Example 5 with InitiativeDto

use of org.collectiveone.modules.initiatives.dto.InitiativeDto 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)

Aggregations

InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)7 NewInitiativeDto (org.collectiveone.modules.initiatives.dto.NewInitiativeDto)6 ArrayList (java.util.ArrayList)4 Transactional (javax.transaction.Transactional)4 GetResult (org.collectiveone.common.dto.GetResult)4 UUID (java.util.UUID)3 TokenType (org.collectiveone.modules.tokens.TokenType)2 Activity (org.collectiveone.modules.activity.Activity)1 ActivityDto (org.collectiveone.modules.activity.dto.ActivityDto)1 DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)1 InitiativeMembersDto (org.collectiveone.modules.initiatives.dto.InitiativeMembersDto)1 InitiativeTagDto (org.collectiveone.modules.initiatives.dto.InitiativeTagDto)1 MemberDto (org.collectiveone.modules.initiatives.dto.MemberDto)1 AppUser (org.collectiveone.modules.users.AppUser)1 PageImpl (org.springframework.data.domain.PageImpl)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1