/*
 * Copyright 2015-2017 OpenCB
 *
 * 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 org.opencb.opencga.server.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.opencb.biodata.models.variant.Variant;
import org.opencb.commons.datastore.core.ObjectMap;
import org.opencb.commons.datastore.core.Query;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.commons.datastore.core.QueryResult;
import org.opencb.opencga.core.common.GitRepositoryState;
import org.opencb.opencga.core.exception.VersionException;
import org.opencb.opencga.core.results.VariantQueryResult;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.util.*;

/**
 * Created by pfurio on 05/05/17.
 */
@Path("/{apiVersion}/meta")
@Produces("application/json")
@Api(value = "Meta", description = "Meta RESTful Web Services API")
public class MetaWSServer extends OpenCGAWSServer {

    public MetaWSServer(@Context UriInfo uriInfo, @Context HttpServletRequest httpServletRequest, @Context HttpHeaders httpHeaders) throws IOException, VersionException {
        super(uriInfo, httpServletRequest, httpHeaders);
    }

    @GET
    @Path("/about")
    @ApiOperation(httpMethod = "GET", value = "Returns info about current OpenCGA code.")
    public Response getAbout() {
        Map<String, String> info = new HashMap<>(5);
        info.put("Program", "OpenCGA (OpenCB)");
        info.put("Version", GitRepositoryState.get().getBuildVersion());
        info.put("Git branch", GitRepositoryState.get().getBranch());
        info.put("Git commit", GitRepositoryState.get().getCommitId());
        info.put("Description", "Big Data platform for processing and analysing NGS data");
        QueryResult queryResult = new QueryResult();
        queryResult.setId("about");
        queryResult.setDbTime(0);
        queryResult.setResult(Collections.singletonList(info));

        return createOkResponse(queryResult);
    }

    @GET
    @Path("/ping")
    @ApiOperation(httpMethod = "GET", value = "Ping Opencga webservices.")
    public Response ping() {

        QueryResult queryResult = new QueryResult();
        queryResult.setId("pong");
        queryResult.setDbTime(0);

        return createOkResponse(queryResult);
    }

    @GET
    @Path("/status")
    @ApiOperation(httpMethod = "GET", value = "Database status.")
    public Response status() {

        QueryResult queryResult = new QueryResult();
        queryResult.setId("Status");
        queryResult.setDbTime(0);
        List<String> results = new ArrayList<>();
        String storageEngineId;
        boolean error = false;

        try {
            if (catalogManager.getDatabaseStatus()) {
                results.add("CatalogMongoDB: OK");
            } else {
                results.add("CatalogMongoDB: KO");
                error = true;
            }
        } catch (Exception e) {
            results.add("CatalogMongoDB: KO");
            error = true;
        }

        try {
            storageEngineId = storageEngineFactory.getVariantStorageEngine().getStorageEngineId();
        } catch (Exception e) {
            return createErrorResponse("No storageEngineId is set in configuration", queryResult);
        }

        try {
            storageEngineFactory.getVariantStorageEngine().testConnection();
            results.add("VariantStorage " + storageEngineId + ": OK");
        } catch (Exception e) {
            results.add("VariantStorage " + storageEngineId + ": KO");
            error = true;
        }

        if (storageEngineFactory.getStorageConfiguration().getSearch().isActive()) {
            if (variantManager.isSolrAvailable()) {
                results.add("Solr: OK");
            } else {
                results.add("Solr: unable to connect with solr!");
                error = true;
            }
        } else {
            results.add("Solr: solr is not active in storage configuration!");
            error = true;
        }

        queryResult.setResult(results);
        if (error) {
            return createErrorResponse("Error", queryResult);
        }
        return createOkResponse(queryResult);
    }
}

@@ -4707,34 +4707,8 @@
 %22);%0A
-            error = true;%0A
     

change error is solr not active in config