use of org.collectiveone.modules.tokens.dto.TransferDto in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method transferAssets.
@Transactional
private PostResult transferAssets(UUID initiativeId, NewInitiativeDto initiativeDto, UUID creatorId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
if (!initiativeDto.getAsSubinitiative()) {
/* if is not a sub-initiative, then create a token for this initiative */
if (initiativeDto.getCreateToken()) {
TokenType token = tokenService.create(initiativeDto.getOwnTokens().getAssetName(), "T");
initiative.getTokenTypes().add(token);
initiative = initiativeRepository.save(initiative);
tokenService.mintToHolder(token.getId(), initiative.getId(), initiativeDto.getOwnTokens().getOwnedByThisHolder(), TokenHolderType.INITIATIVE);
TokenMint mint = new TokenMint();
mint.setToken(token);
mint.setOrderedBy(appUserRepository.findByC1Id(creatorId));
mint.setToHolder(initiativeId);
mint.setMotive("Initiative creation.");
mint.setNotes("");
mint.setValue(initiativeDto.getOwnTokens().getOwnedByThisHolder());
mint = tokenMintRespository.save(mint);
}
return new PostResult("success", "initiative tokens created", initiative.getId().toString());
} else {
Initiative parent = initiativeRepository.findById(UUID.fromString(initiativeDto.getParentInitiativeId()));
/* if it is a sub-initiative, then link to parent initiative */
InitiativeRelationship relationship = new InitiativeRelationship();
relationship.setInitiative(initiative);
relationship.setType(InitiativeRelationshipType.IS_ATTACHED_SUB);
relationship.setOfInitiative(parent);
relationship = initiativeRelationshipRepository.save(relationship);
List<InitiativeTransfer> transfers = new ArrayList<InitiativeTransfer>();
/* and transfer parent assets to child */
for (TransferDto thisTransfer : initiativeDto.getAssetsTransfers()) {
/* ignore zero token transfers */
if (thisTransfer.getValue() > 0) {
TokenType token = tokenService.getTokenType(UUID.fromString(thisTransfer.getAssetId()));
tokenService.transfer(token.getId(), parent.getId(), initiative.getId(), thisTransfer.getValue(), TokenHolderType.INITIATIVE);
/* upper layer keeping track of who transfered what to whom */
InitiativeTransfer transfer = new InitiativeTransfer();
transfer.setFrom(parent);
transfer.setTo(initiative);
transfer.setTokenType(token);
transfer.setValue(thisTransfer.getValue());
transfer.setMotive("sub-initiative creation");
transfer.setNotes("");
transfer.setOrderDate(new Timestamp(System.currentTimeMillis()));
transfer = initiativeTransferRepository.save(transfer);
transfers.add(transfer);
}
}
initiative.getRelationships().add(relationship);
initiativeRepository.save(initiative);
activityService.newSubinitiativeCreated(parent, initiative.getCreator(), initiative, transfers);
}
return new PostResult("success", "sub initiative created and tokens transferred", initiative.getId().toString());
}
use of org.collectiveone.modules.tokens.dto.TransferDto in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeTransfer method toDto.
public TransferDto toDto() {
TransferDto dto = new TransferDto();
dto.setAssetId(tokenType.getId().toString());
dto.setAssetName(tokenType.getName());
dto.setSenderId(from.getId().toString());
dto.setSenderName(from.getMeta().getName());
dto.setReceiverId(to.getId().toString());
dto.setReceiverName(to.getMeta().getName());
if (orderDate != null)
dto.setOrderDate(orderDate.getTime());
if (orderedBy != null)
dto.setOrderedBy(orderedBy.toDtoLight());
dto.setMotive(motive);
dto.setNotes(notes);
dto.setValue(value);
return dto;
}
use of org.collectiveone.modules.tokens.dto.TransferDto in project CollectiveOneWebapp by CollectiveOne.
the class TokenTransferService method getTransfersPending.
@Transactional
public List<TransferDto> getTransfersPending(UUID initiativeId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
List<TransferDto> transfersPending = new ArrayList<TransferDto>();
List<Assignation> assignations = assignationService.getOpenAssignations(initiativeId);
for (Assignation assignation : assignations) {
for (Bill bill : assignation.getBills()) {
TransferDto dto = new TransferDto();
dto.setAssetId(bill.getTokenType().getId().toString());
dto.setAssetName(bill.getTokenType().getName());
dto.setSenderId(initiative.getId().toString());
dto.setSenderName(initiative.getMeta().getName());
dto.setValue(bill.getValue());
transfersPending.add(dto);
}
}
return transfersPending;
}
Aggregations