package uk.ac.ebi.atlas.widget;

import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import org.springframework.web.bind.annotation.ResponseBody;
import uk.ac.ebi.atlas.controllers.JsonExceptionHandlingController;
import uk.ac.ebi.atlas.search.SemanticQuery;
import uk.ac.ebi.atlas.species.SpeciesPropertiesTrader;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import uk.ac.ebi.atlas.solr.analytics.AnalyticsSearchService;

import javax.inject.Inject;

@Controller
@Scope("request")
public final class ExpressionDataController extends JsonExceptionHandlingController {

    private final AnalyticsSearchService analyticsSearchService;
    private final SpeciesPropertiesTrader speciesTrader;
    private final Gson gson = new Gson();

    @Inject
    public ExpressionDataController(AnalyticsSearchService analyticsSearchService,
                                    SpeciesPropertiesTrader speciesTrader) {
        this.analyticsSearchService = analyticsSearchService;
        this.speciesTrader = speciesTrader;
    }

    @RequestMapping(value = "/json/expressionData",produces = "application/json;charset=UTF-8")
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public String existGeneIdentifier(@RequestParam(value = "geneId") String geneId ) {
        boolean results = analyticsSearchService.tissueExpressionAvailableFor(SemanticQuery.create(geneId));
        return gson.toJson(ImmutableMap.of(geneId, results));
    }

    // Wojtek: this doesn't seem right.
    @RequestMapping(value = "/json/expressionData/species",produces = "application/json;charset=UTF-8")
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public String existSpeciesForGeneIdentifier() {
        return gson.toJson(ImmutableMap.of("species", speciesTrader.getAll()));
    }

}

@@ -84,28 +84,61 @@
 ort 
-com.google.gson.Gson
+org.springframework.web.bind.annotation.RequestMethod
 ;%0Aim
@@ -185,25 +185,27 @@
 tion.Res
-ponseBody
+tController
 ;%0Aimport
@@ -322,202 +322,52 @@
 ort 
-uk.ac.ebi.atlas.species.SpeciesPropertiesTrader;%0Aimport org.springframework.context.annotation.Scope;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.stereotype.Controller
+org.springframework.context.annotation.Scope
 ;%0Aim
@@ -492,71 +492,8 @@
 am;%0A
-import org.springframework.web.bind.annotation.ResponseStatus;%0A
 impo
@@ -581,16 +581,20 @@
 ject;%0A%0A@
+Rest
 Controll
@@ -769,107 +769,8 @@
 ice;
-%0A    private final SpeciesPropertiesTrader speciesTrader;%0A    private final Gson gson = new Gson();
 %0A%0A  
@@ -864,83 +864,8 @@
 vice
-,%0A                                    SpeciesPropertiesTrader speciesTrader
 ) %7B%0A
@@ -930,52 +930,8 @@
 ce;%0A
-        this.speciesTrader = speciesTrader;%0A
     
@@ -988,621 +988,597 @@
 ta%22,
-produces = %22application/json;charset=UTF-8%22)%0A    @ResponseStatus(HttpStatus.OK)%0A    @ResponseBody%0A    public String existGeneIdentifier(@RequestParam(value = %22geneId%22) String geneId ) %7B%0A        boolean results = analyticsSearchService.tissueExpressionAvailableFor(SemanticQuery.create(geneId));%0A        return gson.toJson(ImmutableMap.of(geneId, results));%0A    %7D%0A%0A    // Wojtek: this doesn't seem right.%0A    @RequestMapping(value = %22/json/expressionData/species%22,produces = %22application/json;charset=UTF-8%22)%0A    @ResponseStatus(HttpStatus.OK)%0A    @ResponseBody%0A    public String existSpeciesForGeneIdentifier(
+%0A                    method = RequestMethod.GET,%0A                    produces = %22application/json;charset=UTF-8%22)%0A    public String hasTissueExpressionWithRequestParameter(@RequestParam(value = %22geneId%22) String geneId ) %7B%0A        return gson.toJson(ImmutableMap.of(geneId, hasBaselineTissueExpression(geneId)));%0A    %7D%0A%0A//    @RequestMapping(value = %22/json/expressionData/%7BgeneId%7D%22,%0A//                    method = RequestMethod.GET,%0A//                    produces = %22application/json;charset=UTF-8%22)%0A//    public String hasTissueExpressionWithPathVariable(@PathVariable String geneId 
 ) %7B%0A
+//
     
@@ -1620,41 +1620,223 @@
 .of(
-%22species%22, speciesTrader.getAll()
+geneId, hasBaselineTissueExpression(geneId)));%0A//    %7D%0A%0A    private boolean hasBaselineTissueExpression(String geneId) %7B%0A        return analyticsSearchService.tissueExpressionAvailableFor(SemanticQuery.create(geneId
 ));%0A
@@ -1841,11 +1841,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Remove unused endpoint, make code a bit terser and an idea for a more RESTful alternative