-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
103 additions
and
32 deletions.
There are no files selected for viewing
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
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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/org/cbioportal/service/impl/vs/VirtualStudyService.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,63 @@ | ||
package org.cbioportal.service.impl.vs; | ||
|
||
import org.cbioportal.model.CancerStudy; | ||
import org.cbioportal.service.CancerTypeService; | ||
import org.cbioportal.service.exception.CancerTypeNotFoundException; | ||
import org.cbioportal.service.util.SessionServiceRequestHandler; | ||
import org.cbioportal.web.parameter.VirtualStudy; | ||
import org.cbioportal.web.parameter.VirtualStudyData; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class VirtualStudyService { | ||
|
||
private final CancerTypeService cancerTypeService; | ||
private final SessionServiceRequestHandler sessionServiceRequestHandler; | ||
|
||
public VirtualStudyService(SessionServiceRequestHandler sessionServiceRequestHandler, CancerTypeService cancerTypeService) { | ||
this.sessionServiceRequestHandler = sessionServiceRequestHandler; | ||
this.cancerTypeService = cancerTypeService; | ||
} | ||
|
||
public List<CancerStudy> findVirtualStudies(String keyword) { | ||
return sessionServiceRequestHandler.getVirtualStudiesAccessibleToUser("*").stream() | ||
.map(this::toCancerStudy).filter(cs -> shouldSelect(cs, keyword)).toList(); | ||
} | ||
|
||
public Optional<CancerStudy> findVirtualStudy(String id) { | ||
return Optional.ofNullable(sessionServiceRequestHandler.getVirtualStudyById(id)).map(this::toCancerStudy); | ||
} | ||
|
||
private CancerStudy toCancerStudy(VirtualStudy vs) { | ||
VirtualStudyData vsd = vs.getData(); | ||
CancerStudy cs = new CancerStudy(); | ||
cs.setCancerStudyIdentifier(vs.getId()); | ||
cs.setName(vsd.getName()); | ||
//TODO fetch mixed cancer type in the constructor once. To fail initialization if the type is not found | ||
String typeOfCancerId = vsd.getTypeOfCancerId() == null ? "mixed" : vsd.getTypeOfCancerId(); | ||
try { | ||
cs.setTypeOfCancer(cancerTypeService.getCancerType(typeOfCancerId)); | ||
cs.setTypeOfCancerId(typeOfCancerId); | ||
} catch (CancerTypeNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
cs.setDescription(vsd.getDescription()); | ||
cs.setPmid(vsd.getPmid()); | ||
//TODO run filters on the dynamic virtual study | ||
cs.setAllSampleCount(vsd.getStudies().stream().map(s -> s.getSamples().size()).reduce(0, Integer::sum)); | ||
//TODO we can implement this field for published virtual studies to predefine rights on groups even before the study is created | ||
cs.setGroups("PUBLIC"); | ||
return cs; | ||
} | ||
|
||
private static boolean shouldSelect(CancerStudy cs, String keyword) { | ||
//TODO improve the search. The keyword can be also sent to mongo to search for virtual studies | ||
if (keyword == null) { | ||
return true; | ||
} | ||
return cs.getName().toLowerCase().contains(keyword.toLowerCase()); | ||
} | ||
} |
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
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