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