<commit_before>package org.xcolab.portlets.proposals.view.action;


import com.ext.portlet.NoSuchProposalContestPhaseAttributeException;
import com.ext.portlet.ProposalAttributeKeys;
import com.ext.portlet.messaging.MessageUtil;
import com.ext.portlet.model.ContestPhaseRibbonType;
import com.ext.portlet.model.ProposalContestPhaseAttribute;
import com.ext.portlet.service.ContestLocalServiceUtil;
import com.ext.portlet.service.MessageLocalServiceUtil;
import com.ext.portlet.service.MessageRecipientStatusLocalServiceUtil;
import com.ext.portlet.service.ProposalContestPhaseAttributeLocalServiceUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.liferay.util.mail.MailEngineException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.xcolab.portlets.proposals.exceptions.ProposalsAuthorizationException;
import org.xcolab.portlets.proposals.requests.JudgeProposalBean;
import org.xcolab.portlets.proposals.utils.ProposalsContext;
import org.xcolab.portlets.proposals.wrappers.ContestTeamRoleWrapper;
import org.xcolab.portlets.proposals.wrappers.ContestWrapper;

import javax.mail.internet.AddressException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("view")
public class JudgeProposalActionController {

    @Autowired
    private ProposalsContext proposalsContext;

    @RequestMapping(params = {"action=sendEmails"})
    public void sendEmails(ActionRequest request, Model model, ActionResponse response) {
        //TODO code me
    }

    @RequestMapping(params = {"action=saveJudgeRating"})
    public void saveJudgeRating(ActionRequest request, Model model,
                                ActionResponse response, @Valid JudgeProposalBean judgeProposalBean,
                                BindingResult result)
            throws PortalException, SystemException, ProposalsAuthorizationException {
        long proposalId = proposalsContext.getProposal(request).getProposalId();
        long contestPhaseId = proposalsContext.getContestPhase(request).getContestPhasePK();
        // save judge rating
        persistAttribute(proposalId, contestPhaseId, ProposalAttributeKeys.JUDGE_RATING, 0, judgeProposalBean.getJudgeRating(), null);
        // save judge action
        persistAttribute(proposalId, contestPhaseId, ProposalAttributeKeys.JUDGE_ACTION, 0, judgeProposalBean.getJudgeAction().getAttributeValue(), null);
        // save judge comment
        persistAttribute(proposalId, contestPhaseId, ProposalAttributeKeys.JUDGE_COMMENT, 0, -1, judgeProposalBean.getJudgeComment());
    }

    @RequestMapping(params = {"action=sendJudgeRating"})
    public void sendJudgeRating(ActionRequest request, Model model,
                                ActionResponse response, @RequestParam("judgeComment") String judgeComment)
            throws PortalException, SystemException, ProposalsAuthorizationException, AddressException, MailEngineException {
        long proposalId = proposalsContext.getProposal(request).getProposalId();

        List<Long> recipientIds = new ArrayList<Long>();
        String subject = "Judge comment from " + proposalsContext.getUser(request).getScreenName() + " for proposal [" + proposalId + "]";

        ContestWrapper cr = new ContestWrapper(proposalsContext.getContest(request));
        for (User fellow : cr.getContestFellows()) {
            recipientIds.add(fellow.getUserId());
        }

        MessageUtil.sendMessage(subject, judgeComment, proposalsContext.getUser(request).getUserId(),
                proposalsContext.getUser(request).getUserId(), recipientIds, null);

    }

    @RequestMapping(params = {"action=saveFellowRating"})
    public void saveFellowRating(ActionRequest request, Model model,
                                 ActionResponse response, @Valid JudgeProposalBean judgeProposalBean,
                                 BindingResult result) throws PortalException, SystemException, ProposalsAuthorizationException {
        long proposalId = proposalsContext.getProposal(request).getProposalId();<commit_msg>null checks for judges tab<commit_after>package org.xcolab.portlets.proposals.view.action;


import com.ext.portlet.NoSuchProposalContestPhaseAttributeException;
import com.ext.portlet.ProposalAttributeKeys;
import com.ext.portlet.messaging.MessageUtil;
import com.ext.portlet.model.ContestPhaseRibbonType;
import com.ext.portlet.model.ProposalContestPhaseAttribute;
import com.ext.portlet.service.ContestLocalServiceUtil;
import com.ext.portlet.service.MessageLocalServiceUtil;
import com.ext.portlet.service.MessageRecipientStatusLocalServiceUtil;
import com.ext.portlet.service.ProposalContestPhaseAttributeLocalServiceUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.liferay.util.mail.MailEngineException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.xcolab.portlets.proposals.exceptions.ProposalsAuthorizationException;
import org.xcolab.portlets.proposals.requests.JudgeProposalBean;
import org.xcolab.portlets.proposals.utils.ProposalsContext;
import org.xcolab.portlets.proposals.wrappers.ContestTeamRoleWrapper;
import org.xcolab.portlets.proposals.wrappers.ContestWrapper;

import javax.mail.internet.AddressException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("view")
public class JudgeProposalActionController {

    @Autowired
    private ProposalsContext proposalsContext;

    @RequestMapping(params = {"action=sendEmails"})
    public void sendEmails(ActionRequest request, Model model, ActionResponse response) {
        //TODO code me
    }

    @RequestMapping(params = {"action=saveJudgeRating"})
    public void saveJudgeRating(ActionRequest request, Model model,
                                ActionResponse response, @Valid JudgeProposalBean judgeProposalBean,
                                BindingResult result)
            throws PortalException, SystemException, ProposalsAuthorizationException {
        long proposalId = proposalsContext.getProposal(request).getProposalId();
        long contestPhaseId = proposalsContext.getContestPhase(request).getContestPhasePK();

        // save judge rating
        if (judgeProposalBean.getJudgeRating() != null)
            persistAttribute(proposalId, contestPhaseId, ProposalAttributeKeys.JUDGE_RATING, 0, judgeProposalBean.getJudgeRating(), null);

        // save judge action
        if (judgeProposalBean.getJudgeAction() != null)
            persistAttribute(proposalId, contestPhaseId, ProposalAttributeKeys.JUDGE_ACTION, 0, judgeProposalBean.getJudgeAction().getAttributeValue(), null);
        // save judge comment

        if (judgeProposalBean.getJudgeComment() != null)
            persistAttribute(proposalId, contestPhaseId, ProposalAttributeKeys.JUDGE_COMMENT, 0, -1, judgeProposalBean.getJudgeComment());
    }

    @RequestMapping(params = {"action=sendJudgeRating"})
    public void sendJudgeRating(ActionRequest request, Model model,
                                ActionResponse response, @RequestParam("judgeComment") String judgeComment)
            throws PortalException, SystemException, ProposalsAuthorizationException, AddressException, MailEngineException {
        long proposalId = proposalsContext.getProposal(request).getProposalId();

        List<Long> recipientIds = new ArrayList<Long>();
        String subject = "Judge comment from " + proposalsContext.getUser(request).getScreenName() + " for proposal [" + proposalId + "]";

        ContestWrapper cr = new ContestWrapper(proposalsContext.getContest(request));
        for (User fellow : cr.getContestFellows()) {
            recipientIds.add(fellow.getUserId());
        }

        MessageUtil.sendMessage(subject, judgeComment, proposalsContext.getUser(request).getUserId(),
                proposalsContext.getUser(request).getUserId(), recipientIds, null);

    }

    @RequestMapping(params = {"action=saveFellowRating"})
    public void saveFellowRating(ActionRequest request, Model model,
                                 ActionResponse response, @Valid JudgeProposalBean judgeProposalBean,
                                 BindingResult result) throws PortalException, SystemException, ProposalsAuthorizationException {
        long proposalId = proposalsContext.getProposal(request).getProposalId();
{'fraction_non_alphanumeric': 0.08711682292215317, 'fraction_numerical': 0.0008427262193194986, 'mean_word_length': 4.568328445747801, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6749781', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2478, 'n_words': 440}