def try_to_import_subject(
		subject: SubjectWithReports, subject_service: SubjectService, do_update: bool
) -> SubjectImportDataResult:
	if is_blank(subject.subjectId):
		subject_service.redress_storable_id(subject)
		subject_service.create(subject)
	else:
		existing_subject: Optional[Subject] = subject_service.find_by_id(subject.subjectId)
		if existing_subject is None:
			subject_service.create(subject)
		elif do_update:
			subject_service.update(subject)
		else:
			return SubjectImportDataResult(
				subjectId=subject.subjectId, name=subject.name, passed=False, reason='Subject already exists.')

	def set_subject_id(report: Report, subject_id: SubjectId) -> None:
		report.subjectId = subject_id

	ArrayHelper(subject.reports).each(lambda x: set_subject_id(x, subject.subjectId))

	return SubjectImportDataResult(subjectId=subject.subjectId, name=subject.name, passed=True)
    def find_by_name(self, subject_name: str) -> Optional[Subject]:
        storage_service = SubjectStorageService(ask_meta_storage(),
                                                ask_snowflake_generator(),
                                                self.principalService)
        storage_service.begin_transaction()
        try:
            # noinspection PyTypeChecker
            subject: Subject = storage_service.find_by_name(subject_name)
            if subject is None:
                return None
            if subject.tenantId != self.principalService.get_tenant_id():
                raise InquiryKernelException(
                    f'Subject[name={subject_name}] not belongs to '
                    f'current tenant[id={self.principalService.get_tenant_id()}].'
                )
            if not self.principalService.is_admin(
            ) and subject.userId != self.principalService.get_user_id():
                raise InquiryKernelException(
                    f'Subject[name={subject_name}] not belongs to '
                    f'current user[id={self.principalService.get_user_id()}].')

            return subject
        finally:
            storage_service.close_transaction()
Beispiel #3
0
def get_subject_service(principal_service: PrincipalService) -> SubjectService:
    return SubjectService(ask_meta_storage(), ask_snowflake_generator(),
                          principal_service)
Beispiel #4
0
def get_subject_service(
        connected_space_service: ConnectedSpaceService) -> SubjectService:
    return SubjectService(connected_space_service.storage,
                          connected_space_service.snowflakeGenerator,
                          connected_space_service.principalService)
def get_subject_service(user_service: UserService) -> SubjectService:
	return SubjectService(user_service.storage, user_service.snowflakeGenerator, user_service.principalService)
Beispiel #6
0
def get_subject_service(dashboard_service: DashboardService) -> SubjectService:
	return SubjectService(
		dashboard_service.storage, dashboard_service.snowflakeGenerator, dashboard_service.principalService)
def get_subject_service(report_service: ReportService) -> SubjectService:
	return SubjectService(report_service.storage, report_service.snowflakeGenerator, report_service.principalService)