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 com.kri.contact.server.persistence.repository.ProjectSurveyRepository;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
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_0_1 = List.of((short) 0, (short) 1);
|
||||||
private static final List<Short> STATUS_1 = List.of((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 KON_URL_TOKEN = "[$KON-URL]";
|
||||||
private static final String KIWI_URL_TOKEN = "[$KIWI-URL]";
|
private static final String KIWI_URL_TOKEN = "[$KIWI-URL]";
|
||||||
private static final String KON_SURVEY_BASE_URL = "https://kon.kric.com/project/";
|
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();
|
List<TPrjctSurveyEntity> savedTargets = List.of();
|
||||||
if (!saveTargets.isEmpty()) {
|
if (!saveTargets.isEmpty()) {
|
||||||
savedTargets = projectSurveyRepository.saveAllAndFlush(saveTargets);
|
savedTargets = projectSurveyRepository.saveAllAndFlush(saveTargets);
|
||||||
replacePrjctSurveyIdxToken(savedTargets);
|
|
||||||
resolveSurveyUrls(savedTargets, ctx);
|
resolveSurveyUrls(savedTargets, ctx);
|
||||||
}
|
}
|
||||||
return createSurveyMappingSyncPlan(existingMappingMap, savedTargets);
|
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) {
|
private void resolveSurveyUrls(List<TPrjctSurveyEntity> surveys, RequestUserContext ctx) {
|
||||||
for (TPrjctSurveyEntity survey : surveys) {
|
for (TPrjctSurveyEntity survey : surveys) {
|
||||||
ResolvedSurveyUrl resolved = resolveSurveyUrl(survey, ctx);
|
ResolvedSurveyUrl resolved = resolveSurveyUrl(survey, ctx);
|
||||||
@@ -464,7 +452,19 @@ public class ProjectService {
|
|||||||
|
|
||||||
private boolean isSameSurveyTarget(String previousFullUrl, String baseUrl) {
|
private boolean isSameSurveyTarget(String previousFullUrl, String baseUrl) {
|
||||||
return previousFullUrl != null
|
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 미발급 상태이므로,
|
// 토큰이 남아있으면 최초 저장, KON/KIWI full URL로 시작하면 short 미발급 상태이므로,
|
||||||
@@ -478,15 +478,14 @@ public class ProjectService {
|
|||||||
|
|
||||||
private String resolveSurveyBaseUrl(TPrjctSurveyEntity survey) {
|
private String resolveSurveyBaseUrl(TPrjctSurveyEntity survey) {
|
||||||
String surveyPrjctCd = survey.getSurveyPrjctCd();
|
String surveyPrjctCd = survey.getSurveyPrjctCd();
|
||||||
Long prjctSurveyIdx = survey.getPrjctSurveyIdx();
|
if (surveyPrjctCd == null || surveyPrjctCd.isBlank()) {
|
||||||
if (surveyPrjctCd == null || surveyPrjctCd.isBlank() || prjctSurveyIdx == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isKonSurvey(survey)) {
|
if (isKonSurvey(survey)) {
|
||||||
return KON_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp?psidx=" + prjctSurveyIdx;
|
return KON_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp";
|
||||||
}
|
}
|
||||||
if (isKiwiSurvey(survey)) {
|
if (isKiwiSurvey(survey)) {
|
||||||
return KIWI_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp?psidx=" + prjctSurveyIdx;
|
return KIWI_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -505,7 +504,15 @@ public class ProjectService {
|
|||||||
if (queryIndex < 0 || queryIndex + 1 >= url.length()) {
|
if (queryIndex < 0 || queryIndex + 1 >= url.length()) {
|
||||||
return "";
|
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) {
|
private String stripQueryString(String url) {
|
||||||
|
|||||||
Reference in New Issue
Block a user