Skip to content

Commit e04d410

Browse files
committed
remove duplicated code
1 parent 2fa73cc commit e04d410

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.atlas.model.tasks.TaskSearchResult;
3838
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
3939
import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags;
40-
import org.apache.atlas.model.typedef.AtlasRelationshipEndDef;
4140
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
4241
import org.apache.atlas.repository.graph.GraphHelper;
4342
import org.apache.atlas.repository.graphdb.AtlasEdge;
@@ -1727,7 +1726,7 @@ public void resetHasLineageOnInputOutputDelete(Collection<AtlasEdge> removedEdge
17271726

17281727
if (!activeEdgeFound) {
17291728
AtlasGraphUtilsV2.setEncodedProperty(processVertex, HAS_LINEAGE, false);
1730-
AtlasEntity diffEntity = getOrInitializeDiffEntity(processVertex);
1729+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(processVertex);
17311730
diffEntity.setAttribute(HAS_LINEAGE, false);
17321731
// Add removed relationship attribute for notification
17331732
addRemovedProcessRelationshipToDiffEntity(diffEntity, atlasEdge, removedEdges);
@@ -1873,7 +1872,7 @@ private void updateAssetHasLineageStatusV1(AtlasVertex assetVertex, AtlasEdge cu
18731872

18741873
if (processHasLineageCount == 0) {
18751874
AtlasGraphUtilsV2.setEncodedProperty(assetVertex, HAS_LINEAGE, false);
1876-
AtlasEntity diffEntity = getOrInitializeDiffEntity(assetVertex);
1875+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(assetVertex);
18771876
diffEntity.setAttribute(HAS_LINEAGE, false);
18781877
// Add removed relationship attribute for notification
18791878
addRemovedProcessRelationshipToDiffEntity(diffEntity, currentEdge, removedEdges);
@@ -1882,17 +1881,6 @@ private void updateAssetHasLineageStatusV1(AtlasVertex assetVertex, AtlasEdge cu
18821881
RequestContext.get().endMetricRecord(metricRecorder);
18831882
}
18841883

1885-
private AtlasEntity getOrInitializeDiffEntity(AtlasVertex vertex) {
1886-
AtlasEntity diffEntity = RequestContext.get().getDifferentialEntity(GraphHelper.getGuid(vertex));
1887-
if (diffEntity == null) {
1888-
diffEntity = new AtlasEntity();
1889-
diffEntity.setTypeName(GraphHelper.getTypeName(vertex));
1890-
diffEntity.setGuid(GraphHelper.getGuid(vertex));
1891-
diffEntity.setUpdateTime(new Date(RequestContext.get().getRequestTime()));
1892-
RequestContext.get().cacheDifferentialEntity(diffEntity);
1893-
}
1894-
return diffEntity;
1895-
}
18961884

18971885
/**
18981886
* Helper method to add removed process relationship to diff entity's removedRelationshipAttributes
@@ -2006,7 +1994,7 @@ private void updateAssetHasLineageStatusV2(AtlasVertex assetVertex, AtlasEdge cu
20061994
// Only update if no active lineage found
20071995
if (!hasActiveLineage) {
20081996
AtlasGraphUtilsV2.setEncodedProperty(assetVertex, HAS_LINEAGE, false);
2009-
AtlasEntity diffEntity = getOrInitializeDiffEntity(assetVertex);
1997+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(assetVertex);
20101998
diffEntity.setAttribute(HAS_LINEAGE, false);
20111999
// Add removed relationship attribute for notification
20122000
addRemovedProcessRelationshipToDiffEntity(diffEntity, currentEdge, removedEdges);

repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ private Object mapToVertexByTypeCategory(AttributeMutationContext ctx, EntityMut
13831383
objectId.put("typeName", getTypeName(inverseVertex));
13841384
objectId.put("guid", GraphHelper.getGuid(inverseVertex));
13851385

1386-
AtlasEntity diffEntity = getOrInitializeDiffEntity(ctx.getReferringVertex());
1386+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(ctx.getReferringVertex());
13871387
diffEntity.setAddedRelationshipAttribute(ctx.getAttribute().getName(), objectId);
13881388
}
13891389
}
@@ -2279,7 +2279,7 @@ public List appendArrayValue(AttributeMutationContext ctx, EntityMutationContext
22792279
}
22802280
}
22812281

2282-
AtlasEntity diffEntity = getOrInitializeDiffEntity(ctx.getReferringVertex());
2282+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(ctx.getReferringVertex());
22832283
diffEntity.setAddedRelationshipAttribute(attribute.getName(), attrValues);
22842284
}
22852285

@@ -2372,7 +2372,7 @@ public List removeArrayValue(AttributeMutationContext ctx, EntityMutationContext
23722372
attrValues.add(objectId);
23732373
}
23742374

2375-
AtlasEntity diffEntity = getOrInitializeDiffEntity(ctx.getReferringVertex());
2375+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(ctx.getReferringVertex());
23762376
diffEntity.setRemovedRelationshipAttribute(attribute.getName(), attrValues);
23772377
}
23782378

@@ -2519,18 +2519,6 @@ public static void validateCustomRelationship(AtlasVertex end1Vertex, AtlasVerte
25192519
validateCustomRelationshipCount(currentSize, end2Vertex);
25202520
}
25212521

2522-
private AtlasEntity getOrInitializeDiffEntity(AtlasVertex vertex) {
2523-
AtlasEntity diffEntity = RequestContext.get().getDifferentialEntity(GraphHelper.getGuid(vertex));
2524-
if (diffEntity == null) {
2525-
diffEntity = new AtlasEntity();
2526-
diffEntity.setTypeName(GraphHelper.getTypeName(vertex));
2527-
diffEntity.setGuid(GraphHelper.getGuid(vertex));
2528-
diffEntity.setUpdateTime(new Date(RequestContext.get().getRequestTime()));
2529-
RequestContext.get().cacheDifferentialEntity(diffEntity);
2530-
}
2531-
return diffEntity;
2532-
}
2533-
25342522
private static void validateCustomRelationshipCount(long size, AtlasVertex vertex) throws AtlasBaseException {
25352523
if (UD_REL_THRESHOLD < size) {
25362524
throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED,
@@ -6208,7 +6196,7 @@ public void addHasLineage(Set<AtlasEdge> inputOutputEdges, boolean isRestoreEnti
62086196

62096197
if (getEntityHasLineage(processVertex)) {
62106198
AtlasGraphUtilsV2.setEncodedProperty(assetVertex, HAS_LINEAGE, true);
6211-
AtlasEntity diffEntity = getOrInitializeDiffEntity(assetVertex);
6199+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(assetVertex);
62126200
diffEntity.setAttribute(HAS_LINEAGE, true);
62136201
continue;
62146202
}
@@ -6226,17 +6214,17 @@ public void addHasLineage(Set<AtlasEdge> inputOutputEdges, boolean isRestoreEnti
62266214
AtlasGraphUtilsV2.setEncodedProperty(assetVertex, HAS_LINEAGE, true);
62276215
AtlasGraphUtilsV2.setEncodedProperty(processVertex, HAS_LINEAGE, true);
62286216

6229-
AtlasEntity diffEntity = getOrInitializeDiffEntity(assetVertex);
6217+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(assetVertex);
62306218
diffEntity.setAttribute(HAS_LINEAGE, true);
62316219

6232-
diffEntity = getOrInitializeDiffEntity(processVertex);
6220+
diffEntity = entityRetriever.getOrInitializeDiffEntity(processVertex);
62336221
diffEntity.setAttribute(HAS_LINEAGE, true);
62346222
isHasLineageSet = true;
62356223
}
62366224

62376225
if (isRestoreEntity) {
62386226
AtlasGraphUtilsV2.setEncodedProperty(oppositeEdgeAssetVertex, HAS_LINEAGE, true);
6239-
AtlasEntity diffEntity = getOrInitializeDiffEntity(oppositeEdgeAssetVertex);
6227+
AtlasEntity diffEntity = entityRetriever.getOrInitializeDiffEntity(oppositeEdgeAssetVertex);
62406228
diffEntity.setAttribute(HAS_LINEAGE, true);
62416229
} else {
62426230
break;

repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,6 +3305,17 @@ public AtlasRelationshipWithExtInfo mapEdgeToAtlasRelationship(AtlasEdge edge, b
33053305
return ret;
33063306
}
33073307

3308+
public AtlasEntity getOrInitializeDiffEntity(AtlasVertex vertex) {
3309+
AtlasEntity diffEntity = RequestContext.get().getDifferentialEntity(GraphHelper.getGuid(vertex));
3310+
if (diffEntity == null) {
3311+
diffEntity = new AtlasEntity();
3312+
diffEntity.setTypeName(GraphHelper.getTypeName(vertex));
3313+
diffEntity.setGuid(GraphHelper.getGuid(vertex));
3314+
diffEntity.setUpdateTime(new Date(RequestContext.get().getRequestTime()));
3315+
RequestContext.get().cacheDifferentialEntity(diffEntity);
3316+
}
3317+
return diffEntity;
3318+
}
33083319
private AtlasRelationshipWithExtInfo mapSystemAttributes(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo, boolean extendedInfo) throws AtlasBaseException {
33093320
if (LOG.isDebugEnabled()) {
33103321
LOG.debug("Mapping system attributes for relationship");
@@ -3435,6 +3446,7 @@ private Set<String> getPendingTasks(AtlasVertex entityVertex) {
34353446
return new HashSet<>(ret);
34363447
}
34373448

3449+
34383450
private boolean isInactiveEdge(Object element, boolean ignoreInactive) {
34393451
return ignoreInactive && element instanceof AtlasEdge && getStatus((AtlasEdge) element) != AtlasEntity.Status.ACTIVE;
34403452
}

0 commit comments

Comments
 (0)