|
17 | 17 | import org.ihtsdo.rvf.core.service.util.RvfReleaseDbSchemaNameGenerator; |
18 | 18 | import org.slf4j.Logger; |
19 | 19 | import org.slf4j.LoggerFactory; |
20 | | -import org.snomed.module.storage.ModuleMetadata; |
21 | | -import org.snomed.module.storage.ModuleStorageCoordinator; |
22 | | -import org.snomed.module.storage.ModuleStorageCoordinatorException; |
| 20 | +import org.snomed.module.storage.*; |
23 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
24 | 22 | import org.springframework.beans.factory.annotation.Value; |
25 | 23 | import org.springframework.core.io.ResourceLoader; |
@@ -360,36 +358,33 @@ private InputStream downloadProspectiveManifestFile(ValidationRunConfig validati |
360 | 358 | } |
361 | 359 |
|
362 | 360 | public void downloadPreviousReleaseAndDependencyFiles(ValidationRunConfig validationConfig) throws IOException, ModuleStorageCoordinatorException.OperationFailedException, ModuleStorageCoordinatorException.ResourceNotFoundException, ModuleStorageCoordinatorException.InvalidArgumentsException { |
363 | | - // Get all releases from MSC |
364 | | - Map<String, List<ModuleMetadata>> allReleasesMap = moduleStorageCoordinator.getAllReleases(); |
365 | | - List<ModuleMetadata> allModuleMetadata = new ArrayList<>(); |
366 | | - allReleasesMap.values().forEach(allModuleMetadata::addAll); |
367 | | - |
368 | | - if (StringUtils.hasLength(validationConfig.getExtensionDependency())) { |
369 | | - ModuleMetadata moduleMetadata = allModuleMetadata.stream().filter(item -> item.getFilename().equals(validationConfig.getExtensionDependency())).findFirst().orElse(null); |
370 | | - if (moduleMetadata != null) { |
371 | | - File tempFile = File.createTempFile(validationConfig.getRunId() + "_DEPENDENCY_RF2", ZIP_FILE_EXTENSION); |
372 | | - List<ModuleMetadata> moduleMetadataList = moduleStorageCoordinator.getRelease(moduleMetadata.getCodeSystemShortName(), moduleMetadata.getIdentifyingModuleId(), moduleMetadata.getEffectiveTimeString(), true, false); |
373 | | - File dependencyFile = moduleMetadataList.get(0).getFile(); |
374 | | - Files.copy(dependencyFile.toPath(), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
375 | | - validationConfig.setLocalDependencyReleaseFile(tempFile); |
376 | | - Files.delete(dependencyFile.toPath()); |
377 | | - } else { |
378 | | - InputStream dependencyStream = releaseSourceManager.readResourceStreamOrNullIfNotExists(validationConfig.getExtensionDependency()); |
379 | | - if (dependencyStream != null) { |
380 | | - File dependencyFile = File.createTempFile(validationConfig.getRunId() + "_DEPENDENCY_RF2", ZIP_FILE_EXTENSION); |
381 | | - try (OutputStream out = new FileOutputStream(dependencyFile)) { |
382 | | - IOUtils.copy(dependencyStream, out); |
383 | | - } finally { |
384 | | - IOUtils.closeQuietly(dependencyStream, null); |
385 | | - } |
386 | | - validationConfig.setLocalDependencyReleaseFile(dependencyFile); |
| 361 | + RF2Service rf2Service = new RF2Service(); |
| 362 | + Set<RF2Row> mdrsRows = rf2Service.getMDRS(validationConfig.getLocalProspectiveFile(), validationConfig.isRf2DeltaOnly()); |
| 363 | + Set<ModuleMetadata> dependencies = moduleStorageCoordinator.getDependencies(mdrsRows, true); |
| 364 | + if (!dependencies.isEmpty()) { |
| 365 | + for (ModuleMetadata dependency : dependencies) { |
| 366 | + File dependencyFile = dependency.getFile(); |
| 367 | + // At the moment, RVF only allows one dependency. So that the first one will be picked up |
| 368 | + if (validationConfig.getLocalDependencyReleaseFile() == null) { |
| 369 | + File tempFile = File.createTempFile(validationConfig.getRunId() + "_DEPENDENCY_RF2", ZIP_FILE_EXTENSION); |
| 370 | + Files.copy(dependencyFile.toPath(), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 371 | + validationConfig.setLocalDependencyReleaseFile(tempFile); |
| 372 | + validationConfig.setExtensionDependency(dependency.getFilename()); |
| 373 | + logger.info("Dependency {} found from Module Storage Coordinator", dependency.getFilename()); |
| 374 | + } else { |
| 375 | + logger.info("Other dependency {} found from Module Storage Coordinator", dependency.getFilename()); |
387 | 376 | } |
388 | 377 | } |
| 378 | + } else { |
| 379 | + logger.info("No dependency found from Module Storage Coordinator"); |
389 | 380 | } |
390 | 381 |
|
391 | 382 | if (StringUtils.hasLength(validationConfig.getPreviousRelease())) { |
392 | 383 | // Get all releases from MSC |
| 384 | + Map<String, List<ModuleMetadata>> allReleasesMap = moduleStorageCoordinator.getAllReleases(); |
| 385 | + List<ModuleMetadata> allModuleMetadata = new ArrayList<>(); |
| 386 | + allReleasesMap.values().forEach(allModuleMetadata::addAll); |
| 387 | + |
393 | 388 | ModuleMetadata moduleMetadata = allModuleMetadata.stream().filter(item -> item.getFilename().equals(validationConfig.getPreviousRelease())).findFirst().orElse(null); |
394 | 389 | if (moduleMetadata != null) { |
395 | 390 | File previousFile = File.createTempFile(validationConfig.getRunId() + "_PREVIOUS_RF2", ZIP_FILE_EXTENSION); |
|
0 commit comments