Skip to content

Conversation

@Hajarel-moukh
Copy link
Contributor

This PR adds the processing logic for collected variables (LIENS) in Genesis.

@Hajarel-moukh Hajarel-moukh requested review from alexisszmundy and loichenninger and removed request for loichenninger January 12, 2026 09:38
// idem: on garde convertOneVar(entry, String, ...)
convertOneVar(collectedVariable, getValueString(value), variablesMap, 1, dest);
}
if (value != null && !(value instanceof List<?>)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: value instanceof List<?> is already checked in the if just before, hence it will always be false

suggestion: extract both ifs into a method and add return to the first if, then remove the !value instance of check

Copy link
Contributor

Choose a reason for hiding this comment

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

@alicela would it be better if we extract into a method ?

variablesMap,
dstSurveyUnitModel
);
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

note: Sonar doesn't like more than one continue in a method

Copy link
Contributor

Choose a reason for hiding this comment

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

I propose to a extract a method like this, that excludes all "continue" and is easier to read

private static void processCollectedVariable(
Map.Entry<String, Object> entry,
String stateKey,
VariablesMap variablesMap,
SurveyUnitModel dstSurveyUnitModel,
CollectedVariables dest
) {
if (Constants.LIENS.equals(entry.getKey())) {
handleLiensCollectedVariable(entry, DataState.valueOf(stateKey), variablesMap, dstSurveyUnitModel);
return;
}

Map<String, Object> states = JsonUtils.asMap(entry.getValue());
if (states == null) return;

Object value = states.get(stateKey);
if (value == null) return;

if (value instanceof List<?> list) {
    convertListVar(list, entry, variablesMap, dest);
} else {
    convertOneVar(entry, getValueString(value), variablesMap, 1, dest);
}

}

.getVariable(Constants.LIEN + 1)
.getGroupName();

for (int i = 0; i < individus.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Not a big fan of "i" or "k" as variable names as they mean nothing and we can get lost as we go deeper in the code

}
private static VariableModel buildLienVariable(
List<String> liensIndividu,
int k,
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: change "k" variable name to have a meaning behind it

public static final int VOLUMETRY_FILE_EXPIRATION_DAYS = 30;

public static final int MAX_LINKS_ALLOWED = 21;
public static final String LIEN = "LIEN_";
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename PAIRWISE_PREFIX


public static final int MAX_LINKS_ALLOWED = 21;
public static final String LIEN = "LIEN_";
public static final String LIENS = "LIENS";
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename PAIRWISES

variablesMap,
dstSurveyUnitModel
);
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose to a extract a method like this, that excludes all "continue" and is easier to read

private static void processCollectedVariable(
Map.Entry<String, Object> entry,
String stateKey,
VariablesMap variablesMap,
SurveyUnitModel dstSurveyUnitModel,
CollectedVariables dest
) {
if (Constants.LIENS.equals(entry.getKey())) {
handleLiensCollectedVariable(entry, DataState.valueOf(stateKey), variablesMap, dstSurveyUnitModel);
return;
}

Map<String, Object> states = JsonUtils.asMap(entry.getValue());
if (states == null) return;

Object value = states.get(stateKey);
if (value == null) return;

if (value instanceof List<?> list) {
    convertListVar(list, entry, variablesMap, dest);
} else {
    convertOneVar(entry, getValueString(value), variablesMap, 1, dest);
}

}

dstSurveyUnitModel
);
continue;
}
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 this method can be extract as in LunaticJsonRawDataService

}

@SuppressWarnings("unchecked")
static void handleLiensCollectedVariable(
Copy link
Contributor

Choose a reason for hiding this comment

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

change Liens into pairwise

) {
Object value = getValueForState(collectedVariable, dataState.toString());

if (!(value instanceof List<?> individus)
Copy link
Contributor

Choose a reason for hiding this comment

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

add a boolean method to explain why you do these test


for (int linkIndex = 1; linkIndex <= Constants.MAX_LINKS_ALLOWED; linkIndex++) {
dstSurveyUnitModel.getCollectedVariables().add(
buildLienVariable(individualLinks, linkIndex, individualIndex, groupName)
Copy link
Contributor

Choose a reason for hiding this comment

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

here is "lien" and "link".

@Hajarel-moukh Hajarel-moukh merged commit 1391c59 into main Jan 13, 2026
7 of 8 checks passed
@alicela alicela deleted the fixLinkVariables branch January 14, 2026 13:52
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