Skip to content

Commit 627220b

Browse files
committed
More fixes
1 parent 31c3842 commit 627220b

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/main/java/org/cbioportal/service/impl/vs/VSAwareServicesConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cbioportal.service.impl.vs;
22

3+
import org.cbioportal.service.CancerTypeService;
34
import org.cbioportal.service.ReadPermissionService;
45
import org.cbioportal.service.StudyService;
56
import org.cbioportal.service.util.SessionServiceRequestHandler;
@@ -36,7 +37,7 @@ public Executor asyncExecutor() {
3637

3738
@Primary
3839
@Bean
39-
public StudyService studyService(StudyService studyService, Executor asyncExecutor) {
40-
return new VSAwareStudyServiceImpl(studyService, sessionServiceRequestHandler, readPermissionService, asyncExecutor);
40+
public StudyService studyService(StudyService studyService, CancerTypeService cancerTypeService, Executor asyncExecutor) {
41+
return new VSAwareStudyServiceImpl(studyService, sessionServiceRequestHandler, readPermissionService, cancerTypeService, asyncExecutor);
4142
}
4243
}

src/main/java/org/cbioportal/service/impl/vs/VSAwareStudyServiceImpl.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import org.cbioportal.model.CancerStudy;
44
import org.cbioportal.model.CancerStudyTags;
55
import org.cbioportal.model.meta.BaseMeta;
6+
import org.cbioportal.service.CancerTypeService;
67
import org.cbioportal.service.ReadPermissionService;
78
import org.cbioportal.service.StudyService;
9+
import org.cbioportal.service.exception.CancerTypeNotFoundException;
810
import org.cbioportal.service.exception.StudyNotFoundException;
911
import org.cbioportal.service.util.SessionServiceRequestHandler;
1012
import org.cbioportal.utils.security.AccessLevel;
@@ -29,11 +31,13 @@ public class VSAwareStudyServiceImpl implements StudyService {
2931

3032
private final ReadPermissionService readPermissionService;
3133
private final Executor asyncExecutor;
34+
private final CancerTypeService cancerTypeService;
3235

33-
public VSAwareStudyServiceImpl(StudyService studyService, SessionServiceRequestHandler sessionServiceRequestHandler, ReadPermissionService readPermissionService, Executor asyncExecutor) {
36+
public VSAwareStudyServiceImpl(StudyService studyService, SessionServiceRequestHandler sessionServiceRequestHandler, ReadPermissionService readPermissionService, CancerTypeService cancerTypeService, Executor asyncExecutor) {
3437
this.studyService = studyService;
3538
this.sessionServiceRequestHandler = sessionServiceRequestHandler;
3639
this.readPermissionService = readPermissionService;
40+
this.cancerTypeService = cancerTypeService;
3741
this.asyncExecutor = asyncExecutor;
3842
}
3943

@@ -59,25 +63,34 @@ public List<CancerStudy> getAllStudies(String keyword, String projection, Intege
5963
readPermissionService.setReadPermission(result, authentication);
6064
return result;
6165
}
62-
66+
//TODO these should not fail the whole request if one of them fails
6367
@Async
6468
private CompletableFuture<List<CancerStudy>> getVirtualStudiesAsync(String keyword) {
6569
return CompletableFuture.supplyAsync(() -> sessionServiceRequestHandler.getVirtualStudiesAccessibleToUser("*").stream()
66-
.map(VSAwareStudyServiceImpl::toCancerStudy).filter(cs -> shouldSelect(cs, keyword)).toList(), asyncExecutor);
70+
.map(this::toCancerStudy).filter(cs -> shouldSelect(cs, keyword)).toList(), asyncExecutor);
6771
}
6872

6973
@Async
7074
private CompletableFuture<List<CancerStudy>> getMaterialisedStudiesAsync(String keyword, String projection, Authentication authentication, AccessLevel accessLevel) {
7175
return CompletableFuture.supplyAsync(() -> studyService.getAllStudies(keyword, projection, null, null, null, null, authentication, accessLevel), asyncExecutor);
7276
}
7377

74-
private static CancerStudy toCancerStudy(VirtualStudy vs) {
78+
private CancerStudy toCancerStudy(VirtualStudy vs) {
7579
VirtualStudyData vsd = vs.getData();
7680
CancerStudy cs = new CancerStudy();
7781
cs.setCancerStudyIdentifier(vs.getId());
7882
cs.setName(vsd.getName());
83+
String typeOfCancerId = vsd.getTypeOfCancerId() == null ? "mixed" : vsd.getTypeOfCancerId();
84+
try {
85+
cs.setTypeOfCancer(cancerTypeService.getCancerType(typeOfCancerId));
86+
cs.setTypeOfCancerId(typeOfCancerId);
87+
} catch (CancerTypeNotFoundException e) {
88+
throw new RuntimeException(e);
89+
}
7990
cs.setDescription(vsd.getDescription());
8091
cs.setPmid(vsd.getPmid());
92+
//TODO we can implement this field for published virtual studies to predefine rights on groups even before the study is created
93+
cs.setGroups("PUBLIC");
8194
return cs;
8295
}
8396

@@ -100,6 +113,9 @@ private static Comparator<CancerStudy> buildComparator(String sortBy, String dir
100113

101114
private static boolean shouldSelect(CancerStudy cs, String keyword) {
102115
//TODO improve the search. The keyword can be also sent to mongo to search for virtual studies
116+
if (keyword == null) {
117+
return true;
118+
}
103119
return cs.getName().toLowerCase().contains(keyword.toLowerCase());
104120
}
105121

@@ -119,7 +135,7 @@ public CancerStudy getStudy(String studyId) throws StudyNotFoundException {
119135

120136
@Async
121137
private CompletableFuture<Optional<CancerStudy>> getVirtualStudyAsync(String studyId) {
122-
return CompletableFuture.supplyAsync(() -> Optional.ofNullable(sessionServiceRequestHandler.getVirtualStudyById(studyId)).map(VSAwareStudyServiceImpl::toCancerStudy), asyncExecutor);
138+
return CompletableFuture.supplyAsync(() -> Optional.ofNullable(sessionServiceRequestHandler.getVirtualStudyById(studyId)).map(this::toCancerStudy), asyncExecutor);
123139
}
124140

125141
@Async
@@ -154,7 +170,7 @@ public List<CancerStudy> fetchStudies(List<String> studyIds, String projection)
154170
List<CancerStudy> materialisedStudies = studyService.fetchStudies(studyIds, projection);
155171
List<String> notFoundStudyIds = materialisedStudies.stream().map(CancerStudy::getCancerStudyIdentifier).filter(studyId -> !studyIds.contains(studyId)).toList();
156172
//TODO implement using completable futures. It must be better for IO bound operations
157-
List<CancerStudy> virtualStudies = notFoundStudyIds.parallelStream().map(sessionServiceRequestHandler::getVirtualStudyById).map(VSAwareStudyServiceImpl::toCancerStudy).toList();
173+
List<CancerStudy> virtualStudies = notFoundStudyIds.parallelStream().map(sessionServiceRequestHandler::getVirtualStudyById).map(this::toCancerStudy).toList();
158174
return Stream.concat(materialisedStudies.stream(), virtualStudies.stream()).toList();
159175
}
160176

src/test/resources/seed_mini.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ INSERT INTO "type_of_cancer" ("TYPE_OF_CANCER_ID","NAME","DEDICATED_COLOR","SHOR
8181
INSERT INTO "type_of_cancer" ("TYPE_OF_CANCER_ID","NAME","DEDICATED_COLOR","SHORT_NAME","PARENT") VALUES ('blca','Bladder Urothelial Carcinoma','Yellow','Bladder','tissue');
8282
INSERT INTO "type_of_cancer" ("TYPE_OF_CANCER_ID","NAME","DEDICATED_COLOR","SHORT_NAME","PARENT") VALUES ('bpdcn','Blastic Plasmacytoid Dendritic Cell Neoplasm','LightSalmon','BPDCN','tissue');
8383
INSERT INTO "type_of_cancer" ("TYPE_OF_CANCER_ID","NAME","DEDICATED_COLOR","SHORT_NAME","PARENT") VALUES ('brca','Breast Invasive Carcinoma','HotPink','Breast','tissue');
84+
INSERT INTO "type_of_cancer" ("TYPE_OF_CANCER_ID","NAME","DEDICATED_COLOR","SHORT_NAME","PARENT") VALUES ('mixed','Mixed Cancer Types',null,'Mixed',null);
8485

8586
-- reference_genome
8687
INSERT INTO `reference_genome` VALUES (1,'human','hg19','GRCh37',2897310462,'http://hgdownload.cse.ucsc.edu/goldenPath/hg19/bigZips','2009-02-01');

0 commit comments

Comments
 (0)