Search in sources :

Example 36 with Transactional

use of javax.transaction.Transactional 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 37 with Transactional

use of javax.transaction.Transactional 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 38 with Transactional

use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.

the class AssignationService method openAssignation.

@Transactional
public PostResult openAssignation(UUID assignationId) {
    Assignation assignation = assignationRepository.findById(assignationId);
    if (assignation.getState() == AssignationState.ON_HOLD) {
        assignation.setState(AssignationState.OPEN);
        assignation.getConfig().setMinClosureDate(new Timestamp(System.currentTimeMillis()));
        assignation.getConfig().setMaxClosureDate(new Timestamp(System.currentTimeMillis() + assignation.getConfig().getDurationDays() * DAYS_TO_MS));
    }
    assignationRepository.save(assignation);
    return new PostResult("success", "success", assignation.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) PeerReviewedAssignation(org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation) Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Example 39 with Transactional

use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.

the class AssignationService method evaluateAssignation.

@Transactional
private PostResult evaluateAssignation(UUID evaluatorUserId, UUID assignationId, EvaluationDto evaluationsDto) {
    Assignation assignation = assignationRepository.findById(assignationId);
    Evaluator evaluator = evaluatorRepository.findByAssignationIdAndUser_C1Id(assignation.getId(), evaluatorUserId);
    if (evaluator != null) {
        for (EvaluationGradeDto evaluationGradeDto : evaluationsDto.getEvaluationGrades()) {
            UUID receiverUserId = UUID.fromString(evaluationGradeDto.getReceiverUser().getC1Id());
            EvaluationGrade grade = evaluationGradeRepository.findByAssignation_IdAndReceiver_User_C1IdAndEvaluator_User_C1Id(assignation.getId(), receiverUserId, evaluatorUserId);
            grade.setPercent(evaluationGradeDto.getPercent());
            grade.setType(EvaluationGradeType.valueOf(evaluationGradeDto.getType()));
            grade.setState(EvaluationGradeState.DONE);
            evaluationGradeRepository.save(grade);
        }
        evaluator.setState(EvaluatorState.DONE);
        evaluatorRepository.save(evaluator);
        return new PostResult("success", "evaluation saved", evaluator.getId().toString());
    } else {
        return new PostResult("error", "evaluator not found", "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) EvaluationGradeDto(org.collectiveone.modules.assignations.dto.EvaluationGradeDto) PeerReviewedAssignation(org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation) UUID(java.util.UUID) Transactional(javax.transaction.Transactional)

Example 40 with Transactional

use of javax.transaction.Transactional 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)

Aggregations

Transactional (javax.transaction.Transactional)314 Test (org.junit.Test)100 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)25 UserDO (org.neusoft.neubbs.entity.UserDO)21 Timestamp (java.sql.Timestamp)18 TopicDO (org.neusoft.neubbs.entity.TopicDO)18 Initiative (org.collectiveone.modules.initiatives.Initiative)16 GetResult (org.collectiveone.common.dto.GetResult)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)13 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)13 HashMap (java.util.HashMap)12 Date (java.util.Date)11 AppUser (org.collectiveone.modules.users.AppUser)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 IOException (java.io.IOException)9 Booking (org.apache.karaf.examples.jpa.Booking)9