Skip to content

Make model to be loaded genericΒ #106

@eacunaISDA

Description

@eacunaISDA

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions