-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
…val of businessattributes with schemaField
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.linkedin.metadata.timeline.data.dataset.schema; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.linkedin.common.AuditStamp; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.metadata.timeline.data.ChangeCategory; | ||
import com.linkedin.metadata.timeline.data.ChangeEvent; | ||
import com.linkedin.metadata.timeline.data.ChangeOperation; | ||
import com.linkedin.metadata.timeline.data.SemanticChangeType; | ||
import lombok.Builder; | ||
|
||
public class SchemaFieldBusinessAttributeChangeEvent extends ChangeEvent { | ||
@Builder(builderMethodName = "schemaFieldBusinessAttributeChangeEventBuilder") | ||
public SchemaFieldBusinessAttributeChangeEvent( | ||
String entityUrn, | ||
ChangeCategory category, | ||
ChangeOperation operation, | ||
String modifier, | ||
AuditStamp auditStamp, | ||
SemanticChangeType semVerChange, | ||
String description, | ||
Urn parentUrn, | ||
Urn businessAttributeUrn, | ||
Urn datasetUrn) { | ||
super( | ||
Check warning on line 25 in metadata-io/src/main/java/com/linkedin/metadata/timeline/data/dataset/schema/SchemaFieldBusinessAttributeChangeEvent.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/data/dataset/schema/SchemaFieldBusinessAttributeChangeEvent.java#L25
|
||
entityUrn, | ||
category, | ||
operation, | ||
modifier, | ||
ImmutableMap.of( | ||
"parentUrn", parentUrn.toString(), | ||
"businessAttributeUrn", businessAttributeUrn.toString(), | ||
"datasetUrn", datasetUrn.toString()), | ||
Check warning on line 33 in metadata-io/src/main/java/com/linkedin/metadata/timeline/data/dataset/schema/SchemaFieldBusinessAttributeChangeEvent.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/data/dataset/schema/SchemaFieldBusinessAttributeChangeEvent.java#L30-L33
|
||
auditStamp, | ||
semVerChange, | ||
description); | ||
} | ||
Check warning on line 37 in metadata-io/src/main/java/com/linkedin/metadata/timeline/data/dataset/schema/SchemaFieldBusinessAttributeChangeEvent.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/data/dataset/schema/SchemaFieldBusinessAttributeChangeEvent.java#L37
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.linkedin.metadata.timeline.eventgenerator; | ||
|
||
import com.linkedin.businessattribute.BusinessAttributeAssociation; | ||
import com.linkedin.businessattribute.BusinessAttributes; | ||
import com.linkedin.common.AuditStamp; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.metadata.timeline.data.ChangeCategory; | ||
import com.linkedin.metadata.timeline.data.ChangeEvent; | ||
import com.linkedin.metadata.timeline.data.ChangeOperation; | ||
import com.linkedin.metadata.timeline.data.SemanticChangeType; | ||
import com.linkedin.metadata.timeline.data.dataset.schema.SchemaFieldBusinessAttributeChangeEvent; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import javax.annotation.Nonnull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class BusinessAttributesChangeEventGenerator | ||
Check warning on line 19 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L18-L19
|
||
extends EntityChangeEventGenerator<BusinessAttributes> { | ||
|
||
private static final String BUSINESS_ATTRIBUTE_ADDED_FORMAT = | ||
"BusinessAttribute '%s' added to entity '%s'."; | ||
private static final String BUSINESS_ATTRIBUTE_REMOVED_FORMAT = | ||
"BusinessAttribute '%s' removed from entity '%s'."; | ||
|
||
@Override | ||
public List<ChangeEvent> getChangeEvents( | ||
@Nonnull Urn urn, | ||
@Nonnull String entityName, | ||
@Nonnull String aspectName, | ||
@Nonnull Aspect<BusinessAttributes> from, | ||
@Nonnull Aspect<BusinessAttributes> to, | ||
@Nonnull AuditStamp auditStamp) { | ||
log.debug( | ||
Check warning on line 35 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L35
|
||
"Calling BusinessAttributesChangeEventGenerator for entity {} and aspect {}", | ||
entityName, | ||
aspectName); | ||
return computeDiff(urn, entityName, aspectName, from.getValue(), to.getValue(), auditStamp); | ||
Check warning on line 39 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L39
|
||
} | ||
|
||
private List<ChangeEvent> computeDiff( | ||
Urn urn, | ||
String entityName, | ||
String aspectName, | ||
BusinessAttributes previousValue, | ||
BusinessAttributes newValue, | ||
AuditStamp auditStamp) { | ||
List<ChangeEvent> changeEvents = new ArrayList<>(); | ||
Check warning on line 49 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L49
|
||
|
||
BusinessAttributeAssociation previousAssociation = | ||
previousValue != null ? previousValue.getBusinessAttribute() : null; | ||
BusinessAttributeAssociation newAssociation = | ||
newValue != null ? newValue.getBusinessAttribute() : null; | ||
|
||
if (Objects.nonNull(previousAssociation) && Objects.isNull(newAssociation)) { | ||
changeEvents.add( | ||
createChangeEvent( | ||
Check warning on line 58 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L57-L58
|
||
previousAssociation, | ||
urn, | ||
ChangeOperation.REMOVE, | ||
BUSINESS_ATTRIBUTE_REMOVED_FORMAT, | ||
auditStamp)); | ||
|
||
} else if (Objects.isNull(previousAssociation) && Objects.nonNull(newAssociation)) { | ||
changeEvents.add( | ||
createChangeEvent( | ||
Check warning on line 67 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L66-L67
|
||
newAssociation, | ||
urn, | ||
ChangeOperation.ADD, | ||
BUSINESS_ATTRIBUTE_ADDED_FORMAT, | ||
auditStamp)); | ||
} | ||
return changeEvents; | ||
Check warning on line 74 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L74
|
||
} | ||
|
||
private ChangeEvent createChangeEvent( | ||
BusinessAttributeAssociation businessAttributeAssociation, | ||
Urn entityUrn, | ||
ChangeOperation changeOperation, | ||
String format, | ||
AuditStamp auditStamp) { | ||
return SchemaFieldBusinessAttributeChangeEvent.schemaFieldBusinessAttributeChangeEventBuilder() | ||
.entityUrn(entityUrn.toString()) | ||
.category(ChangeCategory.BUSINESS_ATTRIBUTE) | ||
.operation(changeOperation) | ||
.modifier(businessAttributeAssociation.getBusinessAttributeUrn().toString()) | ||
.auditStamp(auditStamp) | ||
.semVerChange(SemanticChangeType.MINOR) | ||
.description( | ||
String.format( | ||
format, businessAttributeAssociation.getBusinessAttributeUrn().getId(), entityUrn)) | ||
.parentUrn(entityUrn) | ||
.businessAttributeUrn(businessAttributeAssociation.getBusinessAttributeUrn()) | ||
.datasetUrn(entityUrn.getIdAsUrn()) | ||
.build(); | ||
Check warning on line 96 in metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java Codecov / codecov/patchmetadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/BusinessAttributesChangeEventGenerator.java#L83-L96
|
||
} | ||
} |