/*
 * Copyright 2017 EMBL - European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.ebi.eva.server.ws;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.eva.commons.mongodb.entities.AnnotationMetadataMongo;
import uk.ac.ebi.eva.commons.mongodb.repositories.AnnotationMetadataRepository;
import uk.ac.ebi.eva.lib.utils.QueryResponse;
import uk.ac.ebi.eva.lib.utils.QueryResult;
import uk.ac.ebi.eva.lib.utils.DBAdaptorConnector;
import uk.ac.ebi.eva.lib.utils.MultiMongoDbFactory;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping(value = "/v1/annotation", produces = "application/json")
@Api(tags = {"annotation"})
public class AnnotationMetadataWSServer extends EvaWSServer {

    @Autowired
    private AnnotationMetadataRepository repository;

    @RequestMapping(value = "", method = RequestMethod.GET)
    @ResponseBody
    public QueryResponse getAnnotationMetadata(@RequestParam(name = "species") String species,
                                               HttpServletResponse response) {
        if (species.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return setQueryResponse("Please specify a species");
        }

        MultiMongoDbFactory.setDatabaseNameForCurrentThread(DBAdaptorConnector.getDBName(species));
        List<AnnotationMetadataMongo> annotationMetadataList = repository.findAllByOrderByCacheVersionDescVepVersionDesc();
        QueryResult<AnnotationMetadataMongo> queryResult = buildQueryResult(annotationMetadataList);
        return setQueryResponse(queryResult);
    }

}

@@ -1060,16 +1060,17 @@
 roller;%0A
+%0A
 import u
@@ -1094,23 +1094,18 @@
 ons.
-mongodb.entitie
+core.model
 s.An
@@ -1120,21 +1120,16 @@
 Metadata
-Mongo
 ;%0Aimport
@@ -1163,18 +1163,14 @@
 odb.
-repositori
+servic
 es.A
@@ -1186,26 +1186,23 @@
 Metadata
-Repository
+Service
 ;%0Aimport
@@ -1226,29 +1226,34 @@
 b.utils.
-QueryResponse
+DBAdaptorConnector
 ;%0Aimport
@@ -1277,27 +1277,35 @@
 b.utils.
-QueryResult
+MultiMongoDbFactory
 ;%0Aimport
@@ -1329,34 +1329,29 @@
 b.utils.
-DBAdaptorConnector
+QueryResponse
 ;%0Aimport
@@ -1375,35 +1375,27 @@
 b.utils.
-MultiMongoDbFactory
+QueryResult
 ;%0A%0Aimpor
@@ -1689,29 +1689,23 @@
 data
-Repository repository
+Service service
 ;%0A%0A 
@@ -2263,21 +2263,16 @@
 Metadata
-Mongo
 %3E annota
@@ -2294,18 +2294,15 @@
 t = 
-repository
+service
 .fin
@@ -2386,21 +2386,16 @@
 Metadata
-Mongo
 %3E queryR

Use service instead of repository in AnnotationMetadataWSServer