77
77
import static dev .sunbirdrc .registry .Constants .*;
78
78
import static dev .sunbirdrc .registry .exception .ErrorMessages .*;
79
79
import static dev .sunbirdrc .registry .middleware .util .Constants .*;
80
- import static dev .sunbirdrc .registry .middleware .util .OSSystemFields ._osState ;
81
- import static dev .sunbirdrc .registry .middleware .util .OSSystemFields .osOwner ;
80
+ import static dev .sunbirdrc .registry .middleware .util .OSSystemFields .*;
82
81
83
82
/**
84
83
* This is helper class, user-service calls this class in-order to access registry functionality
@@ -841,6 +840,14 @@ private JsonNode getUserInfoFromRegistry(HttpServletRequest request, String enti
841
840
throw new Exception ("Forbidden" );
842
841
}
843
842
843
+ private JsonNode getEntityByUserId (String entityName , String userId ) throws Exception {
844
+ ObjectNode payload = getSearchByOwnerQuery (entityName , userId );
845
+ watch .start ("RegistryController.searchEntity" );
846
+ JsonNode result = searchEntity (payload , userId );
847
+ watch .stop ("RegistryController.searchEntity" );
848
+ return result ;
849
+ }
850
+
844
851
@ NotNull
845
852
private ObjectNode getSearchByOwnerQuery (String entityName , String userId ) {
846
853
ObjectNode payload = JsonNodeFactory .instance .objectNode ();
@@ -1015,7 +1022,7 @@ public void invalidateAttestation(String entityName, String entityId, String use
1015
1022
}
1016
1023
if (entity .has (policyName ) && entity .get (policyName ).isArray ()) {
1017
1024
ArrayNode attestations = (ArrayNode ) entity .get (policyName );
1018
- updateAttestation (attestations , propertyToUpdate , attestationPolicy );
1025
+ updateAttestation (attestationPolicy . getAttestorEntity (), userId , entity , attestations , propertyToUpdate , attestationPolicy );
1019
1026
}
1020
1027
}
1021
1028
if (entity != null ) {
@@ -1029,7 +1036,8 @@ public String getPropertyToUpdate(HttpServletRequest request, String entityId){
1029
1036
String propertyURI = getPropertyURI (entityId , request );
1030
1037
return propertyURI .split ("/" )[0 ];
1031
1038
}
1032
- private void updateAttestation (ArrayNode attestations ,String propertyToUpdate , AttestationPolicy attestationPolicy ) {
1039
+
1040
+ private void updateAttestation (String attestorEntity , String userId , JsonNode entity , ArrayNode attestations ,String propertyToUpdate , AttestationPolicy attestationPolicy ) throws Exception {
1033
1041
for (JsonNode attestation : attestations ) {
1034
1042
if (attestation .get (_osState .name ()).asText ().equals (States .PUBLISHED .name ())
1035
1043
&& !attestation .get ("name" ).asText ().equals (propertyToUpdate )
@@ -1046,10 +1054,48 @@ private void updateAttestation(ArrayNode attestations,String propertyToUpdate, A
1046
1054
);
1047
1055
}
1048
1056
((ObjectNode ) attestation ).set (_osState .name (), JsonNodeFactory .instance .textNode (States .INVALID .name ()));
1057
+ } else if (attestation .get (_osState .name ()).asText ().equals (States .ATTESTATION_REQUESTED .name ())) {
1058
+ JsonNode propertyData = JSONUtil .extractPropertyDataFromEntity (entity , attestationPolicy .getAttestationProperties (), null );
1059
+ if (attestation .has ("propertiesOSID" )) {
1060
+ ObjectNode propertiesOSID = attestations .get ("propertiesOSID" ).deepCopy ();
1061
+ Map <String , List <String >> propertiesOSIDMapper = new HashMap <>();
1062
+ ObjectReader reader = objectMapper .readerFor (new TypeReference <List <String >>() {
1063
+ });
1064
+ for (Iterator <Map .Entry <String , JsonNode >> it = propertiesOSID .fields (); it .hasNext (); ) {
1065
+ Map .Entry <String , JsonNode > itr = it .next ();
1066
+ if (itr .getValue ().isArray () && !itr .getValue ().isEmpty () && itr .getValue ().get (0 ).isTextual ()) {
1067
+ List <String > list = reader .readValue (itr .getValue ());
1068
+ propertiesOSIDMapper .put (itr .getKey (), list );
1069
+ }
1070
+ }
1071
+ propertyData = JSONUtil .extractPropertyDataFromEntity (entity , attestationPolicy .getAttestationProperties (), propertiesOSIDMapper );
1072
+ }
1073
+
1074
+ if (!propertyData .equals (JSONUtil .convertStringJsonNode (attestation .get ("propertyData" ).asText ()))) {
1075
+ ((ObjectNode ) attestation ).set (_osState .name (), JsonNodeFactory .instance .textNode (States .DRAFT .name ()));
1076
+ invalidateClaim (attestorEntity , userId , attestation .get (_osClaimId .name ()).asText ());
1077
+ }
1049
1078
}
1050
1079
}
1051
1080
}
1052
1081
1082
+ public void invalidateClaim (String attestorEntityName , String userId , String claimId ) throws Exception {
1083
+ final String attestorPlugin = "did:internal:ClaimPluginActor" ;
1084
+ Action action = Action .SET_TO_DRAFT ;
1085
+ ObjectNode additionalInputs = JsonNodeFactory .instance .objectNode ();
1086
+ JsonNode attestorInfo = getEntityByUserId (attestorEntityName , userId ).get (attestorEntityName ).get (0 );
1087
+ additionalInputs .put ("claimId" , claimId );
1088
+ additionalInputs .put ("action" , action .name ());
1089
+ additionalInputs .put ("notes" , "Closed due to entity update" );
1090
+ additionalInputs .set ("attestorInfo" , attestorInfo );
1091
+ PluginRequestMessage pluginRequestMessage = PluginRequestMessage .builder ().build ();
1092
+ pluginRequestMessage .setAttestorPlugin (attestorPlugin );
1093
+ pluginRequestMessage .setAdditionalInputs (additionalInputs );
1094
+ pluginRequestMessage .setStatus (action .name ());
1095
+ pluginRequestMessage .setUserId (userId );
1096
+ PluginRouter .route (pluginRequestMessage );
1097
+ }
1098
+
1053
1099
public Object getSignedDoc (String title , JsonNode result , Object credentialTemplate ) throws
1054
1100
SignatureException .CreationException , SignatureException .UnreachableException {
1055
1101
Map <String , Object > requestBodyMap = new HashMap <>();
0 commit comments