7
7
import org .apache .logging .log4j .LogManager ;
8
8
import org .apache .logging .log4j .Logger ;
9
9
import org .jembi .jempi .libmpi .dgraph .LibDgraph ;
10
- import org .jembi .jempi .libmpi .postgresql .LibPostgresql ;
11
10
import org .jembi .jempi .shared .kafka .MyKafkaProducer ;
12
11
import org .jembi .jempi .shared .models .*;
13
12
import org .jembi .jempi .shared .serdes .JsonPojoSerializer ;
14
13
import org .jembi .jempi .shared .utils .AuditTrailBridge ;
14
+
15
15
import java .time .LocalDateTime ;
16
16
import java .util .List ;
17
17
import java .util .Locale ;
@@ -39,28 +39,12 @@ public LibMPI(
39
39
auditTrailUtil = new AuditTrailBridge (topicAuditEvents );
40
40
}
41
41
42
- public LibMPI (
43
- final String URL ,
44
- final String USR ,
45
- final String PSW ,
46
- final String kafkaBootstrapServers ,
47
- final String kafkaClientId ) {
48
- LOGGER .info ("{}" , "LibMPI Constructor" );
49
- topicAuditEvents = new MyKafkaProducer <>(kafkaBootstrapServers ,
50
- GlobalConstants .TOPIC_AUDIT_TRAIL ,
51
- new StringSerializer (),
52
- new JsonPojoSerializer <>(),
53
- kafkaClientId );
54
- client = new LibPostgresql (URL , USR , PSW );
55
- auditTrailUtil = new AuditTrailBridge (topicAuditEvents );
56
- }
57
-
58
42
private void sendAuditEvent (
59
- final String interactionID ,
60
- final String goldenID ,
61
- final String message ,
62
- final float score ,
63
- final LinkingRule linkingRule ) {
43
+ final String interactionID ,
44
+ final String goldenID ,
45
+ final String message ,
46
+ final float score ,
47
+ final LinkingRule linkingRule ) {
64
48
65
49
LinkingAuditEventData linkingEvent = new LinkingAuditEventData (message , interactionID , goldenID , score , linkingRule );
66
50
auditTrailUtil .sendAuditEvent (GlobalConstants .AuditEventType .LINKING_EVENT , linkingEvent );
@@ -123,18 +107,26 @@ public List<ExpandedInteraction> findExpandedInteractions(final List<String> int
123
107
return client .findExpandedInteractions (interactionIDs );
124
108
}
125
109
126
- public GoldenRecord findGoldenRecord (final String goldenId ) {
127
- return client .findGoldenRecord (goldenId );
110
+ public Either <MpiGeneralError , GoldenRecord > findGoldenRecord (final String goldenId ) {
111
+ final var records = client .findGoldenRecords (List .of (goldenId ));
112
+ if (records .isRight ()) {
113
+ if (!records .get ().isEmpty ()) {
114
+ return Either .right (records .get ().getFirst ());
115
+ } else {
116
+ return Either .left (new MpiServiceError .CRGidDoesNotExistError (goldenId ));
117
+ }
118
+ }
119
+ return Either .left (records .getLeft ());
128
120
}
129
121
130
- public List <GoldenRecord > findGoldenRecords (final List <String > goldenIds ) {
122
+ public Either < MpiGeneralError , List <GoldenRecord > > findGoldenRecords (final List <String > goldenIds ) {
131
123
return client .findGoldenRecords (goldenIds );
132
124
}
133
125
134
126
public ExpandedGoldenRecord findExpandedGoldenRecord (final String goldenId ) {
135
127
final var records = client .findExpandedGoldenRecords (List .of (goldenId ));
136
128
if (!records .isEmpty ()) {
137
- return records .get ( 0 );
129
+ return records .getFirst ( );
138
130
}
139
131
return null ;
140
132
}
@@ -161,8 +153,8 @@ public List<GoldenRecord> findMatchCandidates(final CustomDemographicData demogr
161
153
return client .findMatchCandidates (demographicData );
162
154
}
163
155
164
- public Either <List <GoldenRecord >, MpiGeneralError > findGoldenRecords (final ApiModels .ApiCrFindRequest request ) {
165
- return client .findGoldenRecords (request );
156
+ public Either <MpiGeneralError , List <GoldenRecord >> apiCrFindGoldenRecords (final ApiModels .ApiCrFindRequest request ) {
157
+ return client .apiCrFindGoldenRecords (request );
166
158
}
167
159
168
160
public LibMPIPaginatedResultSet <ExpandedGoldenRecord > simpleSearchGoldenRecords (
@@ -230,9 +222,17 @@ public boolean setScore(
230
222
final float newScore ) {
231
223
final var result = client .setScore (interactionID , goldenID , newScore );
232
224
if (result ) {
233
- sendAuditEvent (interactionID , goldenID , String .format (Locale .ROOT , "score: %.5f -> %.5f" , oldScore , newScore ), newScore , LinkingRule .UNMATCHED );
225
+ sendAuditEvent (interactionID ,
226
+ goldenID ,
227
+ String .format (Locale .ROOT , "score: %.5f -> %.5f" , oldScore , newScore ),
228
+ newScore ,
229
+ LinkingRule .UNMATCHED );
234
230
} else {
235
- sendAuditEvent (interactionID , goldenID , String .format (Locale .ROOT , "set score error: %.5f -> %.5f" , oldScore , newScore ), newScore , LinkingRule .UNMATCHED );
231
+ sendAuditEvent (interactionID ,
232
+ goldenID ,
233
+ String .format (Locale .ROOT , "set score error: %.5f -> %.5f" , oldScore , newScore ),
234
+ newScore ,
235
+ LinkingRule .UNMATCHED );
236
236
237
237
}
238
238
return result ;
@@ -255,20 +255,20 @@ public boolean updateGoldenRecordField(
255
255
final var result = client .updateGoldenRecordField (goldenId , fieldName , newValue );
256
256
if (result ) {
257
257
sendAuditEvent (interactionId , goldenId , String .format (Locale .ROOT ,
258
- "%s: '%s' -> '%s'" ,
259
- fieldName ,
260
- oldValue ,
261
- newValue ),
262
- -1.0F ,
263
- LinkingRule .UNMATCHED );
258
+ "%s: '%s' -> '%s'" ,
259
+ fieldName ,
260
+ oldValue ,
261
+ newValue ),
262
+ -1.0F ,
263
+ LinkingRule .UNMATCHED );
264
264
} else {
265
265
sendAuditEvent (interactionId , goldenId , String .format (Locale .ROOT ,
266
- "%s: error updating '%s' -> '%s'" ,
267
- fieldName ,
268
- oldValue ,
269
- newValue ),
270
- -1.0F ,
271
- LinkingRule .UNMATCHED );
266
+ "%s: error updating '%s' -> '%s'" ,
267
+ fieldName ,
268
+ oldValue ,
269
+ newValue ),
270
+ -1.0F ,
271
+ LinkingRule .UNMATCHED );
272
272
}
273
273
return result ;
274
274
}
@@ -288,12 +288,12 @@ public Either<MpiGeneralError, LinkInfo> linkToNewGoldenRecord(
288
288
score ), score , LinkingRule .UNMATCHED );
289
289
} else {
290
290
sendAuditEvent (interactionId ,
291
- currentGoldenId ,
292
- String .format (Locale .ROOT ,
293
- "Interaction -> update GoldenID error: old(%s) [%f]" ,
294
- currentGoldenId , score ),
295
- score ,
296
- LinkingRule .UNMATCHED );
291
+ currentGoldenId ,
292
+ String .format (Locale .ROOT ,
293
+ "Interaction -> update GoldenID error: old(%s) [%f]" ,
294
+ currentGoldenId , score ),
295
+ score ,
296
+ LinkingRule .UNMATCHED );
297
297
}
298
298
return result ;
299
299
}
@@ -357,16 +357,16 @@ public LinkInfo createInteractionAndLinkToClonedGoldenRecord(
357
357
final var result = client .createInteractionAndLinkToClonedGoldenRecord (interaction , score );
358
358
if (result != null ) {
359
359
sendAuditEvent (result .interactionUID (),
360
- result .goldenUID (),
361
- String .format (Locale .ROOT ,
362
- "Interaction -> New GoldenRecord (%f)" , score ),
363
- score , LinkingRule .UNMATCHED );
360
+ result .goldenUID (),
361
+ String .format (Locale .ROOT ,
362
+ "Interaction -> New GoldenRecord (%f)" , score ),
363
+ score , LinkingRule .UNMATCHED );
364
364
} else {
365
365
sendAuditEvent (interaction .interactionId (),
366
- null ,
367
- String .format (Locale .ROOT ,
368
- "Interaction -> error linking to new GoldenRecord (%f)" , score ),
369
- score , LinkingRule .UNMATCHED );
366
+ null ,
367
+ String .format (Locale .ROOT ,
368
+ "Interaction -> error linking to new GoldenRecord (%f)" , score ),
369
+ score , LinkingRule .UNMATCHED );
370
370
}
371
371
return result ;
372
372
}
0 commit comments