use of javax.transaction.Transactional 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);
}
use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.
the class AssignationService method approveRevertAssignation.
@Transactional
public PostResult approveRevertAssignation(UUID userId, UUID assignationId, Boolean value) {
Assignation assignation = assignationRepository.findById(assignationId);
if (assignation.getState() == AssignationState.REVERT_ORDERED) {
Receiver receiver = receiverRepository.findByAssignation_IdAndUser_C1Id(assignationId, userId);
if (receiver != null) {
if (value) {
receiver.setRevertApproval(true);
receiverRepository.save(receiver);
} else {
/* a single receiver that rejects will cancel the revert */
assignation.setState(AssignationState.DONE);
activityService.assignationRevertCancelled(assignation);
}
}
return new PostResult("success", "revert of assignation approved by this receiver", "");
} else {
return new PostResult("error", "assignation not in revert, cannot be approved", "");
}
}
use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method getActivityUnderInitiative.
@Transactional
public GetResult<Page<ActivityDto>> getActivityUnderInitiative(UUID initiativeId, PageRequest page, Boolean onlyMessages) {
List<InitiativeDto> subinitiativesTree = getSubinitiativesTree(initiativeId, null);
List<UUID> allInitiativesIds = new ArrayList<UUID>();
allInitiativesIds.add(initiativeId);
allInitiativesIds.addAll(extractAllIdsFromInitiativesTree(subinitiativesTree, new ArrayList<UUID>()));
Page<Activity> activities = null;
if (!onlyMessages) {
activities = activityRepository.findOfInitiatives(allInitiativesIds, page);
} else {
activities = activityRepository.findOfInitiativesAndType(allInitiativesIds, ActivityType.MESSAGE_POSTED, page);
}
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);
}
use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method wantToContribute.
@Transactional
public PostResult wantToContribute(UUID initiativeId, UUID userId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
AppUser user = appUserRepository.findByC1Id(userId);
List<DecisionMaker> admins = decisionMakerRepository.findByGovernance_IdAndRole(initiative.getGovernance().getId(), DecisionMakerRole.ADMIN);
for (DecisionMaker admin : admins) {
WantToContributeNotification notification = new WantToContributeNotification();
notification.setInitiative(initiative);
notification.setAdmin(admin.getUser());
notification.setUser(user);
notification.setEmailState(NotificationEmailState.PENDING);
wantToContributeRepository.save(notification);
}
return new PostResult("success", "notifications recorded for sending", null);
}
use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.
the class FileService method uploadInitiativeImage.
@Transactional
public PostResult uploadInitiativeImage(UUID userId, UUID initiativeId, MultipartFile file) throws IOException {
try (InputStream input = file.getInputStream()) {
try {
ImageIO.read(input).toString();
String key = "InitiativeImages/" + initiativeId.toString();
FileStored fileUploaded = handleFileUpload(userId, key, file, initiativeId);
if (fileUploaded != null) {
return new PostResult("success", "image uploaded", fileUploaded.getId().toString());
}
return new PostResult("error", "error uploading image", "");
} catch (Exception e) {
// It's not an image.
return new PostResult("error", "only image files are supported", "");
}
}
}
Aggregations