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

fix: habilitation cache #286

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<description>Modules for queen back-office</description>

<properties>
<revision>4.5.0</revision>
<revision>4.5.1</revision>
<changelist></changelist>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class DataController {
@PreAuthorize(AuthorityPrivileges.HAS_USER_PRIVILEGES)
@ApiResponse(responseCode = "200", content = {@Content(mediaType = "application/json", schema = @Schema(ref = SchemaType.Names.DATA))})
public ObjectNode getDataBySurveyUnit(@IdValid @PathVariable(value = "id") String surveyUnitId) {
pilotageComponent.checkHabilitations(surveyUnitId, PilotageRole.INTERVIEWER);
pilotageComponent.checkHabilitations(surveyUnitId, PilotageRole.INTERVIEWER, PilotageRole.REVIEWER);
SurveyUnitSummary surveyUnitSummary = surveyUnitService.getSummaryById(surveyUnitId);

// if campaign sensitivity is OFF, return data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ public List<String> getSurveyUnitIds() {
/**
* Retrieve survey units filtered by state
*
* @param campaignId campaign id
* @param stateDataType state
* @param pageNumber page to retrieve
* @return all ids of survey units
*/
@Operation(summary = "Retrieve survey-units by state")
@PostMapping(path = "/survey-units")
@GetMapping(path = "/admin/campaign/{id}/survey-units")
@PreAuthorize(AuthorityPrivileges.HAS_ADMIN_PRIVILEGES)
public PagingResult<SurveyUnitState> getSurveyUnitsByState(
@IdValid @PathVariable("id") String campaignId,
@RequestParam(name="state") StateDataType stateDataType,
@RequestParam(defaultValue = "0") Integer pageNumber) {
return surveyUnitService.getSurveyUnits(stateDataType, pageNumber);
return surveyUnitService.getSurveyUnits(campaignId, stateDataType, pageNumber);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ void on_get_survey_units_return_survey_units() throws Exception {
"currentPage":"2.3#5"
}
}""";
mockMvc.perform(post("/api/survey-units")
mockMvc.perform(get("/api/admin/campaign/SIMPSONS2020X00/survey-units")
.accept(MediaType.APPLICATION_JSON)
.param("state", StateDataTypeInput.INIT.name())
.with(authentication(authenticatedUserTestHelper.getAdminUser()))
)
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.contents.size()", is(13)))
.andExpect(jsonPath("$.contents.size()", is(3)))
// extract and check first element
.andExpect(result -> {
String responseContent = result.getResponse().getContentAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public List<SurveyUnit> findAllSurveyUnits() {
}

@Override
public PagingResult<SurveyUnitState> getSurveyUnits(StateDataType stateDataType, Integer pageNumber) {
public PagingResult<SurveyUnitState> getSurveyUnits(String campaignId, StateDataType stateDataType, Integer pageNumber) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public List<PilotageCampaign> getInterviewerCampaigns() {
}

@Override
@Cacheable(value = CacheName.HABILITATION, key = "{#surveyUnit.id, #surveyUnit.campaignId, #role, #idep}")
@Cacheable(value = CacheName.HABILITATION, key = "{#surveyUnit.id, #surveyUnit.campaign.id, #role, #idep}")
public boolean hasHabilitation(SurveyUnitSummary surveyUnit, PilotageRole role, String idep) {
return pilotageRepository.hasHabilitation(surveyUnit, role, idep);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public List<SurveyUnit> findAllSurveyUnits() {
}

@Override
public PagingResult<SurveyUnitState> getSurveyUnits(StateDataType stateDataType, Integer pageNumber) {
public PagingResult<SurveyUnitState> getSurveyUnits(String campaignId, StateDataType stateDataType, Integer pageNumber) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ public interface SurveyUnitRepository {

/**
*
* @param campaignId campaign id
* @param stateDataType state data type to filter
* @param pageNumber page number
* @return pages of survey units with states
*/
PagingResult<SurveyUnitState> findAllByState(StateDataType stateDataType, Integer pageNumber);
PagingResult<SurveyUnitState> findAllByState(String campaignId, StateDataType stateDataType, Integer pageNumber);

/**
* Find survey units with state linked by ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public List<String> findAllSurveyUnitIds() {
}

@Override
public PagingResult<SurveyUnitState> getSurveyUnits(StateDataType stateDataType, Integer pageNumber) {
return surveyUnitRepository.findAllByState(stateDataType, pageNumber);
public PagingResult<SurveyUnitState> getSurveyUnits(String campaignId, StateDataType stateDataType, Integer pageNumber) {
return surveyUnitRepository.findAllByState(campaignId, stateDataType, pageNumber);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ public interface SurveyUnitService {

List<SurveyUnit> findAllSurveyUnits();

PagingResult<SurveyUnitState> getSurveyUnits(StateDataType stateDataType, Integer pageNumber);
PagingResult<SurveyUnitState> getSurveyUnits(String campaignId, StateDataType stateDataType, Integer pageNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Optional<List<String>> findAllIds() {
}

@Override
public PagingResult<SurveyUnitState> findAllByState(StateDataType stateDataType, Integer pageNumber) {
public PagingResult<SurveyUnitState> findAllByState(String campaignId, StateDataType stateDataType, Integer pageNumber) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public List<SurveyUnit> findAllSurveyUnits() {
}

@Override
public PagingResult<SurveyUnitState> getSurveyUnits(StateDataType stateDataType, Integer pageNumber) {
public PagingResult<SurveyUnitState> getSurveyUnits(String campaignId, StateDataType stateDataType, Integer pageNumber) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public Optional<List<String>> findAllIds() {
}

@Override
public PagingResult<SurveyUnitState> findAllByState(StateDataType state, Integer pageNumber) {
public PagingResult<SurveyUnitState> findAllByState(String campaignId, StateDataType state, Integer pageNumber) {

Pageable pageable = PageRequest.of(pageNumber, 1000, Sort.by("id"));
Page<SurveyUnitState> surveyUnitPages;

surveyUnitPages = crudRepository.findAllByState(state, pageable);
surveyUnitPages = crudRepository.findAllByState(campaignId, state, pageable);

return new PagingResult<>(surveyUnitPages.toList(),
surveyUnitPages.getNumber(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public interface SurveyUnitJpaRepository extends JpaRepository<SurveyUnitDB, Str
/**
* Find all survey units by state
*
* @param campaignId campaign id
* @param stateDataType state data used for filtering
* @return List of survey units by state
*/
Expand All @@ -178,8 +179,10 @@ public interface SurveyUnitJpaRepository extends JpaRepository<SurveyUnitDB, Str
st.currentPage
)
)
from SurveyUnitDB s left join s.stateData st where st.state = :stateDataType""")
Page<SurveyUnitState> findAllByState(StateDataType stateDataType, Pageable pageable);
from SurveyUnitDB s left join s.stateData st
where st.state = :stateDataType
and s.campaign.id = :campaignId""")
Page<SurveyUnitState> findAllByState(String campaignId, StateDataType stateDataType, Pageable pageable);

/**
* Search survey units by ids
Expand Down