def get_api_instance(name:str,ctx:HaloContext,method:str="", *args): global api_dict #ctx = args[0] id = None if HaloContext.items[HaloContext.CORRELATION] in ctx.keys(): id = ctx.get(HaloContext.items[HaloContext.CORRELATION]) logger.debug("ctx:"+str(id)) if not id: id = str(uuid.uuid4())[:8] if name in HALO_API_LIST: class_name = HALO_API_LIST[name] if class_name+id in api_dict: return api_dict[class_name+id] else: session = requests.session() params = [] params.append(ctx) params.append(method) params.append(session) for x in args: params.append(x) api = Reflect.instantiate(class_name, AbsBaseApi, *params) lock.acquire() try: api_dict[class_name+id] = api finally: lock.release() return api raise NoApiDefinitionException(name)
def insert_events_to_repository_class(self): if settings.REQUEST_FILTER_CLEAR_CLASS: clazz = Reflect.instantiate(settings.REQUEST_FILTER_CLEAR_CLASS, RequestFilterClear) else: clazz = RequestFilterClear() return clazz
def get_assembler_by_dto(cls, dto: AbsHaloDto) -> AbsDtoAssembler: dto_type = SysUtil.instance_full_name(dto) if dto_type in settings.DTO_ASSEMBLERS: dto_assembler_type = settings.DTO_ASSEMBLERS[dto_type] assembler: AbsDtoAssembler = Reflect.instantiate( dto_assembler_type, AbsDtoAssembler) return assembler raise MissingDtoAssemblerException(dto_type)
def get_assembler_by_entity(cls, entity: AbsHaloEntity) -> AbsDtoAssembler: entity_type = SysUtil.instance_full_name(entity) if entity_type in settings.DTO_ASSEMBLERS: dto_assembler_type = settings.DTO_ASSEMBLERS[entity_type] assembler: AbsDtoAssembler = Reflect.instantiate( dto_assembler_type, AbsDtoAssembler) return assembler raise MissingDtoAssemblerException(entity_type)
def get_assembler_by_request(cls, request: AbsHaloRequest) -> AbsDtoAssembler: if request.method_id in settings.DTO_ASSEMBLERS: dto_assembler_type = settings.DTO_ASSEMBLERS[request.method_id] assembler: AbsDtoAssembler = Reflect.instantiate( dto_assembler_type, AbsDtoAssembler) return assembler raise MissingDtoAssemblerException(request.method_id)
def bootstrap( start_orm: bool = settings.START_ORM, #True, uow: AbsUnitOfWork = Reflect.instantiate( settings.UOW_CLASS, AbsUnitOfWork), #SqlAlchemyUnitOfWork(), publish: Callable = Reflect.instantiate(settings.PUBLISHER_CLASS, AbsPublisher), #Publisher(), ) -> BoundaryService: if start_orm: from halo_app.infra.sql_orm import clear_mappers clear_mappers() start_mappers = Reflect.import_method_from(settings.ORM_METHOD) start_mappers() dependencies = {'uow': uow, 'publish': publish} for item in settings.DEPENDENCIES: clazz = settings.DEPENDENCIES[item] dependencies[item] = Reflect.instantiate(clazz) injected_event_handlers = { event_type: [ inject_dependencies(handler, dependencies) for handler in event_handlers ] for event_type, event_handlers in EVENT_HANDLERS.items() } injected_command_handlers = { command_type: inject_dependencies(handler, dependencies) for command_type, handler in COMMAND_HANDLERS.items() } injected_query_handlers = { query_type: inject_dependencies(handler, dependencies) for query_type, handler in QUERY_HANDLERS.items() } return BoundaryService( uow=uow, publisher=publish, event_handlers=injected_event_handlers, command_handlers=injected_command_handlers, query_handlers=injected_query_handlers, )
def __init__(self, halo_context, method_id, vars, secure=False, method_roles=None): self.method_id = method_id self.context = halo_context for i in settings.HALO_CONTEXT_LIST: if i not in HaloContext.items: raise MissingHaloContextException(str(i)) if i not in self.context.keys(): raise MissingHaloContextException(str(i)) if settings.SECURITY_FLAG or secure: if settings.HALO_SECURITY_CLASS: self.security = Reflect.instantiate( settings.HALO_SECURITY_CLASS, HaloSecurity) else: self.security = HaloSecurity() self.security.validate_method(method_roles)