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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations