Search in sources :

Example 6 with InitiativeDto

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

the class InitiativeService method getSubinitiativesTree.

@Transactional
public List<InitiativeDto> getSubinitiativesTree(UUID initiativeId, UUID userId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    List<Initiative> subIniatiatives = initiativeRepository.findInitiativesWithRelationship(initiative.getId(), InitiativeRelationshipType.IS_ATTACHED_SUB);
    List<InitiativeDto> subinitiativeDtos = new ArrayList<InitiativeDto>();
    for (Initiative subinitiative : subIniatiatives) {
        if (subinitiative.getStatus() == InitiativeStatus.ENABLED) {
            InitiativeDto subinitiativeDto = subinitiative.toDto();
            if (userId != null) {
                subinitiativeDto.setLoggedMembership(getMemberAndInParent(subinitiative.getId(), userId));
            }
            /* recursively call this for its own sub-initiatives */
            List<InitiativeDto> subsubIniatiativesDto = getSubinitiativesTree(subinitiative.getId(), userId);
            subinitiativeDto.setSubInitiatives(subsubIniatiativesDto);
            subinitiativeDtos.add(subinitiativeDto);
        }
    }
    return subinitiativeDtos;
}
Also used : NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) ArrayList(java.util.ArrayList) Transactional(javax.transaction.Transactional)

Example 7 with InitiativeDto

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

the class InitiativesController method getInitiative.

@RequestMapping(path = "/initiative/{initiativeId}", method = RequestMethod.GET)
public GetResult<InitiativeDto> getInitiative(@PathVariable("initiativeId") String initiativeIdStr, @RequestParam(defaultValue = "false") boolean addAssetsIds, @RequestParam(defaultValue = "false") boolean addSubinitiatives, @RequestParam(defaultValue = "false") boolean addParents, @RequestParam(defaultValue = "false") boolean addMembers, @RequestParam(defaultValue = "false") boolean addLoggedUser) {
    UUID initiativeId = UUID.fromString(initiativeIdStr);
    if (!initiativeService.canAccess(initiativeId, getLoggedUserId())) {
        return new GetResult<InitiativeDto>("error", "access denied", null);
    }
    InitiativeDto initiativeDto = null;
    initiativeDto = initiativeService.getLight(initiativeId);
    if (addAssetsIds) {
        initiativeDto.setAssets(initiativeService.getInitiativeAssetsDtoLight(initiativeId));
    }
    if (addSubinitiatives) {
        initiativeDto.setSubInitiatives(initiativeService.getSubinitiativesTree(initiativeId, null));
    }
    if (addParents) {
        initiativeDto.setParents(initiativeService.getParentInitiativesDtos(initiativeId));
    }
    if (addMembers) {
        initiativeDto.setInitiativeMembers(initiativeService.getMembersAndSubmembers(initiativeId));
    }
    if (addLoggedUser) {
        initiativeDto.setLoggedMembership(initiativeService.getMemberAndInParent(initiativeId, getLoggedUserId()));
    }
    return new GetResult<InitiativeDto>("success", "initiative retrieved", initiativeDto);
}
Also used : GetResult(org.collectiveone.common.dto.GetResult) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) UUID(java.util.UUID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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