Skip to content

Conversation

@Hajarel-moukh
Copy link
Contributor

This PR adds missing and filter variables in metadata by merging Lunatic data into the existing DDI metadata. Tests were added to ensure these variables are correctly included in the resulting metadata model.

@Hajarel-moukh Hajarel-moukh requested review from alexisszmundy and loichenninger and removed request for loichenninger December 16, 2025 08:24
@Hajarel-moukh Hajarel-moukh self-assigned this Dec 16, 2025
metadataModel.getVariables().putVariable(new Variable(varName, group, varType));
}

public static void addMissingAndFilterVariables(MetadataModel metadataModel, String lunaticFilePath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remplace lunaticFilePath par un InputSteam lunaticInputStream ici

public static void addMissingAndFilterVariables(MetadataModel metadataModel, String lunaticFilePath) {
VariablesMap variablesMap = metadataModel.getVariables();

try (InputStream lunaticStream = new FileInputStream(lunaticFilePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remplace l'ouverture de 2 FileInputStreams par JsonNode rootNode = JsonReader.read(lunaticInputStream);

try (InputStream lunaticStream = new FileInputStream(lunaticFilePath);
InputStream lunaticStream2 = new FileInputStream(lunaticFilePath)) {

List<String> missingVars = LunaticReader.getMissingVariablesFromLunatic(lunaticStream);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMissing/getFilter vont prendre en entrée le JsonNode rootNode

MetadataModel metadataModel =
getMetadataFromDDI(ddiUrlString, ddiInputStream);

if (metadataModel != null && lunaticFilePath != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if lunaticInputStream != null

public static MetadataModel getMetadataFromDDIAndLunatic(
String ddiUrlString,
InputStream ddiInputStream,
String lunaticFilePath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lunaticInputStream en entrée

* @param lunaticFile Path to a lunatic questionnaire file.
* @return A List of String.
*/
public static List<String> getMissingVariablesFromLunatic(InputStream lunaticFile) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remplace InputStream lunaticFile par un JsonNode rootNode

* @param lunaticFile Path to a lunatic questionnaire file.
* @return A List of String.
*/
public static List<String> getFilterResultFromLunatic(InputStream lunaticFile) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil, JsonNode en paramètre

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci pour les commentaires, je viens de push toutes les modifications

group = metadataModel.getVariables().getQuestionGridGroup(correspondingVariableName);
} else {
group = metadataModel.getGroup(metadataModel.getGroupNames().getFirst());
log.warn(String.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for logging avoid format, use log.warn( {}, var) instead.
And concat the two logs

variablesNode.forEach(variableNode -> variables.add(variableNode.get("name").asText()));
return variables.stream()
.filter(varToRead -> varToRead.endsWith(MISSING_SUFFIX) || varsEno.contains(varToRead)).toList();
JsonNode variablesNode = rootNode.get("variables");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the VARIABLES constant

}
}
return variables.stream()
.filter(var -> var.startsWith(Constants.FILTER_RESULT_PREFIX))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename "var" to avoird restricted identifiers

List<String> missingVars = LunaticReader.getMissingVariablesFromLunatic(rootNode);
List<String> filterVars = LunaticReader.getFilterResultFromLunatic(rootNode);

for (String var : missingVars) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid "var", maybe missingVar here

}
}

for (String var : filterVars) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid "var"

metadataModel.getVariables().putVariable(new Variable(varName, group, varType));
}

public static void addMissingAndFilterVariables(MetadataModel metadataModel, InputStream lunaticInputStream) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you only use lunatic here. Maybe this method should be in the lunatic reader

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or make it private

) throws MetadataParserException {

MetadataModel metadataModel =
getMetadataFromDDI(ddiUrlString, ddiInputStream);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DDIReader.getMetadataFromDDI
I prefer to show where is the method, what do you think about this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i agree

@Hajarel-moukh
Copy link
Contributor Author

Thank you for all your comments, i have applied all the modifications

@Hajarel-moukh Hajarel-moukh merged commit 19c2c0f into main Dec 17, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants