diff --git a/pom.xml b/pom.xml
index 3cd42cd1..4280ad98 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
fr.insee.survey
platine-management
- 2.5.1
+ 2.6.0
platine-management
REST API for communication between DB and Platine-Management UI and Platine-My-Surveys UI
@@ -20,7 +20,7 @@
3.2.0
3.1.0
5.0.0
- 42.7.3
+ 42.7.3
1.0.2
inseefr
https://sonarcloud.io
@@ -87,7 +87,7 @@
org.postgresql
postgresql
- ${postgre-version}
+ ${postgres-version}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/constants/AuthConstants.java b/src/main/java/fr/insee/survey/datacollectionmanagement/constants/AuthConstants.java
index 14246eb9..d6064ae3 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/constants/AuthConstants.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/constants/AuthConstants.java
@@ -3,4 +3,8 @@
public class AuthConstants {
public static final String OIDC = "OIDC";
+
+ private AuthConstants() {
+ throw new IllegalStateException("Utility class");
+ }
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/constants/Constants.java b/src/main/java/fr/insee/survey/datacollectionmanagement/constants/Constants.java
index f3b69e11..b8eebae8 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/constants/Constants.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/constants/Constants.java
@@ -34,6 +34,8 @@ private Constants() {
public static final String API_SURVEY_UNITS ="/api/survey-units";
public static final String API_SURVEY_UNITS_ID = "/api/survey-units/{id}";
public static final String API_SURVEY_UNITS_ID_QUESTIONINGS = "/api/survey-units/{id}/questionings";
+ public static final String API_SURVEY_UNITS_ID_COMMENT = "/api/survey-units/{id}/comment";
+
public static final String API_QUESTIONINGS_ID_QUESTIONING_ACCREDITATIONS = "/api/questionings/{id}/questioning-accreditations";
public static final String API_QUESTIONING_QUESTIONING_EVENTS = "/api/questionings/questioning-events";
public static final String API_QUESTIONING_ID_QUESTIONING_EVENTS = "/api/questionings/{id}/questioning-events";
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressController.java
index 67da2c4c..2da362aa 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/AddressController.java
@@ -41,9 +41,13 @@ public class AddressController {
private final ContactEventService contactEventService;
+ /**
+ * @deprecated
+ */
@Operation(summary = "Search for a contact address by the contact id")
@GetMapping(value = Constants.API_CONTACTS_ID_ADDRESS, produces = "application/json")
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES + " || " + AuthorityPrivileges.HAS_REPONDENT_LIMITATED_PRIVILEGES)
+ @Deprecated(since="2.6.0", forRemoval=true)
public ResponseEntity getContactAddress(@PathVariable("id") String id) {
Contact contact = contactService.findByIdentifier(id);
if (contact.getAddress() != null)
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactController.java
index 75cd2124..b79d3fca 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactController.java
@@ -5,18 +5,25 @@
import fr.insee.survey.datacollectionmanagement.config.auth.user.AuthorityPrivileges;
import fr.insee.survey.datacollectionmanagement.constants.Constants;
import fr.insee.survey.datacollectionmanagement.contact.domain.Contact;
-import fr.insee.survey.datacollectionmanagement.contact.domain.ContactEvent.ContactEventType;
+import fr.insee.survey.datacollectionmanagement.contact.dto.ContactDetailsDto;
import fr.insee.survey.datacollectionmanagement.contact.dto.ContactDto;
-import fr.insee.survey.datacollectionmanagement.contact.dto.ContactFirstLoginDto;
+import fr.insee.survey.datacollectionmanagement.contact.dto.SearchContactDto;
import fr.insee.survey.datacollectionmanagement.contact.service.AddressService;
import fr.insee.survey.datacollectionmanagement.contact.service.ContactService;
+import fr.insee.survey.datacollectionmanagement.contact.util.ContactParamEnum;
import fr.insee.survey.datacollectionmanagement.contact.util.PayloadUtil;
+import fr.insee.survey.datacollectionmanagement.contact.validation.ValidContactParam;
import fr.insee.survey.datacollectionmanagement.exception.ImpossibleToDeleteException;
import fr.insee.survey.datacollectionmanagement.exception.NotFoundException;
import fr.insee.survey.datacollectionmanagement.exception.NotMatchException;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningAccreditationService;
import fr.insee.survey.datacollectionmanagement.view.service.ViewService;
import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
@@ -34,6 +41,7 @@
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.io.Serial;
+import java.util.Collections;
import java.util.List;
@RestController
@@ -54,24 +62,29 @@ public class ContactController {
private final ModelMapper modelMapper;
+ /**
+ * @deprecated
+ */
@Operation(summary = "Search for contacts, paginated")
@GetMapping(value = Constants.API_CONTACTS_ALL, produces = "application/json")
- public ResponseEntity getContacts(
+ @Deprecated(since = "2.6.0", forRemoval = true)
+ public ContactPage getContacts(
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "20") Integer size,
@RequestParam(defaultValue = "identifier") String sort) {
Pageable pageable = PageRequest.of(page, size, Sort.by(sort));
Page pageC = contactService.findAll(pageable);
List listC = pageC.stream().map(this::convertToDto).toList();
- return ResponseEntity.ok().body(new ContactPage(listC, pageable, pageC.getTotalElements()));
+ return new ContactPage(listC, pageable, pageC.getTotalElements());
}
@Operation(summary = "Search for a contact by its id")
@GetMapping(value = Constants.API_CONTACTS_ID)
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES + " || " + AuthorityPrivileges.HAS_REPONDENT_LIMITATED_PRIVILEGES)
- public ResponseEntity getContact(@PathVariable("id") String id) {
+ public ContactDetailsDto getContact(@PathVariable("id") String id) {
Contact contact = contactService.findByIdentifier(StringUtils.upperCase(id));
- return ResponseEntity.ok().body(convertToFirstLoginDto(contact));
+ List listCampaigns = questioningAccreditationService.findCampaignsForContactId(id);
+ return convertToContactDetailsDto(contact, listCampaigns);
}
@@ -112,9 +125,13 @@ public ResponseEntity putContact(@PathVariable("id") String id,
}
+ /**
+ * @deprecated
+ */
@Operation(summary = "Delete a contact, its address, its contactEvents")
@DeleteMapping(value = Constants.API_CONTACTS_ID)
@ResponseStatus(HttpStatus.NO_CONTENT)
+ @Deprecated(since = "2.6.0", forRemoval = true)
public void deleteContact(@PathVariable("id") String id) {
if (!questioningAccreditationService.findByContactIdentifier(id).isEmpty()) {
@@ -128,17 +145,47 @@ public void deleteContact(@PathVariable("id") String id) {
}
+ @GetMapping(path = Constants.API_CONTACTS_SEARCH, produces = "application/json")
+ @Operation(summary = "Multi-criteria search contacts")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SearchContactDto.class)))),
+ @ApiResponse(responseCode = "400", description = "Bad Request")
+ })
+ public Page searchContacts(
+ @RequestParam(required = true) String searchParam,
+ @RequestParam(required = false) @Valid @ValidContactParam String searchType,
+ @RequestParam(defaultValue = "0") Integer page,
+ @RequestParam(defaultValue = "10") Integer pageSize,
+ @RequestParam(defaultValue = "identifier") String sort) {
+
+ log.info(
+ "Search contact by {} with param = {} page = {} pageSize = {}", searchType, searchParam, page, pageSize);
+
+ Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
+
+ switch (ContactParamEnum.fromValue(searchType)) {
+ case ContactParamEnum.IDENTIFIER:
+ return contactService.searchContactByIdentifier(searchParam, pageable);
+ case ContactParamEnum.NAME:
+ return contactService.searchContactByName(searchParam, pageable);
+ case ContactParamEnum.EMAIL:
+ return contactService.searchContactByEmail(searchParam, pageable);
+ }
+ return new PageImpl<>(Collections.emptyList());
+
+ }
+
private ContactDto convertToDto(Contact contact) {
ContactDto contactDto = modelMapper.map(contact, ContactDto.class);
contactDto.setCivility(contact.getGender().name());
return contactDto;
}
- private ContactFirstLoginDto convertToFirstLoginDto(Contact contact) {
- ContactFirstLoginDto contactFirstLoginDto = modelMapper.map(contact, ContactFirstLoginDto.class);
- contactFirstLoginDto.setCivility(contact.getGender());
- contactFirstLoginDto.setFirstConnect(contact.getContactEvents().stream().noneMatch(e -> e.getType().equals(ContactEventType.firstConnect)));
- return contactFirstLoginDto;
+ private ContactDetailsDto convertToContactDetailsDto(Contact contact, List listCampaigns) {
+ ContactDetailsDto contactDetailsDto = modelMapper.map(contact, ContactDetailsDto.class);
+ contactDetailsDto.setCivility(contact.getGender());
+ contactDetailsDto.setListCampaigns(listCampaigns);
+ return contactDetailsDto;
}
private Contact convertToEntity(ContactDto contactDto) {
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactEventController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactEventController.java
index 3a6acb50..87f44966 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactEventController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/controller/ContactEventController.java
@@ -39,8 +39,12 @@ public class ContactEventController {
private final ModelMapper modelMapper;
+ /**
+ * @deprecated
+ */
@Operation(summary = "Search for contactEvents by the contact id")
@GetMapping(value = Constants.API_CONTACTS_ID_CONTACTEVENTS, produces = "application/json")
+ @Deprecated(since = "2.6.0", forRemoval = true)
public ResponseEntity> getContactContactEvents(@PathVariable("id") String identifier) {
Contact contact = contactService.findByIdentifier(identifier);
return ResponseEntity.status(HttpStatus.OK)
@@ -50,8 +54,13 @@ public ResponseEntity> getContactContactEvents(@PathVariab
}
+
+ /**
+ * @deprecated
+ */
@Operation(summary = "Create a contactEvent")
@PostMapping(value = Constants.API_CONTACTEVENTS, produces = "application/json", consumes = "application/json")
+ @Deprecated(since = "2.6.0", forRemoval = true)
public ResponseEntity postContactEvent(@RequestBody @Valid ContactEventDto contactEventDto) {
Contact contact = contactService.findByIdentifier(contactEventDto.getIdentifier());
@@ -70,9 +79,14 @@ public ResponseEntity postContactEvent(@RequestBody @Valid Cont
}
+
+ /**
+ * @deprecated
+ */
@Operation(summary = "Delete a contact event")
@DeleteMapping(value = Constants.API_CONTACTEVENTS_ID, produces = "application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)
+ @Deprecated(since = "2.6.0", forRemoval = true)
public void deleteContactEvent(@PathVariable("id") Long id) {
ContactEvent contactEvent = contactEventService.findById(id);
Contact contact = contactEvent.getContact();
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/ContactFirstLoginDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/ContactDetailsDto.java
similarity index 87%
rename from src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/ContactFirstLoginDto.java
rename to src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/ContactDetailsDto.java
index dd43201d..f9a26fd6 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/ContactFirstLoginDto.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/ContactDetailsDto.java
@@ -5,9 +5,11 @@
import lombok.Getter;
import lombok.Setter;
+import java.util.List;
+
@Getter
@Setter
-public class ContactFirstLoginDto{
+public class ContactDetailsDto {
private String identifier;
private String externalId;
@@ -20,7 +22,7 @@ public class ContactFirstLoginDto{
private String phone;
private String otherPhone;
private String usualCompanyName;
- private boolean firstConnect;
private AddressDto address;
+ private List listCampaigns;
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/dto/SearchContactDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/SearchContactDto.java
similarity index 67%
rename from src/main/java/fr/insee/survey/datacollectionmanagement/query/dto/SearchContactDto.java
rename to src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/SearchContactDto.java
index 6400d5f8..5ce8b52c 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/dto/SearchContactDto.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/SearchContactDto.java
@@ -1,8 +1,8 @@
-package fr.insee.survey.datacollectionmanagement.query.dto;
-
-public interface SearchContactDto {
- String getIdentifier();
- String getEmail();
- String getFirstName();
- String getLastName();
-}
+package fr.insee.survey.datacollectionmanagement.contact.dto;
+
+public interface SearchContactDto {
+ String getIdentifier();
+ String getEmail();
+ String getFirstName();
+ String getLastName();
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/SearchContactDtoImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/SearchContactDtoImpl.java
new file mode 100644
index 00000000..b70d7101
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/SearchContactDtoImpl.java
@@ -0,0 +1,14 @@
+package fr.insee.survey.datacollectionmanagement.contact.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class SearchContactDtoImpl implements SearchContactDto{
+
+ private String identifier;
+ private String email;
+ private String firstName;
+ private String lastName;
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/repository/ContactRepository.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/repository/ContactRepository.java
index 3d3846e9..11426db5 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/repository/ContactRepository.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/repository/ContactRepository.java
@@ -1,7 +1,7 @@
package fr.insee.survey.datacollectionmanagement.contact.repository;
import fr.insee.survey.datacollectionmanagement.contact.domain.Contact;
-import fr.insee.survey.datacollectionmanagement.query.dto.SearchContactDto;
+import fr.insee.survey.datacollectionmanagement.contact.dto.SearchContactDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -18,36 +18,52 @@ public interface ContactRepository extends PagingAndSortingRepository findByParameter(String param, Pageable pageable);
-
- Page findByIdentifierIgnoreCaseStartingWithOrFirstNameIgnoreCaseStartingWithOrLastNameIgnoreCaseStartingWithOrEmailIgnoreCaseStartingWith(String identifier, String firstName, String lastName, String email, Pageable pageable);
-
- @Query(nativeQuery = true, value = "SELECT * FROM contact c WHERE UPPER(CONCAT(c.first_name, ' ', c.last_name)) LIKE CONCAT(:param, '%')")
- Page findByFirstNameLastName( String param, Pageable pageable);
-
- @Query(nativeQuery = true, value = "SELECT * FROM contact")
- Page findAllNoParameters(Pageable pageable);
+ Page findByIdentifier( String param, Pageable pageable);
+ @Query(
+ value = """
+ SELECT
+ c.identifier as identifier,
+ c.email as email,
+ c.first_name as firstName,
+ c.last_name as lastName
+ FROM
+ contact c
+ WHERE
+ UPPER(c.email) LIKE CONCAT(UPPER(:param), '%')
+ """,
+ nativeQuery = true
+ )
+ Page findByEmail( String param, Pageable pageable);
+ @Query(
+ value = """
+ SELECT
+ c.identifier as identifier,
+ c.email as email,
+ c.first_name as firstName,
+ c.last_name as lastName
+ FROM
+ contact c
+ WHERE
+ UPPER(c.last_name) LIKE CONCAT(UPPER(:param), '%')
+ OR UPPER(CONCAT(c.first_name, ' ', c.last_name)) LIKE CONCAT(UPPER(:param), '%')
+ """,
+ nativeQuery = true
+ )
+ Page findByFirstNameLastName(String param, Pageable pageable);
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/ContactService.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/ContactService.java
index fbf76467..6f1020a3 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/ContactService.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/ContactService.java
@@ -2,8 +2,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import fr.insee.survey.datacollectionmanagement.contact.domain.Contact;
+import fr.insee.survey.datacollectionmanagement.contact.dto.SearchContactDto;
import fr.insee.survey.datacollectionmanagement.exception.NotFoundException;
-import fr.insee.survey.datacollectionmanagement.query.dto.SearchContactDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@@ -46,12 +46,17 @@ public interface ContactService {
*/
void deleteContact(String identifier);
- Page findByParameter(String param, Pageable pageable);
-
Contact createContactAddressEvent(Contact contact, JsonNode payload);
Contact updateContactAddressEvent(Contact contact, JsonNode payload) throws NotFoundException;
void deleteContactAddressEvent(Contact contact);
+ Page searchContactByIdentifier(String identifier, Pageable pageable);
+
+ Page searchContactByEmail(String email, Pageable pageable);
+
+ Page searchContactByName(String name, Pageable pageable);
+
+
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/AddressServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/AddressServiceImpl.java
index 6cfb866b..de3345a6 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/AddressServiceImpl.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/AddressServiceImpl.java
@@ -41,14 +41,11 @@ public void deleteAddressById(Long id) {
}
public AddressDto convertToDto(Address address) {
- AddressDto adressDto = modelMapper.map(address, AddressDto.class);
-
- return adressDto;
+ return modelMapper.map(address, AddressDto.class);
}
public Address convertToEntity(AddressDto addressDto) {
- Address address = modelMapper.map(addressDto, Address.class);
- return address;
+ return modelMapper.map(addressDto, Address.class);
}
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/ContactServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/ContactServiceImpl.java
index 2d6c5004..076f901b 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/ContactServiceImpl.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/service/impl/ContactServiceImpl.java
@@ -4,14 +4,13 @@
import fr.insee.survey.datacollectionmanagement.contact.domain.Contact;
import fr.insee.survey.datacollectionmanagement.contact.domain.ContactEvent;
import fr.insee.survey.datacollectionmanagement.contact.domain.ContactEvent.ContactEventType;
+import fr.insee.survey.datacollectionmanagement.contact.dto.SearchContactDto;
import fr.insee.survey.datacollectionmanagement.contact.repository.ContactRepository;
import fr.insee.survey.datacollectionmanagement.contact.service.AddressService;
import fr.insee.survey.datacollectionmanagement.contact.service.ContactEventService;
import fr.insee.survey.datacollectionmanagement.contact.service.ContactService;
import fr.insee.survey.datacollectionmanagement.exception.NotFoundException;
-import fr.insee.survey.datacollectionmanagement.query.dto.SearchContactDto;
import lombok.RequiredArgsConstructor;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@@ -57,14 +56,20 @@ public void deleteContact(String identifier) {
contactRepository.deleteById(identifier);
}
+
+ @Override
+ public Page searchContactByIdentifier(String identifier, Pageable pageable) {
+ return contactRepository.findByIdentifier(identifier, pageable);
+ }
+
@Override
- public Page findByParameter(String param, Pageable pageable) {
- if (StringUtils.isEmpty(param))
- return contactRepository.findAllNoParameters(pageable);
- String args[] = param.split(" ");
- if (args.length == 1)
- return contactRepository.findByIdentifierIgnoreCaseStartingWithOrFirstNameIgnoreCaseStartingWithOrLastNameIgnoreCaseStartingWithOrEmailIgnoreCaseStartingWith(param, param, param, param, pageable);
- return contactRepository.findByFirstNameLastName(param, pageable);
+ public Page searchContactByEmail(String email, Pageable pageable) {
+ return contactRepository.findByEmail(email, pageable);
+ }
+
+ @Override
+ public Page searchContactByName(String name, Pageable pageable) {
+ return contactRepository.findByFirstNameLastName(name, pageable);
}
@@ -107,4 +112,5 @@ public void deleteContactAddressEvent(Contact contact) {
}
+
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/util/ContactParamEnum.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/util/ContactParamEnum.java
new file mode 100644
index 00000000..7558230d
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/util/ContactParamEnum.java
@@ -0,0 +1,24 @@
+package fr.insee.survey.datacollectionmanagement.contact.util;
+
+import lombok.Getter;
+
+@Getter
+public enum ContactParamEnum {
+
+ IDENTIFIER("identifier"), EMAIL("email"), NAME("name") ;
+
+ ContactParamEnum(String value) {
+ this.value = value;
+ }
+
+ final String value;
+
+ public static ContactParamEnum fromValue(String value) {
+ for (ContactParamEnum param : ContactParamEnum.values()) {
+ if (param.value.equalsIgnoreCase(value)) {
+ return param;
+ }
+ }
+ throw new IllegalArgumentException("No constant found for value: " + value);
+ }
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/validation/ContactParamValidator.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/validation/ContactParamValidator.java
new file mode 100644
index 00000000..f3c36398
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/validation/ContactParamValidator.java
@@ -0,0 +1,23 @@
+package fr.insee.survey.datacollectionmanagement.contact.validation;
+
+import fr.insee.survey.datacollectionmanagement.contact.util.ContactParamEnum;
+import jakarta.validation.ConstraintValidator;
+import jakarta.validation.ConstraintValidatorContext;
+
+import java.util.Arrays;
+
+public class ContactParamValidator implements ConstraintValidator {
+
+ @Override
+ public void initialize(ValidContactParam constraintAnnotation) {
+ ConstraintValidator.super.initialize(constraintAnnotation);
+
+ }
+
+ @Override
+ public boolean isValid(String searchParam, ConstraintValidatorContext context) {
+ if (searchParam == null)
+ return false;
+ return Arrays.stream(ContactParamEnum.values()).anyMatch(v -> searchParam.equalsIgnoreCase(v.name()));
+ }
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/contact/validation/ValidContactParam.java b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/validation/ValidContactParam.java
new file mode 100644
index 00000000..14047eff
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/contact/validation/ValidContactParam.java
@@ -0,0 +1,18 @@
+package fr.insee.survey.datacollectionmanagement.contact.validation;
+
+import jakarta.validation.Constraint;
+import jakarta.validation.Payload;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Constraint(validatedBy = ContactParamValidator.class)
+@Target({ ElementType.FIELD, ElementType.PARAMETER })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ValidContactParam {
+ String message() default "Invalid searchParam value.Only identifier, email and name are valid";
+ Class>[] groups() default {};
+ Class extends Payload>[] payload() default {};
+}
\ No newline at end of file
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/controller/CampaignController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/controller/CampaignController.java
index 64a2ef8f..874f7b1f 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/controller/CampaignController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/controller/CampaignController.java
@@ -134,7 +134,7 @@ public void putParams(@PathVariable("id") String id, @RequestBody @Valid ParamsD
if (paramsDto.getParamId().equalsIgnoreCase(Parameters.ParameterEnum.URL_TYPE.name())
&& Arrays.stream(values()).noneMatch(p -> p.name().equals(paramsDto.getParamValue()))) {
- throw new NotMatchException(String.format("Only %s are valid values for URL_TYPE", Arrays.stream(values()).map(item -> item.name())
+ throw new NotMatchException(String.format("Only %s are valid values for URL_TYPE", Arrays.stream(values()).map(Enum::name)
.collect(joining(" "))));
}
if (paramsDto.getParamId().equalsIgnoreCase(Parameters.ParameterEnum.MAIL_ASSISTANCE.name())
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsController.java
index 9cb1551c..79c27ac0 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/MyQuestioningsController.java
@@ -14,7 +14,7 @@
import java.util.List;
@RestController
-@Tag(name = "4 - Cross domain")
+@Tag(name = "1 - Contacts", description = "Endpoints to create, update, delete and find contacts")
@RequiredArgsConstructor
public class MyQuestioningsController {
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningAccreditationController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningAccreditationController.java
index 6dac8339..18fcff75 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningAccreditationController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningAccreditationController.java
@@ -58,6 +58,7 @@ public class QuestioningAccreditationController {
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
+ @Deprecated
public ResponseEntity> getQuestioningAccreditation(@PathVariable("id") Long id) {
Questioning optQuestioning = questioningService.findbyId(id);
@@ -81,6 +82,7 @@ public ResponseEntity> getQuestioningAccreditation(@PathVariable("id") Long id
@ApiResponse(responseCode = "404", description = "NotFound")
})
@Transactional
+ @Deprecated
public ResponseEntity> postQuestioningAccreditation(@PathVariable("id") Long id,
@RequestBody QuestioningAccreditationDto questioningAccreditationDto) {
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningController.java
index c99a3f57..0bbc1e1c 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/QuestioningController.java
@@ -67,6 +67,7 @@ public ResponseEntity> getQuestioning(@PathVariable("id") Long id) {
@ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(implementation = QuestioningDto.class))),
@ApiResponse(responseCode = "404", description = "NotFound")
})
+ @Deprecated
public ResponseEntity> postQuestioning(@RequestBody QuestioningDto questioningDto) {
SurveyUnit su = surveyUnitService.findbyId(questioningDto.getSurveyUnitId());
;
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/SearchContactController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/SearchContactController.java
deleted file mode 100644
index 6cecdda6..00000000
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/SearchContactController.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package fr.insee.survey.datacollectionmanagement.query.controller;
-
-import fr.insee.survey.datacollectionmanagement.config.auth.user.AuthorityPrivileges;
-import fr.insee.survey.datacollectionmanagement.constants.Constants;
-import fr.insee.survey.datacollectionmanagement.metadata.domain.Partitioning;
-import fr.insee.survey.datacollectionmanagement.metadata.domain.Survey;
-import fr.insee.survey.datacollectionmanagement.metadata.service.PartitioningService;
-import fr.insee.survey.datacollectionmanagement.query.dto.AccreditationDetailDto;
-import fr.insee.survey.datacollectionmanagement.query.dto.SearchContactDto;
-import fr.insee.survey.datacollectionmanagement.query.service.MoogService;
-import fr.insee.survey.datacollectionmanagement.query.service.SearchContactService;
-import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
-import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningAccreditation;
-import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningEvent;
-import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
-import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningAccreditationService;
-import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningEventService;
-import fr.insee.survey.datacollectionmanagement.questioning.util.TypeQuestioningEvent;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
-
-@RestController
-@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES)
-@Tag(name = "4 - Cross domain")
-@Slf4j
-@RequiredArgsConstructor
-public class SearchContactController {
-
- private final SearchContactService searchContactService;
-
- private final QuestioningAccreditationService questioningAccreditationService;
-
- private final PartitioningService partitioningService;
-
- private final QuestioningEventService questioningEventService;
-
- private final MoogService moogService;
-
-
- @GetMapping(path = Constants.API_CONTACTS_SEARCH, produces = "application/json")
- @Operation(summary = "Multi-criteria search contacts")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SearchContactDto.class)))),
- @ApiResponse(responseCode = "400", description = "Bad Request")
- })
- public Page searchContacts(
- @RequestParam(required = false) String param,
- @RequestParam(defaultValue = "0") Integer page,
- @RequestParam(defaultValue = "10") Integer pageSize,
- @RequestParam(defaultValue = "identifier") String sort) {
-
- log.info(
- "Search contact: param = {} ", param, page, pageSize);
-
- Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
-
- return searchContactService.searchContactCrossDomain(param, pageable);
-
-
- }
-
- @GetMapping(path = Constants.API_CONTACTS_ACCREDITATIONS, produces = "application/json")
- @Operation(summary = "Get contact accreditations by the contact id")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = AccreditationDetailDto.class)))),
- @ApiResponse(responseCode = "400", description = "Bad Request")
- })
- public List getContactAccreditations(
- @PathVariable("id") String id,
- @RequestParam(defaultValue = "false") boolean isFilterOpened) {
-
- List listAccreditations = new ArrayList<>();
- List accreditations = questioningAccreditationService.findByContactIdentifier(id);
- for (QuestioningAccreditation questioningAccreditation : accreditations) {
- Questioning questioning = questioningAccreditation.getQuestioning();
- Partitioning part = partitioningService.findById(questioning.getIdPartitioning());
- Optional questioningEvent = questioningEventService.getLastQuestioningEvent(questioning, TypeQuestioningEvent.STATE_EVENTS);
-
- if (!isFilterOpened || partitioningService.isOnGoing(part, new Date())) {
- SurveyUnit su = questioningAccreditation.getQuestioning().getSurveyUnit();
- Survey survey = part.getCampaign().getSurvey();
- listAccreditations.add(new AccreditationDetailDto(
- survey.getSource().getId(),
- survey.getId(),
- survey.getSource().getShortWording(),
- survey.getYear(),
- part.getCampaign().getPeriod(),
- part.getCampaign().getId(),
- part.getId(),
- part.getClosingDate(),
- su.getIdSu(),
- su.getIdentificationName(),
- questioningAccreditation.isMain(),
- questioningEvent.map(QuestioningEvent::getType).orElse(null),
- questioning.getId().toString(),
- moogService.getReadOnlyUrl(part.getCampaign().getId(), su.getIdSu())
- ));
- }
-
- }
-
- return listAccreditations;
-
- }
-
-}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/SearchSurveyUnitController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/SearchSurveyUnitController.java
index 74981e21..58888867 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/SearchSurveyUnitController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/SearchSurveyUnitController.java
@@ -12,7 +12,6 @@
import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningAccreditation;
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningEvent;
-import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningAccreditationService;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningEventService;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
import fr.insee.survey.datacollectionmanagement.questioning.util.TypeQuestioningEvent;
@@ -32,7 +31,7 @@
@RestController
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES)
-@Tag(name = "4 - Cross domain")
+@Tag(name = "2 - Questioning", description = "Enpoints to create, update, delete and find entities around the questionings")
@Slf4j
@RequiredArgsConstructor
public class SearchSurveyUnitController {
@@ -42,8 +41,6 @@ public class SearchSurveyUnitController {
private final QuestioningService questioningService;
- private final QuestioningAccreditationService questioningAccreditationService;
-
private final PartitioningService partitioningService;
private final QuestioningEventService questioningEventService;
@@ -69,16 +66,13 @@ public ResponseEntity> getSurveyUnitContacts(
SearchSurveyUnitContactDto searchSurveyUnitContactDto = new SearchSurveyUnitContactDto();
Contact contact = contactService.findByIdentifier(identifier);
searchSurveyUnitContactDto.setIdentifier(identifier);
+ searchSurveyUnitContactDto.setFunction(contact.getFunction());
searchSurveyUnitContactDto.setCity(contact.getEmail());
searchSurveyUnitContactDto.setEmail(contact.getEmail());
searchSurveyUnitContactDto.setFirstName(contact.getFirstName());
searchSurveyUnitContactDto.setLastName(contact.getLastName());
searchSurveyUnitContactDto.setPhoneNumber(contact.getPhone());
searchSurveyUnitContactDto.setCity(contact.getAddress() != null ? contact.getAddress().getCityName() : null);
- searchSurveyUnitContactDto.setListSourcesId(questioningAccreditationService.findByContactIdentifier(identifier).stream().
- filter(qa -> qa.getQuestioning().getSurveyUnit().getIdSu().equalsIgnoreCase(id)).
- map(qa -> partitioningService.findById(qa.getQuestioning().getIdPartitioning()).getCampaign().getSurvey().getSource().getId()).
- distinct().toList());
listResult.add(searchSurveyUnitContactDto);
}
@@ -89,10 +83,10 @@ public ResponseEntity> getSurveyUnitContacts(
@GetMapping(path = Constants.API_SURVEY_UNITS_PARTITIONINGS, produces = "application/json")
@Operation(summary = "Get contacts authorised to respond to a survey for a survey unit")
+ @Deprecated
public ResponseEntity> getSurveyUnitPartitionings(
@PathVariable("id") String id,
@RequestParam(defaultValue = "false") boolean isFilterOpened) {
-
List listParts = new ArrayList<>();
Set setQuestionings = questioningService.findBySurveyUnitIdSu(id);
for (Questioning questioning : setQuestionings) {
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/WebclientController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/WebclientController.java
index 8a3922df..b8892406 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/WebclientController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/query/controller/WebclientController.java
@@ -153,7 +153,7 @@ public ResponseEntity putQuestioning(@RequestBody Quest
// save questioning and su
questioningService.saveQuestioning(questioning);
su.getQuestionings().add(questioning);
- surveyUnitService.saveSurveyUnitAndAddress(su);
+ surveyUnitService.saveSurveyUnitAddressComments(su);
questioningReturn.setIdPartitioning(idPartitioning);
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/dto/SearchSurveyUnitContactDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/dto/SearchSurveyUnitContactDto.java
index 01219e7a..70487551 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/dto/SearchSurveyUnitContactDto.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/query/dto/SearchSurveyUnitContactDto.java
@@ -3,8 +3,6 @@
import lombok.Getter;
import lombok.Setter;
-import java.util.List;
-
@Getter
@Setter
public class SearchSurveyUnitContactDto {
@@ -15,5 +13,5 @@ public class SearchSurveyUnitContactDto {
private String email;
private String city;
private String phoneNumber;
- private List listSourcesId;
+ private String function;
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/SearchContactService.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/SearchContactService.java
deleted file mode 100644
index 7723b4cf..00000000
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/SearchContactService.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package fr.insee.survey.datacollectionmanagement.query.service;
-
-import fr.insee.survey.datacollectionmanagement.query.dto.SearchContactDto;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-
-public interface SearchContactService {
-
- /**
- * Search contact according to different parameters
- * @param param search contact parameter (mail or identifier or name
- * @return Page SearchContactDto
- */
- Page searchContactCrossDomain(
- String param,
- Pageable pageable);
-}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/impl/MoogServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/impl/MoogServiceImpl.java
index 4a9a4171..7332602d 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/impl/MoogServiceImpl.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/impl/MoogServiceImpl.java
@@ -2,6 +2,7 @@
import fr.insee.survey.datacollectionmanagement.config.JSONCollectionWrapper;
import fr.insee.survey.datacollectionmanagement.constants.UserRoles;
+import fr.insee.survey.datacollectionmanagement.contact.domain.Address;
import fr.insee.survey.datacollectionmanagement.contact.domain.Contact;
import fr.insee.survey.datacollectionmanagement.contact.service.ContactService;
import fr.insee.survey.datacollectionmanagement.exception.NotFoundException;
@@ -22,6 +23,7 @@
import fr.insee.survey.datacollectionmanagement.view.service.ViewService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -71,7 +73,8 @@ public List transformListViewToListMoogSearchDto(List listV
moogCampaign
.setCollectionStartDate(camp.getPartitionings().iterator().next().getOpeningDate().getTime());
moogSearchDto.setIdContact(view.getIdentifier());
- moogSearchDto.setAddress(c.getAddress().getZipCode().concat(" ").concat(c.getAddress().getCityName()));
+ String address = createAddressMoog(c.getAddress());
+ moogSearchDto.setAddress(address);
moogSearchDto.setIdSu(view.getIdSu());
moogSearchDto.setCampaign(moogCampaign);
moogSearchDto.setFirstName(c.getFirstName());
@@ -82,6 +85,16 @@ public List transformListViewToListMoogSearchDto(List listV
return listResult;
}
+ protected String createAddressMoog(Address address) {
+ String zipCode = address.getZipCode();
+ String city = address.getCityName();
+ return StringUtils.trim(String.join(" ", valueNotNull(zipCode), valueNotNull(city)));
+ }
+
+ private String valueNotNull(String value) {
+ return value == null || value.isBlank() ? "" : value;
+ }
+
@Override
public List getMoogEvents(String campaign, String idSu) {
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/impl/SearchContactServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/impl/SearchContactServiceImpl.java
deleted file mode 100644
index 4dcd526b..00000000
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/query/service/impl/SearchContactServiceImpl.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package fr.insee.survey.datacollectionmanagement.query.service.impl;
-
-import fr.insee.survey.datacollectionmanagement.contact.service.ContactService;
-import fr.insee.survey.datacollectionmanagement.query.dto.SearchContactDto;
-import fr.insee.survey.datacollectionmanagement.query.service.SearchContactService;
-import lombok.RequiredArgsConstructor;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.stereotype.Service;
-import org.apache.commons.lang3.StringUtils;
-
-
-@Service
-@RequiredArgsConstructor
-public class SearchContactServiceImpl implements SearchContactService {
-
- private final ContactService contactService;
-
-
- @Override
- public Page searchContactCrossDomain(String param, Pageable pageable) {
- return contactService.findByParameter(StringUtils.upperCase(param), pageable);
- }
-
-
-}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitCommentController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitCommentController.java
new file mode 100644
index 00000000..4d1d032b
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitCommentController.java
@@ -0,0 +1,70 @@
+package fr.insee.survey.datacollectionmanagement.questioning.controller;
+
+import fr.insee.survey.datacollectionmanagement.config.auth.user.AuthorityPrivileges;
+import fr.insee.survey.datacollectionmanagement.constants.Constants;
+import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
+import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
+import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentInputDto;
+import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitCommentService;
+import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.modelmapper.ModelMapper;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+
+import java.util.Date;
+import java.util.Set;
+
+@RestController
+@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES)
+@Tag(name = "2 - Questioning", description = "Enpoints to create, update, delete and find entities around the questionings")
+@Slf4j
+@RequiredArgsConstructor
+@Validated
+public class SurveyUnitCommentController {
+
+ private final SurveyUnitService surveyUnitService;
+ private final SurveyUnitCommentService surveyUnitCommentService;
+ private final ModelMapper modelMapper;
+
+
+ @Operation(summary = "Create a survey unit comment")
+ @PostMapping(value = Constants.API_SURVEY_UNITS_ID_COMMENT, produces = "application/json", consumes = "application/json")
+ @ResponseStatus(HttpStatus.CREATED)
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(implementation = SurveyUnitCommentInputDto.class))),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "404", description = "Not found")
+ })
+ public void postSurveyUnitComment(@PathVariable String id, @Valid @RequestBody SurveyUnitCommentInputDto surveyUnitCommentDto) {
+
+ SurveyUnit surveyUnit = surveyUnitService.findbyId(id);
+ SurveyUnitComment surveyUnitComment = convertToEntity(surveyUnitCommentDto);
+ surveyUnitComment.setDate(new Date());
+ SurveyUnitComment newSurveyUnitComment = surveyUnitCommentService.saveSurveyUnitComment(surveyUnitComment);
+ Set setSurveyUnitComments = surveyUnit.getSurveyUnitComments();
+ setSurveyUnitComments.add(newSurveyUnitComment);
+ surveyUnit.setSurveyUnitComments(setSurveyUnitComments);
+ surveyUnitService.saveSurveyUnit(surveyUnit);
+
+ }
+
+ private SurveyUnitComment convertToEntity(SurveyUnitCommentInputDto surveyUnitCommentDto) {
+ return modelMapper.map(surveyUnitCommentDto, SurveyUnitComment.class);
+ }
+
+
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java
index d98b5de9..430e34cc 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java
@@ -2,12 +2,19 @@
import fr.insee.survey.datacollectionmanagement.config.auth.user.AuthorityPrivileges;
import fr.insee.survey.datacollectionmanagement.constants.Constants;
+import fr.insee.survey.datacollectionmanagement.exception.ImpossibleToDeleteException;
import fr.insee.survey.datacollectionmanagement.exception.NotFoundException;
import fr.insee.survey.datacollectionmanagement.exception.NotMatchException;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
+import fr.insee.survey.datacollectionmanagement.questioning.dto.SearchSurveyUnitDto;
+import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitDetailsDto;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitService;
+import fr.insee.survey.datacollectionmanagement.questioning.util.SurveyUnitParamEnum;
+import fr.insee.survey.datacollectionmanagement.questioning.validation.ValidSurveyUnitParam;
+import fr.insee.survey.datacollectionmanagement.view.service.ViewService;
import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -27,6 +34,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+import java.util.Collections;
import java.util.List;
@RestController
@@ -38,6 +46,7 @@
public class SurveyUnitController {
private final SurveyUnitService surveyUnitService;
+ private final ViewService viewService;
private final ModelMapper modelMapper;
@Operation(summary = "Search for a survey units, paginated")
@@ -47,6 +56,7 @@ public class SurveyUnitController {
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
+ @Deprecated(since="2.6.0", forRemoval=true)
public Page getSurveyUnits(
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "20") Integer size,
@@ -60,33 +70,44 @@ public Page getSurveyUnits(
@Operation(summary = "Multi-criteria search survey-unit")
@GetMapping(value = Constants.API_SURVEY_UNITS_SEARCH, produces = "application/json")
@ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SurveyUnitPage.class))),
+ @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SearchSurveyUnitDto.class)))),
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
- public Page searchSurveyUnits(
- @RequestParam(required = false) String idSu,
- @RequestParam(required = false) String identificationCode,
- @RequestParam(required = false) String identificationName,
+ public Page searchSurveyUnits(
+ @RequestParam(required = true) String searchParam,
+ @RequestParam(required = true) @Valid @ValidSurveyUnitParam @Schema(description = "id or code or name")String searchType,
@RequestParam(defaultValue = "0") Integer page,
- @RequestParam(defaultValue = "20") Integer size,
+ @RequestParam(defaultValue = "20") Integer pageSize,
@RequestParam(defaultValue = "id_su") String sort) {
- Pageable pageable = PageRequest.of(page, size, Sort.by(sort));
- Page pageC = surveyUnitService.findByParameters(idSu, identificationCode, identificationName, pageable);
- List listSuDto = pageC.stream().map(this::convertToDto).toList();
- return new SurveyUnitPage(listSuDto, pageable, pageC.getTotalElements());
+ log.info(
+ "Search surveyUnit by {} with param = {} page = {} pageSize = {}", searchType, searchParam, page, pageSize);
+
+ Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
+
+ switch (SurveyUnitParamEnum.fromValue(searchType)) {
+ case SurveyUnitParamEnum.IDENTIFIER:
+ return surveyUnitService.findbyIdentifier(searchParam, pageable);
+ case SurveyUnitParamEnum.CODE:
+ return surveyUnitService.findbyIdentificationCode(searchParam, pageable);
+ case SurveyUnitParamEnum.NAME:
+ return surveyUnitService.findbyIdentificationName(searchParam, pageable);
+ }
+ return new PageImpl<>(Collections.emptyList());
}
@Operation(summary = "Search for a survey unit by its id")
@GetMapping(value = Constants.API_SURVEY_UNITS_ID, produces = "application/json")
@ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SurveyUnitDto.class))),
+ @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SurveyUnitDetailsDto.class))),
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
- public ResponseEntity findSurveyUnit(@PathVariable("id") String id) {
+ public SurveyUnitDetailsDto findSurveyUnit(@PathVariable("id") String id) {
SurveyUnit surveyUnit = surveyUnitService.findbyId(StringUtils.upperCase(id));
- return ResponseEntity.status(HttpStatus.OK).body(convertToDto(surveyUnit));
+ SurveyUnitDetailsDto surveyUnitDetailsDto = convertToDetailsDto(surveyUnit);
+ surveyUnitDetailsDto.setHasQuestionings(!viewService.findViewByIdSu(id).isEmpty());
+ return surveyUnitDetailsDto;
}
@@ -120,7 +141,7 @@ public ResponseEntity putSurveyUnit(@PathVariable("id") String id
}
return ResponseEntity.status(responseStatus)
- .body(convertToDto(surveyUnitService.saveSurveyUnitAndAddress(surveyUnit)));
+ .body(convertToDto(surveyUnitService.saveSurveyUnitAddressComments(surveyUnit)));
}
@@ -131,27 +152,28 @@ public ResponseEntity putSurveyUnit(@PathVariable("id") String id
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "400", description = "Bad request")
})
- public ResponseEntity deleteSurveyUnit(@PathVariable("id") String id) {
+ @Deprecated(since="2.6.0", forRemoval=true)
+ public void deleteSurveyUnit(@PathVariable("id") String id) {
SurveyUnit surveyUnit = surveyUnitService.findbyId(StringUtils.upperCase(id));
- try {
- if (!surveyUnit.getQuestionings().isEmpty()) {
- log.warn("Some questionings exist for the survey unit {}, the survey unit can't be deleted", id);
- return ResponseEntity.status(HttpStatus.BAD_REQUEST)
- .body("Some questionings exist for this survey unit, the survey unit can't be deleted");
- }
- surveyUnitService.deleteSurveyUnit(id);
- return ResponseEntity.status(HttpStatus.NO_CONTENT).body("Survey unit deleted");
-
- } catch (Exception e) {
- return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Error");
+ if (!surveyUnit.getQuestionings().isEmpty()) {
+ log.warn("Some questionings exist for the survey unit {}, the survey unit can't be deleted", id);
+ throw new ImpossibleToDeleteException("Some questionings exist for this survey unit, the survey unit can't be deleted");
+
}
+ surveyUnitService.deleteSurveyUnit(id);
+
}
private SurveyUnitDto convertToDto(SurveyUnit surveyUnit) {
return modelMapper.map(surveyUnit, SurveyUnitDto.class);
}
+ private SurveyUnitDetailsDto convertToDetailsDto(SurveyUnit surveyUnit) {
+ return modelMapper.map(surveyUnit, SurveyUnitDetailsDto.class);
+ }
+
+
private SurveyUnit convertToEntity(SurveyUnitDto surveyUnitDto) {
return modelMapper.map(surveyUnitDto, SurveyUnit.class);
}
@@ -164,4 +186,6 @@ public SurveyUnitPage(List content, Pageable pageable, long total
super(content, pageable, total);
}
}
+
+
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java
index 56a0ae90..ef54a65c 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java
@@ -33,6 +33,9 @@ public class SurveyUnit {
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private SurveyUnitAddress surveyUnitAddress;
+ @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+ private Set surveyUnitComments;
+
@Override
public String toString() {
return "SurveyUnit [idSu=" + idSu + ", identificationCode=" + identificationCode + ", identificationName="
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnitComment.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnitComment.java
new file mode 100644
index 00000000..e861a982
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnitComment.java
@@ -0,0 +1,20 @@
+package fr.insee.survey.datacollectionmanagement.questioning.domain;
+
+import jakarta.persistence.*;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@Entity
+@Getter
+@Setter
+public class SurveyUnitComment {
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "su_comment_seq")
+ private Long id;
+ @Column(length = 2000)
+ private String comment;
+ private String author;
+ private Date date;
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SearchSurveyUnitDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SearchSurveyUnitDto.java
new file mode 100644
index 00000000..47ecfd2f
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SearchSurveyUnitDto.java
@@ -0,0 +1,8 @@
+package fr.insee.survey.datacollectionmanagement.questioning.dto;
+
+public interface SearchSurveyUnitDto {
+
+ String getIdSu();
+ String getIdentificationCode();
+ String getIdentificationName();
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SearchSurveyUnitDtoImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SearchSurveyUnitDtoImpl.java
new file mode 100644
index 00000000..cd7439ac
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SearchSurveyUnitDtoImpl.java
@@ -0,0 +1,14 @@
+package fr.insee.survey.datacollectionmanagement.questioning.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class SearchSurveyUnitDtoImpl implements SearchSurveyUnitDto{
+
+ private String idSu;
+ private String identificationCode;
+ private String identificationName;
+
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitCommentInputDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitCommentInputDto.java
new file mode 100644
index 00000000..84c725c6
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitCommentInputDto.java
@@ -0,0 +1,11 @@
+package fr.insee.survey.datacollectionmanagement.questioning.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class SurveyUnitCommentInputDto {
+ private String comment;
+ private String author;
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitCommentOutputDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitCommentOutputDto.java
new file mode 100644
index 00000000..40b555d9
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitCommentOutputDto.java
@@ -0,0 +1,14 @@
+package fr.insee.survey.datacollectionmanagement.questioning.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@Getter
+@Setter
+public class SurveyUnitCommentOutputDto {
+ private String comment;
+ private String author;
+ private Date commentDate;
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitDetailsDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitDetailsDto.java
new file mode 100644
index 00000000..575f22be
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitDetailsDto.java
@@ -0,0 +1,21 @@
+package fr.insee.survey.datacollectionmanagement.questioning.dto;
+
+import jakarta.validation.constraints.NotBlank;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Set;
+
+@Getter
+@Setter
+public class SurveyUnitDetailsDto {
+
+ @NotBlank
+ private String idSu;
+ private String identificationCode;
+ private String identificationName;
+ private SurveyUnitAddressDto address;
+ private boolean hasQuestionings;
+ private Set comments;
+
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/SurveyUnitCommentRepository.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/SurveyUnitCommentRepository.java
new file mode 100644
index 00000000..204d5b4e
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/SurveyUnitCommentRepository.java
@@ -0,0 +1,8 @@
+package fr.insee.survey.datacollectionmanagement.questioning.repository;
+
+import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface SurveyUnitCommentRepository extends JpaRepository {
+
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/SurveyUnitRepository.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/SurveyUnitRepository.java
index 427c15a3..a82a9646 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/SurveyUnitRepository.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/SurveyUnitRepository.java
@@ -1,11 +1,11 @@
package fr.insee.survey.datacollectionmanagement.questioning.repository;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
+import fr.insee.survey.datacollectionmanagement.questioning.dto.SearchSurveyUnitDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
import java.util.List;
@@ -13,18 +13,35 @@ public interface SurveyUnitRepository extends JpaRepository
List findAllByIdentificationCode(String identificationCode);
- List findByIdentificationNameIgnoreCase(String identificationName);
-
@Query(nativeQuery = true, value = """
- SELECT *
- FROM survey_unit su
- WHERE (:id_su is null or upper(su.id_su) like upper(concat('%', :id_su, '%')))
- AND (:identification_name is null or upper(su.identification_name) like upper(concat('%', :identification_name, '%')))
- AND (:identification_code is null or upper(su.identification_code) like upper(concat('%', :identification_code, '%')))
+ SELECT
+ *
+ FROM
+ survey_unit su
+ WHERE
+ UPPER(su.id_su) LIKE CONCAT(UPPER(:param), '%')
""")
- Page findByParameters(@Param("id_su") String idSu, @Param("identification_code") String identificationCode, @Param("identification_name") String identificationName, Pageable pageable);
+ Page findByIdentifier(String param, Pageable pageable);
+ @Query(nativeQuery = true, value = """
+ SELECT
+ *
+ FROM
+ survey_unit su
+ WHERE
+ UPPER(su.identification_code) LIKE CONCAT(UPPER(:param), '%')
+
+ """)
+ Page findByIdentificationCode(String param, Pageable pageable);
- @Query(nativeQuery = true, value = "SELECT * FROM survey_unit ORDER BY random() LIMIT 1")
- SurveyUnit findRandomSurveyUnit();
+ @Query(nativeQuery = true, value = """
+ SELECT
+ *
+ FROM
+ survey_unit su
+ WHERE
+ UPPER(su.identification_name) LIKE CONCAT(UPPER(:param), '%')
+
+ """)
+ Page findByIdentificationName(String param, Pageable pageable);
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/QuestioningAccreditationService.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/QuestioningAccreditationService.java
index ed780ea8..358fe83c 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/QuestioningAccreditationService.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/QuestioningAccreditationService.java
@@ -19,4 +19,5 @@ public interface QuestioningAccreditationService {
void deleteAccreditation(QuestioningAccreditation c);
+ List findCampaignsForContactId(String id);
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/SurveyUnitCommentService.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/SurveyUnitCommentService.java
new file mode 100644
index 00000000..34440680
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/SurveyUnitCommentService.java
@@ -0,0 +1,10 @@
+package fr.insee.survey.datacollectionmanagement.questioning.service;
+
+import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
+
+public interface SurveyUnitCommentService {
+
+ SurveyUnitComment saveSurveyUnitComment(SurveyUnitComment surveyUnitComment);
+
+
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/SurveyUnitService.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/SurveyUnitService.java
index 8af5edca..2562d846 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/SurveyUnitService.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/SurveyUnitService.java
@@ -1,27 +1,26 @@
package fr.insee.survey.datacollectionmanagement.questioning.service;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
+import fr.insee.survey.datacollectionmanagement.questioning.dto.SearchSurveyUnitDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
-import java.util.List;
-
public interface SurveyUnitService {
- public SurveyUnit findbyId(String idSu);
+ SurveyUnit findbyId(String idSu);
- public List findbyIdentificationCode(String identificationCode);
+ Page findbyIdentifier(String id, Pageable pageable);
- public List findbyIdentificationName(String identificationName);
+ Page findbyIdentificationCode(String identificationCode, Pageable pageable);
- public Page findAll(Pageable pageable);
+ Page findbyIdentificationName(String identificationName, Pageable pageable);
- public Page findByParameters(String idSu, String identificationCode, String identificationName, Pageable pageable);
+ Page findAll(Pageable pageable);
- public SurveyUnit saveSurveyUnit(SurveyUnit surveyUnit);
+ SurveyUnit saveSurveyUnit(SurveyUnit surveyUnit);
- public SurveyUnit saveSurveyUnitAndAddress(SurveyUnit surveyUnit);
+ SurveyUnit saveSurveyUnitAddressComments(SurveyUnit surveyUnit);
- public void deleteSurveyUnit(String id);
+ void deleteSurveyUnit(String id);
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/QuestioningAccreditationServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/QuestioningAccreditationServiceImpl.java
index dbc2cf30..b2827241 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/QuestioningAccreditationServiceImpl.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/QuestioningAccreditationServiceImpl.java
@@ -1,6 +1,7 @@
package fr.insee.survey.datacollectionmanagement.questioning.service.impl;
import fr.insee.survey.datacollectionmanagement.exception.NotFoundException;
+import fr.insee.survey.datacollectionmanagement.metadata.service.PartitioningService;
import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningAccreditation;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
@@ -20,6 +21,7 @@
public class QuestioningAccreditationServiceImpl implements QuestioningAccreditationService {
private final QuestioningAccreditationRepository questioningAccreditationRepository;
+ private final PartitioningService partitioningService;
public List findByContactIdentifier(String id) {
return questioningAccreditationRepository.findByIdContact(id);
@@ -40,7 +42,7 @@ public Page findAll(Pageable pageable) {
@Override
public QuestioningAccreditation findById(Long id) {
- return questioningAccreditationRepository.findById(id).orElseThrow(()-> new NotFoundException(String.format("QuestioningAccreditation %s not found", id)));
+ return questioningAccreditationRepository.findById(id).orElseThrow(() -> new NotFoundException(String.format("QuestioningAccreditation %s not found", id)));
}
@Override
@@ -53,4 +55,10 @@ public void deleteAccreditation(QuestioningAccreditation acc) {
questioningAccreditationRepository.deleteById(acc.getId());
}
+ @Override
+ public List findCampaignsForContactId(String id) {
+ List listContactAccreditations = findByContactIdentifier(id);
+ return listContactAccreditations.stream().map(acc -> partitioningService.findById(acc.getQuestioning().getIdPartitioning()).getCampaign().getId()).distinct().toList();
+ }
+
}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/SurveyUnitCommentServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/SurveyUnitCommentServiceImpl.java
new file mode 100644
index 00000000..f8cd6a17
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/SurveyUnitCommentServiceImpl.java
@@ -0,0 +1,20 @@
+package fr.insee.survey.datacollectionmanagement.questioning.service.impl;
+
+import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
+import fr.insee.survey.datacollectionmanagement.questioning.repository.SurveyUnitCommentRepository;
+import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitCommentService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+@RequiredArgsConstructor
+public class SurveyUnitCommentServiceImpl implements SurveyUnitCommentService {
+
+ private final SurveyUnitCommentRepository surveyUnitCommentRepository;
+ @Override
+ public SurveyUnitComment saveSurveyUnitComment(SurveyUnitComment surveyUnitComment) {
+ return surveyUnitCommentRepository.save(surveyUnitComment);
+ }
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/SurveyUnitServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/SurveyUnitServiceImpl.java
index 37dbd70a..2f601643 100644
--- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/SurveyUnitServiceImpl.java
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/service/impl/SurveyUnitServiceImpl.java
@@ -2,6 +2,7 @@
import fr.insee.survey.datacollectionmanagement.exception.NotFoundException;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
+import fr.insee.survey.datacollectionmanagement.questioning.dto.SearchSurveyUnitDto;
import fr.insee.survey.datacollectionmanagement.questioning.repository.SurveyUnitAddressRepository;
import fr.insee.survey.datacollectionmanagement.questioning.repository.SurveyUnitRepository;
import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitService;
@@ -11,8 +12,6 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
-import java.util.List;
-
@Service
@Slf4j
@RequiredArgsConstructor
@@ -28,23 +27,24 @@ public SurveyUnit findbyId(String idSu) {
}
@Override
- public List findbyIdentificationCode(String identificationCode) {
- return surveyUnitRepository.findAllByIdentificationCode(identificationCode);
+ public Page findbyIdentifier(String id, Pageable pageable) {
+ return surveyUnitRepository.findByIdentifier(id, pageable);
}
@Override
- public List findbyIdentificationName(String identificationName) {
- return surveyUnitRepository.findByIdentificationNameIgnoreCase(identificationName);
+ public Page findbyIdentificationCode(String identificationCode, Pageable pageable) {
+ return surveyUnitRepository.findByIdentificationCode(identificationCode, pageable);
}
@Override
- public Page findAll(Pageable pageable) {
- return surveyUnitRepository.findAll(pageable);
+ public Page findbyIdentificationName(String identificationName, Pageable pageable) {
+ return surveyUnitRepository.findByIdentificationName(identificationName, pageable);
}
+
@Override
- public Page findByParameters(String idSu, String identificationCode, String identificationName, Pageable pageable) {
- return surveyUnitRepository.findByParameters(idSu, identificationCode, identificationName, pageable);
+ public Page findAll(Pageable pageable) {
+ return surveyUnitRepository.findAll(pageable);
}
@Override
@@ -53,8 +53,14 @@ public SurveyUnit saveSurveyUnit(SurveyUnit surveyUnit) {
}
@Override
- public SurveyUnit saveSurveyUnitAndAddress(SurveyUnit surveyUnit) {
+ public SurveyUnit saveSurveyUnitAddressComments(SurveyUnit surveyUnit) {
+ try {
+ SurveyUnit existingSurveyUnit = findbyId(surveyUnit.getIdSu());
+ surveyUnit.setSurveyUnitComments(existingSurveyUnit.getSurveyUnitComments());
+ } catch (NotFoundException e) {
+ log.debug("Survey unit does not exist");
+ }
if (surveyUnit.getSurveyUnitAddress() != null) {
try {
SurveyUnit existingSurveyUnit = findbyId(surveyUnit.getIdSu());
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/util/SurveyUnitParamEnum.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/util/SurveyUnitParamEnum.java
new file mode 100644
index 00000000..062494c3
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/util/SurveyUnitParamEnum.java
@@ -0,0 +1,24 @@
+package fr.insee.survey.datacollectionmanagement.questioning.util;
+
+import lombok.Getter;
+
+@Getter
+public enum SurveyUnitParamEnum {
+
+ IDENTIFIER("id"), CODE("code"), NAME("name") ;
+
+ SurveyUnitParamEnum(String value) {
+ this.value = value;
+ }
+
+ final String value;
+
+ public static SurveyUnitParamEnum fromValue(String value) {
+ for (SurveyUnitParamEnum param : SurveyUnitParamEnum.values()) {
+ if (param.value.equalsIgnoreCase(value)) {
+ return param;
+ }
+ }
+ throw new IllegalArgumentException("No constant found for value: " + value);
+ }
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/validation/SurveyUnitParamValidator.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/validation/SurveyUnitParamValidator.java
new file mode 100644
index 00000000..bca32070
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/validation/SurveyUnitParamValidator.java
@@ -0,0 +1,23 @@
+package fr.insee.survey.datacollectionmanagement.questioning.validation;
+
+import fr.insee.survey.datacollectionmanagement.questioning.util.SurveyUnitParamEnum;
+import jakarta.validation.ConstraintValidator;
+import jakarta.validation.ConstraintValidatorContext;
+
+import java.util.Arrays;
+
+public class SurveyUnitParamValidator implements ConstraintValidator {
+
+ @Override
+ public void initialize(ValidSurveyUnitParam constraintAnnotation) {
+ ConstraintValidator.super.initialize(constraintAnnotation);
+
+ }
+
+ @Override
+ public boolean isValid(String searchParam, ConstraintValidatorContext context) {
+ if (searchParam == null)
+ return false;
+ return Arrays.stream(SurveyUnitParamEnum.values()).anyMatch(v -> searchParam.equalsIgnoreCase(v.name()));
+ }
+}
diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/validation/ValidSurveyUnitParam.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/validation/ValidSurveyUnitParam.java
new file mode 100644
index 00000000..b4714f20
--- /dev/null
+++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/validation/ValidSurveyUnitParam.java
@@ -0,0 +1,18 @@
+package fr.insee.survey.datacollectionmanagement.questioning.validation;
+
+import jakarta.validation.Constraint;
+import jakarta.validation.Payload;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Constraint(validatedBy = SurveyUnitParamValidator.class)
+@Target({ ElementType.FIELD, ElementType.PARAMETER })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ValidSurveyUnitParam {
+ String message() default "Invalid searchParam value.Only id, code or name are valid";
+ Class>[] groups() default {};
+ Class extends Payload>[] payload() default {};
+}
\ No newline at end of file
diff --git a/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/AddressControllerTest.java b/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/AddressControllerTest.java
index c46c8edc..9a27dc60 100644
--- a/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/AddressControllerTest.java
+++ b/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/AddressControllerTest.java
@@ -32,7 +32,7 @@
@SpringBootTest
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
-public class AddressControllerTest {
+class AddressControllerTest {
@Autowired
MockMvc mockMvc;
diff --git a/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactControllerTest.java b/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactControllerTest.java
index e69a2f00..7752dc02 100644
--- a/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactControllerTest.java
+++ b/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactControllerTest.java
@@ -39,7 +39,7 @@
@SpringBootTest
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
-public class ContactControllerTest {
+class ContactControllerTest {
@Autowired
MockMvc mockMvc;
diff --git a/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactEventControllerTest.java b/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactEventControllerTest.java
index 36d6a416..141ef215 100644
--- a/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactEventControllerTest.java
+++ b/src/test/java/fr/insee/survey/datacollectionmanagement/contacts/controller/ContactEventControllerTest.java
@@ -26,7 +26,7 @@
@SpringBootTest
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
-public class ContactEventControllerTest {
+class ContactEventControllerTest {
@Autowired
MockMvc mockMvc;
diff --git a/src/test/java/fr/insee/survey/datacollectionmanagement/query/CucumberTest.java b/src/test/java/fr/insee/survey/datacollectionmanagement/integration/CucumberTest.java
similarity index 90%
rename from src/test/java/fr/insee/survey/datacollectionmanagement/query/CucumberTest.java
rename to src/test/java/fr/insee/survey/datacollectionmanagement/integration/CucumberTest.java
index d6f38747..24bb8198 100644
--- a/src/test/java/fr/insee/survey/datacollectionmanagement/query/CucumberTest.java
+++ b/src/test/java/fr/insee/survey/datacollectionmanagement/integration/CucumberTest.java
@@ -1,4 +1,4 @@
-package fr.insee.survey.datacollectionmanagement.query;
+package fr.insee.survey.datacollectionmanagement.integration;
import io.cucumber.spring.CucumberContextConfiguration;
import org.junit.platform.suite.api.ConfigurationParameter;
@@ -19,7 +19,7 @@
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("/integration/query")
-@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "fr.insee.survey.datacollectionmanagement.query")
+@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "fr.insee.survey.datacollectionmanagement.integration")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, json:target/cucumber.json, html:target/cucumber_report.html,"
+ " usage:target/usage.jsonx, junit:target/junit.xml")
public class CucumberTest {
diff --git a/src/test/java/fr/insee/survey/datacollectionmanagement/query/QuestioningInformationsSteps.java b/src/test/java/fr/insee/survey/datacollectionmanagement/integration/QuestioningInformationsSteps.java
similarity index 98%
rename from src/test/java/fr/insee/survey/datacollectionmanagement/query/QuestioningInformationsSteps.java
rename to src/test/java/fr/insee/survey/datacollectionmanagement/integration/QuestioningInformationsSteps.java
index 3b6dd509..95dc9a6d 100644
--- a/src/test/java/fr/insee/survey/datacollectionmanagement/query/QuestioningInformationsSteps.java
+++ b/src/test/java/fr/insee/survey/datacollectionmanagement/integration/QuestioningInformationsSteps.java
@@ -1,4 +1,4 @@
-package fr.insee.survey.datacollectionmanagement.query;
+package fr.insee.survey.datacollectionmanagement.integration;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import fr.insee.survey.datacollectionmanagement.config.AuthenticationUserProvider;
@@ -136,7 +136,7 @@ public void createSurveyUnit(String idSu, String label) {
surveyUnitRepository.save(su);
}
- @Given("the contact {string} with firstname {string} and lastanme {string} and gender {string} and the streetnumber {string}")
+ @Given("the contact {string} with firstname {string} and lastname {string} and gender {string} and the streetnumber {string}")
public void createContact(String contactId, String firstName, String lastName, String gender, String streetNumber) {
Contact c = new Contact();
c.setIdentifier(contactId);
diff --git a/src/test/java/fr/insee/survey/datacollectionmanagement/integration/SearchContactSteps.java b/src/test/java/fr/insee/survey/datacollectionmanagement/integration/SearchContactSteps.java
new file mode 100644
index 00000000..c6a163c2
--- /dev/null
+++ b/src/test/java/fr/insee/survey/datacollectionmanagement/integration/SearchContactSteps.java
@@ -0,0 +1,157 @@
+package fr.insee.survey.datacollectionmanagement.integration;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import fr.insee.survey.datacollectionmanagement.config.AuthenticationUserProvider;
+import fr.insee.survey.datacollectionmanagement.config.auth.user.AuthorityRoleEnum;
+import fr.insee.survey.datacollectionmanagement.constants.Constants;
+import fr.insee.survey.datacollectionmanagement.contact.domain.Contact;
+import fr.insee.survey.datacollectionmanagement.contact.dto.SearchContactDtoImpl;
+import fr.insee.survey.datacollectionmanagement.contact.repository.ContactRepository;
+import fr.insee.survey.datacollectionmanagement.contact.util.ContactParamEnum;
+import io.cucumber.datatable.DataTable;
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+import jakarta.transaction.Transactional;
+import org.apache.commons.lang3.StringUtils;
+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.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+
+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.result.MockMvcResultMatchers.status;
+
+@AutoConfigureMockMvc
+@SpringBootTest
+@ActiveProfiles("test")
+public class SearchContactSteps {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private ObjectMapper objectMapper;
+
+ @Autowired
+ private ContactRepository contactRepository;
+
+ private MvcResult mvcResult;
+ private Page pageSearchContact;
+ private String role;
+
+ @Transactional
+ @Given("the following contacts exist:")
+ public void createContacts(DataTable dataTable) {
+ List