From 0839cfcb3d5d98ce305c87f342b77c9b5db4208a Mon Sep 17 00:00:00 2001 From: Simon Demaziere Date: Wed, 18 Dec 2024 10:19:17 +0100 Subject: [PATCH] feat: add new identification configuration and rework identificationState --- .../domain/IdentificationConfiguration.java | 10 +- .../api/dto/statedata/StateDataDto.java | 39 +--- .../dto/surveyunit/SurveyUnitCampaignDto.java | 25 ++- .../service/impl/SurveyUnitServiceImpl.java | 56 +++-- .../api/surveyunit/dto/IdentificationDto.java | 40 +++- .../surveyunit/model/Identification.java | 10 +- .../surveyunit/model/IdentificationState.java | 43 +++- .../model/question/CategoryQuestionValue.java | 2 +- .../HouseholdCompositionQuestionValue.java | 5 + .../IndividualStatusQuestionValue.java | 5 + .../InterviewerCanProcessQuestionValue.java | 5 + .../NumberOfRespondentsQuestionValue.java | 5 + .../PresentInPreviousHomeQuestionValue.java | 5 + .../surveyunit/entity/IdentificationDB.java | 43 +++- .../changelog/560_extend_identification.xml | 16 ++ .../resources/db/dataset/reinit-test-data.sql | 6 +- src/main/resources/db/master.xml | 5 + .../controller/SurveyUnitControllerTest.java | 6 +- .../dto/SurveyUnitDetailDtoTest.java | 5 +- .../model/IdentificationStateTest.java | 198 ++++++++++++++++-- .../SurveyUnitUpdateServiceImplTest.java | 75 +++++-- .../entity/IdentificationDBTest.java | 4 +- .../integration/surveyunit/SurveyUnitIT.java | 15 +- 23 files changed, 469 insertions(+), 154 deletions(-) create mode 100644 src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/HouseholdCompositionQuestionValue.java create mode 100644 src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/IndividualStatusQuestionValue.java create mode 100644 src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/InterviewerCanProcessQuestionValue.java create mode 100644 src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/NumberOfRespondentsQuestionValue.java create mode 100644 src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/PresentInPreviousHomeQuestionValue.java create mode 100644 src/main/resources/db/changelog/560_extend_identification.xml diff --git a/src/main/java/fr/insee/pearljam/api/domain/IdentificationConfiguration.java b/src/main/java/fr/insee/pearljam/api/domain/IdentificationConfiguration.java index bbdbe355..e44779bd 100644 --- a/src/main/java/fr/insee/pearljam/api/domain/IdentificationConfiguration.java +++ b/src/main/java/fr/insee/pearljam/api/domain/IdentificationConfiguration.java @@ -1,7 +1,15 @@ package fr.insee.pearljam.api.domain; public enum IdentificationConfiguration { - IASCO("Identification - Access - Situation - Category - Occupant"), + IASCO("Identification - Access - Situation - Category - Occupant"),// will be replaced by `HOUSEF2F` + HOUSEF2F("Household identification - Face to face"), + HOUSETEL("Household identification - Telephone"), + HOUSETELWSR("Household identification - Telephone - including secondary residence"), + INDF2F("Individual identification - Face to face"), + INDF2FNOR("Individual identification - Face to face - including Non Ordinary residence"), + INDTEL("Individual identification - Telephone"), + INDTELNOR("Individual identification - Telephone - including Non Ordinary residence"), + SRCVREINT("Only for SRCV campaign re-interrogation"), NOIDENT("No identification"); /** diff --git a/src/main/java/fr/insee/pearljam/api/dto/statedata/StateDataDto.java b/src/main/java/fr/insee/pearljam/api/dto/statedata/StateDataDto.java index 1d9104ae..3d50f915 100644 --- a/src/main/java/fr/insee/pearljam/api/dto/statedata/StateDataDto.java +++ b/src/main/java/fr/insee/pearljam/api/dto/statedata/StateDataDto.java @@ -1,36 +1,17 @@ package fr.insee.pearljam.api.dto.statedata; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter public class StateDataDto { private String state; private Long date; private String currentPage; - - public StateDataDto() { - super(); - } - - public StateDataDto(String state, Long date, String currentPage) { - super(); - this.state = state; - this.date = date; - this.currentPage = currentPage; - } - public String getState() { - return state; - } - public void setState(String state) { - this.state = state; - } - public Long getDate() { - return date; - } - public void setDate(Long date) { - this.date = date; - } - public String getCurrentPage() { - return currentPage; - } - public void setCurrentPage(String currentPage) { - this.currentPage = currentPage; - } + } diff --git a/src/main/java/fr/insee/pearljam/api/dto/surveyunit/SurveyUnitCampaignDto.java b/src/main/java/fr/insee/pearljam/api/dto/surveyunit/SurveyUnitCampaignDto.java index e9437bb5..28ea87ae 100644 --- a/src/main/java/fr/insee/pearljam/api/dto/surveyunit/SurveyUnitCampaignDto.java +++ b/src/main/java/fr/insee/pearljam/api/dto/surveyunit/SurveyUnitCampaignDto.java @@ -1,26 +1,21 @@ package fr.insee.pearljam.api.dto.surveyunit; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; - -import fr.insee.pearljam.api.domain.ClosingCauseType; -import fr.insee.pearljam.api.domain.InseeAddress; -import fr.insee.pearljam.api.domain.InseeSampleIdentifier; -import fr.insee.pearljam.api.domain.State; -import fr.insee.pearljam.api.domain.StateType; -import fr.insee.pearljam.api.domain.SurveyUnit; -import fr.insee.pearljam.api.surveyunit.dto.CommentDto; +import fr.insee.pearljam.api.domain.*; import fr.insee.pearljam.api.dto.contactoutcome.ContactOutcomeDto; import fr.insee.pearljam.api.dto.interviewer.InterviewerDto; +import fr.insee.pearljam.api.surveyunit.dto.CommentDto; import fr.insee.pearljam.domain.surveyunit.model.IdentificationState; import lombok.Getter; import lombok.Setter; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + @JsonInclude(JsonInclude.Include.NON_NULL) @Getter @Setter @@ -41,6 +36,9 @@ public class SurveyUnitCampaignDto { private IdentificationState identificationState; private List comments; + @JsonIgnore // used to process identificationState server side, not exposed via API + private IdentificationConfiguration identificationConfiguration; + @JsonIgnoreProperties(value = { "surveyUnitCount" }) private InterviewerDto interviewer; @@ -83,6 +81,7 @@ public SurveyUnitCampaignDto(SurveyUnit su) { } this.state = currentState == null ? null : currentState.getType(); this.campaign = su.getCampaign().getLabel(); + this.identificationConfiguration = su.getCampaign().getIdentificationConfiguration(); this.interviewer = su.getInterviewer() != null ? new InterviewerDto(su.getInterviewer()) : null; this.comments = CommentDto.fromModel(su.getModelComments()); if (su.getContactOucome() != null) { diff --git a/src/main/java/fr/insee/pearljam/api/service/impl/SurveyUnitServiceImpl.java b/src/main/java/fr/insee/pearljam/api/service/impl/SurveyUnitServiceImpl.java index b2be293a..c4568c26 100644 --- a/src/main/java/fr/insee/pearljam/api/service/impl/SurveyUnitServiceImpl.java +++ b/src/main/java/fr/insee/pearljam/api/service/impl/SurveyUnitServiceImpl.java @@ -1,17 +1,20 @@ package fr.insee.pearljam.api.service.impl; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - +import com.fasterxml.jackson.databind.JsonNode; +import fr.insee.pearljam.api.bussinessrules.BussinessRules; +import fr.insee.pearljam.api.constants.Constants; +import fr.insee.pearljam.api.domain.*; +import fr.insee.pearljam.api.dto.contactoutcome.ContactOutcomeDto; +import fr.insee.pearljam.api.dto.organizationunit.OrganizationUnitDto; +import fr.insee.pearljam.api.dto.person.PersonDto; +import fr.insee.pearljam.api.dto.state.StateDto; import fr.insee.pearljam.api.dto.surveyunit.*; +import fr.insee.pearljam.api.exception.BadRequestException; +import fr.insee.pearljam.api.repository.*; +import fr.insee.pearljam.api.service.SurveyUnitService; +import fr.insee.pearljam.api.service.SurveyUnitUpdateService; +import fr.insee.pearljam.api.service.UserService; +import fr.insee.pearljam.api.service.UtilsService; import fr.insee.pearljam.api.surveyunit.dto.SurveyUnitInterviewerResponseDto; import fr.insee.pearljam.api.surveyunit.dto.SurveyUnitUpdateDto; import fr.insee.pearljam.api.surveyunit.dto.SurveyUnitVisibilityDto; @@ -21,32 +24,19 @@ import fr.insee.pearljam.domain.exception.PersonNotFoundException; import fr.insee.pearljam.domain.exception.SurveyUnitNotFoundException; import fr.insee.pearljam.domain.surveyunit.model.IdentificationState; -import fr.insee.pearljam.api.service.SurveyUnitUpdateService; import fr.insee.pearljam.domain.surveyunit.model.SurveyUnitForInterviewer; import jakarta.servlet.http.HttpServletRequest; - -import com.fasterxml.jackson.databind.JsonNode; -import fr.insee.pearljam.api.domain.*; -import fr.insee.pearljam.api.repository.*; - +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import fr.insee.pearljam.api.bussinessrules.BussinessRules; -import fr.insee.pearljam.api.constants.Constants; -import fr.insee.pearljam.api.dto.contactoutcome.ContactOutcomeDto; -import fr.insee.pearljam.api.dto.organizationunit.OrganizationUnitDto; -import fr.insee.pearljam.api.dto.person.PersonDto; -import fr.insee.pearljam.api.dto.state.StateDto; -import fr.insee.pearljam.api.exception.BadRequestException; -import fr.insee.pearljam.api.service.SurveyUnitService; -import fr.insee.pearljam.api.service.UserService; -import fr.insee.pearljam.api.service.UtilsService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author scorcaud @@ -303,7 +293,7 @@ private void updateAddress(SurveyUnit surveyUnit, SurveyUnitUpdateDto surveyUnit @Transactional public HttpStatus updateSurveyUnitViewed(String userId, String suId) { Optional surveyUnitOpt = surveyUnitRepository.findById(suId); - if (!surveyUnitOpt.isPresent()) { + if (surveyUnitOpt.isEmpty()) { log.error(SU_ID_NOT_FOUND_FOR_INTERVIEWER, suId, userId); return HttpStatus.NOT_FOUND; } @@ -367,7 +357,9 @@ public List getClosableSurveyUnits(HttpServletRequest req return suToCheck.stream().map(su -> { SurveyUnitCampaignDto sudto = new SurveyUnitCampaignDto(su); - IdentificationState identificationResult = IdentificationState.getState(su.getModelIdentification()); + IdentificationState identificationResult = + IdentificationState.getState(su.getModelIdentification(), + sudto.getIdentificationConfiguration()); sudto.setIdentificationState(identificationResult); String questionnaireState = Optional.ofNullable(map.get(su.getId())).orElse(Constants.UNAVAILABLE); sudto.setQuestionnaireState(questionnaireState); @@ -493,7 +485,7 @@ private void addOrModifyClosingCause(SurveyUnit surveyUnit, ClosingCauseType typ public List getListStatesBySurveyUnitId(String suId) { Optional su = surveyUnitRepository.findById(suId); - if (!su.isPresent()) { + if (su.isEmpty()) { log.error("SU {} not found in database", suId); return List.of(); } diff --git a/src/main/java/fr/insee/pearljam/api/surveyunit/dto/IdentificationDto.java b/src/main/java/fr/insee/pearljam/api/surveyunit/dto/IdentificationDto.java index 72e7a110..377c2428 100644 --- a/src/main/java/fr/insee/pearljam/api/surveyunit/dto/IdentificationDto.java +++ b/src/main/java/fr/insee/pearljam/api/surveyunit/dto/IdentificationDto.java @@ -1,21 +1,29 @@ package fr.insee.pearljam.api.surveyunit.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import fr.insee.pearljam.domain.surveyunit.model.Identification; -import fr.insee.pearljam.domain.surveyunit.model.question.AccessQuestionValue; -import fr.insee.pearljam.domain.surveyunit.model.question.CategoryQuestionValue; -import fr.insee.pearljam.domain.surveyunit.model.question.IdentificationQuestionValue; -import fr.insee.pearljam.domain.surveyunit.model.question.OccupantQuestionValue; -import fr.insee.pearljam.domain.surveyunit.model.question.SituationQuestionValue; +import fr.insee.pearljam.domain.surveyunit.model.question.*; public record IdentificationDto( IdentificationQuestionValue identification, AccessQuestionValue access, SituationQuestionValue situation, CategoryQuestionValue category, - OccupantQuestionValue occupant) { + OccupantQuestionValue occupant, + @JsonProperty("individual_status") + IndividualStatusQuestionValue individualStatus, + @JsonProperty("interviewer_can_process") + InterviewerCanProcessQuestionValue interviewerCanProcess, + @JsonProperty("number_of_respondents") + NumberOfRespondentsQuestionValue numberOfRespondents, + @JsonProperty("present_in_previous_home") + PresentInPreviousHomeQuestionValue presentInPreviousHome, + @JsonProperty("household_composition") + HouseholdCompositionQuestionValue householdComposition +) { public static Identification toModel(IdentificationDto identificationDto) { - if(identificationDto == null) { + if (identificationDto == null) { return null; } @@ -24,17 +32,29 @@ public static Identification toModel(IdentificationDto identificationDto) { identificationDto.access(), identificationDto.situation(), identificationDto.category(), - identificationDto.occupant()); + identificationDto.occupant(), + identificationDto.individualStatus(), + identificationDto.interviewerCanProcess(), + identificationDto.numberOfRespondents(), + identificationDto.presentInPreviousHome(), + identificationDto.householdComposition() + ); } public static IdentificationDto fromModel(Identification identification) { - if(identification == null) { + if (identification == null) { return null; } return new IdentificationDto(identification.identification(), identification.access(), identification.situation(), identification.category(), - identification.occupant()); + identification.occupant(), + identification.individualStatus(), + identification.interviewerCanProcess(), + identification.numberOfRespondents(), + identification.presentInPreviousHome(), + identification.householdComposition() + ); } } diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/Identification.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/Identification.java index da88805e..31b3d2f4 100644 --- a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/Identification.java +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/Identification.java @@ -1,11 +1,19 @@ package fr.insee.pearljam.domain.surveyunit.model; import fr.insee.pearljam.domain.surveyunit.model.question.*; +import lombok.Builder; +@Builder public record Identification( IdentificationQuestionValue identification, AccessQuestionValue access, SituationQuestionValue situation, CategoryQuestionValue category, - OccupantQuestionValue occupant) { + OccupantQuestionValue occupant, + IndividualStatusQuestionValue individualStatus, + InterviewerCanProcessQuestionValue interviewerCanProcess, + NumberOfRespondentsQuestionValue numberOfRespondents, + PresentInPreviousHomeQuestionValue presentInPreviousHome, + HouseholdCompositionQuestionValue householdComposition +) { } diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationState.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationState.java index a963c487..dfc15ffd 100644 --- a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationState.java +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationState.java @@ -1,5 +1,6 @@ package fr.insee.pearljam.domain.surveyunit.model; +import fr.insee.pearljam.api.domain.IdentificationConfiguration; import fr.insee.pearljam.domain.surveyunit.model.question.CategoryQuestionValue; import fr.insee.pearljam.domain.surveyunit.model.question.IdentificationQuestionValue; import fr.insee.pearljam.domain.surveyunit.model.question.SituationQuestionValue; @@ -9,44 +10,66 @@ public enum IdentificationState { /** * Retrieve the identification state from the identification - * @param identification Identification form which the state is computed + * + * @param identification Identification from which the state is computed + * @param configuration Identification configuration to adapt rules * @return the identification state */ - public static IdentificationState getState(Identification identification) { - if(identification == null || identification.identification() == null) { + public static IdentificationState getState(Identification identification, + IdentificationConfiguration configuration) { + if (identification == null) { return IdentificationState.MISSING; } + return switch (configuration) { + case NOIDENT -> IdentificationState.MISSING; + + case IASCO, HOUSEF2F -> houseF2F(identification); + + // additional rules coming soon + case HOUSETEL, HOUSETELWSR, INDF2F, INDF2FNOR, INDTEL, INDTELNOR, SRCVREINT -> IdentificationState.MISSING; + + }; + + + } + + private static IdentificationState houseF2F(Identification identification) { IdentificationQuestionValue identificationQuestionValue = identification.identification(); - if(identificationQuestionValue == IdentificationQuestionValue.DESTROY || + if (identificationQuestionValue == null) { + return IdentificationState.MISSING; + } + + if (identificationQuestionValue == IdentificationQuestionValue.DESTROY || identificationQuestionValue == IdentificationQuestionValue.UNIDENTIFIED) { return IdentificationState.FINISHED; } - if(identification.access() == null) { + if (identification.access() == null) { return IdentificationState.ONGOING; } SituationQuestionValue situationQuestionValue = identification.situation(); - if(situationQuestionValue == null) { + if (situationQuestionValue == null) { return IdentificationState.ONGOING; } - if(situationQuestionValue == SituationQuestionValue.ABSORBED || + if (situationQuestionValue == SituationQuestionValue.ABSORBED || situationQuestionValue == SituationQuestionValue.NOORDINARY) { return IdentificationState.FINISHED; } CategoryQuestionValue categoryQuestionValue = identification.category(); - if(categoryQuestionValue == null) { + if (categoryQuestionValue == null) { return IdentificationState.ONGOING; } - if(categoryQuestionValue == CategoryQuestionValue.VACANT || + if (categoryQuestionValue == CategoryQuestionValue.VACANT || categoryQuestionValue == CategoryQuestionValue.SECONDARY) { return IdentificationState.FINISHED; } - return identification.occupant() != null ? IdentificationState.FINISHED : IdentificationState.ONGOING; + return identification.occupant() == null ? IdentificationState.ONGOING : IdentificationState.FINISHED; } + } diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/CategoryQuestionValue.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/CategoryQuestionValue.java index 333fc3bd..b0b1bb9e 100644 --- a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/CategoryQuestionValue.java +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/CategoryQuestionValue.java @@ -1,5 +1,5 @@ package fr.insee.pearljam.domain.surveyunit.model.question; public enum CategoryQuestionValue { - PRIMARY, OCCASIONAL, DK, SECONDARY, VACANT; + PRIMARY, OCCASIONAL, SECONDARY, VACANT; } diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/HouseholdCompositionQuestionValue.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/HouseholdCompositionQuestionValue.java new file mode 100644 index 00000000..e2a93e22 --- /dev/null +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/HouseholdCompositionQuestionValue.java @@ -0,0 +1,5 @@ +package fr.insee.pearljam.domain.surveyunit.model.question; + +public enum HouseholdCompositionQuestionValue { + SAMECOMPO, OTHERCOMPO +} diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/IndividualStatusQuestionValue.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/IndividualStatusQuestionValue.java new file mode 100644 index 00000000..49353d65 --- /dev/null +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/IndividualStatusQuestionValue.java @@ -0,0 +1,5 @@ +package fr.insee.pearljam.domain.surveyunit.model.question; + +public enum IndividualStatusQuestionValue { + DCD, NOIDENT, NOFIELD, SAMEADDRESS, OTHERADDRESS +} diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/InterviewerCanProcessQuestionValue.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/InterviewerCanProcessQuestionValue.java new file mode 100644 index 00000000..e0973df7 --- /dev/null +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/InterviewerCanProcessQuestionValue.java @@ -0,0 +1,5 @@ +package fr.insee.pearljam.domain.surveyunit.model.question; + +public enum InterviewerCanProcessQuestionValue { + YES, NO +} diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/NumberOfRespondentsQuestionValue.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/NumberOfRespondentsQuestionValue.java new file mode 100644 index 00000000..52dd7308 --- /dev/null +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/NumberOfRespondentsQuestionValue.java @@ -0,0 +1,5 @@ +package fr.insee.pearljam.domain.surveyunit.model.question; + +public enum NumberOfRespondentsQuestionValue { + ONE, MANY +} diff --git a/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/PresentInPreviousHomeQuestionValue.java b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/PresentInPreviousHomeQuestionValue.java new file mode 100644 index 00000000..8d0017a3 --- /dev/null +++ b/src/main/java/fr/insee/pearljam/domain/surveyunit/model/question/PresentInPreviousHomeQuestionValue.java @@ -0,0 +1,5 @@ +package fr.insee.pearljam.domain.surveyunit.model.question; + +public enum PresentInPreviousHomeQuestionValue { + ATLEASTONE, NONE +} diff --git a/src/main/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDB.java b/src/main/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDB.java index 0cfc3cae..5e23eb9b 100644 --- a/src/main/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDB.java +++ b/src/main/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDB.java @@ -48,6 +48,27 @@ public class IdentificationDB implements Serializable { @Enumerated(EnumType.STRING) private OccupantQuestionValue occupant; + @Column + @Enumerated(EnumType.STRING) + IndividualStatusQuestionValue individualStatus; + + @Column + @Enumerated(EnumType.STRING) + InterviewerCanProcessQuestionValue interviewerCanProcess; + + @Column + @Enumerated(EnumType.STRING) + NumberOfRespondentsQuestionValue numberOfRespondents; + + @Column + @Enumerated(EnumType.STRING) + PresentInPreviousHomeQuestionValue presentInPreviousHome; + + @Column + @Enumerated(EnumType.STRING) + HouseholdCompositionQuestionValue householdComposition; + + /** * The SurveyUnit associated to Identification */ @@ -62,16 +83,22 @@ public IdentificationDB(Identification identification, SurveyUnit su) { this.situation = identification.situation(); this.category = identification.category(); this.occupant = identification.occupant(); + this.individualStatus = identification.individualStatus(); + this.interviewerCanProcess = identification.interviewerCanProcess(); + this.numberOfRespondents = identification.numberOfRespondents(); + this.presentInPreviousHome = identification.presentInPreviousHome(); + this.householdComposition = identification.householdComposition(); } } /** * return model of the db entity + * * @param identificationDB identification DB entity * @return the model object of the db entity */ public static Identification toModel(IdentificationDB identificationDB) { - if(identificationDB == null) { + if (identificationDB == null) { return null; } return new Identification( @@ -79,12 +106,19 @@ public static Identification toModel(IdentificationDB identificationDB) { identificationDB.getAccess(), identificationDB.getSituation(), identificationDB.getCategory(), - identificationDB.getOccupant()); + identificationDB.getOccupant(), + identificationDB.getIndividualStatus(), + identificationDB.getInterviewerCanProcess(), + identificationDB.getNumberOfRespondents(), + identificationDB.getPresentInPreviousHome(), + identificationDB.getHouseholdComposition() + ); } /** * update the db entity from the model object + * * @param identification model object */ public void update(Identification identification) { @@ -97,5 +131,10 @@ public void update(Identification identification) { this.setSituation(identification.situation()); this.setCategory(identification.category()); this.setOccupant(identification.occupant()); + this.setIndividualStatus(identification.individualStatus()); + this.setInterviewerCanProcess(identification.interviewerCanProcess()); + this.setNumberOfRespondents(identification.numberOfRespondents()); + this.setPresentInPreviousHome(identification.presentInPreviousHome()); + this.setHouseholdComposition(identification.householdComposition()); } } diff --git a/src/main/resources/db/changelog/560_extend_identification.xml b/src/main/resources/db/changelog/560_extend_identification.xml new file mode 100644 index 00000000..0b3c49d2 --- /dev/null +++ b/src/main/resources/db/changelog/560_extend_identification.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/db/dataset/reinit-test-data.sql b/src/main/resources/db/dataset/reinit-test-data.sql index 956e28ea..9ea92cfc 100644 --- a/src/main/resources/db/dataset/reinit-test-data.sql +++ b/src/main/resources/db/dataset/reinit-test-data.sql @@ -196,9 +196,9 @@ INSERT INTO closing_cause (date, type, survey_unit_id) VALUES (DATEDIFF('SECOND', TIMESTAMP '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP)) * 1000, 'NPI', '11'); -INSERT INTO public.identification (survey_unit_id, identification,access,situation,category,occupant) VALUES - ('11', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED'), - ('21', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED'); +INSERT INTO public.identification (survey_unit_id, identification,access,situation,category,occupant,individual_status,interviewer_can_process,number_of_respondents,present_in_previous_home,household_composition) VALUES + ('11', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED','SAMEADDRESS','YES','MANY','ATLEASTONE','SAMECOMPO'), + ('21', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED', null, null, null, null, null); INSERT INTO public.communication_template (meshuggah_id, medium, type, campaign_id) VALUES ('mesh1', 'EMAIL', 'REMINDER', 'SIMPSONS2020X00'), diff --git a/src/main/resources/db/master.xml b/src/main/resources/db/master.xml index 238ba1c3..7a6d909b 100644 --- a/src/main/resources/db/master.xml +++ b/src/main/resources/db/master.xml @@ -65,4 +65,9 @@ + + + + + \ No newline at end of file diff --git a/src/test/java/fr/insee/pearljam/api/surveyunit/controller/SurveyUnitControllerTest.java b/src/test/java/fr/insee/pearljam/api/surveyunit/controller/SurveyUnitControllerTest.java index d4c8c32b..239b3b18 100644 --- a/src/test/java/fr/insee/pearljam/api/surveyunit/controller/SurveyUnitControllerTest.java +++ b/src/test/java/fr/insee/pearljam/api/surveyunit/controller/SurveyUnitControllerTest.java @@ -9,9 +9,9 @@ import fr.insee.pearljam.api.utils.MockMvcTestUtils; import fr.insee.pearljam.api.utils.dummy.AuthenticationUserFakeService; import fr.insee.pearljam.api.web.exception.ExceptionControllerAdvice; -import fr.insee.pearljam.domain.surveyunit.model.CommentType; import fr.insee.pearljam.domain.exception.PersonNotFoundException; import fr.insee.pearljam.domain.exception.SurveyUnitNotFoundException; +import fr.insee.pearljam.domain.surveyunit.model.CommentType; import fr.insee.pearljam.domain.surveyunit.model.question.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -92,7 +92,9 @@ void updateSurveyUnit01() throws Exception { AccessQuestionValue.ACC, SituationQuestionValue.ABSORBED, CategoryQuestionValue.OCCASIONAL, - OccupantQuestionValue.IDENTIFIED); + OccupantQuestionValue.IDENTIFIED + , null, null, null, null, null + ); assertThat(surveyUnitUpdated.identification()).isEqualTo(identificationExpected); diff --git a/src/test/java/fr/insee/pearljam/api/surveyunit/dto/SurveyUnitDetailDtoTest.java b/src/test/java/fr/insee/pearljam/api/surveyunit/dto/SurveyUnitDetailDtoTest.java index 8f6af3a4..1b058309 100644 --- a/src/test/java/fr/insee/pearljam/api/surveyunit/dto/SurveyUnitDetailDtoTest.java +++ b/src/test/java/fr/insee/pearljam/api/surveyunit/dto/SurveyUnitDetailDtoTest.java @@ -3,7 +3,9 @@ import fr.insee.pearljam.api.domain.*; import fr.insee.pearljam.api.dto.surveyunit.SurveyUnitDetailDto; import fr.insee.pearljam.domain.surveyunit.model.CommentType; -import fr.insee.pearljam.domain.surveyunit.model.communication.*; +import fr.insee.pearljam.domain.surveyunit.model.communication.CommunicationRequestEmitter; +import fr.insee.pearljam.domain.surveyunit.model.communication.CommunicationRequestReason; +import fr.insee.pearljam.domain.surveyunit.model.communication.CommunicationStatusType; import fr.insee.pearljam.domain.surveyunit.model.question.*; import fr.insee.pearljam.infrastructure.campaign.entity.CommunicationTemplateDB; import fr.insee.pearljam.infrastructure.surveyunit.entity.CommentDB; @@ -50,6 +52,7 @@ void testCreateIdentification01() { SituationQuestionValue.ORDINARY, CategoryQuestionValue.SECONDARY, OccupantQuestionValue.IDENTIFIED, + null, null, null, null, null, surveyUnit); surveyUnit.setIdentification(identificationDB); SurveyUnitDetailDto surveyUnitDetailDto = new SurveyUnitDetailDto(surveyUnit); diff --git a/src/test/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationStateTest.java b/src/test/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationStateTest.java index 3336900c..e4cb49d5 100644 --- a/src/test/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationStateTest.java +++ b/src/test/java/fr/insee/pearljam/domain/surveyunit/model/IdentificationStateTest.java @@ -1,11 +1,15 @@ package fr.insee.pearljam.domain.surveyunit.model; +import fr.insee.pearljam.api.domain.IdentificationConfiguration; import fr.insee.pearljam.domain.surveyunit.model.question.*; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestFactory; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -19,95 +23,247 @@ void testState01() { AccessQuestionValue.NACC, SituationQuestionValue.ORDINARY, CategoryQuestionValue.VACANT, - OccupantQuestionValue.UNIDENTIFIED); + OccupantQuestionValue.UNIDENTIFIED, + null, null, null, null, null + ); List identifications = new ArrayList<>(); identifications.add(identification1); identifications.forEach(identificationToCheck -> - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.MISSING)); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.MISSING)); } @Test @DisplayName("Should return FINISHED when identification question value is destroy or unidentified") void testState02() { Identification identificationDestroy = new Identification( - IdentificationQuestionValue.DESTROY, null, null, null, null); + IdentificationQuestionValue.DESTROY, null, null, null, null, null, null, null, null, null); Identification identificationUnidentified = new Identification( - IdentificationQuestionValue.UNIDENTIFIED, null, null, null, null); + IdentificationQuestionValue.UNIDENTIFIED, null, null, null, null, null, null, null, null, null); List identifications = List.of(identificationDestroy, identificationUnidentified); identifications.forEach(identificationToCheck -> - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.FINISHED)); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.FINISHED)); } @Test @DisplayName("Should return ONGOING state when access is null") void testState03() { Identification identificationToCheck = new Identification( - IdentificationQuestionValue.IDENTIFIED, null, null, null, null); + IdentificationQuestionValue.IDENTIFIED, null, null, null, null, null, null, null, null, null); - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.ONGOING); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.ONGOING); } @Test @DisplayName("Should return ONGOING when situation question value is null") void testState04() { Identification identificationToCheck = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, null, null, null); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, null, null, null, null, null, null, + null, null); - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.ONGOING); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.ONGOING); } @Test @DisplayName("Should return FINISHED when situation question value is absorbed or no ordinary") void testState05() { Identification identificationAbsorbed = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ABSORBED, null, null); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ABSORBED, + null, null, null, null, null, null, null); Identification identificationNoOrdinary = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.NACC, SituationQuestionValue.NOORDINARY, null, null); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.NACC, SituationQuestionValue.NOORDINARY, + null, null, null, null, null, null, null); List identifications = List.of(identificationAbsorbed, identificationNoOrdinary); identifications.forEach(identificationToCheck -> - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.FINISHED)); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.FINISHED)); } @Test @DisplayName("Should return ONGOING when category question value is null") void testState06() { Identification identificationToCheck = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, null, null); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, + null, null, null, null, null, null, null); - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.ONGOING); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.ONGOING); } @Test @DisplayName("Should return FINISHED when category question value is vacant or secondary") void testState07() { Identification identificationVacant = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, CategoryQuestionValue.VACANT, null); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, + CategoryQuestionValue.VACANT, null, null, null, null, null, null); Identification identificationSecondary = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.NACC, SituationQuestionValue.ORDINARY, CategoryQuestionValue.SECONDARY, null); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.NACC, SituationQuestionValue.ORDINARY, + CategoryQuestionValue.SECONDARY, null, null, null, null, null, null); List identifications = List.of(identificationVacant, identificationSecondary); identifications.forEach(identificationToCheck -> - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.FINISHED)); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.FINISHED)); } @Test @DisplayName("Should return FINISHED when occupant is not null") void testState08() { Identification identificationToCheck = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, CategoryQuestionValue.OCCASIONAL, OccupantQuestionValue.IDENTIFIED); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, + CategoryQuestionValue.OCCASIONAL, OccupantQuestionValue.IDENTIFIED, null, null, null, null, null); - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.FINISHED); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.FINISHED); } @Test @DisplayName("Should return ONGOING state") void testState09() { Identification identificationToCheck = new Identification( - IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, CategoryQuestionValue.OCCASIONAL, null); + IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, SituationQuestionValue.ORDINARY, + CategoryQuestionValue.OCCASIONAL, null, null, null, null, null, null); - assertThat(IdentificationState.getState(identificationToCheck)).isEqualTo(IdentificationState.ONGOING); + assertThat(IdentificationState.getState(identificationToCheck, IdentificationConfiguration.HOUSEF2F)).isEqualTo(IdentificationState.ONGOING); } + + @TestFactory + @DisplayName("Parameterized tests for getState method") + Stream testGetState() { + return provideTestCases().map(testCase -> DynamicTest.dynamicTest( + testCase.getTestName(), + () -> { + IdentificationState result = IdentificationState.getState( + testCase.identification, testCase.configuration + ); + assertThat(testCase.expectedState).isEqualTo(result); + } + )); + } + + /// IASCO & HOUSEF2F cases table : --- mean identificationStatus = FINISHED and question should be null and won't + /// be evaluated + /// + /// | identification | access | situation | category | occupant | + /// | -------------- | ---------- | --------------------- | ------------------ | ------------------------- | + /// | DESTROY | --- | --- | --- | --- | + /// | UNIDENTIFIED | --- | --- | --- | --- | + /// | IDENTIFIED | ACC / NACC | ABSORBED / NOORDINARY | --- | --- | + /// | IDENTIFIED | ACC / NACC | ORDINARY | SECONDARY / VACANT | --- | + /// | IDENTIFIED | ACC / NACC | ORDINARY | PRIMARY | IDENTIFIED / UNIDENTIFIED | + private static Stream provideTestCases() { + return Stream.of( + // Cases 1-2 : Null Identification + new TestCase(null, IdentificationConfiguration.NOIDENT, IdentificationState.MISSING), + new TestCase(null, IdentificationConfiguration.HOUSEF2F, IdentificationState.MISSING), + + // Case 3: NOIDENT always returns MISSING + new TestCase(Identification.builder().build(), IdentificationConfiguration.NOIDENT, + IdentificationState.MISSING), + + // Cases 4-5: HOUSEF2F + `identification`[DESTROY / UNIDENTIFIED] => state FINISHED + new TestCase( + iascoIdentBuilder(IdentificationQuestionValue.DESTROY).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + new TestCase( + iascoIdentBuilder(IdentificationQuestionValue.UNIDENTIFIED).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + + // Case 6: HOUSEF2F + `identification`[IDENTIFIED] + `access`[null] => ONGOING + new TestCase( + iascoIdentBuilder(IdentificationQuestionValue.IDENTIFIED).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.ONGOING + ), + + // Case 7-8: HOUSEF2F + `identification`[IDENTIFIED] + `access`[ACC / NACC] => ONGOING + new TestCase( + iascoAccessBuilder(AccessQuestionValue.ACC).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.ONGOING + ), + new TestCase( + iascoAccessBuilder(AccessQuestionValue.NACC).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.ONGOING + ), + + + // Case 9-10: HOUSEF2F previous + `situation`[ABSORBED/NOORDINARY] => FINISHED + new TestCase( + iascoSituationBuilder(SituationQuestionValue.ABSORBED).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + new TestCase( + iascoSituationBuilder(SituationQuestionValue.NOORDINARY).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + + // Case 11-12: HOUSEF2F previous + `category`[SECONDARY / VACANT] => FINISHED + new TestCase( + iascoCategoryBuilder(CategoryQuestionValue.SECONDARY).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + new TestCase( + iascoCategoryBuilder(CategoryQuestionValue.VACANT).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + + // Case 13: HOUSEF2F previous + `category`[PRIMARY] with null occupant => ONGOING + new TestCase( + iascoCategoryBuilder(CategoryQuestionValue.PRIMARY).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.ONGOING + ), + + // HOUSEF2F 14-15 questions completed + new TestCase( + iascoOccupantBuilder(OccupantQuestionValue.IDENTIFIED).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + new TestCase( + iascoOccupantBuilder(OccupantQuestionValue.UNIDENTIFIED).build(), + IdentificationConfiguration.HOUSEF2F, IdentificationState.FINISHED + ), + + // Case 16: Configuration HOUSETEL (and other unimplemented identification configurations) always + // returns MISSING + new TestCase( + Identification.builder().build(), IdentificationConfiguration.HOUSETEL, + IdentificationState.MISSING + )); + } + + + // Builders + + private static Identification.IdentificationBuilder iascoIdentBuilder(IdentificationQuestionValue identification) { + return Identification.builder().identification(identification); + } + + private static Identification.IdentificationBuilder iascoAccessBuilder(AccessQuestionValue access) { + return iascoIdentBuilder(IdentificationQuestionValue.IDENTIFIED).access(access); + } + + private static Identification.IdentificationBuilder iascoSituationBuilder(SituationQuestionValue situation) { + return iascoAccessBuilder(AccessQuestionValue.ACC).situation(situation); + } + + private static Identification.IdentificationBuilder iascoCategoryBuilder(CategoryQuestionValue category) { + return iascoSituationBuilder(SituationQuestionValue.ORDINARY).category(category); + } + + private static Identification.IdentificationBuilder iascoOccupantBuilder(OccupantQuestionValue occupant) { + return iascoCategoryBuilder(CategoryQuestionValue.PRIMARY).occupant(occupant); + } + + + // Helper class to represent a test case + private record TestCase(Identification identification, IdentificationConfiguration configuration, + IdentificationState expectedState) { + String getTestName() { + return String.format( + "Given configuration %s, identification %s, expect state %s", + configuration, identification, expectedState + ); + } + + } + } diff --git a/src/test/java/fr/insee/pearljam/domain/surveyunit/service/SurveyUnitUpdateServiceImplTest.java b/src/test/java/fr/insee/pearljam/domain/surveyunit/service/SurveyUnitUpdateServiceImplTest.java index 46e01280..2de0d8ab 100644 --- a/src/test/java/fr/insee/pearljam/domain/surveyunit/service/SurveyUnitUpdateServiceImplTest.java +++ b/src/test/java/fr/insee/pearljam/domain/surveyunit/service/SurveyUnitUpdateServiceImplTest.java @@ -1,17 +1,26 @@ package fr.insee.pearljam.domain.surveyunit.service; import fr.insee.pearljam.api.campaign.controller.dummy.VisibilityFakeService; -import fr.insee.pearljam.api.domain.*; +import fr.insee.pearljam.api.domain.Campaign; +import fr.insee.pearljam.api.domain.OrganizationUnit; +import fr.insee.pearljam.api.domain.OrganizationUnitType; +import fr.insee.pearljam.api.domain.SurveyUnit; import fr.insee.pearljam.api.service.impl.SurveyUnitUpdateServiceImpl; -import fr.insee.pearljam.api.surveyunit.dto.*; -import fr.insee.pearljam.domain.campaign.port.userside.DateService; -import fr.insee.pearljam.domain.campaign.service.dummy.FixedDateService; +import fr.insee.pearljam.api.surveyunit.dto.CommentDto; +import fr.insee.pearljam.api.surveyunit.dto.CommunicationRequestCreateDto; +import fr.insee.pearljam.api.surveyunit.dto.IdentificationDto; +import fr.insee.pearljam.api.surveyunit.dto.SurveyUnitUpdateDto; import fr.insee.pearljam.domain.campaign.model.Visibility; import fr.insee.pearljam.domain.campaign.model.communication.CommunicationMedium; import fr.insee.pearljam.domain.campaign.model.communication.CommunicationTemplate; import fr.insee.pearljam.domain.campaign.model.communication.CommunicationType; +import fr.insee.pearljam.domain.campaign.port.userside.DateService; +import fr.insee.pearljam.domain.campaign.service.dummy.FixedDateService; import fr.insee.pearljam.domain.surveyunit.model.CommentType; -import fr.insee.pearljam.domain.surveyunit.model.communication.*; +import fr.insee.pearljam.domain.surveyunit.model.communication.CommunicationRequest; +import fr.insee.pearljam.domain.surveyunit.model.communication.CommunicationRequestEmitter; +import fr.insee.pearljam.domain.surveyunit.model.communication.CommunicationRequestReason; +import fr.insee.pearljam.domain.surveyunit.model.communication.CommunicationStatusType; import fr.insee.pearljam.domain.surveyunit.model.question.*; import fr.insee.pearljam.domain.surveyunit.service.dummy.CommunicationRequestFakeRepository; import fr.insee.pearljam.domain.surveyunit.service.dummy.CommunicationTemplateFakeRepository; @@ -220,20 +229,20 @@ void testUpdateComments02() { @Test @DisplayName("Should update identification") void testUpdateIdentification01() { - IdentificationDB identificationDB = new IdentificationDB(2L, - IdentificationQuestionValue.IDENTIFIED, - AccessQuestionValue.ACC, - SituationQuestionValue.ORDINARY, - CategoryQuestionValue.SECONDARY, - OccupantQuestionValue.IDENTIFIED, - surveyUnit); + IdentificationDB identificationDB = createIdentificationDB(); surveyUnit.setIdentification(identificationDB); IdentificationDto identification = new IdentificationDto(IdentificationQuestionValue.UNIDENTIFIED, AccessQuestionValue.NACC, SituationQuestionValue.NOORDINARY, CategoryQuestionValue.VACANT, - OccupantQuestionValue.UNIDENTIFIED); + OccupantQuestionValue.UNIDENTIFIED, + IndividualStatusQuestionValue.OTHERADDRESS, + InterviewerCanProcessQuestionValue.NO, + NumberOfRespondentsQuestionValue.MANY, + PresentInPreviousHomeQuestionValue.NONE, + HouseholdCompositionQuestionValue.OTHERCOMPO + ); surveyUnitDto = createSurveyUnitDto(identification, null, null); surveyUnitService.updateSurveyUnitInfos(surveyUnit, surveyUnitDto); @@ -244,19 +253,18 @@ void testUpdateIdentification01() { assertThat(identificationResult.getSituation()).isEqualTo(SituationQuestionValue.NOORDINARY); assertThat(identificationResult.getCategory()).isEqualTo(CategoryQuestionValue.VACANT); assertThat(identificationResult.getOccupant()).isEqualTo(OccupantQuestionValue.UNIDENTIFIED); + assertThat(identificationResult.getIndividualStatus()).isEqualTo(IndividualStatusQuestionValue.OTHERADDRESS); + assertThat(identificationResult.getInterviewerCanProcess()).isEqualTo(InterviewerCanProcessQuestionValue.NO); + assertThat(identificationResult.getNumberOfRespondents()).isEqualTo(NumberOfRespondentsQuestionValue.MANY); + assertThat(identificationResult.getPresentInPreviousHome()).isEqualTo(PresentInPreviousHomeQuestionValue.NONE); + assertThat(identificationResult.getHouseholdComposition()).isEqualTo(HouseholdCompositionQuestionValue.OTHERCOMPO); assertThat(identificationResult.getSurveyUnit()).isEqualTo(surveyUnit); } @Test @DisplayName("Should not update identification entity when identification model is null") void testUpdateIdentification02() { - IdentificationDB identificationDB = new IdentificationDB(2L, - IdentificationQuestionValue.IDENTIFIED, - AccessQuestionValue.ACC, - SituationQuestionValue.ABSORBED, - CategoryQuestionValue.SECONDARY, - OccupantQuestionValue.IDENTIFIED, - surveyUnit); + IdentificationDB identificationDB = createIdentificationDB(); surveyUnit.setIdentification(identificationDB); surveyUnitDto = createSurveyUnitDto(null, null, null); surveyUnitService.updateSurveyUnitInfos(surveyUnit, surveyUnitDto); @@ -271,7 +279,12 @@ void testUpdateIdentification03() { AccessQuestionValue.NACC, SituationQuestionValue.NOORDINARY, CategoryQuestionValue.VACANT, - OccupantQuestionValue.UNIDENTIFIED); + OccupantQuestionValue.UNIDENTIFIED, + IndividualStatusQuestionValue.OTHERADDRESS, + InterviewerCanProcessQuestionValue.NO, + NumberOfRespondentsQuestionValue.MANY, + PresentInPreviousHomeQuestionValue.NONE, + HouseholdCompositionQuestionValue.OTHERCOMPO); surveyUnitDto = createSurveyUnitDto(identification, null, null); surveyUnitService.updateSurveyUnitInfos(surveyUnit, surveyUnitDto); @@ -284,10 +297,30 @@ void testUpdateIdentification03() { assertThat(identificationResult.getCategory()).isEqualTo(CategoryQuestionValue.VACANT); assertThat(identificationResult.getOccupant()).isEqualTo(OccupantQuestionValue.UNIDENTIFIED); assertThat(identificationResult.getSurveyUnit()).isEqualTo(surveyUnit); + assertThat(identificationResult.getIndividualStatus()).isEqualTo(IndividualStatusQuestionValue.OTHERADDRESS); + assertThat(identificationResult.getInterviewerCanProcess()).isEqualTo(InterviewerCanProcessQuestionValue.NO); + assertThat(identificationResult.getNumberOfRespondents()).isEqualTo(NumberOfRespondentsQuestionValue.MANY); + assertThat(identificationResult.getPresentInPreviousHome()).isEqualTo(PresentInPreviousHomeQuestionValue.NONE); + assertThat(identificationResult.getHouseholdComposition()).isEqualTo(HouseholdCompositionQuestionValue.OTHERCOMPO); } private SurveyUnitUpdateDto createSurveyUnitDto(IdentificationDto identification, List comments, List communicationRequests) { return new SurveyUnitUpdateDto("su-id", null, null, true, comments, null, null, null, identification, communicationRequests); } + + private IdentificationDB createIdentificationDB() { + return new IdentificationDB(2L, + IdentificationQuestionValue.IDENTIFIED, + AccessQuestionValue.ACC, + SituationQuestionValue.ORDINARY, + CategoryQuestionValue.SECONDARY, + OccupantQuestionValue.IDENTIFIED, + IndividualStatusQuestionValue.SAMEADDRESS, + InterviewerCanProcessQuestionValue.YES, + NumberOfRespondentsQuestionValue.ONE, + PresentInPreviousHomeQuestionValue.ATLEASTONE, + HouseholdCompositionQuestionValue.SAMECOMPO, + surveyUnit); + } } diff --git a/src/test/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDBTest.java b/src/test/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDBTest.java index 41e0fcf7..9f53101b 100644 --- a/src/test/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDBTest.java +++ b/src/test/java/fr/insee/pearljam/infrastructure/surveyunit/entity/IdentificationDBTest.java @@ -25,7 +25,7 @@ void setup() { AccessQuestionValue.ACC, SituationQuestionValue.ABSORBED, CategoryQuestionValue.SECONDARY, - OccupantQuestionValue.IDENTIFIED, + OccupantQuestionValue.IDENTIFIED, null, null, null, null, null, surveyUnitDB); } @@ -36,7 +36,7 @@ void testUpdate01() { AccessQuestionValue.NACC, SituationQuestionValue.NOORDINARY, CategoryQuestionValue.VACANT, - OccupantQuestionValue.UNIDENTIFIED); + OccupantQuestionValue.UNIDENTIFIED, null, null, null, null, null); identificationDB.update(identification); assertThat(identificationDB.getId()).isEqualTo(identificationId); assertThat(identificationDB.getIdentification()).isEqualTo(identification.identification()); diff --git a/src/test/java/fr/insee/pearljam/integration/surveyunit/SurveyUnitIT.java b/src/test/java/fr/insee/pearljam/integration/surveyunit/SurveyUnitIT.java index b7d2fa0b..a231707d 100644 --- a/src/test/java/fr/insee/pearljam/integration/surveyunit/SurveyUnitIT.java +++ b/src/test/java/fr/insee/pearljam/integration/surveyunit/SurveyUnitIT.java @@ -4,9 +4,9 @@ import fr.insee.pearljam.api.utils.AuthenticatedUserTestHelper; import fr.insee.pearljam.api.utils.MockMvcTestUtils; import fr.insee.pearljam.api.utils.ScriptConstants; -import fr.insee.pearljam.domain.exception.CommunicationTemplateNotFoundException; import fr.insee.pearljam.config.FixedDateServiceConfiguration; import fr.insee.pearljam.domain.campaign.port.userside.DateService; +import fr.insee.pearljam.domain.exception.CommunicationTemplateNotFoundException; import org.json.JSONException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -113,8 +113,8 @@ void testGetSurveyUnits() throws Exception { * Test that the GET endpoint "api/survey-unit/{id}" * return 200. * - * @throws InterruptedException - * @throws JSONException + * @throws InterruptedException ie + * @throws JSONException jse */ @Test void testGetSurveyUnitDetail() throws Exception { @@ -236,7 +236,12 @@ void testGetSurveyUnitDetail() throws Exception { "access":"ACC", "situation":"ORDINARY", "category":"PRIMARY", - "occupant":"IDENTIFIED" + "occupant":"IDENTIFIED", + "individual_status":"SAMEADDRESS", + "interviewer_can_process":"YES", + "number_of_respondents":"MANY", + "present_in_previous_home":"ATLEASTONE", + "household_composition":"SAMECOMPO" }, "communicationTemplates":[ { @@ -294,7 +299,7 @@ void testGetSurveyUnitDetail() throws Exception { * Test that the PUT endpoint "api/survey-unit/{id}" * return 200 * - * @throws Exception + * @throws Exception e */ @Test @Sql(value = ScriptConstants.REINIT_SQL_SCRIPT, executionPhase = AFTER_TEST_METHOD)