001package ca.uhn.fhir.jpa.bulk.export.job;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2021 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.rest.api.server.bulk.BulkDataExportOptions;
024import ca.uhn.fhir.rest.api.Constants;
025import org.springframework.batch.core.JobParametersBuilder;
026
027import java.util.Date;
028import java.util.List;
029import java.util.Set;
030import java.util.stream.Collectors;
031
032/**
033 * This builder is a helper so you don't have to go lookup what job parameters are required for a bulk export job.
034 *
035 */
036public class BulkExportJobParametersBuilder extends JobParametersBuilder {
037
038        public BulkExportJobParametersBuilder setResourceTypes(List<String> resourceTypes) {
039                String resourceTypesString = resourceTypes.stream().collect(Collectors.joining(","));
040                this.addString("resourceTypes", resourceTypesString);
041                return this;
042        }
043
044        public BulkExportJobParametersBuilder setSince(Date theSince) {
045                this.addDate("since", theSince);
046                return this;
047        }
048
049        public BulkExportJobParametersBuilder setOutputFormat(String theOutputFormat) {
050                //TODO eventually we will support more types.
051                theOutputFormat = Constants.CT_FHIR_NDJSON;
052                this.addString("outputFormat", theOutputFormat);
053                return this;
054        }
055
056        public BulkExportJobParametersBuilder setFilters(Set<String> theFilters) {
057                this.addString("filters", theFilters.stream().collect(Collectors.joining(",")));
058                return this;
059        }
060
061        public BulkExportJobParametersBuilder setJobUUID(String theJobUUID) {
062                this.addString("jobUUID", theJobUUID);
063                return this;
064        }
065        public BulkExportJobParametersBuilder setReadChunkSize(Long theReadChunkSize) {
066                this.addLong("readChunkSize", theReadChunkSize);
067                return this;
068        }
069        public BulkExportJobParametersBuilder setExportStyle(BulkDataExportOptions.ExportStyle theExportStyle) {
070                this.addString("exportStyle", theExportStyle.name());
071                return this;
072        }
073}