Search in sources :

Example 1 with InitiativeRelationship

use of org.collectiveone.modules.initiatives.InitiativeRelationship 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)

Aggregations

ArrayList (java.util.ArrayList)1 Transactional (javax.transaction.Transactional)1 Initiative (org.collectiveone.modules.initiatives.Initiative)1 InitiativeRelationship (org.collectiveone.modules.initiatives.InitiativeRelationship)1 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)1