3
3
import org .cbioportal .model .CancerStudy ;
4
4
import org .cbioportal .model .CancerStudyTags ;
5
5
import org .cbioportal .model .meta .BaseMeta ;
6
+ import org .cbioportal .service .CancerTypeService ;
6
7
import org .cbioportal .service .ReadPermissionService ;
7
8
import org .cbioportal .service .StudyService ;
9
+ import org .cbioportal .service .exception .CancerTypeNotFoundException ;
8
10
import org .cbioportal .service .exception .StudyNotFoundException ;
9
11
import org .cbioportal .service .util .SessionServiceRequestHandler ;
10
12
import org .cbioportal .utils .security .AccessLevel ;
@@ -29,11 +31,13 @@ public class VSAwareStudyServiceImpl implements StudyService {
29
31
30
32
private final ReadPermissionService readPermissionService ;
31
33
private final Executor asyncExecutor ;
34
+ private final CancerTypeService cancerTypeService ;
32
35
33
- public VSAwareStudyServiceImpl (StudyService studyService , SessionServiceRequestHandler sessionServiceRequestHandler , ReadPermissionService readPermissionService , Executor asyncExecutor ) {
36
+ public VSAwareStudyServiceImpl (StudyService studyService , SessionServiceRequestHandler sessionServiceRequestHandler , ReadPermissionService readPermissionService , CancerTypeService cancerTypeService , Executor asyncExecutor ) {
34
37
this .studyService = studyService ;
35
38
this .sessionServiceRequestHandler = sessionServiceRequestHandler ;
36
39
this .readPermissionService = readPermissionService ;
40
+ this .cancerTypeService = cancerTypeService ;
37
41
this .asyncExecutor = asyncExecutor ;
38
42
}
39
43
@@ -59,25 +63,34 @@ public List<CancerStudy> getAllStudies(String keyword, String projection, Intege
59
63
readPermissionService .setReadPermission (result , authentication );
60
64
return result ;
61
65
}
62
-
66
+ //TODO these should not fail the whole request if one of them fails
63
67
@ Async
64
68
private CompletableFuture <List <CancerStudy >> getVirtualStudiesAsync (String keyword ) {
65
69
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 );
67
71
}
68
72
69
73
@ Async
70
74
private CompletableFuture <List <CancerStudy >> getMaterialisedStudiesAsync (String keyword , String projection , Authentication authentication , AccessLevel accessLevel ) {
71
75
return CompletableFuture .supplyAsync (() -> studyService .getAllStudies (keyword , projection , null , null , null , null , authentication , accessLevel ), asyncExecutor );
72
76
}
73
77
74
- private static CancerStudy toCancerStudy (VirtualStudy vs ) {
78
+ private CancerStudy toCancerStudy (VirtualStudy vs ) {
75
79
VirtualStudyData vsd = vs .getData ();
76
80
CancerStudy cs = new CancerStudy ();
77
81
cs .setCancerStudyIdentifier (vs .getId ());
78
82
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
+ }
79
90
cs .setDescription (vsd .getDescription ());
80
91
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" );
81
94
return cs ;
82
95
}
83
96
@@ -100,6 +113,9 @@ private static Comparator<CancerStudy> buildComparator(String sortBy, String dir
100
113
101
114
private static boolean shouldSelect (CancerStudy cs , String keyword ) {
102
115
//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
+ }
103
119
return cs .getName ().toLowerCase ().contains (keyword .toLowerCase ());
104
120
}
105
121
@@ -119,7 +135,7 @@ public CancerStudy getStudy(String studyId) throws StudyNotFoundException {
119
135
120
136
@ Async
121
137
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 );
123
139
}
124
140
125
141
@ Async
@@ -154,7 +170,7 @@ public List<CancerStudy> fetchStudies(List<String> studyIds, String projection)
154
170
List <CancerStudy > materialisedStudies = studyService .fetchStudies (studyIds , projection );
155
171
List <String > notFoundStudyIds = materialisedStudies .stream ().map (CancerStudy ::getCancerStudyIdentifier ).filter (studyId -> !studyIds .contains (studyId )).toList ();
156
172
//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 ();
158
174
return Stream .concat (materialisedStudies .stream (), virtualStudies .stream ()).toList ();
159
175
}
160
176
0 commit comments