def find_enum( import_items: ImportEnumItems) -> Tuple[Enum, List[EnumItem]]: enum_id = import_items.enumId name = import_items.name if is_blank(enum_id) and is_blank(name): raise_400( 'At least one of enumeration id and name must be provided.') enumeration = None if is_not_blank(enum_id): # both provided, find by id enumeration = enum_service.find_by_id(enum_id) elif is_not_blank(name): enumeration = enum_service.find_by_name( name, principal_service.get_tenant_id()) if enumeration is not None: # found if enumeration.tenantId != principal_service.get_tenant_id(): raise_404(f'Enumeration[id={enum_id}, name={name}] not found.') elif is_not_blank(name): # not found, but name is given, create one enumeration = Enum(enumId=enum_id, name=name, tenantId=principal_service.get_tenant_id(), items=[]) enum_service.create(enumeration) else: raise_404(f'Enumeration[id={enum_id}, name={name}] not found.') return enumeration, import_items.items
def action(topic_id: TopicId, factor_id: FactorId) -> ParameterCondition: if isinstance(criteria, AchievementIndicatorCriteriaOnBucket): return self.fake_bucket_criteria_to_condition( criteria.bucketId, criteria.bucketSegmentName)(topic_id, factor_id) elif isinstance(criteria, AchievementIndicatorCriteriaOnExpression): return self.fake_value_criteria_to_condition( criteria.operator, criteria.value)(topic_id, factor_id) else: data = criteria.to_dict() if is_not_blank(data.get('bucketId')) and is_not_blank( data.get('bucketSegmentName')): return self.fake_bucket_criteria_to_condition( data.get('bucketId'), data.get('bucketSegmentName'))(topic_id, factor_id) elif data.get('operator') is not None and is_not_blank( str(data.get('value'))): return self.fake_value_criteria_to_condition( data.get('operator'), str(data.get('value')))(topic_id, factor_id) else: raise IndicatorKernelException( f'Achievement indicator criteria[{data}] not supported.' )
def find_by_ids(self, graphic_ids: List[PipelineGraphicId], user_id: Optional[UserId], tenant_id: Optional[TenantId]) -> List[PipelineGraphic]: criteria = [ EntityCriteriaExpression( left=ColumnNameLiteral(columnName='pipeline_graphic_id'), operator=EntityCriteriaOperator.IN, right=graphic_ids) ] if is_not_blank(user_id): criteria.append( EntityCriteriaExpression( left=ColumnNameLiteral(columnName='user_id'), right=user_id)) if is_not_blank(tenant_id): criteria.append( EntityCriteriaExpression( left=ColumnNameLiteral(columnName='tenant_id'), right=tenant_id)) # noinspection PyTypeChecker return self.storage.find_distinct_values( self.get_entity_finder_for_columns(distinctColumnNames=[ 'pipeline_graphic_id' ], criteria=criteria))
def find_param(params: Optional[List[DataSourceParam]], key: str) -> Optional[str]: for param in params: if is_not_blank(param.name) and param.name.strip().lower() == key: value = param.value if is_not_blank(value): return value.strip() return None
def run_topics_rules( topic_name: Optional[str] = None, frequency: Optional[MonitorRuleStatisticalInterval] = None, process_date: Optional[str] = None, tenant_id: Optional[TenantId] = None, principal_service: PrincipalService = Depends(get_any_admin_principal) ) -> None: principal_service = ask_principal_service(principal_service, tenant_id) if is_not_blank(topic_name): schema = get_topic_service(principal_service).find_schema_by_name( topic_name, principal_service.get_tenant_id()) if schema is None: raise_404(f'Topic[name={topic_name}] not found.') topic_id = schema.get_topic().topicId else: topic_id = None if is_not_blank(process_date): parsed, parsed_date = is_date(process_date, ask_all_date_formats()) if not parsed: raise_400(f'Given process date[{process_date}] cannot be parsed.') process_date = parsed_date else: process_date = get_current_time_in_seconds() process_date = truncate_time(process_date) now = truncate_time(get_current_time_in_seconds()) if process_date.year > now.year: raise_400(f'Given process date[{process_date}] cannot be in future.') if process_date.year == now.year and process_date.month > now.month: raise_400(f'Given process date[{process_date}] cannot be in future.') if process_date.year == now.year and process_date.month == now.month and process_date.day > now.day: raise_400(f'Given process date[{process_date}] cannot be in future.') if frequency == MonitorRuleStatisticalInterval.MONTHLY: # given process date is in this month, run previous month # otherwise, run the given month if process_date.year == now.year and process_date.month == now.month: process_date = to_previous_month(process_date) SelfCleaningMonitorRulesRunner(principal_service) \ .run(process_date, topic_id, MonitorRuleStatisticalInterval.MONTHLY) elif frequency == MonitorRuleStatisticalInterval.WEEKLY: # given process date is in this week, run previous week # otherwise, run the given week if process_date.year == now.year and int( process_date.strftime('%U')) == int(now.strftime('%U')): process_date = to_previous_week(process_date) SelfCleaningMonitorRulesRunner(principal_service) \ .run(process_date, topic_id, MonitorRuleStatisticalInterval.WEEKLY) elif frequency == MonitorRuleStatisticalInterval.DAILY: # given process date is today, run yesterday # otherwise, run the given day if process_date.year == now.year and process_date.month == now.month and process_date.day == now.day: process_date = to_yesterday(process_date) SelfCleaningMonitorRulesRunner(principal_service) \ .run(process_date, topic_id, MonitorRuleStatisticalInterval.DAILY) else: raise_400(f'Given frequency[{frequency}] is not supported.')
def fill_rule_id(monitor_rule: MonitorRule) -> None: monitor_rule.ruleId = monitor_rule_service.generate_storable_id() if is_not_blank(monitor_rule.topicId): monitor_rule.topicId = topic_id_map.get(monitor_rule.topicId) if is_not_blank(monitor_rule.factorId): monitor_rule.factorId = factor_id_map.get(monitor_rule.factorId) if monitor_rule.params is not None: if is_not_blank(monitor_rule.params.topicId): monitor_rule.params.topicId = topic_id_map.get(monitor_rule.topicId) if is_not_blank(monitor_rule.params.factorId): monitor_rule.params.factorId = factor_id_map.get(monitor_rule.factorId)
def get_achievement_data_service( achievement_indicator: AchievementIndicator, principal_service: PrincipalService) -> AchievementDataService: """ to identify that given achievement is based on topic or subject """ indicator = ask_indicator(achievement_indicator.indicatorId, principal_service) topic_or_subject_id = indicator.topicOrSubjectId base_on = indicator.baseOn if base_on == IndicatorBaseOn.TOPIC and is_not_blank(topic_or_subject_id): return get_topic_base_service(achievement_indicator, indicator, topic_or_subject_id, principal_service) elif base_on == IndicatorBaseOn.SUBJECT and is_not_blank(topic_or_subject_id): return get_subject_base_service(achievement_indicator, indicator, topic_or_subject_id, principal_service) else: raise IndicatorKernelException('Indicator is not based on topic, not supported yet.')
def deserialize_from_auto_generated_aggregate_columns( self, row: Dict[str, Any], columns: List[FreeAggregateColumn]) -> Dict[str, Any]: data: Dict[str, Any] = {} for index, column in enumerate(columns): alias = column.alias if is_not_blank(column.alias) else column.name data[alias] = row.get(f'agg_column_{index + 1}') return data
async def fetch_topic_by_name( query_name: Optional[str] = None, tenant_id: Optional[TenantId] = None, principal_service: PrincipalService = Depends(get_any_admin_principal) ) -> List[Topic]: if is_blank(query_name): raise_400('Name criteria is required.') if principal_service.is_tenant_admin(): if is_not_blank( tenant_id) and tenant_id != principal_service.get_tenant_id(): raise_400('Tenant id is incorrect.') else: tenant_id = principal_service.get_tenant_id() if principal_service.is_super_admin() and is_blank(tenant_id): raise_400('Tenant id is required.') topic_service = get_topic_service(principal_service) def action() -> List[Topic]: topic_index_service = get_topic_index_service(topic_service) factor_index_list = topic_index_service.find(query_name, tenant_id) if len(factor_index_list) == 0: return [] topic_ids: List[TopicId] = [] for factor_index in factor_index_list: if factor_index.topicId not in topic_ids: topic_ids.append(factor_index.topicId) return topic_service.find_by_ids(topic_ids, tenant_id) return trans_readonly(topic_service, action)
def factor_use_regexp( data_service: TopicDataService, factor: Factor, data: List[Tuple[Any, int]], rule: MonitorRule, date_range: Tuple[datetime, datetime], should_match: bool ) -> RuleResult: pattern = rule.params.regexp if is_blank(pattern): logger.error(f'Regexp not declared on rule[{rule.dict()}].') return RuleResult.IGNORED def matched(value: Any) -> bool: if value is None: # ignore, it should be detected by factor_is_empty rule return False result = search(pattern, value) if result is not None: # regexp matched return should_match else: return not should_match mismatched = ArrayHelper(data) \ .map(lambda row: row[0]) \ .filter(lambda value: is_not_blank(value)) \ .some(lambda x: matched(x)) return RuleResult.FAILED if mismatched else RuleResult.SUCCESS
def action() -> List[Space]: tenant_id: TenantId = principal_service.get_tenant_id() user_id = principal_service.get_user_id() # noinspection PyTypeChecker user: User = get_user_service(space_service).find_by_id(user_id) user_group_ids = user.groupIds if user_group_ids is None or len(user_group_ids) == 0: return [] user_group_ids = ArrayHelper(user_group_ids).filter(lambda x: is_not_blank(x)).to_list() if len(user_group_ids) == 0: return [] user_group_service = get_user_group_service(space_service) user_groups = user_group_service.find_by_ids(user_group_ids, tenant_id) def gather_space_ids(distinct_space_ids: List[SpaceId], user_group: UserGroup) -> List[SpaceId]: given_space_ids = user_group.spaceIds if given_space_ids is None or len(given_space_ids) == 0: return distinct_space_ids given_space_ids = ArrayHelper(given_space_ids).filter(lambda x: is_not_blank(x)).to_list() for space_id in given_space_ids: if space_id not in distinct_space_ids: distinct_space_ids.append(space_id) return distinct_space_ids space_ids = ArrayHelper(user_groups).reduce(gather_space_ids, []) return space_service.find_by_ids(space_ids, tenant_id)
def action(topic_id: TopicId, factor_id: FactorId) -> ParameterExpression: values = ArrayHelper( segment.value).filter(lambda x: is_not_blank(x)).to_list() if len(values) == 0: raise IndicatorKernelException( 'Value of category segment not declared.') if len(values) == 1 and values[0] == OtherCategorySegmentValue: # other values values = self.gather_defined_category_values(segments) if len(values) == 0: raise IndicatorKernelException( 'No values rather than others of category segment not declared.' ) return ParameterExpression( left=TopicFactorParameter(kind=ParameterKind.TOPIC, topicId=topic_id, factorId=factor_id), operator=ParameterExpressionOperator.NOT_IN, right=values) else: return ParameterExpression( left=TopicFactorParameter(kind=ParameterKind.TOPIC, topicId=topic_id, factorId=factor_id), operator=ParameterExpressionOperator.IN, right=values)
def construct_indicator_criteria( criteria: Optional[Union[dict, AchievementIndicatorCriteria]] ) -> Optional[AchievementIndicatorCriteria]: if criteria is None: return None elif isinstance(criteria, AchievementIndicatorCriteria): return criteria else: bucket_id = criteria.get('bucketId') if is_not_blank(bucket_id): return AchievementIndicatorCriteriaOnBucket(**criteria) operator = criteria.get('operator') if is_not_blank(operator): return AchievementIndicatorCriteriaOnExpression(**criteria) else: return AchievementIndicatorCriteria(**criteria)
def action(user: User) -> User: # crypt password pwd = user.password if is_not_blank(pwd): user.password = crypt_password(pwd) if user.isActive is None: user.isActive = True if user_service.is_storable_id_faked(user.userId): if principal_service.is_super_admin() and check_user_group: if user.groupIds is not None and len(user.groupIds) != 0: # for super admin create user, there is no user group allowed raise_400( 'No user group allowed for creating user by super admin.' ) user_service.redress_storable_id(user) user_group_ids = ArrayHelper(user.groupIds).distinct().to_list() user.groupIds = user_group_ids # noinspection PyTypeChecker user: User = user_service.create(user) # synchronize user to user groups sync_user_to_groups(user_service, user.userId, user_group_ids, user.tenantId) else: # noinspection PyTypeChecker existing_user: Optional[User] = user_service.find_by_id( user.userId) if existing_user is not None: if existing_user.tenantId != user.tenantId: raise_403() elif is_blank(user.password): # keep original password user.password = existing_user.password if principal_service.is_super_admin() and check_user_group: # for super admin update user, simply keep user group user.groupIds = existing_user.groupIds else: user_group_ids = ArrayHelper( user.groupIds).distinct().to_list() user.groupIds = user_group_ids user_group_ids = user.groupIds # noinspection PyTypeChecker user: User = user_service.update(user) if principal_service.is_tenant_admin(): # remove user from user groups, in case user groups are removed removed_user_group_ids = ArrayHelper( existing_user.groupIds).difference( user_group_ids).to_list() remove_user_from_groups(user_service, user.userId, removed_user_group_ids, user.tenantId) # synchronize user to user groups sync_user_to_groups(user_service, user.userId, user_group_ids, user.tenantId) # remove password clear_pwd(user) return user
def action(topic_id: TopicId, factor_id: FactorId) -> ParameterCondition: min_value = segment.value.min max_value = segment.value.max if include == RangeBucketValueIncluding.INCLUDE_MIN: operator_min = ParameterExpressionOperator.MORE_EQUALS else: operator_min = ParameterExpressionOperator.MORE if include == RangeBucketValueIncluding.INCLUDE_MIN: operator_max = ParameterExpressionOperator.LESS else: operator_max = ParameterExpressionOperator.LESS_EQUALS if is_not_blank(min_value) and is_not_blank(max_value): return ParameterJoint( jointType=ParameterJointType.AND, filters=[ ParameterExpression(left=TopicFactorParameter( kind=ParameterKind.TOPIC, topicId=topic_id, factorId=factor_id), operator=operator_min, right=min_value), ParameterExpression(left=TopicFactorParameter( kind=ParameterKind.TOPIC, topicId=topic_id, factorId=factor_id), operator=operator_max, right=max_value) ]) elif is_not_blank(min_value): return ParameterExpression(left=TopicFactorParameter( kind=ParameterKind.TOPIC, topicId=topic_id, factorId=factor_id), operator=operator_min, right=min_value) elif is_not_blank(max_value): return ParameterExpression(left=TopicFactorParameter( kind=ParameterKind.TOPIC, topicId=topic_id, factorId=factor_id), operator=operator_max, right=max_value) else: raise IndicatorKernelException( 'Neither minimum not maximum value of numeric value segment is declared.' )
def deserialize_from_aggregate_row( self, row: List[Any], columns: List[FreeAggregateColumn]) -> Dict[str, Any]: data: Dict[str, Any] = {} for index, column in enumerate(columns): alias = column.alias if is_not_blank(column.alias) else column.name data[alias] = row[index] return data
async def start(self, trigger: TopicTrigger, pipeline_id: Optional[PipelineId] = None) -> None: """ data of trigger must be prepared already """ schema = self.triggerTopicSchema topic = schema.get_topic() if is_not_blank(pipeline_id): pipeline = get_pipeline_service(self.principalService).find_by_id(pipeline_id) if pipeline is None: raise PipelineKernelException(f'Given pipeline[id={pipeline_id}] not found.') else: pipelines = [pipeline] else: pipelines = get_pipeline_service(self.principalService).find_by_topic_id(topic.topicId) if len(pipelines) == 0: if is_not_blank(pipeline_id): raise PipelineKernelException(f'Given pipeline[id={pipeline_id}] not found.') else: logger.warning(f'No pipeline needs to be triggered by topic[id={topic.topicId}, name={topic.name}].') return pipelines = ArrayHelper(pipelines) \ .filter(lambda x: self.should_run(trigger.triggerType, x)).to_list() if len(pipelines) == 0: if is_not_blank(pipeline_id): raise PipelineKernelException( f'Given pipeline[id={pipeline_id}] does not match trigger type[{trigger.triggerType}].') else: logger.warning(f'No pipeline needs to be triggered by topic[id={topic.topicId}, name={topic.name}].') return def construct_queued_pipeline(a_pipeline: Pipeline) -> RuntimePipelineContext: return RuntimePipelineContext( pipeline=a_pipeline, trigger_topic_schema=self.triggerTopicSchema, previous_data=trigger.previous, current_data=trigger.current, principal_service=self.principalService, trace_id=self.traceId, data_id=trigger.internalDataId ) PipelinesDispatcher( contexts=ArrayHelper(pipelines).map(lambda x: construct_queued_pipeline(x)).to_list(), storages=self.storages, ).start(self.handle_monitor_log)
def build_criteria_expression(tables: List[Table], expression: EntityCriteriaExpression): built_left = build_literal(tables, expression.left) op = expression.operator if op == EntityCriteriaOperator.IS_EMPTY: return or_(built_left.is_(None), built_left == '') elif op == EntityCriteriaOperator.IS_NOT_EMPTY: return and_(built_left.is_not(None), built_left != '') elif op == EntityCriteriaOperator.IS_BLANK: return or_(built_left.is_(None), func.trim(built_left) == '') elif op == EntityCriteriaOperator.IS_NOT_BLANK: return and_(built_left.is_not(None), func.trim(built_left) != '') if op == EntityCriteriaOperator.IN or op == EntityCriteriaOperator.NOT_IN: if isinstance(expression.right, ColumnNameLiteral): raise UnsupportedCriteriaException('In or not-in criteria expression on another column is not supported.') elif isinstance(expression.right, ComputedLiteral): if expression.right.operator == ComputedLiteralOperator.CASE_THEN: # TODO cannot know whether the built literal will returns a list or a value, let it be now. built_right = build_literal(tables, expression.right) else: # any other computation will not lead a list built_right = [build_literal(tables, expression.right)] elif isinstance(expression.right, str): built_right = ArrayHelper(expression.right.strip().split(',')).filter(lambda x: is_not_blank(x)).to_list() else: built_right = build_literal(tables, expression.right) if not isinstance(built_right, list): built_right = [built_right] if op == EntityCriteriaOperator.IN: if isinstance(built_left, (bool, str, int, float, Decimal, date, time)): return literal(built_left).in_(built_right) else: return built_left.in_(built_right) elif op == EntityCriteriaOperator.NOT_IN: if isinstance(built_left, (bool, str, int, float, Decimal, date, time)): return literal(built_left).not_in(built_right) else: return built_left.not_in(built_right) built_right = build_literal(tables, expression.right) if op == EntityCriteriaOperator.EQUALS: return built_left == built_right elif op == EntityCriteriaOperator.NOT_EQUALS: return built_left != built_right elif op == EntityCriteriaOperator.LESS_THAN: return built_left < built_right elif op == EntityCriteriaOperator.LESS_THAN_OR_EQUALS: return built_left <= built_right elif op == EntityCriteriaOperator.GREATER_THAN: return built_left > built_right elif op == EntityCriteriaOperator.GREATER_THAN_OR_EQUALS: return built_left >= built_right elif op == EntityCriteriaOperator.LIKE: return built_left.ilike(f'%{built_right}%') elif op == EntityCriteriaOperator.NOT_LIKE: return built_left.not_ilike(f'%{built_right}%') else: raise UnsupportedCriteriaException(f'Unsupported criteria expression operator[{op}].')
def gather_space_ids(distinct_space_ids: List[SpaceId], user_group: UserGroup) -> List[SpaceId]: given_space_ids = user_group.spaceIds if given_space_ids is None or len(given_space_ids) == 0: return distinct_space_ids given_space_ids = ArrayHelper(given_space_ids).filter(lambda x: is_not_blank(x)).to_list() for space_id in given_space_ids: if space_id not in distinct_space_ids: distinct_space_ids.append(space_id) return distinct_space_ids
def build_criteria_expression(self, expression: EntityCriteriaExpression) -> str: built_left = self.build_literal(expression.left) op = expression.operator if op == EntityCriteriaOperator.IS_EMPTY: return f'{built_left} IS NULL OR {built_left} = \'\'' elif op == EntityCriteriaOperator.IS_NOT_EMPTY: return f'{built_left} IS NOT NULL AND {built_left} != \'\'' elif op == EntityCriteriaOperator.IS_BLANK: return f'TRIM({built_left}) = \'\'' elif op == EntityCriteriaOperator.IS_NOT_BLANK: return f'TRIM({built_left}) != \'\'' if op == EntityCriteriaOperator.IN or op == EntityCriteriaOperator.NOT_IN: if isinstance(expression.right, ColumnNameLiteral): raise UnsupportedCriteriaException( 'In or not-in criteria expression on another column is not supported.' ) elif isinstance(expression.right, ComputedLiteral): if expression.right.operator == ComputedLiteralOperator.CASE_THEN: # TODO cannot know whether the built literal will returns a list or a value, let it be now. built_right = self.build_literal(expression.right) else: # any other computation will not lead a list built_right = [self.build_literal(expression.right)] elif isinstance(expression.right, str): built_right = ArrayHelper(expression.right.strip().split( ',')).filter(lambda x: is_not_blank(x)).to_list() else: built_right = self.build_literal(expression.right) if not isinstance(built_right, list): built_right = [built_right] if op == EntityCriteriaOperator.IN: return f'{built_left} IN ({ArrayHelper(built_right).map(lambda x: self.build_literal(x)).join(", ")})' elif op == EntityCriteriaOperator.NOT_IN: return f'{built_left} NOT IN ({ArrayHelper(built_right).map(lambda x: self.build_literal(x)).join(", ")})' built_right = self.build_literal(expression.right) if op == EntityCriteriaOperator.EQUALS: return f'{built_left} = {built_right}' elif op == EntityCriteriaOperator.NOT_EQUALS: return f'{built_left} != {built_right}' elif op == EntityCriteriaOperator.LESS_THAN: return f'{built_left} < {built_right}' elif op == EntityCriteriaOperator.LESS_THAN_OR_EQUALS: return f'{built_left} <= {built_right}' elif op == EntityCriteriaOperator.GREATER_THAN: return f'{built_left} > {built_right}' elif op == EntityCriteriaOperator.GREATER_THAN_OR_EQUALS: return f'{built_left} >= {built_right}' elif op == EntityCriteriaOperator.LIKE: return f'LOWER({built_left}) LIKE \'{self.build_like_pattern(built_right)}\' ESCAPE \'\\\'' elif op == EntityCriteriaOperator.NOT_LIKE: return f'LOWER({built_left}) NOT LIKE \'{self.build_like_pattern(built_right)}\' ESCAPE \'\\\'' else: raise UnsupportedCriteriaException( f'Unsupported criteria expression operator[{op}].')
def find_all(self, tenant_id: Optional[TenantId]) -> List[Topic]: criteria = [] if is_not_blank(tenant_id): criteria.append( EntityCriteriaExpression( left=ColumnNameLiteral(columnName='tenant_id'), right=tenant_id)) # noinspection PyTypeChecker return self.storage.find(self.get_entity_finder(criteria))
def parse_encrypt_factors(topic: Topic) -> List[EncryptFactorGroup]: groups = ArrayHelper(topic.factors) \ .filter(lambda x: x.encrypt is not None and x.encrypt != FactorEncryptMethod.NONE) \ .map(lambda x: EncryptFactor(x)) \ .filter(lambda x: is_not_blank(x.factorName)) \ .group_by(lambda x: x.names[0]) return ArrayHelper(list(groups.items())) \ .map(lambda x: EncryptFactorGroup(name=x[0], factors=x[1])).to_list()
def parse_date_or_time_factors(topic: Topic) -> List[DateOrTimeFactorGroup]: groups = ArrayHelper(topic.factors) \ .filter(is_date_or_time) \ .map(lambda x: DateOrTimeFactor(x)) \ .filter(lambda x: is_not_blank(x.factorName)) \ .group_by(lambda x: x.names[0]) return ArrayHelper(list(groups.items())) \ .map(lambda x: DateOrTimeFactorGroup(name=x[0], factors=x[1])).to_list()
def action() -> List[Enum]: topic_service = get_topic_service(enum_service) topic: Optional[Topic] = topic_service.find_by_id(topic_id) if topic.tenantId != principal_service.get_tenant_id(): raise_403() return ArrayHelper(topic.factors) \ .filter(lambda x: is_not_blank(x.enumId)) \ .map(lambda x: enum_service.find_by_id(x.enumId)) \ .to_list()
def action() -> Space: # noinspection PyTypeChecker space: Space = space_service.delete(space_id) if space is None: raise_404() user_group_ids = space.groupIds if user_group_ids is not None and len(user_group_ids) != 0: user_group_ids = ArrayHelper(user_group_ids).filter(lambda x: is_not_blank(x)).to_list() remove_space_from_groups(space_service, space.spaceId, user_group_ids, space.tenantId) return space
def to_exclude_types(exclude_types: Optional[str]) -> List[TopicType]: if is_blank(exclude_types): return [] else: return ArrayHelper(exclude_types.strip().split(',')) \ .map(lambda x: x.strip()) \ .filter(lambda x: is_not_blank(x)) \ .map(lambda x: to_topic_type(x)) \ .filter(lambda x: x is not None) \ .to_list()
async def trigger_pipeline_async( trigger_data: PipelineTriggerData, principal_service: PrincipalService = Depends(get_any_admin_principal) ) -> PipelineTriggerResult: trace_id = trigger_data.traceId if is_not_blank( trigger_data.traceId) else str(ask_snowflake_generator().next_id()) internal_data_id = await try_to_invoke_pipelines_async( trigger_data, trace_id, principal_service) return PipelineTriggerResult(received=True, traceId=trace_id, internalDataId=str(internal_data_id))
def validate_tenant_id(tenant_id: Optional[TenantId], principal_service: PrincipalService) -> TenantId: if principal_service.is_tenant_admin(): if is_not_blank( tenant_id) and tenant_id != principal_service.get_tenant_id(): raise_400('Tenant id is incorrect.') return principal_service.get_tenant_id() elif principal_service.is_super_admin(): if is_blank(tenant_id): raise_400('Tenant id is required.') return tenant_id
def action() -> User: # noinspection PyTypeChecker user: User = user_service.delete(user_id) if user is None: raise_404() user_group_ids = user.groupIds if user_group_ids is not None and len(user_group_ids) != 0: user_group_ids = ArrayHelper(user_group_ids).filter( lambda x: is_not_blank(x)).to_list() remove_user_from_groups(user_service, user.userId, user_group_ids, user.tenantId) return user
def find_modified_after(self, last_modified_at: datetime, tenant_id: Optional[TenantId]) -> List[Pipeline]: criteria = [ EntityCriteriaExpression( left=ColumnNameLiteral(columnName='last_modified_at'), operator=EntityCriteriaOperator.GREATER_THAN_OR_EQUALS, right=last_modified_at ) ] if is_not_blank(tenant_id): criteria.append(EntityCriteriaExpression(left=ColumnNameLiteral(columnName='tenant_id'), right=tenant_id)) # noinspection PyTypeChecker return self.storage.find(self.get_entity_finder(criteria))