Skip to content

Commit

Permalink
Merge branch 'develop' into TASK-6442
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio authored Dec 10, 2024
2 parents 70ee362 + 7355bde commit 0eb2ad3
Show file tree
Hide file tree
Showing 27 changed files with 170 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.opencb.opencga.core.config.Optimizations;
import org.opencb.opencga.core.models.notes.Note;
import org.opencb.opencga.core.models.notes.NoteCreateParams;
import org.opencb.opencga.core.models.notes.NoteType;
import org.opencb.opencga.core.models.notes.NoteUpdateParams;
import org.opencb.opencga.core.models.organizations.Organization;
import org.opencb.opencga.core.models.organizations.OrganizationConfiguration;
Expand Down Expand Up @@ -164,6 +165,7 @@ private RestResponse<Note> createNotes() throws Exception {
} else {
ObjectMap beanParams = new ObjectMap();
putNestedIfNotEmpty(beanParams, "id", commandOptions.id, true);
putNestedIfNotNull(beanParams, "type", commandOptions.type, true);
putNestedIfNotNull(beanParams, "tags", commandOptions.tags, true);
putNestedIfNotNull(beanParams, "visibility", commandOptions.visibility, true);
putNestedIfNotNull(beanParams, "valueType", commandOptions.valueType, true);
Expand All @@ -186,6 +188,7 @@ private RestResponse<Note> searchNotes() throws Exception {
queryParams.putIfNotEmpty("creationDate", commandOptions.creationDate);
queryParams.putIfNotEmpty("modificationDate", commandOptions.modificationDate);
queryParams.putIfNotEmpty("id", commandOptions.id);
queryParams.putIfNotEmpty("type", commandOptions.type);
queryParams.putIfNotEmpty("scope", commandOptions.scope);
queryParams.putIfNotEmpty("visibility", commandOptions.visibility);
queryParams.putIfNotEmpty("uuid", commandOptions.uuid);
Expand Down Expand Up @@ -230,6 +233,7 @@ private RestResponse<Note> updateNotes() throws Exception {
.readValue(new java.io.File(commandOptions.jsonFile), NoteUpdateParams.class);
} else {
ObjectMap beanParams = new ObjectMap();
putNestedIfNotNull(beanParams, "type", commandOptions.type, true);
putNestedIfNotNull(beanParams, "tags", commandOptions.tags, true);
putNestedIfNotNull(beanParams, "visibility", commandOptions.visibility, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.opencb.opencga.core.models.job.Job;
import org.opencb.opencga.core.models.notes.Note;
import org.opencb.opencga.core.models.notes.NoteCreateParams;
import org.opencb.opencga.core.models.notes.NoteType;
import org.opencb.opencga.core.models.notes.NoteUpdateParams;
import org.opencb.opencga.core.models.study.CustomGroup;
import org.opencb.opencga.core.models.study.Group;
Expand Down Expand Up @@ -398,6 +399,7 @@ private RestResponse<Note> createNotes() throws Exception {
} else {
ObjectMap beanParams = new ObjectMap();
putNestedIfNotEmpty(beanParams, "id", commandOptions.id, true);
putNestedIfNotNull(beanParams, "type", commandOptions.type, true);
putNestedIfNotNull(beanParams, "tags", commandOptions.tags, true);
putNestedIfNotNull(beanParams, "visibility", commandOptions.visibility, true);
putNestedIfNotNull(beanParams, "valueType", commandOptions.valueType, true);
Expand All @@ -420,6 +422,7 @@ private RestResponse<Note> searchNotes() throws Exception {
queryParams.putIfNotEmpty("creationDate", commandOptions.creationDate);
queryParams.putIfNotEmpty("modificationDate", commandOptions.modificationDate);
queryParams.putIfNotEmpty("id", commandOptions.id);
queryParams.putIfNotEmpty("type", commandOptions.type);
queryParams.putIfNotEmpty("uuid", commandOptions.uuid);
queryParams.putIfNotEmpty("userId", commandOptions.userId);
queryParams.putIfNotEmpty("tags", commandOptions.tags);
Expand Down Expand Up @@ -463,6 +466,7 @@ private RestResponse<Note> updateNotes() throws Exception {
.readValue(new java.io.File(commandOptions.jsonFile), NoteUpdateParams.class);
} else {
ObjectMap beanParams = new ObjectMap();
putNestedIfNotNull(beanParams, "type", commandOptions.type, true);
putNestedIfNotNull(beanParams, "tags", commandOptions.tags, true);
putNestedIfNotNull(beanParams, "visibility", commandOptions.visibility, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public class CreateNotesCommandOptions {
@Parameter(names = {"--id"}, description = "The body web service id parameter", required = false, arity = 1)
public String id;

@Parameter(names = {"--type"}, description = "Enum param allowed values: VARIANT, GENE, TRANSCRIPT, PROTEIN, JOB, FILE, SAMPLE, INDIVIDUAL, FAMILY, COHORT, DISEASE_PANEL, CLINICAL_ANALYSIS, WORKFLOW, ORGANIZATION, OTHER, UNKNOWN", required = false, arity = 1)
public String type;

@Parameter(names = {"--tags"}, description = "The body web service tags parameter", required = false, arity = 1)
public String tags;

Expand Down Expand Up @@ -159,6 +162,9 @@ public class SearchNotesCommandOptions {
@Parameter(names = {"--id"}, description = "Note unique identifier.", required = false, arity = 1)
public String id;

@Parameter(names = {"--type"}, description = "Note type.", required = false, arity = 1)
public String type;

@Parameter(names = {"--scope"}, description = "Scope of the Note.", required = false, arity = 1)
public String scope;

Expand Down Expand Up @@ -220,6 +226,9 @@ public class UpdateNotesCommandOptions {
@Parameter(names = {"--include-result"}, description = "Flag indicating to include the created or updated document result in the response", required = false, help = true, arity = 0)
public boolean includeResult = false;

@Parameter(names = {"--type"}, description = "Enum param allowed values: VARIANT, GENE, TRANSCRIPT, PROTEIN, JOB, FILE, SAMPLE, INDIVIDUAL, FAMILY, COHORT, DISEASE_PANEL, CLINICAL_ANALYSIS, WORKFLOW, ORGANIZATION, OTHER, UNKNOWN", required = false, arity = 1)
public String type;

@Parameter(names = {"--tags"}, description = "The body web service tags parameter", required = false, arity = 1)
public String tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ public class CreateNotesCommandOptions {
@Parameter(names = {"--id"}, description = "The body web service id parameter", required = false, arity = 1)
public String id;

@Parameter(names = {"--type"}, description = "Enum param allowed values: VARIANT, GENE, TRANSCRIPT, PROTEIN, JOB, FILE, SAMPLE, INDIVIDUAL, FAMILY, COHORT, DISEASE_PANEL, CLINICAL_ANALYSIS, WORKFLOW, ORGANIZATION, OTHER, UNKNOWN", required = false, arity = 1)
public String type;

@Parameter(names = {"--tags"}, description = "The body web service tags parameter", required = false, arity = 1)
public String tags;

Expand Down Expand Up @@ -447,6 +450,9 @@ public class SearchNotesCommandOptions {
@Parameter(names = {"--id"}, description = "Note unique identifier.", required = false, arity = 1)
public String id;

@Parameter(names = {"--type"}, description = "Note type.", required = false, arity = 1)
public String type;

@Parameter(names = {"--uuid"}, description = "Unique 32-character identifier assigned automatically by OpenCGA.", required = false, arity = 1)
public String uuid;

Expand Down Expand Up @@ -511,6 +517,9 @@ public class UpdateNotesCommandOptions {
@Parameter(names = {"--include-result"}, description = "Flag indicating to include the created or updated document result in the response", required = false, help = true, arity = 0)
public boolean includeResult = false;

@Parameter(names = {"--type"}, description = "Enum param allowed values: VARIANT, GENE, TRANSCRIPT, PROTEIN, JOB, FILE, SAMPLE, INDIVIDUAL, FAMILY, COHORT, DISEASE_PANEL, CLINICAL_ANALYSIS, WORKFLOW, ORGANIZATION, OTHER, UNKNOWN", required = false, arity = 1)
public String type;

@Parameter(names = {"--tags"}, description = "The body web service tags parameter", required = false, arity = 1)
public String tags;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.opencb.opencga.app.migrations.v4.v4_0_0.catalog;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.opencb.opencga.catalog.db.mongodb.OrganizationMongoDBAdaptorFactory;
import org.opencb.opencga.catalog.migration.Migration;
import org.opencb.opencga.catalog.migration.MigrationTool;
import org.opencb.opencga.core.api.ParamConstants;
import org.opencb.opencga.core.models.notes.NoteType;

import java.util.Arrays;

@Migration(id = "addNewNoteType__task_7046",
description = "Add new Note type #7046", version = "4.0.0",
language = Migration.MigrationLanguage.JAVA, domain = Migration.MigrationDomain.CATALOG, date = 20241030)
public class AddNewNoteTypeMigration extends MigrationTool {

@Override
protected void run() throws Exception {
NoteType type = NoteType.UNKNOWN;
if (ParamConstants.ADMIN_ORGANIZATION.equals(organizationId)) {
type = NoteType.ORGANIZATION;
}
MongoCollection<Document> collection = getMongoCollection(OrganizationMongoDBAdaptorFactory.NOTE_COLLECTION);
Bson query = Filters.exists("type", false);
Bson update = Updates.set("type", type);
logger.info("Setting all notes from organization '{}' to type '{}'", organizationId, type);
collection.updateMany(query, update);

// Drop old index
Document oldIndex = new Document()
.append("id", 1)
.append("studyUid", 1)
.append("version", 1);
dropIndex(Arrays.asList(OrganizationMongoDBAdaptorFactory.NOTE_COLLECTION, OrganizationMongoDBAdaptorFactory.NOTE_ARCHIVE_COLLECTION),
oldIndex);
// Generate new indexes
catalogManager.installIndexes(organizationId, token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum QueryParams implements QueryParam {
UUID("uuid", STRING, ""),
SCOPE("scope", STRING, ""),
STUDY("study", STRING, ""),
TYPE("type", STRING, ""),
TAGS("tags", TEXT_ARRAY, ""),
USER_ID("userId", STRING, ""),
VISIBILITY("visibility", STRING, ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opencb.opencga.core.config.Configuration;
import org.opencb.opencga.core.models.notes.Note;
import org.opencb.opencga.core.models.notes.NoteCreateParams;
import org.opencb.opencga.core.models.notes.NoteType;
import org.opencb.opencga.core.models.organizations.Organization;
import org.opencb.opencga.core.models.organizations.OrganizationSummary;
import org.opencb.opencga.core.response.OpenCGAResult;
Expand Down Expand Up @@ -278,7 +279,7 @@ public OpenCGAResult<Organization> createOrganization(Organization organization,

OrganizationSummary organizationSummary = new OrganizationSummary(organization.getId(),
organizationDBAdaptorFactory.getMongoDataStore().getDatabaseName(), OrganizationTag.ACTIVE.name(), null);
NoteCreateParams noteCreateParams = new NoteCreateParams(ORGANIZATION_PREFIX + organization.getId(),
NoteCreateParams noteCreateParams = new NoteCreateParams(ORGANIZATION_PREFIX + organization.getId(), NoteType.ORGANIZATION,
Collections.singletonList(OrganizationTag.ACTIVE.name()), Note.Visibility.PRIVATE, Note.Type.OBJECT, null);
try {
String orgSummaryString = JacksonUtils.getDefaultObjectMapper().writeValueAsString(organizationSummary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private UpdateDocument parseAndValidateUpdateParams(Document note, ObjectMap par
// document.getSet().put(PRIVATE_MODIFICATION_DATE, date);
// }

final String[] acceptedStringParams = {QueryParams.USER_ID.key(), QueryParams.VISIBILITY.key()};
final String[] acceptedStringParams = {QueryParams.USER_ID.key(), QueryParams.VISIBILITY.key(), QueryParams.TYPE.key()};
filterStringParams(parameters, document.getSet(), acceptedStringParams);

Object value = parameters.get(QueryParams.VALUE.key());
Expand Down Expand Up @@ -399,6 +399,7 @@ private Bson parseQuery(Query query) throws CatalogDBException {
break;
case ID:
case UUID:
case TYPE:
case SCOPE:
case USER_ID:
case TAGS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opencb.opencga.core.models.common.Enums;
import org.opencb.opencga.core.models.notes.Note;
import org.opencb.opencga.core.models.notes.NoteCreateParams;
import org.opencb.opencga.core.models.notes.NoteType;
import org.opencb.opencga.core.models.notes.NoteUpdateParams;
import org.opencb.opencga.core.models.study.Study;
import org.opencb.opencga.core.response.OpenCGAResult;
Expand Down Expand Up @@ -396,6 +397,7 @@ public static void validateNewNote(Note note, String userId) throws CatalogParam
ParamUtils.checkObj(note.getValueType(), NoteDBAdaptor.QueryParams.VALUE_TYPE.key());
ParamUtils.checkObj(note.getValue(), NoteDBAdaptor.QueryParams.VALUE.key());

note.setType(ParamUtils.defaultObject(note.getType(), NoteType.UNKNOWN));
note.setTags(CollectionUtils.isNotEmpty(note.getTags()) ? note.getTags() : Collections.emptyList());
note.setUserId(userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ public void runMigration(String organizationId, String version, Collection<Migra
for (Class<? extends MigrationTool> migration : runnableMigrations) {
run(organizationId, migration, appHomePath, params, token);
}

// 5. Execute install indexes just in case there are new indexes
catalogManager.installIndexes(organizationId, token);
}

public List<Class<? extends MigrationTool>> getPendingMigrations(String organizationId, String version, String token)
Expand Down
3 changes: 2 additions & 1 deletion opencga-catalog/src/main/resources/catalog-indexes.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{"collections": ["note", "note_archive"], "fields": {"id": 1, "studyUid": 1, "version": 1}, "options": {"unique": true}}
{"collections": ["note", "note_archive"], "fields": {"id": 1, "studyUid": 1, "type": 1, "version": 1}, "options": {"unique": true}}
{"collections": ["note", "note_archive"], "fields": {"uid": 1, "version": 1}, "options": {"unique": true}}
{"collections": ["note", "note_archive"], "fields": {"uuid": 1, "version": 1}, "options": {"unique": true}}
{"collections": ["note", "note_archive"], "fields": {"scope": 1, "studyUid": 1}, "options": {}}
{"collections": ["note", "note_archive"], "fields": {"type": 1, "studyUid": 1}, "options": {}}
{"collections": ["note", "note_archive"], "fields": {"studyUid": 1}, "options": {}}
{"collections": ["note", "note_archive"], "fields": {"visibility": 1, "studyUid": 1}, "options": {}}
{"collections": ["note", "note_archive"], "fields": {"userId": 1, "studyUid": 1}, "options": {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.opencb.opencga.core.api.ParamConstants;
import org.opencb.opencga.core.models.notes.Note;
import org.opencb.opencga.core.models.notes.NoteCreateParams;
import org.opencb.opencga.core.models.notes.NoteType;
import org.opencb.opencga.core.models.notes.NoteUpdateParams;
import org.opencb.opencga.core.models.organizations.Organization;
import org.opencb.opencga.core.models.study.Study;
Expand All @@ -37,11 +38,14 @@ public void createOrganizationNoteTest() throws CatalogException {
Note note = catalogManager.getNotesManager().createOrganizationNote(noteCreateParams, INCLUDE_RESULT, ownerToken).first();
assertEquals(noteCreateParams.getId(), note.getId());
assertEquals(orgOwnerUserId, note.getUserId());
assertEquals(NoteType.UNKNOWN, note.getType());

noteCreateParams.setId("note2");
noteCreateParams.setType(NoteType.FAMILY);
note = catalogManager.getNotesManager().createOrganizationNote(noteCreateParams, INCLUDE_RESULT, orgAdminToken1).first();
assertEquals(noteCreateParams.getId(), note.getId());
assertEquals(orgAdminUserId1, note.getUserId());
assertEquals(NoteType.FAMILY, note.getType());

thrown.expect(CatalogAuthorizationException.class);
thrown.expectMessage("denied");
Expand All @@ -59,10 +63,12 @@ public void updateOrganizationNoteTest() throws CatalogException {
assertEquals(1, note.getVersion());

NoteUpdateParams noteUpdateParams = new NoteUpdateParams()
.setTags(Arrays.asList("tag1", "tag2"));
.setTags(Arrays.asList("tag1", "tag2"))
.setType(NoteType.GENE);
note = catalogManager.getNotesManager().updateOrganizationNote(note.getId(), noteUpdateParams, INCLUDE_RESULT, ownerToken).first();
assertEquals(2, note.getVersion());
assertEquals(orgOwnerUserId, note.getUserId());
assertEquals(NoteType.GENE, note.getType());
assertEquals(2, note.getTags().size());
assertArrayEquals(noteUpdateParams.getTags().toArray(), note.getTags().toArray());

Expand Down
3 changes: 2 additions & 1 deletion opencga-client/src/main/R/R/Organization-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' | -- | :-- | --: |
#' | create | /{apiVersion}/organizations/create | include, exclude, includeResult, body[*] |
#' | createNotes | /{apiVersion}/organizations/notes/create | include, exclude, includeResult, body[*] |
#' | searchNotes | /{apiVersion}/organizations/notes/search | include, exclude, creationDate, modificationDate, id, scope, visibility, uuid, userId, tags, version |
#' | searchNotes | /{apiVersion}/organizations/notes/search | include, exclude, creationDate, modificationDate, id, type, scope, visibility, uuid, userId, tags, version |
#' | deleteNotes | /{apiVersion}/organizations/notes/{id}/delete | id[*], includeResult |
#' | updateNotes | /{apiVersion}/organizations/notes/{id}/update | include, exclude, id[*], tagsAction, includeResult, body[*] |
#' | userUpdateStatus | /{apiVersion}/organizations/user/{user}/status/update | include, exclude, user[*], organization, includeResult, body[*] |
Expand Down Expand Up @@ -64,6 +64,7 @@ setMethod("organizationClient", "OpencgaR", function(OpencgaR, id, organization,
#' @param creationDate Creation date. Format: yyyyMMddHHmmss. Examples: >2018, 2017-2018, <201805.
#' @param modificationDate Modification date. Format: yyyyMMddHHmmss. Examples: >2018, 2017-2018, <201805.
#' @param id Note unique identifier.
#' @param type Note type.
#' @param scope Scope of the Note.
#' @param visibility Visibility of the Note.
#' @param uuid Unique 32-character identifier assigned automatically by OpenCGA.
Expand Down
3 changes: 2 additions & 1 deletion opencga-client/src/main/R/R/Study-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' | updateGroups | /{apiVersion}/studies/{study}/groups/update | study[*], action, body[*] |
#' | updateGroupsUsers | /{apiVersion}/studies/{study}/groups/{group}/users/update | study[*], group[*], action, body[*] |
#' | createNotes | /{apiVersion}/studies/{study}/notes/create | include, exclude, study[*], includeResult, body[*] |
#' | searchNotes | /{apiVersion}/studies/{study}/notes/search | include, exclude, study[*], creationDate, modificationDate, id, uuid, userId, tags, visibility, version |
#' | searchNotes | /{apiVersion}/studies/{study}/notes/search | include, exclude, study[*], creationDate, modificationDate, id, type, uuid, userId, tags, visibility, version |
#' | deleteNotes | /{apiVersion}/studies/{study}/notes/{id}/delete | study[*], id[*], includeResult |
#' | updateNotes | /{apiVersion}/studies/{study}/notes/{id}/update | include, exclude, study[*], id[*], tagsAction, includeResult, body[*] |
#' | permissionRules | /{apiVersion}/studies/{study}/permissionRules | study[*], entity[*] |
Expand Down Expand Up @@ -169,6 +169,7 @@ setMethod("studyClient", "OpencgaR", function(OpencgaR, group, id, members, stud
#' @param creationDate Creation date. Format: yyyyMMddHHmmss. Examples: >2018, 2017-2018, <201805.
#' @param modificationDate Modification date. Format: yyyyMMddHHmmss. Examples: >2018, 2017-2018, <201805.
#' @param id Note unique identifier.
#' @param type Note type.
#' @param uuid Unique 32-character identifier assigned automatically by OpenCGA.
#' @param userId User that wrote that Note.
#' @param tags Note tags.
Expand Down
Loading

0 comments on commit 0eb2ad3

Please sign in to comment.