261021_01_ENH: 2차 마이그레이션 완료
This commit is contained in:
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.feature.util.StringUtil;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.kart.server.common.consts.KartConstant;
|
||||
import com.kri.kart.server.common.enums.ProjectType;
|
||||
import com.kri.kart.server.dto.project.ProjectRefDto;
|
||||
import com.kri.kart.server.dto.question.QuestionDto;
|
||||
@@ -37,15 +38,6 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "kri.kart.database", name = "enabled", havingValue = "true")
|
||||
public class StatisticsService {
|
||||
private static final String STANDARD_MODE = "STANDARD";
|
||||
// TABULATION requests have no single index; their rows are stored under the INDEX root.
|
||||
private static final String TABULATION_STORAGE_ROOT = "INDEX";
|
||||
private static final String ATTRIBUTE_PROJECTION_SUFFIX = "#A";
|
||||
private static final int PROFILE_QUESTION_ROLE = 1001;
|
||||
private static final List<String> PROFILE_ID_PREFIXES = List.of("PF", "PS");
|
||||
private static final String AUDIT_EVENT = "Get Report Data";
|
||||
private static final String CALCULATION_FAILED_CODE = "REPORT_CALCULATION_FAILED";
|
||||
private static final String CALCULATION_FAILED_MESSAGE = "문항 집계 처리에 실패했습니다.";
|
||||
|
||||
private final StatisticsRepository statisticsRepository;
|
||||
private final QuestionRepository questionRepository;
|
||||
@@ -80,7 +72,7 @@ public class StatisticsService {
|
||||
List<StatisticsRequestDto> requests,
|
||||
RequestUserContext ctx) {
|
||||
StatisticsBatchDto statisticsBatch = prepare(project, requests, ctx, false);
|
||||
logService.writeSiteLog(project, AUDIT_EVENT, objectMapper.valueToTree(requests), ctx);
|
||||
logService.writeSiteLog(project, KartConstant.REPORT_AUDIT_EVENT, objectMapper.valueToTree(requests), ctx);
|
||||
return statisticsBatch;
|
||||
}
|
||||
|
||||
@@ -117,7 +109,7 @@ public class StatisticsService {
|
||||
} catch (RuntimeException error) {
|
||||
event =
|
||||
errorEvent(
|
||||
position, request, 500, CALCULATION_FAILED_CODE, CALCULATION_FAILED_MESSAGE);
|
||||
position, request, 500, KartConstant.CALCULATION_FAILED_CODE, KartConstant.CALCULATION_FAILED_MESSAGE);
|
||||
failed++;
|
||||
}
|
||||
// A calculation can take a while; never write to a stream cancelled in the meantime.
|
||||
@@ -167,7 +159,7 @@ public class StatisticsService {
|
||||
private List<QuestionDto> loadQuestions(ProjectRefDto project, RequestUserContext ctx) {
|
||||
boolean includeProfileQuestions =
|
||||
project.getProjectType() == ProjectType.KIWI
|
||||
&& Integer.valueOf(PROFILE_QUESTION_ROLE).equals(ctx.getUserRole());
|
||||
&& Integer.valueOf(KartConstant.PROFILE_QUESTION_ROLE).equals(ctx.getUserRole());
|
||||
return questionService.organize(questionRepository.list(project, includeProfileQuestions));
|
||||
}
|
||||
|
||||
@@ -233,7 +225,7 @@ public class StatisticsService {
|
||||
return false;
|
||||
}
|
||||
String upperCaseId = normalized.toUpperCase(Locale.ROOT);
|
||||
return PROFILE_ID_PREFIXES.stream().anyMatch(upperCaseId::startsWith);
|
||||
return KartConstant.PROFILE_ID_PREFIXES.stream().anyMatch(upperCaseId::startsWith);
|
||||
}
|
||||
|
||||
private StatisticsResponseDto calculate(
|
||||
@@ -263,7 +255,7 @@ public class StatisticsService {
|
||||
/** Storage root keys selected by the original single-index query: index plus banners. */
|
||||
private List<String> storageRoots(StatisticsRequestDto request) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
ids.add(isStandard(request) ? request.getIndex() : TABULATION_STORAGE_ROOT);
|
||||
ids.add(isStandard(request) ? request.getIndex() : KartConstant.TABULATION_STORAGE_ROOT);
|
||||
request.getBanners().forEach(ids::addAll);
|
||||
return ids.stream().map(this::toStorageRoot).distinct().toList();
|
||||
}
|
||||
@@ -272,7 +264,7 @@ public class StatisticsService {
|
||||
private String toStorageRoot(String id) {
|
||||
return Objects.toString(StringUtil.normalizeBlank(id), "")
|
||||
.toUpperCase(Locale.ROOT)
|
||||
.replace(ATTRIBUTE_PROJECTION_SUFFIX, "")
|
||||
.replace(KartConstant.ATTRIBUTE_PROJECTION_SUFFIX, "")
|
||||
.split("_")[0];
|
||||
}
|
||||
|
||||
@@ -298,7 +290,7 @@ public class StatisticsService {
|
||||
}
|
||||
|
||||
private boolean isStandard(StatisticsRequestDto request) {
|
||||
return STANDARD_MODE.equals(request.getMode());
|
||||
return KartConstant.STANDARD_MODE.equals(request.getMode());
|
||||
}
|
||||
|
||||
private boolean isCancelled(BooleanSupplier cancelled) {
|
||||
@@ -307,7 +299,7 @@ public class StatisticsService {
|
||||
|
||||
/** Server-side failures must not expose internal details to the client. */
|
||||
private String clientMessage(BusinessException error) {
|
||||
return error.getStatus().is5xxServerError() ? CALCULATION_FAILED_MESSAGE : error.getMessage();
|
||||
return error.getStatus().is5xxServerError() ? KartConstant.CALCULATION_FAILED_MESSAGE : error.getMessage();
|
||||
}
|
||||
|
||||
private StatisticsStreamEventDto resultEvent(
|
||||
|
||||
Reference in New Issue
Block a user