-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add main contact search endpoint for business management appli… (…
…#103) * feat: add main contact search endpoint for business management applications * fix: endpoint descritpion * fix: version * fix: add to list instead of replace list
- Loading branch information
Showing
9 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../fr/insee/survey/datacollectionmanagement/query/controller/BusinessContactController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fr.insee.survey.datacollectionmanagement.query.controller; | ||
|
||
import fr.insee.survey.datacollectionmanagement.configuration.auth.user.AuthorityPrivileges; | ||
import fr.insee.survey.datacollectionmanagement.constants.Constants; | ||
import fr.insee.survey.datacollectionmanagement.contact.dto.BusinessContactsDto; | ||
import fr.insee.survey.datacollectionmanagement.contact.service.BusinessContactService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
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.RestController; | ||
|
||
@RestController | ||
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES) | ||
@Tag(name = "6 - Webclients", description = "Enpoints for webclients") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BusinessContactController { | ||
|
||
|
||
private final BusinessContactService businessContactService; | ||
|
||
@Operation(summary = "Search for the main contact by campaign and survey unit") | ||
@GetMapping(value = Constants.API_WEBCLIENT_BUSINESS_MAIN_CONTACT) | ||
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES + " || " + AuthorityPrivileges.HAS_REPONDENT_LIMITATED_PRIVILEGES) | ||
public BusinessContactsDto getListBusinessContact(@PathVariable("campaignId") String campaignId, | ||
@PathVariable("surveyUnitId") String surveyUnitId) { | ||
return businessContactService.findMainContactByCampaignAndSurveyUnit(campaignId, surveyUnitId); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...java/fr/insee/survey/datacollectionmanagement/contact/service/BusinessContactService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package fr.insee.survey.datacollectionmanagement.contact.service; | ||
|
||
import fr.insee.survey.datacollectionmanagement.contact.dto.BusinessContactsDto; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public interface BusinessContactService { | ||
|
||
BusinessContactsDto findMainContactByCampaignAndSurveyUnit(String campaignId, String surveyUnitId); | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
...nsee/survey/datacollectionmanagement/contact/service/impl/BusinessContactServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package fr.insee.survey.datacollectionmanagement.contact.service.impl; | ||
|
||
import fr.insee.survey.datacollectionmanagement.contact.domain.Contact; | ||
import fr.insee.survey.datacollectionmanagement.contact.dto.BusinessAddressDto; | ||
import fr.insee.survey.datacollectionmanagement.contact.dto.BusinessContactDto; | ||
import fr.insee.survey.datacollectionmanagement.contact.dto.BusinessContactsDto; | ||
import fr.insee.survey.datacollectionmanagement.contact.enums.GenderEnum; | ||
import fr.insee.survey.datacollectionmanagement.contact.service.BusinessContactService; | ||
import fr.insee.survey.datacollectionmanagement.contact.service.ContactService; | ||
import fr.insee.survey.datacollectionmanagement.metadata.domain.Partitioning; | ||
import fr.insee.survey.datacollectionmanagement.metadata.service.CampaignService; | ||
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningAccreditation; | ||
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BusinessContactServiceImpl implements BusinessContactService { | ||
|
||
private final QuestioningService questioningService; | ||
|
||
private final CampaignService campaignService; | ||
|
||
private final ContactService contactService; | ||
|
||
@Override | ||
public BusinessContactsDto findMainContactByCampaignAndSurveyUnit(String campaignId, String surveyUnitId) { | ||
Set<Partitioning> setParts = campaignService.findById(campaignId).getPartitionings(); | ||
List<QuestioningAccreditation> questioningAccreditationList = new ArrayList<>(); | ||
for (Partitioning part : setParts) { | ||
questioningAccreditationList.addAll(questioningService.findByIdPartitioningAndSurveyUnitIdSu(part.getId(), surveyUnitId). | ||
getQuestioningAccreditations().stream().filter(QuestioningAccreditation::isMain).toList()); | ||
|
||
} | ||
int size = questioningAccreditationList.size(); | ||
BusinessContactsDto businessContactsDto = new BusinessContactsDto(); | ||
businessContactsDto.setCount(size); | ||
businessContactsDto.setStart(size); | ||
businessContactsDto.setHit(size); | ||
List<BusinessContactDto> businessContactDtoList = new ArrayList<>(); | ||
for (QuestioningAccreditation questioningAccreditation : questioningAccreditationList) { | ||
businessContactDtoList.add(getBusinessContactFromIdentifier(questioningAccreditation.getIdContact())); | ||
} | ||
businessContactsDto.setBusinessContactDtoList(businessContactDtoList); | ||
return businessContactsDto; | ||
} | ||
|
||
private BusinessContactDto getBusinessContactFromIdentifier(@NonNull String contactId) { | ||
Contact contact = contactService.findByIdentifier(contactId); | ||
BusinessContactDto businessContactDto = new BusinessContactDto(); | ||
businessContactDto.setIdeC(contact.getIdentifier()); | ||
businessContactDto.setAdresseMessagerie(contact.getEmail()); | ||
businessContactDto.setNom(contact.getLastName()); | ||
businessContactDto.setPrenom(contact.getFirstName()); | ||
businessContactDto.setFonction(contact.getFunction()); | ||
businessContactDto.setRaisonSocialeUsuelle(contact.getUsualCompanyName()); | ||
businessContactDto.setNumeroTelephone(contact.getPhone()); | ||
businessContactDto.setTelephonePortable(contact.getOtherPhone()); | ||
businessContactDto.setFacSimile(null); | ||
businessContactDto.setCommentaire(contact.getComment()); | ||
businessContactDto.setEcivilite(getBusinessCivility(contact.getGender())); | ||
|
||
BusinessAddressDto businessAddressDto = getBusinessAddressDto(contact); | ||
businessContactDto.setBusinessAddressDto(businessAddressDto); | ||
return businessContactDto; | ||
} | ||
|
||
private static BusinessAddressDto getBusinessAddressDto(Contact contact) { | ||
BusinessAddressDto businessAddressDto = new BusinessAddressDto(); | ||
if (contact.getAddress() != null) { | ||
businessAddressDto.setLibellePays(contact.getAddress().getCountryName()); | ||
businessAddressDto.setNumeroVoie(contact.getAddress().getStreetNumber()); | ||
businessAddressDto.setIndiceRepetition(contact.getAddress().getRepetitionIndex()); | ||
businessAddressDto.setTypeVoie(contact.getAddress().getStreetType()); | ||
businessAddressDto.setLibelleVoie(contact.getAddress().getStreetName()); | ||
businessAddressDto.setComplementAdresse(contact.getAddress().getAddressSupplement()); | ||
businessAddressDto.setMentionSpeciale(contact.getAddress().getSpecialDistribution()); | ||
businessAddressDto.setCodePostal(contact.getAddress().getZipCode()); | ||
businessAddressDto.setLibelleCommune(contact.getAddress().getCityName()); | ||
businessAddressDto.setBureauDistributeur(contact.getAddress().getSpecialDistribution()); | ||
businessAddressDto.setCodeCedex(contact.getAddress().getCedexCode()); | ||
businessAddressDto.setLibelleCedex(contact.getAddress().getCedexName()); | ||
businessAddressDto.setCodeCommune(null); | ||
} | ||
return businessAddressDto; | ||
} | ||
|
||
private String getBusinessCivility(GenderEnum gender) { | ||
if (gender.equals(GenderEnum.Female)) | ||
return "MADAME"; | ||
if (gender.equals(GenderEnum.Male)) | ||
return "MONSIEUR"; | ||
return ""; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...rc/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/BusinessAddressDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fr.insee.survey.datacollectionmanagement.contact.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class BusinessAddressDto { | ||
private String libellePays; | ||
private String numeroVoie; | ||
private String indiceRepetition; | ||
private String typeVoie; | ||
private String libelleVoie; | ||
private String complementAdresse; | ||
private String mentionSpeciale; | ||
private String codePostal; | ||
private String libelleCommune; | ||
private String bureauDistributeur; | ||
private String codeCedex; | ||
private String libelleCedex; | ||
private String codeCommune; | ||
} |
21 changes: 21 additions & 0 deletions
21
...rc/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/BusinessContactDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package fr.insee.survey.datacollectionmanagement.contact.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class BusinessContactDto { | ||
private String ideC; | ||
private String adresseMessagerie; | ||
private String nom; | ||
private String prenom; | ||
private String fonction; | ||
private String raisonSocialeUsuelle; | ||
private String numeroTelephone; | ||
private String telephonePortable; | ||
private String facSimile; | ||
private String commentaire; | ||
private String ecivilite; | ||
private BusinessAddressDto businessAddressDto; | ||
} |
15 changes: 15 additions & 0 deletions
15
...c/main/java/fr/insee/survey/datacollectionmanagement/contact/dto/BusinessContactsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package fr.insee.survey.datacollectionmanagement.contact.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class BusinessContactsDto { | ||
private int hit; | ||
private int start; | ||
private int count; | ||
private List<BusinessContactDto> businessContactDtoList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters