1+ package org .databunker .examples ;
2+
3+ import org .databunker .DatabunkerproApi ;
4+ import org .databunker .options .BasicOptions ;
5+ import org .databunker .options .UserOptions ;
6+ import org .databunker .options .SharedRecordOptions ;
7+ import org .databunker .options .LegalBasisOptions ;
8+ import org .databunker .options .AgreementAcceptOptions ;
9+ import org .databunker .options .ConnectorOptions ;
10+ import org .databunker .options .TenantOptions ;
11+ import org .databunker .options .ProcessingActivityOptions ;
12+ import org .databunker .options .GroupOptions ;
13+ import org .databunker .options .RoleOptions ;
14+ import org .databunker .options .TokenOptions ;
15+ import org .databunker .options .PolicyOptions ;
16+
17+ import java .io .IOException ;
18+ import java .util .HashMap ;
19+ import java .util .Map ;
20+
21+ /**
22+ * Example demonstrating the use of typed options in the DatabunkerPro Java client
23+ */
24+ public class TypedOptionsExample {
25+
26+ public static void main (String [] args ) {
27+ // Initialize the API client
28+ String apiUrl = "https://pro.databunker.org" ;
29+ String apiToken = "your-api-token" ;
30+ String tenantName = "your-tenant-name" ;
31+
32+ try (DatabunkerproApi api = new DatabunkerproApi (apiUrl , apiToken , tenantName )) {
33+
34+ // Example 1: Create a user with typed UserOptions
35+ Map <String , Object > profile = new HashMap <>();
36+ profile .put ("email" , "user@example.com" );
37+ profile .put ("name" , "John Doe" );
38+ profile .put ("phone" , "+1234567890" );
39+
40+ UserOptions userOptions = UserOptions .builder ()
41+ .groupname ("premium" )
42+ .rolename ("user" )
43+ .finaltime ("100d" )
44+ .slidingtime ("30d" )
45+ .build ();
46+
47+ Map <String , Object > result = api .createUser (profile , userOptions , null );
48+ System .out .println ("Created user with token: " + result .get ("token" ));
49+
50+ // Example 2: Create an access token with typed BasicOptions
51+ BasicOptions tokenOptions = BasicOptions .builder ()
52+ .finaltime ("24h" )
53+ .slidingtime ("1h" )
54+ .build ();
55+
56+ Map <String , Object > tokenResult = api .createUserXToken ("email" , "user@example.com" , tokenOptions , null );
57+ System .out .println ("Created access token: " + tokenResult .get ("token" ));
58+
59+ // Example 3: Create a shared record with typed SharedRecordOptions
60+ SharedRecordOptions sharedOptions = SharedRecordOptions .builder ()
61+ .fields ("name,email" )
62+ .partner ("partner-org" )
63+ .appname ("myapp" )
64+ .finaltime ("7d" )
65+ .build ();
66+
67+ Map <String , Object > sharedResult = api .createSharedRecord ("email" , "user@example.com" , sharedOptions , null );
68+ System .out .println ("Created shared record: " + sharedResult .get ("recorduuid" ));
69+
70+ // Example 4: Create a role access token with typed BasicOptions
71+ BasicOptions roleTokenOptions = BasicOptions .builder ()
72+ .finaltime ("7d" )
73+ .slidingtime ("1d" )
74+ .build ();
75+
76+ Map <String , Object > roleTokenResult = api .createRoleXToken ("admin" , roleTokenOptions , null );
77+ System .out .println ("Created role access token: " + roleTokenResult .get ("token" ));
78+
79+ // Example 5: Create legal basis with typed LegalBasisOptions
80+ LegalBasisOptions legalBasisOptions = LegalBasisOptions .builder ()
81+ .brief ("marketing-consent" )
82+ .status ("active" )
83+ .module ("marketing" )
84+ .fulldesc ("Consent for marketing communications" )
85+ .shortdesc ("Marketing consent" )
86+ .basistype ("consent" )
87+ .requiredmsg ("You must accept marketing communications" )
88+ .requiredflag (true )
89+ .build ();
90+
91+ Map <String , Object > legalBasis = api .createLegalBasis (legalBasisOptions , null );
92+ System .out .println ("Created legal basis: " + legalBasis .get ("brief" ));
93+
94+ // Example 6: Accept agreement with typed AgreementAcceptOptions
95+ AgreementAcceptOptions agreementOptions = AgreementAcceptOptions .builder ()
96+ .agreementmethod ("web-form" )
97+ .referencecode ("REF123" )
98+ .starttime ("10d" )
99+ .finaltime ("100d" )
100+ .status ("active" )
101+ .lastmodifiedby ("admin@company.com" )
102+ .build ();
103+
104+ Map <String , Object > agreement = api .acceptAgreement ("email" , "user@example.com" , "marketing-consent" , agreementOptions , null );
105+ System .out .println ("Accepted agreement: " + agreement .get ("status" ));
106+
107+ // Example 7: Create connector with typed ConnectorOptions
108+ ConnectorOptions connectorOptions = ConnectorOptions .builder ()
109+ .connectorname ("my-connector" )
110+ .connectortype ("mysql" )
111+ .apikey ("api-key-123" )
112+ .username ("dbuser" )
113+ .connectordesc ("MySQL database connector" )
114+ .dbhost ("localhost" )
115+ .dbport (3306 )
116+ .dbname ("mydb" )
117+ .tablename ("users" )
118+ .status ("active" )
119+ .build ();
120+
121+ Map <String , Object > connector = api .createConnector (connectorOptions , null );
122+ System .out .println ("Created connector: " + connector .get ("connectorid" ));
123+
124+ // Example 8: Create processing activity with typed ProcessingActivityOptions
125+ ProcessingActivityOptions activityOptions = ProcessingActivityOptions .builder ()
126+ .activity ("data-processing" )
127+ .title ("Data Processing Activity" )
128+ .script ("process_data.js" )
129+ .fulldesc ("Process user data for analytics" )
130+ .applicableto ("users" )
131+ .build ();
132+
133+ Map <String , Object > activity = api .createProcessingActivity (activityOptions , null );
134+ System .out .println ("Created processing activity: " + activity .get ("activity" ));
135+
136+ // Example 9: Create group with typed GroupOptions
137+ GroupOptions groupOptions = GroupOptions .builder ()
138+ .groupname ("premium-users" )
139+ .grouptype ("user-group" )
140+ .groupdesc ("Premium user group" )
141+ .build ();
142+
143+ Map <String , Object > group = api .createGroup (groupOptions , null );
144+ System .out .println ("Created group: " + group .get ("groupid" ));
145+
146+ // Example 10: Create role with typed RoleOptions
147+ RoleOptions roleOptions = RoleOptions .builder ()
148+ .rolename ("admin" )
149+ .roledesc ("Administrator role" )
150+ .build ();
151+
152+ Map <String , Object > role = api .createRole (roleOptions , null );
153+ System .out .println ("Created role: " + role .get ("roleid" ));
154+
155+ // Example 11: Create token with typed TokenOptions
156+ TokenOptions tokenCreateOptions = TokenOptions .builder ()
157+ .unique (true )
158+ .slidingtime ("1h" )
159+ .finaltime ("24h" )
160+ .build ();
161+
162+ Map <String , Object > token = api .createToken ("credit-card" , "4111111111111111" , tokenCreateOptions , null );
163+ System .out .println ("Created token: " + token .get ("token" ));
164+
165+ // Example 12: Create policy with typed PolicyOptions
166+ Map <String , Object > policyData = new HashMap <>();
167+ policyData .put ("retention_days" , 365 );
168+ policyData .put ("auto_delete" , true );
169+
170+ PolicyOptions policyOptions = PolicyOptions .builder ()
171+ .policyname ("data-retention" )
172+ .policydesc ("Data retention policy" )
173+ .policy (policyData )
174+ .build ();
175+
176+ Map <String , Object > policy = api .createPolicy (policyOptions , null );
177+ System .out .println ("Created policy: " + policy .get ("policyid" ));
178+
179+ // Example 13: Create tenant with typed TenantOptions
180+ TenantOptions tenantOptions = TenantOptions .builder ()
181+ .tenantname ("my-tenant" )
182+ .tenantorg ("My Organization" )
183+ .email ("admin@myorg.com" )
184+ .build ();
185+
186+ Map <String , Object > tenant = api .createTenant (tenantOptions , null );
187+ System .out .println ("Created tenant: " + tenant .get ("tenantid" ));
188+
189+ } catch (IOException e ) {
190+ System .err .println ("Error: " + e .getMessage ());
191+ }
192+ }
193+ }
0 commit comments