From 38df44c5cd7f93d145e6944ad23391730f058e8b Mon Sep 17 00:00:00 2001 From: Betty Becuwe <77614323+BettyB979@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:52:00 +0100 Subject: [PATCH] Fix moog extraction (#100) * fix: moog extraction slow (n+1 requests) * refactor: sonar issues * chore: update spring boot version * refactor: sonar issues on tests * fix: sonar issues * refactor: review changes --- .../configuration/LogInterceptor.java | 1 + .../configuration/OpenAPIConfiguration.java | 45 +-- .../configuration/PropertyLogger.java | 2 +- ...acollectionManagementApplicationTests.java | 15 - .../controller/AddressControllerTest.java | 7 - .../controller/ContactControllerTest.java | 1 - .../dataloader/DataloaderTest.java | 4 - .../MyQuestioningsControllerTest.java | 8 +- ...estionningAccreditationControllerTest.java | 20 +- .../QuestionningControllerTest.java | 5 - .../QuestionningEventControllerTest.java | 4 +- .../controller/UserEventControllerTest.java | 1 - .../contact/domain/Address.java | 14 - .../query/repository/MoogRepository.java | 368 ++++++++++-------- .../contact/service/AddressService.java | 12 +- .../dataloader/DataloaderPoc.java | 91 ++--- .../metadata/enums/PeriodEnum.java | 261 ++++++------- .../metadata/enums/PeriodNameEnum.java | 41 ++ pom.xml | 4 +- 19 files changed, 443 insertions(+), 461 deletions(-) delete mode 100644 platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/DatacollectionManagementApplicationTests.java create mode 100644 platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodNameEnum.java diff --git a/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/LogInterceptor.java b/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/LogInterceptor.java index 17dbcc64..84b2b934 100644 --- a/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/LogInterceptor.java +++ b/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/LogInterceptor.java @@ -42,6 +42,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mv) { + // no need to posthandle things for this interceptor } diff --git a/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/OpenAPIConfiguration.java b/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/OpenAPIConfiguration.java index 2ad16862..858e12c7 100644 --- a/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/OpenAPIConfiguration.java +++ b/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/OpenAPIConfiguration.java @@ -27,34 +27,31 @@ public class OpenAPIConfiguration { @Bean public OpenAPI customOpenAPI() { - switch(applicationConfig.getAuthType()) { - - case AuthConstants.OIDC: - - OAuthFlows flows = new OAuthFlows(); - OAuthFlow flow = new OAuthFlow(); - - flow.setAuthorizationUrl(applicationConfig.getKeyCloakUrl() + "/realms/" + applicationConfig.getKeycloakRealm() + "/protocol/openid-connect/auth"); - flow.setTokenUrl(applicationConfig.getKeyCloakUrl() + "/realms/" + applicationConfig.getKeycloakRealm() + "/protocol/openid-connect/token"); - Scopes scopes = new Scopes(); - // scopes.addString("global", "accessEverything"); - flow.setScopes(scopes); - flows = flows.authorizationCode(flow); - - return new OpenAPI() - .components( - new Components().addSecuritySchemes("oauth2", new SecurityScheme().type(SecurityScheme.Type.OAUTH2).flows(flows))) - .info(new Info().title(buildProperties.getName()).version(buildProperties.getVersion())) - .addSecurityItem(new SecurityRequirement().addList("oauth2", Arrays.asList("read", "write"))); - - default: - return new OpenAPI() - .info(new Info().title(buildProperties.getName()).version(buildProperties.getVersion())); - + if (applicationConfig.getAuthType().equals(AuthConstants.OIDC)) { + OAuthFlows flows = getoAuthFlows(); + + return new OpenAPI() + .components( + new Components().addSecuritySchemes("oauth2", new SecurityScheme().type(SecurityScheme.Type.OAUTH2).flows(flows))) + .info(new Info().title(buildProperties.getName()).version(buildProperties.getVersion())) + .addSecurityItem(new SecurityRequirement().addList("oauth2", Arrays.asList("read", "write"))); } + return new OpenAPI() + .info(new Info().title(buildProperties.getName()).version(buildProperties.getVersion())); } + private OAuthFlows getoAuthFlows() { + OAuthFlows flows = new OAuthFlows(); + OAuthFlow flow = new OAuthFlow(); + + flow.setAuthorizationUrl(applicationConfig.getKeyCloakUrl() + "/realms/" + applicationConfig.getKeycloakRealm() + "/protocol/openid-connect/auth"); + flow.setTokenUrl(applicationConfig.getKeyCloakUrl() + "/realms/" + applicationConfig.getKeycloakRealm() + "/protocol/openid-connect/token"); + Scopes scopes = new Scopes(); + flow.setScopes(scopes); + flows = flows.authorizationCode(flow); + return flows; + } } diff --git a/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/PropertyLogger.java b/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/PropertyLogger.java index 2746a48d..b5432164 100644 --- a/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/PropertyLogger.java +++ b/platine-management-api/src/main/java/fr/insee/survey/datacollectionmanagement/configuration/PropertyLogger.java @@ -29,7 +29,7 @@ public void handleContextRefresh(ContextRefreshedEvent event) { log.info("================================ Properties ================================"); final MutablePropertySources sources = ((AbstractEnvironment) env).getPropertySources(); StreamSupport.stream(sources.spliterator(), false) - .filter(ps -> ps instanceof EnumerablePropertySource) + .filter(EnumerablePropertySource.class::isInstance) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()) .flatMap(Arrays::stream) .distinct() diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/DatacollectionManagementApplicationTests.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/DatacollectionManagementApplicationTests.java deleted file mode 100644 index 36d8de69..00000000 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/DatacollectionManagementApplicationTests.java +++ /dev/null @@ -1,15 +0,0 @@ -package fr.insee.survey.datacollectionmanagement; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - -@SpringBootTest -@EnableJpaRepositories -class DatacollectionManagementApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressControllerTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressControllerTest.java index 08c1a6fa..4093f238 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressControllerTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressControllerTest.java @@ -99,13 +99,6 @@ void putAddressCreateUpdate() throws Exception { assertEquals(contactAfterUpdate.getAddress().getStreetName(), addressUpdated.getStreetName()); assertEquals(contactAfterUpdate.getAddress().getCountryName(), addressUpdated.getCountryName()); - // back to before - contact.setAddress(addressBefore); - addressService.saveAddress(addressBefore); - contactService.saveContact(contact); - assertEquals(contact.getAddress().getCityName(), addressBefore.getCityName()); - assertEquals(contact.getAddress().getStreetName(), addressBefore.getStreetName()); - assertEquals(contact.getAddress().getCountryName(), addressBefore.getCountryName()); } diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactControllerTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactControllerTest.java index c181e7bc..b3fb974f 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactControllerTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactControllerTest.java @@ -103,7 +103,6 @@ void putContactCreateUpdateDelete() throws Exception { assertEquals(contact.getFirstName(), contactFound.getFirstName()); assertEquals(contact.getEmail(), contactFound.getEmail()); List list = new ArrayList<>(contactEventService.findContactEventsByContact(contactFound)); - // List list = new ArrayList<>(contactFound.getContactEvents()); assertEquals(1, list.size()); assertEquals(ContactEventTypeEnum.create, list.get(0).getType()); diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderTest.java index f80afd13..381b3422 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderTest.java @@ -271,7 +271,6 @@ private void initMetadata() throws ParseException { Date openingDate = sdf.parse("01/01/" + year); Date closingDate = sdf.parse("31/12/" + year); Date returnDate = sdf.parse("01/06/" + year); - Date today = sdf.parse("31/12/" + year); part.setOpeningDate(openingDate); part.setClosingDate(closingDate); @@ -313,7 +312,6 @@ private void initQuestionning(Faker faker) { QuestioningAccreditation accreditation; Set questioningAccreditations; String fakeSiren; - Random qeRan = new Random(); for (Long i = surveyUnitRepository.count(); i < 10; i++) { SurveyUnit su = new SurveyUnit(); @@ -326,7 +324,6 @@ private void initQuestionning(Faker faker) { } for (Long i = nbExistingQuestionings; i < 10; i++) { qu = new Questioning(); - qe = new QuestioningEvent(); List qeList = new ArrayList<>(); questioningAccreditations = new HashSet<>(); @@ -344,7 +341,6 @@ private void initQuestionning(Faker faker) { // questioning events // everybody in INITLA Optional part = partitioningRepository.findById(qu.getIdPartitioning()); - Date eventDate = today; qeList.add(new QuestioningEvent( faker.date().between(part.get().getOpeningDate(), part.get().getClosingDate()), diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsControllerTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsControllerTest.java index aeba0487..5708855d 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsControllerTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsControllerTest.java @@ -5,12 +5,10 @@ import fr.insee.survey.datacollectionmanagement.constants.AuthorityRoleEnum; import fr.insee.survey.datacollectionmanagement.constants.Constants; import fr.insee.survey.datacollectionmanagement.query.dto.MyQuestioningDto; -import fr.insee.survey.datacollectionmanagement.query.service.CheckHabilitationService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -29,11 +27,7 @@ class MyQuestioningsControllerTest { @Autowired - private MockMvc mockMvc; - - @MockBean - private CheckHabilitationService checkAccreditationService; - + MockMvc mockMvc; @Test void myQuestioningsContactNotExist() throws Exception { diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningAccreditationControllerTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningAccreditationControllerTest.java index 071c1e0e..a66c3cee 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningAccreditationControllerTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningAccreditationControllerTest.java @@ -23,9 +23,9 @@ import org.springframework.test.web.servlet.MockMvc; import java.util.Set; -import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -54,7 +54,7 @@ void init() { void getQuestioningAccreditationOk() throws Exception { Questioning questioning = questioningService.findBySurveyUnitIdSu("100000001").stream().findFirst().get(); Long identifier = questioning.getQuestioningAccreditations().stream().findFirst().get().getId(); - String json = createJsonQuestioningAcreditation(identifier); + String json = createJsonQuestioningAcreditation(); this.mockMvc.perform(get(Constants.API_QUESTIONINGS_ID_QUESTIONING_ACCREDITATIONS, identifier)).andDo(print()).andExpect(status().isOk()) .andExpect(content().json(json, false)); } @@ -109,12 +109,12 @@ void postAccreditationCreateUpdate() throws Exception { post(Constants.API_QUESTIONINGS_ID_QUESTIONING_ACCREDITATIONS, idQuestioning) .content(jsonAccreditation).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()) - .andExpect(content().json(jsonAccreditation.toString(), false)); - Questioning questioning = questioningService.findbyId((long) idQuestioning); + .andExpect(content().json(jsonAccreditation, false)); + Questioning questioning = questioningService.findbyId(idQuestioning); Set setAccreditationFound = questioning.getQuestioningAccreditations(); QuestioningAccreditation accreditationFound = setAccreditationFound.stream() .filter(acc -> acc.getIdContact().equals(idContact)) - .collect(Collectors.toList()).get(0); + .toList().getFirst(); assertEquals(accreditationFound.getCreationAuthor(), accreditation.getCreationAuthor()); assertEquals(accreditationFound.getIdContact(), accreditation.getIdContact()); @@ -125,12 +125,12 @@ void postAccreditationCreateUpdate() throws Exception { post(Constants.API_QUESTIONINGS_ID_QUESTIONING_ACCREDITATIONS, idQuestioning) .content(jsonAccreditationUpdate).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().json(jsonAccreditationUpdate.toString(), false)); + .andExpect(content().json(jsonAccreditationUpdate, false)); - QuestioningAccreditation accreditationFoundAfterUpdate = questioningService.findbyId((long) idQuestioning) + QuestioningAccreditation accreditationFoundAfterUpdate = questioningService.findbyId(idQuestioning) .getQuestioningAccreditations().stream().filter(acc -> acc.getIdContact().equals(idContact)) - .toList().get(0); - assertEquals(true, accreditationFoundAfterUpdate.isMain()); + .toList().getFirst(); + assertTrue(accreditationFoundAfterUpdate.isMain()); } @@ -150,7 +150,7 @@ private String createJson(QuestioningAccreditation accreditation) throws JSONExc return jo.toString(); } - private String createJsonQuestioningAcreditation(Long identifier) throws JSONException { + private String createJsonQuestioningAcreditation() throws JSONException { JSONObject jo1 = new JSONObject(); jo1.put("idContact", "CONT1"); diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningControllerTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningControllerTest.java index b57fda55..3fe514c9 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningControllerTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningControllerTest.java @@ -48,11 +48,6 @@ void getQuestioningsBySurveyUnit() throws Exception { } - private JSONObject createJson(Long id) throws JSONException { - JSONObject jo = new JSONObject(); - jo.put("id", id); - return jo; - } private String createJsonQuestionings(String id) throws JSONException { JSONObject jo = new JSONObject(); diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningEventControllerTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningEventControllerTest.java index 1c7adf0e..ae3c5674 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningEventControllerTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/controller/QuestionningEventControllerTest.java @@ -45,7 +45,7 @@ void init() { void getQuestioningEventOk() throws Exception { Questioning questioning = questioningService.findBySurveyUnitIdSu("100000001").stream().findFirst().get(); Long id = questioning.getQuestioningAccreditations().stream().findFirst().get().getId(); - String json = createJsonQuestioningEvent(id); + String json = createJsonQuestioningEvent(); this.mockMvc.perform(get(Constants.API_QUESTIONING_ID_QUESTIONING_EVENTS, id)).andDo(print()).andExpect(status().isOk()) .andExpect(content().json(json, false)); } @@ -58,7 +58,7 @@ void getQuestioningEventNotFound() throws Exception { } - private String createJsonQuestioningEvent(Long identifier) throws JSONException { + private String createJsonQuestioningEvent() throws JSONException { JSONObject joEventInitla = new JSONObject(); joEventInitla.put("type", "INITLA"); diff --git a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/user/controller/UserEventControllerTest.java b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/user/controller/UserEventControllerTest.java index 8ec9e06b..5e5b8a45 100644 --- a/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/user/controller/UserEventControllerTest.java +++ b/platine-management-api/src/test/java/fr/insee/survey/datacollectionmanagement/user/controller/UserEventControllerTest.java @@ -3,7 +3,6 @@ import fr.insee.survey.datacollectionmanagement.configuration.AuthenticationUserProvider; import fr.insee.survey.datacollectionmanagement.constants.AuthorityRoleEnum; import fr.insee.survey.datacollectionmanagement.constants.Constants; -import fr.insee.survey.datacollectionmanagement.user.domain.UserEvent; import fr.insee.survey.datacollectionmanagement.user.enums.UserEventTypeEnum; import org.json.JSONArray; import org.json.JSONException; diff --git a/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/contact/domain/Address.java b/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/contact/domain/Address.java index ad606d07..d449e754 100644 --- a/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/contact/domain/Address.java +++ b/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/contact/domain/Address.java @@ -30,18 +30,4 @@ public class Address { private String countryCode; private String countryName; - public String toStringMoog() { - return (streetNumber!=null?streetNumber:"") + - " "+ (repetitionIndex!=null?repetitionIndex:"")+ - " " +(streetType!=null?streetType:"")+ - "" + (streetName!=null?streetName:"")+ - " " +(addressSupplement!=null?addressSupplement:"") + - " " + (cityName!=null?cityName:"")+ - " " + (zipCode!=null?zipCode:"") + - " " + (cedexCode!=null?cedexCode:"") + - " " + (cedexName!=null?cedexName:"") + - " " + (specialDistribution!=null?specialDistribution:"") + - " " + (countryCode!=null?countryCode:"") + - " " + (countryName!=null?countryName:""); - } } diff --git a/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/query/repository/MoogRepository.java b/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/query/repository/MoogRepository.java index 1bebe48b..c027d60b 100644 --- a/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/query/repository/MoogRepository.java +++ b/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/query/repository/MoogRepository.java @@ -1,12 +1,10 @@ package fr.insee.survey.datacollectionmanagement.query.repository; -import fr.insee.survey.datacollectionmanagement.contact.repository.AddressRepository; import fr.insee.survey.datacollectionmanagement.query.dto.MoogExtractionRowDto; import fr.insee.survey.datacollectionmanagement.query.dto.MoogQuestioningEventDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; import java.sql.ResultSet; @@ -20,192 +18,224 @@ public class MoogRepository { private final JdbcTemplate jdbcTemplate; - private final AddressRepository addressRepository; - - final String getEventsQuery = "SELECT qe.id, date, type, survey_unit_id_su, campaign_id " - + " FROM questioning_event qe join questioning q on qe.questioning_id=q.id join partitioning p on q.id_partitioning=p.id " - + " WHERE survey_unit_id_su=? AND campaign_id=? "; + static final String GET_EVENTS_QUERY = """ + select + qe.id, + date, + type, + survey_unit_id_su, + campaign_id + from + questioning_event qe + join questioning q on + qe.questioning_id = q.id + join partitioning p on + q.id_partitioning = p.id + where + survey_unit_id_su =? + and campaign_id =? + """; public List getEventsByIdSuByCampaign(String idCampaign, String idSu) { - return jdbcTemplate.query(getEventsQuery, new RowMapper() { - public MoogQuestioningEventDto mapRow(ResultSet rs, int rowNum) throws SQLException { - MoogQuestioningEventDto moogEvent = new MoogQuestioningEventDto(); - moogEvent.setIdManagementMonitoringInfo(rs.getString("id")); - moogEvent.setStatus(rs.getString("type")); - moogEvent.setDateInfo(rs.getTimestamp("date").getTime()); - return moogEvent; - } - }, new Object[]{idSu, idCampaign}); + return jdbcTemplate.query(GET_EVENTS_QUERY, (rs, rowNum) -> { + MoogQuestioningEventDto moogEvent = new MoogQuestioningEventDto(); + moogEvent.setIdManagementMonitoringInfo(rs.getString("id")); + moogEvent.setStatus(rs.getString("type")); + moogEvent.setDateInfo(rs.getTimestamp("date").getTime()); + return moogEvent; + }, idSu, idCampaign); } - final String extractionQuery = - """ - select - id_su, - identifier as id_contact, - first_name as firstname, - last_name as lastname, - address_id as address, - date as dateinfo, - type as status, - batch_num - from - ( - select - id, - campaign_id, - A.id_su, - A.identifier, - first_name, - last_name, - address_id, - id_partitioning as batch_num - from - ( - select - campaign_id, - id_su, - contact.identifier, - first_name, - last_name, - address_id - from - view - left join contact on - contact.identifier = view.identifier - where - campaign_id = ? - ) as A - left join questioning q on - A.id_su = q.survey_unit_id_su - and q.id_partitioning in ( - select - id - from - partitioning p - where - p.campaign_id = ?) - ) as B - left join questioning_event on - B.id = questioning_event.questioning_id - """; + static final String EXTRACTION_QUERY = """ + SELECT + B.id_su, + B.identifier AS id_contact, + B.first_name AS firstname, + B.last_name AS lastname, + addr.id AS address_id, + addr.street_number AS street_number, + addr.repetition_index AS repetition_index, + addr.street_type AS street_type, + addr.street_name AS street_name, + addr.address_supplement AS address_supplement, + addr.zip_code AS zip_code, + addr.city_name AS city_name, + addr.cedex_code AS cedex_code, + addr.cedex_name AS cedex_name, + addr.special_distribution AS special_distribution, + addr.country_code AS country_code, + addr.country_name AS country_name, + B.date AS dateinfo, + B.type AS status, + B.batch_num + FROM ( + SELECT + q.id, + A.campaign_id, + A.id_su, + A.identifier, + A.first_name, + A.last_name, + A.address_id, + q.id_partitioning AS batch_num, + qe.date, + qe.type + FROM ( + SELECT + v.campaign_id, + v.id_su, + contact.identifier, + contact.first_name, + contact.last_name, + contact.address_id + FROM view v + LEFT JOIN contact + ON contact.identifier = v.identifier + WHERE v.campaign_id = ? + ) AS A + LEFT JOIN questioning q + ON A.id_su = q.survey_unit_id_su + AND q.id_partitioning IN ( + SELECT id + FROM partitioning p + WHERE p.campaign_id = ? + ) + LEFT JOIN questioning_event qe + ON q.id = qe.questioning_id + ) AS B + LEFT JOIN address addr + ON B.address_id = addr.id + """; public List getExtraction(String idCampaign) { - return jdbcTemplate.query(extractionQuery, new RowMapper() { - - public MoogExtractionRowDto mapRow(ResultSet rs, int rowNum) throws SQLException { - MoogExtractionRowDto ev = new MoogExtractionRowDto(); - - ev.setAddress("addresse non connue"); - - ev.setStatus(rs.getString("status")); - ev.setDateInfo(rs.getString("dateinfo")); - ev.setIdSu(rs.getString("id_su")); - ev.setIdContact(rs.getString("id_contact")); - ev.setLastname(rs.getString("lastname")); - ev.setFirstname(rs.getString("firstname")); - addressRepository - .findById(rs.getLong("address")) - .ifPresentOrElse( - address -> ev.setAddress(address.toStringMoog()), - () -> log.info("Address not found") - ); - - ev.setBatchNumber(rs.getString("batch_num")); - - return ev; - } - }, new Object[]{idCampaign, idCampaign}); + return jdbcTemplate.query(EXTRACTION_QUERY, (rs, rowNum) -> { + MoogExtractionRowDto ev = new MoogExtractionRowDto(); + + ev.setAddress("addresse non connue"); + + ev.setStatus(rs.getString("status")); + ev.setDateInfo(rs.getString("dateinfo")); + ev.setIdSu(rs.getString("id_su")); + ev.setIdContact(rs.getString("id_contact")); + ev.setLastname(rs.getString("lastname")); + ev.setFirstname(rs.getString("firstname")); + ev.setAddress(createAddress(rs)); + ev.setBatchNumber(rs.getString("batch_num")); + + return ev; + }, idCampaign, idCampaign); } - final String surveyUnitFollowUpQuery = """ - select - distinct on - (id_su) id_su, - batch_num, - case - when type in ('PND') then 1 - else 0 - end as PND - from - ( - select - A.id_su, - A.identifier, - q.id, - q.id_partitioning as batch_num - from - ( - select - id_su, - identifier - from - public.view v - where - campaign_id = ?)as A - left join questioning q on - q.survey_unit_id_su = A.id_su - and q.id_partitioning in ( - select - id - from - partitioning p - where - p.campaign_id = ?)) as B - left join questioning_event qe on - B.id = qe.questioning_id - where - B.id_su not in ( - select - distinct on - (id_su) id_su - from - ( + private static String createAddress(ResultSet rs) throws SQLException { + StringBuilder addressBuilder = new StringBuilder(); + + appendIfNotEmpty(addressBuilder, rs.getString("street_number")); + appendIfNotEmpty(addressBuilder, rs.getString("repetition_index")); + appendIfNotEmpty(addressBuilder, rs.getString("street_type")); + appendIfNotEmpty(addressBuilder, rs.getString("street_name")); + appendIfNotEmpty(addressBuilder, rs.getString("address_supplement")); + appendIfNotEmpty(addressBuilder, rs.getString("zip_code")); + appendIfNotEmpty(addressBuilder, rs.getString("city_name")); + appendIfNotEmpty(addressBuilder, rs.getString("cedex_code")); + appendIfNotEmpty(addressBuilder, rs.getString("cedex_name")); + appendIfNotEmpty(addressBuilder, rs.getString("special_distribution")); + appendIfNotEmpty(addressBuilder, rs.getString("country_code")); + appendIfNotEmpty(addressBuilder, rs.getString("country_name")); + + return addressBuilder.toString().trim(); // Remove trailing spaces + } + + private static void appendIfNotEmpty(StringBuilder builder, String value) { + if (value != null && !value.isEmpty()) { + builder.append(value.trim()).append(" "); + } + } + + static final String SURVEY_UNIT_FOLLOW_UP_QUERY = """ select - id_su, - identifier, - id, - id_partitioning as batch_num + distinct on + (id_su) id_su, + batch_num, + case + when type in ('PND') then 1 + else 0 + end as PND from ( select - id_su, - identifier + A.id_su, + A.identifier, + q.id, + q.id_partitioning as batch_num from - public.view - where - campaign_id = ?)as A - left join questioning q on - q.survey_unit_id_su = A.id_su - and q.id_partitioning in ( + ( + select + id_su, + identifier + from + public.view v + where + campaign_id = ?)as A + left join questioning q on + q.survey_unit_id_su = A.id_su + and q.id_partitioning in ( + select + id + from + partitioning p + where + p.campaign_id = ?)) as B + left join questioning_event qe on + B.id = qe.questioning_id + where + B.id_su not in ( select - id + distinct on + (id_su) id_su from - partitioning p + ( + select + id_su, + identifier, + id, + id_partitioning as batch_num + from + ( + select + id_su, + identifier + from + public.view + where + campaign_id = ?)as A + left join questioning q on + q.survey_unit_id_su = A.id_su + and q.id_partitioning in ( + select + id + from + partitioning p + where + p.campaign_id = ?)) as B + left join questioning_event on + B.id = questioning_event.questioning_id where - p.campaign_id = ?)) as B - left join questioning_event on - B.id = questioning_event.questioning_id - where - type in ('VALINT', 'VALPAP', 'HC', 'REFUSAL', 'WASTE')) - order by - id_su, - pnd desc; - """; + type in ('VALINT', 'VALPAP', 'HC', 'REFUSAL', 'WASTE')) + order by + id_su, + pnd desc + """; public List getSurveyUnitToFollowUp(String idCampaign) { - return jdbcTemplate.query(surveyUnitFollowUpQuery, - new RowMapper() { - public MoogExtractionRowDto mapRow(ResultSet rs, int rowNum) throws SQLException { - MoogExtractionRowDto er = new MoogExtractionRowDto(); - er.setIdSu(rs.getString("id_su")); - er.setPnd(rs.getInt("PND")); - er.setBatchNumber(rs.getString("batch_num")); - - return er; - } - }, new Object[]{idCampaign, idCampaign, idCampaign, idCampaign}); + return jdbcTemplate.query(SURVEY_UNIT_FOLLOW_UP_QUERY, + (rs, rowNum) -> { + MoogExtractionRowDto er = new MoogExtractionRowDto(); + er.setIdSu(rs.getString("id_su")); + er.setPnd(rs.getInt("PND")); + er.setBatchNumber(rs.getString("batch_num")); + return er; + }, idCampaign, idCampaign, idCampaign, idCampaign); } } diff --git a/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/AddressService.java b/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/AddressService.java index 9af53e06..ce77763c 100644 --- a/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/AddressService.java +++ b/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/AddressService.java @@ -9,16 +9,16 @@ @Service public interface AddressService { - public Address findById(Long id); + Address findById(Long id); - public Page
findAll(Pageable pageable); + Page
findAll(Pageable pageable); - public Address saveAddress(Address address); + Address saveAddress(Address address); - public void deleteAddressById(Long id); + void deleteAddressById(Long id); - public AddressDto convertToDto(Address address); + AddressDto convertToDto(Address address); - public Address convertToEntity(AddressDto addressDto); + Address convertToEntity(AddressDto addressDto); } diff --git a/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderPoc.java b/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderPoc.java index 08452168..c6f72d3a 100644 --- a/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderPoc.java +++ b/platine-management-service/src/main/java/fr/insee/survey/datacollectionmanagement/dataloader/DataloaderPoc.java @@ -10,13 +10,14 @@ import fr.insee.survey.datacollectionmanagement.contact.repository.AddressRepository; import fr.insee.survey.datacollectionmanagement.contact.repository.ContactEventRepository; import fr.insee.survey.datacollectionmanagement.contact.repository.ContactRepository; +import fr.insee.survey.datacollectionmanagement.exception.NotFoundException; import fr.insee.survey.datacollectionmanagement.metadata.domain.*; -import fr.insee.survey.datacollectionmanagement.metadata.repository.*; import fr.insee.survey.datacollectionmanagement.metadata.enums.PeriodEnum; import fr.insee.survey.datacollectionmanagement.metadata.enums.PeriodicityEnum; +import fr.insee.survey.datacollectionmanagement.metadata.repository.*; import fr.insee.survey.datacollectionmanagement.questioning.domain.*; -import fr.insee.survey.datacollectionmanagement.questioning.repository.*; import fr.insee.survey.datacollectionmanagement.questioning.enums.TypeQuestioningEvent; +import fr.insee.survey.datacollectionmanagement.questioning.repository.*; import fr.insee.survey.datacollectionmanagement.view.domain.View; import fr.insee.survey.datacollectionmanagement.view.repository.ViewRepository; import jakarta.annotation.PostConstruct; @@ -32,7 +33,7 @@ @Component @Slf4j -@Profile(("demo")) +@Profile("demo") @RequiredArgsConstructor public class DataloaderPoc { @@ -84,12 +85,13 @@ public void init() { Faker faker = new Faker(); initOrder(); - //initContact(faker); - - /*initDataForOneSource(faker, "DVM", 2, PeriodicityEnum.M, 12, 3, 1); - initDataForOneSource(faker, "DVT", 3, PeriodicityEnum.T, 4, 2, 1); - initDataForOneSource(faker, "DVX", 2, PeriodicityEnum.X, 1, 2, 1); - initDataForOneSource(faker, "DVB", 2, PeriodicityEnum.B, 6, 1, 1);*/ + if (contactRepository.count() == 0) { + initContact(faker); + initDataForOneSource(faker, "DVM", 2, PeriodicityEnum.M, 12, 3); + initDataForOneSource(faker, "DVT", 3, PeriodicityEnum.T, 4, 2); + initDataForOneSource(faker, "DVX", 2, PeriodicityEnum.X, 1, 2); + initDataForOneSource(faker, "DVB", 2, PeriodicityEnum.B, 6, 1); + } } @@ -223,9 +225,7 @@ private void initContact(Faker faker) { listContact.add(c); if ((i + 1) % 10000 == 0) { - //addressRepository.saveAll(listAddresses); contactRepository.saveAll(listContact); - //listAddresses = new ArrayList<>(); listContact = new ArrayList<>(); long end = System.currentTimeMillis(); @@ -267,7 +267,6 @@ private Contact initOneContact(Faker faker) { a.setZipCode(fakeAddress.zipCode()); a.setCityName(fakeAddress.cityName()); addressRepository.save(a); - //listAddresses.add(a); c.setIdentifier(randomString(7).toUpperCase()); c.setLastName(name); @@ -283,7 +282,7 @@ private Contact initOneContact(Faker faker) { } private void initDataForOneSource(Faker faker, String sourceName, int nbSurveysBySource, PeriodicityEnum periodicity, - int nbCampaignsBySource, int nbPartByCampaign, int nbQuestioningsByPart) { + int nbCampaignsBySource, int nbPartByCampaign) { int year = Calendar.getInstance().get(Calendar.YEAR); @@ -316,23 +315,19 @@ private void initDataForOneSource(Faker faker, String sourceName, int nbSurveysB log.info("{} campaigns exist in database", campaignRepository.count()); - // while (sourceRepository.count() < 10) { - Source source = new Source(); - String nameSource = sourceName; - - if (!StringUtils.contains(nameSource, " ") && sourceRepository.findById(nameSource).isEmpty()) { + if (!StringUtils.contains(sourceName, " ") && sourceRepository.findById(sourceName).isEmpty()) { - source.setId(nameSource); - source.setLongWording("Have you ever heard about " + nameSource + " ?"); - source.setShortWording("Source about " + nameSource); + source.setId(sourceName); + source.setLongWording("Have you ever heard about " + sourceName + " ?"); + source.setShortWording("Source about " + sourceName); source.setPeriodicity(periodicity); source.setMandatoryMySurveys(false); sourceRepository.save(source); Set setSurveys = new HashSet<>(); - Integer i = rnd.nextInt(); + int i = rnd.nextInt(); if (i % 2 == 0) { setSourcesInsee.add(source); source.setOwner(ownerInsee); @@ -348,11 +343,11 @@ private void initDataForOneSource(Faker faker, String sourceName, int nbSurveysB for (int j = 0; j < nbSurveysBySource; j++) { Survey survey = new Survey(); - String id = nameSource + (year - j); + String id = sourceName + (year - j); survey.setId(id); survey.setYear(year - j); survey.setLongObjectives("The purpose of this survey is to find out everything you can about " - + nameSource + + sourceName + ". Your response is essential to ensure the quality and reliability of the results of this survey."); survey.setShortObjectives("All about " + id); survey.setCommunication("Communication around " + id); @@ -361,7 +356,7 @@ private void initDataForOneSource(Faker faker, String sourceName, int nbSurveysB survey.setCnisUrl("http://cnis/" + id); survey.setNoticeUrl("http://notice/" + id); survey.setVisaNumber(year + randomString(6).toUpperCase()); - survey.setLongWording("Survey " + nameSource + " " + (year - j)); + survey.setLongWording("Survey " + sourceName + " " + (year - j)); survey.setShortWording(id); setSurveys.add(survey); surveyRepository.save(survey); @@ -374,10 +369,10 @@ private void initDataForOneSource(Faker faker, String sourceName, int nbSurveysB String period = periodValue < 10 ? periodicity + "0" + periodValue : periodicity + String.valueOf(periodValue); campaign.setYear(year - j); campaign.setPeriod(PeriodEnum.valueOf(period)); - String idampaign = nameSource + (year - j) + period; + String idampaign = sourceName + (year - j) + period; campaign.setId(idampaign); campaign.setCampaignWording( - "Campaign about " + nameSource + " in " + (year - j) + " and period " + period); + "Campaign about " + sourceName + " in " + (year - j) + " and period " + period); if (campaignRepository.findById(idampaign).isEmpty()) { @@ -398,7 +393,7 @@ private void initDataForOneSource(Faker faker, String sourceName, int nbSurveysB setParts.add(part); part.setCampaign(campaign); partitioningRepository.save(part); - initQuestionning(faker, part, nbQuestioningsByPart); + initQuestionning(faker, part); } campaign.setSurvey(survey); campaign.setPartitionings(setParts); @@ -425,11 +420,7 @@ private void initDataForOneSource(Faker faker, String sourceName, int nbSurveysB } } - private void initQuestionning(Faker faker, Partitioning part, int nbQuestionings) { - - //Long nbExistingQuestionings = questioningRepository.count(); - - //log.info("{} questionings exist in database", nbExistingQuestionings); + private void initQuestionning(Faker faker, Partitioning part) { long start = System.currentTimeMillis(); Questioning qu; @@ -441,7 +432,7 @@ private void initQuestionning(Faker faker, Partitioning part, int nbQuestionings log.info("{} survey units exist in database", surveyUnitRepository.count()); - for (int i = 0; i < nbQuestionings; i++) { + for (int i = 0; i < 1; i++) { SurveyUnit su = new SurveyUnit(); fakeSiren = randomNumeric(9); @@ -522,9 +513,8 @@ private void initQuestionning(Faker faker, Partitioning part, int nbQuestionings } - questioningEvents.stream().forEach(questioningEventRepository::save); + questioningEvents.forEach(questioningEventRepository::save); - //for (int j = 0; j < 4; j++) { accreditation = new QuestioningAccreditation(); accreditation.setIdContact(initOneContact(faker).getIdentifier()); accreditation.setQuestioning(qu); @@ -543,7 +533,6 @@ private void initQuestionning(Faker faker, Partitioning part, int nbQuestionings questioningAccreditations.add(accreditation); questioningAccreditationRepository.save(accreditation); initOneView(accreditation); - // } qu.setQuestioningEvents(questioningEvents); qu.setQuestioningAccreditations(questioningAccreditations); questioningRepository.save(qu); @@ -557,31 +546,15 @@ private void initQuestionning(Faker faker, Partitioning part, int nbQuestionings } - private void initView() { - if (viewRepository.count() == 0) { - - List listAccreditations = questioningAccreditationRepository.findAll(); - listAccreditations.stream().forEach(this::initOneView); - - Iterable listContacts = contactRepository.findAll(); - for (Contact contact : listContacts) { - if (viewRepository.findByIdentifier(contact.getIdentifier()).isEmpty()) { - View view = new View(); - view.setIdentifier(contact.getIdentifier()); - viewRepository.save(view); - - } - } - } - } - private void initOneView(QuestioningAccreditation a) { Partitioning p = partitioningRepository.findById(a.getQuestioning().getIdPartitioning()).orElse(null); View view = new View(); - view.setIdentifier(contactRepository.findById(a.getIdContact()).orElse(null).getIdentifier()); - view.setCampaignId(p.getCampaign().getId()); - view.setIdSu(a.getQuestioning().getSurveyUnit().getIdSu()); - viewRepository.save(view); + view.setIdentifier(contactRepository.findById(a.getIdContact()).orElseThrow(() -> new NotFoundException(String.format("Contact %s not found", a.getIdContact()))).getIdentifier()); + if (p != null) { + view.setCampaignId(p.getCampaign().getId()); + view.setIdSu(a.getQuestioning().getSurveyUnit().getIdSu()); + viewRepository.save(view); + } } diff --git a/platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodEnum.java b/platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodEnum.java index 56e72a3f..4a8db9ab 100644 --- a/platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodEnum.java +++ b/platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodEnum.java @@ -5,131 +5,131 @@ @Getter public enum PeriodEnum { - A00(PeriodicityEnum.A, "annuel"), - X00(PeriodicityEnum.X, "pluriannuel"), - X01(PeriodicityEnum.X, "pluriannuel"), - X02(PeriodicityEnum.X, "pluriannuel"), - X03(PeriodicityEnum.X, "pluriannuel"), - X04(PeriodicityEnum.X, "pluriannuel"), - X05(PeriodicityEnum.X, "pluriannuel"), - X06(PeriodicityEnum.X, "pluriannuel"), - X07(PeriodicityEnum.X, "pluriannuel"), - X08(PeriodicityEnum.X, "pluriannuel"), - X09(PeriodicityEnum.X, "pluriannuel"), - X10(PeriodicityEnum.X, "pluriannuel"), - X11(PeriodicityEnum.X, "pluriannuel"), - X12(PeriodicityEnum.X, "pluriannuel"), - X13(PeriodicityEnum.X, "pluriannuel"), - X14(PeriodicityEnum.X, "pluriannuel"), - X15(PeriodicityEnum.X, "pluriannuel"), - X16(PeriodicityEnum.X, "pluriannuel"), - X17(PeriodicityEnum.X, "pluriannuel"), - X18(PeriodicityEnum.X, "pluriannuel"), - X19(PeriodicityEnum.X, "pluriannuel"), - X20(PeriodicityEnum.X, "pluriannuel"), - X21(PeriodicityEnum.X, "pluriannuel"), - X22(PeriodicityEnum.X, "pluriannuel"), - X23(PeriodicityEnum.X, "pluriannuel"), - X24(PeriodicityEnum.X, "pluriannuel"), - X25(PeriodicityEnum.X, "pluriannuel"), - X26(PeriodicityEnum.X, "pluriannuel"), - X27(PeriodicityEnum.X, "pluriannuel"), - X28(PeriodicityEnum.X, "pluriannuel"), - X29(PeriodicityEnum.X, "pluriannuel"), - X30(PeriodicityEnum.X, "pluriannuel"), - X31(PeriodicityEnum.X, "pluriannuel"), - X32(PeriodicityEnum.X, "pluriannuel"), - X33(PeriodicityEnum.X, "pluriannuel"), - X34(PeriodicityEnum.X, "pluriannuel"), - X35(PeriodicityEnum.X, "pluriannuel"), - X36(PeriodicityEnum.X, "pluriannuel"), - X37(PeriodicityEnum.X, "pluriannuel"), - X38(PeriodicityEnum.X, "pluriannuel"), - X39(PeriodicityEnum.X, "pluriannuel"), - X40(PeriodicityEnum.X, "pluriannuel"), - X41(PeriodicityEnum.X, "pluriannuel"), - X42(PeriodicityEnum.X, "pluriannuel"), - X43(PeriodicityEnum.X, "pluriannuel"), - X44(PeriodicityEnum.X, "pluriannuel"), - X45(PeriodicityEnum.X, "pluriannuel"), - X46(PeriodicityEnum.X, "pluriannuel"), - X47(PeriodicityEnum.X, "pluriannuel"), - X48(PeriodicityEnum.X, "pluriannuel"), - X49(PeriodicityEnum.X, "pluriannuel"), - X50(PeriodicityEnum.X, "pluriannuel"), - X51(PeriodicityEnum.X, "pluriannuel"), - X52(PeriodicityEnum.X, "pluriannuel"), - X53(PeriodicityEnum.X, "pluriannuel"), - X54(PeriodicityEnum.X, "pluriannuel"), - X55(PeriodicityEnum.X, "pluriannuel"), - X56(PeriodicityEnum.X, "pluriannuel"), - X57(PeriodicityEnum.X, "pluriannuel"), - X58(PeriodicityEnum.X, "pluriannuel"), - X59(PeriodicityEnum.X, "pluriannuel"), - X60(PeriodicityEnum.X, "pluriannuel"), - X61(PeriodicityEnum.X, "pluriannuel"), - X62(PeriodicityEnum.X, "pluriannuel"), - X63(PeriodicityEnum.X, "pluriannuel"), - X64(PeriodicityEnum.X, "pluriannuel"), - X65(PeriodicityEnum.X, "pluriannuel"), - X66(PeriodicityEnum.X, "pluriannuel"), - X67(PeriodicityEnum.X, "pluriannuel"), - X68(PeriodicityEnum.X, "pluriannuel"), - X69(PeriodicityEnum.X, "pluriannuel"), - X70(PeriodicityEnum.X, "pluriannuel"), - X71(PeriodicityEnum.X, "pluriannuel"), - X72(PeriodicityEnum.X, "pluriannuel"), - X73(PeriodicityEnum.X, "pluriannuel"), - X74(PeriodicityEnum.X, "pluriannuel"), - X75(PeriodicityEnum.X, "pluriannuel"), - X76(PeriodicityEnum.X, "pluriannuel"), - X77(PeriodicityEnum.X, "pluriannuel"), - X78(PeriodicityEnum.X, "pluriannuel"), - X79(PeriodicityEnum.X, "pluriannuel"), - X80(PeriodicityEnum.X, "pluriannuel"), - X81(PeriodicityEnum.X, "pluriannuel"), - X82(PeriodicityEnum.X, "pluriannuel"), - X83(PeriodicityEnum.X, "pluriannuel"), - X84(PeriodicityEnum.X, "pluriannuel"), - X85(PeriodicityEnum.X, "pluriannuel"), - X86(PeriodicityEnum.X, "pluriannuel"), - X87(PeriodicityEnum.X, "pluriannuel"), - X88(PeriodicityEnum.X, "pluriannuel"), - X89(PeriodicityEnum.X, "pluriannuel"), - X90(PeriodicityEnum.X, "pluriannuel"), - X91(PeriodicityEnum.X, "pluriannuel"), - X92(PeriodicityEnum.X, "pluriannuel"), - X93(PeriodicityEnum.X, "pluriannuel"), - X94(PeriodicityEnum.X, "pluriannuel"), - X95(PeriodicityEnum.X, "pluriannuel"), - X96(PeriodicityEnum.X, "pluriannuel"), - X97(PeriodicityEnum.X, "pluriannuel"), - X98(PeriodicityEnum.X, "pluriannuel"), - X99(PeriodicityEnum.X, "pluriannuel"), - S01(PeriodicityEnum.S, "1er semestre"), - S02(PeriodicityEnum.S, "2nd semestre"), - T01(PeriodicityEnum.T, "1er trimestre"), - T02(PeriodicityEnum.T, "2e trimestre"), - T03(PeriodicityEnum.T, "3e trimestre"), - T04(PeriodicityEnum.T, "4e trimestre"), - M01(PeriodicityEnum.M, "janvier"), - M02(PeriodicityEnum.M, "février"), - M03(PeriodicityEnum.M, "mars"), - M04(PeriodicityEnum.M, "avril"), - M05(PeriodicityEnum.M, "mai"), - M06(PeriodicityEnum.M, "juin"), - M07(PeriodicityEnum.M, "juillet"), - M08(PeriodicityEnum.M, "août"), - M09(PeriodicityEnum.M, "septembre"), - M10(PeriodicityEnum.M, "octobre"), - M11(PeriodicityEnum.M, "novembre"), - M12(PeriodicityEnum.M, "décembre"), - B01(PeriodicityEnum.B, "1er bimestre"), - B02(PeriodicityEnum.B, "2e bimestre"), - B03(PeriodicityEnum.B, "3e bimestre"), - B04(PeriodicityEnum.B, "4e bimestre"), - B05(PeriodicityEnum.B, "5e bimestre"), - B06(PeriodicityEnum.B, "6e bimestre"), + A00(PeriodicityEnum.A, PeriodNameEnum.ANNUAL.getValue()), + X00(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X01(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X02(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X03(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X04(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X05(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X06(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X07(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X08(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X09(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X10(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X11(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X12(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X13(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X14(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X15(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X16(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X17(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X18(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X19(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X20(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X21(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X22(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X23(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X24(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X25(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X26(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X27(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X28(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X29(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X30(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X31(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X32(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X33(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X34(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X35(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X36(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X37(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X38(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X39(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X40(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X41(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X42(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X43(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X44(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X45(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X46(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X47(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X48(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X49(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X50(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X51(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X52(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X53(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X54(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X55(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X56(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X57(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X58(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X59(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X60(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X61(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X62(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X63(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X64(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X65(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X66(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X67(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X68(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X69(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X70(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X71(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X72(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X73(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X74(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X75(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X76(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X77(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X78(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X79(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X80(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X81(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X82(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X83(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X84(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X85(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X86(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X87(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X88(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X89(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X90(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X91(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X92(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X93(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X94(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X95(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X96(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X97(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X98(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + X99(PeriodicityEnum.X, PeriodNameEnum.PLURIANNUAL.getValue()), + S01(PeriodicityEnum.S, PeriodNameEnum.FIRST_SEMESTER.getValue()), + S02(PeriodicityEnum.S, PeriodNameEnum.SECOND_SEMESTER.getValue()), + T01(PeriodicityEnum.T, PeriodNameEnum.FIRST_TRIMESTER.getValue()), + T02(PeriodicityEnum.T, PeriodNameEnum.SECOND_TRIMESTER.getValue()), + T03(PeriodicityEnum.T, PeriodNameEnum.THIRD_TRIMESTER.getValue()), + T04(PeriodicityEnum.T, PeriodNameEnum.FOURTH_TRIMESTER.getValue()), + M01(PeriodicityEnum.M, PeriodNameEnum.JANUARY.getValue()), + M02(PeriodicityEnum.M, PeriodNameEnum.FEBRUARY.getValue()), + M03(PeriodicityEnum.M, PeriodNameEnum.MARCH.getValue()), + M04(PeriodicityEnum.M, PeriodNameEnum.APRIL.getValue()), + M05(PeriodicityEnum.M, PeriodNameEnum.MAY.getValue()), + M06(PeriodicityEnum.M, PeriodNameEnum.JUNE.getValue()), + M07(PeriodicityEnum.M, PeriodNameEnum.JULY.getValue()), + M08(PeriodicityEnum.M, PeriodNameEnum.AUGUST.getValue()), + M09(PeriodicityEnum.M, PeriodNameEnum.SEPTEMBER.getValue()), + M10(PeriodicityEnum.M, PeriodNameEnum.OCTOBER.getValue()), + M11(PeriodicityEnum.M, PeriodNameEnum.NOVEMBER.getValue()), + M12(PeriodicityEnum.M, PeriodNameEnum.DECEMBER.getValue()), + B01(PeriodicityEnum.B, PeriodNameEnum.FIRST_BIMESTER.getValue()), + B02(PeriodicityEnum.B, PeriodNameEnum.SECOND_BIMESTER.getValue()), + B03(PeriodicityEnum.B, PeriodNameEnum.THIRD_BIMESTER.getValue()), + B04(PeriodicityEnum.B, PeriodNameEnum.FOURTH_BIMESTER.getValue()), + B05(PeriodicityEnum.B, PeriodNameEnum.FIFTH_BIMESTER.getValue()), + B06(PeriodicityEnum.B, PeriodNameEnum.SIXTH_BIMESTER.getValue()), ; @@ -141,14 +141,7 @@ public enum PeriodEnum { final PeriodicityEnum period; final String value; - - public static PeriodEnum fromValue(String v) { - for (PeriodEnum c : PeriodEnum.values()) { - if (c.value.equals(v)) { - return c; - } - } - throw new IllegalArgumentException(v); - } + + } diff --git a/platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodNameEnum.java b/platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodNameEnum.java new file mode 100644 index 00000000..fad24439 --- /dev/null +++ b/platine-management-shared/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/enums/PeriodNameEnum.java @@ -0,0 +1,41 @@ +package fr.insee.survey.datacollectionmanagement.metadata.enums; + +public enum PeriodNameEnum { + ANNUAL("annuel"), + PLURIANNUAL("pluriannuel"), + FIRST_SEMESTER("1er semestre"), + SECOND_SEMESTER("2nd semestre"), + FIRST_TRIMESTER("1er trimestre"), + SECOND_TRIMESTER("2e trimestre"), + THIRD_TRIMESTER("3e trimestre"), + FOURTH_TRIMESTER("4e trimestre"), + JANUARY("janvier"), + FEBRUARY("février"), + MARCH("mars"), + APRIL("avril"), + MAY("mai"), + JUNE("juin"), + JULY("juillet"), + AUGUST("août"), + SEPTEMBER("septembre"), + OCTOBER("octobre"), + NOVEMBER("novembre"), + DECEMBER("décembre"), + FIRST_BIMESTER("1er bimestre"), + SECOND_BIMESTER("2e bimestre"), + THIRD_BIMESTER("3e bimestre"), + FOURTH_BIMESTER("4e bimestre"), + FIFTH_BIMESTER("5e bimestre"), + SIXTH_BIMESTER("6e bimestre"); + + private final String value; + + PeriodNameEnum(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} diff --git a/pom.xml b/pom.xml index cb59e290..1646ec4d 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.6 + 3.4.1 @@ -24,7 +24,7 @@ platine-management-api - 2.7.2 + 2.7.3 21 21