
001/*- 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2025 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.interceptor.model; 021 022import jakarta.annotation.Nonnull; 023import jakarta.annotation.Nullable; 024 025public interface IDefaultPartitionSettings { 026 /** 027 * This method returns the default partition ID. Implementers of this interface should overwrite this method to provide 028 * a default partition ID that is different than the default value of null. 029 * 030 * @return the default partition ID 031 */ 032 @Nullable 033 default Integer getDefaultPartitionId() { 034 return null; 035 } 036 037 /** 038 * Test whether <code>theRequestPartitionId</code> is only targeting the default partition where the ID of the default 039 * partition is provided by {@link #getDefaultPartitionId()}. 040 * 041 * @param theRequestPartitionId to perform the evaluation upon. 042 * @return true if the <code>theRequestPartitionId</code> is for the default partition only. 043 */ 044 default boolean isDefaultPartition(@Nonnull RequestPartitionId theRequestPartitionId) { 045 return theRequestPartitionId.isPartition(getDefaultPartitionId()); 046 } 047 048 /** 049 * Test whether <code>theRequestPartitionId</code> has one of its targeted partitions matching the default partition 050 * where the ID of the default partition is provided by {@link #getDefaultPartitionId()}. 051 * 052 * @param theRequestPartitionId to perform the evaluation upon. 053 * @return true if the <code>theRequestPartitionId</code> is targeting the default partition. 054 */ 055 default boolean hasDefaultPartitionId(@Nonnull RequestPartitionId theRequestPartitionId) { 056 return theRequestPartitionId.hasDefaultPartitionId(getDefaultPartitionId()); 057 } 058 059 /** 060 * Returns a RequestPartitionId instance for the default partition. 061 * This is a convenience method that creates a RequestPartitionId using the default partition ID 062 * from {@link #getDefaultPartitionId()}. 063 * 064 * @return a RequestPartitionId for the default partition 065 */ 066 default RequestPartitionId getDefaultRequestPartitionId() { 067 return RequestPartitionId.fromPartitionId(getDefaultPartitionId()); 068 } 069}