Search in sources :

Example 11 with Initiative

use of org.collectiveone.modules.initiatives.Initiative 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;
}
Also used : ArrayList(java.util.ArrayList) TransferDto(org.collectiveone.modules.tokens.dto.TransferDto) Initiative(org.collectiveone.modules.initiatives.Initiative) Member(org.collectiveone.modules.initiatives.Member) Transactional(javax.transaction.Transactional)

Example 12 with Initiative

use of org.collectiveone.modules.initiatives.Initiative 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 13 with Initiative

use of org.collectiveone.modules.initiatives.Initiative 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)

Example 14 with Initiative

use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.

the class TokenController method mintTokens.

@RequestMapping(path = "/token/{tokenId}/mint", method = RequestMethod.PUT)
public PostResult mintTokens(@PathVariable("tokenId") String tokenIdStr, @RequestBody TokenMintDto mintDto) {
    if (getLoggedUser() == null) {
        return new PostResult("error", "endpoint enabled users only", null);
    }
    UUID tokenId = UUID.fromString(tokenIdStr);
    if (governanceService.canMintTokens(tokenId, getLoggedUser().getC1Id()) == DecisionVerdict.DENIED) {
        return new PostResult("error", "not authorized", "");
    }
    Initiative initiative = initiativeService.findByTokenType_Id(tokenId);
    String result = tokenTransferService.mintToInitiative(tokenId, initiative.getId(), getLoggedUser().getC1Id(), mintDto);
    if (result.equals("success")) {
        return new PostResult("success", "tokens minted", tokenId.toString());
    } else {
        return new PostResult("error", "error while minting tokens", "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) Initiative(org.collectiveone.modules.initiatives.Initiative) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Initiative

use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.

the class FileService method uploadCardImage.

@Transactional
public PostResult uploadCardImage(UUID userId, UUID cardWrapperId, MultipartFile file) throws IOException {
    try (InputStream input = file.getInputStream()) {
        try {
            ImageIO.read(input).toString();
            Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
            String key = "CardImages/" + cardWrapperId.toString();
            FileStored fileUploaded = handleFileUpload(userId, key, file, initiative.getId());
            if (fileUploaded != null) {
                return new PostResult("success", "image uploaded", fileUploaded.getId().toString());
            }
            return new PostResult("error", "error uploading image", "");
        } catch (Exception e) {
            // It's not an image.
            return new PostResult("error", "only image files are supported", "");
        }
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) InputStream(java.io.InputStream) Initiative(org.collectiveone.modules.initiatives.Initiative) IOException(java.io.IOException) Transactional(javax.transaction.Transactional)

Aggregations

Initiative (org.collectiveone.modules.initiatives.Initiative)32 Transactional (javax.transaction.Transactional)15 UUID (java.util.UUID)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 PostResult (org.collectiveone.common.dto.PostResult)11 GetResult (org.collectiveone.common.dto.GetResult)10 ArrayList (java.util.ArrayList)4 TransferDto (org.collectiveone.modules.tokens.dto.TransferDto)4 ActivityDto (org.collectiveone.modules.activity.dto.ActivityDto)3 PageRequest (org.springframework.data.domain.PageRequest)3 Email (com.sendgrid.Email)2 Personalization (com.sendgrid.Personalization)2 Timestamp (java.sql.Timestamp)2 Assignation (org.collectiveone.modules.assignations.Assignation)2 ModelCardWrapper (org.collectiveone.modules.model.ModelCardWrapper)2 ModelSection (org.collectiveone.modules.model.ModelSection)2 ModelView (org.collectiveone.modules.model.ModelView)2 TokenMint (org.collectiveone.modules.tokens.TokenMint)2 TokenType (org.collectiveone.modules.tokens.TokenType)2 AssetsDto (org.collectiveone.modules.tokens.dto.AssetsDto)2