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()));
    }

}

package uk.ac.ebi.atlas.widget;

import com.google.common.collect.ImmutableMap;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.atlas.controllers.JsonExceptionHandlingController;
import uk.ac.ebi.atlas.search.SemanticQuery;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import uk.ac.ebi.atlas.solr.analytics.AnalyticsSearchService;

import javax.inject.Inject;

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

    private final AnalyticsSearchService analyticsSearchService;

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

    @RequestMapping(value = "/json/expressionData",
                    method = RequestMethod.GET,
                    produces = "application/json;charset=UTF-8")
    public String hasTissueExpressionWithRequestParameter(@RequestParam(value = "geneId") String geneId ) {
        return gson.toJson(ImmutableMap.of(geneId, hasBaselineTissueExpression(geneId)));
    }

//    @RequestMapping(value = "/json/expressionData/{geneId}",
//                    method = RequestMethod.GET,
//                    produces = "application/json;charset=UTF-8")
//    public String hasTissueExpressionWithPathVariable(@PathVariable String geneId ) {
//        return gson.toJson(ImmutableMap.of(geneId, hasBaselineTissueExpression(geneId)));
//    }

    private boolean hasBaselineTissueExpression(String geneId) {
        return analyticsSearchService.tissueExpressionAvailableFor(SemanticQuery.create(geneId));
    }
}

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