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.Date;
029import java.util.List;
030
031public interface IBulkDataImportSvc {
032
033        class JobInfo {
034                private BulkImportJobStatusEnum myStatus;
035                private Date myStatusTime;
036                private String myStatusMessage;
037
038                public Date getStatusTime() {
039                        return myStatusTime;
040                }
041
042                public JobInfo setStatusTime(Date theStatusTime) {
043                        myStatusTime = theStatusTime;
044                        return this;
045                }
046
047                public BulkImportJobStatusEnum getStatus() {
048                        return myStatus;
049                }
050
051                public JobInfo setStatus(BulkImportJobStatusEnum theStatus) {
052                        myStatus = theStatus;
053                        return this;
054                }
055
056                public String getStatusMessage() {
057                        return myStatusMessage;
058                }
059
060                public JobInfo setStatusMessage(String theStatusMessage) {
061                        myStatusMessage = theStatusMessage;
062                        return this;
063                }
064        }
065
066        /**
067         * 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)
068         */
069        String createNewJob(BulkImportJobJson theJobDescription, @Nonnull List<BulkImportJobFileJson> theInitialFiles);
070
071        /**
072         * Add more files to a job in {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#STAGING STAGING} state
073         *
074         * @param theJobId The job ID
075         * @param theFiles The files to add to the job
076         */
077        void addFilesToJob(String theJobId, List<BulkImportJobFileJson> theFiles);
078
079        /**
080         * Move a job from {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#STAGING STAGING}
081         * state to {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#READY READY}
082         * state, meaning that is is a candidate to be picked up for processing
083         *
084         * @param theJobId The job ID
085         */
086        void markJobAsReadyForActivation(String theJobId);
087
088        /**
089         * This method is intended to be called from the job scheduler, and will begin execution on
090         * the next job in status {@link ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum#READY READY}
091         *
092         * @return Returns {@literal true} if a job was activated
093         */
094        boolean activateNextReadyJob();
095
096        /**
097         * Updates the job status for the given job
098         */
099        void setJobToStatus(String theJobId, BulkImportJobStatusEnum theStatus);
100
101        /**
102         * Updates the job status for the given job
103         */
104        void setJobToStatus(String theJobId, BulkImportJobStatusEnum theStatus, String theStatusMessage);
105
106        /**
107         * Gets the job status for the given job.
108         */
109        JobInfo getJobStatus(String theJobId);
110
111        /**
112         * Gets the number of files available for a given Job ID
113         *
114         * @param theJobId The job ID
115         * @return The file count
116         */
117        BulkImportJobJson fetchJob(String theJobId);
118
119        /**
120         * Fetch a given file by job ID
121         *
122         * @param theJobId     The job ID
123         * @param theFileIndex The index of the file within the job
124         * @return The file
125         */
126        BulkImportJobFileJson fetchFile(String theJobId, int theFileIndex);
127
128        /**
129         * Delete all input files associated with a particular job
130         */
131        void deleteJobFiles(String theJobId);
132
133        /**
134         * Fetch just the file description for the given file
135         */
136        String getFileDescription(String theJobId, int theFileIndex);
137}