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;
}
Aggregations