Search in sources :

Example 6 with AppUser

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

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

the class InitiativeService method createNewToken.

@Transactional
public PostResult createNewToken(UUID initiativeId, AssetsDto tokenDto, UUID userId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    TokenType token = tokenService.create(tokenDto.getAssetName(), "T");
    initiative.getTokenTypes().add(token);
    initiative = initiativeRepository.save(initiative);
    tokenService.mintToHolder(token.getId(), initiative.getId(), tokenDto.getOwnedByThisHolder(), TokenHolderType.INITIATIVE);
    AppUser orderedBy = appUserRepository.findByC1Id(userId);
    TokenMint mint = new TokenMint();
    mint.setToken(token);
    mint.setOrderedBy(orderedBy);
    mint.setToHolder(initiativeId);
    mint.setMotive("Token creation.");
    mint.setNotes("");
    mint.setValue(tokenDto.getOwnedByThisHolder());
    mint = tokenMintRespository.save(mint);
    activityService.newTokenCreated(initiative, orderedBy, token, mint);
    return new PostResult("success", "initiative created and tokens created", initiative.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) TokenType(org.collectiveone.modules.tokens.TokenType) TokenMint(org.collectiveone.modules.tokens.TokenMint) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 8 with AppUser

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

the class MessageService method postMessage.

@Transactional
public PostResult postMessage(MessageDto messageDto, UUID authorId, MessageThreadContextType contextType, UUID elementId) {
    AppUser author = appUserRepository.findByC1Id(authorId);
    Message message = messageDto.toEntity(messageDto, author);
    message = messageRepository.save(message);
    MessageThread thread = getOrCreateThreadFromElementId(contextType, elementId);
    thread.getMessages().add(message);
    message.setThread(thread);
    message = messageRepository.save(message);
    thread = messageThreadRepository.save(thread);
    activityService.messagePosted(message, author, contextType, elementId);
    return new PostResult("success", "message posted", message.getId().toString());
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 9 with AppUser

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

the class TokenTransferService method transferFromInitiativeToUser.

@Transactional
public PostResult transferFromInitiativeToUser(UUID initiativeId, UUID receiverId, UUID assetId, double value) {
    AppUser receiver = appUserRepository.findByC1Id(receiverId);
    TokenType tokenType = tokenService.getTokenType(assetId);
    String result = tokenService.transfer(tokenType.getId(), initiativeId, receiver.getC1Id(), value, TokenHolderType.USER);
    if (result.equals("success")) {
        /* register the transfer to the contributor  */
        Member member = initiativeService.getOrAddMember(initiativeId, receiver.getC1Id());
        MemberTransfer thisTransfer = new MemberTransfer();
        thisTransfer.setMember(member);
        thisTransfer.setTokenType(tokenType);
        thisTransfer.setValue(value);
        thisTransfer.setStatus(MemberTransferStatus.DONE);
        thisTransfer = memberTransferRepository.save(thisTransfer);
        member.getTokensTransfers().add(thisTransfer);
        memberRepository.save(member);
        return new PostResult("success", "assets transferred successfully", thisTransfer.getId().toString());
    } else {
        return new PostResult("error", "error transferring assets: " + result, "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) AppUser(org.collectiveone.modules.users.AppUser) Member(org.collectiveone.modules.initiatives.Member) Transactional(javax.transaction.Transactional)

Example 10 with AppUser

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

the class TokenTransferService method mintToInitiative.

@Transactional
public String mintToInitiative(UUID tokenId, UUID initiativeId, UUID orderByUserId, TokenMintDto mintDto) {
    String result = tokenService.mintToHolder(tokenId, initiativeId, mintDto.getValue(), TokenHolderType.INITIATIVE);
    if (result.equals("success")) {
        AppUser orderedBy = appUserRepository.findByC1Id(orderByUserId);
        TokenMint mint = new TokenMint();
        mint.setToken(tokenService.getTokenType(tokenId));
        mint.setOrderedBy(orderedBy);
        mint.setToHolder(initiativeId);
        mint.setMotive(mintDto.getMotive());
        mint.setNotes(mintDto.getNotes());
        mint.setValue(mintDto.getValue());
        mint = tokenMintRespository.save(mint);
        activityService.tokensMinted(initiativeRepository.findById(initiativeId), mint);
    }
    return result;
}
Also used : AppUser(org.collectiveone.modules.users.AppUser) 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