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 referent data to GET campaigns #124

Merged
merged 6 commits into from
Jan 4, 2024
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
40 changes: 40 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Sonar Analysis

on:
push:
branches:
- main
- master
- develop
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'adopt'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn clean verify -Pcoverage sonar:sonar -Dsonar.projectKey=InseeFr_Pearl-Jam-Back-Office --no-transfer-progress
58 changes: 51 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.insee.pearljam</groupId>
<artifactId>pearljam-back-office</artifactId>
<version>4.1.2</version>
<version>4.1.3</version>
<packaging>war</packaging>
<name>Pearl-Jam-Back-Office</name>
<description>Back-office services for for PearlJam</description>
Expand All @@ -26,6 +26,8 @@
<maven.compiler.release>11</maven.compiler.release>
<testcontainers.version>1.15.2</testcontainers.version>
<keycloak.version>19.0.3</keycloak.version>
<sonar.organization>inseefr</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
<dependencyManagement>
<dependencies>
Expand All @@ -36,6 +38,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -256,9 +264,9 @@
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.8.0</version>
</dependency>
<!-- Manage JSON OBJECT -->
<dependency>
Expand All @@ -276,6 +284,41 @@
<optional>true</optional>
</dependency>
</dependencies>

<profiles>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -383,7 +426,8 @@
<forkedProcessExitTimeoutInSeconds>500</forkedProcessExitTimeoutInSeconds>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx2048m -Xmx1G -XX:PermSize=1024m</argLine>
<!-- argLine to prevent jacoco argLine override -->
<argLine>${argLine} -Xmx2048m -Xmx1G -XX:PermSize=1024m</argLine>
<environmentVariables>
<TESTCONTAINERS_RYUK_DISABLED>true</TESTCONTAINERS_RYUK_DISABLED>
</environmentVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -38,21 +37,23 @@
import fr.insee.pearljam.api.service.ReferentService;
import fr.insee.pearljam.api.service.UtilsService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import fr.insee.pearljam.api.constants.Constants;

@RestController
@Slf4j
@RequiredArgsConstructor
public class CampaignController {

@Autowired
CampaignService campaignService;
private final CampaignService campaignService;

@Autowired
UtilsService utilsService;
private final UtilsService utilsService;

@Autowired
ReferentService referentService;
private final ReferentService referentService;

private static final String NO_USER_ID = "No userId : access denied.";
private static final String DEFAULT_FORCE_VALUE = "false";

/**
* This method is used to post the campaign defined in request body
Expand Down Expand Up @@ -89,7 +90,7 @@ public ResponseEntity<List<CampaignDto>> getListCampaign(HttpServletRequest requ
String userId = utilsService.getUserId(request);
log.info("User {} : GET related campaigns", userId);
if (StringUtils.isBlank(userId)) {
log.warn("No userId : access denied.");
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
List<CampaignDto> lstCampaigns = campaignService.getListCampaign(userId);
Expand All @@ -111,7 +112,7 @@ public ResponseEntity<List<CampaignDto>> getAllCampaigns(HttpServletRequest requ
String userId = utilsService.getUserId(request);
log.info("User {} : GET all campaigns", userId);
if (StringUtils.isBlank(userId)) {
log.warn("No userId : access denied.");
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
} else {
List<CampaignDto> lstCampaigns = campaignService.getAllCampaigns();
Expand All @@ -133,7 +134,7 @@ public ResponseEntity<List<CampaignDto>> getAllCampaigns(HttpServletRequest requ
public ResponseEntity<List<CampaignDto>> getInterviewerCampaigns(HttpServletRequest request) {
String userId = utilsService.getUserId(request);
if (StringUtils.isBlank(userId)) {
log.warn("No userId : access denied.");
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("Interviewer {} : GET related campaigns", userId);
Expand All @@ -158,7 +159,7 @@ public ResponseEntity<List<InterviewerDto>> getListInterviewers(HttpServletReque
@PathVariable(value = "id") String id) {
String userId = utilsService.getUserId(request);
if (StringUtils.isBlank(userId)) {
log.warn("Can't find caller ID");
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] interviewers ", userId, id);
Expand Down Expand Up @@ -192,7 +193,7 @@ public ResponseEntity<List<VisibilityContextDto>> getVisibilities(HttpServletReq
@PathVariable(value = "id") String id) {
String userId = utilsService.getUserId(request);
if (StringUtils.isBlank(userId)) {
log.warn("Can't find caller ID");
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] visibilities ", userId, id);
Expand Down Expand Up @@ -224,7 +225,7 @@ public ResponseEntity<CountDto> getNbSUAbandoned(HttpServletRequest request,
@PathVariable(value = "id") String id) {
String userId = utilsService.getUserId(request);
if (StringUtils.isBlank(userId)) {
log.warn("Can't find caller ID");
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] abandoned survey-units ", userId, id);
Expand Down Expand Up @@ -255,7 +256,7 @@ public ResponseEntity<CountDto> getNbSUNotAttributed(HttpServletRequest request,
@PathVariable(value = "id") String id) {
String callerId = utilsService.getUserId(request);
if (StringUtils.isBlank(callerId)) {
log.warn("Can't find caller ID");
log.warn(NO_USER_ID);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
log.info("{} try to get campaign[{}] not attributed survey-units ", callerId, id);
Expand Down Expand Up @@ -285,8 +286,8 @@ public ResponseEntity<Object> putVisibilityDate(HttpServletRequest request,
@PathVariable(value = "idOu") String idOu) {
String callerId = utilsService.getUserId(request);
if (StringUtils.isBlank(callerId)) {
log.info("Can't find caller Id");
return new ResponseEntity<>("Can't find caller Id", HttpStatus.FORBIDDEN);
log.info(NO_USER_ID);
return new ResponseEntity<>(NO_USER_ID, HttpStatus.FORBIDDEN);
}
log.info("{} try to change OU[{}] visibility on campaign[{}] ", callerId, idOu, idCampaign);
HttpStatus returnCode = campaignService.updateVisibility(idCampaign, idOu, visibilityUpdated);
Expand All @@ -306,7 +307,7 @@ public ResponseEntity<Object> putVisibilityDate(HttpServletRequest request,
@ApiOperation(value = "Delete a campaign")
@DeleteMapping(path = Constants.API_CAMPAIGN_ID)
public ResponseEntity<Object> deleteCampaignById(HttpServletRequest request, @PathVariable(value = "id") String id,
@RequestParam(required = false) boolean force) {
@RequestParam(required = false, defaultValue = DEFAULT_FORCE_VALUE) Boolean force) {
String callerId = utilsService.getUserId(request);
log.info("{} try to delete campaign {}", callerId, id);

Expand All @@ -315,7 +316,7 @@ public ResponseEntity<Object> deleteCampaignById(HttpServletRequest request, @Pa
log.error("DELETE campaign with id {} resulting in 404 because it does not exists", id);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
if (!force && campaignService.isCampaignOngoing(id)) {
if (Boolean.FALSE.equals(force) && campaignService.isCampaignOngoing(id)) {
String errorMessage = String.format("Campaign %s is on-going and can't be deleted", id);
log.info(errorMessage);
return ResponseEntity.status(HttpStatus.CONFLICT).body(errorMessage);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/fr/insee/pearljam/api/dto/campaign/CampaignDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fr.insee.pearljam.api.domain.ContactAttemptConfiguration;
import fr.insee.pearljam.api.domain.ContactOutcomeConfiguration;
import fr.insee.pearljam.api.domain.IdentificationConfiguration;
import fr.insee.pearljam.api.dto.referent.ReferentDto;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class CampaignDto {
Expand All @@ -32,6 +33,7 @@ public class CampaignDto {
private ContactAttemptConfiguration contactAttemptConfiguration;
private ContactOutcomeConfiguration contactOutcomeConfiguration;
private Boolean communicationRequestConfiguration;
private List<ReferentDto> referents;

public CampaignDto() {
super();
Expand Down Expand Up @@ -335,4 +337,12 @@ public void setCommunicationRequestConfiguration(Boolean communicationRequestCon
this.communicationRequestConfiguration = communicationRequestConfiguration;
}

public List<ReferentDto> getReferents() {
return referents;
}

public void setReferents(List<ReferentDto> referents) {
this.referents = referents;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.insee.pearljam.api.dto.interviewer;

import org.apache.commons.validator.EmailValidator;
import org.apache.commons.validator.routines.EmailValidator;

import com.fasterxml.jackson.annotation.JsonIgnore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public interface ContactOutcomeRepository extends JpaRepository<ContactOutcome,
+ "AND organization_unit_id IN (:ouIds) "
// Last state is TBR or FIN or CLO
+ "AND EXISTS ("
+ "SELECT MAX(date) FROM state "
+ "SELECT 1 FROM state "
+ "WHERE survey_unit_id = su.id "
+ "AND date=("
+ "SELECT MAX(date) FROM state "
+ "WHERE survey_unit_id = su.id"
+ ") "
+ "AND type IN ('TBR', 'FIN', 'CLO')"
+ ") "
+ "AND interviewer_id=:interviewerId "
Expand Down Expand Up @@ -89,8 +93,12 @@ Map<String, BigInteger> findContactOutcomeTypeByInterviewerAndCampaign(@Param("c
+ "AND organization_unit_id IN (:ouIds) "
// Last state is TBR or FIN or CLO
+ "AND EXISTS ("
+ "SELECT MAX(date) FROM state "
+ "SELECT 1 FROM state "
+ "WHERE survey_unit_id = su.id "
+ "AND date=("
+ "SELECT MAX(date) FROM state "
+ "WHERE survey_unit_id = su.id"
+ ") "
+ "AND type IN ('TBR', 'FIN', 'CLO')"
+ ") "
+ "AND interviewer_id IS NULL "
Expand Down Expand Up @@ -122,8 +130,12 @@ Map<String, BigInteger> findContactOutcomeTypeNotAttributed(@Param("campaignId")
+ "WHERE campaign_id=?1 "
// Last state is TBR or FIN or CLO
+ "AND EXISTS ("
+ "SELECT MAX(date) FROM state "
+ "SELECT 1 FROM state "
+ "WHERE survey_unit_id = su.id "
+ "AND date=("
+ "SELECT MAX(date) FROM state "
+ "WHERE survey_unit_id = su.id"
+ ") "
+ "AND type IN ('TBR', 'FIN', 'CLO')"
+ ") "
+ ") "
Expand Down Expand Up @@ -152,8 +164,12 @@ Map<String, BigInteger> findContactOutcomeTypeNotAttributed(@Param("campaignId")
+ "WHERE campaign_id=?1 "
// Last state is TBR or FIN or CLO
+ "AND EXISTS ("
+ "SELECT MAX(date) FROM state "
+ "SELECT 1 FROM state "
+ "WHERE survey_unit_id = su.id "
+ "AND date=("
+ "SELECT MAX(date) FROM state "
+ "WHERE survey_unit_id = su.id"
+ ") "
+ "AND type IN ('TBR', 'FIN', 'CLO')"
+ ") "
+ "AND organization_unit_id=?2 "
Expand Down
Loading
Loading