Skip to content

Commit

Permalink
update contactOutcome counts (#86)
Browse files Browse the repository at this point in the history
expose new closing cause in coutings
  • Loading branch information
SimonDmz authored Oct 7, 2022
1 parent 4905614 commit 3e335b8
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 119 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.insee.pearljam</groupId>
<artifactId>pearljam-back-office</artifactId>
<version>4.0.3</version>
<version>4.0.4</version>
<packaging>war</packaging>
<name>Pearl-Jam-Back-Office</name>
<description>Back-office services for for PearlJam</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private Constants() {
public static final String[] CLOSING_CAUSE_FIELDS = { "npaCount", "npiCount", "rowCount", "total" };

public static final String[] CONTACT_OUTCOME_FIELDS = { "inaCount", "refCount", "impCount", "ucdCount", "utrCount",
"alaCount", "acpCount", "dcdCount", "nuhCount", "nerCount" };
"alaCount", "dcdCount", "nuhCount", "dukCount", "duuCount", "noaCount" };

public static final String UNAVAILABLE = "UNAVAILABLE";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ public ResponseEntity<SurveyUnitStatesDto> getStatesBySurveyUnitId(HttpServletRe
@GetMapping(path = "/survey-units/closable")
public ResponseEntity<List<SurveyUnitCampaignDto>> getClosableSurveyUnits(HttpServletRequest request) {
String userId = utilsService.getUserId(request);
LOGGER.info("{} try to GET closable units",userId);
if (StringUtils.isBlank(userId)) {
LOGGER.info("GET closable survey units resulting in 401");
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
Expand All @@ -436,6 +437,8 @@ public ResponseEntity<List<SurveyUnitCampaignDto>> getClosableSurveyUnits(HttpSe
@ApiOperation(value = "Delete survey-unit")
@DeleteMapping(path = "/survey-unit/{id}")
public ResponseEntity<Object> deleteSurveyUnit(HttpServletRequest request, @PathVariable(value = "id") String id){
String userId = utilsService.getUserId(request);
LOGGER.info("{} try to DELETE survey-unit {}",userId, id);
Optional<SurveyUnit> surveyUnitOptional = surveyUnitService.findById(id);
if (!surveyUnitOptional.isPresent()) {
LOGGER.error("DELETE survey-unit with id {} resulting in 404 because it does not exists", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class ClosingCauseCountDto {
private Long npiCount;
private Long npaCount;
private Long npxCount;
private Long rowCount;
private Long total;

Expand Down Expand Up @@ -69,6 +70,20 @@ public void setNpaCount(Long npaCount) {
this.npaCount = npaCount;
}

/**
* @return the npxCount
*/
public Long getNpxCount() {
return npxCount;
}

/**
* @param npxCount the npxCount to set
*/
public void setNpxCount(Long npxCount) {
this.npxCount = npxCount;
}

/**
* @return the rowCount
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,74 @@

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ContactOutcomeTypeCountDto {

private String idDem;
private String labelDem;

private String labelDem;

private CampaignDto campaign;

private Long inaCount;

private Long refCount;

private Long impCount;

private Long ucdCount;

private Long utrCount;

private Long alaCount;

private Long acpCount;

private Long dcdCount;

private Long nuhCount;

private Long nerCount;

private Long total;

public ContactOutcomeTypeCountDto() {
super();
}

public ContactOutcomeTypeCountDto(Map<String, BigInteger> obj) {
if (obj != null && !obj.isEmpty()) {
for(String str : Constants.CONTACT_OUTCOME_FIELDS) {

private Long refCount;

private Long impCount;

private Long ucdCount;

private Long utrCount;

private Long alaCount;

private Long dcdCount;

private Long nuhCount;

private Long dukCount;

private Long duuCount;

private Long noaCount;

private Long total;

public ContactOutcomeTypeCountDto() {
super();
}

public ContactOutcomeTypeCountDto(Map<String, BigInteger> obj) {
if (obj != null && !obj.isEmpty()) {
for (String str : Constants.CONTACT_OUTCOME_FIELDS) {
try {
setLongField(str, obj.get(str)!=null?obj.get(str).longValue():0L);
setLongField(str, obj.get(str) != null ? obj.get(str).longValue() : 0L);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
}
public ContactOutcomeTypeCountDto(Map<String, BigInteger> obj, CampaignDto campaign) {
this.campaign = campaign;
if (obj != null && !obj.isEmpty()) {
for(String str : Constants.CONTACT_OUTCOME_FIELDS) {

}

public ContactOutcomeTypeCountDto(Map<String, BigInteger> obj, CampaignDto campaign) {
this.campaign = campaign;
if (obj != null && !obj.isEmpty()) {
for (String str : Constants.CONTACT_OUTCOME_FIELDS) {
try {
setLongField(str, obj.get(str)!=null?obj.get(str).longValue():0L);
setLongField(str, obj.get(str) != null ? obj.get(str).longValue() : 0L);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
}
public ContactOutcomeTypeCountDto(String idDem, String labelDem, Map<String, BigInteger> obj) {

}

public ContactOutcomeTypeCountDto(String idDem, String labelDem, Map<String, BigInteger> obj) {
this(obj);
this.idDem = idDem;
this.setLabelDem(labelDem);
}





/**
* @return the idDem
*/
Expand Down Expand Up @@ -206,20 +205,6 @@ public void setAlaCount(Long alaCount) {
this.alaCount = alaCount;
}

/**
* @return the acpCount
*/
public Long getAcpCount() {
return acpCount;
}

/**
* @param acpCount the acpCount to set
*/
public void setAcpCount(Long acpCount) {
this.acpCount = acpCount;
}

/**
* @return the dcdCount
*/
Expand Down Expand Up @@ -249,17 +234,45 @@ public void setNuhCount(Long nuhCount) {
}

/**
* @return the nerCount
* @return the dukCount
*/
public Long getDukCount() {
return dukCount;
}

/**
* @param dukCount the dukCount to set
*/
public void setDukCount(Long dukCount) {
this.dukCount = dukCount;
}

/**
* @return the duuCount
*/
public Long getDuuCount() {
return duuCount;
}

/**
* @param nuhCount the duuCount to set
*/
public void setDuuCount(Long duuCount) {
this.duuCount = duuCount;
}

/**
* @return the noaCount
*/
public Long getNerCount() {
return nerCount;
public Long getNoaCount() {
return noaCount;
}

/**
* @param nerCount the nerCount to set
* @param noaCount the noaCount to set
*/
public void setNerCount(Long nerCount) {
this.nerCount = nerCount;
public void setNoaCount(Long noaCount) {
this.noaCount = noaCount;
}

/**
Expand All @@ -277,9 +290,9 @@ public void setTotal(Long total) {
}

public void setLongField(String fieldName, Long value)
throws NoSuchFieldException, IllegalAccessException {
Field field = getClass().getDeclaredField(fieldName);
field.set(this, value);
throws NoSuchFieldException, IllegalAccessException {
Field field = getClass().getDeclaredField(fieldName);
field.set(this, value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class StateCountDto {
private Long nvaCount;
private Long npaCount;
private Long npiCount;
private Long npxCount;
private Long rowCount;
private Long total;

Expand Down Expand Up @@ -316,6 +317,14 @@ public void setNpiCount(Long npiCount) {
this.npiCount = npiCount;
}

public Long getNpxCount() {
return npxCount;
}

public void setNpxCount(Long npxCount) {
this.npxCount = npxCount;
}

public Long getRowCount() {
return rowCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface ClosingCauseRepository extends JpaRepository<ClosingCause, Long
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date "
Expand Down Expand Up @@ -46,6 +47,7 @@ Map<String,BigInteger> getStateClosedByClosingCauseCount(@Param("campaignId") St
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date FROM closing_cause WHERE (survey_unit_id, date) IN ("
Expand All @@ -70,6 +72,7 @@ Map<String,BigInteger> getgetStateClosedByClosingCauseCountByCampaign(@Param("ca
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date FROM closing_cause WHERE (survey_unit_id, date) IN ("
Expand All @@ -96,6 +99,7 @@ Map<String,BigInteger> getClosingCauseCountNotAttributed(@Param("campaignId") St
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date FROM closing_cause WHERE (survey_unit_id, date) IN ("
Expand All @@ -121,6 +125,7 @@ Map<String,BigInteger> getClosingCauseCountSumByInterviewer(@Param("campaignIds"
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date FROM closing_cause WHERE (survey_unit_id, date) IN ("
Expand All @@ -146,6 +151,7 @@ Map<String,BigInteger> getClosingCauseCountNotAttributed(@Param("campaignIds") L
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date FROM closing_cause WHERE (survey_unit_id, date) IN ("
Expand All @@ -169,6 +175,7 @@ Map<String,BigInteger> getClosingCauseCountNotAttributed(@Param("campaignIds") L
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date FROM closing_cause WHERE (survey_unit_id, date) IN ("
Expand All @@ -191,6 +198,7 @@ Map<String,BigInteger> getClosingCauseCountNotAttributed(@Param("campaignIds") L
@Query(value = "SELECT "
+ "SUM(CASE WHEN type='NPA' THEN 1 ELSE 0 END) AS npaCount, "
+ "SUM(CASE WHEN type='NPI' THEN 1 ELSE 0 END) AS npiCount, "
+ "SUM(CASE WHEN type='NPX' THEN 1 ELSE 0 END) AS npxCount, "
+ "SUM(CASE WHEN type='ROW' THEN 1 ELSE 0 END) AS rowCount "
+ "FROM ( "
+ "SELECT DISTINCT(survey_unit_id), type, date "
Expand Down
Loading

0 comments on commit 3e335b8

Please sign in to comment.