use of org.collectiveone.modules.assignations.Receiver in project CollectiveOneWebapp by CollectiveOne.
the class PeerReviewedAssignation method addReceiversEvaluations.
private void addReceiversEvaluations() {
/* Update percentages */
for (Receiver receiver : assignation.getReceivers()) {
ReceiverData receiverData = new ReceiverData();
receiverData.receiverId = receiver.getId().toString();
receiverData.isDonor = false;
if (receiver.getType() == ReceiverType.DONOR) {
receiverData.isDonor = true;
}
List<EvaluationGrade> gradesSet = getReceiverGradesSet(receiver.getId());
double mean = 0.0;
boolean evaluated;
if (gradesSet.size() == 0) {
/* no body evaluated this receiver? mean is zero then */
mean = 0.0;
evaluated = false;
} else {
evaluated = true;
/* compute the mean of evaluations set */
double totalWeight = 0.0;
for (EvaluationGrade grade : gradesSet) {
double thisWeight = grade.getEvaluator().getWeight();
totalWeight += thisWeight;
mean += grade.getPercent() * thisWeight;
}
mean = mean / totalWeight;
}
/* update the receiver evaluations */
List<EvaluationGrade> grades = getReceiverGrades(receiver.getId());
for (EvaluationGrade grade : grades) {
EvaluationData evaluation = new EvaluationData();
evaluation.setEvaluatorId(grade.getEvaluator().getId().toString());
evaluation.setWeight(grade.getEvaluator().getWeight());
if (evaluated) {
if (grade.getType() == EvaluationGradeType.SET) {
evaluation.setValue(grade.getPercent());
} else {
evaluation.setValue(mean);
}
} else {
evaluation.setValue(mean);
}
receiverData.evaluations.add(evaluation);
}
receiversData.add(receiverData);
}
}
use of org.collectiveone.modules.assignations.Receiver 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 "";
}
Aggregations