<commit_before>package org.pdxfinder.web.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.pdxfinder.services.*;
import org.pdxfinder.services.ds.AutoCompleteOption;
import org.pdxfinder.services.dto.CountDTO;
import org.pdxfinder.services.dto.DataAvailableDTO;
import org.pdxfinder.services.dto.DetailsDTO;
import org.pdxfinder.services.dto.VariationDataDTO;
import org.pdxfinder.services.pdf.Label;
import org.pdxfinder.services.pdf.PdfHelper;
import org.pdxfinder.services.pdf.Report;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * Created by csaba on 03/05/2018.
 */
@RestController
public class AjaxController {

    private AutoCompleteService autoCompleteService;
    private PlatformService platformService;
    private MolCharService molCharService;
    private DetailsService detailsService;
    private DrugService drugService;
    private GraphService graphService;

    @Autowired
    PdfService pdfService;

    @Autowired
    public AjaxController(AutoCompleteService autoCompleteService,
                          PlatformService platformService,
                          MolCharService molCharService,
                          DetailsService detailsService,
                          DrugService drugService,
                          GraphService graphService) {

        this.autoCompleteService = autoCompleteService;
        this.platformService = platformService;
        this.molCharService = molCharService;
        this.detailsService = detailsService;
        this.drugService = drugService;
        this.graphService = graphService;
    }

    @RequestMapping(value = "/drugnames")
    List<String> getDrugnames(){

        return drugService.getDrugNames();
    }

    @RequestMapping(value = "/modelcountperdrug")
    public List<CountDTO> getModelCountByDrug() {

        return  drugService.getModelCountByDrugAndComponentType("Drug");
    }

    @RequestMapping(value = "/modelcountpergene")
    public Iterable<Map<String, Object>> getModelCountByMarker() {

        return  graphService.getModelCountByGene();
    }

    @RequestMapping(value = "/autosuggests")
    List<String> getAutoSuggestList(){

        List<String> autoSuggestions = autoCompleteService.getAutoSuggestions();
        return autoSuggestions;
    }


    @RequestMapping(value = "/platform/{dataSrc}")
    public Map findPlatformBySource(@PathVariable String dataSrc) {

        return  platformService.getPlatformCountBySource(dataSrc);
    }


    @RequestMapping(value = "/platformdata/{dataSrc}")
    public List<DataAvailableDTO> findPlatformDataBySource(@PathVariable String dataSrc) {

        //populate list with data [{dataType:"mutation",platform:"CTP", models:20},{},{}]<commit_msg>Fix autocomplete service for wordpress<commit_after>package org.pdxfinder.web.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.pdxfinder.services.*;
import org.pdxfinder.services.ds.AutoCompleteOption;
import org.pdxfinder.services.dto.CountDTO;
import org.pdxfinder.services.dto.DataAvailableDTO;
import org.pdxfinder.services.dto.DetailsDTO;
import org.pdxfinder.services.dto.VariationDataDTO;
import org.pdxfinder.services.pdf.Label;
import org.pdxfinder.services.pdf.PdfHelper;
import org.pdxfinder.services.pdf.Report;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * Created by csaba on 03/05/2018.
 */
@RestController
public class AjaxController {

    private AutoCompleteService autoCompleteService;
    private PlatformService platformService;
    private MolCharService molCharService;
    private DetailsService detailsService;
    private DrugService drugService;
    private GraphService graphService;

    @Autowired
    PdfService pdfService;

    @Autowired
    public AjaxController(AutoCompleteService autoCompleteService,
                          PlatformService platformService,
                          MolCharService molCharService,
                          DetailsService detailsService,
                          DrugService drugService,
                          GraphService graphService) {

        this.autoCompleteService = autoCompleteService;
        this.platformService = platformService;
        this.molCharService = molCharService;
        this.detailsService = detailsService;
        this.drugService = drugService;
        this.graphService = graphService;
    }

    @RequestMapping(value = "/drugnames")
    List<String> getDrugnames(){

        return drugService.getDrugNames();
    }

    @RequestMapping(value = "/modelcountperdrug")
    public List<CountDTO> getModelCountByDrug() {

        return  drugService.getModelCountByDrugAndComponentType("Drug");
    }

    @RequestMapping(value = "/modelcountpergene")
    public Iterable<Map<String, Object>> getModelCountByMarker() {

        return  graphService.getModelCountByGene();
    }

    @RequestMapping(value = "/autosuggests")
    List<AutoCompleteOption> getAutoSuggestList(){

        List<String> autoSuggestions = autoCompleteService.getAutoSuggestions();
        List<AutoCompleteOption> suggestions = new ArrayList<>();

        for(String s : autoSuggestions){
            suggestions.add(new AutoCompleteOption(s, "OntologyTerm"));
        }

        return suggestions;
    }


    @RequestMapping(value = "/platform/{dataSrc}")
    public Map findPlatformBySource(@PathVariable String dataSrc) {

        return  platformService.getPlatformCountBySource(dataSrc);
    }


    @RequestMapping(value = "/platformdata/{dataSrc}")
    public List<DataAvailableDTO> findPlatformDataBySource(@PathVariable String dataSrc) {

        //populate list with data [{dataType:"mutation",platform:"CTP", models:20},{},{}]
{'fraction_non_alphanumeric': 0.0902338811630847, 'fraction_numerical': 0.0031605562579013905, 'mean_word_length': 3.7055762081784387, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4442044', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1675, 'n_words': 311}