Search in sources :

Example 1 with AppUser

use of org.collectiveone.modules.users.AppUser in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method setLikeToCard.

@Transactional
public PostResult setLikeToCard(UUID cardWrapperId, UUID authorId, boolean likeStatus) {
    ModelCardWrapper card = modelCardWrapperRepository.findById(cardWrapperId);
    AppUser author = appUserRepository.findByC1Id(authorId);
    CardLike like = cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapperId, authorId);
    /* add the like*/
    if (likeStatus == true) {
        if (like == null) {
            like = new CardLike();
            like.setAuthor(author);
            like.setCardWrapper(card);
            cardLikeRepository.save(like);
        } else {
        /* nothing to do, the like is already registered */
        }
    } else {
        if (like != null) {
            cardLikeRepository.delete(like);
        } else {
        /* nothing to do, the like is already absent */
        }
    }
    return new PostResult("success", "like status changed", null);
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) AppUser(org.collectiveone.modules.users.AppUser) CardLike(org.collectiveone.modules.governance.CardLike) Transactional(javax.transaction.Transactional)

Example 2 with AppUser

use of org.collectiveone.modules.users.AppUser in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method addMemberOrGet.

@Transactional
public Member addMemberOrGet(UUID initiativeId, UUID c1Id, DecisionMakerRole role) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    AppUser memberUser = appUserRepository.findByC1Id(c1Id);
    Member existingMember = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, c1Id);
    if (existingMember != null) {
        return existingMember;
    }
    Member member = new Member();
    member.setInitiative(initiative);
    member.setUser(memberUser);
    member = memberRepository.save(member);
    initiative.getMembers().add(member);
    initiativeRepository.save(initiative);
    if (role.equals(DecisionMakerRole.ADMIN) || role.equals(DecisionMakerRole.EDITOR)) {
        governanceService.addDecisionMaker(initiative.getGovernance().getId(), memberUser.getC1Id(), role);
    }
    /* members are subscribed to initiatives by default */
    activityService.addSubscriber(initiativeId, memberUser.getC1Id(), SubscriptionElementType.INITIATIVE);
    return member;
}
Also used : AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 3 with AppUser

use of org.collectiveone.modules.users.AppUser in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getOfUser.

@Transactional
public GetResult<List<InitiativeDto>> getOfUser(UUID userC1Id) {
    /* return all super-initiatives (initiatives without parent initiatives) 
		 * and include all sub-initiativespf each of them */
    AppUser user = appUserRepository.findByC1Id(userC1Id);
    /* get all initiatives in which the user is a contributor */
    List<Initiative> superInitiatives = getSuperInitiativesOfMember(user.getC1Id());
    List<InitiativeDto> initiativesDtos = new ArrayList<InitiativeDto>();
    for (Initiative initiative : superInitiatives) {
        if (initiative.getStatus() == InitiativeStatus.ENABLED) {
            InitiativeDto dto = initiative.toDto();
            dto.setLoggedMembership(getMemberAndInParent(initiative.getId(), user.getC1Id()));
            /* look for the full sub-initiative tree of each super initiative */
            List<InitiativeDto> subInitiatives = getSubinitiativesTree(initiative.getId(), user.getC1Id());
            dto.setSubInitiatives(subInitiatives);
            initiativesDtos.add(dto);
        }
    }
    return new GetResult<List<InitiativeDto>>("success", "initiatives retrieved", initiativesDtos);
}
Also used : NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 4 with AppUser

use of org.collectiveone.modules.users.AppUser in project CollectiveOneWebapp by CollectiveOne.

the class InitiativeService method getOrAddMember.

@Transactional
public Member getOrAddMember(UUID initiativeId, UUID userId) {
    Member member = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, userId);
    if (member == null) {
        Initiative initiative = initiativeRepository.findById(initiativeId);
        AppUser user = appUserRepository.findByC1Id(userId);
        member = new Member();
        member.setInitiative(initiative);
        member.setUser(user);
        member = memberRepository.save(member);
    }
    return member;
}
Also used : AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 5 with AppUser

use of org.collectiveone.modules.users.AppUser 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)

Aggregations

Transactional (javax.transaction.Transactional)10 AppUser (org.collectiveone.modules.users.AppUser)10 PostResult (org.collectiveone.common.dto.PostResult)5 GetResult (org.collectiveone.common.dto.GetResult)2 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 WantToContributeNotification (org.collectiveone.modules.activity.WantToContributeNotification)1 CardLike (org.collectiveone.modules.governance.CardLike)1 DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)1 Governance (org.collectiveone.modules.governance.Governance)1 Member (org.collectiveone.modules.initiatives.Member)1 InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)1 NewInitiativeDto (org.collectiveone.modules.initiatives.dto.NewInitiativeDto)1 TokenMint (org.collectiveone.modules.tokens.TokenMint)1 TokenType (org.collectiveone.modules.tokens.TokenType)1