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