Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve manytoone relations in db (no link tables) #98

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1926982
fix: improve manytoone relations in db (no link tables)
BettyB979 Dec 4, 2024
d42b13b
fix: save contact
BettyB979 Dec 4, 2024
ac21341
refactor: contactService and ContactController
BettyB979 Dec 4, 2024
961f322
fix: test
BettyB979 Dec 4, 2024
a156c3e
fix: put metadata for webclients
BettyB979 Dec 4, 2024
3ed91b7
fix: update MDD
BettyB979 Dec 4, 2024
65a35fe
fix: improve search methods for questioning
BettyB979 Dec 5, 2024
cbb7feb
fix: improve search methods for contacts
BettyB979 Dec 5, 2024
88f75e9
fix: improve serach contact by email or identifier
BettyB979 Dec 5, 2024
98d36d5
fix: add missing index
BettyB979 Dec 6, 2024
005a4a6
fix: remove sort in search endpoints
BettyB979 Dec 6, 2024
a22798e
feat: improve search questioning using union all
BettyB979 Dec 6, 2024
322d4be
feat: improve search endpoints using union all (V2 versions)
BettyB979 Dec 6, 2024
d6fc79f
fix: serach param to upper case
BettyB979 Dec 9, 2024
3e3d358
fix: search distinct questioning
BettyB979 Dec 9, 2024
680ae69
fix: remove duplicates contacts
BettyB979 Dec 10, 2024
87b143f
fix: test native query
BettyB979 Dec 10, 2024
c9daa6b
fix: search questioning
BettyB979 Dec 11, 2024
d84a8f1
fix: improve search questioning
BettyB979 Dec 11, 2024
5243c3a
feat: add search by identificationCode
BettyB979 Dec 11, 2024
fa4b340
fix: remove model mapper
BettyB979 Dec 11, 2024
216aa4b
feat: add cucumber tests for search questioning
BettyB979 Dec 11, 2024
03ee34f
refactor: rename methods
BettyB979 Dec 18, 2024
986d604
fix: improve search endpoints
BettyB979 Dec 18, 2024
3a1fd62
fix: remove search v2 version (too slow, even with indexes)
BettyB979 Jan 13, 2025
2d12dd1
fix: put quesitoning for weclients
BettyB979 Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed docs/Contacts.jpg
Binary file not shown.
Binary file added docs/MDD-pilotage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
164 changes: 0 additions & 164 deletions docs/datacollection-uml.iuml

This file was deleted.

Binary file removed docs/di_pg_sicpilbo_dv03 - MDD.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -26,8 +24,6 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.util.List;

@RestController
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES)
@Tag(name = "1 - Contacts", description = "Enpoints to create, update, delete and find contacts")
Expand Down Expand Up @@ -93,13 +89,4 @@ public ResponseEntity<AddressDto> putAddress(@PathVariable("id") String id,

}

class AddressPage extends PageImpl<AddressDto> {

private static final long serialVersionUID = -5570255373624396569L;

public AddressPage(List<AddressDto> content, Pageable pageable, long total) {
super(content, pageable, total);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import fr.insee.survey.datacollectionmanagement.contact.dto.ContactDto;
import fr.insee.survey.datacollectionmanagement.contact.dto.SearchContactDto;
import fr.insee.survey.datacollectionmanagement.contact.enums.ContactParamEnum;
import fr.insee.survey.datacollectionmanagement.contact.enums.GenderEnum;
import fr.insee.survey.datacollectionmanagement.contact.service.AddressService;
import fr.insee.survey.datacollectionmanagement.contact.service.ContactService;
import fr.insee.survey.datacollectionmanagement.contact.util.PayloadUtil;
import fr.insee.survey.datacollectionmanagement.contact.validation.ValidContactParam;
Expand All @@ -30,7 +28,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.springframework.data.domain.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand All @@ -54,14 +51,11 @@
public class ContactController {

private final ContactService contactService;

private final AddressService addressService;


private final ViewService viewService;

private final QuestioningAccreditationService questioningAccreditationService;

private final ModelMapper modelMapper;

/**
* @deprecated
Expand All @@ -75,7 +69,7 @@ public ContactPage getContacts(
@RequestParam(defaultValue = "identifier") String sort) {
Pageable pageable = PageRequest.of(page, size, Sort.by(sort));
Page<Contact> pageC = contactService.findAll(pageable);
List<ContactDto> listC = pageC.stream().map(this::convertToDto).toList();
List<ContactDto> listC = pageC.stream().map(contactService::convertToDto).toList();
return new ContactPage(listC, pageable, pageC.getTotalElements());
}

Expand All @@ -86,7 +80,7 @@ public ContactDetailsDto getContact(@PathVariable("id") String id) {
String idContact = StringUtils.upperCase(id);
Contact contact = contactService.findByIdentifier(idContact);
List<String> listCampaigns = viewService.findDistinctCampaignByIdentifier(idContact);
return convertToContactDetailsDto(contact, listCampaigns);
return contactService.convertToContactDetailsDto(contact, listCampaigns);


}
Expand All @@ -101,28 +95,22 @@ public ResponseEntity<ContactDto> putContact(@PathVariable("id") String id,
if (!contactDto.getIdentifier().equalsIgnoreCase(id)) {
throw new NotMatchException("id and contact identifier don't match");
}
Contact contact;
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(HttpHeaders.LOCATION, ServletUriComponentsBuilder.fromCurrentRequest()
.buildAndExpand(contactDto.getIdentifier()).toUriString());
.buildAndExpand(id).toUriString());

JsonNode payload = PayloadUtil.getPayloadAuthor(auth.getName());

HttpStatus httpStatus = HttpStatus.OK;
try {
contact = convertToEntity(contactDto);
if (contactDto.getAddress() != null)
contact.setAddress(addressService.convertToEntity(contactDto.getAddress()));
Contact contactUpdate = contactService.updateContactAddressEvent(contact, payload);
return ResponseEntity.ok().headers(responseHeaders).body(convertToDto(contactUpdate));
contactService.findByIdentifier(id);
} catch (NotFoundException e) {
log.info("Creating contact with the identifier {}", contactDto.getIdentifier());
contact = convertToEntityNewContact(contactDto);
if (contactDto.getAddress() != null)
contact.setAddress(addressService.convertToEntity(contactDto.getAddress()));
Contact contactCreate = contactService.createContactAddressEvent(contact, payload);
viewService.createView(id, null, null);
return ResponseEntity.status(HttpStatus.CREATED).headers(responseHeaders).body(convertToDto(contactCreate));
httpStatus = HttpStatus.CREATED;
}
Contact contact = contactService.updateOrCreateContact(id, contactDto, payload);


return ResponseEntity.status(httpStatus).headers(responseHeaders).body(contactService.convertToDto(contact));

}

Expand Down Expand Up @@ -157,56 +145,46 @@ public Page<SearchContactDto> 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) {
@RequestParam(defaultValue = "10") Integer pageSize) {

log.info(
"Search contact by {} with param = {} page = {} pageSize = {}", searchType, searchParam, page, pageSize);

Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
Pageable pageable = PageRequest.of(page, pageSize);

switch (ContactParamEnum.fromValue(searchType)) {
case ContactParamEnum.IDENTIFIER:
return contactService.searchContactByIdentifier(searchParam, pageable);
return contactService.searchContactByIdentifier(searchParam.toUpperCase(), pageable);
case ContactParamEnum.NAME:
return contactService.searchContactByName(searchParam, pageable);
return contactService.searchContactByName(searchParam.toUpperCase(), pageable);
case ContactParamEnum.EMAIL:
return contactService.searchContactByEmail(searchParam, pageable);
return contactService.searchContactByEmail(searchParam.toUpperCase(), 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;
}
@GetMapping(path = Constants.API_CONTACTS_SEARCH+"/V2", produces = "application/json")
@Operation(summary = "Search contact by parameter (identifier, email, name, firstName lastName)")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SearchContactDto.class)))),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
public Page<SearchContactDto> searchContactByParam(
@RequestParam(required = true) String searchParam,
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "10") Integer pageSize) {

private ContactDetailsDto convertToContactDetailsDto(Contact contact, List<String> listCampaigns) {
ContactDetailsDto contactDetailsDto = modelMapper.map(contact, ContactDetailsDto.class);
contactDetailsDto.setCivility(contact.getGender());
contactDetailsDto.setListCampaigns(listCampaigns);
return contactDetailsDto;
}
log.info(
"Search contact with param = {} page = {} pageSize = {}", searchParam, page, pageSize);

private Contact convertToEntity(ContactDto contactDto) {
Contact contact = modelMapper.map(contactDto, Contact.class);
contact.setGender(GenderEnum.valueOf(contactDto.getCivility()));
Contact oldContact = contactService.findByIdentifier(contactDto.getIdentifier());
contact.setComment(oldContact.getComment());
contact.setAddress(oldContact.getAddress());
contact.setContactEvents(oldContact.getContactEvents());
Pageable pageable = PageRequest.of(page, pageSize);

return contact;
}
return contactService.searchContactByParam(searchParam.toUpperCase(), pageable);

private Contact convertToEntityNewContact(ContactDto contactDto) {
Contact contact = modelMapper.map(contactDto, Contact.class);
contact.setGender(GenderEnum.valueOf(contactDto.getCivility()));
return contact;
}


static class ContactPage extends PageImpl<ContactDto> {

@Serial
Expand Down
Loading
Loading