Search in sources :

Example 6 with GetResult

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);
}
Also used : ModelViewDto(org.collectiveone.modules.model.dto.ModelViewDto) GetResult(org.collectiveone.common.dto.GetResult) Transactional(javax.transaction.Transactional)

Example 7 with GetResult

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);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) Activity(org.collectiveone.modules.activity.Activity) ActivityDto(org.collectiveone.modules.activity.dto.ActivityDto) Transactional(javax.transaction.Transactional)

Example 8 with GetResult

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

Example 9 with GetResult

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);
}
Also used : GetResult(org.collectiveone.common.dto.GetResult) AppUser(org.collectiveone.modules.users.AppUser) Governance(org.collectiveone.modules.governance.Governance) Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Example 10 with GetResult

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

Aggregations

GetResult (org.collectiveone.common.dto.GetResult)29 UUID (java.util.UUID)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 Transactional (javax.transaction.Transactional)14 ArrayList (java.util.ArrayList)10 Initiative (org.collectiveone.modules.initiatives.Initiative)10 ActivityDto (org.collectiveone.modules.activity.dto.ActivityDto)7 PageRequest (org.springframework.data.domain.PageRequest)7 AssignationDto (org.collectiveone.modules.assignations.dto.AssignationDto)5 PageImpl (org.springframework.data.domain.PageImpl)5 Activity (org.collectiveone.modules.activity.Activity)4 InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)4 NewInitiativeDto (org.collectiveone.modules.initiatives.dto.NewInitiativeDto)4 Sort (org.springframework.data.domain.Sort)4 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)3 ModelCardWrapperDto (org.collectiveone.modules.model.dto.ModelCardWrapperDto)2 ModelViewDto (org.collectiveone.modules.model.dto.ModelViewDto)2 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)2 AppUser (org.collectiveone.modules.users.AppUser)2 Timestamp (java.sql.Timestamp)1