Skip to content

Commit 9297e60

Browse files
committed
VAL-405 Switch to use the new method "getDependencies" from MSC when finding the dependent package
1 parent 858a9c4 commit 9297e60

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

src/main/java/org/ihtsdo/rvf/core/service/ValidationVersionLoader.java

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import org.ihtsdo.rvf.core.service.util.RvfReleaseDbSchemaNameGenerator;
1818
import org.slf4j.Logger;
1919
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.*;
2321
import org.springframework.beans.factory.annotation.Autowired;
2422
import org.springframework.beans.factory.annotation.Value;
2523
import org.springframework.core.io.ResourceLoader;
@@ -360,36 +358,33 @@ private InputStream downloadProspectiveManifestFile(ValidationRunConfig validati
360358
}
361359

362360
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());
387376
}
388377
}
378+
} else {
379+
logger.info("No dependency found from Module Storage Coordinator");
389380
}
390381

391382
if (StringUtils.hasLength(validationConfig.getPreviousRelease())) {
392383
// 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+
393388
ModuleMetadata moduleMetadata = allModuleMetadata.stream().filter(item -> item.getFilename().equals(validationConfig.getPreviousRelease())).findFirst().orElse(null);
394389
if (moduleMetadata != null) {
395390
File previousFile = File.createTempFile(validationConfig.getRunId() + "_PREVIOUS_RF2", ZIP_FILE_EXTENSION);

0 commit comments

Comments
 (0)