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);
}
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);
}
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());
}
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", "");
}
}
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;
}
Aggregations