use of org.collectiveone.modules.tokens.TokenType in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method createNewToken.
@Transactional
public PostResult createNewToken(UUID initiativeId, AssetsDto tokenDto, UUID userId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
TokenType token = tokenService.create(tokenDto.getAssetName(), "T");
initiative.getTokenTypes().add(token);
initiative = initiativeRepository.save(initiative);
tokenService.mintToHolder(token.getId(), initiative.getId(), tokenDto.getOwnedByThisHolder(), TokenHolderType.INITIATIVE);
AppUser orderedBy = appUserRepository.findByC1Id(userId);
TokenMint mint = new TokenMint();
mint.setToken(token);
mint.setOrderedBy(orderedBy);
mint.setToHolder(initiativeId);
mint.setMotive("Token creation.");
mint.setNotes("");
mint.setValue(tokenDto.getOwnedByThisHolder());
mint = tokenMintRespository.save(mint);
activityService.newTokenCreated(initiative, orderedBy, token, mint);
return new PostResult("success", "initiative created and tokens created", initiative.getId().toString());
}
use of org.collectiveone.modules.tokens.TokenType in project CollectiveOneWebapp by CollectiveOne.
the class AssignationService method createAssignation.
public PostResult createAssignation(UUID initiativeId, AssignationDto assignationDto, UUID creatorId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
Assignation assignation = new Assignation();
assignation.setType(AssignationType.valueOf(assignationDto.getType()));
assignation.setMotive(assignationDto.getMotive());
assignation.setNotes(assignationDto.getNotes());
assignation.setCreator(appUserRepository.findByC1Id(creatorId));
assignation.setCreationDate(new Timestamp(System.currentTimeMillis()));
assignation.setState(AssignationState.valueOf(assignationDto.getConfig().getStartState()));
assignation.setInitiative(initiative);
assignation.getAlsoInInitiatives().addAll(initiativeService.getParentGenealogyInitiatives(initiative.getId()));
AssignationConfig config = new AssignationConfig();
config.setSelfBiasVisible(Boolean.valueOf(assignationDto.getConfig().getSelfBiasVisible()));
config.setEvaluationsVisible(Boolean.valueOf(assignationDto.getConfig().getEvaluationsVisible()));
config.setDurationDays(assignationDto.getConfig().getMaxDuration());
if (assignation.getState() == AssignationState.OPEN) {
config.setMinClosureDate(new Timestamp(System.currentTimeMillis()));
config.setMaxClosureDate(new Timestamp(System.currentTimeMillis() + assignationDto.getConfig().getMaxDuration() * DAYS_TO_MS));
}
config = assignationConfigRepository.save(config);
assignation.setConfig(config);
assignation = assignationRepository.save(assignation);
for (ReceiverDto receiverDto : assignationDto.getReceivers()) {
Receiver receiver = new Receiver();
receiver.setUser(appUserRepository.findByC1Id(UUID.fromString(receiverDto.getUser().getC1Id())));
receiver.setAssignation(assignation);
receiver.setAssignedPercent(receiverDto.getPercent());
receiver.setState(ReceiverState.PENDING);
if (receiverDto.getIsDonor()) {
receiver.setType(ReceiverType.DONOR);
} else {
receiver.setType(ReceiverType.NORMAL);
}
receiver = receiverRepository.save(receiver);
assignation.getReceivers().add(receiver);
}
for (BillDto billDto : assignationDto.getAssets()) {
TokenType tokenType = tokenService.getTokenType(UUID.fromString(billDto.getAssetId()));
Bill bill = new Bill();
bill.setAssignation(assignation);
bill.setTokenType(tokenType);
bill.setValue(billDto.getValue());
bill = billRepository.save(bill);
assignation.getBills().add(bill);
}
switch(assignation.getType()) {
case DIRECT:
for (Bill bill : assignation.getBills()) {
for (Receiver receiver : assignation.getReceivers()) {
double value = bill.getValue() * receiver.getAssignedPercent() / 100.0;
PostResult result = tokenTransferService.transferFromInitiativeToUser(assignation.getInitiative().getId(), receiver.getUser().getC1Id(), bill.getTokenType().getId(), value);
if (result.getResult().equals("success")) {
receiver.setState(ReceiverState.RECEIVED);
receiver.setTransfer(memberTransferRepository.findById(UUID.fromString(result.getElementId())));
receiverRepository.save(receiver);
}
}
}
assignation.setState(AssignationState.DONE);
assignationRepository.save(assignation);
activityService.directAssignationCreated(assignation, appUserRepository.findByC1Id(creatorId));
break;
case PEER_REVIEWED:
for (EvaluatorDto evaluatorDto : assignationDto.getEvaluators()) {
Evaluator evaluator = new Evaluator();
evaluator.setUser(appUserRepository.findByC1Id(UUID.fromString(evaluatorDto.getUser().getC1Id())));
evaluator.setAssignation(assignation);
evaluator.setState(EvaluatorState.PENDING);
/* Weight logic TBD */
evaluator.setWeight(1.0);
evaluator = evaluatorRepository.save(evaluator);
/* Create the grades of all evaluators already */
for (Receiver receiver : assignation.getReceivers()) {
EvaluationGrade grade = new EvaluationGrade();
grade.setAssignation(assignation);
grade.setEvaluator(evaluator);
grade.setReceiver(receiver);
grade.setPercent(0.0);
grade.setType(EvaluationGradeType.SET);
grade.setState(EvaluationGradeState.PENDING);
grade = evaluationGradeRepository.save(grade);
evaluator.getGrades().add(grade);
}
assignation.getEvaluators().add(evaluator);
}
activityService.peerReviewedAssignationCreated(assignation, appUserRepository.findByC1Id(creatorId));
break;
}
return new PostResult("success", "success", assignation.getId().toString());
}
Aggregations