Search in sources :

Example 1 with Receiver

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);
    }
}
Also used : EvaluationGrade(org.collectiveone.modules.assignations.EvaluationGrade) Receiver(org.collectiveone.modules.assignations.Receiver)

Example 2 with Receiver

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 "";
}
Also used : ModelCardWrapper(org.collectiveone.modules.model.ModelCardWrapper) TokenMint(org.collectiveone.modules.tokens.TokenMint) Receiver(org.collectiveone.modules.assignations.Receiver) Assignation(org.collectiveone.modules.assignations.Assignation) Evaluator(org.collectiveone.modules.assignations.Evaluator) Initiative(org.collectiveone.modules.initiatives.Initiative) TokenMint(org.collectiveone.modules.tokens.TokenMint) Date(java.util.Date) TokenType(org.collectiveone.modules.tokens.TokenType) ModelSection(org.collectiveone.modules.model.ModelSection) ModelView(org.collectiveone.modules.model.ModelView) InitiativeTransfer(org.collectiveone.modules.tokens.InitiativeTransfer) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Receiver (org.collectiveone.modules.assignations.Receiver)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Assignation (org.collectiveone.modules.assignations.Assignation)1 EvaluationGrade (org.collectiveone.modules.assignations.EvaluationGrade)1 Evaluator (org.collectiveone.modules.assignations.Evaluator)1 Initiative (org.collectiveone.modules.initiatives.Initiative)1 ModelCardWrapper (org.collectiveone.modules.model.ModelCardWrapper)1 ModelSection (org.collectiveone.modules.model.ModelSection)1 ModelView (org.collectiveone.modules.model.ModelView)1 InitiativeTransfer (org.collectiveone.modules.tokens.InitiativeTransfer)1 TokenMint (org.collectiveone.modules.tokens.TokenMint)1 TokenType (org.collectiveone.modules.tokens.TokenType)1