use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class EmailService method getActivityMessage.
private String getActivityMessage(Notification notification) {
Activity act = notification.getActivity();
Initiative initiative = act.getInitiative();
Initiative subInitiative = act.getSubInitiative();
String transferredAssets = (act.getInitiativeTransfers() != null) ? getTransferString(act.getInitiativeTransfers()) : "";
TokenType tokenType = notification.getActivity().getTokenType();
TokenMint mint = notification.getActivity().getMint();
Assignation assignation = notification.getActivity().getAssignation();
InitiativeTransfer transfer = notification.getActivity().getInitiativeTransfer();
ModelView modelView = notification.getActivity().getModelView();
ModelSection modelSection = notification.getActivity().getModelSection();
ModelCardWrapper modelCardWrapper = notification.getActivity().getModelCardWrapper();
ModelSection onSection = notification.getActivity().getOnSection();
ModelView onView = notification.getActivity().getOnView();
ModelSection fromSection = notification.getActivity().getFromSection();
ModelView fromView = notification.getActivity().getFromView();
String message = "";
switch(notification.getActivity().getType()) {
case INITIATIVE_CREATED:
return "<p>created the " + getInitiativeAnchor(initiative) + " initiative and added you as a member.</p>";
case SUBINITIATIVE_CREATED:
return "<p>created the " + getInitiativeAnchor(subInitiative) + " sub-initiative and transferred " + transferredAssets + " to it.</p>";
case INITIATIVE_EDITED:
return "<p>edited the name or purpose of the " + getInitiativeAnchor(initiative) + " initiative.</p>";
case INITIATIVE_DELETED:
return "<p>deleted the initiative " + getInitiativeAnchor(initiative) + ". All its assets, if any, have been transferred to its parent initiative," + "if the parent exist.</p> ";
case TOKENS_MINTED:
return "<p>minted " + mint.getValue() + " " + mint.getToken().getName() + " with motive: " + mint.getMotive() + ".</p>";
case TOKEN_CREATED:
return "<p>created a new token type called " + tokenType.getName() + " in " + getInitiativeAnchor(initiative) + ", and minted " + mint.getValue() + " units.</p>";
case PR_ASSIGNATION_CREATED:
Evaluator evaluator = null;
/* check if this member is an evaluator */
for (Evaluator thisEvaluator : assignation.getEvaluators()) {
if (thisEvaluator.getUser().getC1Id() == notification.getSubscriber().getUser().getC1Id()) {
evaluator = thisEvaluator;
}
}
String receiversList = "";
for (int ix = 0; ix < assignation.getReceivers().size(); ix++) {
/* first element starts the string */
if (ix == 0) {
receiversList += "";
}
/* next elements add a comma or 'and' and a space */
if (ix > 0) {
if (ix == assignation.getReceivers().size() - 1) {
receiversList += " and ";
} else {
receiversList += ", ";
}
}
if (assignation.getReceivers().get(ix).getUser().getC1Id() == notification.getSubscriber().getUser().getC1Id()) {
receiversList += "you";
} else {
receiversList += assignation.getReceivers().get(ix).getUser().getProfile().getNickname();
}
}
message = "<p>created a new peer-reviewed " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " to be distributed among " + receiversList + ", with motive: </p><p>" + assignation.getMotive() + ".</p>";
if (evaluator != null) {
Date closeDate = assignation.getConfig().getMaxClosureDate();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, ''yy");
message += "<p>You are one of the evaluators of this transfer! Please visit the " + getAssignationAnchor(assignation) + " page to make your evaluation.</p>" + "<p>You have until " + dateFormat.format(closeDate) + " at this time of the day to do it.</p>";
}
return message;
case PR_ASSIGNATION_DONE:
return "<p>Peer-reviewed " + getAssignationAnchor(assignation) + " with motive: </p>" + "<p>" + assignation.getMotive() + "</p>" + "<p>has been closed.</p>" + "<p>" + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " have been transferred to its receivers.</p>";
case D_ASSIGNATION_CREATED:
return "<p>made a direct " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " to " + assignation.getReceivers().get(0).getUser().getProfile().getNickname() + ", with motive: </p><p>" + assignation.getMotive() + ".</p>";
case INITIATIVE_TRANSFER:
return "<p>made a transfer of " + transfer.getValue() + " " + transfer.getTokenType().getName() + " to " + getInitiativeAnchor(transfer.getTo()) + ", with motive: </p><p>" + transfer.getMotive() + ".</p>";
case ASSIGNATION_REVERT_ORDERED:
message = "<p>wants to revert the " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ".</p> ";
for (Receiver receiver : assignation.getReceivers()) {
if (receiver.getUser().getC1Id().equals(notification.getSubscriber().getUser().getC1Id())) {
message += "<p>You were one of the transfer receivers, so you will have to approve this revert by " + "visiting the " + getAssignationAnchor(assignation) + " page.</p>";
}
}
return message;
case ASSIGNATION_REVERT_CANCELLED:
return "<p>ordered a revert of the " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ", but this revert has been cancelled.</p> ";
case ASSIGNATION_REVERTED:
return "<p>ordered a revert of the " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ", and the revert has been accepted.</p> ";
case ASSIGNATION_DELETED:
return "<p>deleted the ongoing " + getAssignationAnchor(assignation) + " of " + assignation.getBills().get(0).getValue() + " " + assignation.getBills().get(0).getTokenType().getName() + " with motive: " + assignation.getMotive() + ". No tokens have or will be transferred.</p> ";
case MODEL_VIEW_CREATED:
return "<p>created a new model view named " + getModelViewAnchor(modelView) + "</p> ";
case MODEL_VIEW_EDITED:
return "<p>edited the model " + getModelViewAnchor(modelView) + " view</p> ";
case MODEL_VIEW_DELETED:
return "<p>deleted the model " + getModelViewAnchor(modelView) + " view</p> ";
case MODEL_SECTION_CREATED:
if (onSection != null) {
message = "<p>created a new section " + getModelSectionAnchor(modelSection) + " under section " + getModelSectionAnchor(onSection) + "</p> ";
} else {
message = "<p>created a new section " + getModelSectionAnchor(modelSection) + " under the " + getModelViewAnchor(onView) + " view</p> ";
}
return message;
case MODEL_SECTION_EDITED:
return "<p>edited the model section " + getModelSectionAnchor(modelSection) + "</p> ";
case MODEL_SECTION_DELETED:
return "<p>deleted the model section " + getModelSectionAnchor(modelSection) + "</p> ";
case MODEL_CARDWRAPPER_CREATED:
return "<p>created a new card " + getModelCardWrapperAnchor(modelCardWrapper, onSection) + " in the " + getModelSectionAnchor(onSection) + " section</p> ";
case MODEL_CARDWRAPPER_EDITED:
return "<p>edited the model card " + getModelCardWrapperAnchor(modelCardWrapper) + "</p> ";
case MODEL_CARDWRAPPER_DELETED:
return "<p>deleted the model card " + getModelCardWrapperAnchor(modelCardWrapper) + "</p> ";
case MODEL_SECTION_ADDED:
if (onSection != null) {
message = "<p>added the section " + getModelSectionAnchor(modelSection) + " as sub-section of " + getModelSectionAnchor(onSection) + "</p> ";
} else {
message = "<p>added the section " + getModelSectionAnchor(modelSection) + " under the " + getModelViewAnchor(onView) + " view</p> ";
}
return message;
case MODEL_SECTION_MOVED:
if (onSection != null) {
if (fromSection != null) {
message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from section " + getModelSectionAnchor(fromSection) + " to section " + getModelSectionAnchor(onSection) + "</p> ";
} else {
message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from view " + getModelViewAnchor(fromView) + " to section " + getModelSectionAnchor(onSection) + "</p> ";
}
} else {
if (fromSection != null) {
message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from section " + getModelSectionAnchor(fromSection) + " to the " + getModelViewAnchor(onView) + "view</p> ";
} else {
message = "<p>moved the section " + getModelSectionAnchor(modelSection) + " from view " + getModelViewAnchor(fromView) + " to the " + getModelViewAnchor(onView) + " view</p> ";
}
}
return message;
case MODEL_SECTION_REMOVED:
if (fromSection != null) {
message = "<p>removed the section " + getModelSectionAnchor(modelSection) + " from section " + getModelSectionAnchor(fromSection) + "</p> ";
} else {
message = "<p>removed the section " + getModelSectionAnchor(modelSection) + " from the " + getModelSectionAnchor(fromSection) + " view</p> ";
}
return message;
case MODEL_CARDWRAPPER_ADDED:
return "<p>added the card " + getModelCardWrapperAnchor(modelCardWrapper, onSection) + " under section " + getModelSectionAnchor(onSection) + "</p> ";
case MODEL_CARDWRAPPER_MOVED:
return "<p>moved the card " + getModelCardWrapperAnchor(modelCardWrapper, onSection) + " from section " + getModelSectionAnchor(fromSection) + " to section " + getModelSectionAnchor(onSection) + "</p> ";
case MODEL_CARDWRAPPER_REMOVED:
return "<p>removed the card " + getModelCardWrapperAnchor(modelCardWrapper, fromSection) + " from section " + getModelSectionAnchor(fromSection) + "</p> ";
default:
break;
}
return "";
}
use of org.collectiveone.modules.initiatives.Initiative 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());
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class ModelController method getActivityUnderCard.
@RequestMapping(path = "/activity/model/card/{cardWrapperId}", method = RequestMethod.GET)
public GetResult<Page<ActivityDto>> getActivityUnderCard(@PathVariable("cardWrapperId") String cardWrapperIdStr, @RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam(name = "onlyMessages", defaultValue = "false") Boolean onlyMessages) {
UUID cardWrapperId = UUID.fromString(cardWrapperIdStr);
Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
if (!initiativeService.canAccess(initiative.getId(), getLoggedUserId())) {
return new GetResult<Page<ActivityDto>>("error", "access denied", null);
}
return modelService.getActivityResultUnderCard(cardWrapperId, new PageRequest(page, size), onlyMessages);
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class ModelController method countMessagesUnderSection.
@RequestMapping(path = "/initiative/{initiativeId}/model/section/{sectionId}/countMessages", method = RequestMethod.GET)
public GetResult<Long> countMessagesUnderSection(@PathVariable("initiativeId") String initiativeIdStr, @PathVariable("sectionId") String sectionIdStr, @RequestParam(name = "onlyMessages", defaultValue = "false") Boolean onlyMessages) {
UUID sectionId = UUID.fromString(sectionIdStr);
Initiative initiative = modelService.getSectionInitiative(sectionId);
if (!initiativeService.canAccess(initiative.getId(), getLoggedUserId())) {
return new GetResult<Long>("error", "access denied", null);
}
return modelService.countMessagesUnderSection(sectionId);
}
use of org.collectiveone.modules.initiatives.Initiative in project CollectiveOneWebapp by CollectiveOne.
the class ModelController method countMessagesUnderCard.
@RequestMapping(path = "/initiative/{initiativeId}/model/card/{cardWrapperId}/countMessages", method = RequestMethod.GET)
public GetResult<Long> countMessagesUnderCard(@PathVariable("initiativeId") String initiativeIdStr, @PathVariable("cardWrapperId") String cardWrapperIdStr, @RequestParam(name = "onlyMessages", defaultValue = "false") Boolean onlyMessages) {
UUID cardWrapperId = UUID.fromString(cardWrapperIdStr);
Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
if (!initiativeService.canAccess(initiative.getId(), getLoggedUserId())) {
return new GetResult<Long>("error", "access denied", null);
}
return modelService.countMessagesUnderCard(cardWrapperId, onlyMessages);
}
Aggregations