001package ca.uhn.fhir.jpa.term.job;
002
003/*
004 * #%L
005 * HAPI FHIR JPA Server
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 org.springframework.batch.core.Job;
024import org.springframework.batch.core.JobParametersValidator;
025import org.springframework.batch.core.Step;
026import org.springframework.batch.core.configuration.annotation.StepScope;
027import org.springframework.context.annotation.Bean;
028import org.springframework.context.annotation.Configuration;
029import org.springframework.context.annotation.Lazy;
030import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
031
032import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CODE_SYSTEM_UNIQUE_VERSION_DELETE_STEP_NAME;
033import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CODE_SYSTEM_VERSION_DELETE_JOB_NAME;
034import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CONCEPTS_UNIQUE_VERSION_DELETE_STEP_NAME;
035import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CONCEPT_RELATIONS_UNIQUE_VERSION_DELETE_STEP_NAME;
036
037/**
038 * Configuration for batch job which deletes a specific TermCodeSystemVersion and its related,
039 * TermConceptProperty(es), TermConceptDesignation(s), and TermConceptParentChildLink(s)
040 **/
041@Configuration
042public class TermCodeSystemVersionDeleteJobConfig extends BaseTermCodeSystemDeleteJobConfig {
043
044
045        @Bean(name = TERM_CODE_SYSTEM_VERSION_DELETE_JOB_NAME)
046        @Lazy
047        public Job termCodeSystemVersionDeleteJob() {
048                return myJobBuilderFactory.get(TERM_CODE_SYSTEM_VERSION_DELETE_JOB_NAME)
049                        .validator(termCodeSystemVersionDeleteJobParameterValidator())
050                        .start(termConceptRelationsUniqueVersionDeleteStep())
051                        .next(termConceptsUniqueVersionDeleteStep())
052                        .next(termCodeSystemUniqueVersionDeleteStep())
053                        .build();
054        }
055
056
057        @Bean
058        public JobParametersValidator termCodeSystemVersionDeleteJobParameterValidator() {
059                return new TermCodeSystemVersionDeleteJobParameterValidator();
060        }
061
062
063        @Bean(name = TERM_CONCEPT_RELATIONS_UNIQUE_VERSION_DELETE_STEP_NAME)
064        public Step termConceptRelationsUniqueVersionDeleteStep() {
065                return myStepBuilderFactory.get(TERM_CONCEPT_RELATIONS_UNIQUE_VERSION_DELETE_STEP_NAME)
066                        .<Long, Long>chunk(1)
067                        .reader(batchTermCodeSystemUniqueVersionDeleteReader())
068                        .writer(batchConceptRelationsDeleteWriter())
069                        .build();
070        }
071
072
073        @Bean(name = TERM_CONCEPTS_UNIQUE_VERSION_DELETE_STEP_NAME)
074        public Step termConceptsUniqueVersionDeleteStep() {
075                DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
076                attribute.setTimeout(TERM_CONCEPT_DELETE_TIMEOUT);
077
078                return myStepBuilderFactory.get(TERM_CONCEPTS_UNIQUE_VERSION_DELETE_STEP_NAME)
079                        .<Long, Long>chunk(1)
080                        .reader(batchTermCodeSystemUniqueVersionDeleteReader())
081                        .writer(batchTermConceptsDeleteWriter())
082                        .transactionAttribute(attribute)
083                        .build();
084        }
085
086
087        @Bean(name = TERM_CODE_SYSTEM_UNIQUE_VERSION_DELETE_STEP_NAME)
088        public Step termCodeSystemUniqueVersionDeleteStep() {
089                return myStepBuilderFactory.get(TERM_CODE_SYSTEM_UNIQUE_VERSION_DELETE_STEP_NAME)
090                        .<Long, Long>chunk(1)
091                        .reader(batchTermCodeSystemUniqueVersionDeleteReader())
092                        .writer(batchTermCodeSystemVersionDeleteWriter())
093                        .build();
094        }
095
096
097        @Bean
098        @StepScope
099        public BatchTermCodeSystemUniqueVersionDeleteReader batchTermCodeSystemUniqueVersionDeleteReader() {
100                return new BatchTermCodeSystemUniqueVersionDeleteReader();
101        }
102
103
104
105}