5
5
import de .blacktri .restapi .pojos .Condition ;
6
6
import de .blacktri .restapi .pojos .DataSet ;
7
7
import de .blacktri .restapi .pojos .Decision ;
8
+ import de .blacktri .restapi .pojos .DecisionGroup ;
8
9
import de .blacktri .restapi .pojos .Goal ;
9
10
import de .blacktri .restapi .pojos .Project ;
10
11
import de .blacktri .restapi .pojos .Rule ;
@@ -45,6 +46,8 @@ public class ABTest {
45
46
public static final String GOAL = "/goal/" ;
46
47
public static final String RULE = "/rule/" ;
47
48
public static final String CONDITION = "/condition/" ;
49
+ public static final String DECISIONGROUPS = "/decisiongroups" ;
50
+ public static final String DECISIONGROUP = "/decisiongroup/" ;
48
51
private ABTestingRestConnector restConnector ;
49
52
private String apiKey ;
50
53
private String apiSecret ;
@@ -112,7 +115,7 @@ public Account getAccount(int clientId) {
112
115
* If the user is a client, returns the projects that has been created himself.
113
116
* <p/>
114
117
* Results can be searched/filtered with the following querystring qualifiers that refer to values of the
115
- * resource attributes "type" and "status" (e.g, type=SPLIT status=RUNNING).
118
+ * resource attributes "type" and "status" (e.g, type=SPLIT& status=RUNNING).
116
119
* <p/>
117
120
* The result list can be sorted by providing the qualifier sort with one of the project attributes.
118
121
* A dash can be added to the attribute to indicate descending order (e.g. sort=-createddate).
@@ -278,6 +281,131 @@ public Object stopAutopilot(int clientId, int projectId) {
278
281
}
279
282
280
283
284
+ /**
285
+ * Get a list of decision_groups that the current user has created.
286
+ * <p/>
287
+ * It can be filtered and sorted by one or more of the available fields (e.g, status=RUNNING&sort=name).
288
+ *
289
+ * @param clientId - the user account id to retrieve the data for
290
+ * @param projectId - the ID of the project that the decision group belongs to
291
+ * @param filter - "&" separated key=value pairs to filter, sort and limit results
292
+ * @return Object containig the list of created decision groups
293
+ */
294
+ public List <DecisionGroup > getDecisionGroups (int clientId , int projectId , String filter ) {
295
+ return getRestConnector ().callService (HttpMethod .GET , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUPS , new TypeReference <List <DecisionGroup >>() {
296
+ }, null );
297
+ }
298
+
299
+ /**
300
+ * Returns all data given a project id and a group decision id
301
+ * <p/>
302
+ * Receives a project ID and a decision group id as parameters and returns a JSON object with
303
+ * all of the decision group data
304
+ *
305
+ * @param clientId - the user account id to retrieve the data for
306
+ * @param projectId - the ID of the project that the decision group belongs to
307
+ * @param decisionGroupId - the decision group id
308
+ * @return Object Containing the details for the specified project
309
+ */
310
+ public DecisionGroup getDecisionGroup (int clientId , int projectId , int decisionGroupId ) {
311
+ return getRestConnector ().callService (HttpMethod .GET , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUP + decisionGroupId , new TypeReference <DecisionGroup >() {
312
+ }, null );
313
+ }
314
+
315
+ /**
316
+ * Creates a new decision group
317
+ * <p/>
318
+ * Users can create decision groups by calling this method with a project ID and an array containing
319
+ * all required data for the decision group (name)
320
+ *
321
+ * @param clientId - the user account id to retrieve the data for
322
+ * @param projectId - the ID of the project that the decision group belongs to
323
+ * @param decisionGroup - containing mandatory fields ( array(name => 'groupname'); )
324
+ * @return The new decision group ID
325
+ */
326
+ public Integer createDecisionGroup (int clientId , int projectId , DecisionGroup decisionGroup ) {
327
+ return getRestConnector ().callService (HttpMethod .POST , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUP , new TypeReference <Integer >() {
328
+ }, decisionGroup .toMap ());
329
+ }
330
+
331
+ /**
332
+ * Updates a decision group data
333
+ * <p/>
334
+ * Users can create decision groups by calling this method with a project ID and an array containing
335
+ * all required data for the decision group (name)
336
+ *
337
+ * @param clientId - the user account id to retrieve the data for
338
+ * @param projectId - the ID of the project that the decision group belongs to
339
+ * @param decisionGroup - containing mandatory fields ( array(name => 'groupname'); )
340
+ * @return The new decision group ID
341
+ */
342
+ public Object updateDecisionGroup (int clientId , int projectId , int decisionGroupId , DecisionGroup decisionGroup ) {
343
+ return getRestConnector ().callService (HttpMethod .PUT , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUP + decisionGroupId , null , decisionGroup .toMap ());
344
+ }
345
+
346
+ /**
347
+ * Deletes a decision group given a project and a decision group ID
348
+ *
349
+ * @param clientId - the user account id to retrieve the data for
350
+ * @param projectId - the ID of the project that the decision group belongs to
351
+ * @param decisionGroupId The ID of the decision group to be deleted
352
+ * @return Object Containing the response from the server after trying to delete the given decision
353
+ */
354
+ public Object deleteDecisionGroup (int clientId , int projectId , int decisionGroupId ) {
355
+ return getRestConnector ().callService (HttpMethod .DELETE , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUP + decisionGroupId , null , null );
356
+ }
357
+
358
+ /**
359
+ * given a project ID and a decision group ID, starts the group by updating the necessary fields in the DB
360
+ * (like setting the status to "RUNNING")
361
+ *
362
+ * @param clientId - the user account id to retrieve the data for
363
+ * @param projectId - the ID of the project that the decision group belongs to
364
+ * @param decisionGroupId - The ID of the decision group to be started
365
+ * @return Object Containing the response from the server after trying to start the group
366
+ */
367
+ public Object startDecisionGroup (int clientId , int projectId , int decisionGroupId ) {
368
+ return getRestConnector ().callService (HttpMethod .POST , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUP + decisionGroupId + START , new TypeReference <Boolean >() {
369
+ }, null );
370
+ }
371
+
372
+ /**
373
+ * given a project ID and a decision group ID, stops the group by updating the necessary fields in the DB
374
+ * (like setting the status to "PAUSED")
375
+ *
376
+ * @param clientId - the user account id to retrieve the data for
377
+ * @param projectId - the ID of the project that the decision group belongs to
378
+ * @param decisionGroupId - The ID of the decision group to be paused
379
+ * @return Object Containing the response from the server after trying to stop the group
380
+ */
381
+ public Object stopDecisionGroup (int clientId , int projectId , int decisionGroupId ) {
382
+ return getRestConnector ().callService (HttpMethod .POST , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUP + decisionGroupId + STOP , new TypeReference <Boolean >() {
383
+ }, null );
384
+ }
385
+
386
+ /**
387
+ * given a project ID and a decision group ID, restarts the group by updating the necessary fields in the DB.
388
+ *
389
+ * @param clientId - the user account id to retrieve the data for
390
+ * @param projectId - the ID of the project that the decision group belongs to
391
+ * @param decisionGroupId - The ID of the decision group to be restarted
392
+ * @return Object Containing the response from the server after trying to restart the group
393
+ */
394
+ public Object restartDecisionGroup (int clientId , int projectId , int decisionGroupId ) {
395
+ return getRestConnector ().callService (HttpMethod .POST , ACCOUNT + clientId + PROJECT + projectId + DECISIONGROUP + decisionGroupId + RESTART , new TypeReference <Boolean >() {
396
+ }, null );
397
+ }
398
+
399
+
400
+ private String getDecisionBasePath (int clientId , int projectId , int decisionsGroupId ) {
401
+ String path = ACCOUNT + clientId + PROJECT + projectId ;
402
+ if (decisionsGroupId != -1 ) {
403
+ path += DECISIONGROUP + decisionsGroupId ;
404
+ }
405
+ return path ;
406
+ }
407
+
408
+
281
409
/**
282
410
* Returns a list of decisions for the given project
283
411
* <p/>
@@ -293,15 +421,19 @@ public Object stopAutopilot(int clientId, int projectId) {
293
421
* @param filter - URL parameters to filter results ( name=MyVariatn )
294
422
* @return Object Containing the list of decisions with their respective details for the given project
295
423
*/
296
- public List <Decision > getDecisions (int clientId , int projectId , String sort , String filter ) {
424
+ public List <Decision > getDecisions (int clientId , int projectId , int decisionGroupId , String sort , String filter ) {
297
425
Map <String , Object > queryParameters = new HashMap <>();
298
426
if (StringUtils .hasText (sort )) {
299
427
queryParameters .put ("sort" , sort );
300
428
}
301
- return getRestConnector ().callService (HttpMethod .GET , ACCOUNT + clientId + PROJECT + projectId + DECISIONS , new TypeReference <List <Decision >>() {
429
+ return getRestConnector ().callService (HttpMethod .GET , getDecisionBasePath ( clientId , projectId , decisionGroupId ) + DECISIONS , new TypeReference <List <Decision >>() {
302
430
}, queryParameters , null );
303
431
}
304
432
433
+ public List <Decision > getDecisions (int clientId , int projectId , String sort , String filter ) {
434
+ return getDecisions (clientId , projectId , -1 , sort , filter );
435
+ }
436
+
305
437
/**
306
438
* Returns all data given a decision id
307
439
* <p/>
@@ -313,11 +445,15 @@ public List<Decision> getDecisions(int clientId, int projectId, String sort, Str
313
445
* @param decisionId the id of the decision
314
446
* @return Object Containing all details for the specified decision for the given project
315
447
*/
316
- public Decision getDecision (int clientId , int projectId , int decisionId ) {
317
- return getRestConnector ().callService (HttpMethod .GET , ACCOUNT + clientId + PROJECT + projectId + DECISION + decisionId , new TypeReference <Decision >() {
448
+ public Decision getDecision (int clientId , int projectId , int decisionGroupId , int decisionId ) {
449
+ return getRestConnector ().callService (HttpMethod .GET , getDecisionBasePath ( clientId , projectId , decisionGroupId ) + DECISION + decisionId , new TypeReference <Decision >() {
318
450
}, null );
319
451
}
320
452
453
+ public int getDecision (int clientId , int projectId , Decision decision ) {
454
+ return createDecision (clientId , projectId , -1 , decision );
455
+ }
456
+
321
457
/**
322
458
* Creates a new decision which will be associated with the given project
323
459
*
@@ -326,11 +462,15 @@ public Decision getDecision(int clientId, int projectId, int decisionId) {
326
462
* @param decision - contains each decision field to be created in the DB
327
463
* @return Object Containing the new created decision id
328
464
*/
329
- public int createDecision (int clientId , int projectId , Decision decision ) {
330
- return getRestConnector ().callService (HttpMethod .POST , ACCOUNT + clientId + PROJECT + projectId + "/decision" , new TypeReference <Integer >() {
465
+ public int createDecision (int clientId , int projectId , int decisionGroupId , Decision decision ) {
466
+ return getRestConnector ().callService (HttpMethod .POST , getDecisionBasePath ( clientId , projectId , decisionGroupId ) + "/decision" , new TypeReference <Integer >() {
331
467
}, decision .toMap ());
332
468
}
333
469
470
+ public int createDecision (int clientId , int projectId , Decision decision ) {
471
+ return createDecision (clientId , projectId , -1 , decision );
472
+ }
473
+
334
474
/**
335
475
* Updates a decision with the data passed as parameter
336
476
*
@@ -339,8 +479,12 @@ public int createDecision(int clientId, int projectId, Decision decision) {
339
479
* @param decisionId The ID of the decision to be updated
340
480
* @param decision - contains all required fields to be updated in the DB
341
481
*/
342
- public void updateDecision (int clientId , int projectId , int decisionId , Decision decision ) {
343
- getRestConnector ().callService (HttpMethod .PUT , ACCOUNT + clientId + PROJECT + projectId + DECISION + decisionId , null , decision .toMap ());
482
+ public void updateDecision (int clientId , int projectId , int decisionId , int decisionGroupId , Decision decision ) {
483
+ getRestConnector ().callService (HttpMethod .PUT , ACCOUNT + getDecisionBasePath (clientId , projectId , decisionGroupId ) + DECISION + decisionId , null , decision .toMap ());
484
+ }
485
+
486
+ public void updateDecision (int clientId , int projectId , int decisionGroupId , Decision decision ) {
487
+ updateDecision (clientId , projectId , -1 , decisionGroupId , decision );
344
488
}
345
489
346
490
/**
@@ -350,8 +494,12 @@ public void updateDecision(int clientId, int projectId, int decisionId, Decision
350
494
* @param projectId The ID of the project to delete the decision for
351
495
* @param decisionId The ID of the decision to be deleted
352
496
*/
497
+ public void deleteDecision (int clientId , int projectId , int decisionGroupId , int decisionId ) {
498
+ getRestConnector ().callService (HttpMethod .DELETE , getDecisionBasePath (clientId , projectId , decisionGroupId ) + DECISION + decisionId , null , null );
499
+ }
500
+
353
501
public void deleteDecision (int clientId , int projectId , int decisionId ) {
354
- getRestConnector (). callService ( HttpMethod . DELETE , ACCOUNT + clientId + PROJECT + projectId + DECISION + decisionId , null , null );
502
+ deleteDecision ( clientId , projectId , - 1 , decisionId );
355
503
}
356
504
357
505
/**
0 commit comments