Skip to content

Commit

Permalink
Defer Validator.init until first use
Browse files Browse the repository at this point in the history
  • Loading branch information
smailliwcs committed Feb 22, 2024
1 parent cff2344 commit 1f6a6cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
5 changes: 0 additions & 5 deletions api/src/main/java/com/lantanagroup/link/api/ApiInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.lantanagroup.link.db.TenantService;
import com.lantanagroup.link.db.model.tenant.FhirQuery;
import com.lantanagroup.link.db.model.tenant.Tenant;
import com.lantanagroup.link.validation.Validator;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r4.model.CapabilityStatement;
import org.hl7.fhir.r4.model.Parameters;
Expand All @@ -32,9 +31,6 @@ public class ApiInit {
@Autowired
private SharedService sharedService;

@Autowired
private Validator validator;

private boolean checkPrerequisites() {
logger.info("Checking that API prerequisite services are available. maxRetry: {}, retryWait: {}", config.getMaxRetry(), config.getRetryWait());

Expand Down Expand Up @@ -122,7 +118,6 @@ public void init() {
this.sharedService.initDatabase();
}

this.validator.init();
List<Tenant> tenants = this.sharedService.getTenantConfigs();

for (Tenant tenant : tenants) {
Expand Down
34 changes: 25 additions & 9 deletions core/src/main/java/com/lantanagroup/link/validation/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class Validator {
@Setter
private ApiConfig apiConfig;

private volatile boolean initialized;

public Validator(SharedService sharedService, ApiConfig apiConfig) {
this.sharedService = sharedService;
this.apiConfig = apiConfig;
Expand Down Expand Up @@ -121,17 +123,29 @@ private void writeConformanceResourcesToFile() {
}

public void init() {
this.loadPackages();
this.loadTerminology();
if (this.initialized) {
return;
}

synchronized (this) {
if (this.initialized) {
return;
}

// When needed for debugging
//this.writeConformanceResourcesToFile();
this.loadPackages();
this.loadTerminology();

this.validator = FhirContextProvider.getFhirContext().newValidator();
this.validator.setExecutorService(Executors.newWorkStealingPool());
IValidatorModule module = new FhirInstanceValidator(this.getValidationSupportChain());
this.validator.registerValidatorModule(module);
this.validator.setConcurrentBundleValidation(true);
// When needed for debugging
//this.writeConformanceResourcesToFile();

this.validator = FhirContextProvider.getFhirContext().newValidator();
this.validator.setExecutorService(Executors.newWorkStealingPool());
IValidatorModule module = new FhirInstanceValidator(this.getValidationSupportChain());
this.validator.registerValidatorModule(module);
this.validator.setConcurrentBundleValidation(true);

this.initialized = true;
}
}

/**
Expand Down Expand Up @@ -273,6 +287,8 @@ private void validateResource(Resource resource, OperationOutcome outcome, Opera
}

public OperationOutcome validate(Resource resource, OperationOutcome.IssueSeverity severity) {
this.init();

logger.debug("Validating {}", resource.getResourceType().toString().toLowerCase());

OperationOutcome outcome = new OperationOutcome();
Expand Down

0 comments on commit 1f6a6cc

Please sign in to comment.