001package ca.uhn.fhir.jpa.bulk.imprt.api;
002
003/*-
004 * #%L
005 * HAPI FHIR Storage api
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobFileJson;
024import ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobJson;
025import ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum;
026
027import javax.annotation.Nonnull;
028import java.util.List;
029
030public interface IBulkDataImportSvc {
031
032        /**
033         * Create a new job in {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#STAGING STAGING} state (meaning it won't yet be worked on and can be added to)
034         */
035        String createNewJob(BulkImportJobJson theJobDescription, @Nonnull List<BulkImportJobFileJson> theInitialFiles);
036
037        /**
038         * Add more files to a job in {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#STAGING STAGING} state
039         *
040         * @param theJobId The job ID
041         * @param theFiles The files to add to the job
042         */
043        void addFilesToJob(String theJobId, List<BulkImportJobFileJson> theFiles);
044
045        /**
046         * Move a job from {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#STAGING STAGING}
047         * state to {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#READY READY}
048         * state, meaning that is is a candidate to be picked up for processing
049         *
050         * @param theJobId The job ID
051         */
052        void markJobAsReadyForActivation(String theJobId);
053
054        /**
055         * This method is intended to be called from the job scheduler, and will begin execution on
056         * the next job in status {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#READY READY}
057         *
058         * @return Returns {@literal true} if a job was activated
059         */
060        boolean activateNextReadyJob();
061
062        /**
063         * Updates the job status for the given job
064         */
065        void setJobToStatus(String theJobId, BulkImportJobStatusEnum theStatus);
066
067        /**
068         * Updates the job status for the given job
069         */
070        void setJobToStatus(String theJobId, BulkImportJobStatusEnum theStatus, String theStatusMessage);
071
072        /**
073         * Gets the number of files available for a given Job ID
074         *
075         * @param theJobId The job ID
076         * @return The file count
077         */
078        BulkImportJobJson fetchJob(String theJobId);
079
080        /**
081         * Fetch a given file by job ID
082         *
083         * @param theJobId     The job ID
084         * @param theFileIndex The index of the file within the job
085         * @return The file
086         */
087        BulkImportJobFileJson fetchFile(String theJobId, int theFileIndex);
088
089        /**
090         * Delete all input files associated with a particular job
091         */
092        void deleteJobFiles(String theJobId);
093
094        /**
095         * Fetch just the file description for the given file
096         */
097        String getFileDescription(String theJobId, int theFileIndex);
098}