Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for updateVC #240

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ public ResponseEntity<Object> putEntity(
watch.start(tag);
JsonNode existingNode = registryHelper.readEntity(newRootNode, userId);
String emailId = registryHelper.fetchEmailIdFromToken(request, entityName);
registryHelper.updateEntityAndState(existingNode, newRootNode, userId);
if (existingNode.get(entityName).has(OSSystemFields._osSignedData.name())) {
registryHelper.revokeExistingCredentials(entityName, entityId, userId,
existingNode.get(entityName).get(OSSystemFields._osSignedData.name()).asText(""));
}
registryHelper.updateEntityAndState(existingNode, newRootNode, userId);
registryHelper.invalidateAttestation(entityName, entityId, userId, null);
registryHelper.autoRaiseClaim(entityName, entityId, userId, existingNode, newRootNode, emailId);
responseParams.setErrmsg("");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.sunbirdrc.registry.entities;

import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@Builder
@EqualsAndHashCode
public class UpdateCredential {
private String entity;
private String entityId;
private String attestationProperty;
private String attestationPropertyId;
private String signedData;
private String signedHash;
private String userId;
}


Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import dev.sunbirdrc.registry.middleware.util.Constants;
import dev.sunbirdrc.registry.middleware.util.JSONUtil;
import dev.sunbirdrc.registry.middleware.util.OSSystemFields;
import dev.sunbirdrc.registry.model.event.Event;
import dev.sunbirdrc.registry.model.EventType;
import dev.sunbirdrc.registry.model.event.Event;
import dev.sunbirdrc.registry.service.*;
import dev.sunbirdrc.registry.sink.DatabaseProvider;
import dev.sunbirdrc.registry.sink.OSGraph;
Expand All @@ -33,7 +33,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -319,10 +318,6 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin
}
String parentEntityType = readNode.fields().next().getKey();
HashMap<String, Vertex> uuidVertexMap = vr.getUuidVertexMap();

// Merge the new changes
JsonNode mergedNode = mergeWrapper("/" + parentEntityType, (ObjectNode) readNode, (ObjectNode) inputNode);
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
/*
Expand All @@ -341,11 +336,7 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin
*/

// TODO - Validate before update
JsonNode validationNode = mergedNode.deepCopy();
List<String> removeKeys = new LinkedList<>();
removeKeys.add(uuidPropertyName);
removeKeys.add(Constants.TYPE_STR_JSON_LD);
JSONUtil.removeNodes((ObjectNode) validationNode, removeKeys);

// iValidate.validate(entityNodeType, mergedNode.toString());
// logger.debug("Validated payload before update");

Expand Down Expand Up @@ -373,6 +364,13 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin
}

databaseProvider.commitTransaction(graph, tx);
JsonNode mergedNode = mergeWrapper("/" + parentEntityType, (ObjectNode) readNode, (ObjectNode) inputNode);
logger.debug("After merge the payload is " + mergedNode.toString());
JsonNode validationNode = mergedNode.deepCopy();
List<String> removeKeys = new LinkedList<>();
removeKeys.add(uuidPropertyName);
removeKeys.add(Constants.TYPE_STR_JSON_LD);
JSONUtil.removeNodes((ObjectNode) validationNode, removeKeys);

if (isInternalRegistry(entityType) && isElasticSearchEnabled()) {
if (addShardPrefixForESRecord && !shard.getShardLabel().isEmpty()) {
Expand Down
Loading