package uk.ac.ebi.quickgo.annotation.service.comm.rest.ontology.transformer.statistics;

import uk.ac.ebi.quickgo.annotation.model.StatisticsValue;
import uk.ac.ebi.quickgo.annotation.service.comm.rest.ontology.model.BasicTaxonomyNode;
import uk.ac.ebi.quickgo.rest.search.request.FilterRequest;
import uk.ac.ebi.quickgo.rest.search.request.converter.ConvertedFilter;
import uk.ac.ebi.quickgo.rest.search.results.transformer.AbstractValueInjector;

/**
 * This class is responsible for supplementing an {@link StatisticsValue} instance, which contains
 * a taxonomy identifier (in the key field), with a taxonomy name, through the use of a RESTful service.
 *
 * Created 04/10/17
 * @author Tony Wardell
 */
public class TaxonomyNameInjector extends AbstractValueInjector<BasicTaxonomyNode, StatisticsValue> {

    static final String TAXON_NAME = "taxonName";
    static final String TAXON_ID = "taxonId";

    @Override
    public String getId() {
        return TAXON_NAME;
    }

    @Override
    public FilterRequest buildFilterRequest(StatisticsValue statisticsValue) {
        return FilterRequest.newBuilder()
                .addProperty(getId())
                .addProperty(TAXON_ID, String.valueOf(statisticsValue.getKey()))
                .build();
    }

    @Override
    public void injectValueFromResponse(ConvertedFilter<BasicTaxonomyNode> convertedRequest, StatisticsValue
            statisticsValue) {
        statisticsValue.setName(convertedRequest.getConvertedValue().getScientificName());
    }
}

@@ -804,24 +804,31 @@
 lue%3E %7B%0A%0A    
+public 
 static final
@@ -841,20 +841,18 @@
 g TAXON_
-NAME
+ID
  = %22taxo
@@ -852,20 +852,18 @@
 = %22taxon
-Name
+Id
 %22;%0A    s
@@ -879,34 +879,36 @@
 al String TAXON_
-ID
+NAME
  = %22taxonId%22;%0A%0A 
@@ -900,18 +900,20 @@
 = %22taxon
-Id
+Name
 %22;%0A%0A    

Make TAXON_ID public so it can be referenced by AnnotationController.