use of org.collectiveone.common.dto.GetResult in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method getView.
@Transactional
public GetResult<ModelViewDto> getView(UUID viewId, UUID requestById, Integer level, UUID requestByUserId) {
ModelView view = modelViewRepository.findById(viewId);
ModelViewDto viewDto = view.toDto();
viewDto = addViewSubElements(viewDto, view.getId(), level, requestByUserId);
return new GetResult<ModelViewDto>("success", "view retrieved", viewDto);
}
use of org.collectiveone.common.dto.GetResult in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method getActivityResultUnderSection.
@Transactional
public GetResult<Page<ActivityDto>> getActivityResultUnderSection(UUID sectionId, PageRequest page, Boolean onlyMessages) {
Page<Activity> activities = getActivityUnderSection(sectionId, page, onlyMessages);
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.common.dto.GetResult 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.common.dto.GetResult in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method create.
@Transactional
private GetResult<Initiative> create(UUID c1Id, NewInitiativeDto initiativeDto) {
AppUser creator = appUserRepository.findByC1Id(c1Id);
if (creator == null) {
return new GetResult<Initiative>("error", "creator not found", null);
}
Initiative initiative = new Initiative();
/* Basic properties*/
initiative.setCreator(creator);
initiative.setStatus(InitiativeStatus.ENABLED);
InitiativeMeta meta = new InitiativeMeta();
meta.setName(initiativeDto.getName());
meta.setDriver(initiativeDto.getDriver());
meta.setCreationDate(new Timestamp(System.currentTimeMillis()));
meta.setModelEnabled(true);
if (!initiativeDto.getAsSubinitiative()) {
meta.setColor("#009ee3");
} else {
Initiative parent = initiativeRepository.findById(UUID.fromString(initiativeDto.getParentInitiativeId()));
meta.setColor(parent.getMeta().getColor());
}
meta = initiativeMetaRepository.save(meta);
initiative.setMeta(meta);
initiative = initiativeRepository.save(initiative);
/* Create the governace object of this initiative */
Governance governance = governanceService.create(initiative);
initiative.setGovernance(governance);
initiative = initiativeRepository.save(initiative);
activityService.newInitiativeCreated(initiative, initiative.getCreator());
return new GetResult<Initiative>("success", "initiative created", initiative);
}
use of org.collectiveone.common.dto.GetResult 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);
}
Aggregations