001/*-
002 * #%L
003 * HAPI FHIR JPA Server - Batch2 Task Processor
004 * %%
005 * Copyright (C) 2014 - 2024 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.batch2.api;
021
022import ca.uhn.fhir.model.api.IModelJson;
023import ca.uhn.fhir.rest.api.server.RequestDetails;
024import jakarta.annotation.Nonnull;
025import jakarta.annotation.Nullable;
026
027import java.util.List;
028
029/**
030 * This interface can be used to validate the parameters
031 * object supplied to start a job instance.
032 * <p>
033 * Batch2 automatically uses
034 * <a href="https://www.baeldung.com/javax-validation">JSR 380</a>
035 * to validate the parameters object supplied to job start requests.
036 * <p>
037 * However not all validation is possible using that API. For example
038 * environment-specific rules, or rules about relationships between
039 * multiple parameters.
040 *
041 * @see ca.uhn.fhir.batch2.model.JobDefinition.Builder#setParametersValidator(IJobParametersValidator)
042 */
043public interface IJobParametersValidator<T extends IModelJson> {
044
045        /**
046         * Validate the given job parameters.
047         *
048         * @param theRequestDetails The request details associated with the start request
049         * @param theParameters     The parameters object to validate
050         * @return Any strings returned by this method are treated as validation failures and returned to the client initiating the job. Return <code>null</code> or an empty list to indicate that no validation failures occurred.
051         */
052        @Nullable
053        List<String> validate(RequestDetails theRequestDetails, @Nonnull T theParameters);
054}