260922_02_ENH: 설문 연동시 생성되는 url에서 psidx 제거
This commit is contained in:
@@ -25,6 +25,7 @@ import com.kri.contact.server.persistence.repository.ProjectRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectSurveyRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -50,7 +51,6 @@ public class ProjectService {
|
||||
|
||||
private static final List<Short> STATUS_0_1 = List.of((short) 0, (short) 1);
|
||||
private static final List<Short> STATUS_1 = List.of((short) 1);
|
||||
private static final String PRJCT_SURVEY_IDX_TOKEN = "[$prjctSurveyIdx]";
|
||||
private static final String KON_URL_TOKEN = "[$KON-URL]";
|
||||
private static final String KIWI_URL_TOKEN = "[$KIWI-URL]";
|
||||
private static final String KON_SURVEY_BASE_URL = "https://kon.kric.com/project/";
|
||||
@@ -352,7 +352,6 @@ public class ProjectService {
|
||||
List<TPrjctSurveyEntity> savedTargets = List.of();
|
||||
if (!saveTargets.isEmpty()) {
|
||||
savedTargets = projectSurveyRepository.saveAllAndFlush(saveTargets);
|
||||
replacePrjctSurveyIdxToken(savedTargets);
|
||||
resolveSurveyUrls(savedTargets, ctx);
|
||||
}
|
||||
return createSurveyMappingSyncPlan(existingMappingMap, savedTargets);
|
||||
@@ -409,17 +408,6 @@ public class ProjectService {
|
||||
);
|
||||
}
|
||||
|
||||
private void replacePrjctSurveyIdxToken(List<TPrjctSurveyEntity> surveys) {
|
||||
for (TPrjctSurveyEntity survey : surveys) {
|
||||
String surveyUrl = survey.getSurveyUrl();
|
||||
Long prjctSurveyIdx = survey.getPrjctSurveyIdx();
|
||||
if (surveyUrl == null || prjctSurveyIdx == null || !surveyUrl.contains(PRJCT_SURVEY_IDX_TOKEN)) {
|
||||
continue;
|
||||
}
|
||||
survey.setSurveyUrl(surveyUrl.replace(PRJCT_SURVEY_IDX_TOKEN, prjctSurveyIdx.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveSurveyUrls(List<TPrjctSurveyEntity> surveys, RequestUserContext ctx) {
|
||||
for (TPrjctSurveyEntity survey : surveys) {
|
||||
ResolvedSurveyUrl resolved = resolveSurveyUrl(survey, ctx);
|
||||
@@ -464,7 +452,19 @@ public class ProjectService {
|
||||
|
||||
private boolean isSameSurveyTarget(String previousFullUrl, String baseUrl) {
|
||||
return previousFullUrl != null
|
||||
&& (previousFullUrl.equals(baseUrl) || previousFullUrl.startsWith(baseUrl + "&"));
|
||||
&& !containsPsidxParameter(previousFullUrl)
|
||||
&& (previousFullUrl.equals(baseUrl)
|
||||
|| previousFullUrl.startsWith(baseUrl + "?")
|
||||
|| previousFullUrl.startsWith(baseUrl + "&"));
|
||||
}
|
||||
|
||||
private boolean containsPsidxParameter(String url) {
|
||||
int queryIndex = url.indexOf('?');
|
||||
if (queryIndex < 0 || queryIndex + 1 >= url.length()) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.stream(url.substring(queryIndex + 1).split("&"))
|
||||
.anyMatch(this::isPsidxParameter);
|
||||
}
|
||||
|
||||
// 토큰이 남아있으면 최초 저장, KON/KIWI full URL로 시작하면 short 미발급 상태이므로,
|
||||
@@ -478,15 +478,14 @@ public class ProjectService {
|
||||
|
||||
private String resolveSurveyBaseUrl(TPrjctSurveyEntity survey) {
|
||||
String surveyPrjctCd = survey.getSurveyPrjctCd();
|
||||
Long prjctSurveyIdx = survey.getPrjctSurveyIdx();
|
||||
if (surveyPrjctCd == null || surveyPrjctCd.isBlank() || prjctSurveyIdx == null) {
|
||||
if (surveyPrjctCd == null || surveyPrjctCd.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (isKonSurvey(survey)) {
|
||||
return KON_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp?psidx=" + prjctSurveyIdx;
|
||||
return KON_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp";
|
||||
}
|
||||
if (isKiwiSurvey(survey)) {
|
||||
return KIWI_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp?psidx=" + prjctSurveyIdx;
|
||||
return KIWI_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -505,7 +504,15 @@ public class ProjectService {
|
||||
if (queryIndex < 0 || queryIndex + 1 >= url.length()) {
|
||||
return "";
|
||||
}
|
||||
return url.substring(queryIndex + 1);
|
||||
return Arrays.stream(url.substring(queryIndex + 1).split("&"))
|
||||
.filter(parameter -> !isPsidxParameter(parameter))
|
||||
.collect(Collectors.joining("&"));
|
||||
}
|
||||
|
||||
private boolean isPsidxParameter(String parameter) {
|
||||
int equalsIndex = parameter.indexOf('=');
|
||||
String name = equalsIndex < 0 ? parameter : parameter.substring(0, equalsIndex);
|
||||
return name.equalsIgnoreCase("psidx");
|
||||
}
|
||||
|
||||
private String stripQueryString(String url) {
|
||||
|
||||
Reference in New Issue
Block a user