Search in sources :

Example 46 with Transactional

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

the class FileService method uploadImageProfile.

@Transactional
public void uploadImageProfile(UUID userId, MultipartFile file) {
    String key = "ProfileImages/" + userId.toString();
    FileStored fileUploaded = handleFileUpload(userId, key, file, null);
    if (fileUploaded != null) {
        AppUserProfile profile = appUserProfileRepository.findByUser_C1Id(userId);
        profile.setUploadedPicture(fileUploaded);
        appUserProfileRepository.save(profile);
    }
}
Also used : AppUserProfile(org.collectiveone.modules.users.AppUserProfile) Transactional(javax.transaction.Transactional)

Example 47 with Transactional

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

the class FileService method uploadCardImage.

@Transactional
public PostResult uploadCardImage(UUID userId, UUID cardWrapperId, MultipartFile file) throws IOException {
    try (InputStream input = file.getInputStream()) {
        try {
            ImageIO.read(input).toString();
            Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
            String key = "CardImages/" + cardWrapperId.toString();
            FileStored fileUploaded = handleFileUpload(userId, key, file, initiative.getId());
            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) Initiative(org.collectiveone.modules.initiatives.Initiative) IOException(java.io.IOException) Transactional(javax.transaction.Transactional)

Example 48 with Transactional

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

the class ActivityService method assignationRevertCancelled.

@Transactional
public void assignationRevertCancelled(Assignation assignation) {
    Activity revertOrder = activityRepository.findTop1ByAssignation_IdAndTypeOrderByTimestampDesc(assignation.getId(), ActivityType.ASSIGNATION_REVERT_ORDERED);
    Activity activity = new Activity();
    activity.setType(ActivityType.ASSIGNATION_REVERT_CANCELLED);
    activity.setTriggerUser(revertOrder.getTriggerUser());
    activity.setInitiative(assignation.getInitiative());
    activity.setTimestamp(new Timestamp(System.currentTimeMillis()));
    activity.setAssignation(assignation);
    activity = activityRepository.save(activity);
    addInitiativeActivityNotifications(activity);
}
Also used : Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Example 49 with Transactional

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

the class ActivityService method getInitiativeSubscribers.

@Transactional
private List<Subscriber> getInitiativeSubscribers(UUID initiativeId) {
    /* example https://docs.google.com/drawings/d/1PqPhefzrGVlWVfG-SRGS56l_e2qpNEsajLbnsAWcTfA/edit,
		 * assume initiativeId = C */
    /* start with this initiative subscribers (S3 and S6 in example). Take into account that 
		 * a subscriber state may be SUBSCRIPTION_DISABLED */
    List<Subscriber> allSubscribers = subscriberRepository.findByElementId(initiativeId);
    /* then add the subscribers of all parent initiatives (B and A, in that order) */
    List<Initiative> parents = initiativeService.getParentGenealogyInitiatives(initiativeId);
    for (Initiative parent : parents) {
        List<Subscriber> parentSubscribers = subscriberRepository.findByElementId(parent.getId());
        for (Subscriber parentSubscriber : parentSubscribers) {
            int ixOfSubscriber = indexOfSubscriber(allSubscribers, parentSubscriber);
            if (ixOfSubscriber == -1) {
                /* if this user is not already in the list of subscriptions, then
					 * add it (this means that the applicable subscription is that at
					 * the lowest level) */
                allSubscribers.add(parentSubscriber);
            }
        }
    }
    return allSubscribers;
}
Also used : Initiative(org.collectiveone.modules.initiatives.Initiative) TokenMint(org.collectiveone.modules.tokens.TokenMint) Transactional(javax.transaction.Transactional)

Example 50 with Transactional

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

the class ActivityService method assignationReverted.

@Transactional
public void assignationReverted(Assignation assignation) {
    Activity revertOrder = activityRepository.findTop1ByAssignation_IdAndTypeOrderByTimestampDesc(assignation.getId(), ActivityType.ASSIGNATION_REVERT_ORDERED);
    Activity activity = new Activity();
    activity.setType(ActivityType.ASSIGNATION_REVERTED);
    activity.setTriggerUser(revertOrder.getTriggerUser());
    activity.setInitiative(assignation.getInitiative());
    activity.setTimestamp(new Timestamp(System.currentTimeMillis()));
    activity.setAssignation(assignation);
    activity = activityRepository.save(activity);
    addInitiativeActivityNotifications(activity);
}
Also used : Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)299 Test (org.junit.Test)99 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)24 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 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 IOException (java.io.IOException)9 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)9