-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java-sdk)!: support server-side batch check endpoint (#475)
- Loading branch information
Showing
15 changed files
with
657 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
config/clients/java/template/client-ClientBatchCheckClientResponse.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{{>licenseInfo}} | ||
package {{clientPackage}}.model; | ||
|
||
import {{modelPackage}}.CheckResponse; | ||
import {{errorsPackage}}.FgaError; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.BiFunction; | ||
|
||
public class ClientBatchCheckClientResponse extends CheckResponse { | ||
private final ClientCheckRequest request; | ||
private final Throwable throwable; | ||
private final Integer statusCode; | ||
private final Map<String, List<String>> headers; | ||
private final String rawResponse; | ||
public ClientBatchCheckClientResponse( | ||
ClientCheckRequest request, ClientCheckResponse clientCheckResponse, Throwable throwable) { | ||
this.request = request; | ||
this.throwable = throwable; | ||
if (clientCheckResponse != null) { | ||
this.statusCode = clientCheckResponse.getStatusCode(); | ||
this.headers = clientCheckResponse.getHeaders(); | ||
this.rawResponse = clientCheckResponse.getRawResponse(); | ||
this.setAllowed(clientCheckResponse.getAllowed()); | ||
this.setResolution(clientCheckResponse.getResolution()); | ||
} else if (throwable instanceof FgaError) { | ||
FgaError error = (FgaError) throwable; | ||
this.statusCode = error.getStatusCode(); | ||
this.headers = error.getResponseHeaders().map(); | ||
this.rawResponse = error.getResponseData(); | ||
} else { | ||
// Should be unreachable, but required for type completion | ||
this.statusCode = null; | ||
this.headers = null; | ||
this.rawResponse = null; | ||
} | ||
} | ||
|
||
public ClientCheckRequest getRequest() { | ||
return request; | ||
} | ||
|
||
/** | ||
* Returns the result of the check. | ||
* <p> | ||
* If the HTTP request was unsuccessful, this result will be null. If this is the case, you can examine the | ||
* original request with {@link ClientBatchCheckClientResponse#getRequest()} and the exception with | ||
* {@link ClientBatchCheckClientResponse#getThrowable()}. | ||
* | ||
* @return the check result. Is null if the HTTP request was unsuccessful. | ||
*/ | ||
@Override | ||
public Boolean getAllowed() { | ||
return super.getAllowed(); | ||
} | ||
|
||
/** | ||
* Returns the caught exception if the HTTP request was unsuccessful. | ||
* <p> | ||
* If the HTTP request was unsuccessful, this result will be null. If this is the case, you can examine the | ||
* original request with {@link ClientBatchCheckClientResponse#getRequest()} and the exception with | ||
* {@link ClientBatchCheckClientResponse#getThrowable()}. | ||
* | ||
* @return the caught exception. Is null if the HTTP request was successful. | ||
*/ | ||
public Throwable getThrowable() { | ||
return throwable; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public Map<String, List<String>> getHeaders() { | ||
return headers; | ||
} | ||
|
||
public String getRawResponse() { | ||
return rawResponse; | ||
} | ||
|
||
public String getRelation() { | ||
return request == null ? null : request.getRelation(); | ||
} | ||
|
||
public static BiFunction<ClientCheckResponse, Throwable, ClientBatchCheckClientResponse> asyncHandler( | ||
ClientCheckRequest request) { | ||
return (response, throwable) -> new ClientBatchCheckClientResponse(request, response, throwable); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
config/clients/java/template/client-ClientBatchCheckItem.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}.model; | ||
|
||
import java.util.List; | ||
|
||
public class ClientBatchCheckItem { | ||
private String user; | ||
private String relation; | ||
private String _object; | ||
private List<ClientTupleKey> contextualTuples; | ||
private Object context; | ||
private String correlationId; | ||
public ClientBatchCheckItem user(String user) { | ||
this.user = user; | ||
return this; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public ClientBatchCheckItem relation(String relation) { | ||
this.relation = relation; | ||
return this; | ||
} | ||
|
||
public String getRelation() { | ||
return relation; | ||
} | ||
|
||
public ClientBatchCheckItem _object(String _object) { | ||
this._object = _object; | ||
return this; | ||
} | ||
|
||
public String getObject() { | ||
return _object; | ||
} | ||
|
||
public ClientBatchCheckItem contextualTuples(List<ClientTupleKey> contextualTuples) { | ||
this.contextualTuples = contextualTuples; | ||
return this; | ||
} | ||
|
||
public List<ClientTupleKey> getContextualTuples() { | ||
return contextualTuples; | ||
} | ||
|
||
public ClientBatchCheckItem context(Object context) { | ||
this.context = context; | ||
return this; | ||
} | ||
|
||
public Object getContext() { | ||
return context; | ||
} | ||
|
||
public ClientBatchCheckItem correlationId(String correlationId) { | ||
this.correlationId = correlationId; | ||
return this; | ||
} | ||
|
||
public String getCorrelationId() { | ||
return correlationId; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
config/clients/java/template/client-ClientBatchCheckRequest.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{>licenseInfo}} | ||
package {{invokerPackage}}.model; | ||
|
||
import java.util.List; | ||
|
||
public class ClientBatchCheckRequest { | ||
private List<ClientBatchCheckItem> checks; | ||
public static ClientBatchCheckRequest ofChecks(List<ClientBatchCheckItem> checks) { | ||
return new ClientBatchCheckRequest().checks(checks); | ||
} | ||
|
||
public ClientBatchCheckRequest checks(List<ClientBatchCheckItem> checks) { | ||
this.checks = checks; | ||
return this; | ||
} | ||
|
||
public List<ClientBatchCheckItem> getChecks() { | ||
return checks; | ||
} | ||
} |
90 changes: 7 additions & 83 deletions
90
config/clients/java/template/client-ClientBatchCheckResponse.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,16 @@ | ||
{{>licenseInfo}} | ||
package {{clientPackage}}.model; | ||
|
||
import {{modelPackage}}.CheckResponse; | ||
import {{errorsPackage}}.FgaError; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.BiFunction; | ||
|
||
public class ClientBatchCheckResponse extends CheckResponse { | ||
private final ClientCheckRequest request; | ||
private final Throwable throwable; | ||
private final Integer statusCode; | ||
private final Map<String, List<String>> headers; | ||
private final String rawResponse; | ||
public class ClientBatchCheckResponse { | ||
private final List<ClientBatchCheckSingleResponse> result; | ||
public ClientBatchCheckResponse( | ||
ClientCheckRequest request, ClientCheckResponse clientCheckResponse, Throwable throwable) { | ||
this.request = request; | ||
this.throwable = throwable; | ||
if (clientCheckResponse != null) { | ||
this.statusCode = clientCheckResponse.getStatusCode(); | ||
this.headers = clientCheckResponse.getHeaders(); | ||
this.rawResponse = clientCheckResponse.getRawResponse(); | ||
this.setAllowed(clientCheckResponse.getAllowed()); | ||
this.setResolution(clientCheckResponse.getResolution()); | ||
} else if (throwable instanceof FgaError) { | ||
FgaError error = (FgaError) throwable; | ||
this.statusCode = error.getStatusCode(); | ||
this.headers = error.getResponseHeaders().map(); | ||
this.rawResponse = error.getResponseData(); | ||
} else { | ||
// Should be unreachable, but required for type completion | ||
this.statusCode = null; | ||
this.headers = null; | ||
this.rawResponse = null; | ||
} | ||
} | ||
|
||
public ClientCheckRequest getRequest() { | ||
return request; | ||
} | ||
|
||
/** | ||
* Returns the result of the check. | ||
* <p> | ||
* If the HTTP request was unsuccessful, this result will be null. If this is the case, you can examine the | ||
* original request with {@link ClientBatchCheckResponse#getRequest()} and the exception with | ||
* {@link ClientBatchCheckResponse#getThrowable()}. | ||
* | ||
* @return the check result. Is null if the HTTP request was unsuccessful. | ||
*/ | ||
@Override | ||
public Boolean getAllowed() { | ||
return super.getAllowed(); | ||
} | ||
|
||
/** | ||
* Returns the caught exception if the HTTP request was unsuccessful. | ||
* <p> | ||
* If the HTTP request was unsuccessful, this result will be null. If this is the case, you can examine the | ||
* original request with {@link ClientBatchCheckResponse#getRequest()} and the exception with | ||
* {@link ClientBatchCheckResponse#getThrowable()}. | ||
* | ||
* @return the caught exception. Is null if the HTTP request was successful. | ||
*/ | ||
public Throwable getThrowable() { | ||
return throwable; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public Map<String, List<String>> getHeaders() { | ||
return headers; | ||
} | ||
|
||
public String getRawResponse() { | ||
return rawResponse; | ||
} | ||
|
||
public String getRelation() { | ||
return request == null ? null : request.getRelation(); | ||
public ClientBatchCheckResponse(List<ClientBatchCheckSingleResponse> result) { | ||
this.result = result; | ||
} | ||
|
||
public static BiFunction<ClientCheckResponse, Throwable, ClientBatchCheckResponse> asyncHandler( | ||
ClientCheckRequest request) { | ||
return (response, throwable) -> new ClientBatchCheckResponse(request, response, throwable); | ||
public List<ClientBatchCheckSingleResponse> getResult() { | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.