- Adds updatedAt and updatedBy

This commit is contained in:
mohitdeuex 2025-02-02 23:13:15 +05:30
parent c5cce2b0c7
commit c6b462f0ab
5 changed files with 52 additions and 16 deletions

View File

@ -112,8 +112,12 @@ public class LineageRepository {
}
@Transaction
public void addLineage(AddLineage addLineage) {
public void addLineage(AddLineage addLineage, String updatedBy) {
// Validate from entity
LineageDetails lineageDetails =
addLineage.getEdge().getLineageDetails() != null
? addLineage.getEdge().getLineageDetails()
: new LineageDetails();
EntityReference from = addLineage.getEdge().getFromEntity();
from = Entity.getEntityReferenceById(from.getType(), from.getId(), Include.NON_DELETED);
@ -121,20 +125,22 @@ public class LineageRepository {
EntityReference to = addLineage.getEdge().getToEntity();
to = Entity.getEntityReferenceById(to.getType(), to.getId(), Include.NON_DELETED);
if (addLineage.getEdge().getLineageDetails() != null
&& addLineage.getEdge().getLineageDetails().getPipeline() != null) {
if (lineageDetails.getPipeline() != null) {
// Validate pipeline entity
EntityReference pipeline = addLineage.getEdge().getLineageDetails().getPipeline();
EntityReference pipeline = lineageDetails.getPipeline();
pipeline =
Entity.getEntityReferenceById(pipeline.getType(), pipeline.getId(), Include.NON_DELETED);
// Add pipeline entity details to lineage details
addLineage.getEdge().getLineageDetails().withPipeline(pipeline);
lineageDetails.withPipeline(pipeline);
}
// Update the lineage details with user and time
lineageDetails.setUpdatedAt(System.currentTimeMillis());
lineageDetails.setUpdatedBy(updatedBy);
// Validate lineage details
String detailsJson = validateLineageDetails(from, to, addLineage.getEdge().getLineageDetails());
String detailsJson = validateLineageDetails(from, to, lineageDetails);
// Finally, add lineage relationship
dao.relationshipDAO()
@ -765,7 +771,7 @@ public class LineageRepository {
}
public Response patchLineageEdge(
String fromEntity, UUID fromId, String toEntity, UUID toId, JsonPatch patch) {
String fromEntity, UUID fromId, String toEntity, UUID toId, JsonPatch patch, String updatedBy) {
EntityReference from = Entity.getEntityReferenceById(fromEntity, fromId, Include.NON_DELETED);
EntityReference to = Entity.getEntityReferenceById(toEntity, toId, Include.NON_DELETED);
String json = dao.relationshipDAO().getRelation(fromId, toId, Relationship.UPSTREAM.ordinal());
@ -782,6 +788,11 @@ public class LineageRepository {
pipeline.getType(), pipeline.getId(), Include.NON_DELETED);
updated.withPipeline(pipeline);
}
// Update the lineage details with user and time
updated.setUpdatedAt(System.currentTimeMillis());
updated.setUpdatedBy(updatedBy);
String detailsJson = JsonUtils.pojoToJson(updated);
dao.relationshipDAO()
.insert(fromId, toId, fromEntity, toEntity, Relationship.UPSTREAM.ordinal(), detailsJson);

View File

@ -417,7 +417,7 @@ public class LineageResource {
addLineage.getEdge().getToEntity().getType(),
addLineage.getEdge().getToEntity().getId(),
addLineage.getEdge().getToEntity().getName()));
dao.addLineage(addLineage);
dao.addLineage(addLineage, securityContext.getUserPrincipal().getName());
return Response.status(Status.OK).build();
}
@ -498,7 +498,7 @@ public class LineageResource {
securityContext,
new OperationContext(toEntity, MetadataOperation.EDIT_LINEAGE),
new ResourceContext<>(toEntity, toId, null));
return dao.patchLineageEdge(fromEntity, fromId, toEntity, toId, patch);
return dao.patchLineageEdge(fromEntity, fromId, toEntity, toId, patch, securityContext.getUserPrincipal().getName());
}
@DELETE

View File

@ -54,6 +54,14 @@
"type": "string",
"enum": ["Manual", "ViewLineage", "QueryLineage", "PipelineLineage", "DashboardLineage", "DbtLineage", "SparkLineage", "OpenLineage", "ExternalTableLineage", "CrossDatabaseLineage"],
"default": "Manual"
},
"updatedAt": {
"description": "Last update time corresponding to the new version of the entity in Unix epoch time milliseconds.",
"$ref": "../type/basic.json#/definitions/timestamp"
},
"updatedBy": {
"description": "User who made the update.",
"type": "string"
}
}
},

View File

@ -69,7 +69,6 @@ const DomainSelectablTree: FC<DomainSelectableTreeProps> = ({
} else {
let retn: EntityReference[] = [];
if (selectedDomains.length > 0) {
const domain = getEntityReferenceFromEntity<Domain>(
selectedDomains[0],
EntityType.DOMAIN
@ -97,10 +96,11 @@ const DomainSelectablTree: FC<DomainSelectableTreeProps> = ({
const onSelect = (selectedKeys: React.Key[]) => {
if (!isMultiple) {
const selectedData = [];
for (const item of selectedKeys) {
selectedData.push(findItemByFqn(domains, item as string, false) as Domain);
selectedData.push(
findItemByFqn(domains, item as string, false) as Domain
);
}
setSelectedDomains(selectedData);
@ -113,12 +113,20 @@ const DomainSelectablTree: FC<DomainSelectableTreeProps> = ({
if (Array.isArray(checked)) {
const selectedData = [];
for (const item of checked) {
selectedData.push(findItemByFqn(domains, item as string, false) as Domain);
selectedData.push(
findItemByFqn(domains, item as string, false) as Domain
);
}
setSelectedDomains(selectedData);
} else {
setSelectedDomains([findItemByFqn(domains, checked.checked as unknown as string, false) as Domain]);
setSelectedDomains([
findItemByFqn(
domains,
checked.checked as unknown as string,
false
) as Domain,
]);
}
};

View File

@ -1,5 +1,5 @@
/*
* Copyright 2024 Collate.
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -69,6 +69,15 @@ export interface LineageDetails {
* SQL used for transformation.
*/
sqlQuery?: string;
/**
* Last update time corresponding to the new version of the entity in Unix epoch time
* milliseconds.
*/
updatedAt?: number;
/**
* User who made the update.
*/
updatedBy?: string;
[property: string]: any;
}