sarvenyanik commited on
Commit
29ff7e1
·
1 Parent(s): a305d77

push notification service update

Browse files
src/main/java/com/utility/utilitycommonservice/domain/assembler/SaveLogAssembler.java ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.utility.utilitycommonservice.domain.assembler;
2
+
3
+ import com.fasterxml.jackson.core.JsonProcessingException;
4
+ import com.fasterxml.jackson.databind.ObjectMapper;
5
+ import com.utility.utilitycommonservice.common.helper.RequestScopeHelper;
6
+ import com.utility.utilitycommonservice.dao.entity.PushNotificationLog;
7
+ import com.utility.utilitycommonservice.dao.repository.PushNotificationLogRepository;
8
+ import com.utility.utilitycommonservice.domain.model.notification.enums.LogType;
9
+ import com.utility.utilitycommonservice.domain.model.notification.input.PushNotificationByDomainInput;
10
+ import lombok.RequiredArgsConstructor;
11
+ import lombok.extern.slf4j.Slf4j;
12
+ import org.springframework.stereotype.Component;
13
+
14
+ import java.time.LocalDate;
15
+ import java.util.UUID;
16
+
17
+ @Component
18
+ @RequiredArgsConstructor
19
+ @Slf4j
20
+ public class SaveLogAssembler {
21
+
22
+ private final PushNotificationLogRepository pushNotificationLogRepository;
23
+ private final ObjectMapper mapper = new ObjectMapper();
24
+
25
+ public void assemble(PushNotificationByDomainInput input, LogType logType, String messageId) {
26
+
27
+ try {
28
+ String jsonBody = mapper.writeValueAsString(input.getInfoModel());
29
+ PushNotificationLog pushNotificationLog = PushNotificationLog.builder()
30
+ .uid(UUID.randomUUID().toString())
31
+ .messageId(messageId)
32
+ .logType(logType)
33
+ .text(jsonBody)
34
+ .domainCode(input.getDomainCode())
35
+ .isRead(false)
36
+ .isRemove(false)
37
+ .customerNumber(RequestScopeHelper.getCustomerNumber())
38
+ .createDate(LocalDate.now())
39
+ .build();
40
+ pushNotificationLogRepository.save(pushNotificationLog);
41
+
42
+ }catch (JsonProcessingException e) {
43
+ log.error("a process error occurrence: {}", e.getMessage());
44
+ }
45
+ }
46
+
47
+ }
src/main/java/com/utility/utilitycommonservice/domain/model/notification/input/PushNotificationByDomainInput.java CHANGED
@@ -1,6 +1,7 @@
1
  package com.utility.utilitycommonservice.domain.model.notification.input;
2
 
3
  import com.utility.utilitycommonservice.domain.model.notification.InfoModel;
 
4
  import lombok.Builder;
5
  import lombok.Data;
6
 
@@ -10,4 +11,14 @@ public class PushNotificationByDomainInput {
10
  private InfoModel infoModel;
11
  private String domainCode; // campaign, ai vs.
12
 
 
 
 
 
 
 
 
 
 
 
13
  }
 
1
  package com.utility.utilitycommonservice.domain.model.notification.input;
2
 
3
  import com.utility.utilitycommonservice.domain.model.notification.InfoModel;
4
+ import com.utility.utilitycommonservice.integration.service.model.request.firebase.SendToTopicClientRequest;
5
  import lombok.Builder;
6
  import lombok.Data;
7
 
 
11
  private InfoModel infoModel;
12
  private String domainCode; // campaign, ai vs.
13
 
14
+ public SendToTopicClientRequest toRequest(String jsonBody) {
15
+ return SendToTopicClientRequest.builder()
16
+ .title(infoModel.getTitle())
17
+ .body(jsonBody)
18
+ .imageUrl(infoModel.getImageUrl())
19
+ .url(infoModel.getDeeplink().getNavigationCode())
20
+ .topic(domainCode)
21
+ .build();
22
+ }
23
+
24
  }
src/main/java/com/utility/utilitycommonservice/domain/service/clientbe/notification/notificationImpl/PushServiceImpl.java CHANGED
@@ -1,34 +1,27 @@
1
  package com.utility.utilitycommonservice.domain.service.clientbe.notification.notificationImpl;
2
 
3
- import com.fasterxml.jackson.core.JsonProcessingException;
4
  import com.fasterxml.jackson.databind.ObjectMapper;
5
- import com.utility.utilitycommonservice.common.helper.RequestScopeHelper;
6
- import com.utility.utilitycommonservice.dao.entity.PushNotificationLog;
7
- import com.utility.utilitycommonservice.dao.repository.PushNotificationLogRepository;
8
  import com.utility.utilitycommonservice.domain.assembler.CrudAssembler;
 
9
  import com.utility.utilitycommonservice.domain.model.notification.PushNotificationBody;
10
  import com.utility.utilitycommonservice.domain.model.notification.enums.LogType;
11
  import com.utility.utilitycommonservice.domain.model.notification.input.CrudNotificationInput;
12
  import com.utility.utilitycommonservice.domain.model.notification.input.PushNotificationByDomainInput;
13
  import com.utility.utilitycommonservice.domain.model.notification.output.CrudNotificationOutput;
14
  import com.utility.utilitycommonservice.domain.service.clientbe.notification.PushService;
15
- import com.utility.utilitycommonservice.integration.service.model.request.firebase.SendToTopicClientRequest;
16
  import com.utility.utilitycommonservice.integration.service.service.firebase.PushClientService;
17
  import lombok.RequiredArgsConstructor;
18
  import lombok.extern.slf4j.Slf4j;
19
  import org.springframework.stereotype.Service;
20
 
21
- import java.time.LocalDate;
22
- import java.util.UUID;
23
-
24
  @Service
25
  @RequiredArgsConstructor
26
  @Slf4j
27
  public class PushServiceImpl implements PushService {
28
 
29
  private final PushClientService clientService;
30
- private final PushNotificationLogRepository pushNotificationLogRepository;
31
  private final CrudAssembler crudAssembler;
 
32
  private final ObjectMapper mapper = new ObjectMapper();
33
 
34
  @Override
@@ -40,18 +33,12 @@ public class PushServiceImpl implements PushService {
40
  .isRead(false)
41
  .build();
42
  String jsonBody = mapper.writeValueAsString(pnBody);
43
- var clientResponse = clientService.sendToTopic(SendToTopicClientRequest.builder()
44
- .title(input.getInfoModel().getTitle())
45
- .body(jsonBody)
46
- .imageUrl(input.getInfoModel().getImageUrl())
47
- .url(input.getInfoModel().getDeeplink().getNavigationCode())
48
- .topic(input.getDomainCode())
49
- .build());
50
- saveLog(input, LogType.INFO, clientResponse.getMessageId());
51
 
52
  } catch (Exception e) {
53
  log.error("An error occurrence: {}", e.getMessage());
54
- saveLog(input, LogType.ERROR, null);
55
  }
56
 
57
  }
@@ -64,26 +51,4 @@ public class PushServiceImpl implements PushService {
64
  .build();
65
  }
66
 
67
- private void saveLog(PushNotificationByDomainInput input, LogType logType, String messageId) {
68
-
69
- try {
70
- String jsonBody = mapper.writeValueAsString(input.getInfoModel());
71
- PushNotificationLog pushNotificationLog = PushNotificationLog.builder()
72
- .uid(UUID.randomUUID().toString())
73
- .messageId(messageId)
74
- .logType(logType)
75
- .text(jsonBody)
76
- .domainCode(input.getDomainCode())
77
- .isRead(false)
78
- .isRemove(false)
79
- .customerNumber(RequestScopeHelper.getCustomerNumber())
80
- .createDate(LocalDate.now())
81
- .build();
82
- pushNotificationLogRepository.save(pushNotificationLog);
83
-
84
- }catch (JsonProcessingException e) {
85
- log.error("a process error occurrence: {}", e.getMessage());
86
- }
87
- }
88
-
89
  }
 
1
  package com.utility.utilitycommonservice.domain.service.clientbe.notification.notificationImpl;
2
 
 
3
  import com.fasterxml.jackson.databind.ObjectMapper;
 
 
 
4
  import com.utility.utilitycommonservice.domain.assembler.CrudAssembler;
5
+ import com.utility.utilitycommonservice.domain.assembler.SaveLogAssembler;
6
  import com.utility.utilitycommonservice.domain.model.notification.PushNotificationBody;
7
  import com.utility.utilitycommonservice.domain.model.notification.enums.LogType;
8
  import com.utility.utilitycommonservice.domain.model.notification.input.CrudNotificationInput;
9
  import com.utility.utilitycommonservice.domain.model.notification.input.PushNotificationByDomainInput;
10
  import com.utility.utilitycommonservice.domain.model.notification.output.CrudNotificationOutput;
11
  import com.utility.utilitycommonservice.domain.service.clientbe.notification.PushService;
 
12
  import com.utility.utilitycommonservice.integration.service.service.firebase.PushClientService;
13
  import lombok.RequiredArgsConstructor;
14
  import lombok.extern.slf4j.Slf4j;
15
  import org.springframework.stereotype.Service;
16
 
 
 
 
17
  @Service
18
  @RequiredArgsConstructor
19
  @Slf4j
20
  public class PushServiceImpl implements PushService {
21
 
22
  private final PushClientService clientService;
 
23
  private final CrudAssembler crudAssembler;
24
+ private final SaveLogAssembler saveLogAssembler;
25
  private final ObjectMapper mapper = new ObjectMapper();
26
 
27
  @Override
 
33
  .isRead(false)
34
  .build();
35
  String jsonBody = mapper.writeValueAsString(pnBody);
36
+ var clientResponse = clientService.sendToTopic(input.toRequest(jsonBody));
37
+ saveLogAssembler.assemble(input, LogType.INFO, clientResponse.getMessageId());
 
 
 
 
 
 
38
 
39
  } catch (Exception e) {
40
  log.error("An error occurrence: {}", e.getMessage());
41
+ saveLogAssembler.assemble(input, LogType.ERROR, null);
42
  }
43
 
44
  }
 
51
  .build();
52
  }
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }