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.model;
021
022import ca.uhn.fhir.model.api.IModelJson;
023import ca.uhn.fhir.util.JsonUtil;
024import com.fasterxml.jackson.annotation.JsonProperty;
025
026public class JobInstanceStartRequest implements IModelJson {
027
028        @JsonProperty(value = "jobDefinitionId")
029        private String myJobDefinitionId;
030
031        @JsonProperty(value = "parameters")
032        private String myParameters;
033
034        /**
035         * If true, batch2 will check the existing jobs and
036         * if one with the same parameters that is already running
037         * (ie, not failed, cancelled, etc)
038         * it will return that id
039         */
040        @JsonProperty(value = "useCache")
041        private boolean myUseCache;
042
043        /**
044         * Constructor
045         */
046        public JobInstanceStartRequest() {
047                super();
048        }
049
050        /**
051         * Copy constructor
052         */
053        public JobInstanceStartRequest(JobInstanceStartRequest theJobInstance) {
054                super();
055                setJobDefinitionId(theJobInstance.getJobDefinitionId());
056                setParameters(theJobInstance.getParameters());
057        }
058
059        /**
060         * Constructor
061         *
062         * @since 6.8.0
063         */
064        public JobInstanceStartRequest(String theJobDefinitionId, IModelJson theParameters) {
065                setJobDefinitionId(theJobDefinitionId);
066                setParameters(theParameters);
067        }
068
069        public String getJobDefinitionId() {
070                return myJobDefinitionId;
071        }
072
073        public void setJobDefinitionId(String theJobDefinitionId) {
074                myJobDefinitionId = theJobDefinitionId;
075        }
076
077        public String getParameters() {
078                return myParameters;
079        }
080
081        public void setParameters(String theParameters) {
082                myParameters = theParameters;
083        }
084
085        /**
086         * Sets the parameters for the job.
087         * Please note that these need to be backward compatible as we do not have a way to migrate them to a different structure at the moment.
088         * @param theParameters the parameters
089         * @return the current instance.
090         */
091        public JobInstanceStartRequest setParameters(IModelJson theParameters) {
092                myParameters = JsonUtil.serializeWithSensitiveData(theParameters);
093                return this;
094        }
095
096        public <T extends IModelJson> T getParameters(Class<T> theType) {
097                if (myParameters == null) {
098                        return null;
099                }
100                return JsonUtil.deserialize(myParameters, theType);
101        }
102
103        public boolean isUseCache() {
104                return myUseCache;
105        }
106
107        public void setUseCache(boolean theUseCache) {
108                myUseCache = theUseCache;
109        }
110
111        @Override
112        public String toString() {
113                return "JobInstanceStartRequest{" + "myJobDefinitionId='"
114                                + myJobDefinitionId + '\'' + ", myParameters='"
115                                + myParameters + '\'' + ", myUseCache="
116                                + myUseCache + '}';
117        }
118}