Skip to content

Commit

Permalink
fix: default v3 url (#77)
Browse files Browse the repository at this point in the history
* fix: put default questioning url to V3 if empty params

* refactor: improve javadoc

* fix(tests): fix readonly url test
  • Loading branch information
BettyB979 authored Jul 9, 2024
1 parent 36f9021 commit ac056ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>fr.insee.survey</groupId>
<artifactId>platine-management</artifactId>
<version>2.4.1</version>
<version>2.4.2</version>
<name>platine-management</name>
<description>REST API for communication between DB and Platine-Management UI and Platine-My-Surveys UI</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ public int deleteQuestioningsOfOnePartitioning(Partitioning partitioning) {
SurveyUnit su = q.getSurveyUnit();
su.getQuestionings().remove(q);
surveyUnitService.saveSurveyUnit(su);
q.getQuestioningEvents().stream().forEach(qe -> questioningEventService.deleteQuestioningEvent(qe.getId()));
q.getQuestioningAccreditations().stream()
.forEach(questioningAccreditationService::deleteAccreditation);
q.getQuestioningEvents().forEach(qe -> questioningEventService.deleteQuestioningEvent(qe.getId()));
q.getQuestioningAccreditations().forEach(questioningAccreditationService::deleteAccreditation);
deleteQuestioning(q.getId());
nbQuestioningDeleted++;
}
Expand All @@ -101,15 +100,15 @@ public Set<Questioning> findBySurveyUnitIdSu(String idSu) {
*
* @param baseUrl The base URL for the access.
* @param typeUrl The type of URL (V1 or V2).
* @param role The user role (REVIEWER or INTERVIEWER).
* @param questioning The questioning object.
* @param surveyUnitId The survey unit ID.
* @param role The user role (REVIEWER or INTERVIEWER).
* @param questioning The questioning object.
* @param surveyUnitId The survey unit ID.
* @return The generated access URL.
*/
public String getAccessUrl(String baseUrl, String typeUrl, String role, Questioning questioning, String surveyUnitId, String sourceId) {
// Set default values if baseUrl or typeUrl is empty
baseUrl = StringUtils.defaultIfEmpty(baseUrl, applicationConfig.getQuestioningUrl());
typeUrl = StringUtils.defaultIfEmpty(typeUrl, V2.name());
typeUrl = StringUtils.defaultIfEmpty(typeUrl, V3.name());

if (typeUrl.equalsIgnoreCase(V1.name())) {
return buildV1Url(baseUrl, role, questioning.getModelName(), surveyUnitId);
Expand All @@ -125,14 +124,13 @@ public String getAccessUrl(String baseUrl, String typeUrl, String role, Question
}



/**
* Builds a V1 access URL based on the provided parameters.
*
* @param baseUrl The base URL for the access.
* @param role The user role (REVIEWER or INTERVIEWER).
* @param campaignId The campaign ID.
* @param surveyUnitId The survey unit ID.
* @param role The user role (REVIEWER or INTERVIEWER).
* @param campaignId The campaign ID.
* @param surveyUnitId The survey unit ID.
* @return The generated V1 access URL.
*/
protected String buildV1Url(String baseUrl, String role, String campaignId, String surveyUnitId) {
Expand All @@ -147,10 +145,11 @@ protected String buildV1Url(String baseUrl, String role, String campaignId, Stri

/**
* Builds a V3 access URL based on the provided parameters
* @param baseUrl host url
* @param role
* @param modelName
* @param surveyUnitId
*
* @param baseUrl The base URL for the access.
* @param role The user role (REVIEWER or INTERVIEWER).
* @param modelName The model ID.
* @param surveyUnitId The survey unit ID.
* @return The generated V3 access URL.
*/

Expand All @@ -166,11 +165,11 @@ protected String buildV2Url(String baseUrl, String role, String modelName, Strin

/**
* Builds a V3 access URL based on the provided parameters
* @param baseUrl
* @param role
* @param modelName
* @param surveyUnitId
* @param sourceId
*
* @param baseUrl The base URL for the access.
* @param role The user role (REVIEWER or INTERVIEWER).
* @param modelName The model ID.
* @param surveyUnitId The survey unit ID.
* @return The generated V3 access URL.
*/
protected String buildV3Url(String baseUrl, String role, String modelName, String surveyUnitId, String sourceId, Long questioningId) {
Expand All @@ -186,4 +185,4 @@ protected String buildV3Url(String baseUrl, String role, String modelName, Strin
return "";
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.insee.survey.datacollectionmanagement.query.controller;

import fr.insee.survey.datacollectionmanagement.constants.Constants;
import fr.insee.survey.datacollectionmanagement.query.service.MoogService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand All @@ -22,18 +21,15 @@
class MoogControllerTest {

@Autowired
private MockMvc mockMvc;

@Autowired
private MoogService moogService;

MockMvc mockMvc;

@Test
void getMoogReadOnlyUrl() throws Exception {
String idCampaign = "SOURCE12023T01";
String surveyUnitId = "100000000";
this.mockMvc.perform(get(Constants.MOOG_API_READONLY_URL, idCampaign, surveyUnitId)).andDo(print()).andExpect(status().isOk())

.andExpect(content().string("http://localhost:8081/readonly/questionnaire/m0/unite-enquetee/100000000"));
.andExpect(content().string("http://localhost:8081/v3/review/questionnaire/m0/unite-enquetee/100000000"));
}


Expand Down

0 comments on commit ac056ef

Please sign in to comment.