Search in sources :

Example 1 with AssignationDto

use of org.collectiveone.modules.assignations.dto.AssignationDto in project CollectiveOneWebapp by CollectiveOne.

the class AssignationService method getPeerReviewedAssignation.

@Transactional
public AssignationDto getPeerReviewedAssignation(UUID initiativeId, UUID assignationId, UUID evaluatorAppUserId, Boolean addAllEvaluations) {
    Assignation assignation = assignationRepository.findById(assignationId);
    AssignationDto assignationDto = assignation.toDto();
    /* add the evaluations of logged user */
    Evaluator evaluator = evaluatorRepository.findByAssignationIdAndUser_C1Id(assignation.getId(), evaluatorAppUserId);
    assignationDto.setEvaluationsPending(evaluatorRepository.countByAssignationIdAndState(assignation.getId(), EvaluatorState.PENDING));
    if (evaluator != null) {
        EvaluationDto evaluation = new EvaluationDto();
        evaluation.setId(evaluator.getId().toString());
        evaluation.setEvaluationState(evaluator.getState().toString());
        for (EvaluationGrade grade : evaluator.getGrades()) {
            evaluation.getEvaluationGrades().add(grade.toDto());
        }
        assignationDto.setThisEvaluation(evaluation);
    }
    /* add individual biases */
    if (assignation.getConfig().getSelfBiasVisible()) {
        if (assignation.getState() == AssignationState.DONE) {
            for (Receiver receiver : assignation.getReceivers()) {
                EvaluationGrade selfEvaluation = evaluationGradeRepository.findByAssignation_IdAndReceiver_User_C1IdAndEvaluator_User_C1Id(assignation.getId(), receiver.getUser().getC1Id(), receiver.getUser().getC1Id());
                if (selfEvaluation != null) {
                    /* fill the receivers dtos selfBias */
                    for (ReceiverDto receiverDto : assignationDto.getReceivers()) {
                        if (receiverDto.getUser().getC1Id().equals(receiver.getUser().getC1Id().toString())) {
                            if (selfEvaluation.getState() == EvaluationGradeState.DONE) {
                                if (selfEvaluation.getType() == EvaluationGradeType.SET) {
                                    receiverDto.setSelfBias(selfEvaluation.getPercent() - receiverDto.getEvaluatedPercent());
                                } else {
                                    receiverDto.setSelfBias(999.9);
                                }
                            } else {
                                receiverDto.setSelfBias(999.9);
                            }
                        }
                    }
                }
            }
        }
    }
    /* add all the evaluations */
    if (addAllEvaluations) {
        if (assignation.getConfig().getEvaluationsVisible()) {
            if (assignation.getState() == AssignationState.DONE) {
                for (Evaluator thisEvaluator : assignation.getEvaluators()) {
                    assignationDto.getEvaluators().add(thisEvaluator.toDto());
                }
            }
        }
    }
    return assignationDto;
}
Also used : AssignationDto(org.collectiveone.modules.assignations.dto.AssignationDto) ReceiverDto(org.collectiveone.modules.assignations.dto.ReceiverDto) PeerReviewedAssignation(org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation) EvaluationDto(org.collectiveone.modules.assignations.dto.EvaluationDto) Transactional(javax.transaction.Transactional)

Example 2 with AssignationDto

use of org.collectiveone.modules.assignations.dto.AssignationDto in project CollectiveOneWebapp by CollectiveOne.

the class AssignationService method getAssignationDto.

@Transactional
public GetResult<AssignationDto> getAssignationDto(UUID assignationId, UUID userId, Boolean addAllEvaluations) {
    Assignation assignation = assignationRepository.findById(assignationId);
    AssignationDto assignationDto = null;
    if (assignation.getType() == AssignationType.PEER_REVIEWED) {
        assignationDto = getPeerReviewedAssignation(assignation.getInitiative().getId(), assignation.getId(), userId, addAllEvaluations);
    } else {
        assignationDto = assignation.toDto();
    }
    return new GetResult<AssignationDto>("success", "assignation retreived", assignationDto);
}
Also used : AssignationDto(org.collectiveone.modules.assignations.dto.AssignationDto) GetResult(org.collectiveone.common.dto.GetResult) PeerReviewedAssignation(org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation) Transactional(javax.transaction.Transactional)

Example 3 with AssignationDto

use of org.collectiveone.modules.assignations.dto.AssignationDto in project CollectiveOneWebapp by CollectiveOne.

the class Assignation method toDto.

public AssignationDto toDto() {
    AssignationDto dto = new AssignationDto();
    dto.setId(id.toString());
    dto.setType(type.toString());
    dto.setMotive(motive);
    dto.setNotes(notes);
    dto.setState(state.toString());
    dto.setInitiativeId(initiative.getId().toString());
    dto.setInitiativeName(initiative.getMeta().getName());
    dto.setCreationDate(creationDate.getTime());
    dto.setConfig(config.toDto());
    for (Bill bill : bills) {
        dto.getAssets().add(bill.toDto());
    }
    for (Receiver receiver : receivers) {
        dto.getReceivers().add(receiver.toDto());
    }
    return dto;
}
Also used : AssignationDto(org.collectiveone.modules.assignations.dto.AssignationDto)

Example 4 with AssignationDto

use of org.collectiveone.modules.assignations.dto.AssignationDto in project CollectiveOneWebapp by CollectiveOne.

the class AssignationController method getAssignations.

@RequestMapping(path = "/initiative/{initiativeId}/assignations", method = RequestMethod.GET)
public GetResult<List<AssignationDto>> getAssignations(@PathVariable("initiativeId") String initiativeIdStr, @RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("sortDirection") String sortDirection, @RequestParam("sortProperty") String sortProperty) {
    UUID initiativeId = UUID.fromString(initiativeIdStr);
    if (!initiativeService.canAccess(initiativeId, getLoggedUserId())) {
        return new GetResult<List<AssignationDto>>("error", "access denied", null);
    }
    Sort sort = new Sort(Sort.Direction.valueOf(sortDirection), sortProperty);
    return assignationService.getAssignationsOfInitiative(initiativeId, getLoggedUserId(), new PageRequest(page, size, sort));
}
Also used : AssignationDto(org.collectiveone.modules.assignations.dto.AssignationDto) PageRequest(org.springframework.data.domain.PageRequest) GetResult(org.collectiveone.common.dto.GetResult) Sort(org.springframework.data.domain.Sort) UUID(java.util.UUID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with AssignationDto

use of org.collectiveone.modules.assignations.dto.AssignationDto in project CollectiveOneWebapp by CollectiveOne.

the class AssignationController method getAssignationsOfSubinitiatives.

@RequestMapping(path = "/initiative/{initiativeId}/assignationsOfSubinitiatives", method = RequestMethod.GET)
public GetResult<List<AssignationDto>> getAssignationsOfSubinitiatives(@PathVariable("initiativeId") String initiativeIdStr, @RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("sortDirection") String sortDirection, @RequestParam("sortProperty") String sortProperty) {
    UUID initiativeId = UUID.fromString(initiativeIdStr);
    if (!initiativeService.canAccess(initiativeId, getLoggedUserId())) {
        return new GetResult<List<AssignationDto>>("error", "access denied", null);
    }
    Sort sort = new Sort(Sort.Direction.valueOf(sortDirection), sortProperty);
    return assignationService.getAssignationsOfSubinitiatives(initiativeId, getLoggedUserId(), new PageRequest(page, size, sort));
}
Also used : AssignationDto(org.collectiveone.modules.assignations.dto.AssignationDto) PageRequest(org.springframework.data.domain.PageRequest) GetResult(org.collectiveone.common.dto.GetResult) Sort(org.springframework.data.domain.Sort) UUID(java.util.UUID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AssignationDto (org.collectiveone.modules.assignations.dto.AssignationDto)7 GetResult (org.collectiveone.common.dto.GetResult)5 Transactional (javax.transaction.Transactional)4 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)4 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 PageRequest (org.springframework.data.domain.PageRequest)2 Sort (org.springframework.data.domain.Sort)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 EvaluationDto (org.collectiveone.modules.assignations.dto.EvaluationDto)1 ReceiverDto (org.collectiveone.modules.assignations.dto.ReceiverDto)1