diff --git a/README.md b/README.md index cf998217..aa77391c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ REST API for communication between Pearl Jam DB and Pearl Jam UI. ## Requirements For building and running the application you need: -- [JDK 11](https://jdk.java.net/archive/) +- [JDK 21](https://jdk.java.net/archive/) - Maven 3 - Docker for tests @@ -22,17 +22,7 @@ mvn spring-boot:run ``` ## Application Accesses locally -To access to swagger-ui, use this url : [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) - -## Keycloak Configuration -1. To start the server on port 8180 execute in the bin folder of your keycloak : -```shell -standalone.bat -Djboss.socket.binding.port-offset=100 (on Windows) - -standalone.sh -Djboss.socket.binding.port-offset=100 (on Unix-based systems) -``` -2. Go to the console administration and create role investigator and a user with this role. - +To access to swagger-ui, use this url : [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html) ## Deploy application on Tomcat server ### 1. Package the application @@ -62,7 +52,6 @@ fr.insee.pearljam.logging.level=DEBUG #Application configuration fr.insee.pearljam.application.mode=keycloak fr.insee.pearljam.application.crosOrigin=* -fr.insee.pearljam.application.guestOU=OU-POLE #Database configuration fr.insee.pearljam.persistence.database.host = pearljam-db diff --git a/pom.xml b/pom.xml index baa7f83f..6974d96a 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ com.h2database h2 - runtime + test diff --git a/src/main/java/fr/insee/pearljam/api/configuration/DataInjectorOnStartup.java b/src/main/java/fr/insee/pearljam/api/configuration/DataInjectorOnStartup.java deleted file mode 100644 index a1076058..00000000 --- a/src/main/java/fr/insee/pearljam/api/configuration/DataInjectorOnStartup.java +++ /dev/null @@ -1,23 +0,0 @@ -package fr.insee.pearljam.api.configuration; - -import lombok.RequiredArgsConstructor; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.event.EventListener; - -import fr.insee.pearljam.api.service.DataSetInjectorService; - -@ConditionalOnProperty(name = "feature.enableDataset", havingValue = "true") -@Configuration -@RequiredArgsConstructor -public class DataInjectorOnStartup { - - private final DataSetInjectorService injector; - - @EventListener(ApplicationReadyEvent.class) - public void createDataSetOnStartup() { - injector.createDataSet(); - } -} diff --git a/src/main/java/fr/insee/pearljam/api/controller/DataSetController.java b/src/main/java/fr/insee/pearljam/api/controller/DataSetController.java deleted file mode 100644 index d4551c9e..00000000 --- a/src/main/java/fr/insee/pearljam/api/controller/DataSetController.java +++ /dev/null @@ -1,50 +0,0 @@ -package fr.insee.pearljam.api.controller; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import fr.insee.pearljam.api.service.DataSetInjectorService; -import fr.insee.pearljam.api.service.UtilsService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@RestController -@Tag(name = "10. Data injector", description = "Endpoints for data injection/deletion") -@RequestMapping(path = "/api") -@RequiredArgsConstructor -@Slf4j -public class DataSetController { - - private final DataSetInjectorService injector; - private final UtilsService utilsService; - - @Operation(summary = "Create dataset") - @PostMapping(path = "/create-dataset") - public ResponseEntity createDataSet() { - if (!utilsService.isDevProfile() && !utilsService.isTestProfile()) { - return new ResponseEntity<>(HttpStatus.FORBIDDEN); - } - HttpStatus status = injector.createDataSet(); - return new ResponseEntity<>(status); - } - - @Operation(summary = "Delete dataset") - @DeleteMapping(path = "/delete-dataset") - public ResponseEntity deteteDataSet() { - if (!utilsService.isDevProfile() && !utilsService.isTestProfile()) { - return new ResponseEntity<>(HttpStatus.FORBIDDEN); - } - - HttpStatus status = injector.deleteDataSet(); - - log.info("Dataset deletion end"); - return new ResponseEntity<>(status); - } - -} diff --git a/src/main/java/fr/insee/pearljam/api/service/DataSetInjectorService.java b/src/main/java/fr/insee/pearljam/api/service/DataSetInjectorService.java deleted file mode 100644 index 68606eac..00000000 --- a/src/main/java/fr/insee/pearljam/api/service/DataSetInjectorService.java +++ /dev/null @@ -1,16 +0,0 @@ -package fr.insee.pearljam.api.service; - - -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; - - -@Service -public interface DataSetInjectorService { - - - HttpStatus createDataSet(); - - HttpStatus deleteDataSet(); - -} diff --git a/src/main/java/fr/insee/pearljam/api/service/impl/DataSetInjectorServiceImpl.java b/src/main/java/fr/insee/pearljam/api/service/impl/DataSetInjectorServiceImpl.java deleted file mode 100644 index 211c7440..00000000 --- a/src/main/java/fr/insee/pearljam/api/service/impl/DataSetInjectorServiceImpl.java +++ /dev/null @@ -1,371 +0,0 @@ -package fr.insee.pearljam.api.service.impl; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.util.List; -import java.util.Set; - -import jakarta.persistence.EntityManager; -import jakarta.persistence.EntityManagerFactory; - -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import fr.insee.pearljam.api.domain.Campaign; -import fr.insee.pearljam.api.domain.ClosingCause; -import fr.insee.pearljam.api.domain.ClosingCauseType; -import fr.insee.pearljam.api.domain.Comment; -import fr.insee.pearljam.api.domain.CommentType; -import fr.insee.pearljam.api.domain.ContactAttemptConfiguration; -import fr.insee.pearljam.api.domain.ContactOutcome; -import fr.insee.pearljam.api.domain.ContactOutcomeConfiguration; -import fr.insee.pearljam.api.domain.ContactOutcomeType; -import fr.insee.pearljam.api.domain.Identification; -import fr.insee.pearljam.api.domain.IdentificationConfiguration; -import fr.insee.pearljam.api.domain.InseeAddress; -import fr.insee.pearljam.api.domain.InseeSampleIdentifier; -import fr.insee.pearljam.api.domain.Interviewer; -import fr.insee.pearljam.api.domain.OrganizationUnit; -import fr.insee.pearljam.api.domain.OrganizationUnitType; -import fr.insee.pearljam.api.domain.Person; -import fr.insee.pearljam.api.domain.PhoneNumber; -import fr.insee.pearljam.api.domain.Source; -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.domain.Title; -import fr.insee.pearljam.api.domain.User; -import fr.insee.pearljam.api.domain.Visibility; -import fr.insee.pearljam.api.domain.IdentificationQuestions.AccessQuestionValue; -import fr.insee.pearljam.api.domain.IdentificationQuestions.CategoryQuestionValue; -import fr.insee.pearljam.api.domain.IdentificationQuestions.IdentificationQuestionValue; -import fr.insee.pearljam.api.domain.IdentificationQuestions.OccupantQuestionValue; -import fr.insee.pearljam.api.domain.IdentificationQuestions.SituationQuestionValue; -import fr.insee.pearljam.api.repository.AddressRepository; -import fr.insee.pearljam.api.repository.CampaignRepository; -import fr.insee.pearljam.api.repository.IdentificationRepository; -import fr.insee.pearljam.api.repository.InterviewerRepository; -import fr.insee.pearljam.api.repository.OrganizationUnitRepository; -import fr.insee.pearljam.api.repository.PersonRepository; -import fr.insee.pearljam.api.repository.SampleIdentifierRepository; -import fr.insee.pearljam.api.repository.SurveyUnitRepository; -import fr.insee.pearljam.api.repository.UserRepository; -import fr.insee.pearljam.api.repository.VisibilityRepository; -import fr.insee.pearljam.api.service.DataSetInjectorService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Service -@Transactional -@Slf4j -@RequiredArgsConstructor -public class DataSetInjectorServiceImpl implements DataSetInjectorService { - - private final EntityManagerFactory emf; - - private final CampaignRepository campaignRepository; - private final AddressRepository addressRepository; - private final OrganizationUnitRepository organizationUnitRepository; - private final InterviewerRepository interviewerRepository; - private final SampleIdentifierRepository sampleIdentifierRepository; - private final UserRepository userRepository; - private final VisibilityRepository visibilityRepository; - private final SurveyUnitRepository surveyUnitRepository; - private final PersonRepository personRepository; - private final IdentificationRepository identificationRepository; - - private static final String PHONE_NUMBERS = "+33677542802"; - - public HttpStatus createDataSet() { - - LocalDateTime now = LocalDateTime.now(); - long p1Month = toMilliseconds(now.plusMonths(1)); - long p2Months = toMilliseconds(now.plusMonths(2)); - long m1Day = toMilliseconds(now.minusDays(1)); - long m2Days = toMilliseconds(now.minusDays(2)); - long m3Days = toMilliseconds(now.minusDays(3)); - long m4Days = toMilliseconds(now.minusDays(4)); - long m5Days = toMilliseconds(now.minusDays(5)); - long m6Days = toMilliseconds(now.minusDays(6)); - long m7Days = toMilliseconds(now.minusDays(7)); - - if (!campaignRepository.findAllIds().isEmpty()) { - log.info("The database already contains a campaign, the dataset was not imported"); - return HttpStatus.NOT_MODIFIED; - } - log.info("Dataset creation start"); - - final String FRANCE = "France"; - // create address entities - - InseeAddress address1 = addressRepository - .save(new InseeAddress("Ted Farmer", "", "", "1 rue de la gare", "", "29270 Carhaix", FRANCE, - true, "Bat. C", "Etg 4", "Porte 48", "Escalier B", true)); - InseeAddress address2 = addressRepository - .save(new InseeAddress("Cecilia Ortega", "", "", "2 place de la mairie", "", "90000 Belfort", - FRANCE, false, null, null, null, null, false)); - InseeAddress address3 = addressRepository - .save(new InseeAddress("Claude Watkins", "", "", "3 avenue de la République", "", - "32230 Marciac", FRANCE, false, null, null, null, null, false)); - InseeAddress address4 = addressRepository - .save(new InseeAddress("Veronica Gill", "", "", "4 chemin du ruisseau", "", "44190 Clisson", - FRANCE, false, null, null, null, null, false)); - InseeAddress address5 = addressRepository - .save(new InseeAddress("Christine Aguilar", "", "", "5 rue de l'école", "", - "59620 Aulnoye-Aimeries", FRANCE, false, null, null, null, null, false)); - InseeAddress address6 = addressRepository - .save(new InseeAddress("Louise Walker", "", "", "6 impasse du lac", "", "38200 Vienne", - FRANCE, false, null, null, null, null, false)); - InseeAddress address7 = addressRepository - .save(new InseeAddress("Anthony Bennett", "", "", "7 avenue de la Liberté", "", "62000 Arras", - FRANCE, false, null, null, null, null, false)); - InseeAddress address8 = addressRepository - .save(new InseeAddress("Christopher Lewis", "", "", "8 route du moulin", "", "35000 Rennes", - FRANCE, false, null, null, null, null, false)); - InseeAddress address9 = addressRepository - .save(new InseeAddress("Laurent Neville", "", "", "5 route du sapin", "", "35000 Rennes", - FRANCE, false, null, null, null, null, false)); - - // create organization_unit entities - OrganizationUnit ouNational = organizationUnitRepository.save( - new OrganizationUnit("OU-NATIONAL", "National organizational unit", OrganizationUnitType.NATIONAL)); - OrganizationUnit ouNorth = organizationUnitRepository - .save(new OrganizationUnit("OU-NORTH", "North region organizational unit", OrganizationUnitType.LOCAL)); - OrganizationUnit ouSouth = organizationUnitRepository - .save(new OrganizationUnit("OU-SOUTH", "South region organizational unit", OrganizationUnitType.LOCAL)); - OrganizationUnit ouWest = organizationUnitRepository - .save(new OrganizationUnit("OU-WEST", "West region organizational unit", OrganizationUnitType.LOCAL)); - - ouNorth.setOrganizationUnitParent(ouNational); - ouSouth.setOrganizationUnitParent(ouNational); - ouWest.setOrganizationUnitParent(ouNational); - - // create interviewer entities - - Interviewer intw1 = interviewerRepository.save(new Interviewer("INTW1", "Margie", "Lucas", - "margie.lucas@ou.com", "+3391231231230", null, Title.MISS)); - Interviewer intw2 = interviewerRepository.save(new Interviewer("INTW2", "Carlton", "Campbell", - "carlton.campbell@ou.com", "+3391231231231", null, Title.MISTER)); - Interviewer intw3 = interviewerRepository.save(new Interviewer("INTW3", "Gerald", "Edwards", - "gerald.edwards@ou.com", "+3391231231232", null, Title.MISTER)); - Interviewer intw4 = interviewerRepository.save(new Interviewer("INTW4", "Melody", "Grant", - "melody.grant@ou.com", "+3391231231233", null, Title.MISS)); - - // create sample_identifier entities - InseeSampleIdentifier sampleId1 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(11, "1", 11, 11, 11, 11, 1, 11, 11, "11", "11")); - InseeSampleIdentifier sampleId2 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(12, "1", 12, 12, 12, 12, 1, 12, 12, "12", "12")); - InseeSampleIdentifier sampleId3 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(13, "1", 13, 13, 13, 13, 2, 13, 13, "13", "13")); - InseeSampleIdentifier sampleId4 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(14, "1", 14, 14, 14, 14, 3, 14, 14, "14", "14")); - InseeSampleIdentifier sampleId5 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(20, "2", 20, 20, 20, 20, 1, 20, 20, "20", "20")); - InseeSampleIdentifier sampleId6 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(21, "2", 21, 21, 21, 21, 1, 21, 21, "21", "21")); - InseeSampleIdentifier sampleId7 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(22, "2", 22, 22, 22, 22, 2, 22, 22, "22", "22")); - InseeSampleIdentifier sampleId8 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(23, "2", 23, 23, 23, 23, 1, 23, 23, "23", "23")); - InseeSampleIdentifier sampleId9 = sampleIdentifierRepository - .save(new InseeSampleIdentifier(24, "2", 24, 24, 24, 24, 1, 24, 24, "24", "24")); - - // create user entities - userRepository.save(new User("ABC", "Melinda", "Webb", ouNorth)); - userRepository.save(new User("GUEST", "firstname", "lastname", ouNorth)); - userRepository.save(new User("DEF", "Everett", "Juste", ouNorth)); - User user3 = userRepository.save(new User("GHI", "Elsie", "Clarke", ouSouth)); - User user4 = userRepository.save(new User("JKL", "Julius", "Howell", ouNational)); - userRepository.save(new User("MNO", "Ted", "Kannt", ouWest)); - - String campLabel = "Everyday life and health survey 2021"; - // create campaign entities - Campaign campaign1 = campaignRepository - .save(new Campaign("SIMPSONS2020X00", "Survey on the Simpsons tv show 2020", - IdentificationConfiguration.IASCO, ContactOutcomeConfiguration.F2F, - ContactAttemptConfiguration.F2F, "first.email@test.com", Boolean.FALSE)); - Campaign campaign2 = campaignRepository.save(new Campaign("VQS2021X00", campLabel, - IdentificationConfiguration.IASCO, ContactOutcomeConfiguration.TEL, ContactAttemptConfiguration.TEL, - "second.email@test.com", Boolean.FALSE)); - Campaign campaign3 = campaignRepository.save(new Campaign("ZCLOSEDX00", campLabel, - IdentificationConfiguration.IASCO, ContactOutcomeConfiguration.F2F, ContactAttemptConfiguration.F2F, - "third.email@test.com", Boolean.FALSE)); - Campaign campaign4 = campaignRepository.save(new Campaign("XCLOSEDX00", campLabel, - IdentificationConfiguration.IASCO, ContactOutcomeConfiguration.TEL, ContactAttemptConfiguration.TEL, - "fourth.email@test.com", Boolean.FALSE)); - - // create preference entities : User/Campaign relation - user3.setCampaigns(List.of(campaign1)); - user4.setCampaigns(List.of(campaign1, campaign2)); - - // create visibility entities - - // opened visibilities - visibilityRepository.save(new Visibility(m4Days, m3Days, m2Days, m1Day, p1Month, p2Months, campaign1, ouNorth)); - visibilityRepository.save(new Visibility(m4Days, m3Days, m2Days, m1Day, p1Month, p2Months, campaign2, ouNorth)); - visibilityRepository.save(new Visibility(m4Days, m3Days, m2Days, m1Day, p1Month, p2Months, campaign2, ouSouth)); - visibilityRepository.save(new Visibility(m4Days, m3Days, m2Days, m1Day, p1Month, p2Months, campaign1, ouSouth)); - - // closed visibilities - visibilityRepository.save(new Visibility(m7Days, m6Days, m5Days, m4Days, m3Days, m1Day, campaign3, ouSouth)); - visibilityRepository.save(new Visibility(m7Days, m6Days, m5Days, m4Days, m3Days, m1Day, campaign3, ouWest)); - visibilityRepository.save(new Visibility(m7Days, m6Days, m5Days, m4Days, m3Days, m1Day, campaign4, ouSouth)); - - // create survey_unit entities - - SurveyUnit su11 = surveyUnitRepository - .save(new SurveyUnit("11", true, false, address1, sampleId1, campaign1, intw1)); - su11.setCampaign(campaign1); - su11.setOrganizationUnit(ouNorth); - SurveyUnit su12 = surveyUnitRepository - .save(new SurveyUnit("12", true, false, address2, sampleId2, campaign1, intw1)); - su12.setCampaign(campaign1); - su12.setOrganizationUnit(ouNorth); - SurveyUnit su13 = surveyUnitRepository - .save(new SurveyUnit("13", false, false, address3, sampleId3, campaign1, intw2)); - su13.setCampaign(campaign1); - su13.setOrganizationUnit(ouNorth); - SurveyUnit su14 = surveyUnitRepository - .save(new SurveyUnit("14", false, false, address4, sampleId4, campaign1, intw3)); - su14.setCampaign(campaign1); - su14.setOrganizationUnit(ouNorth); - SurveyUnit su20 = surveyUnitRepository - .save(new SurveyUnit("20", false, false, address5, sampleId5, campaign2, intw1)); - su20.setCampaign(campaign2); - su20.setOrganizationUnit(ouNorth); - SurveyUnit su21 = surveyUnitRepository - .save(new SurveyUnit("21", false, false, address6, sampleId6, campaign2, intw2)); - su21.setCampaign(campaign2); - su21.setOrganizationUnit(ouNorth); - SurveyUnit su22 = surveyUnitRepository - .save(new SurveyUnit("22", false, false, address7, sampleId7, campaign2, intw4)); - su22.setCampaign(campaign2); - su22.setOrganizationUnit(ouNorth); - SurveyUnit su23 = surveyUnitRepository - .save(new SurveyUnit("23", false, false, address8, sampleId8, campaign2, intw4)); - su23.setCampaign(campaign2); - su23.setOrganizationUnit(ouNorth); - SurveyUnit su24 = surveyUnitRepository - .save(new SurveyUnit("24", true, false, address9, sampleId9, campaign1, null)); - su24.setCampaign(campaign1); - su24.setOrganizationUnit(ouNorth); - - // create person entities - String email = "test@test.com"; - Person person1 = personRepository - .save(new Person(Title.MISTER, "Ted", "Farmer", email, true, true, 11111111l, su11)); - Person person2 = personRepository - .save(new Person(Title.MISS, "Cecilia", "Ortega", email, true, true, 11111111l, su12)); - Person person3 = personRepository - .save(new Person(Title.MISTER, "Claude", "Watkins", email, true, true, 11111111l, su13)); - Person person4 = personRepository - .save(new Person(Title.MISS, "Veronica", "Baker", email, true, true, 11111111l, su14)); - Person person5 = personRepository - .save(new Person(Title.MISS, "Christine", "Aguilar", email, true, false, 11111111l, su11)); - Person person6 = personRepository - .save(new Person(Title.MISS, "Louise", "Walker", email, true, false, 11111111l, su11)); - Person person7 = personRepository - .save(new Person(Title.MISTER, "Anthony", "Bennett", email, true, false, 11111111l, su12)); - Person person8 = personRepository - .save(new Person(Title.MISTER, "Christopher", "Lewis", email, true, false, 11111111l, su14)); - Person person9 = personRepository - .save(new Person(Title.MISS, "Harriette", "Raymond", email, true, true, 11111111l, su20)); - Person person10 = personRepository - .save(new Person(Title.MISTER, "Aimée", "Lamothe", email, true, true, 11111111l, su21)); - Person person11 = personRepository - .save(new Person(Title.MISTER, "Perrin", "Blanchard", email, true, true, 11111111l, su22)); - Person person12 = personRepository - .save(new Person(Title.MISTER, "Artus", "Arnoux", email, true, true, 11111111l, su23)); - Person person13 = personRepository - .save(new Person(Title.MISTER, "Laurent", "Neville", email, true, true, 11111111l, su24)); - - // create phone_number entities - person1.setPhoneNumbers(Set.of(new PhoneNumber(Source.FISCAL, true, PHONE_NUMBERS, person1), - new PhoneNumber(Source.FISCAL, false, PHONE_NUMBERS, person1))); - addPhoneNUmber(person2); - addPhoneNUmber(person3); - addPhoneNUmber(person4); - addPhoneNUmber(person5); - addPhoneNUmber(person6); - addPhoneNUmber(person7); - addPhoneNUmber(person8); - addPhoneNUmber(person9); - addPhoneNUmber(person10); - addPhoneNUmber(person11); - addPhoneNUmber(person12); - addPhoneNUmber(person13); - - // create state entities - su11.setStates(Set.of(new State(111112111l, su11, StateType.VIN), - new State(110111111l, su11, StateType.NNS), - new State(101111111l, su11, StateType.TBR))); - su12.setStates(Set.of(new State(111112111l, su12, StateType.TBR))); - su13.setStates(Set.of(new State(111112111l, su13, StateType.TBR))); - su14.setStates(Set.of(new State(111112111l, su14, StateType.TBR))); - su20.setStates(Set.of(new State(111112111l, su20, StateType.VIC))); - su21.setStates(Set.of(new State(111112111l, su21, StateType.VIC))); - su22.setStates(Set.of(new State(111112111l, su22, StateType.FIN))); - su23.setStates(Set.of(new State(111112111l, su23, StateType.VIC))); - su24.setStates(Set.of(new State(111112111l, su24, StateType.TBR))); - // create contact_outcome entities - - su24.setContactOucome(new ContactOutcome(null, 1590504478334l, ContactOutcomeType.DUK, null, su24)); - // create comment entities - su13.setComments(Set.of(new Comment(null, CommentType.INTERVIEWER, "un commentaire", su13))); - // create closing_cause entities - su11.setClosingCause(new ClosingCause(null, m3Days, ClosingCauseType.NPI, su11)); - - // create identification entities - Identification identif1 = identificationRepository - .save(new Identification(null, IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, - SituationQuestionValue.ORDINARY, CategoryQuestionValue.PRIMARY, - OccupantQuestionValue.IDENTIFIED, su11)); - Identification identif2 = identificationRepository - .save(new Identification(null, IdentificationQuestionValue.IDENTIFIED, AccessQuestionValue.ACC, - SituationQuestionValue.ORDINARY, CategoryQuestionValue.PRIMARY, - OccupantQuestionValue.IDENTIFIED, su21)); - - su11.setIdentification(identif1); - su21.setIdentification(identif2); - - log.info("Dataset creation end"); - return HttpStatus.OK; - - } - - public HttpStatus deleteDataSet() { - try (InputStream sqlFileInputStream = getClass().getClassLoader() - .getResource("dataset//delete_data.sql").openStream(); EntityManager em = emf.createEntityManager()) { - - BufferedReader sqlFileBufferedReader = new BufferedReader(new InputStreamReader(sqlFileInputStream)); - executeStatements(sqlFileBufferedReader, em); - } catch (Exception e) { - e.printStackTrace(); - return HttpStatus.NOT_MODIFIED; - } - return HttpStatus.OK; - - } - - void executeStatements(BufferedReader br, EntityManager entityManager) throws IOException { - String line; - while ((line = br.readLine()) != null) { - entityManager.joinTransaction(); - entityManager.createNativeQuery(line).executeUpdate(); - } - } - - private long toMilliseconds(LocalDateTime date) { - return date.atZone(ZoneOffset.UTC).toInstant().toEpochMilli(); - } - - private void addPhoneNUmber(Person person) { - person.setPhoneNumbers(Set.of(new PhoneNumber(Source.FISCAL, true, PHONE_NUMBERS, person))); - } -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 2382e3d4..00000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,86 +0,0 @@ -spring.application.name=api -application.host=http://localhost:8080 - -# Define Roles mapping here -application.roles.interviewer=****** -application.roles.local_user=****** -application.roles.national_user=****** -application.roles.admin=****** -application.roles.webclient=****** - -feature.swagger.enabled=false -feature.oidc.enabled=true -feature.oidc.application-host=${application.host} -feature.oidc.auth-server-host=https://auth-server.host -feature.oidc.auth-server-url=${feature.oidc.auth-server-host}/auth -feature.oidc.realm=my-realm -feature.oidc.client-id=my-client-id -feature.oidc.principal-attribute=id-claim - -application.corsOrigins='*' - -# Folder where to store temp files. -# DO NOT USE THE DEFAULT TEMP DIRECTORY OF THE OS as it adresses some vulnerabilities. -# Use a folder with permissions for the app only -application.temp-folder= - - -# External service URLs -application.external.service.datacollection-url=https://datacollection-api:443 -#application.external.service.mail-url= => need proper mail service implementation - -# Datasource -spring.datasource.url= -spring.datasource.driverClassName=org.postgresql.Driver -spring.datasource.username= -spring.datasource.password= - -spring.main.allow-bean-definition-overriding=true -spring.datasource.hikari.minimum-idle=2 -spring.datasource.hikari.maximum-pool-size=2 - -spring.jpa.open-in-view=false -spring.jpa.hibernate.ddl-auto=none -spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy -spring.jpa.hibernate.naming.implicit-strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy -spring.jpa.properties.id.new_generator_mappings=true -spring.jpa.properties.cache.use_second_level_cache=false -spring.jpa.properties.cache.use_query_cache=false -spring.jpa.properties.generate_statistics=false -spring.jpa.properties.hbm2ddl.auto=validate - -spring.h2.console.enabled=false - -## if auth=KEYCLOAK : uncomment and provide following property -spring.security.oauth2.resourceserver.jwt.issuer-uri=${feature.oidc.auth-server-url}/realms/${feature.oidc.realm} -spring.liquibase.enabled=true -spring.liquibase.contexts=prod -spring.liquibase.defaultSchema=public -spring.liquibase.change-log=classpath:db/master.xml - -spring.profiles.group.cache-testing=test,test-cache - -## if auth=KEYCLOAK : uncomment and provide following properties -# springdoc.swagger-ui.oauth.client-id=${feature.oidc.client-id} -# springdoc.swagger-ui.oauth2RedirectUrl=${application.host}/swagger-ui/oauth2-redirect.html - -springdoc.swagger-ui.path=/ -springdoc.swagger-ui.syntax-highlight.activated=false -springdoc.swagger-ui.tagsSorter=alpha -springdoc.swagger-ui.operationsSorter=method -springdoc.swagger-ui.doc-expansion=none -springdoc.swagger-ui.try-it-out-enabled=true -springdoc.pathsToMatch=/** -springdoc.packagesToScan=fr.insee.pearljam.api - -logging.level.root=INFO -logging.level.liquibase=ERROR -logging.level.springdoc=INFO -logging.logback.rollingpolicy.max-history=90 -logging.pattern.console=%d{YYYY-MM-dd HH:mm:ss.SSS} [%X{id}][%X{user}][%X{method} %X{path}] [%thread] %-5level %logger{36} - %htmlEncode{%m}%n -logging.pattern.file: ${logging.pattern.console} - -feature.logging.file.enabled=false - -# allow creation of a demonstration data set at start-up -feature.enableDataset=false \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 00000000..ef768cac --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,87 @@ +application: + host: http://localhost:8080 + corsOrigins: + # Define Roles mapping here + roles: + interviewer: + local_user: + national_user: + admin: + webclient: + # Folder where to store temp files. + # DO NOT USE THE DEFAULT TEMP DIRECTORY OF THE OS as it adresses some vulnerabilities in a non container env. + # Use a folder with permissions for the app only + temp-folder: + external: + service: + datacollection-url: + mail-url: + +feature: + oidc: + enabled: true + auth-server-host: + application-host: ${application.host} + auth-server-url: ${feature.oidc.auth-server-host}/auth + client-id: + realm: + principal-attribute: + swagger: + enabled: false + logging: + file: + enabled: false + +spring: + datasource: + url: + username: + password: + driver-class-name: org.postgresql.Driver + hikari: + minimum-idle: 2 + maximum-pool-size: 2 + jpa: + open-in-view: false + hibernate: + ddl-auto: none + naming: + physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy + implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy + properties: + id: + new_generator_mappings: true + cache: + use_second_level_cache: false + use_query_cache: false + generate_statistics: false + hbm2ddl: + auto: validate + liquibase: + enabled: true + contexts: prod + changeLog: classpath:db/master.xml + defaultSchema: public + h2: + console: + enabled: false + security: + # used only if oidc enabled + oauth2.resourceserver.jwt.issuer-uri: ${feature.oidc.auth-server-url}/realms/${feature.oidc.realm} + +springdoc: + swagger-ui: + # used only if oidc enabled + oauth.client-id: ${feature.oidc.client-id} + path: / + syntax-highlight: + activated: false + tagsSorter: alpha + doc-expansion: none + +logging: + level: + root: INFO + springdoc: INFO + fr.insee.pearljam: INFO + liquibase: INFO \ No newline at end of file diff --git a/src/main/resources/dataset/delete_data.sql b/src/main/resources/dataset/delete_data.sql deleted file mode 100644 index bade8bdc..00000000 --- a/src/main/resources/dataset/delete_data.sql +++ /dev/null @@ -1,24 +0,0 @@ -DELETE FROM public.closing_cause; -DELETE FROM public.comment; -DELETE FROM public.contact_outcome; -DELETE FROM public.state; -DELETE FROM public.phone_number; -DELETE FROM public.person; -DELETE FROM public.identification - -DELETE FROM public.survey_unit; -DELETE FROM public.visibility; -DELETE FROM public.preference; -DELETE FROM public.campaign; -DELETE FROM public.user; -DELETE FROM public.sample_identifier; -DELETE FROM public.interviewer; -DELETE FROM public.organization_unit; -DELETE FROM public.address; - -DELETE FROM public.campaign_message_recipient; -DELETE FROM public.contact_attempt; -DELETE FROM public.message; -DELETE FROM public.message_status; -DELETE FROM public.oumessage_recipient; -DELETE FROM public.referent diff --git a/src/main/resources/dataset/insert_test_data.sql b/src/main/resources/dataset/insert_test_data.sql deleted file mode 100644 index a6e4d6b0..00000000 --- a/src/main/resources/dataset/insert_test_data.sql +++ /dev/null @@ -1,119 +0,0 @@ -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Ted Farmer' ,'','','1 rue de la gare' ,'','29270 Carhaix' ,'France', true, 'Bat. C', 'Etg 4', 'Porte 48', 'Escalier B', true); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Cecilia Ortega' ,'','','2 place de la mairie' ,'','90000 Belfort' ,'France', false, null, null, null, null, false); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Claude Watkins' ,'','','3 avenue de la République' ,'','32230 Marciac' ,'France', false, null, null, null, null, false); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Veronica Gill' ,'','','4 chemin du ruisseau' ,'','44190 Clisson' ,'France', false, null, null, null, null, false); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Christine Aguilar' ,'','','5 rue de l''école' ,'','59620 Aulnoye-Aimeries' ,'France', false, null, null, null, null, false); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Louise Walker' ,'','','6 impasse du lac' ,'','38200 Vienne' ,'France', false, null, null, null, null, false); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Anthony Bennett' ,'','','7 avenue de la Liberté' ,'','62000 Arras' ,'France', false, null, null, null, null, false); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Christopher Lewis' ,'','','8 route du moulin' ,'','35000 Rennes' ,'France', false, null, null, null, null, false); -INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES ('InseeAddress', 'Laurent Neville' ,'','','5 route du sapin' ,'','35000 Rennes' ,'France', false, null, null, null, null, false); - -INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-NATIONAL', 'National organizational unit', 'NATIONAL', null); -INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-NORTH', 'North region organizational unit', 'LOCAL', 'OU-NATIONAL'); -INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-SOUTH', 'South region organizational unit', 'LOCAL', 'OU-NATIONAL'); -INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-WEST', 'West region organizational unit', 'LOCAL', 'OU-NATIONAL'); - -INSERT INTO public.interviewer (id, email, first_name, last_name, phone_number) VALUES ('INTW1', 'margie.lucas@ou.com', 'Margie', 'Lucas', '+3391231231230'); -INSERT INTO public.interviewer (id, email, first_name, last_name, phone_number) VALUES ('INTW2', 'carlton.campbell@ou.com', 'Carlton', 'Campbell', '+3391231231231'); -INSERT INTO public.interviewer (id, email, first_name, last_name, phone_number) VALUES ('INTW3', 'gerald.edwards@ou.com', 'Gerald', 'Edwards', '+3391231231231'); -INSERT INTO public.interviewer (id, email, first_name, last_name, phone_number) VALUES ('INTW4', 'melody.grant@ou.com', 'Melody', 'Grant', '+3391231231231'); - -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '11', 11, '1', 11, '11', 11, 11, 11, 11, 11, 1); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '12', 12, '1', 12, '12', 12, 12, 12, 12, 12, 1); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '13', 13, '1', 13, '13', 13, 13, 13, 13, 13, 2); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '14', 14, '1', 14, '14', 14, 14, 14, 14, 14, 3); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '20', 20, '2', 20, '20', 20, 20, 20, 20, 20, 1); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '21', 21, '2', 21, '21', 21, 21, 21, 21, 21, 1); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '22', 22, '2', 22, '22', 22, 22, 22, 22, 22, 2); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '23', 23, '2', 23, '23', 23, 23, 23, 23, 23, 1); -INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES ('InseeSampleIdentifier', '24', 24, '2', 24, '24', 24, 24, 24, 24, 24, 1); - -INSERT INTO public."user" (id, first_name, last_name, organization_unit_id) VALUES ('ABC', 'Melinda', 'Webb', 'OU-NORTH'); -INSERT INTO public."user" (id, first_name, last_name, organization_unit_id) VALUES ('DEF', 'Everett', 'Juste', 'OU-NORTH'); -INSERT INTO public."user" (id, first_name, last_name, organization_unit_id) VALUES ('GHI', 'Elsie', 'Clarke', 'OU-SOUTH'); -INSERT INTO public."user" (id, first_name, last_name, organization_unit_id) VALUES ('JKL', 'Julius', 'Howell', 'OU-NATIONAL'); -INSERT INTO public."user" (id, first_name, last_name, organization_unit_id) VALUES ('MNO', 'Ted', 'Kannt', 'OU-WEST'); - -INSERT INTO public.campaign (id, label, email, identification_configuration, contact_attempt_configuration, contact_outcome_configuration) VALUES ('SIMPSONS2020X00', 'Survey on the Simpsons tv show 2020', 'first.email@test.com', 'IASCO', 'F2F', 'F2F'); -INSERT INTO public.campaign (id, label, email, identification_configuration, contact_attempt_configuration, contact_outcome_configuration) VALUES ('VQS2021X00', 'Everyday life and health survey 2021', 'second.email@test.com', 'IASCO', 'TEL', 'TEL'); -INSERT INTO public.campaign (id, label, email, identification_configuration, contact_attempt_configuration, contact_outcome_configuration) VALUES ('ZCLOSEDX00', 'Everyday life and health survey 2021', 'third.email@test.com', 'IASCO', 'F2F', 'F2F'); -INSERT INTO public.campaign (id, label, email, identification_configuration, contact_attempt_configuration, contact_outcome_configuration) VALUES ('XCLOSEDX00', 'Everyday life and health survey 2021', 'fourth.email@test.com', 'IASCO', 'TEL', 'TEL'); - -INSERT INTO public.preference (id_user, id_campaign) VALUES ('GHI', 'SIMPSONS2020X00'); -INSERT INTO public.preference (id_user, id_campaign) VALUES ('JKL', 'SIMPSONS2020X00'); -INSERT INTO public.preference (id_user, id_campaign) VALUES ('JKL', 'VQS2021X00'); - - -INSERT INTO public.visibility(organization_unit_id, campaign_id, collection_end_date, collection_start_date, end_date, identification_phase_start_date, interviewer_start_date, management_start_date) VALUES ('OU-NORTH', 'SIMPSONS2020X00', (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '1 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '2 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '4 DAY'))*1000)); -INSERT INTO public.visibility(organization_unit_id, campaign_id, collection_end_date, collection_start_date, end_date, identification_phase_start_date, interviewer_start_date, management_start_date) VALUES ('OU-NORTH', 'VQS2021X00', (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '1 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '2 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '4 DAY'))*1000)); -INSERT INTO public.visibility(organization_unit_id, campaign_id, collection_end_date, collection_start_date, end_date, identification_phase_start_date, interviewer_start_date, management_start_date) VALUES ('OU-SOUTH', 'VQS2021X00', (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '1 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '2 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '4 DAY'))*1000)); -INSERT INTO public.visibility(organization_unit_id, campaign_id, collection_end_date, collection_start_date, end_date, identification_phase_start_date, interviewer_start_date, management_start_date) VALUES ('OU-SOUTH', 'SIMPSONS2020X00', (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '1 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP + INTERVAL '2 MONTH'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '2 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '4 DAY'))*1000)); -INSERT INTO public.visibility(organization_unit_id, campaign_id, collection_end_date, collection_start_date, end_date, identification_phase_start_date, interviewer_start_date, management_start_date) VALUES ('OU-SOUTH', 'ZCLOSEDX00', (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '4 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '1 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '5 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '6 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '7 DAY'))*1000)); -INSERT INTO public.visibility(organization_unit_id, campaign_id, collection_end_date, collection_start_date, end_date, identification_phase_start_date, interviewer_start_date, management_start_date) VALUES ('OU-WEST', 'ZCLOSEDX00', (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '4 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '1 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '5 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '6 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '7 DAY'))*1000)); -INSERT INTO public.visibility(organization_unit_id, campaign_id, collection_end_date, collection_start_date, end_date, identification_phase_start_date, interviewer_start_date, management_start_date) VALUES ('OU-SOUTH', 'XCLOSEDX00', (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '4 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '1 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '5 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '6 DAY'))*1000), (SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '7 DAY'))*1000)); - -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '11', TRUE, a.id, 'SIMPSONS2020X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Ted Farmer' AND s.bs='11'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '12', TRUE, a.id, 'SIMPSONS2020X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Cecilia Ortega' AND s.bs='12'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '13', FALSE, a.id, 'SIMPSONS2020X00', 'INTW2', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Claude Watkins' AND s.bs='13'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '14', FALSE, a.id, 'SIMPSONS2020X00', 'INTW3', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Veronica Gill' AND s.bs='14'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '20', FALSE, a.id, 'VQS2021X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Christine Aguilar' AND s.bs='20'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '21', FALSE, a.id, 'VQS2021X00', 'INTW2', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Louise Walker' AND s.bs='21'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '22', FALSE, a.id, 'VQS2021X00', 'INTW4', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Anthony Bennett' AND s.bs='22'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '23', FALSE, a.id, 'VQS2021X00', 'INTW4', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Christopher Lewis' AND s.bs='23'; -INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '24', TRUE, a.id, 'SIMPSONS2020X00', NULL, s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Laurent Neville' AND s.bs='24'; - - -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com',TRUE, 'Ted', 'Farmer', 11111111, 0, TRUE, '11'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Cecilia', 'Ortega', 11111111, 1, TRUE, '12'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Claude', 'Watkins', 11111111, 0, TRUE, '13'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Veronica', 'Baker', 11111111, 1, TRUE, '14'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Christine', 'Aguilar', 11111111, 1, FALSE, '11'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Louise', 'Walker', 11111111, 1, FALSE, '11'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Anthony', 'Bennett', 11111111, 0, FALSE, '12'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Christopher', 'Lewis', 11111111, 0, FALSE, '14'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Harriette', 'Raymond', 11111111, 0, TRUE, '20'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Aimée', 'Lamothe', 11111111, 0, TRUE, '21'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Perrin', 'Blanchard', 11111111, 0, TRUE, '22'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Artus', 'Arnoux', 11111111, 0, TRUE, '23'); -INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES ('test@test.com', TRUE,'Laurent', 'Neville', 11111111, 0, TRUE, '24'); - - - -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Ted' and p.last_name='Farmer' and p.survey_unit_id='11'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT FALSE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Ted' and p.last_name='Farmer' and p.survey_unit_id='11'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Cecilia' and p.last_name='Ortega' and p.survey_unit_id='12'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Claude' and p.last_name='Watkins' and p.survey_unit_id='13'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Veronica' and p.last_name='Baker' and p.survey_unit_id='14'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Christine' and p.last_name='Aguilar' and p.survey_unit_id='11'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Louise' and p.last_name='Walker' and p.survey_unit_id='11'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Anthony' and p.last_name='Bennett' and p.survey_unit_id='12'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Christopher' and p.last_name='Lewis' and p.survey_unit_id='14'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Harriette' and p.last_name='Raymond' and p.survey_unit_id='20'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Aimée' and p.last_name='Lamothe' and p.survey_unit_id='21'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Perrin' and p.last_name='Blanchard' and p.survey_unit_id='22'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Artus' and p.last_name='Arnoux' and p.survey_unit_id='23'; -INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Laurent' and p.last_name='Neville' and p.survey_unit_id='24'; - - - -INSERT INTO public.state (date, type, survey_unit_id) VALUES (111112111,'VIN', '11'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (110111111,'NNS', '11'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (111111111,'TBR', '12'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (111111111,'TBR', '13'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (111111111,'TBR', '14'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (101111111,'TBR', '11'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (101111111,'TBR', '24'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (1590504478334, 'VIC', '20'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (1590504478334, 'VIC', '21'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (1590504478334, 'FIN', '22'); -INSERT INTO public.state (date, type, survey_unit_id) VALUES (1590504478334, 'VIC', '23'); - -INSERT INTO public.contact_outcome (date, type, survey_unit_id) VALUES (1590504478334, 'DUK', '24'); - -INSERT INTO public.comment (type, value, survey_unit_id) VALUES ('INTERVIEWER', 'un commentaire', '13'); - -INSERT INTO public.closing_cause (date, type, survey_unit_id) VALUES ((SELECT extract(epoch from (LOCALTIMESTAMP - INTERVAL '3 DAYS'))*1000), 'NPI', '11'); - - -INSERT INTO public.identification (survey_unit_id, identification,access,situation,category,occupant) VALUES ('11', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED'); -INSERT INTO public.identification (survey_unit_id, identification,access,situation,category,occupant) VALUES ('21', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED'); \ No newline at end of file diff --git a/src/main/resources/db/dataset/init-demo-data.sql b/src/main/resources/db/dataset/init-demo-data.sql new file mode 100644 index 00000000..23fa3013 --- /dev/null +++ b/src/main/resources/db/dataset/init-demo-data.sql @@ -0,0 +1,194 @@ +--changeset davdarras:init-demo-data + +INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES + ('InseeAddress', 'Ted Farmer' ,'','','1 rue de la gare' ,'','29270 Carhaix' ,'France', true, 'Bat. C', 'Etg 4', 'Porte 48', 'Escalier B', true), + ('InseeAddress', 'Cecilia Ortega' ,'','','2 place de la mairie' ,'','90000 Belfort' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Claude Watkins' ,'','','3 avenue de la République' ,'','32230 Marciac' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Veronica Gill' ,'','','4 chemin du ruisseau' ,'','44190 Clisson' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Christine Aguilar' ,'','','5 rue de l''école' ,'','59620 Aulnoye-Aimeries' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Louise Walker' ,'','','6 impasse du lac' ,'','38200 Vienne' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Anthony Bennett' ,'','','7 avenue de la Liberté' ,'','62000 Arras' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Christopher Lewis' ,'','','8 route du moulin' ,'','35000 Rennes' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Laurent Neville' ,'','','5 route du sapin' ,'','35000 Rennes' ,'France', false, null, null, null, null, false); + +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-NATIONAL', 'National organizational unit', 'NATIONAL', null); +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-NORTH', 'North region organizational unit', 'LOCAL', 'OU-NATIONAL'); +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-SOUTH', 'South region organizational unit', 'LOCAL', 'OU-NATIONAL'); +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-WEST', 'West region organizational unit', 'LOCAL', 'OU-NATIONAL'); + +INSERT INTO public.interviewer (id, email, first_name, last_name, phone_number) VALUES + ('INTW1', 'margie.lucas@ou.com', 'Margie', 'Lucas', '+3391231231230'), + ('INTW2', 'carlton.campbell@ou.com', 'Carlton', 'Campbell', '+3391231231231'), + ('INTW3', 'gerald.edwards@ou.com', 'Gerald', 'Edwards', '+3391231231231'), + ('INTW4', 'melody.grant@ou.com', 'Melody', 'Grant', '+3391231231231'); + +INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES + ('InseeSampleIdentifier', '11', 11, '1', 11, '11', 11, 11, 11, 11, 11, 1), + ('InseeSampleIdentifier', '12', 12, '1', 12, '12', 12, 12, 12, 12, 12, 1), + ('InseeSampleIdentifier', '13', 13, '1', 13, '13', 13, 13, 13, 13, 13, 2), + ('InseeSampleIdentifier', '14', 14, '1', 14, '14', 14, 14, 14, 14, 14, 3), + ('InseeSampleIdentifier', '20', 20, '2', 20, '20', 20, 20, 20, 20, 20, 1), + ('InseeSampleIdentifier', '21', 21, '2', 21, '21', 21, 21, 21, 21, 21, 1), + ('InseeSampleIdentifier', '22', 22, '2', 22, '22', 22, 22, 22, 22, 22, 2), + ('InseeSampleIdentifier', '23', 23, '2', 23, '23', 23, 23, 23, 23, 23, 1), + ('InseeSampleIdentifier', '24', 24, '2', 24, '24', 24, 24, 24, 24, 24, 1); + +INSERT INTO public.USER (id, first_name, last_name, organization_unit_id) VALUES + ('ABC', 'Melinda', 'Webb', 'OU-NORTH'), + ('DEF', 'Everett', 'Juste', 'OU-NORTH'), + ('GHI', 'Elsie', 'Clarke', 'OU-SOUTH'), + ('JKL', 'Julius', 'Howell', 'OU-NATIONAL'), + ('MNO', 'Ted', 'Kannt', 'OU-WEST'), + ('GUEST', 'firstname', 'lastname', 'OU-NORTH'); + +INSERT INTO public.campaign (id, label, email, identification_configuration, contact_attempt_configuration, contact_outcome_configuration) VALUES + ('SIMPSONS2020X00', 'Survey on the Simpsons tv show 2020', 'first.email@test.com', 'IASCO', 'F2F', 'F2F'), + ('VQS2021X00', 'Everyday life and health survey 2021', 'second.email@test.com', 'IASCO', 'TEL', 'TEL'), + ('ZCLOSEDX00', 'Everyday life and health survey 2021', 'third.email@test.com', 'IASCO', 'F2F', 'F2F'), + ('XCLOSEDX00', 'Everyday life and health survey 2021', 'fourth.email@test.com', 'IASCO', 'TEL', 'TEL'); + +INSERT INTO public.preference (id_user, id_campaign) VALUES + ('GHI', 'SIMPSONS2020X00'), + ('JKL', 'SIMPSONS2020X00'), + ('JKL', 'VQS2021X00'); + + +INSERT INTO visibility ( + organization_unit_id, + campaign_id, + collection_end_date, + collection_start_date, + end_date, + identification_phase_start_date, + interviewer_start_date, + management_start_date +) VALUES + ('OU-NORTH', 'SIMPSONS2020X00', + EXTRACT(EPOCH FROM NOW() + INTERVAL '1 month') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day') * 1000, + EXTRACT(EPOCH FROM NOW() + INTERVAL '2 months') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '2 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '4 days') * 1000), + + ('OU-NORTH', 'VQS2021X00', + EXTRACT(EPOCH FROM NOW() + INTERVAL '1 month') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day') * 1000, + EXTRACT(EPOCH FROM NOW() + INTERVAL '2 months') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '2 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '4 days') * 1000), + + ('OU-SOUTH', 'VQS2021X00', + EXTRACT(EPOCH FROM NOW() + INTERVAL '1 month') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day') * 1000, + EXTRACT(EPOCH FROM NOW() + INTERVAL '2 months') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '2 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '4 days') * 1000), + + ('OU-SOUTH', 'SIMPSONS2020X00', + EXTRACT(EPOCH FROM NOW() + INTERVAL '1 month') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day') * 1000, + EXTRACT(EPOCH FROM NOW() + INTERVAL '2 months') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '2 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '4 days') * 1000), + + ('OU-SOUTH', 'ZCLOSEDX00', + EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '4 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '5 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '6 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '7 days') * 1000), + + ('OU-WEST', 'ZCLOSEDX00', + EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '4 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '5 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '6 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '7 days') * 1000), + + ('OU-SOUTH', 'XCLOSEDX00', + EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '4 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '5 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '6 days') * 1000, + EXTRACT(EPOCH FROM NOW() - INTERVAL '7 days') * 1000); + +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '11', TRUE, a.id, 'SIMPSONS2020X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Ted Farmer' AND s.bs='11'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '12', TRUE, a.id, 'SIMPSONS2020X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Cecilia Ortega' AND s.bs='12'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '13', FALSE, a.id, 'SIMPSONS2020X00', 'INTW2', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Claude Watkins' AND s.bs='13'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '14', FALSE, a.id, 'SIMPSONS2020X00', 'INTW3', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Veronica Gill' AND s.bs='14'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '20', FALSE, a.id, 'VQS2021X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Christine Aguilar' AND s.bs='20'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '21', FALSE, a.id, 'VQS2021X00', 'INTW2', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Louise Walker' AND s.bs='21'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '22', FALSE, a.id, 'VQS2021X00', 'INTW4', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Anthony Bennett' AND s.bs='22'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '23', FALSE, a.id, 'VQS2021X00', 'INTW4', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Christopher Lewis' AND s.bs='23'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '24', TRUE, a.id, 'SIMPSONS2020X00', NULL, s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Laurent Neville' AND s.bs='24'; + + +INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES + ('test@test.com',TRUE, 'Ted', 'Farmer', 11111111, 0, TRUE, '11'), + ('test@test.com', TRUE,'Cecilia', 'Ortega', 11111111, 1, TRUE, '12'), + ('test@test.com', TRUE,'Claude', 'Watkins', 11111111, 0, TRUE, '13'), + ('test@test.com', TRUE,'Veronica', 'Baker', 11111111, 1, TRUE, '14'), + ('test@test.com', TRUE,'Christine', 'Aguilar', 11111111, 1, FALSE, '11'), + ('test@test.com', TRUE,'Louise', 'Walker', 11111111, 1, FALSE, '11'), + ('test@test.com', TRUE,'Anthony', 'Bennett', 11111111, 0, FALSE, '12'), + ('test@test.com', TRUE,'Christopher', 'Lewis', 11111111, 0, FALSE, '14'), + ('test@test.com', TRUE,'Harriette', 'Raymond', 11111111, 0, TRUE, '20'), + ('test@test.com', TRUE,'Aimée', 'Lamothe', 11111111, 0, TRUE, '21'), + ('test@test.com', TRUE,'Perrin', 'Blanchard', 11111111, 0, TRUE, '22'), + ('test@test.com', TRUE,'Artus', 'Arnoux', 11111111, 0, TRUE, '23'), + ('test@test.com', TRUE,'Laurent', 'Neville', 11111111, 0, TRUE, '24'); + + + +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Ted' and p.last_name='Farmer' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT FALSE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Ted' and p.last_name='Farmer' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Cecilia' and p.last_name='Ortega' and p.survey_unit_id='12'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Claude' and p.last_name='Watkins' and p.survey_unit_id='13'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Veronica' and p.last_name='Baker' and p.survey_unit_id='14'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Christine' and p.last_name='Aguilar' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Louise' and p.last_name='Walker' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Anthony' and p.last_name='Bennett' and p.survey_unit_id='12'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Christopher' and p.last_name='Lewis' and p.survey_unit_id='14'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Harriette' and p.last_name='Raymond' and p.survey_unit_id='20'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Aimée' and p.last_name='Lamothe' and p.survey_unit_id='21'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Perrin' and p.last_name='Blanchard' and p.survey_unit_id='22'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Artus' and p.last_name='Arnoux' and p.survey_unit_id='23'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Laurent' and p.last_name='Neville' and p.survey_unit_id='24'; + + + +INSERT INTO public.state (date, type, survey_unit_id) VALUES + (111112111,'VIN', '11'), + (110111111,'NNS', '11'), + (111111111,'TBR', '12'), + (111111111,'TBR', '13'), + (111111111,'TBR', '14'), + (101111111,'TBR', '11'), + (101111111,'TBR', '24'), + (1590504478334, 'VIC', '20'), + (1590504478334, 'VIC', '21'), + (1590504478334, 'FIN', '22'), + (1590504478334, 'VIC', '23'); + +INSERT INTO public.contact_outcome (date, type, survey_unit_id) VALUES + (1590504478334, 'DUK', '24'); + +INSERT INTO public.comment (type, value, survey_unit_id) VALUES + ('INTERVIEWER', 'un commentaire', '13'); + +INSERT INTO closing_cause (date, type, survey_unit_id) VALUES + (EXTRACT(EPOCH FROM NOW() - INTERVAL '3 days') * 1000, 'NPI', '11'); + + +INSERT INTO public.identification (survey_unit_id, identification,access,situation,category,occupant) VALUES + ('11', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED'); + +INSERT INTO public.identification (survey_unit_id, identification,access,situation,category,occupant) VALUES + ('21', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED'); \ No newline at end of file diff --git a/src/main/resources/db/dataset/reinit-test-data.sql b/src/main/resources/db/dataset/reinit-test-data.sql new file mode 100644 index 00000000..809c3aea --- /dev/null +++ b/src/main/resources/db/dataset/reinit-test-data.sql @@ -0,0 +1,222 @@ +--changeset davdarras:reset-data context:test + +SET REFERENTIAL_INTEGRITY FALSE; +TRUNCATE TABLE public.campaign_message_recipient; +TRUNCATE TABLE public.contact_attempt; +TRUNCATE TABLE public.message_status; +TRUNCATE TABLE public.oumessage_recipient; +TRUNCATE TABLE public.referent; +TRUNCATE TABLE public.message; +TRUNCATE TABLE public.interviewer; +TRUNCATE TABLE public.sample_identifier; +TRUNCATE TABLE public.user; +TRUNCATE TABLE public.campaign; +TRUNCATE TABLE public.preference; +TRUNCATE TABLE public.visibility; +TRUNCATE TABLE public.survey_unit; +TRUNCATE TABLE public.identification; +TRUNCATE TABLE public.person; +TRUNCATE TABLE public.phone_number; +TRUNCATE TABLE public.state; +TRUNCATE TABLE public.contact_outcome; +TRUNCATE TABLE public.comment; +TRUNCATE TABLE public.closing_cause; +TRUNCATE TABLE public.organization_unit; +TRUNCATE TABLE public.address; + +--changeset davdarras:init-data context:test + +INSERT INTO public.address (dtype, l1, l2, l3, l4, l5, l6, l7, elevator, building, floor, door, staircase, city_priority_district) VALUES + ('InseeAddress', 'Ted Farmer' ,'','','1 rue de la gare' ,'','29270 Carhaix' ,'France', true, 'Bat. C', 'Etg 4', 'Porte 48', 'Escalier B', true), + ('InseeAddress', 'Cecilia Ortega' ,'','','2 place de la mairie' ,'','90000 Belfort' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Claude Watkins' ,'','','3 avenue de la République' ,'','32230 Marciac' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Veronica Gill' ,'','','4 chemin du ruisseau' ,'','44190 Clisson' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Christine Aguilar' ,'','','5 rue de l''école' ,'','59620 Aulnoye-Aimeries' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Louise Walker' ,'','','6 impasse du lac' ,'','38200 Vienne' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Anthony Bennett' ,'','','7 avenue de la Liberté' ,'','62000 Arras' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Christopher Lewis' ,'','','8 route du moulin' ,'','35000 Rennes' ,'France', false, null, null, null, null, false), + ('InseeAddress', 'Laurent Neville' ,'','','5 route du sapin' ,'','35000 Rennes' ,'France', false, null, null, null, null, false); + +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-NATIONAL', 'National organizational unit', 'NATIONAL', null); +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-NORTH', 'North region organizational unit', 'LOCAL', 'OU-NATIONAL'); +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-SOUTH', 'South region organizational unit', 'LOCAL', 'OU-NATIONAL'); +INSERT INTO public.organization_unit (id, label, type, organization_unit_parent_id) VALUES ('OU-WEST', 'West region organizational unit', 'LOCAL', 'OU-NATIONAL'); + +INSERT INTO public.interviewer (id, email, first_name, last_name, phone_number) VALUES + ('INTW1', 'margie.lucas@ou.com', 'Margie', 'Lucas', '+3391231231230'), + ('INTW2', 'carlton.campbell@ou.com', 'Carlton', 'Campbell', '+3391231231231'), + ('INTW3', 'gerald.edwards@ou.com', 'Gerald', 'Edwards', '+3391231231231'), + ('INTW4', 'melody.grant@ou.com', 'Melody', 'Grant', '+3391231231231'); + +INSERT INTO public.sample_identifier (dtype, autre, bs, ec, le, nograp, noi, nole, nolog, numfa, rges, ssech) VALUES + ('InseeSampleIdentifier', '11', 11, '1', 11, '11', 11, 11, 11, 11, 11, 1), + ('InseeSampleIdentifier', '12', 12, '1', 12, '12', 12, 12, 12, 12, 12, 1), + ('InseeSampleIdentifier', '13', 13, '1', 13, '13', 13, 13, 13, 13, 13, 2), + ('InseeSampleIdentifier', '14', 14, '1', 14, '14', 14, 14, 14, 14, 14, 3), + ('InseeSampleIdentifier', '20', 20, '2', 20, '20', 20, 20, 20, 20, 20, 1), + ('InseeSampleIdentifier', '21', 21, '2', 21, '21', 21, 21, 21, 21, 21, 1), + ('InseeSampleIdentifier', '22', 22, '2', 22, '22', 22, 22, 22, 22, 22, 2), + ('InseeSampleIdentifier', '23', 23, '2', 23, '23', 23, 23, 23, 23, 23, 1), + ('InseeSampleIdentifier', '24', 24, '2', 24, '24', 24, 24, 24, 24, 24, 1); + +INSERT INTO public.USER (id, first_name, last_name, organization_unit_id) VALUES + ('ABC', 'Melinda', 'Webb', 'OU-NORTH'), + ('DEF', 'Everett', 'Juste', 'OU-NORTH'), + ('GHI', 'Elsie', 'Clarke', 'OU-SOUTH'), + ('JKL', 'Julius', 'Howell', 'OU-NATIONAL'), + ('MNO', 'Ted', 'Kannt', 'OU-WEST'), + ('GUEST', 'firstname', 'lastname', 'OU-NORTH'); + +INSERT INTO public.campaign (id, label, email, identification_configuration, contact_attempt_configuration, contact_outcome_configuration) VALUES + ('SIMPSONS2020X00', 'Survey on the Simpsons tv show 2020', 'first.email@test.com', 'IASCO', 'F2F', 'F2F'), + ('VQS2021X00', 'Everyday life and health survey 2021', 'second.email@test.com', 'IASCO', 'TEL', 'TEL'), + ('ZCLOSEDX00', 'Everyday life and health survey 2021', 'third.email@test.com', 'IASCO', 'F2F', 'F2F'), + ('XCLOSEDX00', 'Everyday life and health survey 2021', 'fourth.email@test.com', 'IASCO', 'TEL', 'TEL'); + +INSERT INTO public.preference (id_user, id_campaign) VALUES + ('GHI', 'SIMPSONS2020X00'), + ('JKL', 'SIMPSONS2020X00'), + ('JKL', 'VQS2021X00'); + + +INSERT INTO visibility ( + organization_unit_id, + campaign_id, + collection_end_date, + collection_start_date, + end_date, + identification_phase_start_date, + interviewer_start_date, + management_start_date +) VALUES + ('OU-NORTH', 'SIMPSONS2020X00', + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -4, CURRENT_TIMESTAMP())) * 1000), + + ('OU-NORTH', 'VQS2021X00', + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -4, CURRENT_TIMESTAMP())) * 1000), + + ('OU-SOUTH', 'VQS2021X00', + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -4, CURRENT_TIMESTAMP())) * 1000), + + ('OU-SOUTH', 'SIMPSONS2020X00', + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('MONTH', 2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -2, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -4, CURRENT_TIMESTAMP())) * 1000), + + ('OU-SOUTH', 'ZCLOSEDX00', + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -4, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -5, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -6, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -7, CURRENT_TIMESTAMP())) * 1000), + + ('OU-WEST', 'ZCLOSEDX00', + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -4, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -5, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -6, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -7, CURRENT_TIMESTAMP())) * 1000), + + ('OU-SOUTH', 'XCLOSEDX00', + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -3, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -4, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -1, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -5, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -6, CURRENT_TIMESTAMP())) * 1000, + DATEDIFF('SECOND', '1970-01-01 00:00:00', DATEADD('DAY', -7, CURRENT_TIMESTAMP())) * 1000); + +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '11', TRUE, a.id, 'SIMPSONS2020X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Ted Farmer' AND s.bs='11'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '12', TRUE, a.id, 'SIMPSONS2020X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Cecilia Ortega' AND s.bs='12'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '13', FALSE, a.id, 'SIMPSONS2020X00', 'INTW2', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Claude Watkins' AND s.bs='13'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '14', FALSE, a.id, 'SIMPSONS2020X00', 'INTW3', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Veronica Gill' AND s.bs='14'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '20', FALSE, a.id, 'VQS2021X00', 'INTW1', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Christine Aguilar' AND s.bs='20'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '21', FALSE, a.id, 'VQS2021X00', 'INTW2', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Louise Walker' AND s.bs='21'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '22', FALSE, a.id, 'VQS2021X00', 'INTW4', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Anthony Bennett' AND s.bs='22'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '23', FALSE, a.id, 'VQS2021X00', 'INTW4', s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Christopher Lewis' AND s.bs='23'; +INSERT INTO public.survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) SELECT '24', TRUE, a.id, 'SIMPSONS2020X00', NULL, s.id, 'OU-NORTH' FROM address a, sample_identifier s WHERE a.l1='Laurent Neville' AND s.bs='24'; + + +INSERT INTO public.person (email, favorite_email, first_name, last_name, birthdate, title, privileged, survey_unit_id) VALUES + ('test@test.com',TRUE, 'Ted', 'Farmer', 11111111, 0, TRUE, '11'), + ('test@test.com', TRUE,'Cecilia', 'Ortega', 11111111, 1, TRUE, '12'), + ('test@test.com', TRUE,'Claude', 'Watkins', 11111111, 0, TRUE, '13'), + ('test@test.com', TRUE,'Veronica', 'Baker', 11111111, 1, TRUE, '14'), + ('test@test.com', TRUE,'Christine', 'Aguilar', 11111111, 1, FALSE, '11'), + ('test@test.com', TRUE,'Louise', 'Walker', 11111111, 1, FALSE, '11'), + ('test@test.com', TRUE,'Anthony', 'Bennett', 11111111, 0, FALSE, '12'), + ('test@test.com', TRUE,'Christopher', 'Lewis', 11111111, 0, FALSE, '14'), + ('test@test.com', TRUE,'Harriette', 'Raymond', 11111111, 0, TRUE, '20'), + ('test@test.com', TRUE,'Aimée', 'Lamothe', 11111111, 0, TRUE, '21'), + ('test@test.com', TRUE,'Perrin', 'Blanchard', 11111111, 0, TRUE, '22'), + ('test@test.com', TRUE,'Artus', 'Arnoux', 11111111, 0, TRUE, '23'), + ('test@test.com', TRUE,'Laurent', 'Neville', 11111111, 0, TRUE, '24'); + + + +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Ted' and p.last_name='Farmer' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT FALSE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Ted' and p.last_name='Farmer' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Cecilia' and p.last_name='Ortega' and p.survey_unit_id='12'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Claude' and p.last_name='Watkins' and p.survey_unit_id='13'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Veronica' and p.last_name='Baker' and p.survey_unit_id='14'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Christine' and p.last_name='Aguilar' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Louise' and p.last_name='Walker' and p.survey_unit_id='11'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Anthony' and p.last_name='Bennett' and p.survey_unit_id='12'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Christopher' and p.last_name='Lewis' and p.survey_unit_id='14'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Harriette' and p.last_name='Raymond' and p.survey_unit_id='20'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Aimée' and p.last_name='Lamothe' and p.survey_unit_id='21'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Perrin' and p.last_name='Blanchard' and p.survey_unit_id='22'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Artus' and p.last_name='Arnoux' and p.survey_unit_id='23'; +INSERT INTO public.phone_number (favorite, number, source, person_id) SELECT TRUE,'+33677542802', 0, p.id FROM person p WHERE p.first_name='Laurent' and p.last_name='Neville' and p.survey_unit_id='24'; + + + +INSERT INTO public.state (date, type, survey_unit_id) VALUES + (111112111,'VIN', '11'), + (110111111,'NNS', '11'), + (111111111,'TBR', '12'), + (111111111,'TBR', '13'), + (111111111,'TBR', '14'), + (101111111,'TBR', '11'), + (101111111,'TBR', '24'), + (1590504478334, 'VIC', '20'), + (1590504478334, 'VIC', '21'), + (1590504478334, 'FIN', '22'), + (1590504478334, 'VIC', '23'); + +INSERT INTO public.contact_outcome (date, type, survey_unit_id) VALUES + (1590504478334, 'DUK', '24'); + +INSERT INTO public.comment (type, value, survey_unit_id) VALUES + ('INTERVIEWER', 'un commentaire', '13'); + +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'); + +INSERT INTO public.identification (survey_unit_id, identification,access,situation,category,occupant) VALUES + ('21', 'IDENTIFIED', 'ACC', 'ORDINARY', 'PRIMARY', 'IDENTIFIED'); + +SET REFERENTIAL_INTEGRITY TRUE; \ No newline at end of file diff --git a/src/main/resources/db/demo.xml b/src/main/resources/db/demo.xml new file mode 100644 index 00000000..b0495e09 --- /dev/null +++ b/src/main/resources/db/demo.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/src/main/resources/db/integration-test.xml b/src/main/resources/db/integration-test.xml new file mode 100644 index 00000000..a4bd6a62 --- /dev/null +++ b/src/main/resources/db/integration-test.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/src/test/java/fr/insee/pearljam/api/authKeycloak/TestAuthKeyCloak.java b/src/test/java/fr/insee/pearljam/api/authKeycloak/TestAuthKeyCloak.java index 70782c07..b6fb6d3e 100644 --- a/src/test/java/fr/insee/pearljam/api/authKeycloak/TestAuthKeyCloak.java +++ b/src/test/java/fr/insee/pearljam/api/authKeycloak/TestAuthKeyCloak.java @@ -111,7 +111,6 @@ import fr.insee.pearljam.api.repository.UserRepository; import fr.insee.pearljam.api.repository.VisibilityRepository; import fr.insee.pearljam.api.utils.AuthenticatedUserTestHelper; -import liquibase.Liquibase; import lombok.RequiredArgsConstructor; /* Test class for Keycloak Authentication */ @@ -138,15 +137,12 @@ class TestAuthKeyCloak { private final ReferentService referentservice; private final MessageService messageService; private final PreferenceService preferenceService; - private final DataSetInjectorService injectorService; private final MockMvc mockMvc; private final RestTemplate restTemplate; private MockRestServiceServer mockServer; - public Liquibase liquibase; - static Authentication LOCAL_USER = AuthenticatedUserTestHelper.AUTH_LOCAL_USER; static Authentication INTERVIEWER = AuthenticatedUserTestHelper.AUTH_INTERVIEWER; static Authentication ADMIN = AuthenticatedUserTestHelper.AUTH_ADMIN; @@ -159,7 +155,6 @@ class TestAuthKeyCloak { @BeforeEach public void setUp() { mockServer = MockRestServiceServer.createServer(restTemplate); - injectorService.createDataSet(); } private ResultMatcher expectValidManagementStartDate() { diff --git a/src/test/java/fr/insee/pearljam/api/noAuth/TestNoAuth.java b/src/test/java/fr/insee/pearljam/api/noAuth/TestNoAuth.java index 357e7c7e..6f85190e 100644 --- a/src/test/java/fr/insee/pearljam/api/noAuth/TestNoAuth.java +++ b/src/test/java/fr/insee/pearljam/api/noAuth/TestNoAuth.java @@ -1,6 +1,7 @@ package fr.insee.pearljam.api.noAuth; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -12,13 +13,10 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; - import com.jayway.jsonpath.JsonPath; -import fr.insee.pearljam.api.service.DataSetInjectorService; +import fr.insee.pearljam.api.utils.ScriptConstants; import org.json.JSONException; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -27,6 +25,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestConstructor; +import org.springframework.test.context.jdbc.Sql; import org.springframework.test.web.servlet.MockMvc; import com.fasterxml.jackson.core.JsonProcessingException; @@ -53,23 +52,6 @@ class TestNoAuth { private final MessageRepository messageRepository; private final ClosingCauseRepository closingCauseRepository; private final MockMvc mockMvc; - private final DataSetInjectorService injectorService; - - @BeforeEach - public void clearDataSet() { - injectorService.deleteDataSet(); - } - - /** - * This method set up the dataBase content - * - * @throws Exception - * - */ - @BeforeEach - public void initDataSetIfNotPresent() { - injectorService.createDataSet(); - } private ResultMatcher expectValidManagementStartDate() { return expectTimestampFromCurrentDate("$[0].managementStartDate", -4, ChronoUnit.DAYS); @@ -118,7 +100,6 @@ private ResultMatcher expectTimestampFromCurrentDate(String expression, int unit */ @Test - @Order(1) void testGetCampaign() throws Exception { mockMvc.perform(get("/api/campaigns") .accept(MediaType.APPLICATION_JSON)) @@ -142,7 +123,7 @@ void testGetCampaign() throws Exception { } @Test - @Order(2) + @Sql(value = ScriptConstants.REINIT_SQL_SCRIPT, executionPhase = AFTER_TEST_METHOD) void testPutClosingCauseNoPreviousClosingCause() throws Exception { mockMvc.perform(put("/api/survey-unit/11/closing-cause/NPI") .accept(MediaType.APPLICATION_JSON)) @@ -159,7 +140,7 @@ void testPutClosingCauseNoPreviousClosingCause() throws Exception { * @throws JsonProcessingException */ @Test - @Order(3) + @Sql(value = ScriptConstants.REINIT_SQL_SCRIPT, executionPhase = AFTER_TEST_METHOD) void testPostMessage() throws Exception { List recipients = new ArrayList(); recipients.add("SIMPSONS2020X00"); @@ -175,5 +156,4 @@ void testPostMessage() throws Exception { .findMessagesDtoByIds(messageRepository.getMessageIdsByInterviewer("INTW1")); assertEquals("TEST", messages.get(0).getText()); } - } diff --git a/src/test/java/fr/insee/pearljam/api/utils/ScriptConstants.java b/src/test/java/fr/insee/pearljam/api/utils/ScriptConstants.java new file mode 100644 index 00000000..498e2125 --- /dev/null +++ b/src/test/java/fr/insee/pearljam/api/utils/ScriptConstants.java @@ -0,0 +1,5 @@ +package fr.insee.pearljam.api.utils; + +public class ScriptConstants { + public static final String REINIT_SQL_SCRIPT = "classpath:db/dataset/reinit-test-data.sql"; +} \ No newline at end of file diff --git a/src/test/resources/application-auth.properties b/src/test/resources/application-auth.properties deleted file mode 100644 index c62869df..00000000 --- a/src/test/resources/application-auth.properties +++ /dev/null @@ -1,46 +0,0 @@ -spring.application.name=api -# spring.profiles.active=test - -application.auth=keycloak -application.corsOrigins='*' - -application.roles.interviewer=interviewer_access -application.roles.local_user=local_manager_access -application.roles.national_user=national_manager_access -application.roles.admin=admin_access -application.roles.webclient=webclient_access - -fr.insee.pearljam.application.guestOU=OU-POLE - -spring.liquibase.enabled=true -spring.liquibase.defaultSchema=public -spring.liquibase.contexts=test -spring.liquibase.changeLog=classpath:db/master.xml - -logging.level.root=INFO - -logging.level.liquibase=WARN - -feature.oidc.enabled=true - -#Datacollection config -fr.insee.pearljam.datacollection.service.url.scheme=http -fr.insee.pearljam.datacollection.service.url.host=localhost -fr.insee.pearljam.datacollection.service.url.port=8081 - -#Mail service config -fr.insee.pearljam.mail.service.url.scheme=http -fr.insee.pearljam.mail.service.url.host=localhost -fr.insee.pearljam.mail.service.url.port=8082 -fr.insee.pearljam.mail.service.recipients.list=pearl@pearljam.fr,jam@pearljam.fr -fr.insee.pearljam.mail.service.url.login=pearljam -fr.insee.pearljam.mail.service.url.password=pearljam - -# local database -spring.datasource.url=jdbc:h2:mem:testauthdb;NON_KEYWORDS=user,value;DATABASE_TO_UPPER=TRUE;DEFAULT_NULL_ORDERING=HIGH;INIT=create domain if not exists jsonb as json;MODE=PostgreSQL -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.username=sa -spring.datasource.password=password - -# test verbosity -spring.test.mockmvc.print=none diff --git a/src/test/resources/application-auth.yml b/src/test/resources/application-auth.yml new file mode 100644 index 00000000..d5549271 --- /dev/null +++ b/src/test/resources/application-auth.yml @@ -0,0 +1,52 @@ +application: + corsOrigins: '*' + roles: + interviewer: interviewer_access + local_user: local_manager_access + national_user: national_manager_access + admin: admin_access + webclient: webclient_access + +spring: + application: + name: api + liquibase: + enabled: true + contexts: test + defaultSchema: public + change-log: classpath:db/integration-test.xml + datasource: + url: jdbc:h2:mem:testauthdb;NON_KEYWORDS=user,value;DATABASE_TO_UPPER=TRUE;DEFAULT_NULL_ORDERING=HIGH;INIT=create domain if not exists jsonb as json;MODE=PostgreSQL + driverClassName: org.h2.Driver + username: sa + password: password +logging: + level: + root: INFO + liquibase: WARN + +feature: + oidc: + enabled: true + +fr: + insee: + pearljam: + #Datacollection config + datacollection: + service: + url: + scheme: http + host: localhost + port: 8081 + #Mail service config + mail: + service: + url: + scheme: http + host: localhost + port: 8082 + login: pearljam + password: pearljam + recipients: + list: pearl@pearljam.fr,jam@pearljam.fr \ No newline at end of file diff --git a/src/test/resources/application-noauth.properties b/src/test/resources/application-noauth.properties deleted file mode 100644 index beb16123..00000000 --- a/src/test/resources/application-noauth.properties +++ /dev/null @@ -1,46 +0,0 @@ -spring.application.name=api -# spring.profiles.active=test - -application.auth=keycloak -application.corsOrigins='*' - -application.roles.interviewer=interviewer_access -application.roles.local_user=local_manager_access -application.roles.national_user=national_manager_access -application.roles.admin=admin_access -application.roles.webclient=webclient_access - -fr.insee.pearljam.application.guestOU=OU-POLE - -spring.liquibase.enabled=true -spring.liquibase.defaultSchema=public -spring.liquibase.contexts=test -spring.liquibase.changeLog=classpath:db/master.xml - -logging.level.root=INFO - -logging.level.liquibase=WARN - -feature.oidc.enabled=false - -#Datacollection config -fr.insee.pearljam.datacollection.service.url.scheme=http -fr.insee.pearljam.datacollection.service.url.host=localhost -fr.insee.pearljam.datacollection.service.url.port=8081 - -#Mail service config -fr.insee.pearljam.mail.service.url.scheme=http -fr.insee.pearljam.mail.service.url.host=localhost -fr.insee.pearljam.mail.service.url.port=8082 -fr.insee.pearljam.mail.service.recipients.list=pearl@pearljam.fr,jam@pearljam.fr -fr.insee.pearljam.mail.service.url.login=pearljam -fr.insee.pearljam.mail.service.url.password=pearljam - -# local database -spring.datasource.url=jdbc:h2:mem:testnoauthdb;NON_KEYWORDS=user,value;DATABASE_TO_UPPER=TRUE;DEFAULT_NULL_ORDERING=HIGH;INIT=create domain if not exists jsonb as json;MODE=PostgreSQL -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.username=sa -spring.datasource.password=password - -# test verbosity -spring.test.mockmvc.print=none diff --git a/src/test/resources/application-noauth.yml b/src/test/resources/application-noauth.yml new file mode 100644 index 00000000..866b0b94 --- /dev/null +++ b/src/test/resources/application-noauth.yml @@ -0,0 +1,52 @@ +application: + corsOrigins: '*' + roles: + interviewer: interviewer_access + local_user: local_manager_access + national_user: national_manager_access + admin: admin_access + webclient: webclient_access + +spring: + application: + name: api + liquibase: + enabled: true + contexts: test + defaultSchema: public + change-log: classpath:db/integration-test.xml + datasource: + url: jdbc:h2:mem:testnoauthdb;NON_KEYWORDS=user,value;DATABASE_TO_UPPER=TRUE;DEFAULT_NULL_ORDERING=HIGH;INIT=create domain if not exists jsonb as json;MODE=PostgreSQL + driverClassName: org.h2.Driver + username: sa + password: password + +logging: + level: + root: INFO + +feature: + oidc: + enabled: false + +fr: + insee: + pearljam: + #Datacollection config + datacollection: + service: + url: + scheme: http + host: localhost + port: 8081 + #Mail service config + mail: + service: + url: + scheme: http + host: localhost + port: 8082 + login: pearljam + password: pearljam + recipients: + list: pearl@pearljam.fr,jam@pearljam.fr \ No newline at end of file