1
+ package stewardship ;
2
+
3
+ import java .util .*;
4
+ import javax .json .*;
5
+ import java .io .*;
6
+
7
+ import com .senzing .sdk .*;
8
+ import com .senzing .sdk .core .SzCoreEnvironment ;
9
+
10
+ import static com .senzing .sdk .SzFlag .*;
11
+
12
+ /**
13
+ * Provides a simple example of force-unresolving records that
14
+ * otherwise will not resolve to one another.
15
+ */
16
+ public class ForceUnresolve {
17
+ private static final String TEST = "TEST" ;
18
+
19
+ public static void main (String [] args ) {
20
+ // get the senzing repository settings
21
+ String settings = System .getenv ("SENZING_ENGINE_CONFIGURATION_JSON" );
22
+ if (settings == null ) {
23
+ System .err .println ("Unable to get settings." );
24
+ throw new IllegalArgumentException ("Unable to get settings" );
25
+ }
26
+
27
+ // create a descriptive instance name (can be anything)
28
+ String instanceName = ForceUnresolve .class .getSimpleName ();
29
+
30
+ // initialize the Senzing environment
31
+ SzEnvironment env = SzCoreEnvironment .newBuilder ()
32
+ .settings (settings )
33
+ .instanceName (instanceName )
34
+ .verboseLogging (false )
35
+ .build ();
36
+
37
+ try {
38
+ // get the engine from the environment
39
+ SzEngine engine = env .getEngine ();
40
+
41
+ Map <SzRecordKey , String > recordMap = getRecords ();
42
+ // loop through the example records and add them to the repository
43
+ for (Map .Entry <SzRecordKey ,String > entry : recordMap .entrySet ()) {
44
+ SzRecordKey recordKey = entry .getKey ();
45
+ String recordDefinition = entry .getValue ();
46
+
47
+ // call the addRecord() function with no flags
48
+ engine .addRecord (recordKey , recordDefinition , SZ_NO_FLAGS );
49
+
50
+ System .out .println ("Record " + recordKey .recordId () + " added" );
51
+ System .out .flush ();
52
+ }
53
+
54
+ System .out .println ();
55
+ for (SzRecordKey recordKey : recordMap .keySet ()) {
56
+ String result = engine .getEntity (recordKey , SZ_ENTITY_BRIEF_DEFAULT_FLAGS );
57
+ JsonObject jsonObj = Json .createReader (new StringReader (result )).readObject ();
58
+ long entityId = jsonObj .getJsonObject ("RESOLVED_ENTITY" )
59
+ .getJsonNumber ("ENTITY_ID" ).longValue ();
60
+ System .out .println (
61
+ "Record " + recordKey + " originally resolves to entity " + entityId );
62
+ }
63
+ System .out .println ();
64
+ System .out .println ("Updating records with TRUSTED_ID_NUMBER to force unresolve..." );
65
+ SzRecordKey key4 = SzRecordKey .of (TEST , "4" );
66
+ SzRecordKey key6 = SzRecordKey .of (TEST , "6" );
67
+
68
+ String record4 = engine .getRecord (key4 , SZ_RECORD_DEFAULT_FLAGS );
69
+ String record6 = engine .getRecord (key6 , SZ_RECORD_DEFAULT_FLAGS );
70
+
71
+ JsonObject obj4 = Json .createReader (new StringReader (record4 )).readObject ();
72
+ JsonObject obj6 = Json .createReader (new StringReader (record6 )).readObject ();
73
+
74
+ obj4 = obj4 .getJsonObject ("JSON_DATA" );
75
+ obj6 = obj6 .getJsonObject ("JSON_DATA" );
76
+
77
+ JsonObjectBuilder job4 = Json .createObjectBuilder (obj4 );
78
+ JsonObjectBuilder job6 = Json .createObjectBuilder (obj6 );
79
+
80
+ job4 .add ("TRUSTED_ID_NUMBER" , "TEST_R4-TEST_R6" );
81
+ job4 .add ("TRUSTED_ID_TYPE" , "FORCE_UNRESOLVE" );
82
+
83
+ job6 .add ("TRUSTED_ID_NUMBER" , "TEST_R6-TEST_R4" );
84
+ job6 .add ("TRUSTED_ID_TYPE" , "FORCE_UNRESOLVE" );
85
+
86
+ record4 = job4 .build ().toString ();
87
+ record6 = job6 .build ().toString ();
88
+
89
+ engine .addRecord (key4 , record4 , SZ_NO_FLAGS );
90
+ engine .addRecord (key6 , record6 , SZ_NO_FLAGS );
91
+
92
+ System .out .println ();
93
+ for (SzRecordKey recordKey : recordMap .keySet ()) {
94
+ String result = engine .getEntity (recordKey , SZ_ENTITY_BRIEF_DEFAULT_FLAGS );
95
+ JsonObject jsonObj = Json .createReader (new StringReader (result )).readObject ();
96
+ long entityId = jsonObj .getJsonObject ("RESOLVED_ENTITY" )
97
+ .getJsonNumber ("ENTITY_ID" ).longValue ();
98
+ System .out .println (
99
+ "Record " + recordKey + " now resolves to entity " + entityId );
100
+ }
101
+ System .out .println ();
102
+
103
+ } catch (SzException e ) {
104
+ // handle any exception that may have occurred
105
+ System .err .println ("Senzing Error Message : " + e .getMessage ());
106
+ System .err .println ("Senzing Error Code : " + e .getErrorCode ());
107
+ e .printStackTrace ();
108
+ throw new RuntimeException (e );
109
+
110
+ } catch (Exception e ) {
111
+ e .printStackTrace ();
112
+ if (e instanceof RuntimeException ) {
113
+ throw ((RuntimeException ) e );
114
+ }
115
+ throw new RuntimeException (e );
116
+
117
+ } finally {
118
+ // IMPORTANT: make sure to destroy the environment
119
+ env .destroy ();
120
+ }
121
+
122
+ }
123
+
124
+ /**
125
+ * This is a support method for providing example records to add.
126
+ *
127
+ * @return A {@link Map} of {@link SzRecordKey} keys to {@link String}
128
+ * JSON text values desribing the records to be added.
129
+ */
130
+ public static Map <SzRecordKey , String > getRecords () {
131
+ Map <SzRecordKey , String > records = new LinkedHashMap <>();
132
+ records .put (
133
+ SzRecordKey .of ("TEST" , "4" ),
134
+ """
135
+ {
136
+ "DATA_SOURCE": "TEST",
137
+ "RECORD_ID": "4",
138
+ "PRIMARY_NAME_FULL": "Elizabeth Jonas",
139
+ "ADDR_FULL": "202 Rotary Dr, Rotorville, RI, 78720",
140
+ "SSN_NUMBER": "767-87-7678",
141
+ "DATE_OF_BIRTH": "1/12/1990"
142
+ }
143
+ """ );
144
+
145
+ records .put (
146
+ SzRecordKey .of ("TEST" , "5" ),
147
+ """
148
+ {
149
+ "DATA_SOURCE": "TEST",
150
+ "RECORD_ID": "5",
151
+ "PRIMARY_NAME_FULL": "Beth Jones",
152
+ "ADDR_FULL": "202 Rotary Dr, Rotorville, RI, 78720",
153
+ "SSN_NUMBER": "767-87-7678",
154
+ "DATE_OF_BIRTH": "1/12/1990"
155
+ }
156
+ """ );
157
+
158
+ records .put (
159
+ SzRecordKey .of ("TEST" , "6" ),
160
+ """
161
+ {
162
+ "DATA_SOURCE": "TEST",
163
+ "RECORD_ID": "6",
164
+ "PRIMARY_NAME_FULL": "Betsey Jones",
165
+ "ADDR_FULL": "202 Rotary Dr, Rotorville, RI, 78720",
166
+ "PHONE_NUMBER": "202-787-7678"
167
+ }
168
+ """ );
169
+
170
+ return records ;
171
+ }
172
+ }
0 commit comments