use of org.collectiveone.modules.initiatives.dto.InitiativeTagDto 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.InitiativeTagDto in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method edit.
@Transactional
public PostResult edit(UUID initiativeId, UUID userId, NewInitiativeDto initiativeDto) {
Initiative initiative = initiativeRepository.findById(initiativeId);
InitiativeMeta initiativeMeta = initiative.getMeta();
String oldName = initiativeMeta.getName();
String oldDriver = initiativeMeta.getDriver();
initiativeMeta.setName(initiativeDto.getName());
initiativeMeta.setDriver(initiativeDto.getDriver());
initiativeMeta.setColor(initiativeDto.getColor());
initiativeMeta.setModelEnabled(initiativeDto.getModelEnabled());
if (initiativeDto.getVisibility() != null) {
initiativeMeta.setVisibility(InitiativeVisibility.valueOf(initiativeDto.getVisibility()));
}
/* remove and add all tags */
initiativeMeta.getTags().removeAll(initiativeMeta.getTags());
for (InitiativeTagDto tagDto : initiativeDto.getTags()) {
InitiativeTag tag = initiativeTagRepository.findById(UUID.fromString(tagDto.getId()));
initiativeMeta.getTags().add(tag);
}
/* update or remove image */
if (initiativeDto.getNewImageFileId() != null) {
if (!initiativeDto.getNewImageFileId().equals("REMOVE")) {
UUID imageFileId = initiativeDto.getNewImageFileId().equals("") ? null : UUID.fromString(initiativeDto.getNewImageFileId());
FileStored imageFile = fileStoredRepository.findById(imageFileId);
initiativeMeta.setImageFile(imageFile);
} else {
initiativeMeta.setImageFile(null);
}
}
initiativeMetaRepository.save(initiativeMeta);
if (!oldName.equals(initiativeDto.getName()) || !oldDriver.equals(initiativeDto.getDriver())) {
/* notify only if actually different */
activityService.initiativeEdited(initiative, appUserRepository.findByC1Id(userId), oldName, oldDriver);
}
return new PostResult("success", "initaitive updated", initiative.getId().toString());
}
use of org.collectiveone.modules.initiatives.dto.InitiativeTagDto in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeTag method toDto.
public InitiativeTagDto toDto() {
InitiativeTagDto dto = new InitiativeTagDto();
dto.setId(id.toString());
dto.setTagText(tagText);
dto.setDescription(description);
return dto;
}
Aggregations