Skip to content

Commit

Permalink
lib: rename params, #TASK-4791, #TASK-4641
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Aug 28, 2023
1 parent 39d17e7 commit be9c607
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ private <U> CellBaseDataResponse<U> restCall(List<String> hosts, String version,
if (assembly != null && StringUtils.isEmpty(queryOptions.getString("assembly"))) {
callUrl = callUrl.queryParam("assembly", assembly);
}
if (dataRelease != null && StringUtils.isEmpty(queryOptions.getString(AbstractQuery.DATA_RELEASE))) {
callUrl = callUrl.queryParam(AbstractQuery.DATA_RELEASE, dataRelease);
if (dataRelease != null && StringUtils.isEmpty(queryOptions.getString(AbstractQuery.DATA_RELEASE_PARAM))) {
callUrl = callUrl.queryParam(AbstractQuery.DATA_RELEASE_PARAM, dataRelease);
}
if (apiKey != null && StringUtils.isEmpty(queryOptions.getString(AbstractQuery.API_KEY_PARAM))) {
callUrl = callUrl.queryParam(AbstractQuery.API_KEY_PARAM, apiKey);
Expand All @@ -458,7 +458,7 @@ private <U> CellBaseDataResponse<U> restCall(List<String> hosts, String version,
callUrl = callUrl.queryParam("assembly", assembly);
}
if (dataRelease != null) {
callUrl = callUrl.queryParam(AbstractQuery.DATA_RELEASE, dataRelease);
callUrl = callUrl.queryParam(AbstractQuery.DATA_RELEASE_PARAM, dataRelease);
}
if (apiKey != null) {
callUrl = callUrl.queryParam(AbstractQuery.API_KEY_PARAM, apiKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public ApiKeyManager(String algorithm, Key secretKey) {
defaultApiKey = encode(payload);
}

public ApiKeyManager() {
jwtParser = Jwts.parserBuilder().build();
}

public String encode(ApiKeyJwtPayload payload) {
JwtBuilder jwtBuilder = Jwts.builder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public abstract class AbstractQuery extends CellBaseQueryOptions {
// public static final int DEFAULT_LIMIT = 50;
public static final int DEFAULT_SKIP = 0;

public static final String DATA_RELEASE = "dataRelease";
public static final String DATA_RELEASE_PARAM = "dataRelease";
public static final String API_KEY_PARAM = "apiKey";
@Deprecated
public static final String TOKEN_PARAM = "token";
// @Deprecated
// public static final String TOKEN_PARAM = "token";

// list of fields in this class
private Map<String, Field> classFields;
Expand All @@ -59,7 +59,7 @@ public abstract class AbstractQuery extends CellBaseQueryOptions {
// key = camelCase name (transcriptsBiotype) to annotations
private Map<String, QueryParameter> annotations;

@QueryParameter(id = DATA_RELEASE)
@QueryParameter(id = DATA_RELEASE_PARAM)
private Integer dataRelease;

@QueryParameter(id = API_KEY_PARAM)
Expand Down Expand Up @@ -469,15 +469,4 @@ public AbstractQuery setApiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}

@Deprecated
public String getToken() {
return apiKey;
}

@Deprecated
public AbstractQuery setToken(String token) {
this.apiKey = token;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public CellBaseDataResult<Long> count(Query query) throws CellBaseException {
Bson bson = parseQuery(query);

MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease,
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE, 0));
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE_PARAM, 0));
return new CellBaseDataResult<>(mongoDBCollection.count(bson));
}

public CellBaseDataResult distinct(Query query, String field) throws CellBaseException {
Bson bson = parseQuery(query);

MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease,
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE, 0));
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE_PARAM, 0));
return new CellBaseDataResult<>(mongoDBCollection.distinct(field, bson));
}

Expand All @@ -128,7 +128,7 @@ public CellBaseDataResult<Variant> get(Query query, QueryOptions options) throws
logger.debug("queryOptions: {}", options.toJson());

MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease,
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE, 0));
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE_PARAM, 0));
return new CellBaseDataResult<>(mongoDBCollection.find(bson, null, Variant.class, parsedOptions));
}

Expand All @@ -140,7 +140,7 @@ public CellBaseDataResult nativeGet(Query query, QueryOptions options) throws Ce
logger.debug("queryOptions: {}", options.toJson());

MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease,
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE, 0));
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE_PARAM, 0));
return new CellBaseDataResult<>(mongoDBCollection.find(bson, parsedOptions));
}

Expand All @@ -152,7 +152,7 @@ public Iterator nativeIterator(Query query, QueryOptions options) throws CellBas
Bson bson = parseQuery(query);

MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease,
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE, 0));
(Integer) query.getOrDefault(AbstractQuery.DATA_RELEASE_PARAM, 0));
return mongoDBCollection.nativeQuery().find(bson, options);
}

Expand Down Expand Up @@ -223,6 +223,7 @@ public Bson parseQuery(ClinicalVariantQuery query) {
Object value = entry.getValue();
switch (dotNotationName) {
case "token":
case "apiKey":
case "dataRelease":
// Do nothing
break;
Expand Down Expand Up @@ -416,8 +417,8 @@ private CellBaseDataResult<Variant> getClinicalVariant(Variant variant, GenomeMa
}

// Add data release to query
if (!query.containsKey(AbstractQuery.DATA_RELEASE)) {
query.put(AbstractQuery.DATA_RELEASE, dataRelease);
if (!query.containsKey(AbstractQuery.DATA_RELEASE_PARAM)) {
query.put(AbstractQuery.DATA_RELEASE_PARAM, dataRelease);
}
}

Expand Down Expand Up @@ -471,7 +472,7 @@ public CellBaseIterator iterator(ClinicalVariantQuery query) throws CellBaseExce

@Override
public List<CellBaseDataResult<ClinicalVariant>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease,
String token) {
String apiKey) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public CellBaseDataResult<Gene> aggregationStats(GeneQuery query) {
}

@Override
public List<CellBaseDataResult<Gene>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token)
public List<CellBaseDataResult<Gene>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey)
throws CellBaseException {
return info(ids, queryOptions, null, dataRelease, token);
return info(ids, queryOptions, null, dataRelease, apiKey);
}

public List<CellBaseDataResult<Gene>> info(List<String> ids, ProjectionQueryOptions queryOptions, String source, int dataRelease,
String token) throws CellBaseException {
String apiKey) throws CellBaseException {
List<CellBaseDataResult<Gene>> results = new ArrayList<>();
Bson projection = getProjection(queryOptions);
for (String id : ids) {
Expand Down Expand Up @@ -205,9 +205,10 @@ public Bson parseQuery(GeneQuery geneQuery) {
case "mirna":
createMirnaQuery(value, andBsonList);
break;
case "token":
case "apiKey":
case "source":
case "dataRelease":
case "token":
// do nothing
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public CellBaseDataResult<String> distinct(GenomeQuery query) throws CellBaseExc
}

@Override
public List<CellBaseDataResult<Chromosome>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token)
public List<CellBaseDataResult<Chromosome>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey)
throws CellBaseException {
List<CellBaseDataResult<Chromosome>> results = new ArrayList<>();
MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease, dataRelease);
Expand All @@ -548,8 +548,9 @@ public Bson parseQuery(GenomeQuery query) {
case "name":
createAndOrQuery(value, "chromosomes.name", QueryParam.Type.STRING, andBsonList);
break;
case "dataRelease":
case "token":
case "apiKey":
case "dataRelease":
// Do nothing
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public CellBaseIterator<OntologyTerm> iterator(OntologyQuery query) throws CellB
}

@Override
public List<CellBaseDataResult<OntologyTerm>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token)
throws CellBaseException {
public List<CellBaseDataResult<OntologyTerm>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease,
String apiKey) throws CellBaseException {
List<CellBaseDataResult<OntologyTerm>> results = new ArrayList<>();
Bson projection = getProjection(queryOptions);
MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease, dataRelease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public CellBaseDataResult<PharmaChemical> aggregationStats(PharmaChemicalQuery q

@Override
public List<CellBaseDataResult<PharmaChemical>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease,
String token) throws CellBaseException {
String apiKey) throws CellBaseException {
List<CellBaseDataResult<PharmaChemical>> results = new ArrayList<>();
Bson projection = getProjection(queryOptions);
for (String id : ids) {
Expand Down Expand Up @@ -114,8 +114,9 @@ public Bson parseQuery(PharmaChemicalQuery pharmaQuery) {
String dotNotationName = entry.getKey();
Object value = entry.getValue();
switch (dotNotationName) {
case "dataRelease":
case "token":
case "apiKey":
case "dataRelease":
// do nothing
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public CellBaseIterator<Entry> iterator(ProteinQuery query) throws CellBaseExcep
}

@Override
public List<CellBaseDataResult<Entry>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token)
public List<CellBaseDataResult<Entry>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey)
throws CellBaseException {
List<CellBaseDataResult<Entry>> results = new ArrayList<>();
MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease, dataRelease);
Expand Down Expand Up @@ -364,8 +364,9 @@ public Bson parseQuery(ProteinQuery proteinQuery) {
case "keyword":
createAndOrQuery(value, "keyword.value", QueryParam.Type.STRING, andBsonList);
break;
case "dataRelease":
case "token":
case "apiKey":
case "dataRelease":
// Do nothing
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CellBaseIterator<PubmedArticle> iterator(PublicationQuery query) throws C

@Override
public List<CellBaseDataResult<PubmedArticle>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease,
String token) throws CellBaseException {
String apiKey) throws CellBaseException {
List<CellBaseDataResult<PubmedArticle>> results = new ArrayList<>();
Bson projection = getProjection(queryOptions);
MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease, dataRelease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public Bson parseQuery(RegulationQuery query) {
case "region":
createRegionQuery(query, value, MongoDBCollectionConfiguration.REGULATORY_REGION_CHUNK_SIZE, andBsonList);
break;
case "dataRelease":
case "token":
case "apiKey":
case "dataRelease":
// Do nothing
break;
default:
Expand Down Expand Up @@ -104,7 +105,7 @@ public CellBaseIterator<RegulatoryFeature> iterator(RegulationQuery query) throw

@Override
public List<CellBaseDataResult<RegulatoryFeature>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease,
String token) {
String apiKey) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public CellBaseDataResult<String> distinct(AbstractQuery query) {
}

@Override
public List<CellBaseDataResult> info(List ids, ProjectionQueryOptions queryOptions, int dataRelease, String token) {
public List<CellBaseDataResult> info(List ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public Bson parseQuery(RepeatsQuery query) {
case "region":
createRegionQuery(query, value, MongoDBCollectionConfiguration.REPEATS_CHUNK_SIZE, andBsonList);
break;
case "dataRelease":
case "token":
case "apiKey":
case "dataRelease":
// Do nothing
break;
default:
Expand Down Expand Up @@ -100,7 +101,7 @@ public CellBaseIterator iterator(RepeatsQuery query) throws CellBaseException {
}

@Override
public List<CellBaseDataResult<Repeat>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token) {
public List<CellBaseDataResult<Repeat>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public CellBaseIterator<Transcript> iterator(TranscriptQuery query) throws CellB

@Override
public List<CellBaseDataResult<Transcript>> info(List<String> ids, ProjectionQueryOptions projectionQueryOptions, int dataRelease,
String token) throws CellBaseException {
return info(ids, projectionQueryOptions, null, dataRelease, token);
String apiKey) throws CellBaseException {
return info(ids, projectionQueryOptions, null, dataRelease, apiKey);
}

public List<CellBaseDataResult<Transcript>> info(List<String> ids, ProjectionQueryOptions projectionQueryOptions, String source,
int dataRelease, String token) throws CellBaseException {
int dataRelease, String apiKey) throws CellBaseException {
List<CellBaseDataResult<Transcript>> results = new ArrayList<>();
QueryOptions queryOptions = getInfoQueryOptions(projectionQueryOptions);
for (String id : ids) {
Expand Down Expand Up @@ -221,9 +221,10 @@ public Bson parseQuery(TranscriptQuery query) {
case "transcripts.supportLevel":
andBsonList.add(Filters.regex("transcripts.supportLevel", "^" + value));
break;
case "token":
case "source":
case "apiKey":
case "dataRelease":
case "token":
// Do nothing
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public Bson parseQuery(VariantQuery query) {
case "region":
createRegionQuery(query, query.getRegions(), MongoDBCollectionConfiguration.VARIATION_CHUNK_SIZE, andBsonList);
break;
case VariantQuery.DATA_RELEASE:
case VariantQuery.DATA_RELEASE_PARAM:
case "svType":
// don't do anything, this is parsed later
break;
Expand Down Expand Up @@ -740,7 +740,7 @@ public CellBaseDataResult<String> distinct(VariantQuery query) {
}

@Override
public List<CellBaseDataResult<Variant>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token)
public List<CellBaseDataResult<Variant>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey)
throws CellBaseException {
List<CellBaseDataResult<Variant>> results = new ArrayList<>();
MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease, dataRelease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CellBaseIterator<Xref> iterator(XrefQuery query) throws CellBaseException
}

@Override
public List<CellBaseDataResult<Xref>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token)
public List<CellBaseDataResult<Xref>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey)
throws CellBaseException {
List<CellBaseDataResult<Xref>> results = new ArrayList<>();
for (String id : ids) {
Expand Down Expand Up @@ -153,8 +153,9 @@ public Bson parseQuery(XrefQuery query) {
case "dbname":
createAndOrQuery(value, "transcripts.xrefs.dbName", QueryParam.Type.STRING, andBsonList);
break;
case "dataRelease":
case "token":
case "apiKey":
case "dataRelease":
// Do nothing
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.List;

import static org.opencb.cellbase.core.api.query.AbstractQuery.API_KEY_PARAM;
import static org.opencb.cellbase.core.api.query.AbstractQuery.TOKEN_PARAM;

public class AbstractManager implements AutoCloseable {

Expand Down Expand Up @@ -84,10 +83,7 @@ public AbstractManager(String species, String assembly, CellBaseConfiguration co
}

protected String getApiKey(QueryOptions queryOptions) {
if (queryOptions.containsKey(API_KEY_PARAM)) {
return queryOptions.getString(API_KEY_PARAM);
}
return queryOptions.getString(TOKEN_PARAM);
return queryOptions.getString(API_KEY_PARAM);
}

@Deprecated
Expand Down
Loading

0 comments on commit be9c607

Please sign in to comment.