use of org.collectiveone.modules.tokens.dto.AssetsDto in project CollectiveOneWebapp by CollectiveOne.
the class TokenService method getTokensOfHolderDto.
@Transactional
public AssetsDto getTokensOfHolderDto(UUID tokenTypeId, UUID holderId) {
AssetsDto assetsDto = getTokenDto(tokenTypeId);
/* Amount of tokens held by the input initiative */
assetsDto.setHolderId(holderId.toString());
assetsDto.setOwnedByThisHolder(getHolder(tokenTypeId, holderId).getTokens());
return assetsDto;
}
use of org.collectiveone.modules.tokens.dto.AssetsDto 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 org.collectiveone.modules.tokens.dto.AssetsDto 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.AssetsDto in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method getInitiativeAssetsDtoLight.
/**
*/
@Transactional
public List<AssetsDto> getInitiativeAssetsDtoLight(UUID id) {
Initiative initiative = initiativeRepository.findById(id);
List<TokenType> ownTokens = initiative.getTokenTypes();
List<TokenType> tokenTypes = tokenService.getTokenTypesHeldBy(initiative.getId());
/* add own tokens even if the initiative does not have them */
for (TokenType own : ownTokens) {
if (!tokenTypes.contains(own)) {
tokenTypes.add(own);
}
}
List<AssetsDto> assets = new ArrayList<AssetsDto>();
for (TokenType token : tokenTypes) {
AssetsDto asset = new AssetsDto();
asset.setAssetId(token.getId().toString());
asset.setAssetName(token.getName());
assets.add(asset);
}
return assets;
}
use of org.collectiveone.modules.tokens.dto.AssetsDto in project CollectiveOneWebapp by CollectiveOne.
the class TokenController method getToken.
@RequestMapping(path = "/token/{id}", method = RequestMethod.GET)
public GetResult<AssetsDto> getToken(@PathVariable("id") String id, @RequestParam(defaultValue = "false") Boolean includeSubinitiatives, @RequestParam(defaultValue = "") String initiativeIdStr) {
UUID tokenTypeId = UUID.fromString(id);
Initiative initiative = initiativeService.findByTokenType_Id(tokenTypeId);
if (!initiativeService.canAccess(initiative.getId(), getLoggedUserId())) {
return new GetResult<AssetsDto>("error", "access denied", null);
}
AssetsDto assetDto = tokenService.getTokenDto(UUID.fromString(id));
if (includeSubinitiatives) {
UUID initiativeContextId = UUID.fromString(initiativeIdStr);
if (!initiativeService.canAccess(initiativeContextId, getLoggedUserId())) {
return new GetResult<AssetsDto>("error", "access denied", null);
}
assetDto = tokenTransferService.getTokenDistribution(tokenTypeId, initiativeContextId);
}
return new GetResult<AssetsDto>("success", "initiative retrieved", assetDto);
}
Aggregations