Search in sources :

Example 1 with InitiativeTagDto

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);
}
Also used : InitiativeTagDto(org.collectiveone.modules.initiatives.dto.InitiativeTagDto) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Transactional(javax.transaction.Transactional)

Example 2 with InitiativeTagDto

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());
}
Also used : InitiativeTagDto(org.collectiveone.modules.initiatives.dto.InitiativeTagDto) PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) FileStored(org.collectiveone.modules.files.FileStored) Transactional(javax.transaction.Transactional)

Example 3 with InitiativeTagDto

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;
}
Also used : InitiativeTagDto(org.collectiveone.modules.initiatives.dto.InitiativeTagDto)

Aggregations

InitiativeTagDto (org.collectiveone.modules.initiatives.dto.InitiativeTagDto)3 UUID (java.util.UUID)2 Transactional (javax.transaction.Transactional)2 ArrayList (java.util.ArrayList)1 GetResult (org.collectiveone.common.dto.GetResult)1 PostResult (org.collectiveone.common.dto.PostResult)1 FileStored (org.collectiveone.modules.files.FileStored)1 InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)1 NewInitiativeDto (org.collectiveone.modules.initiatives.dto.NewInitiativeDto)1