"""Neo4j utility functions.""" from flask import request from sound_recordings import config from sound_recordings.constants.profiles import PROFILE_TYPES from sound_recordings.utils.features import is_generate_optimized_size_fields_enabled def by(profile=None, is_for_has_fingerprint_rule=False): """Build value for createdBy and lastModifiedBy attributes. Args: profile (tuple): Profile information in the format (profile_type, profile_id) is_for_has_fingerprint_rule (bool): Flag indicating if the value is for HasFingerprintRule relationship, which requires special handling when optimized size fields FF is enabled Returns: str: Formatted value for createdBy and lastModifiedBy attributes """ if is_for_has_fingerprint_rule: orchard_identity_id = request.headers.get('Orchard-Identity-Id') are_optimized_size_fields_enabled = is_generate_optimized_size_fields_enabled( orchard_identity_id ) if are_optimized_size_fields_enabled: if profile: (profile_type, profile_id) = profile profile_type_id = PROFILE_TYPES.get(profile_type, '0') return f'{profile_id}_{profile_type_id}' return '' # Default behavior if not for HasFingerprintRule or optimized size FF not enabled endpoint_id = request.method.lower() + request.path.replace('/', '-') result = f'{config.SERVICE_NAME}/{endpoint_id}' if profile: (profile_type, profile_id) = profile result = result + f'/{profile_id}/{profile_type}' return result