Search in sources :

Example 1 with TransferDto

use of org.collectiveone.modules.tokens.dto.TransferDto 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 2 with TransferDto

use of org.collectiveone.modules.tokens.dto.TransferDto 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 3 with TransferDto

use of org.collectiveone.modules.tokens.dto.TransferDto 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)

Example 4 with TransferDto

use of org.collectiveone.modules.tokens.dto.TransferDto in project CollectiveOneWebapp by CollectiveOne.

the class TokenController method getTransferFromSubinitiative.

@RequestMapping(path = "/initiative/{initiativeId}/transfersFromSubinitiatives", method = RequestMethod.GET)
public GetResult<List<TransferDto>> getTransferFromSubinitiative(@PathVariable("initiativeId") String initiativeIdStr, @RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("sortDirection") String sortDirection, @RequestParam("sortProperty") String sortProperty) {
    UUID initiativeId = UUID.fromString(initiativeIdStr);
    if (!initiativeService.canAccess(initiativeId, getLoggedUserId())) {
        return new GetResult<List<TransferDto>>("error", "access denied", null);
    }
    Sort sort = new Sort(Sort.Direction.valueOf(sortDirection), sortProperty);
    return tokenTransferService.getTransfersFromSubinitiatives(initiativeId, new PageRequest(page, size, sort));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) GetResult(org.collectiveone.common.dto.GetResult) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Sort(org.springframework.data.domain.Sort) UUID(java.util.UUID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with TransferDto

use of org.collectiveone.modules.tokens.dto.TransferDto in project CollectiveOneWebapp by CollectiveOne.

the class TokenController method getTransferFromInitiative.

@RequestMapping(path = "/initiative/{initiativeId}/transfersToInitiatives", method = RequestMethod.GET)
public GetResult<List<TransferDto>> getTransferFromInitiative(@PathVariable("initiativeId") String initiativeIdStr, @RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("sortDirection") String sortDirection, @RequestParam("sortProperty") String sortProperty) {
    UUID initiativeId = UUID.fromString(initiativeIdStr);
    if (!initiativeService.canAccess(initiativeId, getLoggedUserId())) {
        return new GetResult<List<TransferDto>>("error", "access denied", null);
    }
    Sort sort = new Sort(Sort.Direction.valueOf(sortDirection), sortProperty);
    return tokenTransferService.getTransfersFromInitiative(initiativeId, new PageRequest(page, size, sort));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) GetResult(org.collectiveone.common.dto.GetResult) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Sort(org.springframework.data.domain.Sort) UUID(java.util.UUID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)8 Transactional (javax.transaction.Transactional)5 ArrayList (java.util.ArrayList)4 Initiative (org.collectiveone.modules.initiatives.Initiative)4 UUID (java.util.UUID)2 GetResult (org.collectiveone.common.dto.GetResult)2 PageRequest (org.springframework.data.domain.PageRequest)2 Sort (org.springframework.data.domain.Sort)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Timestamp (java.sql.Timestamp)1 PostResult (org.collectiveone.common.dto.PostResult)1 Assignation (org.collectiveone.modules.assignations.Assignation)1 Bill (org.collectiveone.modules.assignations.Bill)1 InitiativeRelationship (org.collectiveone.modules.initiatives.InitiativeRelationship)1 Member (org.collectiveone.modules.initiatives.Member)1 InitiativeTransfer (org.collectiveone.modules.tokens.InitiativeTransfer)1 TokenMint (org.collectiveone.modules.tokens.TokenMint)1 TokenType (org.collectiveone.modules.tokens.TokenType)1 AssetsDto (org.collectiveone.modules.tokens.dto.AssetsDto)1