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