<commit_before>package org.motechproject.server.messagecampaign;

import org.motechproject.gateway.OutboundEventGateway;
import org.motechproject.model.MotechEvent;
import org.motechproject.server.event.annotations.MotechListener;
import org.motechproject.server.messagecampaign.dao.AllMessageCampaigns;
import org.motechproject.server.messagecampaign.domain.message.CampaignMessage;
import org.springframework.beans.factory.annotation.Autowired;

public class CampaignMessageHandler {

    private OutboundEventGateway outboundEventGateway;
    private AllMessageCampaigns allMessageCampaigns;

    @Autowired
    public CampaignMessageHandler(OutboundEventGateway outboundEventGateway, AllMessageCampaigns allMessageCampaigns) {
        this.outboundEventGateway = outboundEventGateway;
        this.allMessageCampaigns = allMessageCampaigns;
    }

    @MotechListener(subjects = {EventKeys.MESSAGE_CAMPAIGN_SEND_EVENT_SUBJECT})
    public void handleEvent(MotechEvent motechEvent) {
        CampaignMessage campaignMessage = getCampaignMessage(motechEvent);
        outboundEventGateway.sendEventMessage(createNewMotechEvent(motechEvent, campaignMessage));
    }

    private CampaignMessage getCampaignMessage(MotechEvent motechEvent) {
        String campaignName = (String) motechEvent.getParameters().get(EventKeys.CAMPAIGN_NAME_KEY);
        String messageKey = (String) motechEvent.getParameters().get(EventKeys.MESSAGE_KEY);
        return allMessageCampaigns.get(campaignName, messageKey);
    }<commit_msg>Must be annotated as a component in order for it to be registered as a listener<commit_after>package org.motechproject.server.messagecampaign;

import org.motechproject.gateway.OutboundEventGateway;
import org.motechproject.model.MotechEvent;
import org.motechproject.server.event.annotations.MotechListener;
import org.motechproject.server.messagecampaign.dao.AllMessageCampaigns;
import org.motechproject.server.messagecampaign.domain.message.CampaignMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CampaignMessageHandler {

    private OutboundEventGateway outboundEventGateway;
    private AllMessageCampaigns allMessageCampaigns;

    @Autowired
    public CampaignMessageHandler(OutboundEventGateway outboundEventGateway, AllMessageCampaigns allMessageCampaigns) {
        this.outboundEventGateway = outboundEventGateway;
        this.allMessageCampaigns = allMessageCampaigns;
    }

    @MotechListener(subjects = {EventKeys.MESSAGE_CAMPAIGN_SEND_EVENT_SUBJECT})
    public void handleEvent(MotechEvent motechEvent) {
        CampaignMessage campaignMessage = getCampaignMessage(motechEvent);
        outboundEventGateway.sendEventMessage(createNewMotechEvent(motechEvent, campaignMessage));
    }

    private CampaignMessage getCampaignMessage(MotechEvent motechEvent) {
        String campaignName = (String) motechEvent.getParameters().get(EventKeys.CAMPAIGN_NAME_KEY);
        String messageKey = (String) motechEvent.getParameters().get(EventKeys.MESSAGE_KEY);
        return allMessageCampaigns.get(campaignName, messageKey);
    }
{'fraction_non_alphanumeric': 0.06984829329962074, 'fraction_numerical': 0.0, 'mean_word_length': 6.033333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837357', 'n_tokens_mistral': 893, 'n_tokens_neox': 861, 'n_words': 136}