-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
catalog: start organization implementation, #TASK-4389
- Loading branch information
Showing
8 changed files
with
608 additions
and
0 deletions.
There are no files selected for viewing
235 changes: 235 additions & 0 deletions
235
opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/api/OrganizationDBAdaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
package org.opencb.opencga.catalog.db.api; | ||
|
||
import org.opencb.commons.datastore.core.Query; | ||
import org.opencb.commons.datastore.core.QueryOptions; | ||
import org.opencb.commons.datastore.core.QueryParam; | ||
import org.opencb.opencga.catalog.exceptions.CatalogDBException; | ||
import org.opencb.opencga.core.models.organizations.Organization; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.opencb.commons.datastore.core.QueryParam.Type.*; | ||
|
||
public interface OrganizationDBAdaptor extends Iterable<Organization> { | ||
|
||
enum QueryParams implements QueryParam { | ||
UID("uid", LONG, ""), | ||
ID("id", STRING, ""), | ||
UUID("uuid", STRING, ""), | ||
NAME("name", STRING, ""), | ||
DOMAIN("domain", STRING, ""), | ||
OWNER("owner", STRING, ""), | ||
ADMINS("admins", TEXT_ARRAY, ""), | ||
CREATION_DATE("creationDate", DATE, ""), | ||
MODIFICATION_DATE("modificationDate", DATE, ""), | ||
PROJECTS("projects", OBJECT, ""), | ||
AUTHENTICATION_ORIGINS("authenticationOrigins", OBJECT, ""), | ||
ATTRIBUTES("attributes", OBJECT, ""); | ||
|
||
private static Map<String, QueryParams> map = new HashMap<>(); | ||
|
||
static { | ||
for (QueryParams params : QueryParams.values()) { | ||
map.put(params.key(), params); | ||
} | ||
} | ||
|
||
private final String key; | ||
private Type type; | ||
private String description; | ||
|
||
QueryParams(String key, Type type, String description) { | ||
this.key = key; | ||
this.type = type; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String key() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return description; | ||
} | ||
|
||
public static Map<String, QueryParams> getMap() { | ||
return map; | ||
} | ||
|
||
public static QueryParams getParam(String key) { | ||
return map.get(key); | ||
} | ||
} | ||
|
||
// default boolean exists(long projectId) throws CatalogDBException { | ||
// return count(new Query(QueryParams.UID.key(), projectId)).getNumMatches() > 0; | ||
// } | ||
// | ||
// default void checkId(long projectId) throws CatalogDBException { | ||
// if (projectId < 0) { | ||
// throw CatalogDBException.newInstance("Project id '{}' is not valid: ", projectId); | ||
// } | ||
// | ||
// if (!exists(projectId)) { | ||
// throw CatalogDBException.newInstance("Project id '{}' does not exist", projectId); | ||
// } | ||
// } | ||
// | ||
// OpenCGAResult nativeInsert(Map<String, Object> project, String userId) throws CatalogDBException; | ||
// | ||
// OpenCGAResult insert(Project project, String userId, QueryOptions options) | ||
// throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException; | ||
// | ||
// OpenCGAResult<Project> get(String userId, QueryOptions options) throws CatalogDBException; | ||
// | ||
// OpenCGAResult<Project> get(long project, QueryOptions options) throws CatalogDBException; | ||
// | ||
// OpenCGAResult incrementCurrentRelease(long projectId) throws CatalogDBException; | ||
// | ||
// long getId(String userId, String projectAlias) throws CatalogDBException; | ||
// | ||
// String getOwnerId(long projectId) throws CatalogDBException; | ||
// | ||
// | ||
// default OpenCGAResult<Long> count() throws CatalogDBException { | ||
// return count(new Query()); | ||
// } | ||
// | ||
// OpenCGAResult<Long> count(Query query) throws CatalogDBException; | ||
// | ||
// OpenCGAResult<Long> count(Query query, String user, StudyPermissions.Permissions studyPermission) | ||
// throws CatalogDBException, CatalogAuthorizationException; | ||
// | ||
// default OpenCGAResult distinct(String field) throws CatalogDBException { | ||
// return distinct(new Query(), field); | ||
// } | ||
// | ||
// OpenCGAResult distinct(Query query, String field) throws CatalogDBException; | ||
// | ||
// | ||
// default OpenCGAResult stats() { | ||
// return stats(new Query()); | ||
// } | ||
// | ||
// OpenCGAResult stats(Query query); | ||
// | ||
// | ||
// OpenCGAResult<Project> get(Query query, QueryOptions options) throws CatalogDBException; | ||
// | ||
// OpenCGAResult<Project> get(Query query, QueryOptions options, String user) throws CatalogDBException, CatalogParameterException; | ||
// | ||
// default List<OpenCGAResult<Project>> get(List<Query> queries, QueryOptions options) throws CatalogDBException { | ||
// Objects.requireNonNull(queries); | ||
// List<OpenCGAResult<Project>> queryResults = new ArrayList<>(queries.size()); | ||
// for (Query query : queries) { | ||
// queryResults.add(get(query, options)); | ||
// } | ||
// return queryResults; | ||
// } | ||
// | ||
// OpenCGAResult nativeGet(Query query, QueryOptions options) throws CatalogDBException; | ||
// | ||
// OpenCGAResult nativeGet(Query query, QueryOptions options, String user) | ||
// throws CatalogDBException, CatalogAuthorizationException; | ||
// | ||
// default List<OpenCGAResult> nativeGet(List<Query> queries, QueryOptions options) throws CatalogDBException { | ||
// Objects.requireNonNull(queries); | ||
// List<OpenCGAResult> queryResults = new ArrayList<>(queries.size()); | ||
// for (Query query : queries) { | ||
// queryResults.add(nativeGet(query, options)); | ||
// } | ||
// return queryResults; | ||
// } | ||
// | ||
// OpenCGAResult<Project> update(long id, ObjectMap parameters, QueryOptions queryOptions) | ||
// throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException; | ||
// | ||
// OpenCGAResult<Long> update(Query query, ObjectMap parameters, QueryOptions queryOptions) throws CatalogDBException; | ||
// | ||
// OpenCGAResult delete(Project project) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException; | ||
// | ||
// OpenCGAResult delete(Query query) throws CatalogDBException; | ||
// | ||
// default OpenCGAResult<Project> delete(long id, QueryOptions queryOptions) throws CatalogDBException { | ||
// throw new NotImplementedException(""); | ||
// } | ||
// | ||
// @Deprecated | ||
// default OpenCGAResult<Long> delete(Query query, QueryOptions queryOptions) throws CatalogDBException { | ||
// throw new NotImplementedException(""); | ||
// } | ||
// | ||
// @Deprecated | ||
// default OpenCGAResult<Project> remove(long id, QueryOptions queryOptions) throws CatalogDBException { | ||
// throw new NotImplementedException(""); | ||
// } | ||
// | ||
// @Deprecated | ||
// default OpenCGAResult<Long> remove(Query query, QueryOptions queryOptions) throws CatalogDBException { | ||
// throw new NotImplementedException(""); | ||
// } | ||
// | ||
// OpenCGAResult<Project> restore(long id, QueryOptions queryOptions) | ||
// throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException; | ||
// | ||
// OpenCGAResult<Long> restore(Query query, QueryOptions queryOptions) throws CatalogDBException; | ||
// | ||
// | ||
//// OpenCGAResult<Long> updateStatus(Query query, Status status) throws CatalogDBException; | ||
// | ||
// | ||
@Override | ||
default DBIterator<Organization> iterator() { | ||
try { | ||
return iterator(new Query(), new QueryOptions()); | ||
} catch (CatalogDBException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
DBIterator<Organization> iterator(Query query, QueryOptions options) throws CatalogDBException; | ||
|
||
// default DBIterator nativeIterator() throws CatalogDBException { | ||
// return nativeIterator(new Query(), new QueryOptions()); | ||
// } | ||
// | ||
// DBIterator nativeIterator(Query query, QueryOptions options) throws CatalogDBException; | ||
// | ||
// DBIterator<Project> iterator(Query query, QueryOptions options, String user) | ||
// throws CatalogDBException, CatalogAuthorizationException; | ||
// | ||
// DBIterator nativeIterator(Query query, QueryOptions options, String user) | ||
// throws CatalogDBException, CatalogAuthorizationException; | ||
// | ||
// OpenCGAResult rank(Query query, String field, int numResults, boolean asc) throws CatalogDBException; | ||
// | ||
// OpenCGAResult groupBy(Query query, String field, QueryOptions options) throws CatalogDBException; | ||
// | ||
// OpenCGAResult groupBy(Query query, List<String> fields, QueryOptions options) throws CatalogDBException; | ||
// | ||
// OpenCGAResult groupBy(Query query, String field, QueryOptions options, String user) | ||
// throws CatalogDBException, CatalogAuthorizationException; | ||
// | ||
// OpenCGAResult groupBy(Query query, List<String> fields, QueryOptions options, String user) | ||
// throws CatalogDBException, CatalogAuthorizationException; | ||
// | ||
// @Override | ||
// default void forEach(Consumer action) { | ||
// try { | ||
// forEach(new Query(), action, new QueryOptions()); | ||
// } catch (CatalogDBException e) { | ||
// throw new RuntimeException(e); | ||
// } | ||
// } | ||
// | ||
// void forEach(Query query, Consumer<? super Object> action, QueryOptions options) throws CatalogDBException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...talog/src/main/java/org/opencb/opencga/catalog/db/mongodb/OrganizationMongoDBAdaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.opencb.opencga.catalog.db.mongodb; | ||
|
||
import com.mongodb.client.ClientSession; | ||
import org.bson.Document; | ||
import org.opencb.commons.datastore.core.Query; | ||
import org.opencb.commons.datastore.core.QueryOptions; | ||
import org.opencb.commons.datastore.mongodb.MongoDBCollection; | ||
import org.opencb.commons.datastore.mongodb.MongoDBIterator; | ||
import org.opencb.opencga.catalog.db.api.DBIterator; | ||
import org.opencb.opencga.catalog.db.api.OrganizationDBAdaptor; | ||
import org.opencb.opencga.catalog.db.mongodb.converters.OrganizationConverter; | ||
import org.opencb.opencga.catalog.db.mongodb.iterators.ProjectCatalogMongoDBIterator; | ||
import org.opencb.opencga.catalog.exceptions.CatalogDBException; | ||
import org.opencb.opencga.core.config.Configuration; | ||
import org.opencb.opencga.core.models.organizations.Organization; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class OrganizationMongoDBAdaptor extends MongoDBAdaptor implements OrganizationDBAdaptor { | ||
|
||
private final MongoDBCollection organizationCollection; | ||
private final MongoDBCollection deletedOrganizationCollection; | ||
private OrganizationConverter organizationConverter; | ||
|
||
public OrganizationMongoDBAdaptor(MongoDBCollection organizationCollection, MongoDBCollection deletedOrganizationCollection, | ||
Configuration configuration, MongoDBAdaptorFactory dbAdaptorFactory) { | ||
super(configuration, LoggerFactory.getLogger(ProjectMongoDBAdaptor.class)); | ||
this.dbAdaptorFactory = dbAdaptorFactory; | ||
this.organizationCollection = organizationCollection; | ||
this.deletedOrganizationCollection = deletedOrganizationCollection; | ||
this.organizationConverter = new OrganizationConverter(); | ||
} | ||
|
||
@Override | ||
public DBIterator<Organization> iterator(Query query, QueryOptions options) throws CatalogDBException { | ||
return iterator(null, query, options); | ||
} | ||
|
||
public DBIterator<Organization> iterator(ClientSession clientSession, Query query, QueryOptions options) throws CatalogDBException { | ||
MongoDBIterator<Document> mongoCursor = getMongoCursor(clientSession, query, options); | ||
return new ProjectCatalogMongoDBIterator<>(mongoCursor, clientSession, organizationConverter, dbAdaptorFactory, options, null); | ||
} | ||
|
||
private MongoDBIterator<Document> getMongoCursor(ClientSession clientSession, Query query, QueryOptions options) { | ||
return null; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/OrganizationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.opencb.opencga.catalog.db.mongodb.converters; | ||
|
||
import org.apache.avro.generic.GenericRecord; | ||
import org.bson.Document; | ||
import org.opencb.opencga.core.models.common.mixins.GenericRecordAvroJsonMixin; | ||
import org.opencb.opencga.core.models.organizations.Organization; | ||
|
||
public class OrganizationConverter extends OpenCgaMongoConverter<Organization> { | ||
|
||
public OrganizationConverter() { | ||
super(Organization.class); | ||
getObjectMapper().addMixIn(GenericRecord.class, GenericRecordAvroJsonMixin.class); | ||
} | ||
|
||
@Override | ||
public Document convertToStorageType(Organization object) { | ||
Document document = super.convertToStorageType(object); | ||
document.put("uid", document.getInteger("uid").longValue()); | ||
return document; | ||
} | ||
} |
Oops, something went wrong.