Skip to content

Commit

Permalink
Added conditions of the propertyOSID feilds and added Actor flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreejit-K committed Apr 17, 2024
1 parent 02fbc79 commit 8b2ba74
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
import static dev.sunbirdrc.registry.Constants.*;
import static dev.sunbirdrc.registry.exception.ErrorMessages.*;
import static dev.sunbirdrc.registry.middleware.util.Constants.*;
import static dev.sunbirdrc.registry.middleware.util.OSSystemFields._osState;
import static dev.sunbirdrc.registry.middleware.util.OSSystemFields.osOwner;
import static dev.sunbirdrc.registry.middleware.util.OSSystemFields.*;

/**
* This is helper class, user-service calls this class in-order to access registry functionality
Expand Down Expand Up @@ -844,7 +843,7 @@ private JsonNode getUserInfoFromRegistry(HttpServletRequest request, String enti
private JsonNode getEntityByUserId(String entityName, String userId) throws Exception {
ObjectNode payload = getSearchByOwnerQuery(entityName, userId);
watch.start("RegistryController.searchEntity");
JsonNode result = searchEntity(payload);
JsonNode result = searchEntity(payload, userId);
watch.stop("RegistryController.searchEntity");
return result;
}
Expand Down Expand Up @@ -1038,7 +1037,7 @@ public String getPropertyToUpdate(HttpServletRequest request, String entityId){
return propertyURI.split("/")[0];
}

private void updateAttestation(String attestorEntity, String userId, JsonNode entity, ArrayNode attestations,String propertyToUpdate, AttestationPolicy attestationPolicy) {
private void updateAttestation(String attestorEntity, String userId, JsonNode entity, ArrayNode attestations,String propertyToUpdate, AttestationPolicy attestationPolicy) throws Exception {
for (JsonNode attestation : attestations) {
if (attestation.get(_osState.name()).asText().equals(States.PUBLISHED.name())
&& !attestation.get("name").asText().equals(propertyToUpdate)
Expand All @@ -1056,19 +1055,22 @@ private void updateAttestation(String attestorEntity, String userId, JsonNode en
}
((ObjectNode) attestation).set(_osState.name(), JsonNodeFactory.instance.textNode(States.INVALID.name()));
} else if (attestation.get(_osState.name()).asText().equals(States.ATTESTATION_REQUESTED.name())) {
AttestationPolicy attestationPolicy = getAttestationPolicy(attestation.get("entityName").asText(), attestation.get("name").asText());
ObjectNode propertiesOSID = attestation.get("propertiesOSID").deepCopy();
Map<String, List<String>> propertiesOSIDMapper = new HashMap<>();
ObjectReader reader = objectMapper.readerFor(new TypeReference<List<String>>() {
});
for (Iterator<Map.Entry<String, JsonNode>> it = propertiesOSID.fields(); it.hasNext(); ) {
Map.Entry<String, JsonNode> itr = it.next();
if(itr.getValue().isArray() && !itr.getValue().isEmpty() && itr.getValue().get(0).isTextual()) {
List<String> list = reader.readValue(itr.getValue());
propertiesOSIDMapper.put(itr.getKey(), list);
JsonNode propertyData = JSONUtil.extractPropertyDataFromEntity(entity, attestationPolicy.getAttestationProperties(), null);
if (attestation.has("propertiesOSID")) {
ObjectNode propertiesOSID = attestations.get("propertiesOSID").deepCopy();
Map<String, List<String>> propertiesOSIDMapper = new HashMap<>();
ObjectReader reader = objectMapper.readerFor(new TypeReference<List<String>>() {
});
for (Iterator<Map.Entry<String, JsonNode>> it = propertiesOSID.fields(); it.hasNext(); ) {
Map.Entry<String, JsonNode> itr = it.next();
if(itr.getValue().isArray() && !itr.getValue().isEmpty() && itr.getValue().get(0).isTextual()) {
List<String> list = reader.readValue(itr.getValue());
propertiesOSIDMapper.put(itr.getKey(), list);
}
}
propertyData = JSONUtil.extractPropertyDataFromEntity(entity, attestationPolicy.getAttestationProperties(), propertiesOSIDMapper);
}
JsonNode propertyData = JSONUtil.extractPropertyDataFromEntity(entity, attestationPolicy.getAttestationProperties(), propertiesOSIDMapper);

if(!propertyData.equals(JSONUtil.convertStringJsonNode(attestation.get("propertyData").asText()))) {
((ObjectNode) attestation).set(_osState.name(), JsonNodeFactory.instance.textNode(States.DRAFT.name()));
invalidateClaim(attestorEntity, userId, attestation.get(_osClaimId.name()).asText());
Expand Down

0 comments on commit 8b2ba74

Please sign in to comment.