finos / finos/cdm-object-builder

Make model to be loaded generic

Open
#106 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
13
Forks
5
Avg merge
1h 53m
Merged PRs (30d)
2

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 loadModels() throws MalformedURLException {
XtextResourceSet resourceSet = resourceSetProvider.get();
List 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 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 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.

Contributor guide

Open the contributing guide

Research direction

Start with TypescriptObjectBuilderModelGenerator.loadModels and trace its call path to see how the model name could be supplied during the build. Then inspect ClassPathUtils.findRosettaFilePaths and findPathsFromClassPath, using the existing model/cdm/rosetta path as the baseline. Done means model loading is no longer tied to the Common Domain Model and an unavailable model name is handled explicitly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.