<commit_before>package org.motechproject.nms.api.web;

import org.motechproject.event.MotechEvent;
import org.motechproject.event.listener.EventRelay;
import org.motechproject.nms.api.web.contract.LogHelper;
import org.motechproject.nms.api.web.contract.mobileAcademy.CourseResponse;
import org.motechproject.nms.api.web.contract.mobileAcademy.CourseVersionResponse;
import org.motechproject.nms.api.web.contract.mobileAcademy.GetBookmarkResponse;
import org.motechproject.nms.api.web.contract.mobileAcademy.SaveBookmarkRequest;
import org.motechproject.nms.api.web.contract.mobileAcademy.SmsStatusRequest;
import org.motechproject.nms.api.web.contract.mobileAcademy.sms.DeliveryInfo;
import org.motechproject.nms.api.web.converter.MobileAcademyConverter;
import org.motechproject.nms.api.web.validator.MobileAcademyValidator;
import org.motechproject.nms.mobileacademy.dto.MaBookmark;
import org.motechproject.nms.mobileacademy.dto.MaCourse;
import org.motechproject.nms.mobileacademy.exception.CourseNotCompletedException;
import org.motechproject.nms.mobileacademy.service.MobileAcademyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;
import java.util.Map;


/**
 * Mobile Academy controller
 */
@RequestMapping("mobileacademy")
@Controller
public class MobileAcademyController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MobileAcademyController.class);

    private static final String SMS_STATUS_SUBJECT = "nms.ma.sms.deliveryStatus";

    /**
     * MA service to handle all business logic
     */
    @Autowired
    private MobileAcademyService mobileAcademyService;

    /**
     * Event relay service to handle async notifications
     */
    private EventRelay eventRelay;

    // Default constructor for CGLIB generation
    public MobileAcademyController() {
        super();
    }
    /**
     * Constructor for controller
     * @param mobileAcademyService mobile academy service
     * @param eventRelay event relay service
     */
    @Autowired
    public MobileAcademyController(MobileAcademyService mobileAcademyService, EventRelay eventRelay) {
        this.mobileAcademyService = mobileAcademyService;
        this.eventRelay = eventRelay;
    }

    /**
     *
     * 2.2.2.1 Get MA Course – Request
     *
     * Get course
     * @return course response object
     */
    @RequestMapping(
            value = "/course",
            method = RequestMethod.GET)
    @ResponseBody
    public CourseResponse getCourse() {

        log("/mobileacademy/course");

        MaCourse getCourse = mobileAcademyService.getCourse();

        if (getCourse == null) {
            LOGGER.error("No course found in database. Check course ingestion and name");
            throw new InternalError(String.format(NOT_FOUND, "course"));
        }

        CourseResponse response = MobileAcademyConverter.convertCourseDto(getCourse);

        if (response != null) {
            return response;
        } else {
            LOGGER.error("Failed dto mapping, check object mapping");
            throw new InternalError(String.format(INVALID, "CourseResponse"));
        }

    }

    /**
     * Get the version of the course
     * @return Integer representing the timestamp since epoch
     */
    @RequestMapping(
            value = "/courseVersion",
            method = RequestMethod.GET)
    @ResponseBody
    public CourseVersionResponse getCourseVersion() {

        log("/mobileacademy/courseVersion");

        return new CourseVersionResponse(mobileAcademyService.getCourseVersion());
    }

    /**
     * Get bookmark for a user
     * @param callingNumber number of the caller
     * @param callId unique tracking id for the call
     * @return serialized json bookmark response
     */
    @RequestMapping(
            value = "/bookmarkWithScore",
            method = RequestMethod.GET)
    public GetBookmarkResponse getBookmarkWithScore(@RequestParam Long callingNumber,<commit_msg>Fixes NMS-223 (I think)<commit_after>package org.motechproject.nms.api.web;

import org.motechproject.event.MotechEvent;
import org.motechproject.event.listener.EventRelay;
import org.motechproject.nms.api.web.contract.LogHelper;
import org.motechproject.nms.api.web.contract.mobileAcademy.CourseResponse;
import org.motechproject.nms.api.web.contract.mobileAcademy.CourseVersionResponse;
import org.motechproject.nms.api.web.contract.mobileAcademy.GetBookmarkResponse;
import org.motechproject.nms.api.web.contract.mobileAcademy.SaveBookmarkRequest;
import org.motechproject.nms.api.web.contract.mobileAcademy.SmsStatusRequest;
import org.motechproject.nms.api.web.contract.mobileAcademy.sms.DeliveryInfo;
import org.motechproject.nms.api.web.converter.MobileAcademyConverter;
import org.motechproject.nms.api.web.validator.MobileAcademyValidator;
import org.motechproject.nms.mobileacademy.dto.MaBookmark;
import org.motechproject.nms.mobileacademy.dto.MaCourse;
import org.motechproject.nms.mobileacademy.exception.CourseNotCompletedException;
import org.motechproject.nms.mobileacademy.service.MobileAcademyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;
import java.util.Map;


/**
 * Mobile Academy controller
 */
@RequestMapping("mobileacademy")
@Controller
public class MobileAcademyController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MobileAcademyController.class);

    private static final String SMS_STATUS_SUBJECT = "nms.ma.sms.deliveryStatus";

    /**
     * MA service to handle all business logic
     */
    @Autowired
    private MobileAcademyService mobileAcademyService;

    /**
     * Event relay service to handle async notifications
     */
    private EventRelay eventRelay;

    // Default constructor for CGLIB generation
    public MobileAcademyController() {
        super();
    }
    /**
     * Constructor for controller
     * @param mobileAcademyService mobile academy service
     * @param eventRelay event relay service
     */
    @Autowired
    public MobileAcademyController(MobileAcademyService mobileAcademyService, EventRelay eventRelay) {
        this.mobileAcademyService = mobileAcademyService;
        this.eventRelay = eventRelay;
    }

    /**
     *
     * 2.2.2.1 Get MA Course – Request
     *
     * Get course
     * @return course response object
     */
    @RequestMapping(
            value = "/course",
            method = RequestMethod.GET)
    @ResponseBody
    public CourseResponse getCourse() {

        log("/mobileacademy/course");

        MaCourse getCourse = mobileAcademyService.getCourse();

        if (getCourse == null) {
            LOGGER.error("No course found in database. Check course ingestion and name");
            throw new InternalError(String.format(NOT_FOUND, "course"));
        }

        CourseResponse response = MobileAcademyConverter.convertCourseDto(getCourse);

        if (response != null) {
            return response;
        } else {
            LOGGER.error("Failed dto mapping, check object mapping");
            throw new InternalError(String.format(INVALID, "CourseResponse"));
        }

    }

    /**
     * Get the version of the course
     * @return Integer representing the timestamp since epoch
     */
    @RequestMapping(
            value = "/courseVersion",
            method = RequestMethod.GET)
    @ResponseBody
    public CourseVersionResponse getCourseVersion() {

        log("/mobileacademy/courseVersion");

        return new CourseVersionResponse(mobileAcademyService.getCourseVersion());
    }

    /**
     * Get bookmark for a user
     * @param callingNumber number of the caller
     * @param callId unique tracking id for the call
     * @return serialized json bookmark response
     */
    @RequestMapping(
            value = "/bookmarkWithScore",
            method = RequestMethod.GET)
    @ResponseBody
    public GetBookmarkResponse getBookmarkWithScore(@RequestParam Long callingNumber,
{'fraction_non_alphanumeric': 0.08840139009556908, 'fraction_numerical': 0.001629018245004344, 'mean_word_length': 3.6746192893401015, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5046443', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2483, 'n_words': 513}