Search in sources :

Example 1 with ReceiverDto

use of org.collectiveone.modules.assignations.dto.ReceiverDto 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 ReceiverDto

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

the class Receiver method toDto.

public ReceiverDto toDto() {
    ReceiverDto dto = new ReceiverDto();
    dto.setId(id.toString());
    dto.setUser(user.toDtoLight());
    dto.setPercent(assignedPercent);
    dto.setEvaluatedPercent(evaluatedPercent);
    dto.setState(state.toString());
    dto.setIsDonor(type == ReceiverType.DONOR);
    if (revertApproval != null)
        dto.setRevertApproval(revertApproval);
    return dto;
}
Also used : ReceiverDto(org.collectiveone.modules.assignations.dto.ReceiverDto)

Example 3 with ReceiverDto

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

the class AssignationService method createAssignation.

public PostResult createAssignation(UUID initiativeId, AssignationDto assignationDto, UUID creatorId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    Assignation assignation = new Assignation();
    assignation.setType(AssignationType.valueOf(assignationDto.getType()));
    assignation.setMotive(assignationDto.getMotive());
    assignation.setNotes(assignationDto.getNotes());
    assignation.setCreator(appUserRepository.findByC1Id(creatorId));
    assignation.setCreationDate(new Timestamp(System.currentTimeMillis()));
    assignation.setState(AssignationState.valueOf(assignationDto.getConfig().getStartState()));
    assignation.setInitiative(initiative);
    assignation.getAlsoInInitiatives().addAll(initiativeService.getParentGenealogyInitiatives(initiative.getId()));
    AssignationConfig config = new AssignationConfig();
    config.setSelfBiasVisible(Boolean.valueOf(assignationDto.getConfig().getSelfBiasVisible()));
    config.setEvaluationsVisible(Boolean.valueOf(assignationDto.getConfig().getEvaluationsVisible()));
    config.setDurationDays(assignationDto.getConfig().getMaxDuration());
    if (assignation.getState() == AssignationState.OPEN) {
        config.setMinClosureDate(new Timestamp(System.currentTimeMillis()));
        config.setMaxClosureDate(new Timestamp(System.currentTimeMillis() + assignationDto.getConfig().getMaxDuration() * DAYS_TO_MS));
    }
    config = assignationConfigRepository.save(config);
    assignation.setConfig(config);
    assignation = assignationRepository.save(assignation);
    for (ReceiverDto receiverDto : assignationDto.getReceivers()) {
        Receiver receiver = new Receiver();
        receiver.setUser(appUserRepository.findByC1Id(UUID.fromString(receiverDto.getUser().getC1Id())));
        receiver.setAssignation(assignation);
        receiver.setAssignedPercent(receiverDto.getPercent());
        receiver.setState(ReceiverState.PENDING);
        if (receiverDto.getIsDonor()) {
            receiver.setType(ReceiverType.DONOR);
        } else {
            receiver.setType(ReceiverType.NORMAL);
        }
        receiver = receiverRepository.save(receiver);
        assignation.getReceivers().add(receiver);
    }
    for (BillDto billDto : assignationDto.getAssets()) {
        TokenType tokenType = tokenService.getTokenType(UUID.fromString(billDto.getAssetId()));
        Bill bill = new Bill();
        bill.setAssignation(assignation);
        bill.setTokenType(tokenType);
        bill.setValue(billDto.getValue());
        bill = billRepository.save(bill);
        assignation.getBills().add(bill);
    }
    switch(assignation.getType()) {
        case DIRECT:
            for (Bill bill : assignation.getBills()) {
                for (Receiver receiver : assignation.getReceivers()) {
                    double value = bill.getValue() * receiver.getAssignedPercent() / 100.0;
                    PostResult result = tokenTransferService.transferFromInitiativeToUser(assignation.getInitiative().getId(), receiver.getUser().getC1Id(), bill.getTokenType().getId(), value);
                    if (result.getResult().equals("success")) {
                        receiver.setState(ReceiverState.RECEIVED);
                        receiver.setTransfer(memberTransferRepository.findById(UUID.fromString(result.getElementId())));
                        receiverRepository.save(receiver);
                    }
                }
            }
            assignation.setState(AssignationState.DONE);
            assignationRepository.save(assignation);
            activityService.directAssignationCreated(assignation, appUserRepository.findByC1Id(creatorId));
            break;
        case PEER_REVIEWED:
            for (EvaluatorDto evaluatorDto : assignationDto.getEvaluators()) {
                Evaluator evaluator = new Evaluator();
                evaluator.setUser(appUserRepository.findByC1Id(UUID.fromString(evaluatorDto.getUser().getC1Id())));
                evaluator.setAssignation(assignation);
                evaluator.setState(EvaluatorState.PENDING);
                /* Weight logic TBD */
                evaluator.setWeight(1.0);
                evaluator = evaluatorRepository.save(evaluator);
                /* Create the grades of all evaluators already */
                for (Receiver receiver : assignation.getReceivers()) {
                    EvaluationGrade grade = new EvaluationGrade();
                    grade.setAssignation(assignation);
                    grade.setEvaluator(evaluator);
                    grade.setReceiver(receiver);
                    grade.setPercent(0.0);
                    grade.setType(EvaluationGradeType.SET);
                    grade.setState(EvaluationGradeState.PENDING);
                    grade = evaluationGradeRepository.save(grade);
                    evaluator.getGrades().add(grade);
                }
                assignation.getEvaluators().add(evaluator);
            }
            activityService.peerReviewedAssignationCreated(assignation, appUserRepository.findByC1Id(creatorId));
            break;
    }
    return new PostResult("success", "success", assignation.getId().toString());
}
Also used : ReceiverDto(org.collectiveone.modules.assignations.dto.ReceiverDto) PeerReviewedAssignation(org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation) Initiative(org.collectiveone.modules.initiatives.Initiative) Timestamp(java.sql.Timestamp) PostResult(org.collectiveone.common.dto.PostResult) TokenType(org.collectiveone.modules.tokens.TokenType) BillDto(org.collectiveone.modules.assignations.dto.BillDto) EvaluatorDto(org.collectiveone.modules.assignations.dto.EvaluatorDto)

Aggregations

ReceiverDto (org.collectiveone.modules.assignations.dto.ReceiverDto)3 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)2 Timestamp (java.sql.Timestamp)1 Transactional (javax.transaction.Transactional)1 PostResult (org.collectiveone.common.dto.PostResult)1 AssignationDto (org.collectiveone.modules.assignations.dto.AssignationDto)1 BillDto (org.collectiveone.modules.assignations.dto.BillDto)1 EvaluationDto (org.collectiveone.modules.assignations.dto.EvaluationDto)1 EvaluatorDto (org.collectiveone.modules.assignations.dto.EvaluatorDto)1 Initiative (org.collectiveone.modules.initiatives.Initiative)1 TokenType (org.collectiveone.modules.tokens.TokenType)1