2323import org .databunker .options .RoleOptions ;
2424import org .databunker .options .TokenOptions ;
2525import org .databunker .options .PolicyOptions ;
26+ import org .databunker .options .PatchOperation ;
2627import org .databunker .options .OptionsConverter ;
2728
2829import java .io .IOException ;
@@ -89,7 +90,21 @@ private Map<String, Object> makeRequest(String endpoint, Map<String, Object> dat
8990 try (CloseableHttpResponse response = httpClient .execute (request )) {
9091 HttpEntity entity = response .getEntity ();
9192 String responseString = EntityUtils .toString (entity );
92- return objectMapper .readValue (responseString , Map .class );
93+ Map <String , Object > result = objectMapper .readValue (responseString , Map .class );
94+
95+ if (response .getStatusLine ().getStatusCode () < 200 || response .getStatusLine ().getStatusCode () >= 300 ) {
96+ if (result .containsKey ("status" )) {
97+ return result ;
98+ } else {
99+ throw new IOException (result .containsKey ("message" ) ?
100+ (String ) result .get ("message" ) : "API request failed" );
101+ }
102+ }
103+
104+ return result ;
105+ } catch (Exception error ) {
106+ System .err .println ("Error making request: " + error .getMessage ());
107+ throw new IOException ("API request failed" , error );
93108 }
94109 }
95110
@@ -125,6 +140,9 @@ private byte[] rawRequest(String endpoint, Map<String, Object> data, Map<String,
125140 try (CloseableHttpResponse response = httpClient .execute (request )) {
126141 HttpEntity entity = response .getEntity ();
127142 return EntityUtils .toByteArray (entity );
143+ } catch (Exception error ) {
144+ System .err .println ("Error making raw request: " + error .getMessage ());
145+ throw new IOException ("Raw API request failed" , error );
128146 }
129147 }
130148
@@ -217,6 +235,24 @@ public Map<String, Object> patchUser(String mode, String identity, Map<String, O
217235 return makeRequest ("UserPatch" , data , requestMetadata );
218236 }
219237
238+ /**
239+ * Patches a user with typed patch operations
240+ *
241+ * @param mode User identification mode
242+ * @param identity User's identifier
243+ * @param patch Array of patch operations
244+ * @param requestMetadata Optional request metadata
245+ * @return The patched user information
246+ * @throws IOException If an I/O error occurs
247+ */
248+ public Map <String , Object > patchUser (String mode , String identity , PatchOperation [] patch , Map <String , Object > requestMetadata ) throws IOException {
249+ Map <String , Object > data = new HashMap <>();
250+ data .put ("mode" , mode );
251+ data .put ("identity" , identity );
252+ data .put ("patch" , patch );
253+ return makeRequest ("UserPatch" , data , requestMetadata );
254+ }
255+
220256 public Map <String , Object > requestUserUpdate (String mode , String identity , Map <String , Object > profile , Map <String , Object > requestMetadata ) throws IOException {
221257 Map <String , Object > data = new HashMap <>();
222258 data .put ("mode" , mode );
@@ -233,6 +269,24 @@ public Map<String, Object> requestUserPatch(String mode, String identity, Map<St
233269 return makeRequest ("UserPatchRequest" , data , requestMetadata );
234270 }
235271
272+ /**
273+ * Requests a user patch with typed patch operations
274+ *
275+ * @param mode User identification mode
276+ * @param identity User's identifier
277+ * @param patch Array of patch operations
278+ * @param requestMetadata Optional request metadata
279+ * @return The patch request result
280+ * @throws IOException If an I/O error occurs
281+ */
282+ public Map <String , Object > requestUserPatch (String mode , String identity , PatchOperation [] patch , Map <String , Object > requestMetadata ) throws IOException {
283+ Map <String , Object > data = new HashMap <>();
284+ data .put ("mode" , mode );
285+ data .put ("identity" , identity );
286+ data .put ("patch" , patch );
287+ return makeRequest ("UserPatchRequest" , data , requestMetadata );
288+ }
289+
236290 public Map <String , Object > deleteUser (String mode , String identity , Map <String , Object > requestMetadata ) throws IOException {
237291 Map <String , Object > data = new HashMap <>();
238292 data .put ("mode" , mode );
@@ -485,6 +539,8 @@ public Map<String, Object> updateLegalBasis(String brief, LegalBasisOptions opti
485539 return makeRequest ("LegalBasisUpdate" , data , requestMetadata );
486540 }
487541
542+
543+
488544 public Map <String , Object > deleteLegalBasis (String brief , Map <String , Object > requestMetadata ) throws IOException {
489545 Map <String , Object > data = new HashMap <>();
490546 data .put ("brief" , brief );
@@ -616,6 +672,8 @@ public Map<String, Object> updateProcessingActivity(String activity, ProcessingA
616672 return makeRequest ("ProcessingActivityUpdate" , data , requestMetadata );
617673 }
618674
675+
676+
619677 public Map <String , Object > deleteProcessingActivity (String activity , Map <String , Object > requestMetadata ) throws IOException {
620678 Map <String , Object > data = new HashMap <>();
621679 data .put ("activity" , activity );
@@ -940,7 +998,7 @@ public Map<String, Object> createToken(String tokentype, String record, Map<Stri
940998 * @return The created tokens information
941999 * @throws IOException If an I/O error occurs
9421000 */
943- public Map <String , Object > createTokensBulk (Map <String , String >[] records , TokenOptions options , Map <String , Object > requestMetadata ) throws IOException {
1001+ public Map <String , Object > createTokensBulk (Map <String , Object >[] records , TokenOptions options , Map <String , Object > requestMetadata ) throws IOException {
9441002 Map <String , Object > data = new HashMap <>();
9451003 data .put ("records" , records );
9461004 if (options != null ) {
@@ -957,7 +1015,7 @@ public Map<String, Object> createTokensBulk(Map<String, String>[] records, Token
9571015 * @return The created tokens information
9581016 * @throws IOException If an I/O error occurs
9591017 */
960- public Map <String , Object > createTokensBulk (Map <String , String >[] records , Map <String , Object > requestMetadata ) throws IOException {
1018+ public Map <String , Object > createTokensBulk (Map <String , Object >[] records , Map <String , Object > requestMetadata ) throws IOException {
9611019 return createTokensBulk (records , null , requestMetadata );
9621020 }
9631021
@@ -1152,6 +1210,8 @@ public Map<String, Object> updatePolicy(String policyid, PolicyOptions options,
11521210 return makeRequest ("PolicyUpdate" , data , requestMetadata );
11531211 }
11541212
1213+
1214+
11551215 public Map <String , Object > getPolicy (String policyref , Map <String , Object > requestMetadata ) throws IOException {
11561216 Map <String , Object > data = new HashMap <>();
11571217 if (policyref != null ) {
@@ -1353,6 +1413,24 @@ public Map<String, Object> getSystemStats(Map<String, Object> requestMetadata) t
13531413 return makeRequest ("SystemGetSystemStats" , null , requestMetadata );
13541414 }
13551415
1416+ /**
1417+ * Generates a wrapping key from three Shamir's Secret Sharing keys
1418+ *
1419+ * @param key1 First Shamir secret sharing key
1420+ * @param key2 Second Shamir secret sharing key
1421+ * @param key3 Third Shamir secret sharing key
1422+ * @param requestMetadata Optional request metadata
1423+ * @return Generated wrapping key
1424+ * @throws IOException If an I/O error occurs
1425+ */
1426+ public Map <String , Object > generateWrappingKey (String key1 , String key2 , String key3 , Map <String , Object > requestMetadata ) throws IOException {
1427+ Map <String , Object > data = new HashMap <>();
1428+ data .put ("key1" , key1 );
1429+ data .put ("key2" , key2 );
1430+ data .put ("key3" , key3 );
1431+ return makeRequest ("SystemGenerateWrappingKey" , data , requestMetadata );
1432+ }
1433+
13561434 public Map <String , Object > getSystemMetrics (Map <String , Object > requestMetadata ) throws IOException {
13571435 String url = baseURL + "/metrics" ;
13581436 HttpGet request = new HttpGet (url );
0 commit comments