Search in sources :

Example 41 with Transactional

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);
}
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 42 with Transactional

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", "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) PeerReviewedAssignation(org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation) Transactional(javax.transaction.Transactional)

Example 43 with Transactional

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);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) Activity(org.collectiveone.modules.activity.Activity) UUID(java.util.UUID) ActivityDto(org.collectiveone.modules.activity.dto.ActivityDto) Transactional(javax.transaction.Transactional)

Example 44 with Transactional

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);
}
Also used : WantToContributeNotification(org.collectiveone.modules.activity.WantToContributeNotification) PostResult(org.collectiveone.common.dto.PostResult) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 45 with Transactional

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", "");
        }
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) InputStream(java.io.InputStream) IOException(java.io.IOException) 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