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

feat: add main contact search endpoint for business management appli… #103

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion platine-management-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>platine-management-api</artifactId>

<properties>
<springdoc-version>2.8.1</springdoc-version>
<springdoc-version>2.8.0</springdoc-version>
<jakarta-version>3.1.0</jakarta-version>
<cucumber.version>7.18.0</cucumber.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ private Constants() {
public static final String API_WEBCLIENT_METADATA_ID = "/api/metadata/{id}";
public static final String API_WEBCLIENT_QUESTIONINGS = "/api/questionings";
public static final String API_WEBCLIENT_INFORMATIONS = "api/questioning/informations/{idCampaign}/{idUE}";
public static final String API_WEBCLIENT_BUSINESS_MAIN_CONTACT ="/api/main-contact/{campaignId}/{surveyUnitId}";


public static final String API_HEALTHCHECK = "/api/healthcheck";
public static final String ACTUATOR = "/actuator/**";
Expand Down
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);

}
}
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);

}
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);
SimonDmz marked this conversation as resolved.
Show resolved Hide resolved
}
return businessAddressDto;
}

private String getBusinessCivility(GenderEnum gender) {
if (gender.equals(GenderEnum.Female))
return "MADAME";
if (gender.equals(GenderEnum.Male))
return "MONSIEUR";
return "";
}
}
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;
}
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;
}
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;
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<module>platine-management-api</module>
</modules>
<properties>
<revision>2.7.4</revision>
<revision>2.8.1</revision>
<changelist></changelist>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
Loading