Search in sources :

Example 1 with AssetsDto

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;
}
Also used : AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) Transactional(javax.transaction.Transactional)

Example 2 with 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;
}
Also used : AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) Transactional(javax.transaction.Transactional)

Example 3 with 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;
}
Also used : AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Initiative(org.collectiveone.modules.initiatives.Initiative) Transactional(javax.transaction.Transactional)

Example 4 with AssetsDto

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;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) ArrayList(java.util.ArrayList) AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) Transactional(javax.transaction.Transactional)

Example 5 with AssetsDto

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);
}
Also used : GetResult(org.collectiveone.common.dto.GetResult) AssetsDto(org.collectiveone.modules.tokens.dto.AssetsDto) UUID(java.util.UUID) Initiative(org.collectiveone.modules.initiatives.Initiative) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AssetsDto (org.collectiveone.modules.tokens.dto.AssetsDto)6 Transactional (javax.transaction.Transactional)5 Initiative (org.collectiveone.modules.initiatives.Initiative)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 GetResult (org.collectiveone.common.dto.GetResult)1 TokenType (org.collectiveone.modules.tokens.TokenType)1 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1