Пример #1
0
def validate_name_request(location, entity_type, request_action):
    # Raise error if location is invalid
    if location not in ValidLocations.list():
        raise ValueError('Invalid location provided')

    # Raise error if request_action is invalid
    if request_action not in AnalysisRequestActions.list():
        raise ValueError('Invalid request action provided')

    # Throw any errors related to invalid entity_type or request_action for a location
    if location == ValidLocations.CA_BC.value:
        is_protected = False
        is_unprotected = False

        # Determine what request actions are valid
        valid_request_actions = ()

        if entity_type in BCProtectedNameEntityTypes.list():
            is_protected = True
            valid_request_actions = (AnalysisRequestActions.NEW.value,
                                     AnalysisRequestActions.AML.value)

        elif entity_type in BCUnprotectedNameEntityTypes.list():
            is_unprotected = True
            valid_request_actions = (AnalysisRequestActions.NEW.value,
                                     AnalysisRequestActions.DBA.value)

        if is_protected and is_unprotected:
            raise ValueError(
                'An entity name cannot be both protected and unprotected')

        if is_protected and entity_type not in BCProtectedNameEntityTypes.list(
        ):
            raise ValueError(
                'Invalid entity_type provided for a protected BC entity name')

        if is_unprotected and entity_type not in BCUnprotectedNameEntityTypes.list(
        ):
            raise ValueError(
                'Invalid entity_type provided for an unprotected BC entity name'
            )

        if request_action not in valid_request_actions:
            raise Exception('Operation not currently supported')

    elif location in (ValidLocations.CA_NOT_BC.list(),
                      ValidLocations.INTL.list()):
        # If XPRO, nothing is protected (for now anyway)
        valid_request_actions = (AnalysisRequestActions.NEW.value,
                                 AnalysisRequestActions.DBA.value)

        if entity_type not in XproUnprotectedNameEntityTypes.list():
            raise ValueError('Invalid entity_type provided for an XPRO entity')

        if request_action not in valid_request_actions:
            raise Exception('Operation not currently supported')

    return True
Пример #2
0
def validate_name_request(location, entity_type, request_action):
    """ Validates the name analysis request."""
    # Raise error if location is invalid
    if location not in ValidLocations.list():
        raise ValueError('Invalid location provided')

    # Raise error if request_action is invalid
    if request_action not in AnalysisRequestActions.list():
        raise ValueError('Invalid request action provided')

    # Throw any errors related to invalid entity_type or request_action for a location
    if location == ValidLocations.CA_BC.value:
        is_protected = False
        is_unprotected = False
        valid_request_actions = []

        if entity_type in BCProtectedNameEntityTypes.list():
            is_protected = True
            valid_request_actions = [
                AnalysisRequestActions.NEW.value,
                AnalysisRequestActions.CHG.value,
                AnalysisRequestActions.MVE.value
            ]
        elif entity_type in BCUnprotectedNameEntityTypes.list():
            is_unprotected = True
            valid_request_actions = (AnalysisRequestActions.NEW.value, AnalysisRequestActions.DBA.value)

        if is_protected and is_unprotected:
            raise ValueError('An entity name cannot be both protected and unprotected')

        if is_protected and entity_type not in BCProtectedNameEntityTypes.list():
            raise ValueError('Invalid entity_type provided for a protected BC entity name')

        if is_unprotected and entity_type not in BCUnprotectedNameEntityTypes.list():
            raise ValueError('Invalid entity_type provided for an unprotected BC entity name')

    else:
        valid_location = location in [ValidLocations.CA_NOT_BC.value, ValidLocations.INTL.value]
        valid_request_actions = [
            AnalysisRequestActions.NEW.value,
            AnalysisRequestActions.AML.value,
            AnalysisRequestActions.CHG.value,
            AnalysisRequestActions.ASSUMED.value,
            AnalysisRequestActions.REN.value,
            AnalysisRequestActions.REH.value
        ]

        if not valid_location:
            raise ValueError('Invalid location provided')

        if entity_type not in XproUnprotectedNameEntityTypes.list():
            raise ValueError('Invalid entity_type provided for an XPRO entity')

    if request_action not in valid_request_actions:
        raise Exception('Operation not currently supported')

    return True
Пример #3
0
def get_entity_type_code_DEPRECATED(entity_type_str):
    entity_type_code = None
    if BCProtectedNameEntityTypes.has_value(entity_type_str):
        entity_type_code = BCProtectedNameEntityTypes(entity_type_str)
    elif BCUnprotectedNameEntityTypes.has_value(entity_type_str):
        entity_type_code = BCUnprotectedNameEntityTypes(entity_type_str)
    elif XproUnprotectedNameEntityTypes.has_value(entity_type_str):
        entity_type_code = XproUnprotectedNameEntityTypes(entity_type_str)

    return entity_type_code
Пример #4
0
    def _set_designations_by_entity_type_user(self):
        syn_svc = self.synonym_service
        entity_type = self.entity_type

        entity_type_code = None
        if BCProtectedNameEntityTypes.has_value(
                entity_type) and BCProtectedNameEntityTypes(entity_type):
            entity_type_code = BCProtectedNameEntityTypes(entity_type)
        elif BCUnprotectedNameEntityTypes.has_value(
                entity_type) and BCUnprotectedNameEntityTypes(entity_type):
            entity_type_code = BCUnprotectedNameEntityTypes(entity_type)
        elif XproUnprotectedNameEntityTypes.has_value(
                entity_type) and XproUnprotectedNameEntityTypes(entity_type):
            entity_type_code = XproUnprotectedNameEntityTypes(entity_type)
        else:
            raise Exception(
                'Could not set entity type user designations - entity type [' +
                entity_type + '] was not found in BC or XPRO entity types!')

        self._eng_designation_any_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.ANY.value,
            lang=LanguageCodes.ENG.value).data

        self._eng_designation_end_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.END.value,
            lang=LanguageCodes.ENG.value).data

        self._fr_designation_any_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.ANY.value,
            lang=LanguageCodes.FR.value).data

        self._fr_designation_end_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.END.value,
            lang=LanguageCodes.FR.value).data

        self._eng_designation_all_list_correct = self._eng_designation_any_list_correct + self._eng_designation_end_list_correct
        self._eng_designation_all_list_correct.sort(key=len, reverse=True)

        self._fr_designation_all_list_correct = self._fr_designation_any_list_correct + self._fr_designation_end_list_correct
        self._fr_designation_all_list_correct.sort(key=len, reverse=True)

        self._designation_any_list_correct = self._eng_designation_any_list_correct + self._fr_designation_any_list_correct
        self._designation_any_list_correct.sort(key=len, reverse=True)

        self._designation_end_list_correct = self._eng_designation_end_list_correct + self._fr_designation_end_list_correct
        self._designation_end_list_correct.sort(key=len, reverse=True)
Пример #5
0
def validate_name_request(location, entity_type, request_action):
    # Raise error if location is invalid
    if location not in ValidLocations.list():
        raise ValueError('Invalid location provided')

    # Raise error if request_action is invalid
    if request_action not in AnalysisRequestActions.list():
        raise ValueError('Invalid request action provided')

    # Throw any errors related to invalid entity_type or request_action for a location
    if location != ValidLocations.CA_BC.value:
        raise ValueError('Invalid location provided')

    is_protected = False
    is_unprotected = False
    valid_request_actions = []

    if entity_type in BCProtectedNameEntityTypes.list():
        is_protected = True
        valid_request_actions = [
            AnalysisRequestActions.NEW.value, AnalysisRequestActions.CHG.value,
            AnalysisRequestActions.MVE.value
        ]
    elif entity_type in BCUnprotectedNameEntityTypes.list():
        is_unprotected = True
        valid_request_actions = (AnalysisRequestActions.NEW.value,
                                 AnalysisRequestActions.DBA.value)

    if is_protected and is_unprotected:
        raise ValueError(
            'An entity name cannot be both protected and unprotected')

    if is_protected and entity_type not in BCProtectedNameEntityTypes.list():
        raise ValueError(
            'Invalid entity_type provided for a protected BC entity name')

    if is_unprotected and entity_type not in BCUnprotectedNameEntityTypes.list(
    ):
        raise ValueError(
            'Invalid entity_type provided for an unprotected BC entity name')

    if request_action not in valid_request_actions:
        raise Exception('Operation not currently supported')

    return True
Пример #6
0
    def _set_designations_by_entity_type_user(self):
        syn_svc = self.synonym_service
        entity_type = self.entity_type

        entity_type_code = None
        if BCProtectedNameEntityTypes(entity_type):
            entity_type_code = BCProtectedNameEntityTypes(entity_type)
        elif BCUnprotectedNameEntityTypes(entity_type):
            entity_type_code = BCUnprotectedNameEntityTypes(entity_type)
        elif XproUnprotectedNameEntityTypes(entity_type):
            entity_type_code = XproUnprotectedNameEntityTypes(entity_type)

        self._eng_designation_any_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.ANY.value,
            lang=LanguageCodes.ENG.value).data

        self._eng_designation_end_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.END.value,
            lang=LanguageCodes.ENG.value).data

        self._fr_designation_any_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.ANY.value,
            lang=LanguageCodes.FR.value).data

        self._fr_designation_end_list_correct = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.END.value,
            lang=LanguageCodes.FR.value).data

        self._eng_designation_all_list_correct = self._eng_designation_any_list_correct + self._eng_designation_end_list_correct
        self._eng_designation_all_list_correct.sort(key=len, reverse=True)

        self._fr_designation_all_list_correct = self._fr_designation_any_list_correct + self._fr_designation_end_list_correct
        self._fr_designation_all_list_correct.sort(key=len, reverse=True)

        self._designation_any_list_correct = self._eng_designation_any_list_correct + self._fr_designation_any_list_correct
        self._designation_any_list_correct.sort(key=len, reverse=True)

        self._designation_end_list_correct = self._eng_designation_end_list_correct + self._fr_designation_end_list_correct
        self._designation_end_list_correct.sort(key=len, reverse=True)
Пример #7
0
def bc_validate_name_request(location, entity_type, request_action):
    """Validate the params for bc analysis."""
    errors = []
    # Check location is valid
    if location != ValidLocations.CA_BC.value:
        errors.append('Invalid location provided')

    # Check request_action is valid
    if request_action not in AnalysisRequestActions.list():
        errors.append('Invalid request action provided')

    is_protected = False
    is_unprotected = False
    valid_request_actions = []
    if entity_type in BCProtectedNameEntityTypes.list():
        is_protected = True
        valid_request_actions = [
            AnalysisRequestActions.NEW.value, AnalysisRequestActions.CHG.value,
            AnalysisRequestActions.MVE.value, AnalysisRequestActions.REH.value,
            AnalysisRequestActions.REN.value, AnalysisRequestActions.CNV.value,
            AnalysisRequestActions.AML.value
        ]
    # elif entity_type in BCUnprotectedNameEntityTypes.list():
    #     is_unprotected = True
    #     valid_request_actions = (AnalysisRequestActions.NEW.value, AnalysisRequestActions.DBA.value)

    if is_protected and is_unprotected:
        errors.append(
            'An entity name cannot be both protected and unprotected')

    if is_protected and entity_type not in BCProtectedNameEntityTypes.list():
        errors.append(
            'Invalid entity_type provided for a protected BC entity name')

    if is_unprotected and entity_type not in BCUnprotectedNameEntityTypes.list(
    ):
        errors.append(
            'Invalid entity_type provided for an unprotected BC entity name')

    if request_action not in valid_request_actions:
        errors.append('Operation not currently supported')

    return errors
Пример #8
0
    def _set_designations_by_entity_type_user(self):
        syn_svc = self.synonym_service
        entity_type = self.entity_type

        entity_type_code = None
        if BCProtectedNameEntityTypes.has_value(entity_type):
            entity_type_code = BCProtectedNameEntityTypes(entity_type)
        elif BCUnprotectedNameEntityTypes.has_value(entity_type):
            entity_type_code = BCUnprotectedNameEntityTypes(entity_type)
        elif XproUnprotectedNameEntityTypes.has_value(entity_type):
            entity_type_code = XproUnprotectedNameEntityTypes(entity_type)

        any_list = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.ANY.value,
            lang=LanguageCodes.ENG.value).data

        end_list = syn_svc.get_designations(
            entity_type_code=entity_type_code.value,
            position_code=DesignationPositionCodes.END.value,
            lang=LanguageCodes.ENG.value).data

        self._designation_any_list_correct.extend(any_list)
        self._designation_end_list_correct.extend(end_list)
Пример #9
0
    def get():
        name = unquote_plus(request.args.get(
            'name').strip()) if request.args.get('name') else None
        location = unquote_plus(request.args.get(
            'location').strip()) if request.args.get('location') else None
        entity_type = unquote_plus(request.args.get('entity_type').strip(
        )) if request.args.get('entity_type') else None
        # TODO: Let's not call var request_type because it's ambiguous - change to request_action on frontend too
        request_action = unquote_plus(
            request.args.get('request_action').strip()
        ) if request.args.get(
            'request_action'
        ) else None  # TODO: Use request_action not request_type, this needs to be updated on the front end!!!
        # request_action = unquote_plus(request.args.get('request_type').strip()) if request.args.get('request_type') else None  # TODO: Leave this as request_type for now...

        # Do our service stuff
        # Instantiate an appropriate service and register a builder for that service (subclasses of NameAnalysisDirector)
        # We can optionally use a different builder if we want to further tweak analysis by modifying the following procedures:
        # do_analysis (performs the checks)
        # check_name_is_well_formed
        # check_words_to_avoid
        # search_conflicts
        # check_words_requiring_consent
        # check_designation

        service = None

        if not validate_name_request(location, entity_type, request_action):
            return  # TODO: Return invalid response! What is it?

        try:
            if location == ValidLocations.CA_BC.value and entity_type in BCProtectedNameEntityTypes.list(
            ) and request_action in (AnalysisRequestActions.NEW.value,
                                     AnalysisRequestActions.AML.value):
                # Use ProtectedNameAnalysisService
                service = ProtectedNameAnalysisService()
                builder = NameAnalysisBuilder(service)

            elif location == ValidLocations.CA_BC.value and entity_type in BCUnprotectedNameEntityTypes.list(
            ) and request_action in (AnalysisRequestActions.NEW.value):
                # Use UnprotectedNameAnalysisService
                service = UnprotectedNameAnalysisService()
                builder = NameAnalysisBuilder(service)

            elif location in (
                    ValidLocations.CA_NOT_BC.value, ValidLocations.INTL.value
            ) and entity_type in XproUnprotectedNameEntityTypes.list(
            ) and request_action in (AnalysisRequestActions.NEW.value,
                                     AnalysisRequestActions.DBA.value):
                # Use UnprotectedNameAnalysisService
                service = UnprotectedNameAnalysisService()
                builder = NameAnalysisBuilder(service)

            else:
                raise Exception('Invalid scenario')

            if not service:
                raise ValueError('Invalid service provided')
            if not builder:
                raise ValueError('Invalid builder provided')

            # Register and initialize the builder
            service.use_builder(builder)  # Required step! TODO: Enforce this!
            service.set_entity_type(
                entity_type)  # Required step! TODO: Enforce this!
            service.set_name(name)  # Required step! TODO: Enforce this!

        except Exception as error:
            print('Error initializing NameAnalysisService: ' + repr(error))
            raise

        # Perform the name analysis - execute analysis using the supplied builder
        # @:return an array of ProcedureResult[]
        analysis = service.execute_analysis()

        # Build the appropriate response for the analysis result
        analysis_response = AnalysisResponse(service, analysis)
        payload = analysis_response.build_response().to_json()

        response = make_response(payload, 200)
        return response
Пример #10
0
    def get():
        name = get_query_param_str('name')
        location = get_query_param_str('location')
        entity_type = get_query_param_str('entity_type_cd')
        request_action = get_query_param_str('request_action_cd')

        service = None

        if not validate_name_request(location, entity_type, request_action):
            return  # TODO: Return invalid response! What is it?

        valid_location = location == ValidLocations.CA_BC.value
        valid_protected_entity_type = entity_type in BCProtectedNameEntityTypes.list(
        )
        valid_unprotected_entity_type = entity_type in BCUnprotectedNameEntityTypes.list(
        )
        is_protected_action = request_action in [
            AnalysisRequestActions.NEW.value, AnalysisRequestActions.CHG.value,
            AnalysisRequestActions.MVE.value
        ]
        is_unprotected_action = request_action in [
            AnalysisRequestActions.NEW.value
        ]

        try:
            if valid_location and valid_protected_entity_type and is_protected_action:
                # Use ProtectedNameAnalysisService
                service = ProtectedNameAnalysisService()
                builder = NameAnalysisBuilder(service)

            elif valid_location and valid_unprotected_entity_type and is_unprotected_action:
                # Use UnprotectedNameAnalysisService
                service = UnprotectedNameAnalysisService()
                builder = NameAnalysisBuilder(service)

            else:
                raise Exception('Invalid scenario')

            if not service:
                raise ValueError('Invalid service provided')
            if not builder:
                raise ValueError('Invalid builder provided')

            # Register and initialize the builder
            service.use_builder(builder)  # Required step! TODO: Enforce this!
            service.set_entity_type(
                entity_type)  # Required step! TODO: Enforce this!
            service.set_name(name)  # Required step! TODO: Enforce this!

        except Exception as err:
            print('Error initializing BcNameAnalysis service: ' +
                  repr(err.with_traceback(None)))
            raise

        # Perform the name analysis - execute analysis using the supplied builder
        # @:return an array of ProcedureResult[]
        analysis = service.execute_analysis()

        # Build the appropriate response for the analysis result
        analysis_response = AnalysisResponse(service, analysis)
        payload = analysis_response.build_response().to_json()

        response = make_response(payload, 200)
        return response
    def _set_designations_by_entity_type_user(self):
        syn_svc = self.synonym_service
        entity_type = self.entity_type

        entity_type_code = None
        if BCProtectedNameEntityTypes.has_value(entity_type):
            entity_type_code = BCProtectedNameEntityTypes(entity_type)
        # elif BCUnprotectedNameEntityTypes.has_value(entity_type) and BCUnprotectedNameEntityTypes(entity_type):
        #     entity_type_code = BCUnprotectedNameEntityTypes(entity_type)
        # elif XproUnprotectedNameEntityTypes.has_value(entity_type) and XproUnprotectedNameEntityTypes(entity_type):
        #     entity_type_code = XproUnprotectedNameEntityTypes(entity_type)
        else:
            raise Exception(
                f"Could not set designations. Entity type '{entity_type}' was not found in BC entity types!")

        self._eng_designation_any_list_correct = syn_svc.get_designations(entity_type_code=entity_type_code.value,
                                                                          position_code=DesignationPositionCodes.ANY.value,
                                                                          lang=LanguageCodes.ENG.value).data
        # Commented out because business seems unsure if we will need to put it in again
        # add ccc / Community Contribution Company to BC limited/benefit companies
        # entities_allowed_ccc_in_name = [ EntityTypes.CORPORATION.value, EntityTypes.BENEFIT_COMPANY.value ]
        # if entity_type in entities_allowed_ccc_in_name:
        #     self._eng_designation_any_list_correct += ['ccc', 'community contribution company']

        # add association to coops / societies
        entities_allowed_association_in_name = [ EntityTypes.COOPERATIVE.value, EntityTypes.SOCIETY.value ]
        if entity_type in entities_allowed_association_in_name:
            self._eng_designation_any_list_correct += ['association']

        self._eng_designation_end_list_correct = syn_svc.get_designations(entity_type_code=entity_type_code.value,
                                                                          position_code=DesignationPositionCodes.END.value,
                                                                          lang=LanguageCodes.ENG.value).data

        self._fr_designation_any_list_correct = syn_svc.get_designations(entity_type_code=entity_type_code.value,
                                                                         position_code=DesignationPositionCodes.ANY.value,
                                                                         lang=LanguageCodes.FR.value).data

        self._fr_designation_end_list_correct = syn_svc.get_designations(entity_type_code=entity_type_code.value,
                                                                         position_code=DesignationPositionCodes.END.value,
                                                                         lang=LanguageCodes.FR.value).data

        self._eng_designation_all_list_correct = self._eng_designation_any_list_correct + self._eng_designation_end_list_correct
        self._eng_designation_all_list_correct.sort(key=len, reverse=True)

        self._fr_designation_all_list_correct = self._fr_designation_any_list_correct + self._fr_designation_end_list_correct
        self._fr_designation_all_list_correct.sort(key=len, reverse=True)

        self._designation_any_list_correct = self._eng_designation_any_list_correct + self._fr_designation_any_list_correct
        self._designation_any_list_correct.sort(key=len, reverse=True)

        self._designation_end_list_correct = self._eng_designation_end_list_correct + self._fr_designation_end_list_correct
        self._designation_end_list_correct.sort(key=len, reverse=True)
        # for entity types returning incorrect data clear the lists
        clear_designation_reqs_for_these = [
            EntityTypes.FINANCIAL_INSTITUTION.value,
            EntityTypes.PARISH.value,
            EntityTypes.PRIVATE_ACT.value
        ]
        if entity_type in clear_designation_reqs_for_these:
            self._eng_designation_all_list_correct = []
            self._fr_designation_all_list_correct = []
            self._designation_any_list_correct = []
            self._designation_end_list_correct = []
Пример #12
0
    MAX_ROW_LIMIT = os.getenv('MAX_ROWS', '100')

    try:

        sql = "select r.id, r.nr_num, r.state_cd, n.choice, n.name, n.decision_text, n.conflict1_num, n.conflict1, n.conflict1_num " \
              "from requests r, names n " \
              "where r.id = n.nr_id and n.state = " + '\'' + State.REJECTED + '\'' + " and " \
              "r.state_cd in(" + '\'' + State.APPROVED + '\',' + '\'' + State.CONDITIONAL + '\',' + '\'' + State.REJECTED + '\') and '\
              "r.request_type_cd = " + '\'' + EntityTypes.CORPORATION.value + '\'' + " and " \
              "r.nr_num not in (select nr_num from uat_results) " \
              "order by r.submitted_date " \
              "limit " + MAX_ROW_LIMIT

        requests = db.session.execute(sql)
        for request_id, nr_num, state_cd, choice, name, decision_text, conflict1_num, conflict1, conflict_num1 in requests:
            if entry_params['entity_type'] in BCProtectedNameEntityTypes.list():
                start_time_name = datetime.utcnow()
                service = ProtectedNameAnalysisService()
                builder = NameAnalysisBuilder(service)

                service.use_builder(builder)
                service.set_entity_type(entry_params.get('entity_type'))
                service.set_name(name)

                analysis = service.execute_analysis()

                # Build the appropriate response for the analysis result
                analysis_response = AnalysisResponse(service, analysis)
                payload = analysis_response.build_response()
                end_time_name = datetime.utcnow()