diff --git a/java/claim/src/main/java/dev/sunbirdrc/claim/entity/Claim.java b/java/claim/src/main/java/dev/sunbirdrc/claim/entity/Claim.java index 175088a50..98e13026f 100644 --- a/java/claim/src/main/java/dev/sunbirdrc/claim/entity/Claim.java +++ b/java/claim/src/main/java/dev/sunbirdrc/claim/entity/Claim.java @@ -185,8 +185,8 @@ public String getAttestationId() { return attestationId; } - public void setAttestationId(String attestationOSID) { - this.attestationId = attestationOSID; + public void setAttestationId(String attestationUUID) { + this.attestationId = attestationUUID; } public String getAttestationName() { diff --git a/java/claim/src/main/java/dev/sunbirdrc/claim/service/ClaimsAuthorizer.java b/java/claim/src/main/java/dev/sunbirdrc/claim/service/ClaimsAuthorizer.java index 04cf69970..14da0d4eb 100644 --- a/java/claim/src/main/java/dev/sunbirdrc/claim/service/ClaimsAuthorizer.java +++ b/java/claim/src/main/java/dev/sunbirdrc/claim/service/ClaimsAuthorizer.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.Collections; @@ -14,7 +15,8 @@ public class ClaimsAuthorizer { private static final String ATTESTOR = "ATTESTOR"; - private static final String UUID_PROPERTY_NAME = "osid"; + @Value("${uuid-property-name}") + private String uuidPropertyName; private static final Logger logger = LoggerFactory.getLogger(ClaimsAuthorizer.class); private final ConditionResolverService conditionResolverService; @@ -42,8 +44,8 @@ public boolean isAuthorizedAttestor(Claim claim, JsonNode attestorNode) { } public boolean isAuthorizedRequestor(Claim claim, JsonNode attestorNode) { - if(!attestorNode.isNull() && attestorNode.has(UUID_PROPERTY_NAME)) { - String userEntityId = attestorNode.get(UUID_PROPERTY_NAME).asText(); + if(!attestorNode.isNull() && attestorNode.has(uuidPropertyName)) { + String userEntityId = attestorNode.get(uuidPropertyName).asText(); return claim.getEntityId().equals(userEntityId); } return false; diff --git a/java/claim/src/main/resources/application.properties b/java/claim/src/main/resources/application.properties index 51a497d85..a8d3441b0 100644 --- a/java/claim/src/main/resources/application.properties +++ b/java/claim/src/main/resources/application.properties @@ -8,4 +8,6 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true -sunbirdrc.url=${sunbirdrc_url:http://localhost:8081} \ No newline at end of file +sunbirdrc.url=${sunbirdrc_url:http://localhost:8081} + +uuid-property-name=${uuid_property_name:osid} diff --git a/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ESMessage.java b/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ESMessage.java index b2d5a3353..1bfa19989 100644 --- a/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ESMessage.java +++ b/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ESMessage.java @@ -6,18 +6,12 @@ @JsonSerialize public class ESMessage { String indexName; - String osid; + String uuidPropertyValue; JsonNode input; public ESMessage() { } - /*public ESMessage(String indexName, String osid, JsonNode input) { - setIndexName(indexName); - setOsid(osid); - setInput(input); - }*/ - public String getIndexName() { return indexName; } @@ -26,12 +20,12 @@ public void setIndexName(String indexName) { this.indexName = indexName; } - public String getOsid() { - return osid; + public String getUuidPropertyValue() { + return uuidPropertyValue; } - public void setOsid(String osid) { - this.osid = osid; + public void setUuidPropertyValue(String uuidPropertyValue) { + this.uuidPropertyValue = uuidPropertyValue; } public JsonNode getInput() { diff --git a/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java b/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java index b519fdaf9..7c1b60f9d 100644 --- a/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java +++ b/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java @@ -211,17 +211,17 @@ public RestStatus addEntity(String index, String entityId, JsonNode inputEntity) * Reads the document from Elastic search * * @param index - ElasticSearch Index - * @param osid - which maps to document + * @param uuidPropertyValue - which maps to document * @return */ @Override @Retryable(value = {IOException.class, ConnectException.class}, maxAttemptsExpression = "#{${service.retry.maxAttempts}}", backoff = @Backoff(delayExpression = "#{${service.retry.backoff.delay}}")) - public Map readEntity(String index, String osid) throws IOException { - logger.debug("readEntity starts with index {} and entityId {}", index, osid); + public Map readEntity(String index, String uuidPropertyValue) throws IOException { + logger.debug("readEntity starts with index {} and entityId {}", index, uuidPropertyValue); GetResponse response = null; - response = getClient(index).get(new GetRequest(index, searchType, osid), RequestOptions.DEFAULT); + response = getClient(index).get(new GetRequest(index, searchType, uuidPropertyValue), RequestOptions.DEFAULT); return response.getSourceAsMap(); } @@ -230,19 +230,19 @@ public Map readEntity(String index, String osid) throws IOExcept * Updates the document with updated inputEntity * * @param index - ElasticSearch Index - * @param osid - which maps to document + * @param uuidPropertyValue - which maps to document * @param inputEntity - input json document for updating * @return */ @Override - public RestStatus updateEntity(String index, String osid, JsonNode inputEntity) { - logger.debug("updateEntity starts with index {} and entityId {}", index, osid); + public RestStatus updateEntity(String index, String uuidPropertyValue, JsonNode inputEntity) { + logger.debug("updateEntity starts with index {} and entityId {}", index, uuidPropertyValue); UpdateResponse response = null; try { Map inputMap = JSONUtil.convertJsonNodeToMap(inputEntity); logger.debug("updateEntity inputMap {}", inputMap); logger.debug("updateEntity inputEntity {}", inputEntity); - response = getClient(index.toLowerCase()).update(new UpdateRequest(index.toLowerCase(), searchType, osid).doc(inputMap), RequestOptions.DEFAULT); + response = getClient(index.toLowerCase()).update(new UpdateRequest(index.toLowerCase(), searchType, uuidPropertyValue).doc(inputMap), RequestOptions.DEFAULT); } catch (IOException e) { logger.error("Exception in updating a record to ElasticSearch: {}", ExceptionUtils.getStackTrace(e)); } @@ -253,20 +253,20 @@ public RestStatus updateEntity(String index, String osid, JsonNode inputEntity) * Updates the document status to inactive into elastic-search * * @param index - ElasticSearch Index - * @param osid - which maps to document + * @param uuidPropertyValue - which maps to document * @return */ @Override - public RestStatus deleteEntity(String index, String osid) { + public RestStatus deleteEntity(String index, String uuidPropertyValue) { DocWriteResponse response = null; try { String indexL = index.toLowerCase(); - Map readMap = readEntity(indexL, osid); + Map readMap = readEntity(indexL, uuidPropertyValue); if (isHardDeleteEnabled) { - response = getClient(indexL).delete(new DeleteRequest(indexL, searchType, osid), RequestOptions.DEFAULT); + response = getClient(indexL).delete(new DeleteRequest(indexL, searchType, uuidPropertyValue), RequestOptions.DEFAULT); } else { readMap.put(Constants.STATUS_KEYWORD, Constants.STATUS_INACTIVE); - response = getClient(indexL).update(new UpdateRequest(indexL, searchType, osid).doc(readMap), RequestOptions.DEFAULT); + response = getClient(indexL).update(new UpdateRequest(indexL, searchType, uuidPropertyValue).doc(readMap), RequestOptions.DEFAULT); } } catch (NullPointerException | IOException e) { logger.error("exception in deleteEntity {}", ExceptionUtils.getStackTrace(e)); diff --git a/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/IElasticService.java b/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/IElasticService.java index 2eb492bef..43ab532b3 100644 --- a/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/IElasticService.java +++ b/java/elastic-search/src/main/java/dev/sunbirdrc/elastic/IElasticService.java @@ -20,26 +20,26 @@ public interface IElasticService extends HealthIndicator { */ RestStatus addEntity(String index, String id, JsonNode inputEntity); - /** Reads document with respect to input osid from ES + /** Reads document with respect to input uuidPropertyValue from ES * @param index - ElasticSearch Index - * @param osid - which maps to document + * @param uuidPropertyValue - which maps to document * @return */ - Map readEntity(String index, String osid) throws IOException; + Map readEntity(String index, String uuidPropertyValue) throws IOException; - /** updates document with respect to input osid to ES + /** updates document with respect to input uuidPropertyValue to ES * @param index - ElasticSearch Index * @param inputEntity - input json document for updating - * @param osid - which maps to document + * @param uuidPropertyValue - which maps to document * @return */ - RestStatus updateEntity(String index, String osid, JsonNode inputEntity); + RestStatus updateEntity(String index, String uuidPropertyValue, JsonNode inputEntity); - /** deletes document with respect to input osid from ES + /** deletes document with respect to input uuidPropertyValue from ES * @param index - ElasticSearch Index - * @param osid - which maps to document + * @param uuidPropertyValue - which maps to document */ - RestStatus deleteEntity(String index, String osid); + RestStatus deleteEntity(String index, String uuidPropertyValue); /** searches documents from ES based on query * @param index - ElasticSearch Index diff --git a/java/middleware-commons/src/main/java/dev/sunbirdrc/registry/middleware/util/JSONUtil.java b/java/middleware-commons/src/main/java/dev/sunbirdrc/registry/middleware/util/JSONUtil.java index 9e76a2f2b..62ec2137e 100644 --- a/java/middleware-commons/src/main/java/dev/sunbirdrc/registry/middleware/util/JSONUtil.java +++ b/java/middleware-commons/src/main/java/dev/sunbirdrc/registry/middleware/util/JSONUtil.java @@ -481,23 +481,23 @@ public static String readValFromJsonTree(String path, JsonNode input) { return typeList.get(0); } - public static String getOSIDFromArrNode(JsonNode resultNode, JsonNode requestBody, List fieldsToRemove) { + public static String getUUIDPropertyValueFromArrNode(String uuidPropertyName, String propertiesUUIDKeyName, JsonNode resultNode, JsonNode requestBody) { if (resultNode.isArray()) { ArrayNode arrayNode = (ArrayNode) resultNode; - JsonNode matchingClaim = searchClaimOsIdFromRequestProperties(arrayNode,requestBody); - return matchingClaim!=null?matchingClaim.get("osid").asText():""; + JsonNode matchingClaim = searchClaimUUIDPropertyValueFromRequestProperties(propertiesUUIDKeyName, arrayNode,requestBody); + return matchingClaim != null ? matchingClaim.get(uuidPropertyName).asText() : ""; } return ""; } - private static JsonNode searchClaimOsIdFromRequestProperties(ArrayNode arrayNode, JsonNode requestBody) { - if (requestBody.get("propertiesOSID") != null) { - Map> requestBodyProperty = objectMapper.convertValue(requestBody.get("propertiesOSID"), Map.class); + private static JsonNode searchClaimUUIDPropertyValueFromRequestProperties(String propertiesUUIDKeyName, ArrayNode arrayNode, JsonNode requestBody) { + if (requestBody.get(propertiesUUIDKeyName) != null) { + Map> requestBodyProperty = objectMapper.convertValue(requestBody.get(propertiesUUIDKeyName), Map.class); Iterator claimIterator = arrayNode.elements(); while (claimIterator.hasNext()) { JsonNode claimEntry = claimIterator.next(); - if (claimEntry.get("propertiesOSID") != null) { - JsonNode property = claimEntry.get("propertiesOSID"); + if (claimEntry.get(propertiesUUIDKeyName) != null) { + JsonNode property = claimEntry.get(propertiesUUIDKeyName); Map claimEntryProperty = objectMapper.convertValue(property, Map.class); if (isRequestBodyPropertyPresentInClaim(requestBodyProperty, claimEntryProperty)) { return claimEntry; @@ -518,16 +518,16 @@ private static JsonNode searchClaimOsIdFromRequestProperties(ArrayNode arrayNode private static boolean isRequestBodyPropertyPresentInClaim(Map> requestBodyProperty,Map claimEntryProperty){ for(Map.Entry> entry: requestBodyProperty.entrySet()){ - List requestBodyPropertyOSID = entry.getValue(); + List requestBodyPropertyUUID = entry.getValue(); String key = entry.getKey(); - if(!((List) objectMapper.convertValue(claimEntryProperty.get(key), List.class)).containsAll(requestBodyPropertyOSID)){ + if(!((List) objectMapper.convertValue(claimEntryProperty.get(key), List.class)).containsAll(requestBodyPropertyUUID)){ return false; } } return true; } - public static JsonNode extractPropertyDataFromEntity(JsonNode entityNode, Map attestationProperties, Map> propertiesOSIDMapper) { + public static JsonNode extractPropertyDataFromEntity(String uuidPropertyName, JsonNode entityNode, Map attestationProperties, Map> propertiesUUIDMapper) { if(attestationProperties == null) { return JsonNodeFactory.instance.nullNode(); } @@ -539,13 +539,13 @@ public static JsonNode extractPropertyDataFromEntity(JsonNode entityNode, Map osids = propertiesOSIDMapper.get(key); + if(readNode.isArray() && propertiesUUIDMapper != null && propertiesUUIDMapper.containsKey(key)) { + List uuidPropertyValues = propertiesUUIDMapper.get(key); ArrayNode arrayNode = (ArrayNode) readNode; ArrayNode filteredArrNode = JsonNodeFactory.instance.arrayNode(); for(JsonNode node :arrayNode) { - if(node.has("osid") && osids.contains(node.get("osid").asText())) { + if(node.has(uuidPropertyName) && uuidPropertyValues.contains(node.get(uuidPropertyName).asText())) { filteredArrNode.add(node); } } diff --git a/java/middleware-commons/src/test/java/dev/sunbirdrc/registry/middleware/util/JSONUtilTest.java b/java/middleware-commons/src/test/java/dev/sunbirdrc/registry/middleware/util/JSONUtilTest.java index 33d78ed9e..852500459 100644 --- a/java/middleware-commons/src/test/java/dev/sunbirdrc/registry/middleware/util/JSONUtilTest.java +++ b/java/middleware-commons/src/test/java/dev/sunbirdrc/registry/middleware/util/JSONUtilTest.java @@ -244,7 +244,7 @@ public void shouldAbleToFetchPropertiesFromEntity() throws IOException { put("educationDetails", new ArrayList<>(Arrays.asList("1", "2"))); } }; - JsonNode actualPropertyData = JSONUtil.extractPropertyDataFromEntity(entityNode, attestationProperties, properyOSIDMapper); + JsonNode actualPropertyData = JSONUtil.extractPropertyDataFromEntity("osid", entityNode, attestationProperties, properyOSIDMapper); assertEquals(expectedPropertyNode, actualPropertyData); } diff --git a/java/plugins/divoc-external-plugin/src/main/java/dev/sunbirdrc/plugin/DivocPDFActor.java b/java/plugins/divoc-external-plugin/src/main/java/dev/sunbirdrc/plugin/DivocPDFActor.java index 640fe8200..5835a8e67 100644 --- a/java/plugins/divoc-external-plugin/src/main/java/dev/sunbirdrc/plugin/DivocPDFActor.java +++ b/java/plugins/divoc-external-plugin/src/main/java/dev/sunbirdrc/plugin/DivocPDFActor.java @@ -52,7 +52,7 @@ public void onReceive(MessageProtos.Message request) throws Throwable { PluginResponseMessage pluginResponseMessage = PluginResponseMessageCreator.createPluginResponseMessage(pluginRequestMessage); if (fileBytes != null) { pluginResponseMessage.setFiles(Collections.singletonList(PluginFile.builder().file(fileBytes) - .fileName(String.format("%s.pdf", pluginRequestMessage.getAttestationOSID())).build())); + .fileName(String.format("%s.pdf", pluginRequestMessage.getAttestationUUID())).build())); pluginResponseMessage.setStatus(Action.GRANT_CLAIM.name()); ObjectNode responseNode = objectMapper.createObjectNode(); responseNode.set("status", JsonNodeFactory.instance.textNode("true")); diff --git a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/MosipActor.java b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/MosipActor.java index a2b7b264d..86b20b68d 100644 --- a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/MosipActor.java +++ b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/MosipActor.java @@ -9,9 +9,7 @@ import dev.sunbirdrc.pojos.PluginRequestMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; import org.sunbird.akka.core.BaseActor; import org.sunbird.akka.core.MessageProtos; @@ -28,8 +26,8 @@ public void onReceive(MessageProtos.Message request) throws Throwable { logger.info("Received request message {} ", pluginRequestMessage); JsonNode additionalInput = pluginRequestMessage.getAdditionalInputs(); FetchCredentialsDto fetchCredentialsDto = FetchCredentialsDto.builder() - .osid(pluginRequestMessage.getSourceOSID()) - .attestationOsid(pluginRequestMessage.getAttestationOSID()) + .uuidPropertyValue(pluginRequestMessage.getSourceUUID()) + .attestationUuid(pluginRequestMessage.getAttestationUUID()) .uid(additionalInput.get("uid").asText()) .otp(additionalInput.get("otp").asText()) .transactionId(additionalInput.get("transactionId").asText()) diff --git a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/controller/MosipCallbackController.java b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/controller/MosipCallbackController.java index 303c96242..da4b59613 100644 --- a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/controller/MosipCallbackController.java +++ b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/controller/MosipCallbackController.java @@ -14,17 +14,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.http.HttpEntity; import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.sunbird.akka.core.ActorCache; import org.sunbird.akka.core.MessageProtos; import org.sunbird.akka.core.Router; -import javax.servlet.http.HttpServletRequest; import java.util.Collections; import java.util.Date; import java.util.Map; @@ -40,6 +38,9 @@ public class MosipCallbackController { @Autowired private ObjectMapper objectMapper; + @Value("${database.uuidPropertyName}") + private String uuidPropertyName; + @RequestMapping(value = "/plugin/mosip/callback", method = RequestMethod.POST) public ResponseEntity callbackHandler(@RequestHeader Map headers, @RequestParam Map queryParams, @RequestBody String request) throws JsonProcessingException { try { @@ -49,16 +50,16 @@ public ResponseEntity callbackHandler(@RequestHeader Map headers byte[] bytes = mosipServices.fetchMosipPdf(headers, request); if (bytes != null) { - String attestationOSID = requestBody.get("event").get("data").get("attestationOsid").asText(); + String attestationUUID = requestBody.get("event").get("data").get("attestationOsid").asText(); PluginResponseMessage pluginResponseMessage = PluginResponseMessage.builder().policyName("attestation-MOSIP") .sourceEntity("User") - .sourceOSID(requestBody.get("event").get("data").get("osid").asText()) - .attestationOSID(attestationOSID) + .sourceUUID(requestBody.get("event").get("data").get(uuidPropertyName).asText()) + .attestationUUID(attestationUUID) .attestorPlugin("did:external:MosipActor") .additionalData(JsonNodeFactory.instance.nullNode()) .date(new Date()) .validUntil(new Date()) - .version("").files(Collections.singletonList(PluginFile.builder().file(bytes).fileName(String.format("%s.pdf",attestationOSID)).build())).build(); + .version("").files(Collections.singletonList(PluginFile.builder().file(bytes).fileName(String.format("%s.pdf",attestationUUID)).build())).build(); pluginResponseMessage.setStatus(Action.GRANT_CLAIM.name()); pluginResponseMessage.setResponse(requestBody.get("event").get("data").toString()); LOGGER.info("{}", pluginResponseMessage); diff --git a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/dto/FetchCredentialsDto.java b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/dto/FetchCredentialsDto.java index ce72d8db2..9a9ee5b4f 100644 --- a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/dto/FetchCredentialsDto.java +++ b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/dto/FetchCredentialsDto.java @@ -9,6 +9,6 @@ public class FetchCredentialsDto { String otp; String uid; String transactionId; - String osid; - String attestationOsid; + String uuidPropertyValue; + String attestationUuid; } diff --git a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/services/MosipServices.java b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/services/MosipServices.java index 23611481d..fb2cd726f 100644 --- a/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/services/MosipServices.java +++ b/java/plugins/mosip-external-plugin/src/main/java/dev/sunbirdrc/plugin/services/MosipServices.java @@ -1,6 +1,5 @@ package dev.sunbirdrc.plugin.services; -import com.fasterxml.jackson.databind.JsonNode; import dev.sunbirdrc.plugin.constant.Constants; import dev.sunbirdrc.plugin.dto.*; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -9,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.*; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -157,8 +155,8 @@ public Object fetchCredentials(FetchCredentialsDto fetchCredentialsDto) { .id(Constants.MOSIP_IDENTITY_OTP_INTERNAL) .request(CredentialsRequestDto.builder() .additionalData(new HashMap(){{ - put("osid", fetchCredentialsDto.getOsid()); - put("attestationOsid", fetchCredentialsDto.getAttestationOsid()); + put("osid", fetchCredentialsDto.getUuidPropertyValue()); + put("attestationOsid", fetchCredentialsDto.getAttestationUuid()); }}) .individualId(fetchCredentialsDto.getUid()) .issuer(issuer) diff --git a/java/pojos/src/main/java/dev/sunbirdrc/pojos/AuditInfo.java b/java/pojos/src/main/java/dev/sunbirdrc/pojos/AuditInfo.java index 6b899ac7b..84251e5d7 100644 --- a/java/pojos/src/main/java/dev/sunbirdrc/pojos/AuditInfo.java +++ b/java/pojos/src/main/java/dev/sunbirdrc/pojos/AuditInfo.java @@ -6,6 +6,7 @@ public class AuditInfo { private String op; private String path; private Object value; + private String from; public String getOp() { return op; @@ -23,6 +24,15 @@ public void setPath(String path) { this.path = path; } + @JsonIgnore + public String getFrom() { + return from; + } + + public void setFrom(String path) { + this.from = path; + } + @JsonIgnore public Object getValue() { return value; diff --git a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessage.java b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessage.java index f229d3167..f8625c51f 100644 --- a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessage.java +++ b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessage.java @@ -23,8 +23,8 @@ public class PluginRequestMessage { private JsonNode additionalInputs; private String propertyData; private String sourceEntity; - private String sourceOSID; - private String attestationOSID; + private String sourceUUID; + private String attestationUUID; private String attestationType; private String attestorPlugin; private String attestorEntity; @@ -33,7 +33,7 @@ public class PluginRequestMessage { private String status; @Nullable private String userId; - private Map> propertiesOSID; + private Map> propertiesUUID; private String emailId; public Optional getActorName() { diff --git a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessageCreator.java b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessageCreator.java index 827308c00..1dbcfdffa 100644 --- a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessageCreator.java +++ b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginRequestMessageCreator.java @@ -8,27 +8,27 @@ public class PluginRequestMessageCreator { public static PluginRequestMessage create(String propertyData, String condition, - String attestationOSID, + String attestationUUID, String entityName, String userId, String entityId, JsonNode additionalInput, String status, String name, String attestorPlugin, String attestorEntity, - String attestorSignin, Map> propertiesOSID, String emailId) { + String attestorSignin, Map> propertiesUUIDs, String emailId) { PluginRequestMessage pluginRequestMessage = new PluginRequestMessage(); pluginRequestMessage.setPolicyName(name); pluginRequestMessage.setAdditionalInputs(additionalInput); pluginRequestMessage.setPropertyData(propertyData); pluginRequestMessage.setSourceEntity(entityName); - pluginRequestMessage.setSourceOSID(entityId); - pluginRequestMessage.setAttestationOSID(attestationOSID); + pluginRequestMessage.setSourceUUID(entityId); + pluginRequestMessage.setAttestationUUID(attestationUUID); pluginRequestMessage.setAttestorPlugin(attestorPlugin); pluginRequestMessage.setAttestorEntity(attestorEntity); pluginRequestMessage.setAttestorSignin(attestorSignin); pluginRequestMessage.setConditions(condition); pluginRequestMessage.setStatus(status); pluginRequestMessage.setUserId(userId); - pluginRequestMessage.setPropertiesOSID(propertiesOSID); + pluginRequestMessage.setPropertiesUUID(propertiesUUIDs); pluginRequestMessage.setEmailId(emailId); return pluginRequestMessage; } diff --git a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessage.java b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessage.java index 6be9f52da..2c2bde7d0 100644 --- a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessage.java +++ b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessage.java @@ -22,8 +22,8 @@ public class PluginResponseMessage { private String policyName; private String sourceEntity; - private String sourceOSID; - private String attestationOSID; + private String sourceUUID; + private String attestationUUID; private String attestorPlugin; private String response; private String signedData; @@ -34,7 +34,7 @@ public class PluginResponseMessage { private Date validUntil; private String version; private String userId; - private Map> propertiesOSID; + private Map> propertiesUUIDs; private String emailId; @Builder.Default private List files = new ArrayList<>(); diff --git a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessageCreator.java b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessageCreator.java index 9aa4046e5..ee5b8014d 100644 --- a/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessageCreator.java +++ b/java/pojos/src/main/java/dev/sunbirdrc/pojos/PluginResponseMessageCreator.java @@ -12,8 +12,8 @@ public static PluginResponseMessage createClaimResponseMessage(String claimId, A additionalData.put("claimId", claimId); return PluginResponseMessage.builder() .sourceEntity(pluginRequestMessage.getSourceEntity()) - .sourceOSID(pluginRequestMessage.getSourceOSID()) - .attestationOSID(pluginRequestMessage.getAttestationOSID()) + .sourceUUID(pluginRequestMessage.getSourceUUID()) + .attestationUUID(pluginRequestMessage.getAttestationUUID()) .attestorPlugin(pluginRequestMessage.getAttestorPlugin()) .additionalData(additionalData) .policyName(pluginRequestMessage.getPolicyName()) @@ -21,7 +21,7 @@ public static PluginResponseMessage createClaimResponseMessage(String claimId, A .date(new Date()) .validUntil(new Date()) .version("") - .propertiesOSID(pluginRequestMessage.getPropertiesOSID()) + .propertiesUUIDs(pluginRequestMessage.getPropertiesUUID()) .userId(pluginRequestMessage.getUserId()) .emailId(pluginRequestMessage.getEmailId()) .build(); @@ -31,8 +31,8 @@ public static PluginResponseMessage createPluginResponseMessage(PluginRequestMes return PluginResponseMessage.builder() .policyName(pluginRequestMessage.getPolicyName()) .sourceEntity(pluginRequestMessage.getSourceEntity()) - .sourceOSID(pluginRequestMessage.getSourceOSID()) - .attestationOSID(pluginRequestMessage.getAttestationOSID()) + .sourceUUID(pluginRequestMessage.getSourceUUID()) + .attestationUUID(pluginRequestMessage.getAttestationUUID()) .attestorPlugin(pluginRequestMessage.getAttestorPlugin()) .additionalData(JsonNodeFactory.instance.nullNode()) .date(new Date()).validUntil(new Date()).version("") diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/consumers/CreateEntityConsumer.java b/java/registry/src/main/java/dev/sunbirdrc/registry/consumers/CreateEntityConsumer.java index 7e123b512..9d06768c3 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/consumers/CreateEntityConsumer.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/consumers/CreateEntityConsumer.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import dev.sunbirdrc.registry.Constants; import dev.sunbirdrc.registry.helper.RegistryHelper; import dev.sunbirdrc.registry.model.dto.CreateEntityMessage; import dev.sunbirdrc.registry.model.dto.CreateEntityStatus; @@ -14,7 +13,6 @@ import dev.sunbirdrc.registry.sink.shard.ShardManager; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.kafka.clients.consumer.ConsumerRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -74,9 +72,9 @@ public void createEntityConsumer(@Payload String message, @Header(KafkaHeaders.R JsonNode inputJson = createEntityMessage.getInputJson(); String entityType = inputJson.fields().next().getKey(); Shard shard = shardManager.getShard(inputJson.get(entityType).get(shardManager.getShardProperty())); - String entityOsid = registryService.addEntity(shard, createEntityMessage.getUserId(), inputJson, createEntityMessage.isSkipSignature()); - registryHelper.autoRaiseClaim(entityType, entityOsid, createEntityMessage.getUserId(), null, inputJson, createEntityMessage.getEmailId()); - postCreateEntityMessage = PostCreateEntityMessage.builder().entityType(entityType).osid(entityOsid) + String entityUuid = registryService.addEntity(shard, createEntityMessage.getUserId(), inputJson, createEntityMessage.isSkipSignature()); + registryHelper.autoRaiseClaim(entityType, entityUuid, createEntityMessage.getUserId(), null, inputJson, createEntityMessage.getEmailId()); + postCreateEntityMessage = PostCreateEntityMessage.builder().entityType(entityType).uuid(entityUuid) .transactionId(key).userId(createEntityMessage.getUserId()).status(CreateEntityStatus.SUCCESSFUL).message("").build(); } catch (Exception e) { logger.error("Creating entity failed: {}", ExceptionUtils.getStackTrace(e)); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryAttestationPolicyController.java b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryAttestationPolicyController.java index 3f56a084e..18b0476db 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryAttestationPolicyController.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryAttestationPolicyController.java @@ -76,17 +76,17 @@ public ResponseEntity getAttestationPolicies(@PathVariable String entityName, Ht } } - @PutMapping("/api/v1/{entityName}/attestationPolicy/{policyOSID}") - public ResponseEntity updateAttestationPolicy(@PathVariable String entityName, @PathVariable String policyOSID, + @PutMapping("/api/v1/{entityName}/attestationPolicy/{policyUUID}") + public ResponseEntity updateAttestationPolicy(@PathVariable String entityName, @PathVariable String policyUUID, @RequestBody final AttestationPolicy attestationPolicy, HttpServletRequest request) { ResponseParams responseParams = new ResponseParams(); Response response = new Response(Response.API_ID.UPDATE, "OK", responseParams); try { if (definitionsManager.isValidEntityName(entityName)) { String userId = registryHelper.getUserId(entityName); - final Optional attestationPolicyOptional = registryHelper.findAttestationPolicyById(userId, policyOSID); + final Optional attestationPolicyOptional = registryHelper.findAttestationPolicyById(userId, policyUUID); if (attestationPolicyOptional.isPresent() && attestationPolicyOptional.get().getCreatedBy().equals(userId)) { - logger.info("Updating attestation policies id: {}", policyOSID); + logger.info("Updating attestation policies id: {}", policyUUID); response.setResult(registryHelper.updateAttestationPolicy(userId, attestationPolicy)); responseParams.setStatus(Response.Status.SUCCESSFUL); return new ResponseEntity<>(response, HttpStatus.OK); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java index 85e3b226b..a3101f20f 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryClaimsController.java @@ -142,15 +142,15 @@ public ResponseEntity riseAttestation(HttpServletRequest request, @Reque JsonNode entityNode = registryHelper.readEntity(userId, attestationRequest.getEntityName(), attestationRequest.getEntityId(), false, null, false) .get(attestationRequest.getEntityName()); - JsonNode propertyData = JSONUtil.extractPropertyDataFromEntity(entityNode, attestationPolicy.getAttestationProperties(), attestationRequest.getPropertiesOSID()); + JsonNode propertyData = JSONUtil.extractPropertyDataFromEntity(uuidPropertyName, entityNode, attestationPolicy.getAttestationProperties(), attestationRequest.getPropertiesUUID(uuidPropertyName)); if(!propertyData.isNull()) { attestationRequest.setPropertyData(propertyData); } attestationRequest.setOsCreatedAt(LocalDateTime.ofInstant(new Date().toInstant(), ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")) ); attestationRequest.setUserId(userId); attestationRequest.setEmailId(emailId); - String attestationOSID = registryHelper.triggerAttestation(attestationRequest, attestationPolicy); - response.setResult(Collections.singletonMap("attestationOSID", attestationOSID)); + String attestationUUID = registryHelper.triggerAttestation(attestationRequest, attestationPolicy); + response.setResult(Collections.singletonMap("attestation" + uuidPropertyName.toUpperCase(), attestationUUID)); } catch (Exception e) { logger.error("Exception occurred while saving attestation data {}", ExceptionUtils.getStackTrace(e)); responseParams.setErrmsg(e.getMessage()); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/NotFoundException.java b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/NotFoundException.java index 6c37d4db0..e112a9203 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/NotFoundException.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/NotFoundException.java @@ -1,13 +1,9 @@ package dev.sunbirdrc.registry.dao; public class NotFoundException extends Exception { - private final String entityType; - private final String osid; - public NotFoundException(String entityType, String osid) { - super(String.format("Record not found of type %s with id %s", entityType, osid)); - this.entityType = entityType; - this.osid = osid; + public NotFoundException(String entityType, String uuidPropertyValue) { + super(String.format("Record not found of type %s with id %s", entityType, uuidPropertyValue)); } } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/RegistryDaoImpl.java b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/RegistryDaoImpl.java index e8b0fb955..fa1be8778 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/RegistryDaoImpl.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/RegistryDaoImpl.java @@ -99,12 +99,12 @@ public void updateVertex(Graph graph, Vertex vertex, JsonNode inputJsonNode, Str if (inputJsonNode.isObject()) { String objectName = inputJsonNode.fields().next().getKey(); logger.debug("Going to update objectName {}", objectName); - JsonNode osidJsonNode = inputJsonNode.get(uuidPropertyName); - String osidVal = ""; - if (osidJsonNode != null) { - osidVal = osidJsonNode.textValue(); + JsonNode uuidJsonNode = inputJsonNode.get(uuidPropertyName); + String uuidPropertyValue = ""; + if (uuidJsonNode != null) { + uuidPropertyValue = uuidJsonNode.textValue(); } - if (databaseProvider.getId(vertex).equals(osidVal)) { + if (databaseProvider.getId(vertex).equals(uuidPropertyValue)) { updateObject(graph, vertex, (ObjectNode) inputJsonNode); } else { VertexWriter vertexWriter = new VertexWriter(graph, getDatabaseProvider(), uuidPropertyName); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexReader.java b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexReader.java index fcae8748c..f63d939ff 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexReader.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexReader.java @@ -335,13 +335,13 @@ private ArrayNode expandChildObject(ObjectNode entityNode, List processe Map.Entry item = entryIterator.next(); JsonNode ar = item.getValue(); for (JsonNode node : ar) { - String osidVal; + String uuidPropertyValue; if (node.isObject()) { - osidVal = ArrayHelper.unquoteString(node.get(uuidPropertyName).asText()); + uuidPropertyValue = ArrayHelper.unquoteString(node.get(uuidPropertyName).asText()); } else { - osidVal = ArrayHelper.unquoteString(node.asText()); + uuidPropertyValue = ArrayHelper.unquoteString(node.asText()); } - ObjectNode ovalue = uuidNodeMap.getOrDefault(osidVal, null); + ObjectNode ovalue = uuidNodeMap.getOrDefault(uuidPropertyValue, null); expandChildObject(ovalue, currentLevel + 1); if (ovalue != null) { resultArr.add(ovalue); @@ -375,27 +375,27 @@ private ArrayNode expandChildObject(ObjectNode entityNode, List processe * Neo4j supports custom ids and so we can directly query vertex with id - without client side filtering. * SqlG does not support custom id, but the result is direct from the database without client side filtering * unlike Neo4j. - * @param osid the osid of vertex to be loaded - * @return the vertex associated with osid passed + * @param uuidPropertyValue the uuidPropertyValue of vertex to be loaded + * @return the vertex associated with uuidPropertyValue passed */ - public Vertex getVertex(String entityType, String osid) { + public Vertex getVertex(String entityType, String uuidPropertyValue) { Vertex vertex = null; Iterator itrV = null; switch (databaseProvider.getProvider()) { case NEO4J: - itrV = graph.vertices(osid); + itrV = graph.vertices(uuidPropertyValue); break; case SQLG: case CASSANDRA: case TINKERGRAPH: if (null != entityType) { - itrV = graph.traversal().clone().V().hasLabel(entityType).has(uuidPropertyName, osid); + itrV = graph.traversal().clone().V().hasLabel(entityType).has(uuidPropertyName, uuidPropertyValue); } else { - itrV = graph.traversal().clone().V().has(uuidPropertyName, osid); + itrV = graph.traversal().clone().V().has(uuidPropertyName, uuidPropertyValue); } break; default: - itrV = graph.vertices(osid); + itrV = graph.vertices(uuidPropertyValue); break; } @@ -434,18 +434,18 @@ public String getInternalType(Vertex vertex) { /** * Hits the database to read contents * This is the entry function to read contents of a given entity - * @param osid + * @param uuidPropertyValue * the id to be read * @return * @throws Exception */ - public JsonNode read(String entityType, String osid) throws Exception { - rootVertex = getVertex(entityType, osid); + public JsonNode read(String entityType, String uuidPropertyValue) throws Exception { + rootVertex = getVertex(entityType, uuidPropertyValue); return readInternal(rootVertex); } - public JsonNode read(String osid) throws Exception { - rootVertex = getVertex(null, osid); + public JsonNode read(String uuidPropertyValue) throws Exception { + rootVertex = getVertex(null, uuidPropertyValue); return readInternal(rootVertex); } @@ -501,8 +501,8 @@ private void expandReferenceNodes(ObjectNode rootNode) { String pattern = "^"+ DID_TYPE+":[^:]+:[^:]+"; if(entry.getValue().isValueNode() && entry.getValue().asText().matches(pattern)) { String[] dids = entry.getValue().asText().split(":"); - String osid = RecordIdentifier.parse(dids[2]).getUuid(); - Iterator vertexIterator = graph.traversal().clone().V().hasLabel(dids[1]).has(uuidPropertyName, osid); + String uuidPropertyValue = RecordIdentifier.parse(dids[2]).getUuid(); + Iterator vertexIterator = graph.traversal().clone().V().hasLabel(dids[1]).has(uuidPropertyName, uuidPropertyValue); while (vertexIterator.hasNext()) { Vertex dependent = vertexIterator.next(); ObjectNode references; diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexWriter.java b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexWriter.java index f34939e22..71e7fcbaa 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexWriter.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/VertexWriter.java @@ -2,12 +2,10 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import dev.sunbirdrc.registry.middleware.util.Constants; import dev.sunbirdrc.registry.sink.DatabaseProvider; import dev.sunbirdrc.registry.util.ArrayHelper; -import dev.sunbirdrc.registry.util.RecordIdentifier; import dev.sunbirdrc.registry.util.RefLabelHelper; import dev.sunbirdrc.registry.util.TypePropertyHelper; import org.apache.tinkerpop.gremlin.process.traversal.P; @@ -18,15 +16,12 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; -import static dev.sunbirdrc.registry.middleware.util.Constants.DID_TYPE; - /** * Helps in writing a vertex, edge into the database */ @@ -34,7 +29,7 @@ public class VertexWriter { private String uuidPropertyName; private Graph graph; private DatabaseProvider databaseProvider; - private String parentOSid; + private String parentUUIDPropertyValue; private static final String EMPTY_STR = ""; private Logger logger = LoggerFactory.getLogger(VertexWriter.class); @@ -138,7 +133,7 @@ private void writeArrayNode(Vertex vertex, String entryKey, ArrayNode arrayNode, Vertex blankNode = vertex; String label; - identifyParentOSid(vertex); + identifyParentUuid(vertex); if (isArrayItemObject) { label = RefLabelHelper.getArrayLabel(entryKey, uuidPropertyName); @@ -154,7 +149,7 @@ private void writeArrayNode(Vertex vertex, String entryKey, ArrayNode arrayNode, removeExistingDefaultProperty(vertex, entryKey); vertex.property(label, databaseProvider.getId(blankNode)); blankNode.property(Constants.INTERNAL_TYPE_KEYWORD, entryKey); - blankNode.property(Constants.ROOT_KEYWORD, parentOSid); + blankNode.property(Constants.ROOT_KEYWORD, parentUUIDPropertyValue); } for (JsonNode jsonNode : arrayNode) { @@ -162,7 +157,7 @@ private void writeArrayNode(Vertex vertex, String entryKey, ArrayNode arrayNode, Vertex createdV = processNode(entryKey, jsonNode); ObjectNode objectNode = (ObjectNode) jsonNode; objectNode.put(uuidPropertyName,databaseProvider.getId(createdV)); - createdV.property(Constants.ROOT_KEYWORD, parentOSid); + createdV.property(Constants.ROOT_KEYWORD, parentUUIDPropertyValue); uidList.add(databaseProvider.getId(createdV)); if (isSignature) { Edge e = addEdge(Constants.SIGNATURE_FOR+Constants.ARRAY_ITEM, blankNode, createdV); @@ -197,24 +192,24 @@ public Vertex writeSingleNode(Vertex parentVertex, String label, JsonNode entryV object.put(uuidPropertyName,idToSet); parentVertex.property(RefLabelHelper.getLabel(label, uuidPropertyName), idToSet); - identifyParentOSid(parentVertex); - v.property(Constants.ROOT_KEYWORD, parentOSid); + identifyParentUuid(parentVertex); + v.property(Constants.ROOT_KEYWORD, parentUUIDPropertyValue); logger.debug("Added edge between {} and {}", parentVertex.label(), v.label()); return v; } - private void identifyParentOSid(Vertex vertex) { + private void identifyParentUuid(Vertex vertex) { // This attribute will help identify the root from any child - if (parentOSid == null || parentOSid.isEmpty()) { - parentOSid = databaseProvider.getId(vertex); + if (parentUUIDPropertyValue == null || parentUUIDPropertyValue.isEmpty()) { + parentUUIDPropertyValue = databaseProvider.getId(vertex); } } private Vertex processNode(String label, JsonNode jsonObject) { Vertex vertex = createVertex(label); - identifyParentOSid(vertex); + identifyParentUuid(vertex); jsonObject.fields().forEachRemaining(entry -> { JsonNode entryValue = entry.getValue(); @@ -254,7 +249,7 @@ public Edge addEdge(String label, Vertex v1, Vertex v2) { */ public String writeNodeEntity(JsonNode node) { Vertex resultVertex = null; - String rootOsid = null; + String rootUuidPropertyValue = null; Iterator> entryIterator = node.fields(); while (entryIterator.hasNext()) { Map.Entry entry = entryIterator.next(); @@ -263,11 +258,11 @@ public String writeNodeEntity(JsonNode node) { // parent name/definition if (entry.getValue().isObject()) { resultVertex = processNode(entry.getKey(), entry.getValue()); - rootOsid = databaseProvider.getId(resultVertex); - entryObject.put(uuidPropertyName,rootOsid); + rootUuidPropertyValue = databaseProvider.getId(resultVertex); + entryObject.put(uuidPropertyName,rootUuidPropertyValue); } } - return rootOsid; + return rootUuidPropertyValue; } } \ No newline at end of file diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationPolicy.java b/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationPolicy.java index c85f0f170..d135973fa 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationPolicy.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationPolicy.java @@ -1,6 +1,9 @@ package dev.sunbirdrc.registry.entities; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AllArgsConstructor; @@ -11,10 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; @JsonIgnoreProperties(ignoreUnknown = true) @Builder @@ -24,7 +24,7 @@ public class AttestationPolicy { private static final Logger logger = LoggerFactory.getLogger(AttestationPolicy.class); - private String osid; + private Map additionalProperties = new HashMap<>(); private final static String PLUGIN_SPLITTER = ":"; @@ -77,6 +77,20 @@ public String getAttestorEntity() { return split.length == 2 ? split[1] : ""; } + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + additionalProperties.put(name, value); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + public Object getProperty(String name) { + return additionalProperties.get(name); + } + public String getNodePath() { return name + "/[]"; } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationStep.java b/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationStep.java index 24567ff87..bb3970cb6 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationStep.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/entities/AttestationStep.java @@ -1,11 +1,26 @@ package dev.sunbirdrc.registry.entities; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import lombok.Data; +import java.util.HashMap; +import java.util.Map; + @Data public class AttestationStep { - private String osid; + private Map additionalProperties = new HashMap<>(); private String apiURL; private String apiMethod; private String apiRequestSchema; + + @JsonAnySetter + public void setAdditionalProperty(String name, String value) { + additionalProperties.put(name, value); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java b/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java index bc304a9f1..e87fb2b29 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java @@ -439,7 +439,7 @@ public void addEntityProperty(String entityName, String entityId, JsonNode input public String triggerAttestation(AttestationRequest attestationRequest, AttestationPolicy attestationPolicy) throws Exception { addAttestationProperty(attestationRequest); //TODO: remove reading the entity after update - String attestationOSID = getAttestationOSID(attestationRequest); + String attestationUUIDPropertyValue = getAttestationUUIDPropertyValue(attestationRequest); String condition = ""; if (attestationPolicy.isInternal()) { @@ -456,14 +456,14 @@ public String triggerAttestation(AttestationRequest attestationRequest, Attestat } PluginRequestMessage message = PluginRequestMessageCreator.create( - propertyData, condition, attestationOSID, attestationRequest.getEntityName(), + propertyData, condition, attestationUUIDPropertyValue, attestationRequest.getEntityName(), attestationRequest.getEmailId(), attestationRequest.getEntityId(), attestationRequest.getAdditionalInput(), Action.RAISE_CLAIM.name(), attestationPolicy.getName(), attestationPolicy.getAttestorPlugin(), attestationPolicy.getAttestorEntity(), attestationPolicy.getAttestorSignin(), - attestationRequest.getPropertiesOSID(), attestationRequest.getEmailId()); + attestationRequest.getPropertiesUUID(uuidPropertyName), attestationRequest.getEmailId()); PluginRouter.route(message); - return attestationOSID; + return attestationUUIDPropertyValue; } @@ -489,13 +489,12 @@ private void updateGetFileUrl(JsonNode additionalInput) throws UnreachableExcept } } - private String getAttestationOSID(AttestationRequest attestationRequest) throws Exception { + private String getAttestationUUIDPropertyValue(AttestationRequest attestationRequest) throws Exception { JsonNode resultNode = readEntity("", attestationRequest.getEntityName(), attestationRequest.getEntityId(), false, null, false) .get(attestationRequest.getEntityName()) .get(attestationRequest.getName()); - List fieldsToRemove = getFieldsToRemove(attestationRequest.getEntityName()); - return JSONUtil.getOSIDFromArrNode(resultNode, JSONUtil.convertObjectJsonNode(attestationRequest), fieldsToRemove); + return JSONUtil.getUUIDPropertyValueFromArrNode(uuidPropertyName, AttestationRequest.PropertiesUUIDKey(uuidPropertyName), resultNode, JSONUtil.convertObjectJsonNode(attestationRequest)); } private void addAttestationProperty(AttestationRequest attestationRequest) throws Exception { @@ -596,12 +595,12 @@ public void attestEntity(String entityName, JsonNode node, String[] jsonPaths, S public void updateState(PluginResponseMessage pluginResponseMessage) throws Exception { String attestationName = pluginResponseMessage.getPolicyName(); - String attestationOSID = pluginResponseMessage.getAttestationOSID(); + String attestationUUID = pluginResponseMessage.getAttestationUUID(); String sourceEntity = pluginResponseMessage.getSourceEntity(); AttestationPolicy attestationPolicy = getAttestationPolicy(sourceEntity, attestationName); String userId = ""; - JsonNode root = readEntity(userId, sourceEntity, pluginResponseMessage.getSourceOSID(), false, null, false); + JsonNode root = readEntity(userId, sourceEntity, pluginResponseMessage.getSourceUUID(), false, null, false); ObjectNode metaData = JsonNodeFactory.instance.objectNode(); JsonNode additionalData = pluginResponseMessage.getAdditionalData(); Action action = Action.valueOf(pluginResponseMessage.getStatus()); @@ -609,7 +608,7 @@ public void updateState(PluginResponseMessage pluginResponseMessage) throws Exce switch (action) { case GRANT_CLAIM: Object credentialTemplate = attestationPolicy.getCredentialTemplate(); - // checking size greater than 1, bcz empty template contains osid field + // checking size greater than 1, bcz empty template contains uuid property field if (credentialTemplate != null && !credentialTemplate.toString().isEmpty()) { JsonNode response = objectMapper.readTree(pluginResponseMessage.getResponse()); if (!signatureEnabled) { @@ -647,7 +646,7 @@ public void updateState(PluginResponseMessage pluginResponseMessage) throws Exce additionalData.get(CLAIM_ID).asText("") ); } - String propertyURI = attestationName + "/" + attestationOSID; + String propertyURI = attestationName + "/" + attestationUUID; uploadAttestedFiles(pluginResponseMessage, metaData); JsonNode nodeToUpdate = entityStateHelper.manageState(attestationPolicy, root, propertyURI, action, metaData); updateEntity(nodeToUpdate, userId, true); @@ -661,9 +660,11 @@ private void triggerNextFLowIfExists(PluginResponseMessage pluginResponseMessage try { AttestationPolicy nextAttestationPolicy = getAttestationPolicy(sourceEntity, attestationPolicy.getCompletionValue()); AttestationRequest attestationRequest = AttestationRequest.builder().entityName(pluginResponseMessage.getSourceEntity()) - .entityId(pluginResponseMessage.getSourceOSID()).name(attestationPolicy.getCompletionValue()) + .entityId(pluginResponseMessage.getSourceUUID()).name(attestationPolicy.getCompletionValue()) .additionalInput(pluginResponseMessage.getAdditionalData()).emailId(pluginResponseMessage.getEmailId()) - .userId(pluginResponseMessage.getUserId()).propertiesOSID(pluginResponseMessage.getPropertiesOSID()) + .userId(pluginResponseMessage.getUserId()) + .additionalProperties(Collections.singletonMap(AttestationRequest.PropertiesUUIDKey(uuidPropertyName), pluginResponseMessage.getPropertiesUUIDs())) +// .propertiesOSID(pluginResponseMessage.getPropertiesUUIDs()) .propertyData(JSONUtil.convertStringJsonNode(pluginResponseMessage.getResponse())).build(); triggerAttestation(attestationRequest, nextAttestationPolicy); } catch (PolicyNotFoundException e) { @@ -715,7 +716,7 @@ private void uploadAttestedFiles(PluginResponseMessage pluginResponseMessage, Ob ArrayNode fileUris = JsonNodeFactory.instance.arrayNode(); pluginResponseMessage.getFiles().forEach(file -> { String propertyURI = String.format("%s/%s/%s/documents/%s", pluginResponseMessage.getSourceEntity(), - pluginResponseMessage.getSourceOSID(), pluginResponseMessage.getPolicyName(), file.getFileName()); + pluginResponseMessage.getSourceUUID(), pluginResponseMessage.getPolicyName(), file.getFileName()); try { fileStorageService.save(new ByteArrayInputStream(file.getFile()), propertyURI); } catch (Exception e) { @@ -1057,13 +1058,14 @@ public String getPropertyToUpdate(HttpServletRequest request, String entityId){ } private void updateAttestation(String attestorEntity, String userId, JsonNode entity, ArrayNode attestations,String propertyToUpdate, AttestationPolicy attestationPolicy) throws Exception { + String propertiesUUIDKey = AttestationRequest.PropertiesUUIDKey(uuidPropertyName); for (JsonNode attestation : attestations) { if (attestation.get(_osState.name()).asText().equals(States.PUBLISHED.name()) && !attestation.get("name").asText().equals(propertyToUpdate) ){ - if(attestation.has("propertiesOSID")) { - ObjectNode propertiesOSID = attestation.get("propertiesOSID").deepCopy(); - JSONUtil.removeNode(propertiesOSID, uuidPropertyName); + if(attestation.has(propertiesUUIDKey)) { + ObjectNode propertiesUUID = attestation.get(propertiesUUIDKey).deepCopy(); + JSONUtil.removeNode(propertiesUUID, uuidPropertyName); } if(attestationPolicy.getCredentialTemplate() != null && OSSystemFields.attestation.hasCredential(GenericConfiguration.getSignatureProvider(), attestation)) { signatureHelper.revoke( @@ -1074,20 +1076,20 @@ 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())) { - JsonNode propertyData = JSONUtil.extractPropertyDataFromEntity(entity, attestationPolicy.getAttestationProperties(), null); - if (attestation.has("propertiesOSID")) { - ObjectNode propertiesOSID = attestations.get("propertiesOSID").deepCopy(); - Map> propertiesOSIDMapper = new HashMap<>(); + JsonNode propertyData = JSONUtil.extractPropertyDataFromEntity(uuidPropertyName, entity, attestationPolicy.getAttestationProperties(), null); + if (attestation.has(propertiesUUIDKey)) { + ObjectNode propertiesUUIDs = attestations.get(propertiesUUIDKey).deepCopy(); + Map> propertiesUUIDMapper = new HashMap<>(); ObjectReader reader = objectMapper.readerFor(new TypeReference>() { }); - for (Iterator> it = propertiesOSID.fields(); it.hasNext(); ) { + for (Iterator> it = propertiesUUIDs.fields(); it.hasNext(); ) { Map.Entry itr = it.next(); if(itr.getValue().isArray() && !itr.getValue().isEmpty() && itr.getValue().get(0).isTextual()) { List list = reader.readValue(itr.getValue()); - propertiesOSIDMapper.put(itr.getKey(), list); + propertiesUUIDMapper.put(itr.getKey(), list); } } - propertyData = JSONUtil.extractPropertyDataFromEntity(entity, attestationPolicy.getAttestationProperties(), propertiesOSIDMapper); + propertyData = JSONUtil.extractPropertyDataFromEntity(uuidPropertyName, entity, attestationPolicy.getAttestationProperties(), propertiesUUIDMapper); } if(!propertyData.equals(JSONUtil.convertStringJsonNode(attestation.get("propertyData").asText()))) { @@ -1268,15 +1270,15 @@ public String updateAttestationPolicy(String userId, AttestationPolicy attestati return updateProperty(updateJson, userId); } - public Optional findAttestationPolicyById(String userId, String policyOSID) throws Exception { - JsonNode jsonNode = readEntity(userId, ATTESTATION_POLICY, policyOSID, false, null, false) + public Optional findAttestationPolicyById(String userId, String policyUUID) throws Exception { + JsonNode jsonNode = readEntity(userId, ATTESTATION_POLICY, policyUUID, false, null, false) .get(ATTESTATION_POLICY); return Optional.of(objectMapper.treeToValue(jsonNode, AttestationPolicy.class)); } public void deleteAttestationPolicy(String entityName, AttestationPolicy attestationPolicy) throws Exception { - deleteEntity(entityName, attestationPolicy.getOsid(), attestationPolicy.getCreatedBy()); + deleteEntity(entityName, (String) attestationPolicy.getProperty(uuidPropertyName), attestationPolicy.getCreatedBy()); } public boolean doesEntityOperationRequireAuthorization(String entity) { @@ -1290,8 +1292,8 @@ boolean hasAttestationPropertiesChanged(JsonNode updatedNode, JsonNode existingN JsonNode extractedExistingAttestationNode = null; JsonNode extractedUpdatedAttestationNode = null; try { - extractedExistingAttestationNode = JSONUtil.extractPropertyDataFromEntity(existingNode.get(entityName), attestationPolicy.getAttestationProperties(), null); - extractedUpdatedAttestationNode = JSONUtil.extractPropertyDataFromEntity(updatedNode, attestationPolicy.getAttestationProperties(), null); + extractedExistingAttestationNode = JSONUtil.extractPropertyDataFromEntity(uuidPropertyName, existingNode.get(entityName), attestationPolicy.getAttestationProperties(), null); + extractedUpdatedAttestationNode = JSONUtil.extractPropertyDataFromEntity(uuidPropertyName, updatedNode, attestationPolicy.getAttestationProperties(), null); if(!StringUtils.isEmpty(path) && !(extractedExistingAttestationNode.toString()) .equals(extractedUpdatedAttestationNode.toString())) { result = true; @@ -1315,7 +1317,7 @@ public void autoRaiseClaim(String entityName, String entityId, String userId, Js attestationRequest.setEntityId(entityId); attestationRequest.setName(attestationPolicy.getName()); attestationRequest.setEntityName(entityName); - JsonNode node = JSONUtil.extractPropertyDataFromEntity(updatedNode, attestationPolicy.getAttestationProperties(), new HashMap<>()); + JsonNode node = JSONUtil.extractPropertyDataFromEntity(uuidPropertyName, updatedNode, attestationPolicy.getAttestationProperties(), new HashMap<>()); attestationRequest.setPropertyData(node); attestationRequest.setUserId(userId); attestationRequest.setEmailId(emailId); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/AttestationRequest.java b/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/AttestationRequest.java index 3e2b193b1..b48eb0769 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/AttestationRequest.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/AttestationRequest.java @@ -1,5 +1,7 @@ package dev.sunbirdrc.registry.model.dto; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.databind.JsonNode; import lombok.AllArgsConstructor; import lombok.Builder; @@ -7,6 +9,7 @@ import lombok.NoArgsConstructor; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,8 +23,31 @@ public class AttestationRequest { private String name; private String userId; private JsonNode additionalInput; - private Map> propertiesOSID; +// private Map> propertiesOSID; private JsonNode propertyData; private String emailId; private String osCreatedAt; + private Map additionalProperties = new HashMap<>(); + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + additionalProperties.put(name, value); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + public Object getProperty(String name) { + return additionalProperties.get(name); + } + + public static String PropertiesUUIDKey(String uuidPropertyName) { + return "properties" + uuidPropertyName.toUpperCase(); + } + + public Map> getPropertiesUUID(String uuidPropertyName) { + return (Map>) getProperty(PropertiesUUIDKey(uuidPropertyName)); + } } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/PostCreateEntityMessage.java b/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/PostCreateEntityMessage.java index 34b9c7f15..eed55a6bb 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/PostCreateEntityMessage.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/model/dto/PostCreateEntityMessage.java @@ -12,7 +12,7 @@ public class PostCreateEntityMessage { private String userId; private String entityType; - private String osid; + private String uuid; private String transactionId; private CreateEntityStatus status; private String message; diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticReadService.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticReadService.java index 5456d91d9..9d0d38646 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticReadService.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticReadService.java @@ -49,7 +49,7 @@ public class ElasticReadService implements IReadService { /** * This method interacts with the Elasticsearch and reads the record * - * @param id - osid + * @param id - uuid property value * @param entityType - elastic-search index * @param configurator * @return diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticSearchService.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticSearchService.java index 9131046de..15d44161d 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticSearchService.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ElasticSearchService.java @@ -31,8 +31,7 @@ import dev.sunbirdrc.registry.middleware.util.Constants; import dev.sunbirdrc.registry.util.RecordIdentifier; -import static dev.sunbirdrc.registry.middleware.util.Constants.DID_TYPE; -import static dev.sunbirdrc.registry.middleware.util.Constants.ENTITY_TYPE; +import static dev.sunbirdrc.registry.middleware.util.Constants.*; /** * This class provide search option with Elastic search Hits elastic search @@ -124,7 +123,7 @@ public JsonNode search(JsonNode inputQueryNode, String userId) throws IOExceptio private ArrayNode expandReference(JsonNode searchedNode) { ArrayNode arrayNode = (ArrayNode) searchedNode; ArrayNode nodeWithExpandedReference = JsonNodeFactory.instance.arrayNode(); - HashMap> indexOsidsMap = new HashMap<>(); + HashMap> indexUuidsMap = new HashMap<>(); for (JsonNode node : arrayNode) { ObjectNode objectNode = (ObjectNode) node; objectNode.fields().forEachRemaining(objectField -> { @@ -132,24 +131,24 @@ private ArrayNode expandReference(JsonNode searchedNode) { if(objectField.getValue().asText().matches(pattern)) { String[] referenceStrSplit = objectField.getValue().asText().split(":"); String indexName = referenceStrSplit[1].toLowerCase(); - String osid = referenceStrSplit[2]; - List osids; - if(indexOsidsMap.get(indexName) == null) { - osids = new ArrayList(); + String uuidPropertyValue = referenceStrSplit[2]; + List uuidPropertyValues; + if(indexUuidsMap.get(indexName) == null) { + uuidPropertyValues = new ArrayList(); } else { - osids = indexOsidsMap.get(indexName); + uuidPropertyValues = indexUuidsMap.get(indexName); } - osids.add(osid); - indexOsidsMap.put(indexName, osids); + uuidPropertyValues.add(uuidPropertyValue); + indexUuidsMap.put(indexName, uuidPropertyValues); } }); } SearchQuery searchQuery = null; ArrayNode referenceNodes = JsonNodeFactory.instance.arrayNode(); - for (Map.Entry> indexOsidEntry: indexOsidsMap.entrySet()) { + for (Map.Entry> indexUuidPropertyEntry: indexUuidsMap.entrySet()) { try { - searchQuery = getSearchQuery(indexOsidEntry.getKey(), indexOsidEntry.getValue()); - referenceNodes.addAll((ArrayNode) elasticService.search(indexOsidEntry.getKey(), searchQuery)); + searchQuery = getSearchQuery(indexUuidPropertyEntry.getKey(), indexUuidPropertyEntry.getValue()); + referenceNodes.addAll((ArrayNode) elasticService.search(indexUuidPropertyEntry.getKey(), searchQuery)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } catch (IOException e) { @@ -162,9 +161,9 @@ private ArrayNode expandReference(JsonNode searchedNode) { objectNode.fields().forEachRemaining(objectField -> { if (objectField.getValue().asText().startsWith("did:")) { String[] referenceStrSplit = objectField.getValue().asText().split(":"); - String osid = referenceStrSplit[2]; + String uuidPropertyValue = referenceStrSplit[2]; for(JsonNode referenceNode: finalReferenceNodes) { - if(referenceNode.get("osid").textValue().contains(osid)) { + if(referenceNode.get(uuidPropertyName).textValue().contains(uuidPropertyValue)) { objectNode.set(objectField.getKey(), referenceNode); } } @@ -175,32 +174,21 @@ private ArrayNode expandReference(JsonNode searchedNode) { return nodeWithExpandedReference; } - private SearchQuery getSearchQuery(String entityName, String osid) throws JsonProcessingException { - String filter = "{\"filters\": {\"osid\":{ \"eq\":\"" + osid + "\"}}}"; - ObjectNode jsonNode = (ObjectNode) objectMapper.readTree(filter); - ArrayNode entity = JsonNodeFactory.instance.arrayNode(); - entity.add(entityName); - jsonNode.set(ENTITY_TYPE, entity); - SearchQuery searchQuery1 = getSearchQuery(jsonNode, offset, limit); - return searchQuery1; - } - - private SearchQuery getSearchQuery(String entityName, List osids) throws JsonProcessingException { - ArrayNode osidsArrayNode = JsonNodeFactory.instance.arrayNode(); - for (String osid: osids) { - osidsArrayNode.add("1-"+osid); + private SearchQuery getSearchQuery(String entityName, List uuidPropertyValues) throws JsonProcessingException { + ArrayNode uuidPropertyValuesArrayNode = JsonNodeFactory.instance.arrayNode(); + for (String uuidPropertyValue: uuidPropertyValues) { + uuidPropertyValuesArrayNode.add("1-"+uuidPropertyValue); } ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); ObjectNode conditionNode = JsonNodeFactory.instance.objectNode(); - conditionNode.set("or", osidsArrayNode); - ObjectNode osidFilterNode = JsonNodeFactory.instance.objectNode(); - osidFilterNode.set("osid", conditionNode); - objectNode.set("filters", osidFilterNode); + conditionNode.set("or", uuidPropertyValuesArrayNode); + ObjectNode uuidPropertyValueFilterNode = JsonNodeFactory.instance.objectNode(); + uuidPropertyValueFilterNode.set(uuidPropertyName, conditionNode); + objectNode.set(FILTERS, uuidPropertyValueFilterNode); ArrayNode entity = JsonNodeFactory.instance.arrayNode(); entity.add(entityName); objectNode.set(ENTITY_TYPE, entity); - SearchQuery searchQuery1 = getSearchQuery(objectNode, offset, limit); - return searchQuery1; + return getSearchQuery(objectNode, offset, limit); } private void updateStatusFilter(SearchQuery searchQuery) { diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeReadService.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeReadService.java index 7bc647770..c94e48b37 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeReadService.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeReadService.java @@ -53,7 +53,7 @@ public class NativeReadService implements IReadService { /** * This method interacts with the native db and reads the record * - * @param id - osid + * @param id - UUID Property Value * @param entityType * @param configurator * @return @@ -69,7 +69,7 @@ public JsonNode getEntity(Shard shard, String userId, String id, String entityTy JsonNode result = registryDao.getEntity(graph, entityType, id, configurator); if (!shard.getShardLabel().isEmpty()) { - // Replace osid with shard details + // Replace uuid property value with shard details String prefix = shard.getShardLabel() + RecordIdentifier.getSeparator(); JSONUtil.addPrefix((ObjectNode) result, prefix, new ArrayList(Arrays.asList(uuidPropertyName))); } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java index dad499634..cccf43b22 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java @@ -131,7 +131,7 @@ public JsonNode search(JsonNode inputQueryNode, String userId, boolean skipRemov try (Transaction tx = shard.getDatabaseProvider().startTransaction(graph)) { ObjectNode shardResult = (ObjectNode) searchDao.search(graph, searchQuery, expandInternal); if (!shard.getShardLabel().isEmpty()) { - // Replace osid with shard details + // Replace uuidPropertyValue with shard details String prefix = shard.getShardLabel() + RecordIdentifier.getSeparator(); JSONUtil.addPrefix((ObjectNode) shardResult, prefix, new ArrayList<>(Arrays.asList(uuidPropertyName))); } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/RegistryServiceImpl.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/RegistryServiceImpl.java index f6f9e6f8e..989037820 100755 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/RegistryServiceImpl.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/RegistryServiceImpl.java @@ -266,7 +266,7 @@ public String addEntity(Shard shard, String userId, JsonNode rootNode, boolean s if (isElasticSearchEnabled()) { if (addShardPrefixForESRecord && !shard.getShardLabel().isEmpty()) { - // Replace osid with shard details + // Replace uuid property value with shard details String prefix = shard.getShardLabel() + RecordIdentifier.getSeparator(); JSONUtil.addPrefix((ObjectNode) rootNode, prefix, new ArrayList<>(Collections.singletonList(uuidPropertyName))); } @@ -346,20 +346,6 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin logger.debug("After merge the payload is " + mergedNode.toString()); // TODO: need to revoke and re-sign the entity // Re-sign, i.e., remove and add entity signature again -/* - if (signatureEnabled) { - logger.debug("Removing earlier signature and adding new one"); - String entitySignUUID = signatureHelper.removeEntitySignature(parentEntityType, (ObjectNode) mergedNode); - JsonNode newSignature = signatureHelper.signJson(mergedNode); - String rootOsid = mergedNode.get(entityType).get(uuidPropertyName).asText(); - ObjectNode objectSignNode = (ObjectNode) newSignature; - objectSignNode.put(uuidPropertyName, entitySignUUID); - objectSignNode.put(Constants.ROOT_KEYWORD, rootOsid); - Vertex oldEntitySignatureVertex = uuidVertexMap.get(entitySignUUID); - - registryDao.updateVertex(graph, oldEntitySignatureVertex, newSignature, entityType); - } -*/ // TODO - Validate before update JsonNode validationNode = mergedNode.deepCopy(); @@ -373,7 +359,7 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin // Finally update // Input nodes have shard labels if (!shard.getShardLabel().isEmpty()) { - // Replace osid without shard details + // Replace uuid property value without shard details String prefix = shard.getShardLabel() + RecordIdentifier.getSeparator(); JSONUtil.trimPrefix((ObjectNode) inputNode, uuidPropertyName, prefix); } @@ -397,7 +383,7 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin if (isInternalRegistry(entityType) && isElasticSearchEnabled()) { if (addShardPrefixForESRecord && !shard.getShardLabel().isEmpty()) { - // Replace osid with shard details + // Replace uuid property value with shard details String prefix = shard.getShardLabel() + RecordIdentifier.getSeparator(); JSONUtil.addPrefix((ObjectNode) mergedNode, prefix, new ArrayList<>(Collections.singletonList(uuidPropertyName))); } @@ -511,11 +497,11 @@ private void doUpdate(Shard shard, Graph graph, IRegistryDao registryDao, Vertex // Simple object - just update that object (new uuid will not be issued) // Simple NEW object - need to update the root // Array object - need to delete and then add new one - JsonNode parentOsidNode = userInputNode.get(uuidPropertyName); + JsonNode parentUuidNode = userInputNode.get(uuidPropertyName); Vertex existingVertex = null; try { - String parentOsid = (parentOsidNode == null) ? "" : parentOsidNode.textValue(); - existingVertex = uuidVertexMap.getOrDefault(parentOsid, null); + String parentUuid = (parentUuidNode == null) ? "" : parentUuidNode.textValue(); + existingVertex = uuidVertexMap.getOrDefault(parentUuid, null); } catch (IllegalStateException propException) { logger.debug("Root vertex {} doesn't have any property named {}", shard.getDatabaseProvider().getId(rootVertex), uuidPropertyName); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/SignatureV2ServiceImpl.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/SignatureV2ServiceImpl.java index 73bf89b35..8daeb36e7 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/SignatureV2ServiceImpl.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/impl/SignatureV2ServiceImpl.java @@ -37,8 +37,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Stream; -import static dev.sunbirdrc.registry.Constants.HTTPS_URI_PREFIX; -import static dev.sunbirdrc.registry.Constants.HTTP_URI_PREFIX; +import static dev.sunbirdrc.registry.Constants.*; import static dev.sunbirdrc.registry.middleware.util.Constants.CONNECTION_FAILURE; @Component @@ -63,6 +62,9 @@ public class SignatureV2ServiceImpl implements SignatureService, ICertificateSer @Value("${signature.v2.issuerDidMethod}") private String credentialIssuerMethod; + @Value("${database.uuidPropertyName}") + public String uuidPropertyName; + @Autowired protected RetryRestTemplate retryRestTemplate; @Autowired @@ -167,7 +169,7 @@ public JsonNode issueCredential(String title, Object credentialTemplate, JsonNod node.set("method", JsonNodeFactory.instance.textNode(credentialMethod)); ArrayNode tags = JsonNodeFactory.instance.arrayNode(); tags.add(title); - if(input.get("osid") != null) tags.add(input.get("osid")); + if(input.get(uuidPropertyName) != null) tags.add(input.get(uuidPropertyName)); node.set("tags", tags); // send the request and issue credential @@ -191,7 +193,7 @@ public JsonNode getCredentialById(String credentialId) throws IOException, NotFo public byte[] getCredentialById(String credentialId, String format, String templateId, String template) throws IOException, NotFoundException { HttpHeaders headers = new HttpHeaders(); headers.set("templateId", templateId); - if(template != null) headers.set("template", template.trim()); + if(template != null) headers.set(Template, template.trim()); headers.setAccept(Collections.singletonList(MediaType.valueOf(format))); ResponseEntity response = retryRestTemplate.getForObject(getCredentialByIdURL, headers, byte[].class, credentialId); if (response.getStatusCode().is2xxSuccessful()) { diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/sink/Neo4jIdProvider.java b/java/registry/src/main/java/dev/sunbirdrc/registry/sink/Neo4jIdProvider.java index bd14c68ac..886b0e80b 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/sink/Neo4jIdProvider.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/sink/Neo4jIdProvider.java @@ -16,7 +16,7 @@ public String fieldName() { /** * When read back using labels, the library gives back only the id. - * Here we are loading only the extra osid for our convenience. + * Here we are loading only the extra uuidPropertyValue for our convenience. * @param entity * @return */ diff --git a/java/registry/src/test/java/dev/sunbirdrc/registry/helper/RegistryHelperTest.java b/java/registry/src/test/java/dev/sunbirdrc/registry/helper/RegistryHelperTest.java index 80fb2b884..568303231 100644 --- a/java/registry/src/test/java/dev/sunbirdrc/registry/helper/RegistryHelperTest.java +++ b/java/registry/src/test/java/dev/sunbirdrc/registry/helper/RegistryHelperTest.java @@ -18,7 +18,6 @@ import dev.sunbirdrc.registry.middleware.util.Constants; import dev.sunbirdrc.registry.model.DBConnectionInfoMgr; import dev.sunbirdrc.registry.service.*; -import dev.sunbirdrc.registry.sink.DatabaseProvider; import dev.sunbirdrc.registry.sink.shard.Shard; import dev.sunbirdrc.registry.sink.shard.ShardManager; import dev.sunbirdrc.registry.util.*; @@ -29,8 +28,6 @@ import dev.sunbirdrc.workflow.KieConfiguration; import dev.sunbirdrc.workflow.RuleEngineService; import org.apache.commons.io.IOUtils; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.Vertex; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Before; @@ -42,11 +39,8 @@ import org.mockito.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import org.sunbird.akka.core.SunbirdActorFactory; @@ -475,10 +469,10 @@ public void shouldTriggerNextAttestationFlow() throws Exception { mockDefinitionManager(); PluginResponseMessage pluginResponseMessage = PluginResponseMessage.builder() .policyName("test") - .attestationOSID("test-1") + .attestationUUID("test-1") .sourceEntity("Student") .policyName("testAttestationPolicy") - .sourceOSID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") + .sourceUUID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") .status("GRANT_CLAIM") .response("{}") .build(); @@ -514,10 +508,10 @@ public void shouldNotTriggerNextAttestationFlowIfOnCompleteIsNotPresent() throws mockDefinitionManager(); PluginResponseMessage pluginResponseMessage = PluginResponseMessage.builder() .policyName("test") - .attestationOSID("test-1") + .attestationUUID("test-1") .sourceEntity("Student") .policyName("testAttestationPolicy") - .sourceOSID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") + .sourceUUID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") .status("GRANT_CLAIM") .response("{}") .build(); @@ -550,10 +544,10 @@ public void shouldTriggerConcatFunctionOnAttestationCompleted() throws Exception )); PluginResponseMessage pluginResponseMessage = PluginResponseMessage.builder() .policyName("test") - .attestationOSID("test-1") + .attestationUUID("test-1") .sourceEntity("Student") .policyName("testAttestationPolicy") - .sourceOSID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") + .sourceUUID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") .status("GRANT_CLAIM") .response("{}") .build(); @@ -591,10 +585,10 @@ public void shouldTriggerProviderFunctionOnAttestationCompleted() throws Excepti )); PluginResponseMessage pluginResponseMessage = PluginResponseMessage.builder() .policyName("test") - .attestationOSID("test-1") + .attestationUUID("test-1") .sourceEntity("Student") .policyName("testAttestationPolicy") - .sourceOSID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") + .sourceUUID("1-b4907dc2-d3a8-49dc-a933-2b473bdd2ddb") .status("GRANT_CLAIM") .response("{}") .build(); diff --git a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/AutoAttestorActor.java b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/AutoAttestorActor.java index 1a208cbb7..a7aa62672 100644 --- a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/AutoAttestorActor.java +++ b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/AutoAttestorActor.java @@ -31,7 +31,7 @@ public class AutoAttestorActor extends BaseActor { private static final Logger logger = LoggerFactory.getLogger(AutoAttestorActor.class); private static final String SYSTEM_PROPERTY_URL = "/api/v1/system/%s/%s"; private static final String VALUE = "value"; - private static final String UUID_PROPERTY_NAME = "osid"; + private static final String UUID_PROPERTY_NAME = System.getenv().getOrDefault("uuid_property_name", "osid"); private static final String VALID_PROPERTY = "valid"; @Override diff --git a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ClaimPluginActor.java b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ClaimPluginActor.java index bdb6106c1..3bb40f876 100644 --- a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ClaimPluginActor.java +++ b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ClaimPluginActor.java @@ -71,8 +71,8 @@ private void attestClaim(PluginRequestMessage pluginRequestMessage) throws IOExc ); ClaimDTO claimDTO = Objects.requireNonNull(responseEntity.getBody()); pluginRequestMessage.setSourceEntity(claimDTO.getEntity()); - pluginRequestMessage.setSourceOSID(claimDTO.getEntityId()); - pluginRequestMessage.setAttestationOSID(claimDTO.getAttestationId()); + pluginRequestMessage.setSourceUUID(claimDTO.getEntityId()); + pluginRequestMessage.setAttestationUUID(claimDTO.getAttestationId()); pluginRequestMessage.setPolicyName(claimDTO.getAttestationName()); pluginRequestMessage.setPropertyData(claimDTO.getPropertyData()); callPluginResponseActor(pluginRequestMessage, claimId, Action.valueOf(status)); @@ -95,12 +95,12 @@ private void riseClaim(PluginRequestMessage pluginRequestMessage) throws IOExcep ClaimDTO claimDTO = new ClaimDTO(); claimDTO.setEntity(pluginRequestMessage.getSourceEntity()); - claimDTO.setEntityId(pluginRequestMessage.getSourceOSID()); + claimDTO.setEntityId(pluginRequestMessage.getSourceUUID()); claimDTO.setPropertyURI(""); claimDTO.setPropertyData(pluginRequestMessage.getPropertyData()); claimDTO.setConditions(pluginRequestMessage.getConditions()); claimDTO.setAttestorEntity(pluginRequestMessage.getAttestorEntity()); - claimDTO.setAttestationId(pluginRequestMessage.getAttestationOSID()); + claimDTO.setAttestationId(pluginRequestMessage.getAttestationUUID()); claimDTO.setNotes(notes); claimDTO.setAttestationName(pluginRequestMessage.getPolicyName()); claimDTO.setRequestorName(pluginRequestMessage.getUserId()); diff --git a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ElasticSearchActor.java b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ElasticSearchActor.java index 1ab3ca97a..faec7cbf9 100644 --- a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ElasticSearchActor.java +++ b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/ElasticSearchActor.java @@ -22,13 +22,13 @@ public void onReceive(MessageProtos.Message request) throws Throwable { //ESMessage es = objectMapper.writeValue(request.getPayload(), ESMessage.class); switch (request.getPerformOperation()) { case "ADD": - elasticSearch.addEntity(esMessage.getIndexName(), esMessage.getOsid(), esMessage.getInput()); + elasticSearch.addEntity(esMessage.getIndexName(), esMessage.getUuidPropertyValue(), esMessage.getInput()); break; case "UPDATE": - elasticSearch.updateEntity(esMessage.getIndexName(), esMessage.getOsid(), esMessage.getInput()); + elasticSearch.updateEntity(esMessage.getIndexName(), esMessage.getUuidPropertyValue(), esMessage.getInput()); break; case "DELETE": - elasticSearch.deleteEntity(esMessage.getIndexName(), esMessage.getOsid()); + elasticSearch.deleteEntity(esMessage.getIndexName(), esMessage.getUuidPropertyValue()); break; case "READ": break; diff --git a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/PluginResponseActor.java b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/PluginResponseActor.java index cfea73474..7ee610e3a 100644 --- a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/PluginResponseActor.java +++ b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/PluginResponseActor.java @@ -48,7 +48,7 @@ private void callUpdateAttestationAPI(PluginResponseMessage pluginResponseMessag HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity entity = new HttpEntity<>(pluginResponseMessage, headers); - String uri = String.format(SYSTEM_PROPERTY_URL, pluginResponseMessage.getSourceEntity(), pluginResponseMessage.getSourceOSID(), pluginResponseMessage.getPolicyName(), pluginResponseMessage.getAttestationOSID()); + String uri = String.format(SYSTEM_PROPERTY_URL, pluginResponseMessage.getSourceEntity(), pluginResponseMessage.getSourceUUID(), pluginResponseMessage.getPolicyName(), pluginResponseMessage.getAttestationUUID()); RestTemplate restTemplate = new RestTemplate(); ResponseEntity responseEntity = restTemplate.exchange(REGISTRY_HOST_URL + uri, HttpMethod.PUT, entity, ResponseParams.class); logger.info("Update status api call's status {}", responseEntity.getStatusCode()); diff --git a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/factory/MessageFactory.java b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/factory/MessageFactory.java index 1e4a2c9a9..bc45ad09c 100644 --- a/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/factory/MessageFactory.java +++ b/java/sunbirdrc-actors/src/main/java/dev/sunbirdrc/actors/factory/MessageFactory.java @@ -47,7 +47,7 @@ public MessageProtos.Message createAuditMessage(AuditRecord auditRecord) throws return msgBuilder.build(); } - public MessageProtos.Message createOSActorMessage(boolean esEnabled, String operation, String index, String osid, JsonNode latestNode, + public MessageProtos.Message createOSActorMessage(boolean esEnabled, String operation, String index, String uuidPropertyValue, JsonNode latestNode, AuditRecord auditRecord) throws JsonProcessingException { MessageProtos.Message.Builder msgBuilder = MessageProtos.Message.newBuilder(); msgBuilder.setPerformOperation(operation); @@ -55,7 +55,7 @@ public MessageProtos.Message createOSActorMessage(boolean esEnabled, String oper Value.Builder payloadBuilder = msgBuilder.getPayloadBuilder(); ESMessage esMessage = new ESMessage(); esMessage.setIndexName(index); - esMessage.setOsid(osid); + esMessage.setUuidPropertyValue(uuidPropertyValue); esMessage.setInput(latestNode); ObjectMapper objectMapper = new ObjectMapper(); OSEvent osEvent = new OSEvent();