def create(cls, pid_value=None, object_uuid=None, data=None, object_type=None, **kwargs): if not pid_value and not current_app.config.get( "FEATURE_FLAG_ENABLE_BAI_CREATION", False): return pid_value = pid_value or get_first_value_for_schema( get_value(data, "ids", []), "INSPIRE BAI") new_pid = pid_value or cls.generate_bai(data) pid_from_db = cls.query_pid_value(new_pid) if not pid_from_db: provider_object = super().create( pid_value=new_pid, object_type=object_type, object_uuid=object_uuid, status=PIDStatus.REGISTERED, **kwargs, ) elif pid_from_db.object_uuid != object_uuid: raise PIDAlreadyExistsError(pid_value=pid_value, pid_type="bai") else: # Correct pid already assigned to this record provider_object = super().get(pid_value=pid_value) return provider_object
def create(cls, pid_value=None, object_uuid=None, data=None, object_type=None, **kwargs): if not pid_value and not current_app.config.get( "FEATURE_FLAG_ENABLE_BAI_CREATION", False): return pid_value = pid_value or get_first_value_for_schema( get_value(data, "ids", []), "INSPIRE BAI") retry_count = (current_app.config.get("PIDSTORE_BAI_MAX_RETRY_COUNT", 5) if not pid_value else 1) for _ in range(retry_count): last_exception = None new_pid = pid_value or cls.generate_bai(data) pid_from_db = cls.query_pid_value(new_pid) if not pid_from_db: try: provider_object = super().create( pid_value=new_pid, object_type=object_type, object_uuid=object_uuid, status=PIDStatus.REGISTERED, **kwargs, ) # Pid created successfully. break except IntegrityError as e: last_exception = e elif pid_from_db.object_uuid != object_uuid: last_exception = PIDAlreadyExistsError(pid_value=pid_value, pid_type="bai") else: provider_object = super().get(pid_value=pid_value) break # Correct pid already assigned to this record time.sleep(current_app.config.get("PIDSTORE_BAI_RETRY_DELAY", 5)) if last_exception: raise last_exception return provider_object
def create(cls, pid_value=None, object_uuid=None, data=None, object_type=None, **kwargs): pid_value = pid_value or get_first_value_for_schema( get_value(data, "ids", []), "INSPIRE BAI") if not pid_value: pid_value = cls.generate_bai(data) pid_from_db = cls.query_pid_value(pid_value) if not pid_from_db: pid_from_db = super().create( pid_value=pid_value, object_type=object_type, object_uuid=object_uuid, status=PIDStatus.REGISTERED, **kwargs, ) else: if pid_from_db.object_uuid != object_uuid: raise PIDAlreadyExistsError(pid_value=pid_value, pid_type="bai") return pid_from_db
def get_bai(data): return get_first_value_for_schema(data.get("ids", []), "INSPIRE BAI") or missing
def get_ror(data): return get_first_value_for_schema( data.get("external_system_identifiers", []), "ROR" )
def get_grid(data): return get_first_value_for_schema( data.get("external_system_identifiers", []), "GRID" )