Skip to content

Commit 2fdc132

Browse files
committed
RAP-128 Contruct full tables if there is no Full files in the package
1 parent a8226a6 commit 2fdc132

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,4 +760,29 @@ public long getBinaryArchiveSchemaLastModifiedDate(String schemaName) {
760760
return 0L;
761761
}
762762
}
763+
764+
public void insertIntoProspectiveFullTables(String schemaName) throws SQLException {
765+
try (Connection connection = rvfDynamicDataSource.getConnection(schemaName)) {
766+
DatabaseMetaData md = connection.getMetaData();
767+
ResultSet rs = md.getTables(null, null, "%", null);
768+
Set<String> snapShotTables = new HashSet<>();
769+
while (rs.next()) {
770+
if (rs.getString(3).endsWith("_s")) {
771+
snapShotTables.add(rs.getString(3));
772+
}
773+
}
774+
insertIntoProspectiveFullTables(snapShotTables, connection);
775+
}
776+
}
777+
778+
private void insertIntoProspectiveFullTables(Set<String> snapShotTables, Connection connection) throws SQLException {
779+
for (String snapshotTable: snapShotTables) {
780+
String fullTable = snapshotTable.replaceAll("_s$","_f");
781+
StringBuilder insertSQL = new StringBuilder();
782+
insertSQL.append(INSERT_INTO).append(fullTable).append(SQL_SELECT).append(snapshotTable);
783+
try (PreparedStatement ps = connection.prepareStatement(insertSQL.toString())) {
784+
ps.execute();
785+
}
786+
}
787+
}
763788
}

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ public void loadProspectiveVersion(ValidationStatusReport statusReport, MysqlExe
109109
//load prospective version alone now as used to combine with dependency for extension testing
110110
uploadReleaseFileIntoDB(prospectiveVersion, null, validationConfig.getLocalProspectiveFile(), rf2FilesLoaded);
111111
}
112-
112+
final String schemaName = prospectiveVersion.startsWith(RVF_DB_PREFIX) ? prospectiveVersion : RVF_DB_PREFIX + prospectiveVersion;
113113
if (!validationConfig.isRf2DeltaOnly() && !checkDeltaFilesExist(validationConfig.getLocalProspectiveFile())) {
114-
final String schemaName = prospectiveVersion.startsWith(RVF_DB_PREFIX) ? prospectiveVersion : RVF_DB_PREFIX + prospectiveVersion;
115114
releaseDataManager.insertIntoProspectiveDeltaTables(schemaName, executionConfig);
116115
}
116+
if (!checkFullFilesExist(validationConfig.getLocalProspectiveFile())) {
117+
releaseDataManager.insertIntoProspectiveFullTables(schemaName);
118+
}
117119

118120
statusReport.setTotalRF2FilesLoaded(rf2FilesLoaded.size());
119121
Collections.sort(rf2FilesLoaded);
@@ -141,6 +143,24 @@ private boolean checkDeltaFilesExist(File localProspectiveFile) throws ReleaseIm
141143
return false;
142144
}
143145

146+
private boolean checkFullFilesExist(File localProspectiveFile) throws ReleaseImportException {
147+
try {
148+
String deltaDirectoryPath = new ReleaseImporter().unzipRelease(new FileInputStream(localProspectiveFile), ReleaseImporter.ImportType.FULL).getAbsolutePath();
149+
try(Stream<Path> pathStream = Files.find(new File(deltaDirectoryPath).toPath(), 50,
150+
(path, basicFileAttributes) -> path.toFile().getName().matches("x?(sct|rel)2_Concept_[^_]*Full_.*.txt"))) {
151+
if (pathStream.findFirst().isPresent()) {
152+
return true;
153+
}
154+
}
155+
} catch (IOException | IllegalStateException e) {
156+
if (e.getMessage().contains("No Full files found")) {
157+
return false;
158+
}
159+
throw new ReleaseImportException("Error while searching input files.", e);
160+
}
161+
return false;
162+
}
163+
144164
private String loadRelease(String releaseVersion) throws IOException, BusinessServiceException {
145165
if (releaseVersion != null && releaseVersion.endsWith(ZIP_FILE_EXTENSION)) {
146166
String schemaName = RvfReleaseDbSchemaNameGenerator.generate(releaseVersion);
@@ -431,9 +451,9 @@ public void combineCurrentExtensionWithDependencySnapshot(MysqlExecutionConfig e
431451
if (isExtension(validationConfig)) {
432452
try {
433453
releaseDataManager.copyTableData(extensionVersion, combinedVersion, DELTA_TABLE, null);
434-
releaseDataManager.copyTableData(extensionVersion, combinedVersion,FULL_TABLE, null);
454+
releaseDataManager.copyTableData(extensionVersion, combinedVersion, FULL_TABLE, null);
435455
releaseDataManager.copyTableData(executionConfig.getExtensionDependencyVersion(),
436-
extensionVersion, combinedVersion,SNAPSHOT_TABLE, null);
456+
extensionVersion, combinedVersion, SNAPSHOT_TABLE, null);
437457
resourceLoader.loadResourceData(combinedSchema);
438458
} catch (Exception e) {
439459
String errorMsg = e.getMessage();

0 commit comments

Comments
 (0)