-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SO-2902: Add multi-language RF2 import support. #194
Changes from 5 commits
36ca49a
45be2bf
03faa6a
fdbfab1
6724fcf
5d570af
8f6aa50
360660f
0d002c4
bbdfc2a
5f24b78
d6d7eec
ce4198f
cc853fb
e733067
f750f87
53eb20d
4cc9f5f
2ed7940
924ef02
a71ce1d
797d4d5
c1b1cd1
0534a6b
e10c0bc
4888bbc
bfbbde1
222e30a
9f25745
e409c61
a24bb80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,11 @@ | |
import static com.b2international.snowowl.snomed.api.rest.CodeSystemVersionRestRequests.createVersion; | ||
import static com.b2international.snowowl.snomed.api.rest.CodeSystemVersionRestRequests.getVersion; | ||
import static com.b2international.snowowl.snomed.api.rest.SnomedComponentRestRequests.getComponent; | ||
import static com.b2international.snowowl.snomed.api.rest.SnomedImportRestRequests.*; | ||
import static com.b2international.snowowl.snomed.api.rest.SnomedImportRestRequests.createImport; | ||
import static com.b2international.snowowl.snomed.api.rest.SnomedImportRestRequests.deleteImport; | ||
import static com.b2international.snowowl.snomed.api.rest.SnomedImportRestRequests.getImport; | ||
import static com.b2international.snowowl.snomed.api.rest.SnomedImportRestRequests.uploadImportFile; | ||
import static com.b2international.snowowl.snomed.api.rest.SnomedImportRestRequests.waitForImportJob; | ||
import static com.b2international.snowowl.test.commons.rest.RestExtensions.lastPathSegment; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
|
@@ -203,5 +207,52 @@ public void import11ExtensionConceptWithVersion() { | |
getComponent(branchPath, SnomedComponentType.CONCEPT, "555231000005107").statusCode(200); | ||
getVersion("SNOMEDCT-NE", "2015-02-05").statusCode(200); | ||
} | ||
|
||
|
||
@Test | ||
public void importMoreThanOneLanguageCodeDescription() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. importDescriptionsWithMultipleLanguageCodes or importDescriptionsWithDifferentLanguageCodes |
||
final String enDescriptionId = "41320138114"; | ||
final String svDescriptionId = "24688171113"; | ||
final String conceptIdODescription = "301795004"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary extra line |
||
getComponent(branchPath, SnomedComponentType.DESCRIPTION, enDescriptionId).statusCode(404); | ||
getComponent(branchPath, SnomedComponentType.DESCRIPTION, svDescriptionId).statusCode(404); | ||
getComponent(branchPath, SnomedComponentType.CONCEPT, conceptIdODescription).statusCode(404); | ||
|
||
final Map<?, ?> importConfiguration = ImmutableMap.builder() | ||
.put("type", Rf2ReleaseType.DELTA.name()) | ||
.put("branchPath", branchPath.getPath()) | ||
.put("createVersions", false) | ||
.build(); | ||
|
||
importArchive("SnomedCT_Release_INT_20150131_new_concept_for_languageCode.zip"); | ||
getComponent(branchPath, SnomedComponentType.CONCEPT, conceptIdODescription).statusCode(200); | ||
|
||
importArchive("SnomedCT_Release_INT_20150201_new_description_with2_language_code.zip", importConfiguration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description in sct2_Description_Delta-sv_INT_20150201 has a language code 'en', please fix that! |
||
getComponent(branchPath, SnomedComponentType.DESCRIPTION, enDescriptionId).statusCode(200); | ||
getComponent(branchPath, SnomedComponentType.DESCRIPTION, svDescriptionId).statusCode(200); | ||
} | ||
|
||
@Test | ||
public void importFromMoreThanOneLanguageRefset() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are not importing more than one language refset! It should be rather something like: |
||
final String enLanguageRefsetConceptId = "34d07985-48a0-41e7-b6ec-b28e6b00adfc"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should decide to either merge the two test cases together (since the RF2 files are the same and you always import both descriptions and language refset members as well) or split the RF2 files and test language refset and description import separately. |
||
final String svLanguageRefsetConceptId = "34d07985-48a0-41e7-b6ec-b28e6b00adfb"; | ||
final String conceptIdOfDescriptions = "301795004"; | ||
|
||
getComponent(branchPath, SnomedComponentType.MEMBER, enLanguageRefsetConceptId).statusCode(404); | ||
getComponent(branchPath, SnomedComponentType.MEMBER, svLanguageRefsetConceptId).statusCode(404); | ||
getComponent(branchPath, SnomedComponentType.CONCEPT, conceptIdOfDescriptions).statusCode(404); | ||
|
||
final Map<?, ?> importConfiguration = ImmutableMap.builder() | ||
.put("type", Rf2ReleaseType.DELTA.name()) | ||
.put("branchPath", branchPath.getPath()) | ||
.put("createVersions", false) | ||
.build(); | ||
importArchive("SnomedCT_Release_INT_20150131_new_concept_for_languageCode.zip"); | ||
getComponent(branchPath, SnomedComponentType.CONCEPT, conceptIdOfDescriptions).statusCode(200); | ||
|
||
importArchive("SnomedCT_Release_INT_20150201_new_description_with2_language_code.zip", importConfiguration); | ||
getComponent(branchPath, SnomedComponentType.MEMBER, enLanguageRefsetConceptId).statusCode(200); | ||
getComponent(branchPath, SnomedComponentType.MEMBER, svLanguageRefsetConceptId).statusCode(200); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,13 +107,20 @@ public void execute(final CommandInterpreter interpreter) { | |
// Setting up configuration only with the required fields | ||
config.setSourceKind(ImportSourceKind.ARCHIVE); | ||
config.setArchiveFile(archiveFile); | ||
config.setDescriptionsFile(new File(archiveFileSet.getFileName(zipFiles, ReleaseComponentType.DESCRIPTION, contentSubType))); | ||
config.setLanguageRefSetFile(languageRefSetFile); | ||
final Collection<String> allFileName = archiveFileSet.getAllFileName(zipFiles, ReleaseComponentType.DESCRIPTION, contentSubType); | ||
final Collection<File> descriptionFileNames = Collections.emptySet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the initialization of this set. You create an immutable set and then try to add elements to it?? |
||
for (String fileName : allFileName) { | ||
descriptionFileNames.add(new File(fileName)); | ||
} | ||
config.setDescriptionsFiles(descriptionFileNames); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are in a for loop here, why do you add all the description files to the config in each iteration? |
||
config.addLanguageRefSetFiles(languageRefSetFile); | ||
|
||
final SnomedRefSetNameCollector provider = new SnomedRefSetNameCollector(config, new NullProgressMonitor(), ""); | ||
|
||
try { | ||
provider.parse(config.toURL(config.getLanguageRefSetFile())); | ||
for (File langFile : config.getLanguageRefSetFiles()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are already iterating through the available language refset files in the outer for loop, I don't think this is necessary here. |
||
provider.parse(config.toURL(langFile)); | ||
} | ||
} catch (final IOException e) { | ||
interpreter.println(e); | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
import com.b2international.snowowl.snomed.importer.net4j.SnomedImportResult; | ||
import com.b2international.snowowl.snomed.importer.net4j.SnomedValidationDefect; | ||
import com.b2international.snowowl.snomed.importer.rf2.util.ImportUtil; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.io.Files; | ||
|
||
/** | ||
|
@@ -92,12 +93,12 @@ protected void indicating(final ExtendedDataInputStream in, final OMMonitor moni | |
receivedFilesDirectory.deleteOnExit(); | ||
|
||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setConceptsFile(f); }}, monitor.fork()); | ||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setDescriptionsFile(f); }}, monitor.fork()); | ||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setDescriptionsFiles(ImmutableList.of(f)); }}, monitor.fork()); | ||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setTextDefinitionFile(f); }}, monitor.fork()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not going to work like this, see how refset URLs or excluded refset ids are sent over the wire. |
||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setRelationshipsFile(f); }}, monitor.fork()); | ||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setStatedRelationshipsFile(f); }}, monitor.fork()); | ||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setDescriptionType(f); }}, monitor.fork()); | ||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setLanguageRefSetFile(f); }}, monitor.fork()); | ||
readComponent(in, importConfiguration, receivedFilesDirectory, new FileCallback() { @Override public void setFile(final File f) { importConfiguration.setLanguageRefSetFiles(ImmutableList.of(f)); }}, monitor.fork()); | ||
|
||
final int refSetUrlCount = in.readInt(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,9 +67,10 @@ public static Set<URL> collectUrlFromRelease(final ImportConfiguration configura | |
// Add reference set URLs from the first wizard page in case they're not present | ||
try { | ||
|
||
if (null != configuration.getLanguageRefSetFile()) { | ||
collectedUrlSet.add(configuration.toURL(configuration.getLanguageRefSetFile())); | ||
for (File langFiles : configuration.getLanguageRefSetFiles()) { | ||
collectedUrlSet.add(configuration.toURL(langFiles)); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line |
||
|
||
if (null != configuration.getDescriptionType()) { | ||
collectedUrlSet.add(configuration.toURL(configuration.getDescriptionType())); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ private void parseFilesAndTerminology(URL refSetURL) { | |
} | ||
|
||
// Step 2: Get descriptions for reference set IDs using the description file (if present) | ||
if (configuration.getDescriptionsFile() != null) { | ||
if (!configuration.getDescriptionsFiles().isEmpty()) { | ||
readDescriptionFile(unlabeledRefSetIds, convertedMonitor.newChild(1)); | ||
} | ||
|
||
|
@@ -173,11 +173,15 @@ public void handleRecord(int recordCount, List<String> record) { | |
subMonitor.setWorkRemaining(LARGE_WORK_REMAINING); | ||
} | ||
}; | ||
|
||
URL url = configuration.toURL(configuration.getDescriptionsFile()); | ||
descriptionReader = new InputStreamReader(url.openStream()); | ||
CsvParser parser = new CsvParser(descriptionReader, getFileName(url), CSV_SETTINGS, descriptionParserCallback, DESCRIPTION_FIELD_COUNT); | ||
parser.parse(); | ||
if (!configuration.getDescriptionsFiles().isEmpty()) { | ||
for(File descFile : configuration.getDescriptionsFiles()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing space |
||
URL url = configuration.toURL(descFile); | ||
descriptionReader = new InputStreamReader(url.openStream()); | ||
CsvParser parser = new CsvParser(descriptionReader, getFileName(url), CSV_SETTINGS, descriptionParserCallback, DESCRIPTION_FIELD_COUNT); | ||
parser.parse(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line |
||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,8 +137,10 @@ private void addReleaseFilesForValidating() throws IOException { | |
releaseFileValidators.add(new SnomedConceptValidator(configuration, this)); | ||
} | ||
|
||
if (isValidReleaseFile(configuration.getDescriptionsFile())) { | ||
releaseFileValidators.add(new SnomedDescriptionValidator(configuration, this, configuration.getDescriptionsFile())); | ||
for (File descFile : configuration.getDescriptionsFiles()) { | ||
if (isValidReleaseFile(descFile)) { | ||
releaseFileValidators.add(new SnomedDescriptionValidator(configuration, this, descFile)); | ||
} | ||
} | ||
|
||
if (isValidReleaseFile(configuration.getTextDefinitionFile())) { | ||
|
@@ -162,9 +164,12 @@ private void addRefSetFilesForValidating() throws IOException { | |
|
||
//if the reference file URL set does not contain a language validator yet, specify one | ||
if (!Iterables.any(releaseFileValidators, Predicates.instanceOf(SnomedLanguageRefSetValidator.class))) { | ||
|
||
if (isValidReleaseFile(configuration.getLanguageRefSetFile())) { | ||
releaseFileValidators.add(new SnomedLanguageRefSetValidator(configuration, configuration.toURL(configuration.getLanguageRefSetFile()), this)); | ||
Collection<File> languageRefSetFiles = configuration.getLanguageRefSetFiles(); | ||
for (File langFile : languageRefSetFiles) { | ||
if (isValidReleaseFile(langFile)) { | ||
releaseFileValidators.add(new SnomedLanguageRefSetValidator(configuration, configuration.toURL(langFile), this)); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line |
||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,16 @@ | |
import java.io.File; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get the following exception when I open the import wizard in the client (server-client mode): |
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.Path; | ||
|
||
import com.b2international.commons.ZipURLHandler; | ||
import com.b2international.commons.collections.Collections3; | ||
import com.b2international.snowowl.snomed.common.ContentSubType; | ||
import com.b2international.snowowl.snomed.importer.release.ReleaseFileSet; | ||
import com.google.common.collect.Maps; | ||
|
@@ -58,10 +61,10 @@ public enum ImportSourceKind { | |
private File archiveFile; | ||
private File rootFile; | ||
private File conceptsFile; | ||
private File descriptionsFile; | ||
private Collection<File> descriptionsFiles = Collections.emptySet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the initialization of this collection There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks to this the collection will be initialized still as immutable. |
||
private File relationshipsFile; | ||
private File statedRelationshipsFile; | ||
private File languageRefSetFile; | ||
private Collection<File> languageRefSetFiles = Collections.emptySet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the initialization of this collection |
||
private File descriptionType; | ||
private File textDefinitionFile; | ||
|
||
|
@@ -115,14 +118,14 @@ public void setConceptsFile(final File conceptsFile) { | |
this.conceptsFile = conceptsFile; | ||
} | ||
|
||
public File getDescriptionsFile() { | ||
return descriptionsFile; | ||
public Collection<File> getDescriptionsFiles() { | ||
return descriptionsFiles; | ||
} | ||
|
||
public void setDescriptionsFile(final File descriptionsFile) { | ||
this.descriptionsFile = descriptionsFile; | ||
public void setDescriptionsFiles(final Collection<File> descriptionsFiles) { | ||
this.descriptionsFiles = Collections3.toImmutableSet(descriptionsFiles); | ||
} | ||
|
||
public File getRelationshipsFile() { | ||
return relationshipsFile; | ||
} | ||
|
@@ -131,14 +134,18 @@ public void setRelationshipsFile(final File relationshipsFile) { | |
this.relationshipsFile = relationshipsFile; | ||
} | ||
|
||
public File getLanguageRefSetFile() { | ||
return languageRefSetFile; | ||
public Collection<File> getLanguageRefSetFiles() { | ||
return languageRefSetFiles; | ||
} | ||
|
||
public void setLanguageRefSetFile(final File languageRefSetFile) { | ||
this.languageRefSetFile = languageRefSetFile; | ||
public void setLanguageRefSetFiles(final Collection<File> languageRefSetFiles) { | ||
this.languageRefSetFiles = Collections3.toImmutableSet(languageRefSetFiles); | ||
} | ||
|
||
|
||
public void addLanguageRefSetFiles(final File languageRefSetFile) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I would like to add one language refset file to a collection why the method name addLanguageRefSetFile_s_? |
||
this.languageRefSetFiles.add(languageRefSetFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if I call this add method right after I called setLanguageRefSetFiles(Collection files) ???? |
||
} | ||
|
||
public ImportSourceKind getSourceKind() { | ||
return sourceKind; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.Collection; | ||
|
||
import org.eclipse.net4j.signal.RequestWithMonitoring; | ||
import org.eclipse.net4j.util.io.ExtendedDataInputStream; | ||
|
@@ -69,16 +70,23 @@ protected void requesting(final ExtendedDataOutputStream out, final OMMonitor mo | |
} | ||
|
||
out.writeUTF(importConfiguration.getCodeSystemShortName()); | ||
|
||
final Collection<File> descriptionsFiles = importConfiguration.getDescriptionsFiles(); | ||
final Collection<File> languageRefSetFiles = importConfiguration.getLanguageRefSetFiles(); | ||
monitor.worked(); // 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this here? Have you checked how the monitor's work is calculated here? |
||
|
||
for (File descfile : descriptionsFiles) { | ||
writeComponent(out, descfile, monitor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not going to work like this, see how refset URLs or excluded refset ids are sent over the wire. |
||
} | ||
|
||
for (File langFile : languageRefSetFiles) { | ||
writeComponent(out, langFile, monitor.fork()); // + 7 | ||
} | ||
|
||
writeComponent(out, importConfiguration.getConceptsFile(), monitor.fork()); | ||
writeComponent(out, importConfiguration.getDescriptionsFile(), monitor.fork()); | ||
writeComponent(out, importConfiguration.getTextDefinitionFile(), monitor.fork()); | ||
writeComponent(out, importConfiguration.getRelationshipsFile(), monitor.fork()); | ||
writeComponent(out, importConfiguration.getStatedRelationshipsFile(), monitor.fork()); | ||
writeComponent(out, importConfiguration.getDescriptionType(), monitor.fork()); | ||
writeComponent(out, importConfiguration.getLanguageRefSetFile(), monitor.fork()); // + 7 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That comment is a clue! |
||
|
||
out.writeInt(importConfiguration.getRefSetUrls().size()); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a number to the test method's name like the others above. As you can see there is an annotation at the top: @FixMethodOrder(MethodSorters.NAME_ASCENDING) which enforces method execution order.