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