
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_DELETE_JOB_NAME; 033import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CODE_SYSTEM_DELETE_STEP_NAME; 034import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CODE_SYSTEM_VERSION_DELETE_STEP_NAME; 035import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CONCEPTS_DELETE_STEP_NAME; 036import static ca.uhn.fhir.jpa.batch.config.BatchConstants.TERM_CONCEPT_RELATIONS_DELETE_STEP_NAME; 037 038/** 039 * Configuration for batch job which deletes a TermCodeSystem and its related TermCodeSystemVersion(s), 040 * TermConceptProperty(es), TermConceptDesignation(s), and TermConceptParentChildLink(s) 041 **/ 042@Configuration 043public class TermCodeSystemDeleteJobConfig extends BaseTermCodeSystemDeleteJobConfig { 044 045 046 @Bean(name = TERM_CODE_SYSTEM_DELETE_JOB_NAME) 047 @Lazy 048 public Job termCodeSystemDeleteJob() { 049 return myJobBuilderFactory.get(TERM_CODE_SYSTEM_DELETE_JOB_NAME) 050 .validator(termCodeSystemDeleteJobParameterValidator()) 051 .start(termConceptRelationsDeleteStep()) 052 .next(termConceptsDeleteStep()) 053 .next(termCodeSystemVersionDeleteStep()) 054 .next(termCodeSystemDeleteStep()) 055 .build(); 056 } 057 058 @Bean 059 public JobParametersValidator termCodeSystemDeleteJobParameterValidator() { 060 return new TermCodeSystemDeleteJobParameterValidator(); 061 } 062 063 /** 064 * This steps deletes TermConceptParentChildLink(s), TermConceptProperty(es) and TermConceptDesignation(s) 065 * related to TermConcept(s) of the TermCodeSystemVersion being deleted 066 */ 067 @Bean(name = TERM_CONCEPT_RELATIONS_DELETE_STEP_NAME) 068 public Step termConceptRelationsDeleteStep() { 069 return myStepBuilderFactory.get(TERM_CONCEPT_RELATIONS_DELETE_STEP_NAME) 070 .<Long, Long>chunk(1) 071 .reader(batchTermCodeSystemVersionDeleteReader()) 072 .writer(batchConceptRelationsDeleteWriter()) 073 .build(); 074 } 075 076 /** 077 * This steps deletes TermConcept(s) of the TermCodeSystemVersion being deleted 078 */ 079 @Bean(name = TERM_CONCEPTS_DELETE_STEP_NAME) 080 public Step termConceptsDeleteStep() { 081 DefaultTransactionAttribute attribute = new DefaultTransactionAttribute(); 082 attribute.setTimeout(TERM_CONCEPT_DELETE_TIMEOUT); 083 084 return myStepBuilderFactory.get(TERM_CONCEPTS_DELETE_STEP_NAME) 085 .<Long, Long>chunk(1) 086 .reader(batchTermCodeSystemVersionDeleteReader()) 087 .writer(batchTermConceptsDeleteWriter()) 088 .transactionAttribute(attribute) 089 .build(); 090 } 091 092 /** 093 * This steps deletes the TermCodeSystemVersion 094 */ 095 @Bean(name = TERM_CODE_SYSTEM_VERSION_DELETE_STEP_NAME) 096 public Step termCodeSystemVersionDeleteStep() { 097 return myStepBuilderFactory.get(TERM_CODE_SYSTEM_VERSION_DELETE_STEP_NAME) 098 .<Long, Long>chunk(1) 099 .reader(batchTermCodeSystemVersionDeleteReader()) 100 .writer(batchTermCodeSystemVersionDeleteWriter()) 101 .build(); 102 } 103 104 @Bean(name = TERM_CODE_SYSTEM_DELETE_STEP_NAME) 105 public Step termCodeSystemDeleteStep() { 106 return myStepBuilderFactory.get(TERM_CODE_SYSTEM_DELETE_STEP_NAME) 107 .tasklet(termCodeSystemDeleteTasklet()) 108 .build(); 109 } 110 111 @Bean 112 @StepScope 113 public BatchTermCodeSystemVersionDeleteReader batchTermCodeSystemVersionDeleteReader() { 114 return new BatchTermCodeSystemVersionDeleteReader(); 115 } 116 117 @Bean 118 public TermCodeSystemDeleteTasklet termCodeSystemDeleteTasklet() { 119 return new TermCodeSystemDeleteTasklet(); 120 } 121 122}