Compare commits

...

2 Commits

20 changed files with 330 additions and 53 deletions

View File

@@ -23,6 +23,12 @@ Source: .agent/consumer-references/platform-capabilities.md
- Redis and scheduling are opt-in through their `kri.*.enabled` settings and matching runtime dependencies.
- HTTP bypass targets are server-configured. Never accept an arbitrary full target URL from a frontend; retain allowed-path checks and do not forward hop-by-hop headers.
- The external API client returns response bodies as documented, while bypass responses preserve raw bytes and target `Content-Type`.
- Bypass filters all HTTP/2 pseudo headers (names starting with `:`) in addition to existing hop-by-hop headers; use the response status accessor instead of forwarding `:status`.
- `kri.http.bypass.targets.<target>.throw-on-error` defaults to `false`. When enabled, the final response after response customizers throws public `com.kri.common.feature.http.ExternalApiResponseException` for non-2xx status; existing targets retain response-return behavior by default.
- `BypassResponse.requireSuccess()` and `ExternalApiResponse.requireSuccess()` explicitly enforce the same non-2xx guard. `ExternalApiClient` keeps its existing default behavior and decoded `getBody()` API, and `getBodyBytes()` exposes a defensive copy of the original received bytes, including compressed and binary error bodies.
- A response customizer's `ExternalApiResponseException`, including one thrown by `requireSuccess()`, propagates unchanged; other customizer failures keep the existing `BYPASS_RESPONSE_CUSTOMIZE_FAILED` behavior. Response charset parsing ignores charset-like text inside other quoted `Content-Type` parameters and retains the UTF-8 fallback.
- With Spring MVC and Servlet API present and `kri.web.enabled=true` (default), `ExternalApiErrorAutoConfiguration` registers a handler for this dedicated exception before the general error advice. It relays the original status, body bytes, `Content-Type`, and `Content-Encoding`, including empty bodies; authentication, cookie, and transport headers are not relayed by the error handler. Enable this policy only for targets whose raw errors may be exposed to clients. Connection failures remain distinct from upstream HTTP errors.
- A consumer-provided error handler bean named `externalApiResponseAdvice` replaces the default without importing runtime types; explicitly caught/controller-handled exceptions also remain under the consumer's control.
- `ExternalApiClient` multipart requests generate their own boundary and ignore a caller-supplied `Content-Type`. Multipart headers and `formField` values use UTF-8, while file bodies preserve the supplied bytes.
- Multipart filenames, including non-ASCII names, are sent unchanged in the quoted `filename` parameter as raw UTF-8. No ASCII fallback or `filename*` parameter is added; CR/LF rejection and quote/backslash escaping still apply.
- `JsonUtil` requires the consumer's explicit `ObjectMapper`; shared date/time helpers define KST as `Asia/Seoul` and also expose UTC semantics.

View File

@@ -17,7 +17,7 @@
### Shared Library and Integrations
- Consume `com.kri.common:starter:beta.1.6.3`. Do not change this approved version or duplicate an available KriCommon feature without separate explicit approval.
- Consume `com.kri.common:starter:beta.1.6.8`. Do not change this approved version or duplicate an available KriCommon feature without separate explicit approval.
- Import public KriCommon APIs from `com.kri.common.feature.*` and keep application code out of KriCommon runtime internals.
- Treat IntranetExtension, NotiHub, ShortUrl, CTI, file storage, and other external dependencies as explicit boundaries with validated inputs, timeouts, error mapping, retry/idempotency decisions, and safe rollback behavior.
- Never log API keys, credentials, full message bodies, telephone numbers in bulk, uploaded list contents, or unrestricted personal information.

View File

@@ -242,6 +242,8 @@ When implementation is complete, report in Korean:
- Consume KriCommon as `com.kri.common:starter:<approved-version>` through the repository's established Gradle version-management convention.
- Import service-facing APIs from `com.kri.common.feature.*`; treat `com.kri.common.runtime.*` as internal.
- Prefer a shared feature or approved extension point over duplicating authentication, HTTP, error, enum, Excel, Redis, JSON, date/time, JPA, crypto, or utility behavior locally.
- For HTTP/2 header safety and original upstream error propagation, use the shared HTTP/bypass features documented in the routed platform-capabilities reference instead of implementing consumer-local header filters and raw-response exception handlers.
- Response customizers may call `requireSuccess()`; its upstream exception propagates unchanged. Response charset parsing ignores charset-like text inside other quoted header parameters.
- Do not modify KriCommon or another consumer repository unless it is explicitly included in the approved task scope.
### Required Shared References

View File

@@ -38,7 +38,7 @@ repositories {
}
dependencies {
implementation "com.kri.common:starter:beta.1.6.7"
implementation "com.kri.common:starter:beta.1.6.8"
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'

View File

@@ -15,7 +15,9 @@ public enum ChannelType implements CodeEnum<Short> {
@Schema(description = "이메일")
EMAIL((short) 1),
@Schema(description = "문자")
SMS((short) 2);
SMS((short) 2),
@Schema(description = "알림톡")
KKO_AT((short) 3);
private final Short code;

View File

@@ -1,7 +1,6 @@
package com.kri.contact.server.common.external.notihub;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kri.common.feature.http.bypass.BypassClient;
import com.kri.common.feature.http.bypass.BypassForwardOptions;
@@ -14,6 +13,10 @@ import com.kri.common.feature.web.RequestUserContext;
import com.kri.contact.server.common.external.notihub.dto.NotiHubBulkSendCreateRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubBulkSendInfoDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubBulkSendResponseDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListResponseDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubReportExcelResponseDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubReportPageRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubReportPageResponseDto;
@@ -74,7 +77,7 @@ public class NotiHubApiClient {
public NotiHubTemplateDto getTemplate(Long tmplatIdx) {
String url = notiHubBaseUrl + "/template/" + tmplatIdx;
try {
ExternalApiResponse response = externalApiClient.get(url, headers());
ExternalApiResponse response = externalApiClient.get(url, headers()).requireSuccess();
return objectMapper.readValue(response.getBody(), NotiHubTemplateDto.class);
} catch (JsonProcessingException e) {
throw BusinessException.badRequest("NOTI_HUB_RESPONSE_PARSE_FAILED", "noti-hub 응답을 해석할 수 없습니다.")
@@ -96,6 +99,37 @@ public class NotiHubApiClient {
return postSingle("/send-sms/single", request, ctx);
}
public NotiHubSendSingleResponseDto sendKkoSingle(
NotiHubSendRequestSingleDto request,
RequestUserContext ctx
) {
return postSingle("/send-kko/single", request, ctx);
}
public String createKkoBulk(NotiHubBulkSendCreateRequestDto request) {
return createBulk("/send-kko/create/bulk", request);
}
public NotiHubBulkSendResponseDto sendKkoBulk(NotiHubSendRequestBulkDto request) {
return sendBulk("/send-kko/bulk", request);
}
public ResponseEntity<NotiHubKkoTemplateListResponseDto> getKkoTemplateList(
NotiHubKkoTemplateListRequestDto body,
HttpServletRequest request,
RequestUserContext ctx
) {
return relay(request, body, NotiHubKkoTemplateListResponseDto.class, ctx);
}
public ResponseEntity<NotiHubKkoTemplateDetailDto> getKkoTemplateDetail(
NotiHubKkoTemplateDetailRequestDto body,
HttpServletRequest request,
RequestUserContext ctx
) {
return relay(request, body, NotiHubKkoTemplateDetailDto.class, ctx);
}
public String createEmailBulk(NotiHubBulkSendCreateRequestDto request) {
return createBulk("/send-email/create/bulk", request);
}
@@ -240,8 +274,13 @@ public class NotiHubApiClient {
}
private String createBulk(String path, NotiHubBulkSendCreateRequestDto request) {
ExternalApiResponse response = put(notiHubBaseUrl + path, request);
return response.getBody();
ExternalApiResponse response = put(notiHubBaseUrl + path, request).requireSuccess();
String bulkSendKey = response.getBody();
if (bulkSendKey == null || bulkSendKey.isBlank() || bulkSendKey.length() != 32) {
throw BusinessException.of(HttpStatus.BAD_GATEWAY, "NOTI_HUB_BULK_KEY_INVALID",
"noti-hub 대량 발송 키가 올바르지 않습니다.");
}
return bulkSendKey;
}
private NotiHubBulkSendResponseDto sendBulk(String path, NotiHubSendRequestBulkDto request) {
@@ -257,7 +296,7 @@ public class NotiHubApiClient {
private ExternalApiResponse post(String url, Object request) {
try {
return externalApiClient.post(url, headers(), objectMapper.writeValueAsString(request));
return externalApiClient.post(url, headers(), objectMapper.writeValueAsString(request)).requireSuccess();
} catch (JsonProcessingException e) {
throw BusinessException.badRequest("NOTI_HUB_REQUEST_SERIALIZE_FAILED", "noti-hub 요청을 생성할 수 없습니다.")
.with("url", url);
@@ -270,6 +309,9 @@ public class NotiHubApiClient {
} catch (JsonProcessingException e) {
throw BusinessException.badRequest("NOTI_HUB_REQUEST_SERIALIZE_FAILED", "noti-hub 요청을 생성할 수 없습니다.")
.with("url", url);
} catch (RuntimeException e) {
throw BusinessException.of(HttpStatus.BAD_GATEWAY, "NOTI_HUB_CALL_FAILED",
"noti-hub에 연결할 수 없습니다.");
}
}
@@ -354,7 +396,7 @@ public class NotiHubApiClient {
HttpHeaders headers = new HttpHeaders();
headers.putAll(response.getHeaders());
// JSON serialization changes the bytes; upstream representation headers no longer apply.
headers.remove(HttpHeaders.CONTENT_LENGTH);
headers.remove(HttpHeaders.CONTENT_LENGTH);
headers.remove(HttpHeaders.CONTENT_ENCODING);
headers.remove(HttpHeaders.ETAG);
if (headers.getContentType() == null) {
@@ -374,32 +416,6 @@ public class NotiHubApiClient {
}
}
private void requireSuccessfulResponse(ResponseEntity<byte[]> response) {
if (response.getStatusCode().is2xxSuccessful()) {
return;
}
HttpStatus status = HttpStatus.resolve(response.getStatusCode().value());
if (status == null) {
status = HttpStatus.BAD_GATEWAY;
}
String code = "NOTI_HUB_ERROR";
String message = status.getReasonPhrase();
byte[] body = response.getBody();
if (body != null && body.length > 0) {
try {
JsonNode error = objectMapper.readTree(body);
if (error != null) {
code = error.path("code").asText(code);
message = error.path("detail").asText(message);
}
} catch (IOException e) {
// An invalid error body retains the HTTP status and its standard message.
}
}
throw BusinessException.of(status, code, message);
}
private ResponseEntity<byte[]> forward(
HttpServletRequest request,
byte[] body,
@@ -425,9 +441,7 @@ public class NotiHubApiClient {
}
throw e;
}
ResponseEntity<byte[]> result = toResponseEntity(response, request);
requireSuccessfulResponse(result);
return result;
return toResponseEntity(response, request);
}
private ResponseEntity<byte[]> relayMultipart(

View File

@@ -1,5 +1,6 @@
package com.kri.contact.server.common.external.notihub.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
@@ -24,6 +25,7 @@ public class NotiHubBulkSendCreateRequestDto {
@Schema(description = "resve")
private Boolean resve;
@Schema(description = "sendDt")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime sendDt;
@Schema(description = "trgtCnt")
private Integer trgtCnt;

View File

@@ -0,0 +1,35 @@
package com.kri.contact.server.common.external.notihub.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class NotiHubKkoTemplateDetailDto {
private String templateCode;
private String templateName;
private String templateContent;
private String templatePreviewMessage;
private String templateMessageType;
private String templateEmphasizeType;
private String inspectionStatus;
private String status;
private Boolean block;
private Boolean dormant;
private String templateExtra;
private String templateImageName;
private String templateImageUrl;
private String templateTitle;
private String templateSubtitle;
private String templateHeader;
private JsonNode templateItemHighlight;
private JsonNode templateItem;
private JsonNode templateRepresentLink;
private List<JsonNode> buttons;
private List<JsonNode> quickReplies;
}

View File

@@ -0,0 +1,21 @@
package com.kri.contact.server.common.external.notihub.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class NotiHubKkoTemplateDetailRequestDto {
@NotBlank
@Size(max = 30)
@Pattern(regexp = "[A-Za-z0-9_-]+")
private String templateCode;
}

View File

@@ -0,0 +1,21 @@
package com.kri.contact.server.common.external.notihub.dto;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
public class NotiHubKkoTemplateListRequestDto {
@Size(min = 2, max = 50)
private String keyword;
public NotiHubKkoTemplateListRequestDto(String keyword) {
setKeyword(keyword);
}
public void setKeyword(String keyword) {
this.keyword = keyword == null || keyword.isBlank() ? null : keyword.trim();
}
}

View File

@@ -0,0 +1,19 @@
package com.kri.contact.server.common.external.notihub.dto;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class NotiHubKkoTemplateListResponseDto {
private int totalCount;
private int totalPage;
private int currentPage;
private List<NotiHubKkoTemplateSummaryDto> list;
}

View File

@@ -0,0 +1,21 @@
package com.kri.contact.server.common.external.notihub.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class NotiHubKkoTemplateSummaryDto {
private String templateCode;
private String templateName;
private String serviceStatus;
private String createdAt;
private String modifiedAt;
}

View File

@@ -33,7 +33,6 @@ public class NotiHubTemplateBasicDto extends NotiHubExtensibleDto {
@Size(max = 128)
private String tmplatTitle;
@NotBlank
private String tmplatBody;
private String senderKey;

View File

@@ -44,6 +44,26 @@ public class MessageSendController {
return messageSendService.sendEmailBulk(prjctIdx, request, ctx);
}
@Operation(summary = "Kakao Alimtalk single send")
@PostMapping("/kko/single/{prjctIdx}")
public MessageSendSingleResponseDto sendKkoSingle(
@PathVariable Long prjctIdx,
@Valid @RequestBody MessageSendSingleRequestDto request,
RequestUserContext ctx
) {
return messageSendService.sendKkoSingle(prjctIdx, request, ctx);
}
@Operation(summary = "Kakao Alimtalk bulk send")
@PostMapping("/kko/bulk/{prjctIdx}")
public MessageSendBulkResponseDto sendKkoBulk(
@PathVariable Long prjctIdx,
@Valid @RequestBody MessageSendBulkRequestDto request,
RequestUserContext ctx
) {
return messageSendService.sendKkoBulk(prjctIdx, request, ctx);
}
@Operation(summary = "SMS single send")
@PostMapping("/sms/single/{prjctIdx}")
public MessageSendSingleResponseDto sendSmsSingle(

View File

@@ -1,6 +1,10 @@
package com.kri.contact.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListResponseDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateBasicDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateDetailDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateSummaryDto;
@@ -15,7 +19,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
@@ -30,6 +36,24 @@ public class MessageTemplateController {
private final MessageTemplateService messageTemplateService;
@PostMapping(value = "/kko/list", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<NotiHubKkoTemplateListResponseDto> getKkoTemplateList(
@Valid @RequestBody NotiHubKkoTemplateListRequestDto body,
HttpServletRequest request,
RequestUserContext ctx
) {
return messageTemplateService.getKkoTemplateList(body, request, ctx);
}
@PostMapping(value = "/kko/detail", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<NotiHubKkoTemplateDetailDto> getKkoTemplateDetail(
@Valid @RequestBody NotiHubKkoTemplateDetailRequestDto body,
HttpServletRequest request,
RequestUserContext ctx
) {
return messageTemplateService.getKkoTemplateDetail(body, request, ctx);
}
@GetMapping("/list/{chnnlTy}/{itrntPrjctCd}")
public ResponseEntity<List<NotiHubTemplateSummaryDto>> getTemplateList(
@PathVariable Integer chnnlTy,

View File

@@ -1,5 +1,6 @@
package com.kri.contact.server.dto.message;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.kri.contact.server.dto.list.ListFilterDto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
@@ -26,6 +27,7 @@ public class MessageSendBulkRequestDto {
private Boolean resve;
@Schema(description = "예약 발송 일시")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime sendDt;
@Valid

View File

@@ -1,5 +1,6 @@
package com.kri.contact.server.dto.message;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
@@ -23,6 +24,7 @@ public class MessageSendSingleRequestDto {
@Schema(description = "resve")
private Boolean resve;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "sendDt")
private LocalDateTime sendDt;

View File

@@ -24,6 +24,7 @@ import com.kri.contact.server.dto.message.MessageSendBulkRequestDto;
import com.kri.contact.server.dto.message.MessageSendSingleRequestDto;
import com.kri.contact.server.dto.message.MessageSendSingleResponseDto;
import com.kri.contact.server.dto.project.ProjectInfoDto;
import com.kri.contact.server.dto.project.ProjectSurveyDto;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -81,6 +82,24 @@ public class MessageSendService {
return sendBulk(prjctIdx, request, ctx, ChannelType.SMS);
}
@Transactional(readOnly = true)
public MessageSendSingleResponseDto sendKkoSingle(
Long prjctIdx,
MessageSendSingleRequestDto request,
RequestUserContext ctx
) {
return sendSingle(prjctIdx, request, ctx, ChannelType.KKO_AT);
}
@Transactional(readOnly = true)
public MessageSendBulkResponseDto sendKkoBulk(
Long prjctIdx,
MessageSendBulkRequestDto request,
RequestUserContext ctx
) {
return sendBulk(prjctIdx, request, ctx, ChannelType.KKO_AT);
}
private MessageSendSingleResponseDto sendSingle(
Long prjctIdx,
MessageSendSingleRequestDto request,
@@ -124,6 +143,8 @@ public class MessageSendService {
if (channelType == ChannelType.EMAIL) {
response = notiHubApiClient.sendEmailSingle(notiRequest, ctx);
} else if (channelType == ChannelType.KKO_AT) {
response = notiHubApiClient.sendKkoSingle(notiRequest, ctx);
} else {
response = notiHubApiClient.sendSmsSingle(notiRequest, ctx);
}
@@ -237,7 +258,7 @@ public class MessageSendService {
) {
List<NotiHubDestInfoDto> result = new ArrayList<>();
for (ListSearchService.DownloadListRow row : rows) {
Map<String, String> msgParam = createMessageParams(row, messageContext.paramHeaderByName());
Map<String, String> msgParam = createMessageParams(row, messageContext);
String destNm = resolveHeaderValue(row, messageContext.headerById().get(destNameHeaderId));
for (Integer destHeaderId : destHeaderIds) {
@@ -274,7 +295,7 @@ public class MessageSendService {
Set<String> bodyParams = extractTemplateParams(template.getTmplatBody());
Set<String> templateParams = SetUtils.union(titleParams, bodyParams);
Map<Integer, ListHeaderDto> headerById = listHeaderService.getHeader(prjctIdx).stream()
Map<Integer, ListHeaderDto> headerById = listHeaderService.getHeader(prjctIdx).stream()
.collect(Collectors.toMap(
ListHeaderDto::getListHderId,
header -> header,
@@ -299,7 +320,29 @@ public class MessageSendService {
LinkedHashMap::new
));
return new MessageContext(project, template, headerById, paramHeaderByName);
Map<String, String> surveyUrlByName = new LinkedHashMap<>();
if (project.getSurveys() != null) {
for (ProjectSurveyDto survey : project.getSurveys()) {
String name = survey.getSurveyName();
String url = normalizeBlank(survey.getSurveyUrl());
if (!templateParams.contains(name) || paramHeaderByName.containsKey(name) || url == null) {
continue;
}
if (surveyUrlByName.putIfAbsent(name, url) != null) {
throw BusinessException.badRequest("DUPLICATE_SURVEY_NAME", "치환할 설문명이 중복됩니다.")
.with("surveyName", name);
}
}
}
Set<String> requiredHeaderParams = new HashSet<>(templateParams);
surveyUrlByName.values().forEach(url -> requiredHeaderParams.addAll(extractTemplateParams(url)));
headerById.values().stream()
.filter(header -> requiredHeaderParams.contains(header.getListHderNm()))
.forEach(header -> paramHeaderByName.putIfAbsent(header.getListHderNm(), header));
return new MessageContext(project, template, headerById, paramHeaderByName,
templateParams, surveyUrlByName);
}
private String createBulkSendKey(
@@ -320,9 +363,11 @@ public class MessageSendService {
.trgtCnt(targetCount)
.build();
return channelType == ChannelType.EMAIL
? notiHubApiClient.createEmailBulk(notiRequest)
: notiHubApiClient.createSmsBulk(notiRequest);
return switch (channelType) {
case EMAIL -> notiHubApiClient.createEmailBulk(notiRequest);
case SMS -> notiHubApiClient.createSmsBulk(notiRequest);
case KKO_AT -> notiHubApiClient.createKkoBulk(notiRequest);
};
}
private NotiHubBulkSendResponseDto sendBulkChunk(
@@ -335,25 +380,44 @@ public class MessageSendService {
.destInfoList(destInfos)
.build();
return channelType == ChannelType.EMAIL
? notiHubApiClient.sendEmailBulk(request)
: notiHubApiClient.sendSmsBulk(request);
return switch (channelType) {
case EMAIL -> notiHubApiClient.sendEmailBulk(request);
case SMS -> notiHubApiClient.sendSmsBulk(request);
case KKO_AT -> notiHubApiClient.sendKkoBulk(request);
};
}
private Map<String, String> createMessageParams(
ListSearchService.DownloadListRow row,
Map<String, ListHeaderDto> paramHeaderByName
MessageContext messageContext
) {
Map<String, String> headerParams = new LinkedHashMap<>();
Map<String, String> msgParam = new LinkedHashMap<>();
for (Map.Entry<String, ListHeaderDto> entry : paramHeaderByName.entrySet()) {
for (Map.Entry<String, ListHeaderDto> entry : messageContext.paramHeaderByName().entrySet()) {
String value = resolveHeaderValue(row, entry.getValue());
if (value != null) {
msgParam.put(entry.getKey(), value);
headerParams.put(entry.getKey(), value);
if (messageContext.templateParams().contains(entry.getKey())) {
msgParam.put(entry.getKey(), value);
}
}
}
messageContext.surveyUrlByName().forEach((name, url) ->
msgParam.put(name, resolveSurveyUrlParams(url, headerParams)));
return msgParam;
}
private String resolveSurveyUrlParams(String url, Map<String, String> headerParams) {
Matcher matcher = TEMPLATE_PARAM_PATTERN.matcher(url);
StringBuilder resolved = new StringBuilder();
while (matcher.find()) {
String value = headerParams.get(normalizeBlank(matcher.group(1)));
matcher.appendReplacement(resolved, Matcher.quoteReplacement(value == null ? matcher.group() : value));
}
matcher.appendTail(resolved);
return resolved.toString();
}
private String resolveHeaderValue(ListSearchService.DownloadListRow row, ListHeaderDto header) {
if (header == null) {
return null;
@@ -419,7 +483,7 @@ public class MessageSendService {
if (normalized == null) {
return null;
}
if (channelType == ChannelType.SMS) {
if (channelType == ChannelType.SMS || channelType == ChannelType.KKO_AT) {
String digits = normalized.replaceAll("\\D", "");
return digits.isBlank() ? null : digits;
}
@@ -461,7 +525,9 @@ public class MessageSendService {
ProjectInfoDto project,
NotiHubTemplateDto template,
Map<Integer, ListHeaderDto> headerById,
Map<String, ListHeaderDto> paramHeaderByName
Map<String, ListHeaderDto> paramHeaderByName,
Set<String> templateParams,
Map<String, String> surveyUrlByName
) {}
private static class ListFilterDtoFactory {

View File

@@ -2,6 +2,10 @@ package com.kri.contact.server.service;
import com.kri.common.feature.web.BusinessException;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListRequestDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListResponseDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateBasicDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateDetailDto;
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateSummaryDto;
@@ -19,6 +23,22 @@ public class MessageTemplateService {
private final NotiHubApiClient notiHubApiClient;
public ResponseEntity<NotiHubKkoTemplateListResponseDto> getKkoTemplateList(
NotiHubKkoTemplateListRequestDto body,
HttpServletRequest request,
RequestUserContext ctx
) {
return notiHubApiClient.getKkoTemplateList(body, request, ctx);
}
public ResponseEntity<NotiHubKkoTemplateDetailDto> getKkoTemplateDetail(
NotiHubKkoTemplateDetailRequestDto body,
HttpServletRequest request,
RequestUserContext ctx
) {
return notiHubApiClient.getKkoTemplateDetail(body, request, ctx);
}
public ResponseEntity<List<NotiHubTemplateSummaryDto>> getTemplateList(
HttpServletRequest request,
RequestUserContext ctx

View File

@@ -40,6 +40,7 @@ kri:
request-timeout: 30s
targets:
noti-hub:
throw-on-error: true
base-url: ${kri.api-url.noti-hub}
allowed-paths:
- /message-template