1
1
package org .test .consumer .service ;
2
2
3
+ import java .lang .reflect .InvocationTargetException ;
4
+ import java .lang .reflect .Method ;
5
+ import java .nio .ByteBuffer ;
6
+ import java .time .format .DateTimeFormatter ;
7
+ import java .util .ArrayList ;
8
+ import java .util .List ;
3
9
import lombok .AllArgsConstructor ;
10
+ import lombok .extern .slf4j .Slf4j ;
4
11
import org .apache .fineract .avro .BulkMessageItemV1 ;
5
- import org .slf4j .Logger ;
6
- import org .slf4j .LoggerFactory ;
7
12
import org .springframework .stereotype .Service ;
8
13
import org .test .consumer .data .EventMessageDTO ;
9
14
import org .test .consumer .domain .EventMessage ;
10
15
import org .test .consumer .repository .EventMessageRepository ;
11
16
import org .test .consumer .utility .ByteBufferConvertor ;
12
17
13
- import java .lang .reflect .InvocationTargetException ;
14
- import java .lang .reflect .Method ;
15
- import java .nio .ByteBuffer ;
16
- import java .util .ArrayList ;
17
- import java .util .List ;
18
-
19
18
@ Service
20
19
@ AllArgsConstructor
20
+ @ Slf4j
21
21
public class MessageConsumerServiceImpl implements MessageConsumerService {
22
-
23
- private static final Logger logger = LoggerFactory .getLogger (MessageConsumerServiceImpl .class );
24
-
25
22
private final EventMessageRepository repository ;
26
23
private final ByteBufferConvertor byteBufferConvertor ;
27
24
@@ -31,8 +28,9 @@ public List<EventMessageDTO> getMessages() {
31
28
List <EventMessage > messages = repository .findAll ();
32
29
try {
33
30
eventMessages = convertToReadableFormat (messages );
34
- } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e ) {
35
- logger .error ("Unable to read message {}" , e );
31
+ } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
32
+ IllegalAccessException e ) {
33
+ log .error ("Unable to read message" , e );
36
34
}
37
35
return eventMessages ;
38
36
}
@@ -43,8 +41,9 @@ public List<EventMessageDTO> getMessagesByType(String eventType) {
43
41
List <EventMessage > messages = repository .findByType (eventType );
44
42
try {
45
43
eventMessages = convertToReadableFormat (messages );
46
- } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e ) {
47
- logger .error ("Unable to read message {}" , e );
44
+ } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
45
+ IllegalAccessException e ) {
46
+ log .error ("Unable to read message" , e );
48
47
}
49
48
return eventMessages ;
50
49
}
@@ -55,7 +54,7 @@ public void deleteMessages() {
55
54
}
56
55
57
56
private List <EventMessageDTO > convertToReadableFormat (List <EventMessage > messages )
58
- throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException , IllegalAccessException {
57
+ throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException , IllegalAccessException {
59
58
List <EventMessageDTO > eventMessages = new ArrayList <>();
60
59
for (EventMessage message : messages ) {
61
60
Class payLoadClass = Class .forName (message .getSchema ());
@@ -71,22 +70,26 @@ private List<EventMessageDTO> convertToReadableFormat(List<EventMessage> message
71
70
bulkMessagePayload .append (bulkMessageData );
72
71
bulkMessagePayload .append (System .lineSeparator ());
73
72
}
74
- eventMessages .add (new EventMessageDTO (message .getEventId (), message .getType (), message .getCategory (), message .getTenantId (), message . getCreatedAt (),
75
- bulkMessagePayload .toString (),
76
- message .getBusinessDate ()));
73
+ eventMessages .add (new EventMessageDTO (message .getEventId (), message .getType (), message .getCategory (), message .getTenantId (), getCreatedAt (message ),
74
+ bulkMessagePayload .toString (),
75
+ message .getBusinessDate ()));
77
76
78
77
} else {
79
78
eventMessages .add (
80
- new EventMessageDTO (message .getEventId (), message .getType (), message .getCategory (), message .getTenantId (), message . getCreatedAt (), payLoad .toString (),
81
- message .getBusinessDate ()));
79
+ new EventMessageDTO (message .getEventId (), message .getType (), message .getCategory (), message .getTenantId (), getCreatedAt (message ), payLoad .toString (),
80
+ message .getBusinessDate ()));
82
81
}
83
82
}
84
83
85
84
return eventMessages ;
86
85
}
87
86
87
+ private String getCreatedAt (EventMessage message ) {
88
+ return DateTimeFormatter .ISO_LOCAL_DATE_TIME .format (message .getCreatedAt ());
89
+ }
90
+
88
91
private EventMessageDTO retrieveBulkMessage (BulkMessageItemV1 messageItem )
89
- throws ClassNotFoundException , InvocationTargetException , IllegalAccessException , NoSuchMethodException {
92
+ throws ClassNotFoundException , InvocationTargetException , IllegalAccessException , NoSuchMethodException {
90
93
Class messageBulkMessagePayLoad = Class .forName (messageItem .getDataschema ());
91
94
Method methodForPayLoad = messageBulkMessagePayLoad .getMethod ("fromByteBuffer" , ByteBuffer .class );
92
95
Object payLoadBulkItem = methodForPayLoad .invoke (null , messageItem .getData ());
0 commit comments