Skip to content

Commit

Permalink
split domain implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
PRATHAM2002-DS committed Mar 27, 2024
1 parent 8280a02 commit 8e48c5c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void processUpdateDomain(AtlasEntity entity, AtlasVertex vertex) throws
}
}

if (!currentParentDomainQualifiedName.equals(newParentDomainQualifiedName) && entity.hasRelationshipAttribute(PARENT_DOMAIN)) {
if (!currentParentDomainQualifiedName.equals(newParentDomainQualifiedName) && entity.hasRelationshipAttribute(DATA_DOMAIN)) {
//Auth check
isAuthorized(currentParentDomainHeader, parentDomain);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ private void processUpdateDomain(AtlasEntity entity, AtlasVertex vertex) throws
}
}


if (!currentParentDomainQualifiedName.equals(newParentDomainQualifiedName) && entity.hasRelationshipAttribute(PARENT_DOMAIN)) {
if(storedDomain.getRelationshipAttribute(PARENT_DOMAIN) == null){
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Cannot move Root Domain");
}

//Auth check
isAuthorized(currentParentDomainHeader, parentDomain);
if(parentDomain != null && currentParentDomainHeader != null){
isAuthorized(currentParentDomainHeader, parentDomain);
}

processMoveSubDomainToAnotherDomain(entity, vertex, currentParentDomainQualifiedName, newParentDomainQualifiedName, vertexQnName, superDomainQualifiedName);

Expand All @@ -147,18 +148,30 @@ private void processMoveSubDomainToAnotherDomain(AtlasEntity domain,

try {
String domainName = (String) domain.getAttribute(NAME);
String updatedQualifiedName = "";

LOG.info("Moving subdomain {} to Domain {}", domainName, targetDomainQualifiedName);

domainExists(domainName, targetDomainQualifiedName);

String updatedQualifiedName = currentSubDomainQualifiedName.replace(sourceDomainQualifiedName, targetDomainQualifiedName);

domain.setAttribute(QUALIFIED_NAME, updatedQualifiedName);
domain.setAttribute(PARENT_DOMAIN_QN, targetDomainQualifiedName);
domain.setAttribute(SUPER_DOMAIN_QN, superDomainQualifiedName);
// Move Sub-Domain as root Domain
if(targetDomainQualifiedName.isEmpty()){
targetDomainQualifiedName = "default";
updatedQualifiedName = currentSubDomainQualifiedName.replace(sourceDomainQualifiedName, targetDomainQualifiedName);
domain.setAttribute(QUALIFIED_NAME, updatedQualifiedName);
domain.setAttribute(PARENT_DOMAIN_QN, null);
domain.setAttribute(SUPER_DOMAIN_QN, null);
superDomainQualifiedName = updatedQualifiedName ;
}
else{
updatedQualifiedName = currentSubDomainQualifiedName.replace(sourceDomainQualifiedName, targetDomainQualifiedName);
domain.setAttribute(QUALIFIED_NAME, updatedQualifiedName);
domain.setAttribute(PARENT_DOMAIN_QN, targetDomainQualifiedName);
domain.setAttribute(SUPER_DOMAIN_QN, superDomainQualifiedName);
}

moveChildrenToAnotherDomain(domainVertex, superDomainQualifiedName, sourceDomainQualifiedName, targetDomainQualifiedName);
moveChildrenToAnotherDomain(domainVertex, superDomainQualifiedName, null, sourceDomainQualifiedName, targetDomainQualifiedName);

LOG.info("Moved subDomain {} to Domain {}", domainName, targetDomainQualifiedName);

Expand All @@ -168,6 +181,7 @@ private void processMoveSubDomainToAnotherDomain(AtlasEntity domain,
}

private void moveChildrenToAnotherDomain(AtlasVertex childDomainVertex,
String superDomainQualifiedName,
String parentDomainQualifiedName,
String sourceDomainQualifiedName,
String targetDomainQualifiedName) throws AtlasBaseException {
Expand All @@ -179,14 +193,14 @@ private void moveChildrenToAnotherDomain(AtlasVertex childDomainVertex,
Map<String, Object> updatedAttributes = new HashMap<>();

String currentDomainQualifiedName = childDomainVertex.getProperty(QUALIFIED_NAME, String.class);
String updatedQualifiedName = currentDomainQualifiedName.replace(sourceDomainQualifiedName, targetDomainQualifiedName);
String updatedDomainQualifiedName = currentDomainQualifiedName.replace(sourceDomainQualifiedName, targetDomainQualifiedName);

// Change domain qualifiedName
childDomainVertex.setProperty(QUALIFIED_NAME, updatedQualifiedName);
updatedAttributes.put(QUALIFIED_NAME, updatedQualifiedName);
childDomainVertex.setProperty(QUALIFIED_NAME, updatedDomainQualifiedName);
updatedAttributes.put(QUALIFIED_NAME, updatedDomainQualifiedName);

//change superDomainQN, parentDomainQN
childDomainVertex.setProperty(SUPER_DOMAIN_QN, targetDomainQualifiedName);
childDomainVertex.setProperty(SUPER_DOMAIN_QN, superDomainQualifiedName);
childDomainVertex.setProperty(PARENT_DOMAIN_QN, parentDomainQualifiedName);

//update system properties
Expand All @@ -198,15 +212,15 @@ private void moveChildrenToAnotherDomain(AtlasVertex childDomainVertex,

while (products.hasNext()) {
AtlasVertex productVertex = products.next();
moveChildDataProductToAnotherDomain(productVertex, parentDomainQualifiedName, sourceDomainQualifiedName, targetDomainQualifiedName);
moveChildDataProductToAnotherDomain(productVertex, superDomainQualifiedName, updatedDomainQualifiedName, sourceDomainQualifiedName, targetDomainQualifiedName);
}

// Get all children domains of current domain
Iterator<AtlasVertex> childDomains = getActiveChildrenVertices(childDomainVertex, DOMAIN_PARENT_EDGE_LABEL);

while (childDomains.hasNext()) {
AtlasVertex childVertex = childDomains.next();
moveChildrenToAnotherDomain(childVertex, updatedQualifiedName, sourceDomainQualifiedName, targetDomainQualifiedName);
moveChildrenToAnotherDomain(childVertex, superDomainQualifiedName, updatedDomainQualifiedName, sourceDomainQualifiedName, targetDomainQualifiedName);
}

recordUpdatedChildEntities(childDomainVertex, updatedAttributes);
Expand All @@ -218,6 +232,7 @@ private void moveChildrenToAnotherDomain(AtlasVertex childDomainVertex,
}

private void moveChildDataProductToAnotherDomain(AtlasVertex productVertex,
String superDomainQualifiedName,
String parentDomainQualifiedName,
String sourceDomainQualifiedName,
String targetDomainQualifiedName) throws AtlasBaseException {
Expand All @@ -234,8 +249,8 @@ private void moveChildDataProductToAnotherDomain(AtlasVertex productVertex,
productVertex.setProperty(QUALIFIED_NAME, updatedQualifiedName);
updatedAttributes.put(QUALIFIED_NAME, updatedQualifiedName);

productVertex.setProperty(PARENT_DOMAIN_QN, targetDomainQualifiedName);
productVertex.setProperty(SUPER_DOMAIN_QN, parentDomainQualifiedName);
productVertex.setProperty(PARENT_DOMAIN_QN, parentDomainQualifiedName);
productVertex.setProperty(SUPER_DOMAIN_QN, superDomainQualifiedName);

//update system properties
GraphHelper.setModifiedByAsString(productVertex, RequestContext.get().getUser());
Expand Down

0 comments on commit 8e48c5c

Please sign in to comment.