Spaces:
Sleeping
Sleeping
Commit ·
85048d7
1
Parent(s): 39e18d3
add campaign services
Browse files- src/main/java/com/artandscience/webbff/webbff/WebbffApplication.java +2 -0
- src/main/java/com/artandscience/webbff/webbff/api/controller/CampaignController.java +31 -0
- src/main/java/com/artandscience/webbff/webbff/api/model/response/GetCampaignResponse.java +17 -0
- src/main/java/com/artandscience/webbff/webbff/common/base/model/BaseModel.java +12 -0
- src/main/java/com/artandscience/webbff/webbff/common/base/model/RequestHeader.java +1 -0
- src/main/java/com/artandscience/webbff/webbff/common/constants/HeaderConstant.java +3 -1
- src/main/java/com/artandscience/webbff/webbff/common/exception/CoreException.java +14 -0
- src/main/java/com/artandscience/webbff/webbff/common/interceptor/ResponseErrorHandler.java +9 -0
- src/main/java/com/artandscience/webbff/webbff/common/interceptor/TransactionFilter.java +2 -0
- src/main/java/com/artandscience/webbff/webbff/common/service/SessionService.java +0 -11
- src/main/java/com/artandscience/webbff/webbff/common/service/StateManagementService.java +15 -0
- src/main/java/com/artandscience/webbff/webbff/common/service/impl/{SessionServiceImpl.java → StateManagementServiceImpl.java} +40 -15
- src/main/java/com/artandscience/webbff/webbff/domain/constants/CampaignConstants.java +10 -0
- src/main/java/com/artandscience/webbff/webbff/domain/model/campaign/CampaignDetailModel.java +26 -0
- src/main/java/com/artandscience/webbff/webbff/domain/model/campaign/CampaignModel.java +33 -0
- src/main/java/com/artandscience/webbff/webbff/domain/model/enums/CampaignType.java +15 -0
- src/main/java/com/artandscience/webbff/webbff/domain/model/output/GetCampaignOutput.java +19 -0
- src/main/java/com/artandscience/webbff/webbff/domain/model/state/CampaignDetailState.java +19 -0
- src/main/java/com/artandscience/webbff/webbff/domain/model/state/CampaignState.java +22 -0
- src/main/java/com/artandscience/webbff/webbff/domain/model/state/CampaignStateList.java +17 -0
- src/main/java/com/artandscience/webbff/webbff/domain/service/CampaignService.java +13 -0
- src/main/java/com/artandscience/webbff/webbff/domain/service/impl/CampaignServiceImpl.java +75 -0
- src/main/java/com/artandscience/webbff/webbff/integration/config/EmptyObjectProvider.java +33 -0
- src/main/java/com/artandscience/webbff/webbff/integration/config/FeignClientConfiguration.java +43 -0
- src/main/java/com/artandscience/webbff/webbff/integration/decoder/FeignDecoder.java +53 -0
- src/main/java/com/artandscience/webbff/webbff/integration/decoder/FeignErrorDecoder.java +13 -0
- src/main/java/com/artandscience/webbff/webbff/integration/interceptor/FeignClientInterceptor.java +42 -0
- src/main/java/com/artandscience/webbff/webbff/integration/interceptor/FeignClientRequestInterceptor.java +35 -0
- src/main/java/com/artandscience/webbff/webbff/integration/service/CampaignClientService.java +16 -0
- src/main/java/com/artandscience/webbff/webbff/integration/service/response/StartSessionClientResponse.java +17 -0
- src/main/java/com/artandscience/webbff/webbff/integration/service/response/base/BaseClientResponse.java +20 -0
- src/main/resources/application.yml +6 -1
src/main/java/com/artandscience/webbff/webbff/WebbffApplication.java
CHANGED
|
@@ -2,8 +2,10 @@ package com.artandscience.webbff.webbff;
|
|
| 2 |
|
| 3 |
import org.springframework.boot.SpringApplication;
|
| 4 |
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
| 5 |
|
| 6 |
@SpringBootApplication
|
|
|
|
| 7 |
public class WebbffApplication {
|
| 8 |
|
| 9 |
public static void main(String[] args) {
|
|
|
|
| 2 |
|
| 3 |
import org.springframework.boot.SpringApplication;
|
| 4 |
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
| 5 |
+
import org.springframework.cloud.openfeign.EnableFeignClients;
|
| 6 |
|
| 7 |
@SpringBootApplication
|
| 8 |
+
@EnableFeignClients
|
| 9 |
public class WebbffApplication {
|
| 10 |
|
| 11 |
public static void main(String[] args) {
|
src/main/java/com/artandscience/webbff/webbff/api/controller/CampaignController.java
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.api.controller;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.api.model.response.GetCampaignResponse;
|
| 4 |
+
import com.artandscience.webbff.webbff.common.base.controller.BaseController;
|
| 5 |
+
import com.artandscience.webbff.webbff.common.base.response.MessageResponse;
|
| 6 |
+
import com.artandscience.webbff.webbff.domain.service.CampaignService;
|
| 7 |
+
import lombok.RequiredArgsConstructor;
|
| 8 |
+
import org.springframework.web.bind.annotation.GetMapping;
|
| 9 |
+
import org.springframework.web.bind.annotation.RequestMapping;
|
| 10 |
+
import org.springframework.web.bind.annotation.RestController;
|
| 11 |
+
|
| 12 |
+
@RequiredArgsConstructor
|
| 13 |
+
@RestController
|
| 14 |
+
@RequestMapping("/campaign-service")
|
| 15 |
+
public class CampaignController extends BaseController {
|
| 16 |
+
|
| 17 |
+
private final CampaignService campaignService;
|
| 18 |
+
|
| 19 |
+
@GetMapping("/sessionStart")
|
| 20 |
+
public MessageResponse<Void> sessionStart() {
|
| 21 |
+
campaignService.startSession();
|
| 22 |
+
return responseSuccess(null);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
@GetMapping("/getCampaign")
|
| 26 |
+
public MessageResponse<GetCampaignResponse> getCampaign() {
|
| 27 |
+
var output = campaignService.getCampaign();
|
| 28 |
+
return responseSuccess(output.toResponse());
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/api/model/response/GetCampaignResponse.java
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.api.model.response;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.domain.model.state.CampaignStateList;
|
| 4 |
+
import lombok.AllArgsConstructor;
|
| 5 |
+
import lombok.Builder;
|
| 6 |
+
import lombok.Data;
|
| 7 |
+
import lombok.NoArgsConstructor;
|
| 8 |
+
|
| 9 |
+
@Data
|
| 10 |
+
@Builder
|
| 11 |
+
@AllArgsConstructor
|
| 12 |
+
@NoArgsConstructor
|
| 13 |
+
public class GetCampaignResponse {
|
| 14 |
+
|
| 15 |
+
private CampaignStateList campaignStateList;
|
| 16 |
+
|
| 17 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/common/base/model/BaseModel.java
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.common.base.model;
|
| 2 |
+
|
| 3 |
+
import lombok.Data;
|
| 4 |
+
|
| 5 |
+
import java.io.Serial;
|
| 6 |
+
import java.io.Serializable;
|
| 7 |
+
|
| 8 |
+
@Data
|
| 9 |
+
public class BaseModel implements Serializable {
|
| 10 |
+
@Serial
|
| 11 |
+
private static final Long serialVersionUID = -8494890402734747721L;
|
| 12 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/common/base/model/RequestHeader.java
CHANGED
|
@@ -17,5 +17,6 @@ public class RequestHeader {
|
|
| 17 |
private String wafPassword;
|
| 18 |
private String diamondUsername;
|
| 19 |
private String diamondPassword;
|
|
|
|
| 20 |
|
| 21 |
}
|
|
|
|
| 17 |
private String wafPassword;
|
| 18 |
private String diamondUsername;
|
| 19 |
private String diamondPassword;
|
| 20 |
+
private String customerNumber;
|
| 21 |
|
| 22 |
}
|
src/main/java/com/artandscience/webbff/webbff/common/constants/HeaderConstant.java
CHANGED
|
@@ -7,7 +7,9 @@ public class HeaderConstant {
|
|
| 7 |
public static String HEADER_LANGUAGE = "x-language";
|
| 8 |
public static String HEADER_DEVICE_APP_NAME = "x-device-app-name";
|
| 9 |
public static String HEADER_DEVICE_APP_VERSION = "x-device-app-version";
|
| 10 |
-
public static String HEADER_SESSION_ID = "x-session-id";
|
| 11 |
public static String HEADER_CORRELATION_ID = "x-correlation-id";
|
|
|
|
|
|
|
| 12 |
|
| 13 |
}
|
|
|
|
| 7 |
public static String HEADER_LANGUAGE = "x-language";
|
| 8 |
public static String HEADER_DEVICE_APP_NAME = "x-device-app-name";
|
| 9 |
public static String HEADER_DEVICE_APP_VERSION = "x-device-app-version";
|
| 10 |
+
public static String HEADER_SESSION_ID = "x-b3-session-id";
|
| 11 |
public static String HEADER_CORRELATION_ID = "x-correlation-id";
|
| 12 |
+
public static String HEADER_CUSTOMER_NUMBER = "x-customer-number";
|
| 13 |
+
|
| 14 |
|
| 15 |
}
|
src/main/java/com/artandscience/webbff/webbff/common/exception/CoreException.java
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.common.exception;
|
| 2 |
+
|
| 3 |
+
import lombok.Getter;
|
| 4 |
+
|
| 5 |
+
import java.io.Serial;
|
| 6 |
+
import java.io.Serializable;
|
| 7 |
+
|
| 8 |
+
@Getter
|
| 9 |
+
public class CoreException extends RuntimeException implements Serializable {
|
| 10 |
+
|
| 11 |
+
@Serial
|
| 12 |
+
private static final Long serialVersionUID = -8494890402734747723L;
|
| 13 |
+
|
| 14 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/common/interceptor/ResponseErrorHandler.java
CHANGED
|
@@ -23,6 +23,7 @@ import org.springframework.web.method.HandlerMethod;
|
|
| 23 |
|
| 24 |
import java.util.ArrayList;
|
| 25 |
import java.util.List;
|
|
|
|
| 26 |
import java.util.Optional;
|
| 27 |
|
| 28 |
@RestControllerAdvice
|
|
@@ -40,6 +41,9 @@ public class ResponseErrorHandler extends BaseController {
|
|
| 40 |
log.error("Exception occurred: " + e.getMessage(), e);
|
| 41 |
var messageModel = getDefaultMessageModel(handlerMethod);
|
| 42 |
MessageBox messageBox = externalAttributeService.getMessageBox(messageModel);
|
|
|
|
|
|
|
|
|
|
| 43 |
List<MessageBox> messageBoxList = new ArrayList<>();
|
| 44 |
messageBoxList.add(messageBox);
|
| 45 |
return responseFail(messageBoxList);
|
|
@@ -94,4 +98,9 @@ public class ResponseErrorHandler extends BaseController {
|
|
| 94 |
return controllerName.replace("Controller","") + "_" + handlerMethod.getMethod().getName();
|
| 95 |
}
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
|
|
|
| 23 |
|
| 24 |
import java.util.ArrayList;
|
| 25 |
import java.util.List;
|
| 26 |
+
import java.util.Objects;
|
| 27 |
import java.util.Optional;
|
| 28 |
|
| 29 |
@RestControllerAdvice
|
|
|
|
| 41 |
log.error("Exception occurred: " + e.getMessage(), e);
|
| 42 |
var messageModel = getDefaultMessageModel(handlerMethod);
|
| 43 |
MessageBox messageBox = externalAttributeService.getMessageBox(messageModel);
|
| 44 |
+
if (Objects.isNull(messageBox)) {
|
| 45 |
+
messageBox = getDefaultMessageBox();
|
| 46 |
+
}
|
| 47 |
List<MessageBox> messageBoxList = new ArrayList<>();
|
| 48 |
messageBoxList.add(messageBox);
|
| 49 |
return responseFail(messageBoxList);
|
|
|
|
| 98 |
return controllerName.replace("Controller","") + "_" + handlerMethod.getMethod().getName();
|
| 99 |
}
|
| 100 |
|
| 101 |
+
private MessageBox getDefaultMessageBox() {
|
| 102 |
+
var messageModel = MessageModel.builder().code("DEFAULT_MESSAGE_BOX").build();
|
| 103 |
+
return externalAttributeService.getMessageBox(messageModel);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
}
|
src/main/java/com/artandscience/webbff/webbff/common/interceptor/TransactionFilter.java
CHANGED
|
@@ -20,6 +20,7 @@ import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HE
|
|
| 20 |
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_DEVICE_APP_VERSION;
|
| 21 |
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_SESSION_ID;
|
| 22 |
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_CORRELATION_ID;
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
|
|
@@ -53,6 +54,7 @@ public class TransactionFilter extends OncePerRequestFilter {
|
|
| 53 |
.deviceAppVersion(request.getHeader(HEADER_DEVICE_APP_VERSION))
|
| 54 |
.sessionId(request.getHeader(HEADER_SESSION_ID))
|
| 55 |
.correlationId(request.getHeader(HEADER_CORRELATION_ID))
|
|
|
|
| 56 |
.build();
|
| 57 |
}
|
| 58 |
|
|
|
|
| 20 |
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_DEVICE_APP_VERSION;
|
| 21 |
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_SESSION_ID;
|
| 22 |
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_CORRELATION_ID;
|
| 23 |
+
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_CUSTOMER_NUMBER;
|
| 24 |
|
| 25 |
|
| 26 |
|
|
|
|
| 54 |
.deviceAppVersion(request.getHeader(HEADER_DEVICE_APP_VERSION))
|
| 55 |
.sessionId(request.getHeader(HEADER_SESSION_ID))
|
| 56 |
.correlationId(request.getHeader(HEADER_CORRELATION_ID))
|
| 57 |
+
.customerNumber(request.getHeader(HEADER_CUSTOMER_NUMBER))
|
| 58 |
.build();
|
| 59 |
}
|
| 60 |
|
src/main/java/com/artandscience/webbff/webbff/common/service/SessionService.java
DELETED
|
@@ -1,11 +0,0 @@
|
|
| 1 |
-
package com.artandscience.webbff.webbff.common.service;
|
| 2 |
-
|
| 3 |
-
public interface SessionService {
|
| 4 |
-
|
| 5 |
-
<T> void setSession(String sessionKey, String exTime, T object);
|
| 6 |
-
|
| 7 |
-
<T> T getSession(String sessionKey, Class<T> returnType, boolean... isNullable);
|
| 8 |
-
|
| 9 |
-
void removeSession(String sessionKey);
|
| 10 |
-
|
| 11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/main/java/com/artandscience/webbff/webbff/common/service/StateManagementService.java
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.common.service;
|
| 2 |
+
|
| 3 |
+
public interface StateManagementService {
|
| 4 |
+
|
| 5 |
+
<T> void setState(String key, String exTime, T object);
|
| 6 |
+
|
| 7 |
+
<T> void setStateBySession(String key, T object);
|
| 8 |
+
|
| 9 |
+
<T> T getState(String key, Class<T> returnType, boolean... isNullable);
|
| 10 |
+
|
| 11 |
+
<T> T getStateBySession(String key, Class<T> returnType, boolean... isNullable);
|
| 12 |
+
|
| 13 |
+
void removeState(String key);
|
| 14 |
+
|
| 15 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/common/service/impl/{SessionServiceImpl.java → StateManagementServiceImpl.java}
RENAMED
|
@@ -4,7 +4,7 @@ package com.artandscience.webbff.webbff.common.service.impl;
|
|
| 4 |
import com.artandscience.webbff.webbff.common.exception.SessionException;
|
| 5 |
import com.artandscience.webbff.webbff.common.exception.enums.SessionErrorType;
|
| 6 |
import com.artandscience.webbff.webbff.common.scope.RequestHeaderScope;
|
| 7 |
-
import com.artandscience.webbff.webbff.common.service.
|
| 8 |
import com.artandscience.webbff.webbff.common.utils.RedisUtil;
|
| 9 |
import io.micrometer.common.util.StringUtils;
|
| 10 |
import lombok.RequiredArgsConstructor;
|
|
@@ -17,44 +17,69 @@ import java.util.concurrent.TimeUnit;
|
|
| 17 |
@Service
|
| 18 |
@Slf4j
|
| 19 |
@RequiredArgsConstructor
|
| 20 |
-
public class
|
| 21 |
|
| 22 |
private final RedisUtil redisUtil;
|
| 23 |
|
| 24 |
private final RequestHeaderScope requestHeaderScope;
|
| 25 |
|
| 26 |
@Value("${spring.data.redis.session-expire-time}")
|
| 27 |
-
private String
|
| 28 |
|
| 29 |
@Override
|
| 30 |
-
public <T> void
|
| 31 |
-
String
|
| 32 |
-
String expireTime = !StringUtils.isEmpty(exTime) ? exTime : sessionExpireTime;
|
| 33 |
redisUtil.putValue(key,object,Integer.parseInt(expireTime), TimeUnit.MINUTES);
|
| 34 |
}
|
| 35 |
|
| 36 |
@Override
|
| 37 |
-
public <T>
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
try {
|
| 41 |
Boolean nullableSession = false;
|
| 42 |
if (isNullable.length > 0) {
|
| 43 |
nullableSession = isNullable[0];
|
| 44 |
}
|
| 45 |
-
|
| 46 |
-
if ((!nullableSession &&
|
| 47 |
-
log.error("
|
| 48 |
}
|
| 49 |
}catch (Exception ex) {
|
| 50 |
-
log.error("
|
| 51 |
throw new SessionException(SessionErrorType.SESSION_NOT_FOUND);
|
| 52 |
}
|
| 53 |
-
return returnType.cast(
|
| 54 |
}
|
| 55 |
|
| 56 |
@Override
|
| 57 |
-
public void
|
| 58 |
|
| 59 |
}
|
| 60 |
}
|
|
|
|
| 4 |
import com.artandscience.webbff.webbff.common.exception.SessionException;
|
| 5 |
import com.artandscience.webbff.webbff.common.exception.enums.SessionErrorType;
|
| 6 |
import com.artandscience.webbff.webbff.common.scope.RequestHeaderScope;
|
| 7 |
+
import com.artandscience.webbff.webbff.common.service.StateManagementService;
|
| 8 |
import com.artandscience.webbff.webbff.common.utils.RedisUtil;
|
| 9 |
import io.micrometer.common.util.StringUtils;
|
| 10 |
import lombok.RequiredArgsConstructor;
|
|
|
|
| 17 |
@Service
|
| 18 |
@Slf4j
|
| 19 |
@RequiredArgsConstructor
|
| 20 |
+
public class StateManagementServiceImpl implements StateManagementService {
|
| 21 |
|
| 22 |
private final RedisUtil redisUtil;
|
| 23 |
|
| 24 |
private final RequestHeaderScope requestHeaderScope;
|
| 25 |
|
| 26 |
@Value("${spring.data.redis.session-expire-time}")
|
| 27 |
+
private String stateExpireTime;
|
| 28 |
|
| 29 |
@Override
|
| 30 |
+
public <T> void setState(String key, String exTime, T object) {
|
| 31 |
+
String expireTime = !StringUtils.isEmpty(exTime) ? exTime : stateExpireTime;
|
|
|
|
| 32 |
redisUtil.putValue(key,object,Integer.parseInt(expireTime), TimeUnit.MINUTES);
|
| 33 |
}
|
| 34 |
|
| 35 |
@Override
|
| 36 |
+
public <T> void setStateBySession(String key, T object) {
|
| 37 |
+
String stateKey = key + "-" + requestHeaderScope.getRequestHeader().getSessionId();
|
| 38 |
+
redisUtil.putValue(stateKey,object,Integer.parseInt(stateExpireTime), TimeUnit.MINUTES);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
@Override
|
| 42 |
+
public <T> T getState(String key, Class<T> returnType, boolean... isNullable) {
|
| 43 |
+
Object stateObject = null;
|
| 44 |
+
String stateKey = StringUtils.isEmpty(key) ? requestHeaderScope.getRequestHeader().getSessionId() : key;
|
| 45 |
+
try {
|
| 46 |
+
Boolean nullableSession = false;
|
| 47 |
+
if (isNullable.length > 0) {
|
| 48 |
+
nullableSession = isNullable[0];
|
| 49 |
+
}
|
| 50 |
+
stateObject = redisUtil.getValue(stateKey);
|
| 51 |
+
if ((!nullableSession && stateObject == null) || returnType == null) {
|
| 52 |
+
log.error("StateManagementService get object is null for key: " + key);
|
| 53 |
+
}
|
| 54 |
+
}catch (Exception ex) {
|
| 55 |
+
log.error("StateManagementService get object is null for key: " + key);
|
| 56 |
+
throw new SessionException(SessionErrorType.SESSION_NOT_FOUND);
|
| 57 |
+
}
|
| 58 |
+
return returnType.cast(stateObject);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
@Override
|
| 62 |
+
public <T> T getStateBySession(String key, Class<T> returnType, boolean... isNullable) {
|
| 63 |
+
Object stateObject = null;
|
| 64 |
+
String stateKey = key + "-" + requestHeaderScope.getRequestHeader().getSessionId();
|
| 65 |
try {
|
| 66 |
Boolean nullableSession = false;
|
| 67 |
if (isNullable.length > 0) {
|
| 68 |
nullableSession = isNullable[0];
|
| 69 |
}
|
| 70 |
+
stateObject = redisUtil.getValue(stateKey);
|
| 71 |
+
if ((!nullableSession && stateObject == null) || returnType == null) {
|
| 72 |
+
log.error("StateManagementService get object is null for key: " + key);
|
| 73 |
}
|
| 74 |
}catch (Exception ex) {
|
| 75 |
+
log.error("StateManagementService get object is null for key: " + key);
|
| 76 |
throw new SessionException(SessionErrorType.SESSION_NOT_FOUND);
|
| 77 |
}
|
| 78 |
+
return returnType.cast(stateObject);
|
| 79 |
}
|
| 80 |
|
| 81 |
@Override
|
| 82 |
+
public void removeState(String sessionKey) {
|
| 83 |
|
| 84 |
}
|
| 85 |
}
|
src/main/java/com/artandscience/webbff/webbff/domain/constants/CampaignConstants.java
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.constants;
|
| 2 |
+
|
| 3 |
+
import lombok.extern.slf4j.Slf4j;
|
| 4 |
+
|
| 5 |
+
@Slf4j
|
| 6 |
+
public abstract class CampaignConstants {
|
| 7 |
+
|
| 8 |
+
public static final String CAMPAIGN_STATE = "CampaignState";
|
| 9 |
+
|
| 10 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/model/campaign/CampaignDetailModel.java
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.model.campaign;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.domain.model.state.CampaignDetailState;
|
| 4 |
+
import lombok.AllArgsConstructor;
|
| 5 |
+
import lombok.Builder;
|
| 6 |
+
import lombok.Data;
|
| 7 |
+
import lombok.NoArgsConstructor;
|
| 8 |
+
|
| 9 |
+
@Data
|
| 10 |
+
@AllArgsConstructor
|
| 11 |
+
@NoArgsConstructor
|
| 12 |
+
@Builder
|
| 13 |
+
public class CampaignDetailModel {
|
| 14 |
+
private String imageUrl;
|
| 15 |
+
private String title;
|
| 16 |
+
private String text;
|
| 17 |
+
|
| 18 |
+
public CampaignDetailState toState() {
|
| 19 |
+
return CampaignDetailState.builder()
|
| 20 |
+
.imageUrl(imageUrl)
|
| 21 |
+
.title(title)
|
| 22 |
+
.text(text)
|
| 23 |
+
.build();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/model/campaign/CampaignModel.java
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.model.campaign;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.domain.model.enums.CampaignType;
|
| 4 |
+
import com.artandscience.webbff.webbff.domain.model.state.CampaignState;
|
| 5 |
+
import lombok.AllArgsConstructor;
|
| 6 |
+
import lombok.Builder;
|
| 7 |
+
import lombok.Data;
|
| 8 |
+
import lombok.NoArgsConstructor;
|
| 9 |
+
|
| 10 |
+
import java.util.Objects;
|
| 11 |
+
|
| 12 |
+
@Data
|
| 13 |
+
@AllArgsConstructor
|
| 14 |
+
@NoArgsConstructor
|
| 15 |
+
@Builder
|
| 16 |
+
public class CampaignModel {
|
| 17 |
+
|
| 18 |
+
private String campaignId;
|
| 19 |
+
private String imageUrl;
|
| 20 |
+
private CampaignType campaignType;
|
| 21 |
+
private CampaignDetailModel campaignDetail;
|
| 22 |
+
|
| 23 |
+
public CampaignState toState() {
|
| 24 |
+
return CampaignState.builder()
|
| 25 |
+
.campaignId(campaignId)
|
| 26 |
+
.imageUrl(imageUrl)
|
| 27 |
+
.campaignType(campaignType)
|
| 28 |
+
.campaignDetailState(!Objects.isNull(campaignDetail) ? campaignDetail.toState() : null)
|
| 29 |
+
.isRead(false)
|
| 30 |
+
.build();
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/model/enums/CampaignType.java
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.model.enums;
|
| 2 |
+
|
| 3 |
+
import lombok.Getter;
|
| 4 |
+
|
| 5 |
+
@Getter
|
| 6 |
+
public enum CampaignType {
|
| 7 |
+
CAMPAIGN_MAIN("CAMPAIGN_MAIN"),HERO_CAMPAIGN("HERO_CAMPAIGN"), NONE("NONE");
|
| 8 |
+
|
| 9 |
+
private final String code;
|
| 10 |
+
|
| 11 |
+
CampaignType(String code) {
|
| 12 |
+
this.code = code;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/model/output/GetCampaignOutput.java
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.model.output;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.api.model.response.GetCampaignResponse;
|
| 4 |
+
import com.artandscience.webbff.webbff.domain.model.state.CampaignStateList;
|
| 5 |
+
import lombok.Builder;
|
| 6 |
+
import lombok.Data;
|
| 7 |
+
|
| 8 |
+
@Data
|
| 9 |
+
@Builder
|
| 10 |
+
public class GetCampaignOutput {
|
| 11 |
+
private CampaignStateList campaignStateList;
|
| 12 |
+
|
| 13 |
+
public GetCampaignResponse toResponse() {
|
| 14 |
+
return GetCampaignResponse.builder()
|
| 15 |
+
.campaignStateList(campaignStateList)
|
| 16 |
+
.build();
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/model/state/CampaignDetailState.java
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.model.state;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.common.base.model.BaseModel;
|
| 4 |
+
import lombok.AllArgsConstructor;
|
| 5 |
+
import lombok.Builder;
|
| 6 |
+
import lombok.Data;
|
| 7 |
+
import lombok.NoArgsConstructor;
|
| 8 |
+
|
| 9 |
+
@Data
|
| 10 |
+
@Builder
|
| 11 |
+
@AllArgsConstructor
|
| 12 |
+
@NoArgsConstructor
|
| 13 |
+
public class CampaignDetailState extends BaseModel {
|
| 14 |
+
|
| 15 |
+
private String imageUrl;
|
| 16 |
+
private String title;
|
| 17 |
+
private String text;
|
| 18 |
+
|
| 19 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/model/state/CampaignState.java
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.model.state;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.common.base.model.BaseModel;
|
| 4 |
+
import com.artandscience.webbff.webbff.domain.model.enums.CampaignType;
|
| 5 |
+
import lombok.AllArgsConstructor;
|
| 6 |
+
import lombok.Builder;
|
| 7 |
+
import lombok.Data;
|
| 8 |
+
import lombok.NoArgsConstructor;
|
| 9 |
+
|
| 10 |
+
@Data
|
| 11 |
+
@Builder
|
| 12 |
+
@AllArgsConstructor
|
| 13 |
+
@NoArgsConstructor
|
| 14 |
+
public class CampaignState extends BaseModel {
|
| 15 |
+
|
| 16 |
+
private String campaignId;
|
| 17 |
+
private String imageUrl;
|
| 18 |
+
private CampaignType campaignType;
|
| 19 |
+
private Boolean isRead;
|
| 20 |
+
private CampaignDetailState campaignDetailState;
|
| 21 |
+
|
| 22 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/model/state/CampaignStateList.java
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.model.state;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.common.base.model.BaseModel;
|
| 4 |
+
import lombok.AllArgsConstructor;
|
| 5 |
+
import lombok.Builder;
|
| 6 |
+
import lombok.Data;
|
| 7 |
+
import lombok.NoArgsConstructor;
|
| 8 |
+
|
| 9 |
+
import java.util.List;
|
| 10 |
+
|
| 11 |
+
@Data
|
| 12 |
+
@Builder
|
| 13 |
+
@AllArgsConstructor
|
| 14 |
+
@NoArgsConstructor
|
| 15 |
+
public class CampaignStateList extends BaseModel {
|
| 16 |
+
private List<CampaignState> campaignStates;
|
| 17 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/service/CampaignService.java
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.service;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.domain.model.output.GetCampaignOutput;
|
| 4 |
+
|
| 5 |
+
public interface CampaignService {
|
| 6 |
+
|
| 7 |
+
void startSession();
|
| 8 |
+
|
| 9 |
+
GetCampaignOutput getCampaign();
|
| 10 |
+
|
| 11 |
+
void endSession();
|
| 12 |
+
|
| 13 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/domain/service/impl/CampaignServiceImpl.java
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.domain.service.impl;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.common.service.StateManagementService;
|
| 4 |
+
import com.artandscience.webbff.webbff.domain.model.output.GetCampaignOutput;
|
| 5 |
+
import com.artandscience.webbff.webbff.domain.model.state.CampaignState;
|
| 6 |
+
import com.artandscience.webbff.webbff.domain.model.state.CampaignStateList;
|
| 7 |
+
import com.artandscience.webbff.webbff.domain.service.CampaignService;
|
| 8 |
+
import com.artandscience.webbff.webbff.integration.service.CampaignClientService;
|
| 9 |
+
import lombok.RequiredArgsConstructor;
|
| 10 |
+
import lombok.extern.slf4j.Slf4j;
|
| 11 |
+
import org.springframework.stereotype.Service;
|
| 12 |
+
|
| 13 |
+
import java.util.ArrayList;
|
| 14 |
+
import java.util.List;
|
| 15 |
+
import java.util.Objects;
|
| 16 |
+
|
| 17 |
+
import static com.artandscience.webbff.webbff.domain.constants.CampaignConstants.CAMPAIGN_STATE;
|
| 18 |
+
|
| 19 |
+
@Service
|
| 20 |
+
@RequiredArgsConstructor
|
| 21 |
+
@Slf4j
|
| 22 |
+
public class CampaignServiceImpl implements CampaignService {
|
| 23 |
+
|
| 24 |
+
private final CampaignClientService campaignClientService;
|
| 25 |
+
private final StateManagementService stateManagementService;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@Override
|
| 29 |
+
public void startSession() {
|
| 30 |
+
var clientResponse = campaignClientService.sessionStart();
|
| 31 |
+
List<CampaignState> campaignStates = new ArrayList<>();
|
| 32 |
+
|
| 33 |
+
// state yazılacak.
|
| 34 |
+
if (!Objects.isNull(clientResponse) && !Objects.isNull(clientResponse.getPayload())
|
| 35 |
+
&& !Objects.isNull(clientResponse.getPayload().getCampaignModels())) {
|
| 36 |
+
for (var campaignModel : clientResponse.getPayload().getCampaignModels()) {
|
| 37 |
+
var campaignState = campaignModel.toState();
|
| 38 |
+
campaignStates.add(campaignState);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
var campaignState = CampaignStateList.builder()
|
| 42 |
+
.campaignStates(campaignStates)
|
| 43 |
+
.build();
|
| 44 |
+
stateManagementService.setStateBySession(CAMPAIGN_STATE, campaignState);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
@Override
|
| 48 |
+
public GetCampaignOutput getCampaign() {
|
| 49 |
+
|
| 50 |
+
var state = stateManagementService.getStateBySession(CAMPAIGN_STATE,
|
| 51 |
+
CampaignStateList.class, true);
|
| 52 |
+
|
| 53 |
+
if (!Objects.isNull(state) && !Objects.isNull(state.getCampaignStates())
|
| 54 |
+
&& !state.getCampaignStates().isEmpty()) {
|
| 55 |
+
|
| 56 |
+
return GetCampaignOutput.builder()
|
| 57 |
+
.campaignStateList(state)
|
| 58 |
+
.build();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
return GetCampaignOutput.builder().build();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
@Override
|
| 65 |
+
public void endSession() {
|
| 66 |
+
|
| 67 |
+
var state = stateManagementService.getStateBySession(CAMPAIGN_STATE,
|
| 68 |
+
CampaignStateList.class, true);
|
| 69 |
+
|
| 70 |
+
if (!Objects.isNull(state)) {
|
| 71 |
+
stateManagementService.removeState(CAMPAIGN_STATE);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
}
|
| 75 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/config/EmptyObjectProvider.java
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.config;
|
| 2 |
+
|
| 3 |
+
import org.springframework.beans.BeansException;
|
| 4 |
+
import org.springframework.beans.factory.ObjectProvider;
|
| 5 |
+
|
| 6 |
+
import java.util.function.Consumer;
|
| 7 |
+
|
| 8 |
+
public class EmptyObjectProvider<T> implements ObjectProvider<T> {
|
| 9 |
+
@Override
|
| 10 |
+
public T getObject(Object... args) throws BeansException {
|
| 11 |
+
return null;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
@Override
|
| 15 |
+
public T getIfAvailable() throws BeansException {
|
| 16 |
+
return null;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
@Override
|
| 20 |
+
public T getIfUnique() throws BeansException {
|
| 21 |
+
return null;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
@Override
|
| 25 |
+
public T getObject() throws BeansException {
|
| 26 |
+
return null;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
@Override
|
| 30 |
+
public void forEach(Consumer<? super T> action) {
|
| 31 |
+
ObjectProvider.super.forEach(action);
|
| 32 |
+
}
|
| 33 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/config/FeignClientConfiguration.java
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.config;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.common.scope.RequestHeaderScope;
|
| 4 |
+
import com.artandscience.webbff.webbff.integration.decoder.FeignDecoder;
|
| 5 |
+
import com.artandscience.webbff.webbff.integration.interceptor.FeignClientInterceptor;
|
| 6 |
+
import com.artandscience.webbff.webbff.integration.interceptor.FeignClientRequestInterceptor;
|
| 7 |
+
import feign.Client;
|
| 8 |
+
import feign.RequestInterceptor;
|
| 9 |
+
import feign.Retryer;
|
| 10 |
+
import feign.codec.Decoder;
|
| 11 |
+
import lombok.RequiredArgsConstructor;
|
| 12 |
+
import org.springframework.beans.factory.ObjectFactory;
|
| 13 |
+
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
| 14 |
+
import org.springframework.cloud.openfeign.support.SpringDecoder;
|
| 15 |
+
import org.springframework.context.annotation.Bean;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@RequiredArgsConstructor
|
| 19 |
+
public class FeignClientConfiguration {
|
| 20 |
+
|
| 21 |
+
private final RequestHeaderScope requestHeaderScope;
|
| 22 |
+
|
| 23 |
+
@Bean
|
| 24 |
+
public Client client() {
|
| 25 |
+
return new FeignClientInterceptor(null,null);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
@Bean
|
| 29 |
+
public RequestInterceptor requestInterceptor() {
|
| 30 |
+
return new FeignClientRequestInterceptor(requestHeaderScope);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
@Bean
|
| 34 |
+
public Retryer retryer() {
|
| 35 |
+
return Retryer.NEVER_RETRY;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* @Bean
|
| 39 |
+
public Decoder feignDecoder(ObjectFactory<HttpMessageConverters> messageConverters) {
|
| 40 |
+
return new FeignDecoder(new SpringDecoder(messageConverters, new EmptyObjectProvider<>()));
|
| 41 |
+
}*/
|
| 42 |
+
|
| 43 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/decoder/FeignDecoder.java
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.decoder;
|
| 2 |
+
|
| 3 |
+
import feign.*;
|
| 4 |
+
import feign.codec.DecodeException;
|
| 5 |
+
import feign.codec.Decoder;
|
| 6 |
+
import org.apache.logging.log4j.util.Strings;
|
| 7 |
+
import org.springframework.cloud.openfeign.support.SpringDecoder;
|
| 8 |
+
|
| 9 |
+
import java.io.IOException;
|
| 10 |
+
import java.io.InputStream;
|
| 11 |
+
import java.lang.reflect.Type;
|
| 12 |
+
import java.nio.charset.StandardCharsets;
|
| 13 |
+
import java.util.Objects;
|
| 14 |
+
import java.util.Optional;
|
| 15 |
+
|
| 16 |
+
public class FeignDecoder implements Decoder {
|
| 17 |
+
|
| 18 |
+
private final Decoder decoder;
|
| 19 |
+
|
| 20 |
+
public FeignDecoder(SpringDecoder decoder) {
|
| 21 |
+
this.decoder = decoder;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
@Override
|
| 25 |
+
public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
|
| 26 |
+
if (Objects.isNull(response.body())) {
|
| 27 |
+
return null;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
String responseBody;
|
| 31 |
+
try(InputStream inputStream = response.body().asInputStream()) {
|
| 32 |
+
responseBody = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
var serviceName = Optional.ofNullable(response)
|
| 36 |
+
.map(Response::request)
|
| 37 |
+
.map(Request::requestTemplate)
|
| 38 |
+
.map(RequestTemplate::feignTarget)
|
| 39 |
+
.map(Target::name).orElse(Strings.EMPTY);
|
| 40 |
+
|
| 41 |
+
try {
|
| 42 |
+
return this.decoder.decode(Response.builder()
|
| 43 |
+
.status(response.status())
|
| 44 |
+
.headers(response.headers())
|
| 45 |
+
.body(responseBody, StandardCharsets.UTF_8)
|
| 46 |
+
.request(response.request())
|
| 47 |
+
.build(), type);
|
| 48 |
+
} catch (Exception e) {
|
| 49 |
+
return responseBody;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
}
|
| 53 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/decoder/FeignErrorDecoder.java
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.decoder;
|
| 2 |
+
|
| 3 |
+
import feign.Response;
|
| 4 |
+
import feign.codec.ErrorDecoder;
|
| 5 |
+
import org.springframework.stereotype.Component;
|
| 6 |
+
|
| 7 |
+
@Component
|
| 8 |
+
public class FeignErrorDecoder implements ErrorDecoder {
|
| 9 |
+
@Override
|
| 10 |
+
public Exception decode(String s, Response response) {
|
| 11 |
+
return new Exception(response.reason());
|
| 12 |
+
}
|
| 13 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/interceptor/FeignClientInterceptor.java
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.interceptor;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.common.exception.CoreException;
|
| 4 |
+
import feign.Client;
|
| 5 |
+
import feign.Request;
|
| 6 |
+
import feign.Response;
|
| 7 |
+
import lombok.extern.slf4j.Slf4j;
|
| 8 |
+
import org.springframework.util.StreamUtils;
|
| 9 |
+
|
| 10 |
+
import javax.net.ssl.HostnameVerifier;
|
| 11 |
+
import javax.net.ssl.SSLSocketFactory;
|
| 12 |
+
import java.io.IOException;
|
| 13 |
+
import java.io.InputStream;
|
| 14 |
+
import java.nio.charset.StandardCharsets;
|
| 15 |
+
|
| 16 |
+
@Slf4j
|
| 17 |
+
public class FeignClientInterceptor extends Client.Default{
|
| 18 |
+
|
| 19 |
+
public FeignClientInterceptor(SSLSocketFactory sslContextFactory, HostnameVerifier hostnameVerifier) {
|
| 20 |
+
super(sslContextFactory,hostnameVerifier);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@Override
|
| 24 |
+
public Response execute(Request request, Request.Options options) throws IOException {
|
| 25 |
+
String responseBody = "";
|
| 26 |
+
try(Response response = super.execute(request,options)) {
|
| 27 |
+
if (response.body() != null) {
|
| 28 |
+
InputStream bodyStream = response.body().asInputStream();
|
| 29 |
+
responseBody = StreamUtils.copyToString(bodyStream, StandardCharsets.UTF_8);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
handleException(responseBody);
|
| 33 |
+
|
| 34 |
+
return response.toBuilder().body(responseBody, StandardCharsets.UTF_8).build();
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
private void handleException(String responseBody) throws CoreException, IOException {
|
| 39 |
+
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/interceptor/FeignClientRequestInterceptor.java
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.interceptor;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.common.base.model.RequestHeader;
|
| 4 |
+
import com.artandscience.webbff.webbff.common.scope.RequestHeaderScope;
|
| 5 |
+
import feign.RequestInterceptor;
|
| 6 |
+
import feign.RequestTemplate;
|
| 7 |
+
import lombok.AllArgsConstructor;
|
| 8 |
+
|
| 9 |
+
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_DEVICE_APP_NAME;
|
| 10 |
+
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_LANGUAGE;
|
| 11 |
+
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_DEVICE_APP_VERSION;
|
| 12 |
+
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_SESSION_ID;
|
| 13 |
+
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_CORRELATION_ID;
|
| 14 |
+
import static com.artandscience.webbff.webbff.common.constants.HeaderConstant.HEADER_CUSTOMER_NUMBER;
|
| 15 |
+
|
| 16 |
+
@AllArgsConstructor
|
| 17 |
+
public class FeignClientRequestInterceptor implements RequestInterceptor {
|
| 18 |
+
|
| 19 |
+
private final RequestHeaderScope requestHeaderScope;
|
| 20 |
+
|
| 21 |
+
private static void setRequestHeader(RequestTemplate requestTemplate, RequestHeader requestHeader) {
|
| 22 |
+
requestTemplate.header(HEADER_LANGUAGE, requestHeader.getLanguage());
|
| 23 |
+
requestTemplate.header(HEADER_DEVICE_APP_NAME, requestHeader.getDeviceAppName());
|
| 24 |
+
requestTemplate.header(HEADER_DEVICE_APP_VERSION, requestHeader.getDeviceAppName());
|
| 25 |
+
requestTemplate.header(HEADER_SESSION_ID, requestHeader.getSessionId());
|
| 26 |
+
requestTemplate.header(HEADER_CORRELATION_ID, requestHeader.getCorrelationId());
|
| 27 |
+
requestTemplate.header(HEADER_CUSTOMER_NUMBER, requestHeader.getCustomerNumber());
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
@Override
|
| 31 |
+
public void apply(RequestTemplate requestTemplate) {
|
| 32 |
+
var requestHeader = requestHeaderScope.getRequestHeader();
|
| 33 |
+
setRequestHeader(requestTemplate, requestHeader);
|
| 34 |
+
}
|
| 35 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/service/CampaignClientService.java
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.service;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.integration.config.FeignClientConfiguration;
|
| 4 |
+
import com.artandscience.webbff.webbff.integration.service.response.StartSessionClientResponse;
|
| 5 |
+
import com.artandscience.webbff.webbff.integration.service.response.base.BaseClientResponse;
|
| 6 |
+
import org.springframework.cloud.openfeign.FeignClient;
|
| 7 |
+
import org.springframework.web.bind.annotation.GetMapping;
|
| 8 |
+
|
| 9 |
+
@FeignClient(name = "${campaign-core-service.name}", url = "${campaign-core-service.base-url}",
|
| 10 |
+
configuration = FeignClientConfiguration.class)
|
| 11 |
+
public interface CampaignClientService {
|
| 12 |
+
|
| 13 |
+
@GetMapping("${campaign-core-service.session-start}")
|
| 14 |
+
BaseClientResponse<StartSessionClientResponse> sessionStart();
|
| 15 |
+
|
| 16 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/service/response/StartSessionClientResponse.java
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.service.response;
|
| 2 |
+
|
| 3 |
+
import com.artandscience.webbff.webbff.domain.model.campaign.CampaignModel;
|
| 4 |
+
import lombok.AllArgsConstructor;
|
| 5 |
+
import lombok.Builder;
|
| 6 |
+
import lombok.Data;
|
| 7 |
+
import lombok.NoArgsConstructor;
|
| 8 |
+
|
| 9 |
+
import java.util.List;
|
| 10 |
+
|
| 11 |
+
@Data
|
| 12 |
+
@Builder
|
| 13 |
+
@AllArgsConstructor
|
| 14 |
+
@NoArgsConstructor
|
| 15 |
+
public class StartSessionClientResponse {
|
| 16 |
+
List<CampaignModel> campaignModels;
|
| 17 |
+
}
|
src/main/java/com/artandscience/webbff/webbff/integration/service/response/base/BaseClientResponse.java
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.artandscience.webbff.webbff.integration.service.response.base;
|
| 2 |
+
|
| 3 |
+
import lombok.Data;
|
| 4 |
+
import lombok.NoArgsConstructor;
|
| 5 |
+
|
| 6 |
+
@Data
|
| 7 |
+
@NoArgsConstructor
|
| 8 |
+
public class BaseClientResponse<T> {
|
| 9 |
+
private Boolean isSuccess;
|
| 10 |
+
private String errorCode;
|
| 11 |
+
private String errorDescription;
|
| 12 |
+
private String errorType;
|
| 13 |
+
private String errorFunction;
|
| 14 |
+
private String transactionId;
|
| 15 |
+
private T payload;
|
| 16 |
+
|
| 17 |
+
public BaseClientResponse(T payload) {
|
| 18 |
+
this.payload = payload;
|
| 19 |
+
}
|
| 20 |
+
}
|
src/main/resources/application.yml
CHANGED
|
@@ -32,4 +32,9 @@ spring:
|
|
| 32 |
server:
|
| 33 |
port: 9090
|
| 34 |
servlet:
|
| 35 |
-
context-path: /arts-web-bff-service
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
server:
|
| 33 |
port: 9090
|
| 34 |
servlet:
|
| 35 |
+
context-path: /arts-web-bff-service
|
| 36 |
+
|
| 37 |
+
campaign-core-service:
|
| 38 |
+
name: "campaign-service"
|
| 39 |
+
base-url: "${BASE_CORE_SERVICE_URL}/api/v1/campaign"
|
| 40 |
+
session-start: "/startSession"
|