Skip to content

Commit

Permalink
Merge pull request #200 from InseeFr/devGenesisLunaticOnlyDdiFix
Browse files Browse the repository at this point in the history
Genesis stops looking for DDI if lunatic only
  • Loading branch information
alexisszmundy authored Dec 13, 2024
2 parents 9218874 + 1bb04ec commit 5f13085
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void init(String idCampaign) throws KraftwerkException {
inDirectory = controlInputSequenceGenesis.getInDirectory(idCampaign);
//First we check the modes present in database for the given questionnaire
//We build userInputs for the given questionnaire
userInputs = new UserInputsGenesis(controlInputSequenceGenesis.isHasConfigFile(), inDirectory, client.getModes(idCampaign), fileUtilsInterface);
userInputs = new UserInputsGenesis(controlInputSequenceGenesis.isHasConfigFile(), inDirectory,
client.getModes(idCampaign), fileUtilsInterface, withDDI);
if (!userInputs.getModes().isEmpty()) {
try {
metadataModels = withDDI ? MetadataUtilsGenesis.getMetadata(userInputs.getModeInputsMap(), fileUtilsInterface): MetadataUtilsGenesis.getMetadataFromLunatic(userInputs.getModeInputsMap(), fileUtilsInterface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ public class UserInputsGenesis extends UserInputs{

private final List<Mode> modes;

public UserInputsGenesis(boolean hasConfigFile, Path inputDirectory, List<Mode> modes, FileUtilsInterface fileUtilsInterface) throws KraftwerkException {
public UserInputsGenesis(boolean hasConfigFile, Path inputDirectory, List<Mode> modes, FileUtilsInterface fileUtilsInterface, boolean withDDI) throws KraftwerkException {
super(inputDirectory, fileUtilsInterface);
this.hasConfigFile = hasConfigFile;
this.modes=modes;
computeInputs();
computeInputs(withDDI);
}

private void computeInputs() throws KraftwerkException {
private void computeInputs(boolean withDDI) throws KraftwerkException {
UserInputsFile userInputsFile;
if(hasConfigFile){
userInputsFile = new UserInputsFile(inputDirectory.resolve(Constants.USER_INPUT_FILE), inputDirectory, fileUtilsInterface);
modeInputsMap = userInputsFile.getModeInputsMap();
}else{
for (Mode mode : modes) {
ModeInputs modeInputs = getModeInputs(mode);
ModeInputs modeInputs = getModeInputs(mode, withDDI);
modeInputsMap.put(mode.name(), modeInputs);
}
}
Expand All @@ -47,10 +47,13 @@ private void computeInputs() throws KraftwerkException {
* @param mode mode to get inputs from
* @return a ModeInputs object
*/
private ModeInputs getModeInputs(Mode mode) throws KraftwerkException {
private ModeInputs getModeInputs(Mode mode, boolean withDDI) throws KraftwerkException {
ModeInputs modeInputs = new ModeInputs();
modeInputs.setDdiUrl(findDDIFile(inputDirectory.resolve(mode.name())).toString());
modeInputs.setLunaticFile(findLunaticFile(inputDirectory.resolve(mode.name())));
if (withDDI) {
modeInputs.setDdiUrl(findDDIFile(inputDirectory.resolve(mode.name())).toString());
}
modeInputs.setLunaticFile(findLunaticFile(inputDirectory.resolve(mode.name())));

modeInputs.setDataMode(mode.name());
if (mode == Mode.WEB || mode == Mode.TEL || mode == Mode.F2F) {
modeInputs.setDataFormat("LUNATIC_XML");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void testReadValidUserInput_singleMode() throws KraftwerkException {
List<Mode> modes = new ArrayList<>();
modes.add(Mode.F2F);

UserInputsGenesis userInputsGenesis = new UserInputsGenesis(false, inputSamplesDirectory.resolve("Valid"), modes, new FileSystemImpl(TestConstants.TEST_RESOURCES_DIRECTORY));
UserInputsGenesis userInputsGenesis = new UserInputsGenesis(false, inputSamplesDirectory.resolve("Valid"), modes, new FileSystemImpl(TestConstants.TEST_RESOURCES_DIRECTORY), true);
//
ModeInputs modeInputs = userInputsGenesis.getModeInputs("F2F");
assertNotNull(modeInputs.getDdiUrl());
Expand All @@ -36,4 +36,23 @@ void testReadValidUserInput_singleMode() throws KraftwerkException {
assertNull(userInputsGenesis.getVtlTransformationsFile());
assertNull(userInputsGenesis.getVtlInformationLevelsFile());
}

@Test
void testReadValidUserInput_singleMode_lunatic_only() throws KraftwerkException {
List<Mode> modes = new ArrayList<>();
modes.add(Mode.F2F);

UserInputsGenesis userInputsGenesis = new UserInputsGenesis(false, inputSamplesDirectory.resolve("Valid"), modes, new FileSystemImpl(TestConstants.TEST_RESOURCES_DIRECTORY), false);
//
ModeInputs modeInputs = userInputsGenesis.getModeInputs("F2F");
assertNull(modeInputs.getDdiUrl());
assertNotNull(modeInputs.getLunaticFile());
assertEquals(DataFormat.LUNATIC_XML, modeInputs.getDataFormat());
assertNull(modeInputs.getParadataFolder());
assertNull(modeInputs.getModeVtlFile());
//
assertNull(userInputsGenesis.getVtlReconciliationFile());
assertNull(userInputsGenesis.getVtlTransformationsFile());
assertNull(userInputsGenesis.getVtlInformationLevelsFile());
}
}

0 comments on commit 5f13085

Please sign in to comment.