Skip to content

Commit 5a9ad81

Browse files
author
Philipp Hofmann
committed
Allow headline testing as well
1 parent 1de1f70 commit 5a9ad81

File tree

8 files changed

+441
-36
lines changed

8 files changed

+441
-36
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>de.blacktri</groupId>
77
<artifactId>rest-api</artifactId>
8-
<version>1.0-SNAPSHOT</version>
8+
<version>1.3-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<properties>

src/main/java/de/blacktri/restapi/ABTest.java

+158-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import de.blacktri.restapi.pojos.Condition;
66
import de.blacktri.restapi.pojos.DataSet;
77
import de.blacktri.restapi.pojos.Decision;
8+
import de.blacktri.restapi.pojos.DecisionGroup;
89
import de.blacktri.restapi.pojos.Goal;
910
import de.blacktri.restapi.pojos.Project;
1011
import de.blacktri.restapi.pojos.Rule;
@@ -45,6 +46,8 @@ public class ABTest {
4546
public static final String GOAL = "/goal/";
4647
public static final String RULE = "/rule/";
4748
public static final String CONDITION = "/condition/";
49+
public static final String DECISIONGROUPS = "/decisiongroups";
50+
public static final String DECISIONGROUP = "/decisiongroup/";
4851
private ABTestingRestConnector restConnector;
4952
private String apiKey;
5053
private String apiSecret;
@@ -112,7 +115,7 @@ public Account getAccount(int clientId) {
112115
* If the user is a client, returns the projects that has been created himself.
113116
* <p/>
114117
* 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).
116119
* <p/>
117120
* The result list can be sorted by providing the qualifier sort with one of the project attributes.
118121
* 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) {
278281
}
279282

280283

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+
281409
/**
282410
* Returns a list of decisions for the given project
283411
* <p/>
@@ -293,15 +421,19 @@ public Object stopAutopilot(int clientId, int projectId) {
293421
* @param filter - URL parameters to filter results ( name=MyVariatn )
294422
* @return Object Containing the list of decisions with their respective details for the given project
295423
*/
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) {
297425
Map<String, Object> queryParameters = new HashMap<>();
298426
if (StringUtils.hasText(sort)) {
299427
queryParameters.put("sort", sort);
300428
}
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>>() {
302430
}, queryParameters, null);
303431
}
304432

433+
public List<Decision> getDecisions(int clientId, int projectId, String sort, String filter) {
434+
return getDecisions(clientId, projectId, -1, sort, filter);
435+
}
436+
305437
/**
306438
* Returns all data given a decision id
307439
* <p/>
@@ -313,11 +445,15 @@ public List<Decision> getDecisions(int clientId, int projectId, String sort, Str
313445
* @param decisionId the id of the decision
314446
* @return Object Containing all details for the specified decision for the given project
315447
*/
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>() {
318450
}, null);
319451
}
320452

453+
public int getDecision(int clientId, int projectId, Decision decision) {
454+
return createDecision(clientId, projectId, -1, decision);
455+
}
456+
321457
/**
322458
* Creates a new decision which will be associated with the given project
323459
*
@@ -326,11 +462,15 @@ public Decision getDecision(int clientId, int projectId, int decisionId) {
326462
* @param decision - contains each decision field to be created in the DB
327463
* @return Object Containing the new created decision id
328464
*/
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>() {
331467
}, decision.toMap());
332468
}
333469

470+
public int createDecision(int clientId, int projectId, Decision decision) {
471+
return createDecision(clientId, projectId, -1, decision);
472+
}
473+
334474
/**
335475
* Updates a decision with the data passed as parameter
336476
*
@@ -339,8 +479,12 @@ public int createDecision(int clientId, int projectId, Decision decision) {
339479
* @param decisionId The ID of the decision to be updated
340480
* @param decision - contains all required fields to be updated in the DB
341481
*/
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);
344488
}
345489

346490
/**
@@ -350,8 +494,12 @@ public void updateDecision(int clientId, int projectId, int decisionId, Decision
350494
* @param projectId The ID of the project to delete the decision for
351495
* @param decisionId The ID of the decision to be deleted
352496
*/
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+
353501
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);
355503
}
356504

357505
/**

src/main/java/de/blacktri/restapi/pojos/Decision.java

+8
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,13 @@ public String getRunpattern() {
231231
public void setRunpattern(String runpattern) {
232232
this.runpattern = runpattern;
233233
}
234+
235+
@Override
236+
public String toString() {
237+
return "Decision{" +
238+
"id=" + id +
239+
", name='" + name + '\'' +
240+
'}';
241+
}
234242
}
235243

0 commit comments

Comments
 (0)