<commit_before>package org.openlmis.admin.controller;

import org.openlmis.core.domain.Product;
import org.openlmis.core.handler.ProductImportHandler;
import org.openlmis.upload.parser.CSVParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

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

@Controller
@RequestMapping("/resources/pages/admin")
public class UploadController {

    private CSVParser csvParser;
    private ProductImportHandler handler;
    private final Map<String, Class[]> modelMap = new HashMap<String, Class[]>();

    @Autowired
    public UploadController(CSVParser csvParser, ProductImportHandler handler) {
        this.csvParser = csvParser;
        this.handler = handler;
        modelMap.put("product", new Class[]{Product.class, ProductImportHandler.class});
    }

    @RequestMapping(value = "/upload", method = RequestMethod.POST, headers = "Accept=application/json")
    public ModelAndView upload(@RequestParam(value = "csvFile", required = true) MultipartFile multipartFile,
                               @RequestParam(value = "model", required = true) String model) {

        ModelAndView modelAndView = new ModelAndView();

        try {
            Class[] modelAndHandler = modelMap.get(model);
            if (modelAndHandler == null) {
                modelAndView.addObject("error", "Incorrect file");
            } else {
                csvParser.process(multipartFile.getInputStream(), modelAndHandler[0], handler);
                modelAndView.addObject("message", "uploaded successfully");
            }
        } catch (Exception e) {
            modelAndView.addObject("error", e.getMessage());
        }
        return modelAndView;
    }
}<commit_msg>|#122| Balvinder & Rahul | removed handler lookup<commit_after>package org.openlmis.admin.controller;

import org.openlmis.core.domain.Product;
import org.openlmis.core.handler.ProductImportHandler;
import org.openlmis.upload.parser.CSVParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

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

@Controller
@RequestMapping("/resources/pages/admin")
public class UploadController {

    private CSVParser csvParser;
    private ProductImportHandler handler;
    private final Map<String, Class> modelMap = new HashMap<String, Class>();

    @Autowired
    public UploadController(CSVParser csvParser, ProductImportHandler handler) {
        this.csvParser = csvParser;
        this.handler = handler;
        modelMap.put("product", Product.class);
    }

    @RequestMapping(value = "/upload", method = RequestMethod.POST, headers = "Accept=application/json")
    public ModelAndView upload(@RequestParam(value = "csvFile", required = true) MultipartFile multipartFile,
                               @RequestParam(value = "model", required = true) String model) {

        ModelAndView modelAndView = new ModelAndView();

        try {
            Class modelClass = modelMap.get(model);
            if (modelClass == null) {
                modelAndView.addObject("error", "Incorrect file");
            } else {
                csvParser.process(multipartFile.getInputStream(), modelClass, handler);
                modelAndView.addObject("message", "uploaded successfully");
            }
        } catch (Exception e) {
            modelAndView.addObject("error", e.getMessage());
        }
        return modelAndView;
    }
}
{'fraction_non_alphanumeric': 0.10542975407840273, 'fraction_numerical': 0.0009739469198928658, 'mean_word_length': 3.5593784683684793, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '537542', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1067, 'n_words': 217}