Skip to content

Commit

Permalink
Merge branch 'main' into devMissingAndFilterResultLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisszmundy committed Mar 19, 2024
2 parents e7c3ea7 + fa8392f commit 87f7e4a
Show file tree
Hide file tree
Showing 23 changed files with 157 additions and 301 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@bfd2106013da0957cdede0b6c39fb5ca25ae375e

- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.1.0 - [2024-02-23]

### Fixed
- Upgrade to Java 21

### Added
- End point to delete all responses of one questionnaire

## 1.0.7 - [2024-02-13]

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Coverage Status](https://coveralls.io/repos/github/InseeFr/Genesis-API/badge.svg?branch=main)](https://coveralls.io/github/InseeFr/Genesis-API?branch=main)

# Genesis Api

The Genesis API will provide an interface with the responses' referential (Genesis DB)
The Genesis API will provide an interface with the responses' referential (Genesis DB)
37 changes: 13 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.insee.genesis</groupId>
<artifactId>genesis-api</artifactId>
<version>1.0.7</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>genesis-api</name>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>
</parent>

<properties>
<java.version>17</java.version>
<springdoc.version>2.3.0</springdoc.version>
<java.version>21</java.version>
<springdoc.version>2.4.0</springdoc.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<cucumber.version>7.15.0</cucumber.version>
<karate.version>1.3.1</karate.version>
<!-- Proprietes sonar -->
<jacoco.version>0.8.11</jacoco.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
Expand All @@ -29,6 +28,7 @@
<!-- Pi Test-->
<pitest.version>1.15.8</pitest.version>
<pitest.junit.version>1.2.1</pitest.junit.version>
<jackson.version>2.16.2</jackson.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -85,11 +85,6 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<!-- XML libraries -->
<!-- XML-XSLT with Saxon -->
Expand All @@ -99,12 +94,14 @@
<version>12.4</version>
</dependency>

<!-- JSON -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- generate implementation auto -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
Expand All @@ -131,14 +128,6 @@
<scope>test</scope>
</dependency>

<!-- Karate -->
<!-- https://www.baeldung.com/karate-rest-api-testing -->
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
Expand All @@ -153,12 +142,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<version>3.13.0</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.10.0.2594</version>
<version>3.11.0.3922</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand All @@ -173,7 +162,7 @@
</execution>
<execution>
<id>report</id>
<phase>report</phase>
<phase>post-integration-test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
import fr.insee.genesis.exceptions.GenesisException;
import fr.insee.genesis.exceptions.NoDataError;
import fr.insee.genesis.infrastructure.utils.FileUtils;
import fr.insee.genesis.infrastructure.utils.JSONUtils;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.json.simple.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.*;
import java.nio.file.Files;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -209,6 +208,15 @@ public ResponseEntity<Object> saveResponsesFromXmlCampaignFolder(@RequestParam("
return new ResponseEntity<>("Data saved", HttpStatus.OK);
}

@Operation(summary = "Delete all responses of one questionnaire")
@DeleteMapping(path = "/delete-responses/by-questionnaire")
public ResponseEntity<Object> deleteAllResponsesByQuestionnaire(@RequestParam("idQuestionnaire") String idQuestionnaire) {
log.info("Try to delete all responses of questionnaire : " + idQuestionnaire);
Long ndDocuments = surveyUnitService.deleteByIdQuestionnaire(idQuestionnaire);
log.info("{} responses deleted",ndDocuments);
return new ResponseEntity<>(String.format("%d responses deleted",ndDocuments), HttpStatus.OK);
}

@Operation(summary = "Retrieve responses with IdUE and IdQuestionnaire from Genesis Database")
@GetMapping(path = "/get-responses/by-ue-and-questionnaire")
public ResponseEntity<List<SurveyUnitUpdateDto>> findResponsesByUEAndQuestionnaire( @RequestParam("idUE") String idUE,
Expand Down Expand Up @@ -260,9 +268,9 @@ public ResponseEntity<SurveyUnitUpdateSimplified> getLatestByUEOneObject ( @Requ
outputExternalVariables.addAll(response.getExternalVariables());
});
return new ResponseEntity<>(SurveyUnitUpdateSimplified.builder()
.idQuest(responses.get(0).getIdQuest())
.idCampaign(responses.get(0).getIdCampaign())
.idUE(responses.get(0).getIdUE())
.idQuest(responses.getFirst().getIdQuest())
.idCampaign(responses.getFirst().getIdCampaign())
.idUE(responses.getFirst().getIdUE())
.variablesUpdate(outputVariables)
.externalVariables(outputExternalVariables)
.build(), HttpStatus.OK);
Expand All @@ -288,9 +296,9 @@ public ResponseEntity<List<SurveyUnitUpdateSimplified>> getLatestForUEList( @Req
});
if (!outputVariables.isEmpty() || !outputExternalVariables.isEmpty()) {
results.add(SurveyUnitUpdateSimplified.builder()
.idQuest(responses.get(0).getIdQuest())
.idCampaign(responses.get(0).getIdCampaign())
.idUE(responses.get(0).getIdUE())
.idQuest(responses.getFirst().getIdQuest())
.idCampaign(responses.getFirst().getIdCampaign())
.idUE(responses.getFirst().getIdUE())
.mode(mode)
.variablesUpdate(outputVariables)
.externalVariables(outputExternalVariables)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fr.insee.genesis.domain.dtos;

import lombok.*;
import org.json.simple.JSONObject;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

Expand All @@ -20,12 +21,4 @@ public CollectedVariableDto(String idVar, List<String> values, String idLoop, St
this.idParent = idParent;
}

public JSONObject toJSONObject(){
JSONObject jsonObject = super.toJSONObject();
jsonObject.put("idLoop", idLoop);
jsonObject.put("idParent", idParent);

return jsonObject;
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package fr.insee.genesis.domain.dtos;

import java.time.LocalDateTime;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Builder;
import lombok.Data;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.time.LocalDateTime;
import java.util.List;

@Builder
@Data
Expand All @@ -17,38 +16,11 @@ public class SurveyUnitUpdateDto {
private String idUE;
private DataState state;
private Mode mode;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'hh:mm")
private LocalDateTime recordDate;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'hh:mm")
private LocalDateTime fileDate;
private List<CollectedVariableDto> collectedVariables;
private List<VariableDto> externalVariables;

public JSONObject toJSONObject(){
JSONObject jsonObject = new JSONObject();
jsonObject.put("idQuest",idQuest);
jsonObject.put("idCampaign",idCampaign);
jsonObject.put("idUE",idUE);
jsonObject.put("state",state.toString());
jsonObject.put("mode",mode.getModeName());
jsonObject.put("recordDate",recordDate.toString());
jsonObject.put("fileDate",fileDate.toString());

JSONArray collectedVariablesJSONArray = new JSONArray();
if(collectedVariables != null){
for(CollectedVariableDto collectedVariableDto : collectedVariables){
collectedVariablesJSONArray.add(collectedVariableDto.toJSONObject());
}
}

JSONArray externalVariablesJSONArray = new JSONArray();
if(externalVariables != null) {
for (VariableDto variableDto : externalVariables){
externalVariablesJSONArray.add(variableDto.toJSONObject());
}
}

jsonObject.put("collectedVariables",collectedVariablesJSONArray);
jsonObject.put("externalVariables",externalVariablesJSONArray);

return jsonObject;
}
}
12 changes: 3 additions & 9 deletions src/main/java/fr/insee/genesis/domain/dtos/VariableDto.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fr.insee.genesis.domain.dtos;

import lombok.*;
import org.json.simple.JSONObject;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

Expand All @@ -13,11 +14,4 @@ public class VariableDto {
private String idVar;
private List<String> values;

public JSONObject toJSONObject(){
JSONObject jsonObject = new JSONObject();
jsonObject.put("idVar", idVar);
jsonObject.put("values",values);

return jsonObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface SurveyUnitUpdateApiPort {
List<SurveyUnitId> findDistinctIdUEsByIdQuestionnaire(String idQuestionnaire);

List<Mode> findModesByIdQuestionnaire(String idQuestionnaire);

Long deleteByIdQuestionnaire(String idQuestionnaire);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public interface SurveyUnitUpdatePersistencePort {

List<SurveyUnitDto> findIdUEsByIdQuestionnaire(String idQuestionnaire);

Long deleteByIdQuestionnaire(String idQuestionnaire);


}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public List<Mode> findModesByIdQuestionnaire(String idQuestionnaire) {
return sources.stream().distinct().toList();
}

@Override
public Long deleteByIdQuestionnaire(String idQuestionnaire) {
return surveyUnitUpdatePersistencePort.deleteByIdQuestionnaire(idQuestionnaire);
}

private static List<Mode> getDistinctsModes(List<SurveyUnitUpdateDto> surveyUnits) {
List<Mode> sources = new ArrayList<>();
surveyUnits.forEach(surveyUnitDto -> sources.add(surveyUnitDto.getMode()));
Expand Down
Loading

0 comments on commit 87f7e4a

Please sign in to comment.