-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Object Builder to become more generic in loading data model
Description of Problem:
The CDM Object Builder is currently closely tied to the loading and navigating of the Common Data Model. If made more generic, this object builder would allow for a developer forking the repository to run a build with a different data model, perhaps an extension of the CDM or one of similar structure available within the Rosetta file path structure.
Potential Solutions:
The build currently relies on parameter arguments passed into the main java class that generates the Object Builder to load the related data model as specified in dependencies. However, it has some custom code that could be made more generic to allow for the build to accommodate a different data model to be loaded.
Impacted Java class: TypescriptObjectBuilderModelGenerator
Method: loadModels is currently using the ClassPathUtils method findRosettaFilePaths which is currently tied to the Common Domain Model structure.
AS-IS
private List<RosettaModel> loadModels() throws MalformedURLException {
XtextResourceSet resourceSet = resourceSetProvider.get();
List<Path> rosettaFilePaths = ClassPathUtils.findRosettaFilePaths();
for (Path rosettaFilePath : rosettaFilePaths) {
resourceSet.getResource(URI.createURI(rosettaFilePath.toUri().toURL()
.toString(), true), true);
}
return resourceSet.getResources().stream()
.map(Resource::getContents)
.flatMap(Collection::stream)
.map(RosettaModel.class::cast)
.collect(Collectors.toList());
}
The model is currently hardcoded in the ClassPathUtils class findRosettaFilePaths method:
public static List<Path> findRosettaFilePaths() {
return findPathsFromClassPath(ImmutableList.of("model", "cdm/rosetta"), ".*\\.rosetta", Optional.empty(), ClassPathUtils.class.getClassLoader());
}
If passing a parameter in the method with the chosen data model name (from those available in the path structure), this could be controlled during build to switch to a different model.
TO-BE
In loadModels method:
findRosettaFilePaths(modelName);
In findRosettaFilePaths - it would take the modelName as a String parameter, something like this:
public static List<Path> findRosettaFilePaths(String modelName) {
return ClassPathUtils.findPathsFromClassPath(ImmutableList.of("model", modelName + "/rosetta"), ".*\\.rosetta", Optional.empty(), ClassPathUtils.class.getClassLoader());
}
Exception Handling
A modelName that cannot be found on the file paths would need to be handled.