Skip to content

Commit

Permalink
Add v2 api support (#38)
Browse files Browse the repository at this point in the history
* Use /v2/check instead of /v2/authorize

* Create and update classes for new list params/filters

* Add BaseWarrantObject and object crud methods

* Update resource classes to extend BaseWarrantObject

* Update warrant client methods to use objects api

* Update live and client tests

* Remove unused import

* Add object create methods that take an object

* Rename BaseListResult to BaseWarrantObjectListResult

* Remove commented out code

* Update ListResult to accept any type

* Replace objectId object filter with query

* Return warrantToken when creating or deleting warrants

* Return warrant token for object deletes

* Update all http methods to return warrant token if exists

* Fix crud objects test
  • Loading branch information
stanleyphu authored Nov 3, 2023
1 parent 26533e6 commit 0be3af5
Show file tree
Hide file tree
Showing 20 changed files with 1,456 additions and 669 deletions.
47 changes: 10 additions & 37 deletions src/main/java/dev/warrant/ListParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,27 @@
import java.util.Map;

public class ListParams {
private int page = 0;
private int limit = 0;
private String beforeId;
private String beforeValue;
private String afterId;
private String afterValue;
private String prevCursor;
private String nextCursor;
private String sortBy;
private String sortOrder;

public ListParams() {
}

public ListParams withPage(int page) {
this.page = page;
return this;
}

public ListParams withLimit(int limit) {
this.limit = limit;
return this;
}

public ListParams withBeforeId(String beforeId) {
this.beforeId = beforeId;
return this;
}

public ListParams withBeforeValue(String beforeValue) {
this.beforeValue = beforeValue;
public ListParams withPrevCursor(String prevCursor) {
this.prevCursor = prevCursor;
return this;
}

public ListParams withAfterId(String afterId) {
this.afterId = afterId;
return this;
}

public ListParams withAfterValue(String afterValue) {
this.afterValue = afterValue;
public ListParams withNextCursor(String nextCursor) {
this.nextCursor = nextCursor;
return this;
}

Expand All @@ -58,23 +40,14 @@ public ListParams withSortOrder(String sortOrder) {

public Map<String, Object> asMap() {
Map<String, Object> params = new HashMap<>();
if (this.page != 0) {
params.put("page", page);
}
if (this.limit != 0) {
params.put("limit", limit);
}
if (this.beforeId != null) {
params.put("beforeId", beforeId);
}
if (this.beforeValue != null) {
params.put("beforeValue", beforeValue);
}
if (this.afterId != null) {
params.put("afterId", afterId);
if (this.prevCursor != null) {
params.put("prevCursor", prevCursor);
}
if (this.afterValue != null) {
params.put("afterValue", afterValue);
if (this.nextCursor != null) {
params.put("nextCursor", nextCursor);
}
if (this.sortBy != null) {
params.put("sortBy", sortBy);
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/dev/warrant/ObjectFilters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.warrant;

import java.util.HashMap;
import java.util.Map;

public class ObjectFilters {

private String objectType = "";
private String query = "";

public ObjectFilters() {
}

public ObjectFilters withObjectType(String objectType) {
this.objectType = objectType;
return this;
}

public ObjectFilters withQuery(String query) {
this.query = query;
return this;
}

public Map<String, Object> asMap() {
Map<String, Object> params = new HashMap<>();
if (!this.objectType.isEmpty()) {
params.put("objectType", objectType);
}
if (!this.query.isEmpty()) {
params.put("q", query);
}
return params;
}
}
348 changes: 273 additions & 75 deletions src/main/java/dev/warrant/WarrantBaseClient.java

Large diffs are not rendered by default.

562 changes: 325 additions & 237 deletions src/main/java/dev/warrant/WarrantClient.java

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/main/java/dev/warrant/model/QueryResult.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package dev.warrant.model;

import java.util.Map;
import java.util.HashMap;

public class QueryResult {

private String objectType;
private String objectId;
private Warrant warrant;
private Boolean isImplicit;
private Map<String, Object> meta;

public QueryResult() {
// For json serialization
Expand All @@ -16,6 +20,15 @@ public QueryResult(String objectType, String objectId, Warrant warrant, Boolean
this.objectId = objectId;
this.warrant = warrant;
this.isImplicit = isImplicit;
this.meta = new HashMap<String, Object>();
}

public QueryResult(String objectType, String objectId, Warrant warrant, Boolean isImplicit, Map<String, Object> meta) {
this.objectType = objectType;
this.objectId = objectId;
this.warrant = warrant;
this.isImplicit = isImplicit;
this.meta = meta;
}

public String getObjectType() {
Expand Down Expand Up @@ -49,4 +62,12 @@ public Boolean isImplicit() {
public void setIsImplicit(Boolean isImplicit) {
this.isImplicit = isImplicit;
}

public Map<String, Object> getMeta() {
return this.meta;
}

public void setMeta(Map<String, Object> meta) {
this.meta = meta;
}
}
28 changes: 23 additions & 5 deletions src/main/java/dev/warrant/model/QueryResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@
public class QueryResultSet {

private QueryResult[] results;
private String lastId;
private String prevCursor;
private String nextCursor;

public QueryResultSet() {
// For json serialization
}

public QueryResultSet(QueryResult[] results, String lastId) {
public QueryResultSet(QueryResult[] results) {
this.results = results;
this.lastId = lastId;
}

public QueryResultSet(QueryResult[] results, String prevCursor, String nextCursor) {
this.results = results;
this.prevCursor = prevCursor;
this.nextCursor = nextCursor;
}

public QueryResult[] getResults() {
return this.results;
}

public String getLastId() {
return this.lastId;
public String getPrevCursor() {
return prevCursor;
}

public void setPrevCursor(String prevCursor) {
this.prevCursor = prevCursor;
}

public String getNextCursor() {
return nextCursor;
}

public void setNextCursor(String nextCursor) {
this.nextCursor = nextCursor;
}
}
5 changes: 5 additions & 0 deletions src/main/java/dev/warrant/model/Warrant.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Warrant {
private String relation;
private WarrantSubject subject;
private String policy;
private String warrantToken;

public Warrant() {
// For json serialization
Expand Down Expand Up @@ -66,4 +67,8 @@ public String getPolicy() {
public void setPolicy(String policy) {
this.policy = policy;
}

public String getWarrantToken() {
return warrantToken;
}
}
70 changes: 70 additions & 0 deletions src/main/java/dev/warrant/model/object/BaseWarrantObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package dev.warrant.model.object;

import java.util.Map;
import java.util.HashMap;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class BaseWarrantObject implements WarrantObject {
protected String objectType;
protected String objectId;
protected Map<String, Object> meta;

public BaseWarrantObject() {
// For json serialization
}

public BaseWarrantObject(String objectType) {
this.objectType = objectType;
this.meta = new HashMap<String, Object>();
}

public BaseWarrantObject(String objectType, String objectId) {
this.objectType = objectType;
this.objectId = objectId;
this.meta = new HashMap<String, Object>();
}

public BaseWarrantObject(String objectType, String objectId, Map<String, Object> meta) {
this.objectType = objectType;
this.objectId = objectId;
this.meta = meta;
}

public String getObjectType() {
return objectType;
}

public void setObjectType(String objectType) {
this.objectType = objectType;
}

public String getObjectId() {
return objectId;
}

public void setObjectId(String objectId) {
this.objectId = objectId;
}

public Map<String, Object> getMeta() {
return meta;
}

public void setMeta(Map<String, Object> meta) {
this.meta = meta;
}

public String id() {
return objectId;
}

public String type() {
return objectType;
}

public Map<String, Object> meta() {
return meta;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dev.warrant.model.object;

public class BaseWarrantObjectListResult {
private BaseWarrantObject[] results;
private String prevCursor;
private String nextCursor;

public BaseWarrantObjectListResult() {
// For json serialization
}

public BaseWarrantObjectListResult(BaseWarrantObject[] results) {
this.results = results;
}

public BaseWarrantObjectListResult(BaseWarrantObject[] results, String prevCursor, String nextCursor) {
this.results = results;
this.prevCursor = prevCursor;
this.nextCursor = nextCursor;
}

public BaseWarrantObject[] getResults() {
return results;
}

public void setResults(BaseWarrantObject[] results) {
this.results = results;
}

public String getPrevCursor() {
return prevCursor;
}

public void setPrevCursor(String prevCursor) {
this.prevCursor = prevCursor;
}

public String getNextCursor() {
return nextCursor;
}

public void setNextCursor(String nextCursor) {
this.nextCursor = nextCursor;
}
}
26 changes: 13 additions & 13 deletions src/main/java/dev/warrant/model/object/Feature.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package dev.warrant.model.object;

public class Feature implements WarrantObject {
static final String OBJECT_TYPE = "feature";
import java.util.Map;

private String featureId;
public class Feature extends BaseWarrantObject {
public static final String OBJECT_TYPE = "feature";

public Feature() {
// For json serialization
super();
}

public Feature(String featureId) {
this.featureId = featureId;
super(OBJECT_TYPE, featureId);
}

public Feature(String featureId, Map<String, Object> meta) {
super(OBJECT_TYPE, featureId, meta);
}

public String getFeatureId() {
return featureId;
return objectId;
}

public void setFeatureId(String featureId) {
this.featureId = featureId;
this.objectId = featureId;
}

@Override
public String id() {
return featureId;
return objectId;
}

@Override
public String type() {
return "feature";
return OBJECT_TYPE;
}

// @Override
// public Map<String, Object> meta() {
// return null;
// }
}
Loading

0 comments on commit 0be3af5

Please sign in to comment.