use of gov.cms.bfd.model.codebook.extractor.SupportedCodebook in project beneficiary-fhir-data by CMSgov.
the class CodebookVariableReader method buildVariablesMultimappedById.
/**
* @return A multimap of the known Variables. Why a multimap? Because some {@link Variable}s
* appear in more than one {@link Codebook}, and we need to cope with that.
*/
private static Map<String, List<Variable>> buildVariablesMultimappedById() {
/*
* Build a multimap of the known Variables. Why a multimap? Because some
* Variables appear in more than one Codebook, and we need to cope with that.
*/
Map<String, List<Variable>> variablesById = new LinkedHashMap<>();
for (SupportedCodebook supportedCodebook : SupportedCodebook.values()) {
/*
* Find the Codebook XML file on the classpath. Note that this code will be used
* inside an annotation processor, and those have odd context classloaders. So
* instead of the context classloader, we use the classloader used to load one
* of the types from the same JAR.
*/
ClassLoader contextClassLoader = Codebook.class.getClassLoader();
URL supportedCodebookUrl = contextClassLoader.getResource(supportedCodebook.getCodebookXmlResourceName());
if (supportedCodebookUrl == null) {
throw new IllegalStateException(String.format("Unable to locate classpath resource: '%s'." + " JVM Classpath: '%s'. Classloader: '%s'. Classloader URLs: '%s'.", supportedCodebook.getCodebookXmlResourceName(), System.getProperty("java.class.path"), contextClassLoader, contextClassLoader instanceof URLClassLoader ? Arrays.toString(((URLClassLoader) contextClassLoader).getURLs()) : "N/A"));
}
// Unmarshall the Codebook XML and pull its Variables.
try (InputStream codebookXmlStream = supportedCodebookUrl.openStream()) {
Codebook codebook = unmarshallCodebookXml(codebookXmlStream);
for (Variable variable : codebook.getVariables()) {
if (!variablesById.containsKey(variable.getId()))
variablesById.put(variable.getId(), new ArrayList<>());
variablesById.get(variable.getId()).add(variable);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return variablesById;
}
Aggregations