diff --git a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/core/CellBaseDBAdaptor.java b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/core/CellBaseDBAdaptor.java index 4a26ad81d6..0ae1c13f70 100644 --- a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/core/CellBaseDBAdaptor.java +++ b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/core/CellBaseDBAdaptor.java @@ -16,6 +16,7 @@ package org.opencb.cellbase.core.api.core; +import org.opencb.cellbase.core.api.queries.AbstractQuery; import org.opencb.cellbase.core.result.CellBaseDataResult; import org.opencb.commons.datastore.core.Query; import org.opencb.commons.datastore.core.QueryOptions; @@ -76,6 +77,8 @@ default List nativeGet(List queries, QueryOptions opt return queryResults; } + CellBaseDataResult nativeGet(AbstractQuery query); + @Override default Iterator iterator() { return iterator(new Query(), new QueryOptions()); diff --git a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/AbstractQuery.java b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/AbstractQuery.java index d7b2b8a76f..4c50d9c662 100644 --- a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/AbstractQuery.java +++ b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/AbstractQuery.java @@ -21,20 +21,17 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.opencb.cellbase.core.exception.CellbaseException; import org.opencb.commons.datastore.core.ObjectMap; import org.opencb.commons.datastore.core.Query; import org.opencb.commons.datastore.core.QueryOptions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; -public class AbstractQuery extends org.opencb.cellbase.core.api.queries.QueryOptions { +public abstract class AbstractQuery extends org.opencb.cellbase.core.api.queries.QueryOptions { protected ObjectMapper objectMapper; protected Logger logger; @@ -94,6 +91,9 @@ private Map> loadPropertiesMap() { return internalPropertiesMap; } + + protected abstract void validateQuery() throws QueryException; + /** * Checks if values for query are legal, e.g. >= 0 and <= MAX Checks the following parameters: * @@ -101,30 +101,52 @@ private Map> loadPropertiesMap() { * - LIMIT * * NULL values are considered valid. - * @throws CellbaseException if the skip or limit values are invalid + * @throws QueryException if the skip or limit values are invalid. */ - public void validate() throws CellbaseException { - Integer skip = getSkip(); - Integer limit = getLimit(); + public void validate() throws QueryException { + this.checkIncludeAndExclude(); + this.checkLimitAndSkip(); + this.checkSortAndOrder(); - if (skip != null) { - if (skip < 0) { - throw new CellbaseException("Invalid value for skip field " + skip + ". Must be greater than zero"); - } - if (skip > MAX_RECORDS) { - throw new CellbaseException("Invalid value for skip field " + skip + ". Must be less than " + MAX_RECORDS); + // Execute private checks + this.validateQuery(); + } + + private void checkIncludeAndExclude() throws QueryException { + if (CollectionUtils.isNotEmpty(includes) && CollectionUtils.isNotEmpty(excludes)) { + Collection intersection = CollectionUtils.intersection(includes, excludes); + if (intersection.size() > 0) { + throw new QueryException(""); } } + } + private void checkLimitAndSkip() throws QueryException { + Integer limit = getLimit(); if (limit != null) { if (limit < 0) { - throw new CellbaseException("Invalid value for limit field " + limit + ". Must be greater than zero"); + throw new QueryException("Invalid value for limit field " + limit + ". Must be greater than zero"); } - if (limit > MAX_RECORDS) { - throw new CellbaseException("Invalid value for limit field " + limit + ". Must be less than " + MAX_RECORDS); +// if (limit > MAX_RECORDS) { +// throw new QueryException("Invalid value for limit field " + limit + ". Must be less than " + MAX_RECORDS); +// } + } + + Integer skip = getSkip(); + if (skip != null) { + if (skip < 0) { + throw new QueryException("Invalid value for skip field " + skip + ". Must be greater than zero"); } +// if (skip > MAX_RECORDS) { +// throw new QueryException("Invalid value for skip field " + skip + ". Must be less than " + MAX_RECORDS); +// } + } + } + + private void checkSortAndOrder() throws QueryException { + if (order != null && StringUtils.isEmpty(sort)) { + throw new QueryException(""); } - return; } public void setDefaults() { @@ -146,7 +168,6 @@ public QueryOptions toQueryOptions() { queryOptions.put(QueryOptions.EXCLUDE, StringUtils.join(excludes)); queryOptions.put(QueryOptions.SORT, sort); queryOptions.put(QueryOptions.ORDER, order); - queryOptions.put(QueryOptions.TIMEOUT, timeout); queryOptions.put(QueryOptions.FACET, facet); return queryOptions; } diff --git a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/FeatureQuery.java b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/FeatureQuery.java index f3c92772ea..175de0d4ca 100644 --- a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/FeatureQuery.java +++ b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/FeatureQuery.java @@ -18,7 +18,8 @@ import java.util.Map; -public class FeatureQuery extends AbstractQuery { +@Deprecated +public class FeatureQuery { private Boolean histogram; private static final int HISTOGRAM_INTERVAL_SIZE = 200000; @@ -28,7 +29,7 @@ public FeatureQuery() { } public FeatureQuery(Map params) { - super(params); +// super(params); } public Boolean getHistogram() { diff --git a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/GeneQuery.java b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/GeneQuery.java index 9626e5ab9f..6f2d89151f 100644 --- a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/GeneQuery.java +++ b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/GeneQuery.java @@ -17,15 +17,14 @@ package org.opencb.cellbase.core.api.queries; import org.opencb.biodata.models.core.Region; -import org.opencb.cellbase.core.exception.CellbaseException; import java.util.ArrayList; import java.util.List; import java.util.Map; -public class GeneQuery extends FeatureQuery { +public class GeneQuery extends AbstractQuery { - private List ids; + private List id; private List names; private List biotypes; private List regions; @@ -50,12 +49,50 @@ public GeneQuery(Map params) { super(params); } - public List getIds() { - return ids; + @Override + protected void validateQuery() throws QueryException { + } - public GeneQuery setIds(List ids) { - this.ids = ids; + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("GeneQuery{"); + sb.append("id=").append(id); + sb.append(", names=").append(names); + sb.append(", biotypes=").append(biotypes); + sb.append(", regions=").append(regions); + sb.append(", transcriptsBiotype=").append(transcriptsBiotype); + sb.append(", transcriptsXrefs=").append(transcriptsXrefs); + sb.append(", transcriptsId=").append(transcriptsId); + sb.append(", transcriptsName=").append(transcriptsName); + sb.append(", transcriptsAnnotationFlags=").append(transcriptsAnnotationFlags); + sb.append(", transcriptsTfbsName=").append(transcriptsTfbsName); + sb.append(", annotationDiseasesId=").append(annotationDiseasesId); + sb.append(", annotationDiseasesName=").append(annotationDiseasesName); + sb.append(", annotationExpressionGene=").append(annotationExpressionGene); + sb.append(", annotationExpressionTissue=").append(annotationExpressionTissue); + sb.append(", annotationExpressionValue=").append(annotationExpressionValue); + sb.append(", annotationDrugsName=").append(annotationDrugsName); + sb.append(", annotationDrugsGene=").append(annotationDrugsGene); + sb.append(", objectMapper=").append(objectMapper); + sb.append(", limit=").append(limit); + sb.append(", skip=").append(skip); + sb.append(", count=").append(count); + sb.append(", sort='").append(sort).append('\''); + sb.append(", order=").append(order); + sb.append(", facet='").append(facet).append('\''); + sb.append(", includes=").append(includes); + sb.append(", excludes=").append(excludes); + sb.append('}'); + return sb.toString(); + } + + public List getId() { + return id; + } + + public GeneQuery setId(List id) { + this.id = id; return this; } @@ -204,37 +241,8 @@ public GeneQuery setAnnotationDrugsGene(List annotationDrugsGene) { return this; } - public void validate() throws CellbaseException { - super.validate(); - - // excludes and includes contain valid values - } - - @Override - public String toString() { - return "GeneQuery{" - + "ids=" + ids - + ", names=" + names - + ", biotypes=" + biotypes - + ", regions=" + regions - + ", transcriptsBiotype=" + transcriptsBiotype - + ", transcriptsXrefs=" + transcriptsXrefs - + ", transcriptsId=" + transcriptsId - + ", transcriptsName=" + transcriptsName - + ", transcriptsAnnotationFlags=" + transcriptsAnnotationFlags - + ", transcriptsTfbsName=" + transcriptsTfbsName - + ", annotationDiseasesId=" + annotationDiseasesId - + ", annotationDiseasesName=" + annotationDiseasesName - + ", annotationExpressionGene=" + annotationExpressionGene - + ", annotationExpressionTissue=" + annotationExpressionTissue - + ", annotationExpressionValue=" + annotationExpressionValue - + ", annotationDrugsName=" + annotationDrugsName - + ", annotationDrugsGene=" + annotationDrugsGene - + '}'; - } - public static class Builder { - private List ids; + private List id; private List names; private List biotypes; private List regions; @@ -256,7 +264,7 @@ public Builder() { } public Builder withIds(List ids) { - this.ids = ids; + this.id = ids; return this; } @@ -342,7 +350,7 @@ public Builder withAnnotationDrugsGene(List annotationDrugsGene) { public GeneQuery build() { GeneQuery geneQuery = new GeneQuery(); - geneQuery.ids = this.ids; + geneQuery.id = this.id; geneQuery.names = this.names; geneQuery.biotypes = this.biotypes; geneQuery.regions = this.regions; diff --git a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/ProjectionQueryOptions.java b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/ProjectionQueryOptions.java index 1c745ae2b5..df07ac4e0e 100644 --- a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/ProjectionQueryOptions.java +++ b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/ProjectionQueryOptions.java @@ -22,19 +22,15 @@ public class ProjectionQueryOptions { - protected List excludes; protected List includes; + protected List excludes; public ProjectionQueryOptions() { } - public List getExcludes() { - return excludes; - } - - public ProjectionQueryOptions setExcludes(List excludes) { + public ProjectionQueryOptions(List includes, List excludes) { + this.includes = includes; this.excludes = excludes; - return this; } public ProjectionQueryOptions addExcludes(String excludes) { @@ -45,6 +41,23 @@ public ProjectionQueryOptions addExcludes(String excludes) { return this; } + public ProjectionQueryOptions addExcludes(List excludes) { + if (this.excludes == null) { + this.excludes = new ArrayList<>(); + } + this.excludes.addAll(excludes); + return this; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("ProjectionQueryOptions{"); + sb.append("includes=").append(includes); + sb.append(", excludes=").append(excludes); + sb.append('}'); + return sb.toString(); + } + public List getIncludes() { return includes; } @@ -54,11 +67,12 @@ public ProjectionQueryOptions setIncludes(List includes) { return this; } - @Override - public String toString() { - return "ProjectionQueryOptions{" - + "excludes=" + excludes - + ", includes=" + includes - + '}'; + public List getExcludes() { + return excludes; + } + + public ProjectionQueryOptions setExcludes(List excludes) { + this.excludes = excludes; + return this; } } diff --git a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/QueryException.java b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/QueryException.java new file mode 100644 index 0000000000..45919afc03 --- /dev/null +++ b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/QueryException.java @@ -0,0 +1,24 @@ +/* + * Copyright 2015-2020 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.cellbase.core.api.queries; + +public class QueryException extends Exception { + + public QueryException(String message) { + super(message); + } +} diff --git a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/QueryOptions.java b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/QueryOptions.java index a231bfe874..05b974aa57 100644 --- a/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/QueryOptions.java +++ b/cellbase-core/src/main/java/org/opencb/cellbase/core/api/queries/QueryOptions.java @@ -16,14 +16,16 @@ package org.opencb.cellbase.core.api.queries; +import java.util.List; + public class QueryOptions extends ProjectionQueryOptions { - protected Integer skip; protected Integer limit; - protected String sort; + protected Integer skip; protected Boolean count; + protected String sort; protected Order order; - protected String timeout; +// protected String timeout; protected String facet; enum Order { @@ -34,13 +36,40 @@ enum Order { public QueryOptions() { } - public Integer getSkip() { - return skip; + public QueryOptions(Integer limit, Integer skip, Boolean count, String sort, Order order, String facet) { + this.limit = limit; + this.skip = skip; + this.count = count; + this.sort = sort; + this.order = order; + this.facet = facet; } - public QueryOptions setSkip(Integer skip) { + public QueryOptions(Integer limit, Integer skip, Boolean count, String sort, Order order, String facet, + List includes, List excludes) { + super(includes, excludes); + + this.limit = limit; this.skip = skip; - return this; + this.count = count; + this.sort = sort; + this.order = order; + this.facet = facet; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("QueryOptions{"); + sb.append("limit=").append(limit); + sb.append(", skip=").append(skip); + sb.append(", count=").append(count); + sb.append(", sort='").append(sort).append('\''); + sb.append(", order=").append(order); + sb.append(", facet='").append(facet).append('\''); + sb.append(", includes=").append(includes); + sb.append(", excludes=").append(excludes); + sb.append('}'); + return sb.toString(); } public Integer getLimit() { @@ -52,12 +81,12 @@ public QueryOptions setLimit(Integer limit) { return this; } - public String getSort() { - return sort; + public Integer getSkip() { + return skip; } - public QueryOptions setSort(String sort) { - this.sort = sort; + public QueryOptions setSkip(Integer skip) { + this.skip = skip; return this; } @@ -70,21 +99,21 @@ public QueryOptions setCount(Boolean count) { return this; } - public Order getOrder() { - return order; + public String getSort() { + return sort; } - public QueryOptions setOrder(Order order) { - this.order = order; + public QueryOptions setSort(String sort) { + this.sort = sort; return this; } - public String getTimeout() { - return timeout; + public Order getOrder() { + return order; } - public QueryOptions setTimeout(String timeout) { - this.timeout = timeout; + public QueryOptions setOrder(Order order) { + this.order = order; return this; } @@ -96,17 +125,4 @@ public QueryOptions setFacet(String facet) { this.facet = facet; return this; } - - @Override - public String toString() { - return "QueryOptions{" - + "skip=" + skip - + ", limit=" + limit - + ", sort='" + sort + '\'' - + ", count=" + count - + ", order=" + order - + ", timeout='" + timeout + '\'' - + ", facet='" + facet + '\'' - + '}'; - } } diff --git a/cellbase-core/src/test/java/org/opencb/cellbase/core/GeneQueryTest.java b/cellbase-core/src/test/java/org/opencb/cellbase/core/GeneQueryTest.java index daff19b02e..3532abaf35 100644 --- a/cellbase-core/src/test/java/org/opencb/cellbase/core/GeneQueryTest.java +++ b/cellbase-core/src/test/java/org/opencb/cellbase/core/GeneQueryTest.java @@ -45,7 +45,7 @@ public void testQuery() { paramMap.put("xxx", ""); geneQuery = new GeneQuery(paramMap); - assertEquals("1", geneQuery.getIds().get(0)); + assertEquals("1", geneQuery.getId().get(0)); assertEquals("a", geneQuery.getBiotypes().get(0)); assertEquals("b", geneQuery.getBiotypes().get(1)); @@ -119,7 +119,7 @@ public void testBuild() { geneQuery = new GeneQuery.Builder().withIds(Arrays.asList("1")).withBiotypes(Arrays.asList("a", "b", "c")) .withAnnotationDrugsGene(Arrays.asList("My gene", "another-gene")).build(); - assertEquals("1", geneQuery.getIds().get(0)); + assertEquals("1", geneQuery.getId().get(0)); assertEquals("a", geneQuery.getBiotypes().get(0)); assertEquals("b", geneQuery.getBiotypes().get(1)); diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/GeneMongoDBAdaptor.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/GeneMongoDBAdaptor.java index 86539c8eb8..f94c12757d 100644 --- a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/GeneMongoDBAdaptor.java +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/GeneMongoDBAdaptor.java @@ -289,27 +289,69 @@ private Bson parseQuery(Query geneQuery) { } } + + private Bson parseQuery(GeneQuery geneQuery) { List andBsonList = new ArrayList<>(); createRegionQuery(geneQuery, QueryParams.REGION.key(), MongoDBCollectionConfiguration.GENE_CHUNK_SIZE, andBsonList); - createOrQuery(geneQuery, QueryParams.ID.key(), "id", andBsonList); - createOrQuery(geneQuery, QueryParams.NAME.key(), "name", andBsonList); - createOrQuery(geneQuery, QueryParams.BIOTYPE.key(), "biotype", andBsonList); - createOrQuery(geneQuery, QueryParams.XREFS.key(), "transcripts.xrefs.id", andBsonList); + if (CollectionUtils.isNotEmpty(geneQuery.getId())) { + createOrQuery(geneQuery.getId(), "id", andBsonList); + } - createOrQuery(geneQuery, QueryParams.TRANSCRIPT_ID.key(), "transcripts.id", andBsonList); - createOrQuery(geneQuery, QueryParams.TRANSCRIPT_NAME.key(), "transcripts.name", andBsonList); - createOrQuery(geneQuery, QueryParams.TRANSCRIPT_BIOTYPE.key(), "transcripts.biotype", andBsonList); - createOrQuery(geneQuery, QueryParams.TRANSCRIPT_ANNOTATION_FLAGS.key(), "transcripts.annotationFlags", andBsonList); + if (CollectionUtils.isNotEmpty(geneQuery.getNames())) { + createOrQuery(geneQuery.getNames(), "name", andBsonList); + } - createOrQuery(geneQuery, QueryParams.TFBS_NAME.key(), "transcripts.tfbs.name", andBsonList); - createOrQuery(geneQuery, QueryParams.ANNOTATION_DISEASE_ID.key(), "annotation.diseases.id", andBsonList); - createOrQuery(geneQuery, QueryParams.ANNOTATION_DISEASE_NAME.key(), "annotation.diseases.name", andBsonList); - createOrQuery(geneQuery, QueryParams.ANNOTATION_EXPRESSION_GENE.key(), "annotation.expression.geneName", andBsonList); + if (CollectionUtils.isNotEmpty(geneQuery.getBiotypes())) { + createOrQuery(geneQuery.getBiotypes(), "biotype", andBsonList); + } - createOrQuery(geneQuery, QueryParams.ANNOTATION_DRUGS_NAME.key(), "annotation.drugs.drugName", andBsonList); - createOrQuery(geneQuery, QueryParams.ANNOTATION_DRUGS_GENE.key(), "annotation.drugs.geneName", andBsonList); + if (CollectionUtils.isNotEmpty(geneQuery.getBiotypes())) { + createOrQuery(geneQuery.getTranscriptsXrefs(), "transcripts.xrefs", andBsonList); + } +, + + + if (CollectionUtils.isNotEmpty(geneQuery.getTranscriptsId())) { + createOrQuery(geneQuery.getTranscriptsId(), "transcripts.id", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getTranscriptsName())) { + createOrQuery(geneQuery.getTranscriptsName(), "transcripts.name", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getTranscriptsBiotype())) { + createOrQuery(geneQuery.getTranscriptsBiotype(), "transcripts.biotype", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getTranscriptsAnnotationFlags())) { + createOrQuery(geneQuery.getTranscriptsAnnotationFlags(), "transcripts.annotationFlags", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getTranscriptsTfbsName())) { + createOrQuery(geneQuery.getTranscriptsTfbsName(), "transcripts.tfbs.name", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getAnnotationDiseasesId())) { + createOrQuery(geneQuery.getAnnotationDiseasesId(), "annotation.diseases.id", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getAnnotationDiseasesName())) { + createOrQuery(geneQuery.getAnnotationDiseasesName(), "annotation.diseases.name", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getAnnotationExpressionGene())) { + createOrQuery(geneQuery.getAnnotationExpressionGene(), "annotation.expression.gene", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getAnnotationDrugsName())) { + createOrQuery(geneQuery.getAnnotationDrugsName(), "annotation.drugs.name", andBsonList); + } + + if (CollectionUtils.isNotEmpty(geneQuery.getAnnotationDrugsGene())) { + createOrQuery(geneQuery.getAnnotationDrugsGene(), "annotation.drugs.gene", andBsonList); + } createExpressionQuery(geneQuery, andBsonList); @@ -337,7 +379,6 @@ private Boolean postDBFilteringParametersEnabled(Query geneQuery) { return StringUtils.isNotEmpty(geneQuery.getString(QueryParams.TRANSCRIPT_ANNOTATION_FLAGS.key())); } - @Deprecated private CellBaseDataResult postDBFiltering(Query geneQuery, CellBaseDataResult documentCellBaseDataResult) { String annotationFlagsString = geneQuery.getString(QueryParams.TRANSCRIPT_ANNOTATION_FLAGS.key()); if (StringUtils.isNotEmpty(annotationFlagsString)) { diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/GeneManager.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/GeneManager.java index ec977f0c68..83f49c0919 100644 --- a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/GeneManager.java +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/GeneManager.java @@ -19,8 +19,8 @@ import org.opencb.biodata.models.core.Gene; import org.opencb.cellbase.core.api.core.GeneDBAdaptor; import org.opencb.cellbase.core.api.queries.GeneQuery; +import org.opencb.cellbase.core.api.queries.QueryException; import org.opencb.cellbase.core.config.CellBaseConfiguration; -import org.opencb.cellbase.core.exception.CellbaseException; import org.opencb.cellbase.core.result.CellBaseDataResult; import org.opencb.commons.datastore.core.Query; @@ -41,7 +41,7 @@ private void init() { geneDBAdaptor = dbAdaptorFactory.getGeneDBAdaptor(species, assembly); } - public CellBaseDataResult search(GeneQuery geneQuery) throws CellbaseException { + public CellBaseDataResult search(GeneQuery geneQuery) throws QueryException { geneQuery.setDefaults(); geneQuery.validate(); // TODO throw execption if facets populated diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/MetaWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/MetaWSServer.java index 9e3988c772..48f5b01f88 100644 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/MetaWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/MetaWSServer.java @@ -226,8 +226,7 @@ public Response status(@PathParam("species") @ApiParam(name = "species", value = @GET @Path("/api") @ApiOperation(value = "API", response = Map.class) - public Response api(@ApiParam(value = "List of categories to get API from, e.g. Xref,Gene") @QueryParam("category") String categoryStr) - { + public Response api(@ApiParam(value = "List of categories to get API from, e.g. Xref,Gene") @QueryParam("category") String category) { List> api = new ArrayList<>(20); Map classes = new LinkedHashMap<>(); classes.put("clinical", ClinicalWSServer.class); @@ -243,28 +242,26 @@ public Response api(@ApiParam(value = "List of categories to get API from, e.g. classes.put("variant", VariantWSServer.class); classes.put("xref", IdWSServer.class); - if (StringUtils.isNotEmpty(categoryStr)) { - for (String category : categoryStr.split(",")) { - Class clazz = classes.get(category.toLowerCase()); + if (StringUtils.isNotEmpty(category)) { + for (String cat : category.split(",")) { + Class clazz = classes.get(cat.toLowerCase()); if (clazz == null) { - return createErrorResponse(new CellbaseException("Category not found: " + category)); + return createErrorResponse(new CellbaseException("Category not found: " + cat)); } LinkedHashMap help = getHelp(clazz); api.add(help); } } else { // Get API for all categories - for (String category : classes.keySet()) { - api.add(getHelp(classes.get(category))); + for (String cat : classes.keySet()) { + api.add(getHelp(classes.get(cat))); } } - return createOkResponse(new CellBaseDataResult<>(null, 0, Collections.emptyList(), 1, - Collections.singletonList(api), 1)); + return createOkResponse(new CellBaseDataResult<>(null, 0, Collections.emptyList(), 1, Collections.singletonList(api), 1)); } private LinkedHashMap getHelp(Class clazz) { LinkedHashMap map = new LinkedHashMap<>(); - map.put("name", ((Api) clazz.getAnnotation(Api.class)).value()); map.put("path", ((Path) clazz.getAnnotation(Path.class)).value()); @@ -274,18 +271,15 @@ private LinkedHashMap getHelp(Class clazz) { String httpMethod = "GET"; if (method.getAnnotation(POST.class) != null) { httpMethod = "POST"; - } else { - if (method.getAnnotation(DELETE.class) != null) { - httpMethod = "DELETE"; - } } + ApiOperation apiOperationAnnotation = method.getAnnotation(ApiOperation.class); if (pathAnnotation != null && apiOperationAnnotation != null && !apiOperationAnnotation.hidden()) { LinkedHashMap endpoint = new LinkedHashMap<>(); endpoint.put("path", map.get("path") + pathAnnotation.value()); endpoint.put("method", httpMethod); - endpoint.put("response", StringUtils.substringAfterLast(apiOperationAnnotation.response().getName() - .replace("Void", ""), ".")); + endpoint.put("response", StringUtils + .substringAfterLast(apiOperationAnnotation.response().getName().replace("Void", ""), ".")); String responseClass = apiOperationAnnotation.response().getName().replace("Void", ""); endpoint.put("responseClass", responseClass.endsWith(";") ? responseClass : responseClass + ";"); diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java index d53c07e350..cf4015e3d8 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java @@ -25,6 +25,7 @@ import org.opencb.biodata.models.variant.Variant; import org.opencb.cellbase.core.ParamConstants; import org.opencb.cellbase.core.api.queries.GeneQuery; +import org.opencb.cellbase.core.api.queries.QueryException; import org.opencb.cellbase.core.exception.CellbaseException; import org.opencb.cellbase.core.result.CellBaseDataResult; import org.opencb.cellbase.lib.SpeciesUtils; @@ -302,7 +303,7 @@ public Response getAggregationStats(@DefaultValue("") @QueryParam("fields") @ApiImplicitParam(name = "skip", value = ParamConstants.SKIP_DESCRIPTION, required = false, defaultValue = "0", dataType = "java.util.List", paramType = "query") }) - public Response getAll() throws CellbaseException { + public Response getAll() throws QueryException { GeneQuery geneQuery = new GeneQuery(uriParams); CellBaseDataResult queryResults = geneManager.search(geneQuery); return createOkResponse(queryResults);