7272
7373 URI resource = URI.create("https://storage.example/data/resource");
7474 URI purpose = URI.create("https://purpose.example/1");
75- AccessCredentialQuery<AccessGrant> query = AccessCredentialQuery.newBuilder()
75+ CredentialFilter<AccessGrant> filter = CredentialFilter.newBuilder()
76+ .status(CredentialStatus.ACTIVE)
7677 .resource(resource)
77- .mode("Read")
7878 .purpose(purpose)
7979 .build(AccessGrant.class);
8080
81- client.query(query)
82- .thenApply(grants -> AccessGrantSession.ofAccessGrant(openid, grants.toArray(new AccessGrant[0])))
81+ client.query(filter)
82+ .thenApply(results -> AccessGrantSession.ofAccessGrant(openid,
83+ results.getItems().toArray(new AccessGrant[0])))
8384 .thenApply(session -> SolidClient.getClient().session(session))
8485 .thenAccept(cl -> {
8586 // Do something with the Access Grant-scoped client
@@ -427,29 +428,32 @@ static String getPageQueryParam(final URI uri) {
427428 <T extends AccessCredential > List <T > processFilterResponseBody (final InputStream input ,
428429 final Set <String > validTypes , final Class <T > clazz ) throws IOException {
429430
430- final List <T > items = new ArrayList <>();
431- final List <Object > data = jsonService .fromJson (input ,
432- new ArrayList <Object >(){}.getClass ().getGenericSuperclass ());
433- for (final Object item : data ) {
434- Utils .asMap (item ).ifPresent (credential ->
435- Utils .asSet (credential .get (TYPE )).ifPresent (types -> {
436- types .retainAll (validTypes );
437- if (!types .isEmpty ()) {
438- final Map <String , Object > presentation = new HashMap <>();
439- presentation .put (CONTEXT , Arrays .asList (VC_CONTEXT_URI ));
440- presentation .put (TYPE , Arrays .asList ("VerifiablePresentation" ));
441- presentation .put (VERIFIABLE_CREDENTIAL , Arrays .asList (credential ));
442- if (AccessGrant .class .equals (clazz )) {
443- items .add ((T ) AccessGrant .of (new String (serialize (presentation ), UTF_8 )));
444- } else if (AccessRequest .class .equals (clazz )) {
445- items .add ((T ) AccessRequest .of (new String (serialize (presentation ), UTF_8 )));
446- } else if (AccessDenial .class .equals (clazz )) {
447- items .add ((T ) AccessDenial .of (new String (serialize (presentation ), UTF_8 )));
431+ final List <T > page = new ArrayList <>();
432+ final Map <String , Object > data = jsonService .fromJson (input ,
433+ new HashMap <String , Object >(){}.getClass ().getGenericSuperclass ());
434+ System .out .println ("JSON: " + data );
435+ Utils .asSet (data .get ("items" )).ifPresent (items -> {
436+ for (final Object item : items ) {
437+ Utils .asMap (item ).ifPresent (credential ->
438+ Utils .asSet (credential .get (TYPE )).ifPresent (types -> {
439+ types .retainAll (validTypes );
440+ if (!types .isEmpty ()) {
441+ final Map <String , Object > presentation = new HashMap <>();
442+ presentation .put (CONTEXT , Arrays .asList (VC_CONTEXT_URI ));
443+ presentation .put (TYPE , Arrays .asList ("VerifiablePresentation" ));
444+ presentation .put (VERIFIABLE_CREDENTIAL , Arrays .asList (credential ));
445+ if (AccessGrant .class .equals (clazz )) {
446+ page .add ((T ) AccessGrant .of (new String (serialize (presentation ), UTF_8 )));
447+ } else if (AccessRequest .class .equals (clazz )) {
448+ page .add ((T ) AccessRequest .of (new String (serialize (presentation ), UTF_8 )));
449+ } else if (AccessDenial .class .equals (clazz )) {
450+ page .add ((T ) AccessDenial .of (new String (serialize (presentation ), UTF_8 )));
451+ }
448452 }
449- }
450- }));
451- }
452- return items ;
453+ }));
454+ }
455+ });
456+ return page ;
453457 }
454458
455459 /**
@@ -463,7 +467,9 @@ <T extends AccessCredential> List<T> processFilterResponseBody(final InputStream
463467 * @param mode the access mode, may be {@code null}
464468 * @param clazz the AccessCredential type, either {@link AccessGrant} or {@link AccessRequest}
465469 * @return the next stage of completion, including the matched Access Credentials
470+ * @deprecated As of 1.3, replaced by {@link #query(CredentialFilter)}
466471 */
472+ @ Deprecated
467473 public <T extends AccessCredential > CompletionStage <List <T >> query (final URI resource , final URI creator ,
468474 final URI recipient , final URI purpose , final String mode , final Class <T > clazz ) {
469475
@@ -479,7 +485,9 @@ public <T extends AccessCredential> CompletionStage<List<T>> query(final URI res
479485 * @param <T> the AccessCredential type
480486 * @param query the access credential query, never {@code null}
481487 * @return the next stage of completion, including the matched Access Credentials
488+ * @deprecated As of 1.3, replaced by {@link #query(CredentialFilter)}
482489 */
490+ @ Deprecated
483491 public <T extends AccessCredential > CompletionStage <List <T >> query (final AccessCredentialQuery <T > query ) {
484492 Objects .requireNonNull (query , "The query may not be null!" );
485493 return query (query .getResource (), query .getCreator (), query .getRecipient (), query .getPurposes (),
0 commit comments