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 search questioning #91

Merged
merged 17 commits into from
Nov 26, 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
2 changes: 2 additions & 0 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
distribution: 'temurin'
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
env:
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2
with:
format: 'table'
scan-type: 'repo'
Expand Down
Binary file removed docs/MDD Platine.pdf
Binary file not shown.
Binary file added docs/di_pg_sicpilbo_dv03 - MDD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/metadata.jpg
Binary file not shown.
Binary file removed docs/questioning.jpg
Binary file not shown.
Binary file removed docs/user.jpg
Binary file not shown.
Binary file removed docs/view.jpg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ private Constants() {
//API QUESTIONING DOMAIN
public static final String API_QUESTIONINGS = "/api/questionings";
public static final String API_QUESTIONINGS_ID = "/api/questionings/{id}";
public static final String API_QUESTIONINGS_SEARCH = "/api/questionings/search";

public static final String API_SURVEY_UNITS ="/api/survey-units";
public static final String API_SURVEY_UNITS_ID = "/api/survey-units/{id}";
public static final String API_SURVEY_UNITS_ID_QUESTIONINGS = "/api/survey-units/{id}/questionings";
Expand All @@ -41,6 +43,8 @@ private Constants() {
public static final String API_QUESTIONING_ID_QUESTIONING_EVENTS = "/api/questionings/{id}/questioning-events";
public static final String API_QUESTIONING_QUESTIONING_EVENTS_ID = "/api/questionings/questioning-events/{id}";
public static final String API_QUESTIONING_ID_QUESTIONING_COMMUNICATIONS = "/api/questionings/{id}/questioning-communications";
public static final String API_QUESTIONING_ID_COMMENT = "/api/questionings/{id}/comment";


public static final String API_MAIN_CONTACT = "/api/main-contact";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ public class QuestioningController {

private final ModelMapper modelMapper;

@Operation(summary = "Search for a questioning by id")
@GetMapping(value = Constants.API_QUESTIONINGS_ID, produces = "application/json")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = QuestioningDto.class))),
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
public ResponseEntity<?> getQuestioning(@PathVariable("id") Long id) {

Questioning questioning = questioningService.findbyId(id);
try {
return new ResponseEntity<>(convertToDto(questioning), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<String>("Error", HttpStatus.BAD_REQUEST);
}
}

@Operation(summary = "Create or update questioning")
@PostMapping(value = Constants.API_QUESTIONINGS, produces = "application/json", consumes = "application/json")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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.query.dto.QuestioningDetailsDto;
import fr.insee.survey.datacollectionmanagement.query.dto.SearchQuestioningDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
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.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES)
@Slf4j
@Tag(name = "2 - Questioning", description = "Enpoints to create, update, delete and find entities around the questionings")
@RequiredArgsConstructor
public class SearchQuestioningController {

private final QuestioningService questioningService;

@Operation(summary = "Multi-criteria search questionings")
@GetMapping(value = Constants.API_QUESTIONINGS_SEARCH, produces = "application/json")
public Page<SearchQuestioningDto> searchQuestionings(
@RequestParam(required = false) String searchParam,
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "20") Integer pageSize) {
log.info(
"Search questionings with param {} page = {} pageSize = {}", searchParam, page, pageSize);

Pageable pageable = PageRequest.of(page, pageSize);

return questioningService.searchQuestioning(searchParam, pageable);

}

@Operation(summary = "Get questioning details")
@GetMapping(value = Constants.API_QUESTIONINGS_ID, produces = "application/json")
public QuestioningDetailsDto getQuestioning (@PathVariable("id") Long id) {

return questioningService.getQuestioningDetails(id);

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package fr.insee.survey.datacollectionmanagement.questioning.controller;

import fr.insee.survey.datacollectionmanagement.configuration.auth.user.AuthorityPrivileges;
import fr.insee.survey.datacollectionmanagement.constants.Constants;
import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningComment;
import fr.insee.survey.datacollectionmanagement.questioning.dto.QuestioningCommentInputDto;
import fr.insee.survey.datacollectionmanagement.questioning.dto.QuestioningCommentOutputDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningCommentService;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Set;

@RestController
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES)
@Tag(name = "2 - Questioning", description = "Enpoints to create, update, delete and find entities around the questionings")
@Slf4j
@RequiredArgsConstructor
@Validated
public class QuestioningCommentController {

private final QuestioningService questioningService;
private final QuestioningCommentService questioningCommentService;
private final ModelMapper modelMapper;


@Operation(summary = "Create a questioning comment")
@PostMapping(value = Constants.API_QUESTIONING_ID_COMMENT, produces = "application/json", consumes = "application/json")
@ResponseStatus(HttpStatus.CREATED)
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(implementation = QuestioningCommentInputDto.class))),
@ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "404", description = "Not found")
})
public QuestioningCommentOutputDto postQuestioningComment(@PathVariable Long id, @Valid @RequestBody QuestioningCommentInputDto questioningCommentDto) {

Questioning questioning = questioningService.findbyId(id);
QuestioningComment questioningComment = questioningCommentService.convertToEntity(questioningCommentDto);
questioningComment.setDate(new Date());
QuestioningComment newQuestioningComment = questioningCommentService.saveQuestioningComment(questioningComment);
Set<QuestioningComment> setQuestioningComments = questioning.getQuestioningComments();
setQuestioningComments.add(newQuestioningComment);
questioning.setQuestioningComments(setQuestioningComments);
questioningService.saveQuestioning(questioning);
return questioningCommentService.convertToOutputDto(newQuestioningComment);

}




}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningCommunication;
import fr.insee.survey.datacollectionmanagement.questioning.dto.QuestioningCommunicationDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningCommunicationService;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
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.modelmapper.ModelMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;

import java.text.ParseException;
import java.util.List;
import java.util.Set;

@RestController
Expand All @@ -30,27 +28,16 @@ public class QuestioningCommunicationController {

private final QuestioningService questioningService;

private final ModelMapper modelMapper;
private final QuestioningCommunicationService questioningCommunicationService;

@Operation(summary = "Search for questioning communications by questioning id")
@GetMapping(value = Constants.API_QUESTIONING_ID_QUESTIONING_COMMUNICATIONS, produces = "application/json")
public ResponseEntity<?> findQuestioningCommunicationsByQuestioningId(@PathVariable("id") Long id) {
public List<QuestioningCommunicationDto> findQuestioningCommunicationsByQuestioningId(@PathVariable("id") Long id) {
Questioning questioning = questioningService.findbyId(id);
Set<QuestioningCommunication> setQe = questioning.getQuestioningCommunications();
return ResponseEntity.status(HttpStatus.OK)
.body(setQe.stream()
.map(this::convertToDto).toList());
return setQe.stream().map(questioningCommunicationService::convertToDto).toList();

}


private QuestioningCommunicationDto convertToDto(QuestioningCommunication questioningCommunication) {
return modelMapper.map(questioningCommunication, QuestioningCommunicationDto.class);
}

private QuestioningCommunication convertToEntity(QuestioningCommunicationDto questioningCommunicationDto) throws ParseException {
return modelMapper.map(questioningCommunicationDto, QuestioningCommunication.class);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class QuestioningEventController {

private final UploadService uploadService;

private final ModelMapper modelMapper;

@Operation(summary = "Search for a questioning event by questioning id")
@GetMapping(value = Constants.API_QUESTIONING_ID_QUESTIONING_EVENTS, produces = "application/json")
@ApiResponses(value = {
Expand All @@ -61,7 +59,7 @@ public ResponseEntity<?> findQuestioningEventsByQuestioning(@PathVariable("id")
Set<QuestioningEvent> setQe = questioning.getQuestioningEvents();
return ResponseEntity.status(HttpStatus.OK)
.body(setQe.stream()
.map(this::convertToDto).toList());
.map(questioningEventService::convertToDto).toList());

}

Expand All @@ -76,7 +74,7 @@ public ResponseEntity<?> postQuestioningEvent(@Parameter(description = "question
Questioning questioning = questioningService.findbyId(id);

try {
QuestioningEvent questioningEvent = convertToEntity(questioningEventDto);
QuestioningEvent questioningEvent = questioningEventService.convertToEntity(questioningEventDto);
QuestioningEvent newQuestioningEvent = questioningEventService.saveQuestioningEvent(questioningEvent);
Set<QuestioningEvent> setQuestioningEvents = questioning.getQuestioningEvents();
setQuestioningEvents.add(newQuestioningEvent);
Expand All @@ -86,7 +84,7 @@ public ResponseEntity<?> postQuestioningEvent(@Parameter(description = "question
responseHeaders.set(HttpHeaders.LOCATION,
ServletUriComponentsBuilder.fromCurrentRequest().toUriString());
return ResponseEntity.status(HttpStatus.CREATED).headers(responseHeaders)
.body(convertToDto(newQuestioningEvent));
.body(questioningEventService.convertToDto(newQuestioningEvent));

} catch (ParseException e) {
log.error(e.getMessage(),e);
Expand Down Expand Up @@ -123,13 +121,6 @@ public ResponseEntity<?> deleteQuestioningEvent(@PathVariable("id") Long id) {
}
}

private QuestioningEventDto convertToDto(QuestioningEvent questioningEvent) {
return modelMapper.map(questioningEvent, QuestioningEventDto.class);
}

private QuestioningEvent convertToEntity(QuestioningEventDto questioningEventDto) throws ParseException {
return modelMapper.map(questioningEventDto, QuestioningEvent.class);
}

class QuestioningEventPage extends PageImpl<QuestioningEventDto> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentInputDto;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentOutputDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitCommentService;
import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -46,22 +47,21 @@ public class SurveyUnitCommentController {
@ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "404", description = "Not found")
})
public void postSurveyUnitComment(@PathVariable String id, @Valid @RequestBody SurveyUnitCommentInputDto surveyUnitCommentDto) {
public SurveyUnitCommentOutputDto postSurveyUnitComment(@PathVariable String id, @Valid @RequestBody SurveyUnitCommentInputDto surveyUnitCommentDto) {

SurveyUnit surveyUnit = surveyUnitService.findbyId(id);
SurveyUnitComment surveyUnitComment = convertToEntity(surveyUnitCommentDto);
SurveyUnitComment surveyUnitComment = surveyUnitCommentService.convertToEntity(surveyUnitCommentDto);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the service which converts to entity ? controller only needs to control input data

surveyUnitComment.setDate(new Date());
SurveyUnitComment newSurveyUnitComment = surveyUnitCommentService.saveSurveyUnitComment(surveyUnitComment);
Set<SurveyUnitComment> setSurveyUnitComments = surveyUnit.getSurveyUnitComments();
setSurveyUnitComments.add(newSurveyUnitComment);
surveyUnit.setSurveyUnitComments(setSurveyUnitComments);
surveyUnitService.saveSurveyUnit(surveyUnit);
return surveyUnitCommentService.convertToOutputDto(surveyUnit);

}

private SurveyUnitComment convertToEntity(SurveyUnitCommentInputDto surveyUnitCommentDto) {
return modelMapper.map(surveyUnitCommentDto, SurveyUnitComment.class);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import fr.insee.survey.datacollectionmanagement.configuration.AuthenticationUserProvider;
import fr.insee.survey.datacollectionmanagement.constants.AuthorityRoleEnum;
import fr.insee.survey.datacollectionmanagement.constants.Constants;
import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -13,11 +12,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand All @@ -40,23 +37,6 @@ void init() {
SecurityContextHolder.getContext().setAuthentication(AuthenticationUserProvider.getAuthenticatedUser("test", AuthorityRoleEnum.ADMIN));
}

@Test
@Transactional
void getQuestioningOk() throws Exception {
Questioning questioning = questioningService.findBySurveyUnitIdSu("100000001").stream().findFirst().get();
Long id = questioning.getQuestioningAccreditations().stream().findFirst().get().getId();
String json = createJson(id).toString();
this.mockMvc.perform(get(Constants.API_QUESTIONINGS_ID, id)).andDo(print()).andExpect(status().isOk())
.andExpect(content().json(json, false));
}

@Test
void getQuestioningNotFound() throws Exception {
String id = "300";
this.mockMvc.perform(get(Constants.API_QUESTIONINGS_ID, id)).andDo(print())
.andExpect(status().is(HttpStatus.NOT_FOUND.value()));

}

@Test
void getQuestioningsBySurveyUnit() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class Questioning {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<QuestioningCommunication> questioningCommunications;

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<QuestioningComment> questioningComments;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@NonNull
private SurveyUnit surveyUnit;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.insee.survey.datacollectionmanagement.questioning.domain;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@Entity
@Getter
@Setter
public class QuestioningComment {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "quest_comment_seq")
private Long id;
@Column(length = 2000)
private String comment;
private String author;
private Date date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fr.insee.survey.datacollectionmanagement.questioning.repository;

import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningComment;
import org.springframework.data.jpa.repository.JpaRepository;

public interface QuestioningCommentRepository extends JpaRepository<QuestioningComment, Long> {

}
Loading