Skip to content

Commit

Permalink
Merge pull request #29 from kc-bclaudel/master
Browse files Browse the repository at this point in the history
Review endpoints and add endpoint GET questionnaire/id/metadata
  • Loading branch information
nicolasTurban authored May 26, 2021
2 parents e3b48b5 + dc80650 commit e1eb736
Show file tree
Hide file tree
Showing 19 changed files with 1,831 additions and 1,439 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.insee.queen</groupId>
<artifactId>queen</artifactId>
<version>3.0.5</version>
<version>3.1.0</version>
<packaging>war</packaging>
<name>Queen-Back-Office</name>
<description>Back-office services for Queen</description>
Expand Down
42 changes: 22 additions & 20 deletions src/main/java/fr/insee/queen/api/configuration/KeycloakConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,28 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/swagger-ui.html/**", "/v2/api-docs","/csrf", "/", "/webjars/**", "/swagger-resources/**").permitAll()
.antMatchers("/environnement", "/healthcheck").permitAll()
// configuration for endpoints
.antMatchers(Constants.API_CAMPAIGNS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGNS_CONTEXT).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_SURVEY_UNITS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_SURVEY_UNITS_CREATE).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_QUESTIONAIRE).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_QUESTIONAIRE_ID).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_REQUIRED_NOMENCLATURES).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_DATA).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_COMMENT).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_STATE_DATA).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_DEPOSIT_PROOF).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_PERSONALIZATION).hasRole(role)
.antMatchers(Constants.API_NOMENCLATURE).hasRole(role)
.antMatchers(Constants.API_NOMENCLATURE_POST).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE).hasRole(role)
.antMatchers(Constants.API_PARADATAEVENT).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_NOMENCLATURE).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_CREATE_QUESTIONNAIRE).hasRole(role)
.antMatchers(Constants.API_CREATE_DATASET).hasRole(role)
.antMatchers(Constants.API_CAMPAIGNS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_CONTEXT).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_SURVEY_UNITS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_SURVEY_UNIT).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_METADATA).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_QUESTIONAIRES).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_QUESTIONAIREID).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_REQUIREDNOMENCLATURES).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_DATA).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_COMMENT).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_STATEDATA).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_DEPOSITPROOF).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_PERSONALIZATION).hasRole(role)
.antMatchers(Constants.API_NOMENCLATURE).hasRole(role)
.antMatchers(Constants.API_NOMENCLATURE_ID).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_ID).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_ID_METADATA).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_ID_REQUIREDNOMENCLATURE).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIREMODELS).hasRole(role)
.antMatchers(Constants.API_PARADATAEVENT).hasRole(role)
.antMatchers(Constants.API_CREATE_DATASET).hasRole(role)
.anyRequest().denyAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,51 +78,55 @@ protected void configure(HttpSecurity http) throws Exception {
// configuration for Swagger
.antMatchers("/swagger-ui.html/**", "/v2/api-docs", "/csrf", "/", "/webjars/**", "/swagger-resources/**")
.permitAll().antMatchers("/environnement", "/healthcheck").permitAll()
.antMatchers(Constants.API_CAMPAIGNS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGNS_CONTEXT).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_SURVEY_UNITS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_SURVEY_UNITS_CREATE).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_QUESTIONAIRE).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_QUESTIONAIRE_ID).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_REQUIRED_NOMENCLATURES).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_DATA).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_COMMENT).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_STATE_DATA).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_DEPOSIT_PROOF).hasRole(role)
.antMatchers(Constants.API_SURVEY_UNIT_PERSONALIZATION).hasRole(role)
.antMatchers(Constants.API_CAMPAIGNS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_CONTEXT).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_SURVEY_UNITS).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_SURVEY_UNIT).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_METADATA).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_QUESTIONAIRES).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_QUESTIONAIREID).hasRole(role)
.antMatchers(Constants.API_CAMPAIGN_ID_REQUIREDNOMENCLATURES).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_DATA).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_COMMENT).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_STATEDATA).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_DEPOSITPROOF).hasRole(role)
.antMatchers(Constants.API_SURVEYUNIT_ID_PERSONALIZATION).hasRole(role)
.antMatchers(Constants.API_NOMENCLATURE).hasRole(role)
.antMatchers(Constants.API_NOMENCLATURE_POST).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE).hasRole(role)
.antMatchers(Constants.API_NOMENCLATURE_ID).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_ID).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_ID_METADATA).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_ID_REQUIREDNOMENCLATURE).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIREMODELS).hasRole(role)
.antMatchers(Constants.API_PARADATAEVENT).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_NOMENCLATURE).hasRole(role)
.antMatchers(Constants.API_QUESTIONNAIRE_CREATE_QUESTIONNAIRE).hasRole(role)
.antMatchers(Constants.API_CREATE_DATASET).hasRole(role)
.anyRequest().denyAll();

} else {
http.httpBasic().disable();
http.authorizeRequests()
.antMatchers(Constants.API_CAMPAIGNS,
Constants.API_CAMPAIGNS_CONTEXT,
Constants.API_CAMPAIGN_SURVEY_UNITS,
Constants.API_CAMPAIGN_SURVEY_UNITS_CREATE,
Constants.API_CAMPAIGN_QUESTIONAIRE,
Constants.API_CAMPAIGN_QUESTIONAIRE_ID,
Constants.API_CAMPAIGN_REQUIRED_NOMENCLATURES,
Constants.API_SURVEY_UNIT,
Constants.API_SURVEY_UNIT_DATA,
Constants.API_SURVEY_UNIT_COMMENT,
Constants.API_SURVEY_UNIT_DEPOSIT_PROOF,
Constants.API_SURVEY_UNIT_STATE_DATA,
Constants.API_SURVEY_UNIT_PERSONALIZATION,
Constants.API_NOMENCLATURE,
Constants.API_NOMENCLATURE_POST,
Constants.API_PARADATAEVENT,
Constants.API_QUESTIONNAIRE_NOMENCLATURE,
Constants.API_QUESTIONNAIRE,
Constants.API_QUESTIONNAIRE_CREATE_QUESTIONNAIRE,
Constants.API_CREATE_DATASET)
.antMatchers(Constants.API_CAMPAIGNS,
Constants.API_CAMPAIGN_CONTEXT,
Constants.API_CAMPAIGN_ID_SURVEY_UNITS,
Constants.API_CAMPAIGN_ID_SURVEY_UNIT,
Constants.API_CAMPAIGN_ID_METADATA,
Constants.API_CAMPAIGN_ID_QUESTIONAIRES,
Constants.API_CAMPAIGN_ID_QUESTIONAIREID,
Constants.API_CAMPAIGN_ID_REQUIREDNOMENCLATURES,
Constants.API_SURVEYUNIT_ID,
Constants.API_SURVEYUNIT_ID_DATA,
Constants.API_SURVEYUNIT_ID_COMMENT,
Constants.API_SURVEYUNIT_ID_STATEDATA,
Constants.API_SURVEYUNIT_ID_DEPOSITPROOF,
Constants.API_SURVEYUNIT_ID_PERSONALIZATION,
Constants.API_NOMENCLATURE,
Constants.API_NOMENCLATURE_ID,
Constants.API_QUESTIONNAIRE_ID,
Constants.API_QUESTIONNAIRE_ID_METADATA,
Constants.API_QUESTIONNAIRE_ID_REQUIREDNOMENCLATURE,
Constants.API_QUESTIONNAIREMODELS,
Constants.API_PARADATAEVENT,
Constants.API_CREATE_DATASET)
.permitAll();
}
}
Expand Down
38 changes: 20 additions & 18 deletions src/main/java/fr/insee/queen/api/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,32 @@ private Constants() {

//API url for endpoints
public static final String API_CAMPAIGNS = "/api/campaigns";
public static final String API_CAMPAIGN_SURVEY_UNITS = "/api/campaign/{idCampaign}/survey-units";
public static final String API_CAMPAIGN_SURVEY_UNITS_CREATE = "/api/campaign/{idCampaign}/survey-unit";
public static final String API_CAMPAIGN_QUESTIONAIRE = "/api/campaign/{idCampaign}/questionnaires";
public static final String API_CAMPAIGN_QUESTIONAIRE_ID = "/api/campaign/{idCampaign}/questionnaire-id";
public static final String API_CAMPAIGN_REQUIRED_NOMENCLATURES = "/api/campaign/{id}/required-nomenclatures";
public static final String API_SURVEY_UNIT= "/api/survey-unit/{id}";
public static final String API_SURVEY_UNIT_DATA = "/api/survey-unit/{id}/data";
public static final String API_SURVEY_UNIT_COMMENT = "/api/survey-unit/{id}/comment";
public static final String API_SURVEY_UNIT_STATE_DATA = "/api/survey-unit/{id}/state-data";
public static final String API_SURVEY_UNIT_DEPOSIT_PROOF = "/api/survey-unit/{id}/deposit-proof";
public static final String API_SURVEY_UNIT_PERSONALIZATION = "/api/survey-unit/{id}/personalization";
public static final String API_NOMENCLATURE = "/api/nomenclature/{id}";
public static final String API_NOMENCLATURE_POST = "/api/nomenclature";
public static final String API_QUESTIONNAIRE = "/api/questionnaire/{id}";
public static final String API_QUESTIONNAIRE_CREATE_QUESTIONNAIRE = "/api/questionnaire-models";
public static final String API_CAMPAIGN_CONTEXT = "/api/campaign/context";
public static final String API_CAMPAIGN_ID_SURVEY_UNITS = "/api/campaign/{id}/survey-units";
public static final String API_CAMPAIGN_ID_SURVEY_UNIT = "/api/campaign/{id}/survey-unit";
public static final String API_CAMPAIGN_ID_METADATA = "/api/campaign/{id}/metadata";
public static final String API_CAMPAIGN_ID_QUESTIONAIRES = "/api/campaign/{id}/questionnaires";
public static final String API_CAMPAIGN_ID_QUESTIONAIREID = "/api/campaign/{id}/questionnaire-id";
public static final String API_CAMPAIGN_ID_REQUIREDNOMENCLATURES = "/api/campaign/{id}/required-nomenclatures";
public static final String API_SURVEYUNIT_ID= "/api/survey-unit/{id}";
public static final String API_SURVEYUNIT_ID_DATA = "/api/survey-unit/{id}/data";
public static final String API_SURVEYUNIT_ID_COMMENT = "/api/survey-unit/{id}/comment";
public static final String API_SURVEYUNIT_ID_STATEDATA = "/api/survey-unit/{id}/state-data";
public static final String API_SURVEYUNIT_ID_DEPOSITPROOF = "/api/survey-unit/{id}/deposit-proof";
public static final String API_SURVEYUNIT_ID_PERSONALIZATION = "/api/survey-unit/{id}/personalization";
public static final String API_NOMENCLATURE = "/api/nomenclature";
public static final String API_NOMENCLATURE_ID = "/api/nomenclature/{id}";
public static final String API_QUESTIONNAIRE_ID = "/api/questionnaire/{id}";
public static final String API_QUESTIONNAIRE_ID_METADATA = "/api/questionnaire/{id}/metadata";
public static final String API_QUESTIONNAIRE_ID_REQUIREDNOMENCLATURE = "/api/questionnaire/{id}/required-nomenclatures";
public static final String API_QUESTIONNAIREMODELS = "/api/questionnaire-models";
public static final String API_PARADATAEVENT = "/api/paradata";
public static final String API_QUESTIONNAIRE_NOMENCLATURE = "/api/questionnaire/{id}/required-nomenclatures";
public static final String API_CAMPAIGNS_CONTEXT = "/api/campaign/context";

public static final String API_CREATE_DATASET = "/api/create-dataset";

//Pilotage filter url
public static final String API_HABILITATION = "/api/check-habilitation";
public static final String API_PEARLJAM_SURVEY_UNITS = "/api/survey-units";
public static final String API_PEARLJAM_SURVEYUNITS = "/api/survey-units";



Expand Down
55 changes: 44 additions & 11 deletions src/main/java/fr/insee/queen/api/controller/MetadataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import org.springframework.web.bind.annotation.RestController;

import fr.insee.queen.api.domain.Campaign;
import fr.insee.queen.api.domain.QuestionnaireModel;
import fr.insee.queen.api.dto.metadata.MetadataDto;
import fr.insee.queen.api.service.CampaignService;
import fr.insee.queen.api.service.MetadataService;
import fr.insee.queen.api.service.QuestionnaireModelService;
import io.swagger.annotations.ApiOperation;

/**
Expand All @@ -32,10 +34,14 @@ public class MetadataController {
private static final Logger LOGGER = LoggerFactory.getLogger(MetadataController.class);

@Autowired
CampaignService campaignService;
CampaignService campaignService;

@Autowired
QuestionnaireModelService questionnaireModelService;

@Autowired
MetadataService metadataService;

/**
* This method is using to get the metadata associated to a specific campaign
*
Expand All @@ -44,19 +50,46 @@ public class MetadataController {
*/
@ApiOperation(value = "Get metadata by campaign Id ")
@GetMapping(path = "/campaign/{id}/metadata")
public ResponseEntity<Object> getDataBySurveyUnit(@PathVariable(value = "id") String id){
public ResponseEntity<Object> getMetadataByCampaignId(@PathVariable(value = "id") String id){
Optional<Campaign> campaignOptional = campaignService.findById(id);
if (!campaignOptional.isPresent()) {
LOGGER.info("GET comment for reporting unit with id {} resulting in 404", id);
LOGGER.info("GET metadata for campaign with id {} resulting in 404", id);
return ResponseEntity.notFound().build();
}
MetadataDto metadataDto = metadataService.findDtoByCampaignId(id);
if (metadataDto == null) {
LOGGER.info("GET metadata for campaign with id {} resulting in 404 : No metadate found for campaign", id);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
LOGGER.info("GET metadata for campaign with id {} resulting in 200", id);
return new ResponseEntity<>(metadataDto.getValue(), HttpStatus.OK);
}

/**
* This method is using to get the metadata associated to a specific questionnaire
*
* @param id the id of the campaign
* @return {@link metaData} the metadata associated to the reporting unit
*/
@ApiOperation(value = "Get metadata by questionnaire Id ")
@GetMapping(path = "/questionnaire/{id}/metadata")
public ResponseEntity<Object> getMetadataByQuestionnaireId(@PathVariable(value = "id") String id){
Optional<QuestionnaireModel> questionnaireOptional = questionnaireModelService.findById(id);
if (!questionnaireOptional.isPresent()) {
LOGGER.info("GET metadata for questionnaire with id {} resulting in 404 : Questionnaire not found", id);
return ResponseEntity.notFound().build();
}
if(questionnaireOptional.get().getCampaign()==null) {
LOGGER.info("GET metadata for questionnaire with id {} resulting in 404 : No campaign associated to questionnaire", id);
return ResponseEntity.notFound().build();
} else {
LOGGER.info("GET comment for reporting unit with id {} resulting in 200", id);
MetadataDto metadataDto = metadataService.findDtoByCampaignId(id);
if (metadataDto == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}else {
return new ResponseEntity<>(metadataDto.getValue(), HttpStatus.OK);
}
}

MetadataDto metadataDto = metadataService.findDtoByCampaignId(questionnaireOptional.get().getCampaign().getId());
if (metadataDto == null) {
LOGGER.info("GET metadata for questionnaire with id {} resulting in 404 : No metadate found for campaign", id);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
LOGGER.info("GET metadata for questionnaire with id {} resulting in 200", id);
return new ResponseEntity<>(metadataDto.getValue(), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class SurveyUnitController {
*/
@ApiOperation(value = "Get survey-unit")
@GetMapping(path = "/survey-unit/{id}")
public ResponseEntity<Object> getSurveyUnitById(HttpServletRequest request, @PathVariable(value = "id") String id) {
public ResponseEntity<SurveyUnitResponseDto> getSurveyUnitById(HttpServletRequest request, @PathVariable(value = "id") String id) {
Optional<SurveyUnit> suOpt = surveyUnitService.findById(id);
if(!suOpt.isPresent()) {
LOGGER.info("GET survey-units with id {} resulting in 404", id);
Expand All @@ -82,7 +82,7 @@ public ResponseEntity<Object> getSurveyUnitById(HttpServletRequest request, @Pat
SurveyUnit su = suOpt.get();
SurveyUnitResponseDto resp = new SurveyUnitResponseDto(
null,
null,
su.getQuestionnaireModelId(),
su.getPersonalization()==null ? null :su.getPersonalization().getValue(),
su.getData()==null ? null : su.getData().getValue(),
su.getComment()==null ? null : su.getComment().getValue(),
Expand Down
24 changes: 1 addition & 23 deletions src/main/java/fr/insee/queen/api/domain/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
Expand Down Expand Up @@ -42,13 +40,6 @@ public class Data {
@org.springframework.data.annotation.Id
protected UUID id;

/**
* The version of data ('INIT' or 'COLLECTED')
*/
@Enumerated(EnumType.STRING)
@Column(columnDefinition = "varchar(9) default 'INIT'")
private Version version;

/**
* The value of data (jsonb format)
*/
Expand All @@ -68,10 +59,9 @@ public Data() {
super();
this.id = UUID.randomUUID();
}
public Data(UUID id, Version version, JsonNode value, SurveyUnit surveyUnit) {
public Data(UUID id, JsonNode value, SurveyUnit surveyUnit) {
super();
this.id = id;
this.version = version;
this.value = value;
this.surveyUnit = surveyUnit;
}
Expand All @@ -87,18 +77,6 @@ public UUID getId() {
public void setId(UUID id) {
this.id = id;
}
/**
* @return version of comment
*/
public Version getVersion() {
return version;
}
/**
* @param version version to set
*/
public void setVersion(Version version) {
this.version = version;
}
/**
* @return value of comment
*/
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/fr/insee/queen/api/domain/Version.java

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/java/fr/insee/queen/api/dto/data/DataDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

import com.fasterxml.jackson.databind.JsonNode;

import fr.insee.queen.api.domain.Version;

public interface DataDto {
Version getVersion();
JsonNode getValue();
}
Loading

0 comments on commit e1eb736

Please sign in to comment.