package uk.ac.ebi.quickgo.ontology.controller;

import uk.ac.ebi.quickgo.common.SearchableField;
import uk.ac.ebi.quickgo.graphics.service.GraphImageService;
import uk.ac.ebi.quickgo.ontology.OntologyRestConfig;
import uk.ac.ebi.quickgo.ontology.common.OntologyType;
import uk.ac.ebi.quickgo.ontology.controller.validation.OBOControllerValidationHelper;
import uk.ac.ebi.quickgo.ontology.model.GOTerm;
import uk.ac.ebi.quickgo.ontology.model.OBOTerm;
import uk.ac.ebi.quickgo.ontology.service.OntologyService;
import uk.ac.ebi.quickgo.ontology.metadata.MetaDataProvider;
import uk.ac.ebi.quickgo.ontology.service.search.SearchServiceConfig;
import uk.ac.ebi.quickgo.rest.metadata.MetaData;
import uk.ac.ebi.quickgo.rest.search.SearchService;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * REST controller for accessing GO related information.
 *
 * For complete list of necessary endpoints, and their behaviour:
 *  refer to https://www.ebi.ac.uk/seqdb/confluence/display/GOA/REST+API
 *
 * Created 16/11/15
 * @author Edd
 */
@RestController
@RequestMapping(value = "/ontology/go")
public class GOController extends OBOController<GOTerm> {

    private final MetaDataProvider metaDataProvider;

    @Autowired
    public GOController(OntologyService<GOTerm> goOntologyService,
            SearchService<OBOTerm> ontologySearchService,
            SearchableField searchableField,
            SearchServiceConfig.OntologyCompositeRetrievalConfig ontologyRetrievalConfig,
            GraphImageService graphImageService,
            OBOControllerValidationHelper goValidationHelper,
            OntologyRestConfig.OntologyPagingConfig ontologyPagingConfig,
            MetaDataProvider metaDataProvider) {
        super(goOntologyService, ontologySearchService, searchableField, ontologyRetrievalConfig, graphImageService,
              goValidationHelper, ontologyPagingConfig, OntologyType.GO);
        this.metaDataProvider = metaDataProvider;
    }

    /**
     * Get meta data information about the Ontology service
     *
     * @return response with metadata information.
     */
    @ApiOperation(value = "Get meta data information about the Ontology service",
            notes = "Ontology version number and creation date.")
    @RequestMapping(value = "/about", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<MetaData> provideMetaData() {
        return getAboutResponse(this.metaDataProvider.lookupMetaData());
    }

    /**
     * Creates a {@link ResponseEntity} containing a {@link MetaData} for an about request.
     *
     * @param metaData result
     * @return a {@link ResponseEntity} containing a {@link MetaData}
     */
    ResponseEntity<MetaData> getAboutResponse(MetaData metaData) {
        if (metaData == null) {
          return new ResponseEntity<>(metaData, HttpStatus.INTERNAL_SERVER_ERROR);
        }
        return new ResponseEntity<>(metaData, HttpStatus.OK);
    }
}

@@ -736,16 +736,61 @@
 rvice;%0A%0A
+import com.google.common.base.Preconditions;%0A
 import i
@@ -2326,16 +2326,116 @@
 pe.GO);%0A
+        Preconditions.checkArgument(metaDataProvider != null, %22Metadata provider cannot be null.%22);%0A
         
@@ -2476,16 +2476,16 @@
 ovider;%0A
-
     %7D%0A%0A 
@@ -2949,32 +2949,36 @@
  return 
-getAboutResponse
+new ResponseEntity%3C%3E
 (this.me
@@ -3012,469 +3012,8 @@
 ta()
-);%0A    %7D%0A%0A    /**%0A     * Creates a %7B@link ResponseEntity%7D containing a %7B@link MetaData%7D for an about request.%0A     *%0A     * @param metaData result%0A     * @return a %7B@link ResponseEntity%7D containing a %7B@link MetaData%7D%0A     */%0A    ResponseEntity%3CMetaData%3E getAboutResponse(MetaData metaData) %7B%0A        if (metaData == null) %7B%0A          return new ResponseEntity%3C%3E(metaData, HttpStatus.INTERNAL_SERVER_ERROR);%0A        %7D%0A        return new ResponseEntity%3C%3E(metaData
 , Ht

Remove getAboutResponse as it was doing enough to warrant existing.