def create_study(self, study_name: str, group_ids: List[str], params: RequestParameters) -> str: sid = str(uuid4()) study_path = str(self.study_service.get_default_workspace_path() / sid) raw = RawStudy( id=sid, name=study_name, workspace=DEFAULT_WORKSPACE_NAME, path=study_path, ) raw = self.study_service.create_study(raw) self._save_study(raw, params.user, group_ids) self.event_bus.push( Event(EventType.STUDY_CREATED, raw.to_json_summary())) return str(raw.id)
def import_study( self, stream: IO[bytes], group_ids: List[str], params: RequestParameters, ) -> str: sid = str(uuid4()) path = str(self.study_service.get_default_workspace_path() / sid) study = RawStudy(id=sid, workspace=DEFAULT_WORKSPACE_NAME, path=path) study = self.importer_service.import_study(study, stream) status = self._analyse_study(study) self._save_study( study, owner=params.user, group_ids=group_ids, content_status=status, ) self.event_bus.push( Event(EventType.STUDY_CREATED, study.to_json_summary())) return str(study.id)
def sync_studies_on_disk(self, folders: List[StudyFolder]) -> None: # delete orphan studies on database paths = [str(f.path) for f in folders] for study in self.repository.get_all(): if isinstance( study, RawStudy) and (study.workspace != DEFAULT_WORKSPACE_NAME and study.path not in paths): logger.info( f"Study={study.id} is not present in disk and will be deleted" ) self.event_bus.push( Event(EventType.STUDY_DELETED, study.to_json_summary())) self.repository.delete(study.id) # Add new studies paths = [ study.path for study in self.repository.get_all() if isinstance(study, RawStudy) ] for folder in folders: if str(folder.path) not in paths: study = RawStudy( id=str(uuid4()), name=folder.path.name, path=str(folder.path), workspace=folder.workspace, owner=None, groups=folder.groups, public_mode=PublicMode.FULL if len(folder.groups) == 0 else PublicMode.NONE, ) study.content_status = self._analyse_study(study) logger.info( f"Study={study.id} appears on disk and will be added") self.event_bus.push( Event(EventType.STUDY_CREATED, study.to_json_summary())) self.repository.save(study)