-
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
Changes from 3 commits
b9035f9
ff64617
50bd610
98d9c16
5dc10e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,12 @@ public class Constants { | |
| public static final String VOLUMETRY_RAW_FILE_SUFFIX = "_RAW_VOLUMETRY"; | ||
| public static final String VOLUMETRY_FILE_DATE_FORMAT = "yyyy_MM_dd"; | ||
| public static final int VOLUMETRY_FILE_EXPIRATION_DAYS = 30; | ||
|
|
||
| public static final int MAX_LINKS_ALLOWED = 21; | ||
| public static final String LIEN = "LIEN_"; | ||
| public static final String LIENS = "LIENS"; | ||
|
||
| public static final String NO_PAIRWISE_VALUE = "99"; | ||
| public static final String SCHEDULE_ARCHIVE_FOLDER_NAME = "genesis_deleted_schedules"; | ||
| public static final String SAME_AXIS_VALUE = "0"; | ||
|
|
||
|
|
||
| // XML sequential reading parameters | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import static fr.insee.genesis.domain.service.rawdata.RawResponseService.handleLiensCollectedVariable; | ||
|
|
||
| @Service | ||
| @Slf4j | ||
|
|
@@ -487,26 +488,28 @@ private static void convertToCollectedVar( | |
| final var dest = dstSurveyUnitModel.getCollectedVariables(); | ||
|
|
||
| for (Map.Entry<String, Object> collectedVariable : collectedMap.entrySet()) { | ||
| // Map for this variable (COLLECTED/EDITED -> value) | ||
| Map<String, Object> states = JsonUtils.asMap(collectedVariable.getValue()); | ||
|
|
||
| // nothing if no state | ||
| if (states == null || states.isEmpty()) { | ||
| String variableName = collectedVariable.getKey(); | ||
|
|
||
| if (Constants.LIENS.equals(variableName)) { | ||
| handleLiensCollectedVariable( | ||
| collectedVariable, | ||
| dataState, | ||
| variablesMap, | ||
| dstSurveyUnitModel | ||
| ); | ||
| continue; | ||
|
||
| } | ||
|
|
||
| if (states.containsKey(stateKey)) { | ||
| Map<String, Object> states = JsonUtils.asMap(collectedVariable.getValue()); | ||
| if (states != null && states.containsKey(stateKey)) { | ||
| Object value = states.get(stateKey); | ||
|
|
||
| // liste ? | ||
| if (value instanceof List<?>) { | ||
| // on garde exactement ta signature existante | ||
| convertListVar(value, collectedVariable, variablesMap, dest); | ||
| } | ||
|
|
||
| // scalaire non null ? | ||
| if (value != null && !(value instanceof List<?>)) { | ||
| // idem: on garde convertOneVar(entry, String, ...) | ||
| convertOneVar(collectedVariable, getValueString(value), variablesMap, 1, dest); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -422,6 +422,7 @@ private void convertRawDataCollectedVariables( | |
| convertToCollectedVar(dstSurveyUnitModel, dataState, variablesMap, collectedMap); | ||
| } | ||
|
|
||
|
|
||
| private static void convertToCollectedVar( | ||
| SurveyUnitModel dstSurveyUnitModel, | ||
| DataState dataState, | ||
|
|
@@ -433,6 +434,17 @@ private static void convertToCollectedVar( | |
|
|
||
| for (Map.Entry<String, Object> collectedVariable : collectedMap.entrySet()) { | ||
| // Map for this variable (COLLECTED/EDITED -> value) | ||
| String variableName = collectedVariable.getKey(); | ||
|
|
||
| if (Constants.LIENS.equals(variableName)) { | ||
| handleLiensCollectedVariable( | ||
| collectedVariable, | ||
| dataState, | ||
| variablesMap, | ||
| dstSurveyUnitModel | ||
| ); | ||
| continue; | ||
| } | ||
|
||
| Map<String, Object> states = JsonUtils.asMap(collectedVariable.getValue()); | ||
|
|
||
| if (states != null && states.containsKey(stateKey)) { | ||
|
|
@@ -519,4 +531,67 @@ private static void convertToExternalVar(SurveyUnitModel dstSurveyUnitModel, Var | |
| public Page<RawResponseModel> findRawResponseDataByCampaignIdAndDate(String campaignId, Instant startDate, Instant endDate, Pageable pageable) { | ||
| return rawResponsePersistencePort.findByCampaignIdAndDate(campaignId,startDate, endDate,pageable); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| static void handleLiensCollectedVariable( | ||
|
||
| Map.Entry<String, Object> collectedVariable, | ||
| DataState dataState, | ||
| VariablesMap variablesMap, | ||
| SurveyUnitModel dstSurveyUnitModel | ||
| ) { | ||
| Object value = getValueForState(collectedVariable, dataState.toString()); | ||
|
|
||
| if (!(value instanceof List<?> individus) | ||
|
||
| || !variablesMap.hasVariable(Constants.LIEN + 1)) { | ||
| return; | ||
| } | ||
|
|
||
| String groupName = variablesMap | ||
| .getVariable(Constants.LIEN + 1) | ||
| .getGroupName(); | ||
|
|
||
| for (int individualIndex = 0; individualIndex < individus.size(); individualIndex++) { | ||
| List<String> individualLinks = (List<String>) individus.get(individualIndex); | ||
|
|
||
| for (int linkIndex = 1; linkIndex <= Constants.MAX_LINKS_ALLOWED; linkIndex++) { | ||
| dstSurveyUnitModel.getCollectedVariables().add( | ||
| buildLienVariable(individualLinks, linkIndex, individualIndex, groupName) | ||
|
||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static VariableModel buildLienVariable( | ||
| List<String> liensIndividu, | ||
| int linkIndex, | ||
| int iteration, | ||
| String groupName | ||
| ) { | ||
| String value = Constants.NO_PAIRWISE_VALUE; | ||
|
|
||
| if (linkIndex <= liensIndividu.size()) { | ||
| String v = liensIndividu.get(linkIndex - 1); | ||
| value = (v == null || v.isBlank()) | ||
| ? Constants.SAME_AXIS_VALUE | ||
| : v; | ||
| } | ||
|
|
||
| return VariableModel.builder() | ||
| .varId(Constants.LIEN + linkIndex) | ||
| .value(value) | ||
| .scope(groupName) | ||
| .iteration(iteration) | ||
| .parentId(groupName) | ||
| .build(); | ||
| } | ||
|
|
||
|
|
||
| private static Object getValueForState( | ||
| Map.Entry<String, Object> collectedVariable, | ||
| String stateKey | ||
| ) { | ||
| Map<String, Object> states = JsonUtils.asMap(collectedVariable.getValue()); | ||
| return states != null ? states.get(stateKey) : null; | ||
| } | ||
|
|
||
| } | ||
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