-
Notifications
You must be signed in to change notification settings - Fork 4
Fix link variables #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix link variables #380
Conversation
| // idem: on garde convertOneVar(entry, String, ...) | ||
| convertOneVar(collectedVariable, getValueString(value), variablesMap, 1, dest); | ||
| } | ||
| if (value != null && !(value instanceof List<?>)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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++) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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_"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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".
This PR adds the processing logic for collected variables (LIENS) in Genesis.