@@ -97,6 +97,10 @@ public class AccessGrantClient {
9797 private static final String FOR_PERSONAL_DATA = "forPersonalData" ;
9898 private static final String HAS_STATUS = "hasStatus" ;
9999 private static final String MODE = "mode" ;
100+ private static final String PROVIDED_CONSENT = "providedConsent" ;
101+ private static final String FOR_PURPOSE = "forPurpose" ;
102+ private static final String EXPIRATION_DATE = "expirationDate" ;
103+ private static final String CREDENTIAL = "credential" ;
100104 private static final URI ACCESS_GRANT = URI .create ("http://www.w3.org/ns/solid/vc#SolidAccessGrant" );
101105 private static final URI ACCESS_REQUEST = URI .create ("http://www.w3.org/ns/solid/vc#SolidAccessRequest" );
102106 private static final URI ACCESS_DENIAL = URI .create ("http://www.w3.org/ns/solid/vc#SolidAccessDenial" );
@@ -592,26 +596,24 @@ <T extends AccessCredential> List<T> processQueryResponse(final InputStream inpu
592596 final Map <String , Object > data = jsonService .fromJson (input ,
593597 new HashMap <String , Object >(){}.getClass ().getGenericSuperclass ());
594598 final List <T > grants = new ArrayList <>();
595- if (data .get (VERIFIABLE_CREDENTIAL ) instanceof Collection ) {
596- for (final Object item : (Collection ) data .get (VERIFIABLE_CREDENTIAL )) {
597- Utils .asMap (item ).ifPresent (credential ->
598- Utils .asSet (credential .get (TYPE )).ifPresent (types -> {
599- types .retainAll (validTypes );
600- if (!types .isEmpty ()) {
601- final Map <String , Object > presentation = new HashMap <>();
602- presentation .put (CONTEXT , Arrays .asList (VC_CONTEXT_URI ));
603- presentation .put (TYPE , Arrays .asList ("VerifiablePresentation" ));
604- presentation .put (VERIFIABLE_CREDENTIAL , Arrays .asList (credential ));
605- if (AccessGrant .class .equals (clazz )) {
606- grants .add ((T ) AccessGrant .of (new String (serialize (presentation ), UTF_8 )));
607- } else if (AccessRequest .class .equals (clazz )) {
608- grants .add ((T ) AccessRequest .of (new String (serialize (presentation ), UTF_8 )));
609- } else if (AccessDenial .class .equals (clazz )) {
610- grants .add ((T ) AccessDenial .of (new String (serialize (presentation ), UTF_8 )));
611- }
599+ for (final Object item : getCredentials (data )) {
600+ Utils .asMap (item ).ifPresent (credential ->
601+ Utils .asSet (credential .get (TYPE )).ifPresent (types -> {
602+ types .retainAll (validTypes );
603+ if (!types .isEmpty ()) {
604+ final Map <String , Object > presentation = new HashMap <>();
605+ presentation .put (CONTEXT , Arrays .asList (VC_CONTEXT_URI ));
606+ presentation .put (TYPE , Arrays .asList ("VerifiablePresentation" ));
607+ presentation .put (VERIFIABLE_CREDENTIAL , Arrays .asList (credential ));
608+ if (AccessGrant .class .equals (clazz )) {
609+ grants .add ((T ) AccessGrant .of (new String (serialize (presentation ), UTF_8 )));
610+ } else if (AccessRequest .class .equals (clazz )) {
611+ grants .add ((T ) AccessRequest .of (new String (serialize (presentation ), UTF_8 )));
612+ } else if (AccessDenial .class .equals (clazz )) {
613+ grants .add ((T ) AccessDenial .of (new String (serialize (presentation ), UTF_8 )));
612614 }
613- }));
614- }
615+ }
616+ }));
615617 }
616618
617619 return grants ;
@@ -661,6 +663,14 @@ byte[] serialize(final Map<String, Object> data) {
661663 }
662664 }
663665
666+ static Collection <Object > getCredentials (final Map <String , Object > data ) {
667+ final Object credential = data .get (VERIFIABLE_CREDENTIAL );
668+ if (credential instanceof Collection ) {
669+ return (Collection ) credential ;
670+ }
671+ return Collections .emptyList ();
672+ }
673+
664674 static List <Map <String , Object >> buildQuery (final URI issuer , final URI type , final URI agent , final URI resource ,
665675 final String mode ) {
666676 final List <Map <String , Object >> queries = new ArrayList <>();
@@ -693,7 +703,7 @@ static void buildQuery(final List<Map<String, Object>> queries, final URI issuer
693703 final Map <String , Object > subject = new HashMap <>();
694704 if (!consent .isEmpty ()) {
695705 if (isAccessGrant (type ) || isAccessDenial (type )) {
696- subject .put ("providedConsent" , consent );
706+ subject .put (PROVIDED_CONSENT , consent );
697707 } else if (isAccessRequest (type )) {
698708 subject .put ("hasConsent" , consent );
699709 }
@@ -745,21 +755,21 @@ static Map<String, Object> buildAccessDenialv1(final URI agent, final Set<URI> r
745755 consent .put (FOR_PERSONAL_DATA , resources );
746756 consent .put (IS_PROVIDED_TO_PERSON , agent );
747757 if (!purposes .isEmpty ()) {
748- consent .put ("forPurpose" , purposes );
758+ consent .put (FOR_PURPOSE , purposes );
749759 }
750760
751761 final Map <String , Object > subject = new HashMap <>();
752- subject .put ("providedConsent" , consent );
762+ subject .put (PROVIDED_CONSENT , consent );
753763
754764 final Map <String , Object > credential = new HashMap <>();
755765 credential .put (CONTEXT , Arrays .asList (VC_CONTEXT_URI , INRUPT_CONTEXT_URI ));
756766 if (expiration != null ) {
757- credential .put ("expirationDate" , expiration .truncatedTo (ChronoUnit .SECONDS ).toString ());
767+ credential .put (EXPIRATION_DATE , expiration .truncatedTo (ChronoUnit .SECONDS ).toString ());
758768 }
759769 credential .put (CREDENTIAL_SUBJECT , subject );
760770
761771 final Map <String , Object > data = new HashMap <>();
762- data .put ("credential" , credential );
772+ data .put (CREDENTIAL , credential );
763773 return data ;
764774 }
765775
@@ -772,21 +782,21 @@ static Map<String, Object> buildAccessGrantv1(final URI agent, final Set<URI> re
772782 consent .put (FOR_PERSONAL_DATA , resources );
773783 consent .put (IS_PROVIDED_TO_PERSON , agent );
774784 if (!purposes .isEmpty ()) {
775- consent .put ("forPurpose" , purposes );
785+ consent .put (FOR_PURPOSE , purposes );
776786 }
777787
778788 final Map <String , Object > subject = new HashMap <>();
779- subject .put ("providedConsent" , consent );
789+ subject .put (PROVIDED_CONSENT , consent );
780790
781791 final Map <String , Object > credential = new HashMap <>();
782792 credential .put (CONTEXT , Arrays .asList (VC_CONTEXT_URI , INRUPT_CONTEXT_URI ));
783793 if (expiration != null ) {
784- credential .put ("expirationDate" , expiration .truncatedTo (ChronoUnit .SECONDS ).toString ());
794+ credential .put (EXPIRATION_DATE , expiration .truncatedTo (ChronoUnit .SECONDS ).toString ());
785795 }
786796 credential .put (CREDENTIAL_SUBJECT , subject );
787797
788798 final Map <String , Object > data = new HashMap <>();
789- data .put ("credential" , credential );
799+ data .put (CREDENTIAL , credential );
790800 return data ;
791801 }
792802
@@ -800,7 +810,7 @@ static Map<String, Object> buildAccessRequestv1(final URI agent, final Set<URI>
800810 consent .put (IS_CONSENT_FOR_DATA_SUBJECT , agent );
801811 }
802812 if (!purposes .isEmpty ()) {
803- consent .put ("forPurpose" , purposes );
813+ consent .put (FOR_PURPOSE , purposes );
804814 }
805815
806816 final Map <String , Object > subject = new HashMap <>();
@@ -809,12 +819,12 @@ static Map<String, Object> buildAccessRequestv1(final URI agent, final Set<URI>
809819 final Map <String , Object > credential = new HashMap <>();
810820 credential .put (CONTEXT , Arrays .asList (VC_CONTEXT_URI , INRUPT_CONTEXT_URI ));
811821 if (expiration != null ) {
812- credential .put ("expirationDate" , expiration .truncatedTo (ChronoUnit .SECONDS ).toString ());
822+ credential .put (EXPIRATION_DATE , expiration .truncatedTo (ChronoUnit .SECONDS ).toString ());
813823 }
814824 credential .put (CREDENTIAL_SUBJECT , subject );
815825
816826 final Map <String , Object > data = new HashMap <>();
817- data .put ("credential" , credential );
827+ data .put (CREDENTIAL , credential );
818828 return data ;
819829 }
820830
0 commit comments