Skip to content

Commit 3067d73

Browse files
committed
util class for copy
1 parent 619a6d8 commit 3067d73

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

metadata-io/src/main/java/com/linkedin/metadata/entity/EntityServiceImpl.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -2533,13 +2533,9 @@ private UpdateAspectResult ingestAspectToLocalDB(
25332533
if (previousValue != null
25342534
&& DataTemplateUtil.areEqual(previousValue, writeItem.getRecordTemplate())) {
25352535

2536-
SystemMetadata latestSystemMetadata = null;
2537-
try {
2538-
latestSystemMetadata =
2539-
new SystemMetadata(previousBatchAspect.getSystemMetadata().data().copy());
2540-
} catch (CloneNotSupportedException e) {
2541-
throw new RuntimeException(e);
2542-
}
2536+
SystemMetadata latestSystemMetadata =
2537+
GenericRecordUtils.copy(previousBatchAspect.getSystemMetadata(), SystemMetadata.class);
2538+
25432539
latestSystemMetadata.setLastRunId(
25442540
previousBatchAspect.getSystemMetadata().getRunId(), SetMode.REMOVE_IF_NULL);
25452541
latestSystemMetadata.setLastObserved(

metadata-utils/src/main/java/com/linkedin/metadata/utils/GenericRecordUtils.java

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.JsonNode;
55
import com.linkedin.common.urn.Urn;
66
import com.linkedin.data.ByteString;
7+
import com.linkedin.data.DataMap;
78
import com.linkedin.data.template.RecordTemplate;
89
import com.linkedin.entity.Aspect;
910
import com.linkedin.entity.EntityResponse;
@@ -13,6 +14,8 @@
1314
import com.linkedin.metadata.models.registry.EntityRegistry;
1415
import com.linkedin.mxe.GenericAspect;
1516
import com.linkedin.mxe.GenericPayload;
17+
import java.lang.reflect.Constructor;
18+
import java.lang.reflect.InvocationTargetException;
1619
import java.nio.charset.StandardCharsets;
1720
import java.util.Map;
1821
import java.util.stream.Collectors;
@@ -23,6 +26,22 @@ public class GenericRecordUtils {
2326

2427
private GenericRecordUtils() {}
2528

29+
public static <T extends RecordTemplate> T copy(T input, Class<T> clazz) {
30+
try {
31+
if (input == null) {
32+
return null;
33+
}
34+
Constructor<T> constructor = clazz.getConstructor(DataMap.class);
35+
return constructor.newInstance(input.data().copy());
36+
} catch (CloneNotSupportedException
37+
| InvocationTargetException
38+
| NoSuchMethodException
39+
| InstantiationException
40+
| IllegalAccessException e) {
41+
throw new RuntimeException(e);
42+
}
43+
}
44+
2645
/** Deserialize the given value into the aspect based on the input aspectSpec */
2746
@Nonnull
2847
public static RecordTemplate deserializeAspect(

0 commit comments

Comments
 (0)