Skip to content

Commit

Permalink
update with main
Browse files Browse the repository at this point in the history
  • Loading branch information
chopadetejaswini committed Oct 13, 2023
1 parent 49532d2 commit 547d1d1
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import dev.sunbirdrc.actors.factory.MessageFactory;
import dev.sunbirdrc.elastic.IElasticService;
import dev.sunbirdrc.pojos.ComponentHealthInfo;
import dev.sunbirdrc.pojos.HealthCheckResponse;
import dev.sunbirdrc.pojos.HealthIndicator;
import dev.sunbirdrc.registry.dao.*;
import dev.sunbirdrc.registry.exception.RecordNotFoundException;
import dev.sunbirdrc.registry.exception.SignatureException;
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 +31,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 All @@ -46,7 +43,6 @@
import java.util.stream.Collectors;

import static dev.sunbirdrc.registry.Constants.Schema;
import static dev.sunbirdrc.registry.exception.ErrorMessages.INVALID_ID_MESSAGE;

@Service
@Qualifier("sync")
Expand Down Expand Up @@ -157,7 +153,7 @@ public HealthCheckResponse health(Shard shard) throws Exception {
* @throws Exception
*/
@Override
public Vertex deleteEntityById(Shard shard, String userId, String uuid) throws Exception {
public Vertex deleteEntityById(Shard shard, String entityName, String userId, String uuid) throws Exception {
DatabaseProvider databaseProvider = shard.getDatabaseProvider();
IRegistryDao registryDao = new RegistryDaoImpl(databaseProvider, definitionsManager, uuidPropertyName);
try (OSGraph osGraph = databaseProvider.getOSGraph()) {
Expand Down Expand Up @@ -187,8 +183,14 @@ public Vertex deleteEntityById(Shard shard, String userId, String uuid) throws E
}
}
}

@Override
public void maskAndEmitEvent(JsonNode deletedNode, String index, EventType delete, String userId, String uuid) throws JsonProcessingException {
JsonNode maskedNode = entityTransformer.updatePrivateAndInternalFields(
deletedNode,
definitionsManager.getDefinition(index).getOsSchemaConfiguration()
);
Event event = eventService.createTelemetryObject(delete.name(), userId, "USER", uuid, index, maskedNode);
eventService.pushEvents(event);
}

/**
* This method adds the entity into db, calls elastic and audit asynchronously
Expand Down Expand Up @@ -253,6 +255,9 @@ public String addEntity(Shard shard, String userId, JsonNode rootNode, boolean s
auditService.auditAdd(
auditService.createAuditRecord(userId, entityId, tx, vertexLabel),
shard, rootNode);
if(isEventsEnabled) {
maskAndEmitEvent(rootNode.get(vertexLabel), vertexLabel, EventType.ADD, userId, entityId);
}
}
if (vertexLabel.equals(Schema)) {
schemaService.addSchema(rootNode);
Expand All @@ -273,7 +278,7 @@ private void generateCredentials(JsonNode rootNode, String vertexLabel) throws S
}

@Override
public void updateEntity(Shard shard, String userId, String id, String jsonString) throws Exception {
public void updateEntity(Shard shard, String userId, String id, String jsonString, boolean skipSignature) throws Exception {
JsonNode inputNode = objectMapper.readTree(jsonString);
String entityType = inputNode.fields().next().getKey();
systemFieldsHelper.ensureUpdateAuditFields(entityType, inputNode.get(entityType), userId);
Expand Down Expand Up @@ -346,7 +351,9 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin
JSONUtil.trimPrefix((ObjectNode) inputNode, uuidPropertyName, prefix);
}

generateCredentials(inputNode, entityType);
if (!skipSignature) {
generateCredentials(inputNode, entityType);
}

if (entityType.equals(Schema)) {
schemaService.validateUpdateSchema(readNode, inputNode);
Expand Down Expand Up @@ -374,7 +381,9 @@ public void updateEntity(Shard shard, String userId, String id, String jsonStrin
auditService.auditUpdate(
auditService.createAuditRecord(userId, rootId, tx, entityType),
shard, mergedNode, readNode);

if(isEventsEnabled) {
maskAndEmitEvent(inputNode.get(entityType), entityType, EventType.UPDATE, userId, id);
}
}
}
}
Expand Down Expand Up @@ -551,4 +560,5 @@ private ObjectNode mergeWrapper(String entityType, ObjectNode databaseNode, Obje
});
return result;
}

}

0 comments on commit 547d1d1

Please sign in to comment.