From b76f2dca347f09694f44d8152f525f16b6098f65 Mon Sep 17 00:00:00 2001 From: pfurio Date: Fri, 14 Jul 2023 15:02:52 +0200 Subject: [PATCH] catalog: start organization implementation, #TASK-4389 --- .../catalog/db/api/OrganizationDBAdaptor.java | 235 ++++++++++++++++++ .../db/mongodb/MongoDBAdaptorFactory.java | 15 ++ .../mongodb/OrganizationMongoDBAdaptor.java | 46 ++++ .../converters/OrganizationConverter.java | 21 ++ .../OrganizationCatalogMongoDBIterator.java | 88 +++++++ .../catalog/managers/OrganizationManager.java | 22 ++ .../opencga/core/api/FieldConstants.java | 10 + .../models/organizations/Organization.java | 171 +++++++++++++ 8 files changed, 608 insertions(+) create mode 100644 opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/api/OrganizationDBAdaptor.java create mode 100644 opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/OrganizationMongoDBAdaptor.java create mode 100644 opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/OrganizationConverter.java create mode 100644 opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/OrganizationCatalogMongoDBIterator.java create mode 100644 opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/OrganizationManager.java create mode 100644 opencga-core/src/main/java/org/opencb/opencga/core/models/organizations/Organization.java diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/api/OrganizationDBAdaptor.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/api/OrganizationDBAdaptor.java new file mode 100644 index 00000000000..94f3762c659 --- /dev/null +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/api/OrganizationDBAdaptor.java @@ -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 { + + 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 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 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 project, String userId) throws CatalogDBException; +// +// OpenCGAResult insert(Project project, String userId, QueryOptions options) +// throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException; +// +// OpenCGAResult get(String userId, QueryOptions options) throws CatalogDBException; +// +// OpenCGAResult 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 count() throws CatalogDBException { +// return count(new Query()); +// } +// +// OpenCGAResult count(Query query) throws CatalogDBException; +// +// OpenCGAResult 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 get(Query query, QueryOptions options) throws CatalogDBException; +// +// OpenCGAResult get(Query query, QueryOptions options, String user) throws CatalogDBException, CatalogParameterException; +// +// default List> get(List queries, QueryOptions options) throws CatalogDBException { +// Objects.requireNonNull(queries); +// List> 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 nativeGet(List queries, QueryOptions options) throws CatalogDBException { +// Objects.requireNonNull(queries); +// List queryResults = new ArrayList<>(queries.size()); +// for (Query query : queries) { +// queryResults.add(nativeGet(query, options)); +// } +// return queryResults; +// } +// +// OpenCGAResult update(long id, ObjectMap parameters, QueryOptions queryOptions) +// throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException; +// +// OpenCGAResult 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 delete(long id, QueryOptions queryOptions) throws CatalogDBException { +// throw new NotImplementedException(""); +// } +// +// @Deprecated +// default OpenCGAResult delete(Query query, QueryOptions queryOptions) throws CatalogDBException { +// throw new NotImplementedException(""); +// } +// +// @Deprecated +// default OpenCGAResult remove(long id, QueryOptions queryOptions) throws CatalogDBException { +// throw new NotImplementedException(""); +// } +// +// @Deprecated +// default OpenCGAResult remove(Query query, QueryOptions queryOptions) throws CatalogDBException { +// throw new NotImplementedException(""); +// } +// +// OpenCGAResult restore(long id, QueryOptions queryOptions) +// throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException; +// +// OpenCGAResult restore(Query query, QueryOptions queryOptions) throws CatalogDBException; +// +// +//// OpenCGAResult updateStatus(Query query, Status status) throws CatalogDBException; +// +// + @Override + default DBIterator iterator() { + try { + return iterator(new Query(), new QueryOptions()); + } catch (CatalogDBException e) { + throw new RuntimeException(e); + } + } + + DBIterator 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 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 fields, QueryOptions options) throws CatalogDBException; +// +// OpenCGAResult groupBy(Query query, String field, QueryOptions options, String user) +// throws CatalogDBException, CatalogAuthorizationException; +// +// OpenCGAResult groupBy(Query query, List 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 action, QueryOptions options) throws CatalogDBException; + +} diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java index 05acf9aed2b..d16008639f8 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java @@ -46,6 +46,7 @@ */ public class MongoDBAdaptorFactory implements DBAdaptorFactory { + public static final String ORGANIZATION_COLLECTION = "organization"; public static final String USER_COLLECTION = "user"; public static final String STUDY_COLLECTION = "study"; public static final String FILE_COLLECTION = "file"; @@ -87,6 +88,7 @@ public class MongoDBAdaptorFactory implements DBAdaptorFactory { @Deprecated public static final String OLD_DELETED_INTERPRETATION_COLLECTION = "deleted_interpretation"; + public static final String DELETED_ORGANIZATION_COLLECTION = "organization_deleted"; public static final String DELETED_USER_COLLECTION = "user_deleted"; public static final String DELETED_STUDY_COLLECTION = "study_deleted"; public static final String DELETED_FILE_COLLECTION = "file_deleted"; @@ -104,6 +106,7 @@ public class MongoDBAdaptorFactory implements DBAdaptorFactory { public static final String AUDIT_COLLECTION = "audit"; public static final List COLLECTIONS_LIST = Arrays.asList( + ORGANIZATION_COLLECTION, USER_COLLECTION, STUDY_COLLECTION, FILE_COLLECTION, @@ -122,6 +125,7 @@ public class MongoDBAdaptorFactory implements DBAdaptorFactory { PANEL_ARCHIVE_COLLECTION, INTERPRETATION_ARCHIVE_COLLECTION, + DELETED_ORGANIZATION_COLLECTION, DELETED_USER_COLLECTION, DELETED_STUDY_COLLECTION, DELETED_FILE_COLLECTION, @@ -147,6 +151,7 @@ public class MongoDBAdaptorFactory implements DBAdaptorFactory { private MongoDBCollection metaCollection; private Map collections; + private OrganizationMongoDBAdaptor organizationDBAdaptor; private UserMongoDBAdaptor userDBAdaptor; private StudyMongoDBAdaptor studyDBAdaptor; private IndividualMongoDBAdaptor individualDBAdaptor; @@ -266,6 +271,10 @@ public MetaMongoDBAdaptor getCatalogMetaDBAdaptor() { return metaDBAdaptor; } + public OrganizationMongoDBAdaptor getOrganizationDBAdaptor() { + return organizationDBAdaptor; + } + @Override public UserMongoDBAdaptor getCatalogUserDBAdaptor() { return userDBAdaptor; @@ -354,6 +363,7 @@ private void connect(Configuration catalogConfiguration) throws CatalogDBExcepti metaCollection = mongoDataStore.getCollection(METADATA_COLLECTION); MongoDBCollection migrationCollection = mongoDataStore.getCollection(MIGRATION_COLLECTION); + MongoDBCollection organizationCollection = mongoDataStore.getCollection(ORGANIZATION_COLLECTION); MongoDBCollection userCollection = mongoDataStore.getCollection(USER_COLLECTION); MongoDBCollection studyCollection = mongoDataStore.getCollection(STUDY_COLLECTION); MongoDBCollection fileCollection = mongoDataStore.getCollection(FILE_COLLECTION); @@ -372,6 +382,7 @@ private void connect(Configuration catalogConfiguration) throws CatalogDBExcepti MongoDBCollection panelArchivedCollection = mongoDataStore.getCollection(PANEL_ARCHIVE_COLLECTION); MongoDBCollection interpretationArchivedCollection = mongoDataStore.getCollection(INTERPRETATION_ARCHIVE_COLLECTION); + MongoDBCollection deletedOrganizationCollection = mongoDataStore.getCollection(DELETED_ORGANIZATION_COLLECTION); MongoDBCollection deletedUserCollection = mongoDataStore.getCollection(DELETED_USER_COLLECTION); MongoDBCollection deletedStudyCollection = mongoDataStore.getCollection(DELETED_STUDY_COLLECTION); MongoDBCollection deletedFileCollection = mongoDataStore.getCollection(DELETED_FILE_COLLECTION); @@ -390,6 +401,7 @@ private void connect(Configuration catalogConfiguration) throws CatalogDBExcepti collections.put(METADATA_COLLECTION, metaCollection); collections.put(MIGRATION_COLLECTION, migrationCollection); + collections.put(ORGANIZATION_COLLECTION, organizationCollection); collections.put(USER_COLLECTION, userCollection); collections.put(STUDY_COLLECTION, studyCollection); collections.put(FILE_COLLECTION, fileCollection); @@ -408,6 +420,7 @@ private void connect(Configuration catalogConfiguration) throws CatalogDBExcepti collections.put(PANEL_ARCHIVE_COLLECTION, panelArchivedCollection); collections.put(INTERPRETATION_ARCHIVE_COLLECTION, interpretationArchivedCollection); + collections.put(DELETED_ORGANIZATION_COLLECTION, deletedOrganizationCollection); collections.put(DELETED_USER_COLLECTION, deletedUserCollection); collections.put(DELETED_STUDY_COLLECTION, deletedStudyCollection); collections.put(DELETED_FILE_COLLECTION, deletedFileCollection); @@ -429,6 +442,8 @@ private void connect(Configuration catalogConfiguration) throws CatalogDBExcepti catalogConfiguration, this); jobDBAdaptor = new JobMongoDBAdaptor(jobCollection, deletedJobCollection, catalogConfiguration, this); projectDBAdaptor = new ProjectMongoDBAdaptor(userCollection, deletedUserCollection, catalogConfiguration, this); + organizationDBAdaptor = new OrganizationMongoDBAdaptor(organizationCollection, deletedOrganizationCollection, catalogConfiguration, + this); sampleDBAdaptor = new SampleMongoDBAdaptor(sampleCollection, sampleArchivedCollection, deletedSampleCollection, catalogConfiguration, this); studyDBAdaptor = new StudyMongoDBAdaptor(studyCollection, deletedStudyCollection, catalogConfiguration, this); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/OrganizationMongoDBAdaptor.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/OrganizationMongoDBAdaptor.java new file mode 100644 index 00000000000..c7486df7893 --- /dev/null +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/OrganizationMongoDBAdaptor.java @@ -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 iterator(Query query, QueryOptions options) throws CatalogDBException { + return iterator(null, query, options); + } + + public DBIterator iterator(ClientSession clientSession, Query query, QueryOptions options) throws CatalogDBException { + MongoDBIterator mongoCursor = getMongoCursor(clientSession, query, options); + return new ProjectCatalogMongoDBIterator<>(mongoCursor, clientSession, organizationConverter, dbAdaptorFactory, options, null); + } + + private MongoDBIterator getMongoCursor(ClientSession clientSession, Query query, QueryOptions options) { + return null; + } +} diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/OrganizationConverter.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/OrganizationConverter.java new file mode 100644 index 00000000000..e0670ecab85 --- /dev/null +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/OrganizationConverter.java @@ -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 { + + 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; + } +} diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/OrganizationCatalogMongoDBIterator.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/OrganizationCatalogMongoDBIterator.java new file mode 100644 index 00000000000..ef161f79012 --- /dev/null +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/OrganizationCatalogMongoDBIterator.java @@ -0,0 +1,88 @@ +package org.opencb.opencga.catalog.db.mongodb.iterators; + +import com.mongodb.client.ClientSession; +import org.bson.Document; +import org.opencb.commons.datastore.core.QueryOptions; +import org.opencb.commons.datastore.mongodb.GenericDocumentComplexConverter; +import org.opencb.commons.datastore.mongodb.MongoDBIterator; +import org.opencb.opencga.catalog.db.api.OrganizationDBAdaptor; +import org.opencb.opencga.catalog.db.mongodb.MongoDBAdaptorFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Queue; +import java.util.Set; + +public class OrganizationCatalogMongoDBIterator extends CatalogMongoDBIterator { + + private final String user; + + private final QueryOptions options; + + private final Queue organizationListBuffer; + + private final Logger logger; + + private static final int BUFFER_SIZE = 100; + + private static final String UID = OrganizationDBAdaptor.QueryParams.UID.key(); + + public OrganizationCatalogMongoDBIterator(MongoDBIterator mongoCursor, ClientSession clientSession, + GenericDocumentComplexConverter converter, MongoDBAdaptorFactory dbAdaptorFactory, + QueryOptions options, String user) { + super(mongoCursor, clientSession, converter, null); + + this.options = options != null ? new QueryOptions(options) : new QueryOptions(); + + this.user = user; + + this.organizationListBuffer = new LinkedList<>(); + this.logger = LoggerFactory.getLogger(OrganizationCatalogMongoDBIterator.class); + } + + @Override + public boolean hasNext() { + if (organizationListBuffer.isEmpty()) { + fetchNextBatch(); + } + return !organizationListBuffer.isEmpty(); + } + + @Override + public E next() { + Document next = organizationListBuffer.remove(); + + if (filter != null) { + next = filter.apply(next); + } + +// addAclInformation(next, options); + + if (converter != null) { + return (E) converter.convertToDataModelType(next); + } else { + return (E) next; + } + } + + private void fetchNextBatch() { + Set organizationUidSet = new HashSet<>(); + + // Get next BUFFER_SIZE documents + int counter = 0; + while (mongoCursor.hasNext() && counter < BUFFER_SIZE) { + Document organizationDocument = mongoCursor.next().get("organizations", Document.class); + + organizationListBuffer.add(organizationDocument); + counter++; + + if (options == null || !options.containsKey(QueryOptions.EXCLUDE) + || !options.getAsStringList(QueryOptions.EXCLUDE).contains("organizations.studies")) { + organizationUidSet.add(organizationDocument.get(UID, Long.class)); + } + } + + } +} diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/OrganizationManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/OrganizationManager.java new file mode 100644 index 00000000000..08325a8dbb7 --- /dev/null +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/OrganizationManager.java @@ -0,0 +1,22 @@ +package org.opencb.opencga.catalog.managers; + +import org.opencb.opencga.catalog.auth.authorization.AuthorizationManager; +import org.opencb.opencga.catalog.db.DBAdaptorFactory; +import org.opencb.opencga.catalog.io.CatalogIOManager; +import org.opencb.opencga.core.config.Configuration; + +public class OrganizationManager extends AbstractManager { + + private final CatalogIOManager catalogIOManager; + + OrganizationManager(AuthorizationManager authorizationManager, AuditManager auditManager, CatalogManager catalogManager, + DBAdaptorFactory catalogDBAdaptorFactory, CatalogIOManager catalogIOManager, Configuration configuration) { + super(authorizationManager, auditManager, catalogManager, catalogDBAdaptorFactory, configuration); + this.catalogIOManager = catalogIOManager; + } + + + + + +} diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java b/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java index 4cccaaae80b..1dcd17f6fe5 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java @@ -36,6 +36,16 @@ public class FieldConstants { public static final String QUALITY_CONTROL_FILES_DESCRIPTION = "File IDs related to the quality control."; public static final String QUALITY_CONTROL_COMMENTS_DESCRIPTION = "Comments related to the quality control."; + // Organization + public static final String ORGANIZATION_ID_DESCRIPTION = "Organization unique identifier."; + public static final String ORGANIZATION_NAME_DESCRIPTION = "Organization name."; + public static final String ORGANIZATION_DOMAIN_DESCRIPTION = "Organization domain. Example: 'zettagenomics.com'."; + public static final String ORGANIZATION_OWNER_DESCRIPTION = "Owner of the organization."; + public static final String ORGANIZATION_ADMINS_DESCRIPTION = "Administrative users of the organization."; + public static final String ORGANIZATION_PROJECTS_DESCRIPTION = "Projects the organization holds."; + public static final String ORGANIZATION_AUTHENTICATION_ORIGINS_DESCRIPTION = "Authentication origins used by the organization. This " + + "contains all the configuration necessary to be able to communicate with the external authentication origins."; + //Sample public static final String SAMPLE_ID_DESCRIPTION = "Sample data model hosts information about any biological material, normally " + "extracted from an _Individual_, that is used for a particular analysis. This is the main data model, it stores the most " diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/models/organizations/Organization.java b/opencga-core/src/main/java/org/opencb/opencga/core/models/organizations/Organization.java new file mode 100644 index 00000000000..3d3eca18b37 --- /dev/null +++ b/opencga-core/src/main/java/org/opencb/opencga/core/models/organizations/Organization.java @@ -0,0 +1,171 @@ +package org.opencb.opencga.core.models.organizations; + +import org.opencb.commons.annotations.DataClass; +import org.opencb.commons.annotations.DataField; +import org.opencb.opencga.core.api.FieldConstants; +import org.opencb.opencga.core.config.AuthenticationOrigin; +import org.opencb.opencga.core.models.PrivateFields; +import org.opencb.opencga.core.models.project.Project; + +import java.util.List; +import java.util.Map; + +@DataClass(id = "Organization", since = "3.0", + description = "Organization data model hosts information about the organization managing the data.") +public class Organization extends PrivateFields { + + @DataField(id = "uuid", managed = true, indexed = true, unique = true, immutable = true, + description = FieldConstants.GENERIC_UUID_DESCRIPTION) + private String uuid; + + @DataField(id = "id", required = true, indexed = true, unique = true, immutable = true, + description = FieldConstants.ORGANIZATION_ID_DESCRIPTION) + private String id; + + @DataField(id = "name", description = FieldConstants.ORGANIZATION_NAME_DESCRIPTION) + private String name; + + @DataField(id = "domain", description = FieldConstants.ORGANIZATION_DOMAIN_DESCRIPTION) + private String domain; + + @DataField(id = "owner", description = FieldConstants.ORGANIZATION_OWNER_DESCRIPTION) + private String owner; + + @DataField(id = "admins", description = FieldConstants.ORGANIZATION_ADMINS_DESCRIPTION) + private List admins; + + @DataField(id = "creationDate", description = FieldConstants.GENERIC_CREATION_DATE_DESCRIPTION) + private String creationDate; + + @DataField(id = "modificationDate", description = FieldConstants.GENERIC_MODIFICATION_DATE_DESCRIPTION) + private String modificationDate; + + @DataField(id = "projects", description = FieldConstants.ORGANIZATION_PROJECTS_DESCRIPTION) + private List projects; + + @DataField(id = "authenticationOrigins", description = FieldConstants.ORGANIZATION_AUTHENTICATION_ORIGINS_DESCRIPTION) + private List authenticationOrigins; + + @DataField(id = "attributes", description = FieldConstants.GENERIC_ATTRIBUTES_DESCRIPTION) + private Map attributes; + + public Organization() { + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("Organization{"); + sb.append("uuid='").append(uuid).append('\''); + sb.append(", id='").append(id).append('\''); + sb.append(", name='").append(name).append('\''); + sb.append(", domain='").append(domain).append('\''); + sb.append(", owner='").append(owner).append('\''); + sb.append(", admins=").append(admins); + sb.append(", creationDate='").append(creationDate).append('\''); + sb.append(", modificationDate='").append(modificationDate).append('\''); + sb.append(", projects=").append(projects); + sb.append(", authenticationOrigins=").append(authenticationOrigins); + sb.append(", attributes=").append(attributes); + sb.append('}'); + return sb.toString(); + } + + public String getUuid() { + return uuid; + } + + public Organization setUuid(String uuid) { + this.uuid = uuid; + return this; + } + + public String getId() { + return id; + } + + public Organization setId(String id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public Organization setName(String name) { + this.name = name; + return this; + } + + public String getDomain() { + return domain; + } + + public Organization setDomain(String domain) { + this.domain = domain; + return this; + } + + public String getOwner() { + return owner; + } + + public Organization setOwner(String owner) { + this.owner = owner; + return this; + } + + public List getAdmins() { + return admins; + } + + public Organization setAdmins(List admins) { + this.admins = admins; + return this; + } + + public String getCreationDate() { + return creationDate; + } + + public Organization setCreationDate(String creationDate) { + this.creationDate = creationDate; + return this; + } + + public String getModificationDate() { + return modificationDate; + } + + public Organization setModificationDate(String modificationDate) { + this.modificationDate = modificationDate; + return this; + } + + public List getProjects() { + return projects; + } + + public Organization setProjects(List projects) { + this.projects = projects; + return this; + } + + public List getAuthenticationOrigins() { + return authenticationOrigins; + } + + public Organization setAuthenticationOrigins(List authenticationOrigins) { + this.authenticationOrigins = authenticationOrigins; + return this; + } + + public Map getAttributes() { + return attributes; + } + + public Organization setAttributes(Map attributes) { + this.attributes = attributes; + return this; + } +}