Search in sources :

Example 26 with Transactional

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

the class TokenService method getTokenDto.

@Transactional
public AssetsDto getTokenDto(UUID tokenTypeId, boolean getExisting) {
    TokenType token = tokenTypeRepository.findById(tokenTypeId);
    AssetsDto assetsDto = new AssetsDto();
    /* token info */
    assetsDto.setAssetId(token.getId().toString());
    assetsDto.setAssetName(token.getName());
    if (getExisting) {
        /* Total amount of tokens in circulation */
        double existingTokens = getTotalExisting(token.getId());
        assetsDto.setTotalExistingTokens(existingTokens);
    }
    return assetsDto;
}
Also used : AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) Transactional(javax.transaction.Transactional)

Example 27 with Transactional

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

the class TokenTransferService method getTransferredToSubinitiatives.

/**
 * Get the tokens transferred from one initiative into its sub-initiatives
 */
@Transactional
public List<TransferDto> getTransferredToSubinitiatives(UUID tokenId, UUID initiativeId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    TokenType token = tokenService.getTokenType(tokenId);
    /* get of sub-initiatives */
    List<InitiativeRelationship> subinitiativesRelationships = initiativeRelationshipRepository.findByOfInitiativeIdAndInitiative_StatusAndType(initiative.getId(), InitiativeStatus.ENABLED, InitiativeRelationshipType.IS_ATTACHED_SUB);
    List<TransferDto> transferredToSubinitiatives = new ArrayList<TransferDto>();
    for (InitiativeRelationship relationship : subinitiativesRelationships) {
        /* get all transfers of a given token made from and to these initiatives */
        Double totalTransferred = initiativeTransferRepository.getTotalTransferredFromTo(tokenId, relationship.getOfInitiative().getId(), relationship.getInitiative().getId());
        Double totalReturned = initiativeTransferRepository.getTotalTransferredFromTo(tokenId, relationship.getInitiative().getId(), relationship.getOfInitiative().getId());
        TransferDto dto = new TransferDto();
        dto.setAssetId(token.getId().toString());
        dto.setAssetName(token.getName());
        dto.setSenderId(relationship.getOfInitiative().getId().toString());
        dto.setSenderName(relationship.getOfInitiative().getMeta().getName());
        dto.setReceiverId(relationship.getInitiative().getId().toString());
        dto.setReceiverName(relationship.getInitiative().getMeta().getName());
        dto.setValue(totalTransferred - totalReturned);
        transferredToSubinitiatives.add(dto);
    }
    return transferredToSubinitiatives;
}
Also used : InitiativeRelationship(org.collectiveone.modules.initiatives.InitiativeRelationship) ArrayList(java.util.ArrayList) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 28 with Transactional

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

the class TokenTransferService method transferFromInitiativeToInitiative.

@Transactional
public PostResult transferFromInitiativeToInitiative(UUID fromInitiativeId, UUID toInitiativeId, UUID orderByUserId, UUID assetId, double value, String motive, String notes) {
    TokenType tokenType = tokenService.getTokenType(assetId);
    Initiative from = initiativeRepository.findById(fromInitiativeId);
    Initiative to = initiativeRepository.findById(toInitiativeId);
    String result = tokenService.transfer(tokenType.getId(), from.getId(), to.getId(), value, TokenHolderType.INITIATIVE);
    if (result.equals("success")) {
        /* register the transfer to the initiative  */
        InitiativeTransfer transfer = new InitiativeTransfer();
        transfer.setTokenType(tokenType);
        transfer.setFrom(from);
        transfer.setTo(to);
        transfer.setMotive(motive);
        transfer.setNotes(notes);
        transfer.setValue(value);
        transfer.setOrderDate(new Timestamp(System.currentTimeMillis()));
        transfer.setOrderedBy(appUserRepository.findByC1Id(orderByUserId));
        transfer = initiativeTransferRepository.save(transfer);
        activityService.transferToSubinitiative(transfer);
        return new PostResult("success", "transfer done", transfer.getId().toString());
    } else {
        return new PostResult("success", "error making the transfer:" + result, "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) Initiative(org.collectiveone.modules.initiatives.Initiative) Timestamp(java.sql.Timestamp) Transactional(javax.transaction.Transactional)

Example 29 with Transactional

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

the class TokenTransferService method getTransferredToUsers.

/**
 * Get the tokens transferred from one initiative to its members
 */
@Transactional
public List<TransferDto> getTransferredToUsers(UUID tokenId, UUID initiativeId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    TokenType token = tokenService.getTokenType(tokenId);
    List<TransferDto> transferredToUsers = new ArrayList<TransferDto>();
    for (Member member : initiative.getMembers()) {
        /* get all transfers of a given token made from an initiative to a contributor */
        double totalTransferred = memberTransferRepository.getTotalTransferred(tokenId, member.getId());
        TransferDto dto = new TransferDto();
        dto.setAssetId(token.getId().toString());
        dto.setAssetName(token.getName());
        dto.setSenderId(initiative.getId().toString());
        dto.setSenderName(initiative.getMeta().getName());
        dto.setReceiverId(member.getUser().getC1Id().toString());
        dto.setReceiverName(member.getUser().getProfile().getNickname());
        dto.setValue(totalTransferred);
        transferredToUsers.add(dto);
    }
    return transferredToUsers;
}
Also used : ArrayList(java.util.ArrayList) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Initiative(org.collectiveone.modules.initiatives.Initiative) Member(org.collectiveone.modules.initiatives.Member) Transactional(javax.transaction.Transactional)

Example 30 with Transactional

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

the class TokenTransferService method getTokenDistribution.

/**
 * Get the distribution of an asset starting from a given initiative
 * and including the tokens transferred to its sub-initiatives and members
 */
@Transactional
public AssetsDto getTokenDistribution(UUID tokenId, UUID initiativeId) {
    Initiative initiative = initiativeRepository.findById(initiativeId);
    AssetsDto assetDto = tokenService.getTokensOfHolderDto(tokenId, initiative.getId());
    assetDto.setHolderName(initiative.getMeta().getName());
    assetDto.setTransferredToSubinitiatives(getTransferredToSubinitiatives(tokenId, initiative.getId()));
    assetDto.setTransferredToUsers(getTransferredToUsers(tokenId, initiative.getId()));
    assetDto.setTransfersPending(getTransfersPending(initiative.getId()));
    /* sum all tranfers as additional data */
    assetDto.setTotalTransferredToSubinitiatives(0.0);
    for (TransferDto transfer : assetDto.getTransferredToSubinitiatives()) {
        assetDto.setTotalTransferredToSubinitiatives(assetDto.getTotalTransferredToSubinitiatives() + transfer.getValue());
    }
    assetDto.setTotalTransferredToUsers(0.0);
    for (TransferDto transfer : assetDto.getTransferredToUsers()) {
        assetDto.setTotalTransferredToUsers(assetDto.getTotalTransferredToUsers() + transfer.getValue());
    }
    assetDto.setTotalPending(0.0);
    for (TransferDto transfer : assetDto.getTransfersPending()) {
        assetDto.setTotalPending(assetDto.getTotalPending() + transfer.getValue());
    }
    assetDto.setTotalUnderThisHolder(assetDto.getOwnedByThisHolder() + assetDto.getTotalTransferredToSubinitiatives() + assetDto.getTotalTransferredToUsers());
    return assetDto;
}
Also used : AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Initiative(org.collectiveone.modules.initiatives.Initiative) 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