Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
f59284ad
Commit
f59284ad
authored
Aug 29, 2017
by
Sarath Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2040: Relationship with many-to-many cardinality gives incorrect relationship attribute value
parent
1b7e41f1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
486 additions
and
113 deletions
+486
-113
AtlasRelationshipType.java
...ain/java/org/apache/atlas/type/AtlasRelationshipType.java
+25
-16
AtlasStructType.java
.../src/main/java/org/apache/atlas/type/AtlasStructType.java
+1
-1
TestRelationshipUtilsV2.java
...c/test/java/org/apache/atlas/TestRelationshipUtilsV2.java
+69
-18
GraphHelper.java
...n/java/org/apache/atlas/repository/graph/GraphHelper.java
+45
-28
DeleteHandlerV1.java
...ache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
+11
-6
EntityGraphMapper.java
...he/atlas/repository/store/graph/v1/EntityGraphMapper.java
+82
-21
EntityGraphRetriever.java
...atlas/repository/store/graph/v1/EntityGraphRetriever.java
+7
-2
AtlasRelationshipStoreHardDeleteV1Test.java
...tore/graph/v1/AtlasRelationshipStoreHardDeleteV1Test.java
+60
-1
AtlasRelationshipStoreSoftDeleteV1Test.java
...tore/graph/v1/AtlasRelationshipStoreSoftDeleteV1Test.java
+63
-1
AtlasRelationshipStoreV1Test.java
...pository/store/graph/v1/AtlasRelationshipStoreV1Test.java
+123
-19
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
View file @
f59284ad
...
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
...
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
BOTH
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
IN
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
IN
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
OUT
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
OUT
;
...
@@ -118,24 +119,33 @@ public class AtlasRelationshipType extends AtlasStructType {
...
@@ -118,24 +119,33 @@ public class AtlasRelationshipType extends AtlasStructType {
}
}
private
void
addRelationshipEdgeDirection
()
{
private
void
addRelationshipEdgeDirection
()
{
AtlasRelationshipEndDef
endDef1
=
relationshipDef
.
getEndDef1
();
AtlasRelationshipEndDef
endDef1
=
relationshipDef
.
getEndDef1
();
AtlasRelationshipEndDef
endDef2
=
relationshipDef
.
getEndDef2
();
AtlasRelationshipEndDef
endDef2
=
relationshipDef
.
getEndDef2
();
AtlasAttribute
end1Attribute
=
end1Type
.
getRelationshipAttribute
(
endDef1
.
getName
());
AtlasAttribute
end2Attribute
=
end2Type
.
getRelationshipAttribute
(
endDef2
.
getName
());
//default relationship edge direction is end1 (out) -> end2 (in)
if
(
StringUtils
.
equals
(
endDef1
.
getType
(),
endDef2
.
getType
())
&&
AtlasRelationshipEdgeDirection
end1Direction
=
OUT
;
StringUtils
.
equals
(
endDef1
.
getName
(),
endDef2
.
getName
()))
{
AtlasRelationshipEdgeDirection
end2Direction
=
IN
;
if
(
endDef1
.
getIsLegacyAttribute
()
&&
endDef2
.
getIsLegacyAttribute
())
{
AtlasAttribute
endAttribute
=
end1Type
.
getRelationshipAttribute
(
endDef1
.
getName
());
end2Direction
=
OUT
;
}
else
if
(!
endDef1
.
getIsLegacyAttribute
()
&&
endDef2
.
getIsLegacyAttribute
())
{
end1Direction
=
IN
;
end2Direction
=
OUT
;
}
end1Attribute
.
setRelationshipEdgeDirection
(
end1Direction
);
endAttribute
.
setRelationshipEdgeDirection
(
BOTH
);
end2Attribute
.
setRelationshipEdgeDirection
(
end2Direction
);
}
else
{
AtlasAttribute
end1Attribute
=
end1Type
.
getRelationshipAttribute
(
endDef1
.
getName
());
AtlasAttribute
end2Attribute
=
end2Type
.
getRelationshipAttribute
(
endDef2
.
getName
());
//default relationship edge direction is end1 (out) -> end2 (in)
AtlasRelationshipEdgeDirection
end1Direction
=
OUT
;
AtlasRelationshipEdgeDirection
end2Direction
=
IN
;
if
(
endDef1
.
getIsLegacyAttribute
()
&&
endDef2
.
getIsLegacyAttribute
())
{
end2Direction
=
OUT
;
}
else
if
(!
endDef1
.
getIsLegacyAttribute
()
&&
endDef2
.
getIsLegacyAttribute
())
{
end1Direction
=
IN
;
end2Direction
=
OUT
;
}
end1Attribute
.
setRelationshipEdgeDirection
(
end1Direction
);
end2Attribute
.
setRelationshipEdgeDirection
(
end2Direction
);
}
}
}
@Override
@Override
...
@@ -200,7 +210,6 @@ public class AtlasRelationshipType extends AtlasStructType {
...
@@ -200,7 +210,6 @@ public class AtlasRelationshipType extends AtlasStructType {
AtlasRelationshipEndDef
endDef2
=
relationshipDef
.
getEndDef2
();
AtlasRelationshipEndDef
endDef2
=
relationshipDef
.
getEndDef2
();
RelationshipCategory
relationshipCategory
=
relationshipDef
.
getRelationshipCategory
();
RelationshipCategory
relationshipCategory
=
relationshipDef
.
getRelationshipCategory
();
String
name
=
relationshipDef
.
getName
();
String
name
=
relationshipDef
.
getName
();
boolean
isContainer1
=
endDef1
.
getIsContainer
();
boolean
isContainer1
=
endDef1
.
getIsContainer
();
boolean
isContainer2
=
endDef2
.
getIsContainer
();
boolean
isContainer2
=
endDef2
.
getIsContainer
();
...
...
intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
View file @
f59284ad
...
@@ -794,6 +794,6 @@ public class AtlasStructType extends AtlasType {
...
@@ -794,6 +794,6 @@ public class AtlasStructType extends AtlasType {
private
static
final
char
DOUBLE_QUOTE_CHAR
=
'"'
;
private
static
final
char
DOUBLE_QUOTE_CHAR
=
'"'
;
private
static
final
char
SPACE_CHAR
=
' '
;
private
static
final
char
SPACE_CHAR
=
' '
;
public
enum
AtlasRelationshipEdgeDirection
{
IN
,
OUT
}
public
enum
AtlasRelationshipEdgeDirection
{
IN
,
OUT
,
BOTH
}
}
}
}
}
intg/src/test/java/org/apache/atlas/TestRelationshipUtilsV2.java
View file @
f59284ad
...
@@ -23,8 +23,8 @@ import com.google.common.collect.ImmutableSet;
...
@@ -23,8 +23,8 @@ import com.google.common.collect.ImmutableSet;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
...
@@ -33,18 +33,17 @@ import org.apache.atlas.model.typedef.AtlasRelationshipDef;
...
@@ -33,18 +33,17 @@ import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import
org.apache.atlas.model.typedef.AtlasRelationshipEndDef
;
import
org.apache.atlas.model.typedef.AtlasRelationshipEndDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.
atlas.type.AtlasTypeUtil
;
import
org.apache.
commons.lang.ArrayUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
getArrayTypeName
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasRelationshipDef
.
PropagateTags
.
BOTH
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
getMapTypeName
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasRelationshipDef
.
PropagateTags
.
ONE_TO_TWO
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasRelationshipDef
.
PropagateTags
.
ONE_TO_TWO
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasRelationshipDef
.
RelationshipCategory
.
AGGREGATION
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasRelationshipDef
.
RelationshipCategory
.
AGGREGATION
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasRelationshipDef
.
RelationshipCategory
.
ASSOCIATION
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasRelationshipDef
.
RelationshipCategory
.
ASSOCIATION
;
...
@@ -72,12 +71,13 @@ public final class TestRelationshipUtilsV2 {
...
@@ -72,12 +71,13 @@ public final class TestRelationshipUtilsV2 {
public
static
final
String
EMPLOYEE_TYPE
=
"Employee"
;
public
static
final
String
EMPLOYEE_TYPE
=
"Employee"
;
public
static
final
String
EMPLOYEE_DEPARTMENT_TYPE
=
"EmployeeDepartment"
;
public
static
final
String
EMPLOYEE_DEPARTMENT_TYPE
=
"EmployeeDepartment"
;
public
static
final
String
EMPLOYEE_MANAGER_TYPE
=
"EmployeeManager"
;
public
static
final
String
EMPLOYEE_MANAGER_TYPE
=
"EmployeeManager"
;
public
static
final
String
EMPLOYEE_MENTOR_TYPE
=
"EmployeeMentor"
;
public
static
final
String
EMPLOYEE_MENTORS_TYPE
=
"EmployeeMentors"
;
public
static
final
String
EMPLOYEE_FRIENDS_TYPE
=
"EmployeeFriends"
;
public
static
final
String
PERSON_SIBLING_TYPE
=
"PersonSibling"
;
public
static
final
String
TYPE_A
=
"A"
;
public
static
final
String
TYPE_A
=
"A"
;
public
static
final
String
TYPE_B
=
"B"
;
public
static
final
String
TYPE_B
=
"B"
;
public
static
final
String
DEFAULT_VERSION
=
"1.0"
;
public
static
final
String
DEFAULT_VERSION
=
"1.0"
;
private
TestRelationshipUtilsV2
()
{
}
private
TestRelationshipUtilsV2
()
{
}
public
static
AtlasTypesDef
getDepartmentEmployeeTypes
()
throws
AtlasBaseException
{
public
static
AtlasTypesDef
getDepartmentEmployeeTypes
()
throws
AtlasBaseException
{
...
@@ -121,23 +121,36 @@ public final class TestRelationshipUtilsV2 {
...
@@ -121,23 +121,36 @@ public final class TestRelationshipUtilsV2 {
DEFAULT_VERSION
,
AGGREGATION
,
ONE_TO_TWO
,
DEFAULT_VERSION
,
AGGREGATION
,
ONE_TO_TWO
,
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"department"
,
SINGLE
),
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"department"
,
SINGLE
),
new
AtlasRelationshipEndDef
(
DEPARTMENT_TYPE
,
"employees"
,
SET
,
true
));
new
AtlasRelationshipEndDef
(
DEPARTMENT_TYPE
,
"employees"
,
SET
,
true
));
/******* [Manager -> Employee] Relationship *******/
/******* [Manager -> Employee] Relationship *******/
AtlasRelationshipDef
employeeManagerType
=
new
AtlasRelationshipDef
(
EMPLOYEE_MANAGER_TYPE
,
description
(
EMPLOYEE_MANAGER_TYPE
),
AtlasRelationshipDef
employeeManagerType
=
new
AtlasRelationshipDef
(
EMPLOYEE_MANAGER_TYPE
,
description
(
EMPLOYEE_MANAGER_TYPE
),
DEFAULT_VERSION
,
AGGREGATION
,
ONE_TO_TWO
,
DEFAULT_VERSION
,
AGGREGATION
,
ONE_TO_TWO
,
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"manager"
,
SINGLE
),
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"manager"
,
SINGLE
),
new
AtlasRelationshipEndDef
(
MANAGER_TYPE
,
"subordinates"
,
SET
,
true
));
new
AtlasRelationshipEndDef
(
MANAGER_TYPE
,
"subordinates"
,
SET
,
true
));
/******* [Mentor -> Employee] Relationship *******/
/******* [Mentors -> Employee] Relationship *******/
AtlasRelationshipDef
employeeMentorType
=
new
AtlasRelationshipDef
(
EMPLOYEE_MENTOR_TYPE
,
description
(
EMPLOYEE_MENTOR_TYPE
),
AtlasRelationshipDef
employeeMentorsType
=
new
AtlasRelationshipDef
(
EMPLOYEE_MENTORS_TYPE
,
description
(
EMPLOYEE_MENTORS_TYPE
),
DEFAULT_VERSION
,
AGGREGATION
,
ONE_TO_TWO
,
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"mentors"
,
SET
),
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"mentees"
,
SET
,
true
));
/******* [Friends -> Employee] Relationship *******/
AtlasRelationshipDef
employeeFriendsType
=
new
AtlasRelationshipDef
(
EMPLOYEE_FRIENDS_TYPE
,
description
(
EMPLOYEE_FRIENDS_TYPE
),
DEFAULT_VERSION
,
ASSOCIATION
,
ONE_TO_TWO
,
DEFAULT_VERSION
,
ASSOCIATION
,
ONE_TO_TWO
,
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"mentor"
,
SINGLE
),
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"friends"
,
SET
),
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"mentees"
,
SET
));
new
AtlasRelationshipEndDef
(
EMPLOYEE_TYPE
,
"friends"
,
SET
));
/******* [Person -> Sibling] Relationship *******/
AtlasRelationshipDef
personSiblingType
=
new
AtlasRelationshipDef
(
PERSON_SIBLING_TYPE
,
description
(
PERSON_SIBLING_TYPE
),
DEFAULT_VERSION
,
ASSOCIATION
,
BOTH
,
new
AtlasRelationshipEndDef
(
PERSON_TYPE
,
"sibling"
,
SINGLE
),
new
AtlasRelationshipEndDef
(
PERSON_TYPE
,
"sibling"
,
SINGLE
));
return
new
AtlasTypesDef
(
ImmutableList
.
of
(
orgLevelType
),
return
new
AtlasTypesDef
(
ImmutableList
.
of
(
orgLevelType
),
ImmutableList
.
of
(
addressType
),
ImmutableList
.
of
(
addressType
),
ImmutableList
.
of
(
securityClearanceType
),
ImmutableList
.
of
(
securityClearanceType
),
ImmutableList
.
of
(
personType
,
employeeType
,
departmentType
,
managerType
),
ImmutableList
.
of
(
personType
,
employeeType
,
departmentType
,
managerType
),
ImmutableList
.
of
(
employeeDepartmentType
,
employeeManagerType
,
employeeMentorType
));
ImmutableList
.
of
(
employeeDepartmentType
,
employeeManagerType
,
employeeMentor
sType
,
employeeFriendsType
,
personSibling
Type
));
}
}
public
static
AtlasEntitiesWithExtInfo
getDepartmentEmployeeInstances
()
{
public
static
AtlasEntitiesWithExtInfo
getDepartmentEmployeeInstances
()
{
...
@@ -163,25 +176,30 @@ public final class TestRelationshipUtilsV2 {
...
@@ -163,25 +176,30 @@ public final class TestRelationshipUtilsV2 {
johnAddr
.
setAttribute
(
"street"
,
"Stewart Drive"
);
johnAddr
.
setAttribute
(
"street"
,
"Stewart Drive"
);
johnAddr
.
setAttribute
(
"city"
,
"Sunnyvale"
);
johnAddr
.
setAttribute
(
"city"
,
"Sunnyvale"
);
/******* Manager - Jane (John and Max subordinates) *******/
AtlasStruct
mikeAddr
=
new
AtlasStruct
(
ADDRESS_TYPE
);
mikeAddr
.
setAttribute
(
"street"
,
"Casa Verde St"
);
mikeAddr
.
setAttribute
(
"city"
,
"San Jose"
);
/******* Manager - Jane (Subordinates: [John, Max]) *******/
AtlasEntity
jane
=
new
AtlasEntity
(
MANAGER_TYPE
);
AtlasEntity
jane
=
new
AtlasEntity
(
MANAGER_TYPE
);
jane
.
setAttribute
(
"name"
,
"Jane"
);
jane
.
setAttribute
(
"name"
,
"Jane"
);
jane
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
jane
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
jane
.
setAttribute
(
"address"
,
janeAddr
);
jane
.
setAttribute
(
"address"
,
janeAddr
);
/******* Manager - Julius (
no subordinates
) *******/
/******* Manager - Julius (
Subordinates: [], Sibling: Jane
) *******/
AtlasEntity
julius
=
new
AtlasEntity
(
MANAGER_TYPE
);
AtlasEntity
julius
=
new
AtlasEntity
(
MANAGER_TYPE
);
julius
.
setAttribute
(
"name"
,
"Julius"
);
julius
.
setAttribute
(
"name"
,
"Julius"
);
julius
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
julius
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
julius
.
setRelationshipAttribute
(
"sibling"
,
getAtlasObjectId
(
jane
));
julius
.
setAttribute
(
"address"
,
juliusAddr
);
julius
.
setAttribute
(
"address"
,
juliusAddr
);
/******* Employee - Max (Manager: Jane, Mentor: Julius) *******/
/******* Employee - Max (Manager: Jane, Mentor
s: [Julius], Sibling
: Julius) *******/
AtlasEntity
max
=
new
AtlasEntity
(
EMPLOYEE_TYPE
);
AtlasEntity
max
=
new
AtlasEntity
(
EMPLOYEE_TYPE
);
max
.
setAttribute
(
"name"
,
"Max"
);
max
.
setAttribute
(
"name"
,
"Max"
);
max
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
max
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
max
.
setAttribute
(
"address"
,
maxAddr
);
max
.
setAttribute
(
"address"
,
maxAddr
);
max
.
setRelationshipAttribute
(
"manager"
,
getAtlasObjectId
(
jane
));
max
.
setRelationshipAttribute
(
"manager"
,
getAtlasObjectId
(
jane
));
max
.
setRelationshipAttribute
(
"mentor
"
,
getAtlasObjectId
(
julius
));
max
.
setRelationshipAttribute
(
"mentor
s"
,
getAtlasObjectIds
(
julius
));
max
.
setAttribute
(
"birthday"
,
new
Date
(
1979
,
3
,
15
));
max
.
setAttribute
(
"birthday"
,
new
Date
(
1979
,
3
,
15
));
max
.
setAttribute
(
"hasPets"
,
true
);
max
.
setAttribute
(
"hasPets"
,
true
);
max
.
setAttribute
(
"age"
,
36
);
max
.
setAttribute
(
"age"
,
36
);
...
@@ -193,13 +211,14 @@ public final class TestRelationshipUtilsV2 {
...
@@ -193,13 +211,14 @@ public final class TestRelationshipUtilsV2 {
max
.
setAttribute
(
"numberOfStarsEstimate"
,
new
BigInteger
(
"1000000000000000000000000000000"
));
max
.
setAttribute
(
"numberOfStarsEstimate"
,
new
BigInteger
(
"1000000000000000000000000000000"
));
max
.
setAttribute
(
"approximationOfPi"
,
new
BigDecimal
(
"3.1415926535897932"
));
max
.
setAttribute
(
"approximationOfPi"
,
new
BigDecimal
(
"3.1415926535897932"
));
/******* Employee - John (Manager: Jane, Mentor
: Max
) *******/
/******* Employee - John (Manager: Jane, Mentor
s: [Max], Friends: [Max]
) *******/
AtlasEntity
john
=
new
AtlasEntity
(
EMPLOYEE_TYPE
);
AtlasEntity
john
=
new
AtlasEntity
(
EMPLOYEE_TYPE
);
john
.
setAttribute
(
"name"
,
"John"
);
john
.
setAttribute
(
"name"
,
"John"
);
john
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
john
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
john
.
setAttribute
(
"address"
,
johnAddr
);
john
.
setAttribute
(
"address"
,
johnAddr
);
john
.
setRelationshipAttribute
(
"manager"
,
getAtlasObjectId
(
jane
));
john
.
setRelationshipAttribute
(
"manager"
,
getAtlasObjectId
(
jane
));
john
.
setRelationshipAttribute
(
"mentor"
,
getAtlasObjectId
(
max
));
john
.
setRelationshipAttribute
(
"mentors"
,
getAtlasObjectIds
(
max
,
julius
));
john
.
setRelationshipAttribute
(
"friends"
,
getAtlasObjectIds
(
max
));
john
.
setAttribute
(
"birthday"
,
new
Date
(
1950
,
5
,
15
));
john
.
setAttribute
(
"birthday"
,
new
Date
(
1950
,
5
,
15
));
john
.
setAttribute
(
"hasPets"
,
true
);
john
.
setAttribute
(
"hasPets"
,
true
);
john
.
setAttribute
(
"numberOfCars"
,
1
);
john
.
setAttribute
(
"numberOfCars"
,
1
);
...
@@ -211,11 +230,30 @@ public final class TestRelationshipUtilsV2 {
...
@@ -211,11 +230,30 @@ public final class TestRelationshipUtilsV2 {
john
.
setAttribute
(
"numberOfStarsEstimate"
,
new
BigInteger
(
"1000000000000000000000"
));
john
.
setAttribute
(
"numberOfStarsEstimate"
,
new
BigInteger
(
"1000000000000000000000"
));
john
.
setAttribute
(
"approximationOfPi"
,
new
BigDecimal
(
"3.141592653589793238462643383279502884197169399375105820974944592307816406286"
));
john
.
setAttribute
(
"approximationOfPi"
,
new
BigDecimal
(
"3.141592653589793238462643383279502884197169399375105820974944592307816406286"
));
/******* Employee - Mike (Manager: Julius, Friends: [Max, John]) *******/
AtlasEntity
mike
=
new
AtlasEntity
(
EMPLOYEE_TYPE
);
mike
.
setAttribute
(
"name"
,
"Mike"
);
mike
.
setRelationshipAttribute
(
"department"
,
getAtlasObjectId
(
hrDept
));
mike
.
setAttribute
(
"address"
,
mikeAddr
);
mike
.
setRelationshipAttribute
(
"manager"
,
getAtlasObjectId
(
julius
));
mike
.
setRelationshipAttribute
(
"friends"
,
getAtlasObjectIds
(
max
,
john
));
mike
.
setAttribute
(
"birthday"
,
new
Date
(
1947
,
8
,
15
));
mike
.
setAttribute
(
"hasPets"
,
false
);
mike
.
setAttribute
(
"numberOfCars"
,
2
);
mike
.
setAttribute
(
"houseNumber"
,
3737
);
mike
.
setAttribute
(
"carMileage"
,
25000
);
mike
.
setAttribute
(
"shares"
,
Long
.
MIN_VALUE
);
mike
.
setAttribute
(
"salary"
,
Double
.
MIN_VALUE
);
mike
.
setAttribute
(
"age"
,
37
);
mike
.
setAttribute
(
"numberOfStarsEstimate"
,
new
BigInteger
(
"5000050000050000050005"
));
mike
.
setAttribute
(
"approximationOfPi"
,
new
BigDecimal
(
"3.14159"
));
ret
.
addEntity
(
hrDept
);
ret
.
addEntity
(
hrDept
);
ret
.
addEntity
(
jane
);
ret
.
addEntity
(
jane
);
ret
.
addEntity
(
julius
);
ret
.
addEntity
(
julius
);
ret
.
addEntity
(
max
);
ret
.
addEntity
(
max
);
ret
.
addEntity
(
john
);
ret
.
addEntity
(
john
);
ret
.
addEntity
(
mike
);
return
ret
;
return
ret
;
}
}
...
@@ -264,4 +302,16 @@ public final class TestRelationshipUtilsV2 {
...
@@ -264,4 +302,16 @@ public final class TestRelationshipUtilsV2 {
private
static
ImmutableSet
<
String
>
superType
(
String
superTypeName
)
{
private
static
ImmutableSet
<
String
>
superType
(
String
superTypeName
)
{
return
StringUtils
.
isNotEmpty
(
superTypeName
)
?
ImmutableSet
.
of
(
superTypeName
)
:
ImmutableSet
.<
String
>
of
();
return
StringUtils
.
isNotEmpty
(
superTypeName
)
?
ImmutableSet
.
of
(
superTypeName
)
:
ImmutableSet
.<
String
>
of
();
}
}
private
static
List
<
AtlasObjectId
>
getAtlasObjectIds
(
AtlasEntity
...
entities
)
{
List
<
AtlasObjectId
>
ret
=
new
ArrayList
<>();
if
(
ArrayUtils
.
isNotEmpty
(
entities
))
{
for
(
AtlasEntity
entity
:
entities
)
{
ret
.
add
(
getAtlasObjectId
(
entity
));
}
}
return
ret
;
}
}
}
\ No newline at end of file
repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
View file @
f59284ad
...
@@ -42,7 +42,6 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
...
@@ -42,7 +42,6 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import
org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1
;
import
org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasRelationshipType
;
import
org.apache.atlas.type.AtlasRelationshipType
;
import
org.apache.atlas.type.AtlasStructType
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.typesystem.IReferenceableInstance
;
import
org.apache.atlas.typesystem.IReferenceableInstance
;
import
org.apache.atlas.typesystem.ITypedInstance
;
import
org.apache.atlas.typesystem.ITypedInstance
;
...
@@ -86,6 +85,10 @@ import java.util.Set;
...
@@ -86,6 +85,10 @@ import java.util.Set;
import
java.util.Stack
;
import
java.util.Stack
;
import
java.util.UUID
;
import
java.util.UUID
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
BOTH
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
IN
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
OUT
;
/**
/**
* Utility class for graph operations.
* Utility class for graph operations.
*/
*/
...
@@ -308,7 +311,7 @@ public final class GraphHelper {
...
@@ -308,7 +311,7 @@ public final class GraphHelper {
//In some cases of parallel APIs, the edge is added, but get edge by label doesn't return the edge. ATLAS-1104
//In some cases of parallel APIs, the edge is added, but get edge by label doesn't return the edge. ATLAS-1104
//So traversing all the edges
//So traversing all the edges
public
Iterator
<
AtlasEdge
>
getAdjacentEdgesByLabel
(
AtlasVertex
instanceVertex
,
AtlasEdgeDirection
direction
,
final
String
edgeLabel
)
{
public
static
Iterator
<
AtlasEdge
>
getAdjacentEdgesByLabel
(
AtlasVertex
instanceVertex
,
AtlasEdgeDirection
direction
,
final
String
edgeLabel
)
{
if
(
LOG
.
isDebugEnabled
())
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Finding edges for {} with label {}"
,
string
(
instanceVertex
),
edgeLabel
);
LOG
.
debug
(
"Finding edges for {} with label {}"
,
string
(
instanceVertex
),
edgeLabel
);
}
}
...
@@ -348,11 +351,11 @@ public final class GraphHelper {
...
@@ -348,11 +351,11 @@ public final class GraphHelper {
return
null
;
return
null
;
}
}
public
Iterator
<
AtlasEdge
>
getIncomingEdgesByLabel
(
AtlasVertex
instanceVertex
,
String
edgeLabel
)
{
public
static
Iterator
<
AtlasEdge
>
getIncomingEdgesByLabel
(
AtlasVertex
instanceVertex
,
String
edgeLabel
)
{
return
getAdjacentEdgesByLabel
(
instanceVertex
,
AtlasEdgeDirection
.
IN
,
edgeLabel
);
return
getAdjacentEdgesByLabel
(
instanceVertex
,
AtlasEdgeDirection
.
IN
,
edgeLabel
);
}
}
public
Iterator
<
AtlasEdge
>
getOutGoingEdgesByLabel
(
AtlasVertex
instanceVertex
,
String
edgeLabel
)
{
public
static
Iterator
<
AtlasEdge
>
getOutGoingEdgesByLabel
(
AtlasVertex
instanceVertex
,
String
edgeLabel
)
{
return
getAdjacentEdgesByLabel
(
instanceVertex
,
AtlasEdgeDirection
.
OUT
,
edgeLabel
);
return
getAdjacentEdgesByLabel
(
instanceVertex
,
AtlasEdgeDirection
.
OUT
,
edgeLabel
);
}
}
...
@@ -361,20 +364,24 @@ public final class GraphHelper {
...
@@ -361,20 +364,24 @@ public final class GraphHelper {
switch
(
edgeDirection
)
{
switch
(
edgeDirection
)
{
case
IN:
case
IN:
ret
=
getEdgeForLabel
(
vertex
,
edgeLabel
,
AtlasEdgeDirection
.
IN
);
ret
=
getEdgeForLabel
(
vertex
,
edgeLabel
,
AtlasEdgeDirection
.
IN
);
break
;
break
;
case
OUT:
case
OUT:
ret
=
getEdgeForLabel
(
vertex
,
edgeLabel
,
AtlasEdgeDirection
.
OUT
);
break
;
case
BOTH:
default
:
default
:
ret
=
getEdgeForLabel
(
vertex
,
edgeLabel
,
AtlasEdgeDirection
.
OUT
);
ret
=
getEdgeForLabel
(
vertex
,
edgeLabel
,
AtlasEdgeDirection
.
BOTH
);
break
;
break
;
}
}
return
ret
;
return
ret
;
}
}
public
Iterator
<
AtlasEdge
>
getEdgesForLabel
(
AtlasVertex
vertex
,
String
edgeLabel
,
AtlasRelationshipEdgeDirection
edgeDirection
)
{
public
static
Iterator
<
AtlasEdge
>
getEdgesForLabel
(
AtlasVertex
vertex
,
String
edgeLabel
,
AtlasRelationshipEdgeDirection
edgeDirection
)
{
Iterator
<
AtlasEdge
>
ret
;
Iterator
<
AtlasEdge
>
ret
=
null
;
switch
(
edgeDirection
)
{
switch
(
edgeDirection
)
{
case
IN:
case
IN:
...
@@ -382,8 +389,11 @@ public final class GraphHelper {
...
@@ -382,8 +389,11 @@ public final class GraphHelper {
break
;
break
;
case
OUT:
case
OUT:
default
:
ret
=
getOutGoingEdgesByLabel
(
vertex
,
edgeLabel
);
ret
=
getOutGoingEdgesByLabel
(
vertex
,
edgeLabel
);
break
;
case
BOTH:
ret
=
getAdjacentEdgesByLabel
(
vertex
,
AtlasEdgeDirection
.
BOTH
,
edgeLabel
);
break
;
break
;
}
}
...
@@ -1341,32 +1351,38 @@ public final class GraphHelper {
...
@@ -1341,32 +1351,38 @@ public final class GraphHelper {
return
StringUtils
.
isNotEmpty
(
edge
.
getLabel
())
?
edgeLabel
.
startsWith
(
"r:"
)
:
false
;
return
StringUtils
.
isNotEmpty
(
edge
.
getLabel
())
?
edgeLabel
.
startsWith
(
"r:"
)
:
false
;
}
}
public
static
AtlasObjectId
getReferenceObjectId
(
AtlasEdge
edge
,
AtlasRelationshipEdgeDirection
relationshipDirection
)
{
public
static
AtlasObjectId
getReferenceObjectId
(
AtlasEdge
edge
,
AtlasRelationshipEdgeDirection
relationshipDirection
,
AtlasVertex
parentVertex
)
{
AtlasObjectId
ret
=
null
;
AtlasObjectId
ret
=
null
;
if
(
relationshipDirection
==
AtlasRelationshipEdgeDirection
.
OUT
)
{
if
(
relationshipDirection
==
OUT
)
{
ret
=
new
AtlasObjectId
(
getGuid
(
edge
.
getInVertex
()),
getTypeName
(
edge
.
getInVertex
()));
ret
=
getAtlasObjectIdForInVertex
(
edge
);
}
else
if
(
relationshipDirection
==
IN
)
{
ret
=
getAtlasObjectIdForOutVertex
(
edge
);
}
else
if
(
relationshipDirection
==
AtlasRelationshipEdgeDirection
.
IN
)
{
}
else
if
(
relationshipDirection
==
BOTH
){
ret
=
new
AtlasObjectId
(
getGuid
(
edge
.
getOutVertex
()),
getTypeName
(
edge
.
getOutVertex
()));
// since relationship direction is BOTH, edge direction can be inward or outward
// compare with parent entity vertex and pick the right reference vertex
if
(
verticesEquals
(
parentVertex
,
edge
.
getOutVertex
()))
{
ret
=
getAtlasObjectIdForInVertex
(
edge
);
}
else
{
ret
=
getAtlasObjectIdForOutVertex
(
edge
);
}
}
}
return
ret
;
return
ret
;
}
}
public
static
AtlasObjectId
getCurrentObjectId
(
AtlasEdge
edge
,
AtlasRelationshipEdgeDirection
relationshipDirection
)
{
public
static
AtlasObjectId
getAtlasObjectIdForOutVertex
(
AtlasEdge
edge
)
{
String
typeName
=
null
;
return
new
AtlasObjectId
(
getGuid
(
edge
.
getOutVertex
()),
getTypeName
(
edge
.
getOutVertex
()));
String
guid
=
null
;
}
if
(
relationshipDirection
==
AtlasRelationshipEdgeDirection
.
OUT
)
{
typeName
=
GraphHelper
.
getTypeName
(
edge
.
getOutVertex
());
guid
=
GraphHelper
.
getGuid
(
edge
.
getOutVertex
());
}
else
if
(
relationshipDirection
==
AtlasRelationshipEdgeDirection
.
IN
)
{
public
static
AtlasObjectId
getAtlasObjectIdForInVertex
(
AtlasEdge
edge
)
{
typeName
=
GraphHelper
.
getTypeName
(
edge
.
getInVertex
());
return
new
AtlasObjectId
(
getGuid
(
edge
.
getInVertex
()),
getTypeName
(
edge
.
getInVertex
()));
guid
=
GraphHelper
.
getGuid
(
edge
.
getInVertex
());
}
}
return
new
AtlasObjectId
(
guid
,
typeName
);
private
static
boolean
verticesEquals
(
AtlasVertex
vertexA
,
AtlasVertex
vertexB
)
{
return
StringUtils
.
equals
(
getGuid
(
vertexB
),
getGuid
(
vertexA
));
}
}
}
}
\ No newline at end of file
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
View file @
f59284ad
...
@@ -40,6 +40,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
...
@@ -40,6 +40,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import
org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection
;
import
org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -54,9 +55,13 @@ import java.util.Set;
...
@@ -54,9 +55,13 @@ import java.util.Set;
import
java.util.Stack
;
import
java.util.Stack
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
EDGE_LABEL_PREFIX
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
EDGE_LABEL_PREFIX
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
getAtlasObjectIdForInVertex
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
getAtlasObjectIdForOutVertex
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
getGuid
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
getReferenceObjectId
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
getReferenceObjectId
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
isRelationshipEdge
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
isRelationshipEdge
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
string
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
string
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
BOTH
;
public
abstract
class
DeleteHandlerV1
{
public
abstract
class
DeleteHandlerV1
{
...
@@ -219,14 +224,14 @@ public abstract class DeleteHandlerV1 {
...
@@ -219,14 +224,14 @@ public abstract class DeleteHandlerV1 {
* @throws AtlasException
* @throws AtlasException
*/
*/
public
boolean
deleteEdgeReference
(
AtlasEdge
edge
,
TypeCategory
typeCategory
,
boolean
isOwned
,
public
boolean
deleteEdgeReference
(
AtlasEdge
edge
,
TypeCategory
typeCategory
,
boolean
isOwned
,
boolean
forceDeleteStructTrait
)
throws
AtlasBaseException
{
boolean
forceDeleteStructTrait
,
AtlasVertex
vertex
)
throws
AtlasBaseException
{
// default edge direction is outward
// default edge direction is outward
return
deleteEdgeReference
(
edge
,
typeCategory
,
isOwned
,
forceDeleteStructTrait
,
AtlasRelationshipEdgeDirection
.
OUT
);
return
deleteEdgeReference
(
edge
,
typeCategory
,
isOwned
,
forceDeleteStructTrait
,
AtlasRelationshipEdgeDirection
.
OUT
,
vertex
);
}
}
public
boolean
deleteEdgeReference
(
AtlasEdge
edge
,
TypeCategory
typeCategory
,
boolean
isOwned
,
boolean
forceDeleteStructTrait
,
public
boolean
deleteEdgeReference
(
AtlasEdge
edge
,
TypeCategory
typeCategory
,
boolean
isOwned
,
boolean
forceDeleteStructTrait
,
AtlasRelationshipEdgeDirection
relationshipDirection
)
throws
AtlasBaseException
{
AtlasRelationshipEdgeDirection
relationshipDirection
,
AtlasVertex
entityVertex
)
throws
AtlasBaseException
{
LOG
.
debug
(
"Deleting {}"
,
string
(
edge
));
LOG
.
debug
(
"Deleting {}"
,
string
(
edge
));
boolean
forceDelete
=
boolean
forceDelete
=
(
typeCategory
==
TypeCategory
.
STRUCT
||
typeCategory
==
TypeCategory
.
CLASSIFICATION
)
&&
forceDeleteStructTrait
;
(
typeCategory
==
TypeCategory
.
STRUCT
||
typeCategory
==
TypeCategory
.
CLASSIFICATION
)
&&
forceDeleteStructTrait
;
...
@@ -250,7 +255,7 @@ public abstract class DeleteHandlerV1 {
...
@@ -250,7 +255,7 @@ public abstract class DeleteHandlerV1 {
if
(
isRelationshipEdge
(
edge
))
{
if
(
isRelationshipEdge
(
edge
))
{
deleteEdge
(
edge
,
false
);
deleteEdge
(
edge
,
false
);
AtlasObjectId
deletedReferenceObjectId
=
getReferenceObjectId
(
edge
,
relationshipDirection
);
AtlasObjectId
deletedReferenceObjectId
=
getReferenceObjectId
(
edge
,
relationshipDirection
,
entityVertex
);
RequestContextV1
.
get
().
recordEntityUpdate
(
deletedReferenceObjectId
);
RequestContextV1
.
get
().
recordEntityUpdate
(
deletedReferenceObjectId
);
}
else
{
}
else
{
//legacy case - not a relationship edge
//legacy case - not a relationship edge
...
@@ -344,7 +349,7 @@ public abstract class DeleteHandlerV1 {
...
@@ -344,7 +349,7 @@ public abstract class DeleteHandlerV1 {
if
(
edges
!=
null
)
{
if
(
edges
!=
null
)
{
while
(
edges
.
hasNext
())
{
while
(
edges
.
hasNext
())
{
AtlasEdge
edge
=
edges
.
next
();
AtlasEdge
edge
=
edges
.
next
();
deleteEdgeReference
(
edge
,
elemType
.
getTypeCategory
(),
isOwned
,
false
);
deleteEdgeReference
(
edge
,
elemType
.
getTypeCategory
(),
isOwned
,
false
,
instanceVertex
);
}
}
}
}
}
}
...
@@ -377,7 +382,7 @@ public abstract class DeleteHandlerV1 {
...
@@ -377,7 +382,7 @@ public abstract class DeleteHandlerV1 {
boolean
isOwned
)
throws
AtlasBaseException
{
boolean
isOwned
)
throws
AtlasBaseException
{
AtlasEdge
edge
=
graphHelper
.
getEdgeForLabel
(
outVertex
,
edgeLabel
);
AtlasEdge
edge
=
graphHelper
.
getEdgeForLabel
(
outVertex
,
edgeLabel
);
if
(
edge
!=
null
)
{
if
(
edge
!=
null
)
{
deleteEdgeReference
(
edge
,
typeCategory
,
isOwned
,
false
);
deleteEdgeReference
(
edge
,
typeCategory
,
isOwned
,
false
,
outVertex
);
}
}
}
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
View file @
f59284ad
...
@@ -51,6 +51,7 @@ import org.apache.atlas.type.AtlasType;
...
@@ -51,6 +51,7 @@ import org.apache.atlas.type.AtlasType;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.IteratorUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -70,7 +71,9 @@ import static org.apache.atlas.repository.graph.GraphHelper.getTypeName;
...
@@ -70,7 +71,9 @@ import static org.apache.atlas.repository.graph.GraphHelper.getTypeName;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
isRelationshipEdge
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
isRelationshipEdge
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
string
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
string
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
.
AtlasGraphUtilsV1
.
getIdFromVertex
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
.
AtlasGraphUtilsV1
.
getIdFromVertex
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
BOTH
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
IN
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
IN
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
OUT
;
@Component
@Component
public
class
EntityGraphMapper
{
public
class
EntityGraphMapper
{
...
@@ -353,7 +356,7 @@ public class EntityGraphMapper {
...
@@ -353,7 +356,7 @@ public class EntityGraphMapper {
AtlasEdge
newEdge
=
mapStructValue
(
ctx
,
context
);
AtlasEdge
newEdge
=
mapStructValue
(
ctx
,
context
);
if
(
currentEdge
!=
null
&&
!
currentEdge
.
equals
(
newEdge
))
{
if
(
currentEdge
!=
null
&&
!
currentEdge
.
equals
(
newEdge
))
{
deleteHandler
.
deleteEdgeReference
(
currentEdge
,
ctx
.
getAttrType
().
getTypeCategory
(),
false
,
true
);
deleteHandler
.
deleteEdgeReference
(
currentEdge
,
ctx
.
getAttrType
().
getTypeCategory
(),
false
,
true
,
ctx
.
getReferringVertex
()
);
}
}
return
newEdge
;
return
newEdge
;
...
@@ -423,7 +426,7 @@ public class EntityGraphMapper {
...
@@ -423,7 +426,7 @@ public class EntityGraphMapper {
//delete old reference
//delete old reference
deleteHandler
.
deleteEdgeReference
(
currentEdge
,
ctx
.
getAttrType
().
getTypeCategory
(),
ctx
.
getAttribute
().
isOwnedRef
(),
deleteHandler
.
deleteEdgeReference
(
currentEdge
,
ctx
.
getAttrType
().
getTypeCategory
(),
ctx
.
getAttribute
().
isOwnedRef
(),
true
,
ctx
.
getAttribute
().
getRelationshipEdgeDirection
());
true
,
ctx
.
getAttribute
().
getRelationshipEdgeDirection
()
,
ctx
.
getReferringVertex
()
);
}
}
return
newEdge
;
return
newEdge
;
...
@@ -457,7 +460,7 @@ public class EntityGraphMapper {
...
@@ -457,7 +460,7 @@ public class EntityGraphMapper {
if
(!
inverseEdge
.
equals
(
newEdge
))
{
if
(!
inverseEdge
.
equals
(
newEdge
))
{
// Disconnect old reference
// Disconnect old reference
deleteHandler
.
deleteEdgeReference
(
inverseEdge
,
inverseAttribute
.
getAttributeType
().
getTypeCategory
(),
deleteHandler
.
deleteEdgeReference
(
inverseEdge
,
inverseAttribute
.
getAttributeType
().
getTypeCategory
(),
inverseAttribute
.
isOwnedRef
(),
true
);
inverseAttribute
.
isOwnedRef
(),
true
,
inverseVertex
);
}
}
else
{
else
{
// Edge already exists for this attribute between these vertices.
// Edge already exists for this attribute between these vertices.
...
@@ -675,9 +678,7 @@ public class EntityGraphMapper {
...
@@ -675,9 +678,7 @@ public class EntityGraphMapper {
Map
<
String
,
Object
>
relationshipAttributes
=
getRelationshipAttributes
(
ctx
.
getValue
());
Map
<
String
,
Object
>
relationshipAttributes
=
getRelationshipAttributes
(
ctx
.
getValue
());
if
(
ctx
.
getCurrentEdge
()
!=
null
)
{
if
(
ctx
.
getCurrentEdge
()
!=
null
)
{
ret
=
updateRelationship
(
ctx
.
getCurrentEdge
(),
attributeVertex
,
edgeDirection
,
relationshipAttributes
);
ret
=
updateRelationship
(
ctx
.
getCurrentEdge
(),
entityVertex
,
attributeVertex
,
edgeDirection
,
relationshipAttributes
);
recordEntityUpdate
(
attributeVertex
);
}
else
{
}
else
{
String
relationshipName
=
graphHelper
.
getRelationshipDefName
(
entityVertex
,
entityType
,
attributeName
);
String
relationshipName
=
graphHelper
.
getRelationshipDefName
(
entityVertex
,
entityType
,
attributeName
);
...
@@ -805,10 +806,16 @@ public class EntityGraphMapper {
...
@@ -805,10 +806,16 @@ public class EntityGraphMapper {
List
newElements
=
(
List
)
ctx
.
getValue
();
List
newElements
=
(
List
)
ctx
.
getValue
();
AtlasArrayType
arrType
=
(
AtlasArrayType
)
attribute
.
getAttributeType
();
AtlasArrayType
arrType
=
(
AtlasArrayType
)
attribute
.
getAttributeType
();
AtlasType
elementType
=
arrType
.
getElementType
();
AtlasType
elementType
=
arrType
.
getElementType
();
List
<
Object
>
currentElements
=
getArrayElementsProperty
(
elementType
,
ctx
.
getReferringVertex
(),
ctx
.
getVertexProperty
());
boolean
isReference
=
AtlasGraphUtilsV1
.
isReference
(
elementType
);
boolean
isReference
=
AtlasGraphUtilsV1
.
isReference
(
elementType
);
AtlasAttribute
inverseRefAttribute
=
attribute
.
getInverseRefAttribute
();
AtlasAttribute
inverseRefAttribute
=
attribute
.
getInverseRefAttribute
();
List
<
Object
>
newElementsCreated
=
new
ArrayList
<>();
List
<
Object
>
newElementsCreated
=
new
ArrayList
<>();
List
<
Object
>
currentElements
;
if
(
isRelationshipAttribute
(
attribute
))
{
currentElements
=
getArrayElementsUsingRelationship
(
ctx
.
getReferringVertex
(),
attribute
,
elementType
);
}
else
{
currentElements
=
getArrayElementsProperty
(
elementType
,
ctx
.
getReferringVertex
(),
ctx
.
getVertexProperty
());
}
if
(
CollectionUtils
.
isNotEmpty
(
newElements
))
{
if
(
CollectionUtils
.
isNotEmpty
(
newElements
))
{
for
(
int
index
=
0
;
index
<
newElements
.
size
();
index
++)
{
for
(
int
index
=
0
;
index
<
newElements
.
size
();
index
++)
{
...
@@ -817,6 +824,7 @@ public class EntityGraphMapper {
...
@@ -817,6 +824,7 @@ public class EntityGraphMapper {
ctx
.
getVertexProperty
(),
elementType
,
existingEdge
);
ctx
.
getVertexProperty
(),
elementType
,
existingEdge
);
Object
newEntry
=
mapCollectionElementsToVertex
(
arrCtx
,
context
);
Object
newEntry
=
mapCollectionElementsToVertex
(
arrCtx
,
context
);
if
(
isReference
&&
newEntry
instanceof
AtlasEdge
&&
inverseRefAttribute
!=
null
)
{
if
(
isReference
&&
newEntry
instanceof
AtlasEdge
&&
inverseRefAttribute
!=
null
)
{
// Update the inverse reference value.
// Update the inverse reference value.
AtlasEdge
newEdge
=
(
AtlasEdge
)
newEntry
;
AtlasEdge
newEdge
=
(
AtlasEdge
)
newEntry
;
...
@@ -829,7 +837,7 @@ public class EntityGraphMapper {
...
@@ -829,7 +837,7 @@ public class EntityGraphMapper {
}
}
if
(
isReference
)
{
if
(
isReference
)
{
List
<
AtlasEdge
>
additionalEdges
=
removeUnusedArrayEntries
(
attribute
,
(
List
)
currentElements
,
(
List
)
newElementsCreated
);
List
<
AtlasEdge
>
additionalEdges
=
removeUnusedArrayEntries
(
attribute
,
(
List
)
currentElements
,
(
List
)
newElementsCreated
,
ctx
.
getReferringVertex
()
);
newElementsCreated
.
addAll
(
additionalEdges
);
newElementsCreated
.
addAll
(
additionalEdges
);
}
}
...
@@ -1048,7 +1056,7 @@ public class EntityGraphMapper {
...
@@ -1048,7 +1056,7 @@ public class EntityGraphMapper {
AtlasEdge
currentEdge
=
(
AtlasEdge
)
currentMap
.
get
(
currentKey
);
AtlasEdge
currentEdge
=
(
AtlasEdge
)
currentMap
.
get
(
currentKey
);
if
(!
newMap
.
values
().
contains
(
currentEdge
))
{
if
(!
newMap
.
values
().
contains
(
currentEdge
))
{
boolean
deleted
=
deleteHandler
.
deleteEdgeReference
(
currentEdge
,
mapType
.
getValueType
().
getTypeCategory
(),
attribute
.
isOwnedRef
(),
true
);
boolean
deleted
=
deleteHandler
.
deleteEdgeReference
(
currentEdge
,
mapType
.
getValueType
().
getTypeCategory
(),
attribute
.
isOwnedRef
(),
true
,
vertex
);
if
(!
deleted
)
{
if
(!
deleted
)
{
additionalMap
.
put
(
currentKey
,
currentEdge
);
additionalMap
.
put
(
currentKey
,
currentEdge
);
...
@@ -1104,8 +1112,10 @@ public class EntityGraphMapper {
...
@@ -1104,8 +1112,10 @@ public class EntityGraphMapper {
return
newEdge
;
return
newEdge
;
}
}
private
AtlasEdge
updateRelationship
(
AtlasEdge
currentEdge
,
final
AtlasVertex
newEntityVertex
,
AtlasRelationshipEdgeDirection
edgeDirection
,
Map
<
String
,
Object
>
relationshipAttributes
)
throws
AtlasBaseException
{
private
AtlasEdge
updateRelationship
(
AtlasEdge
currentEdge
,
final
AtlasVertex
parentEntityVertex
,
final
AtlasVertex
newEntityVertex
,
AtlasRelationshipEdgeDirection
edgeDirection
,
Map
<
String
,
Object
>
relationshipAttributes
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Updating entity reference using relationship {} for reference attribute {}"
,
getTypeName
(
newEntityVertex
));
LOG
.
debug
(
"Updating entity reference using relationship {} for reference attribute {}"
,
getTypeName
(
newEntityVertex
));
}
}
...
@@ -1115,8 +1125,15 @@ public class EntityGraphMapper {
...
@@ -1115,8 +1125,15 @@ public class EntityGraphMapper {
// Max's mentor updated from John to Jane (John.mentee --> Max.mentor)
// Max's mentor updated from John to Jane (John.mentee --> Max.mentor)
// mentor attribute (IN direction), current mentee vertex (John) (OUT vertex)
// mentor attribute (IN direction), current mentee vertex (John) (OUT vertex)
String
currentEntityId
=
(
edgeDirection
==
IN
)
?
getIdFromVertex
(
currentEdge
.
getOutVertex
())
:
String
currentEntityId
;
getIdFromVertex
(
currentEdge
.
getInVertex
());
if
(
edgeDirection
==
IN
)
{
currentEntityId
=
getIdFromOutVertex
(
currentEdge
);
}
else
if
(
edgeDirection
==
OUT
)
{
currentEntityId
=
getIdFromInVertex
(
currentEdge
);
}
else
{
currentEntityId
=
getIdFromBothVertex
(
currentEdge
,
parentEntityVertex
);
}
String
newEntityId
=
getIdFromVertex
(
newEntityVertex
);
String
newEntityId
=
getIdFromVertex
(
newEntityVertex
);
AtlasEdge
ret
=
currentEdge
;
AtlasEdge
ret
=
currentEdge
;
...
@@ -1129,8 +1146,17 @@ public class EntityGraphMapper {
...
@@ -1129,8 +1146,17 @@ public class EntityGraphMapper {
relationshipName
=
currentEdge
.
getLabel
();
relationshipName
=
currentEdge
.
getLabel
();
}
}
ret
=
(
edgeDirection
==
IN
)
?
getOrCreateRelationship
(
newEntityVertex
,
currentEdge
.
getInVertex
(),
relationshipName
,
relationshipAttributes
)
:
if
(
edgeDirection
==
IN
)
{
getOrCreateRelationship
(
currentEdge
.
getOutVertex
(),
newEntityVertex
,
relationshipName
,
relationshipAttributes
);
ret
=
getOrCreateRelationship
(
newEntityVertex
,
currentEdge
.
getInVertex
(),
relationshipName
,
relationshipAttributes
);
}
else
if
(
edgeDirection
==
OUT
)
{
ret
=
getOrCreateRelationship
(
currentEdge
.
getOutVertex
(),
newEntityVertex
,
relationshipName
,
relationshipAttributes
);
}
else
{
ret
=
getOrCreateRelationship
(
newEntityVertex
,
parentEntityVertex
,
relationshipName
,
relationshipAttributes
);
}
//record entity update on new relationship vertex
recordEntityUpdate
(
newEntityVertex
);
}
}
return
ret
;
return
ret
;
...
@@ -1145,6 +1171,21 @@ public class EntityGraphMapper {
...
@@ -1145,6 +1171,21 @@ public class EntityGraphMapper {
}
}
}
}
public
static
List
<
Object
>
getArrayElementsUsingRelationship
(
AtlasVertex
vertex
,
AtlasAttribute
attribute
,
AtlasType
elementType
)
{
List
<
Object
>
ret
=
null
;
if
(
AtlasGraphUtilsV1
.
isReference
(
elementType
))
{
AtlasRelationshipEdgeDirection
edgeDirection
=
attribute
.
getRelationshipEdgeDirection
();
String
edgeLabel
=
attribute
.
getRelationshipEdgeLabel
();
Iterator
<
AtlasEdge
>
edgesForLabel
=
GraphHelper
.
getEdgesForLabel
(
vertex
,
edgeLabel
,
edgeDirection
);
ret
=
IteratorUtils
.
toList
(
edgesForLabel
);
}
return
ret
;
}
private
AtlasEdge
getEdgeAt
(
List
<
Object
>
currentElements
,
int
index
,
AtlasType
elemType
)
{
private
AtlasEdge
getEdgeAt
(
List
<
Object
>
currentElements
,
int
index
,
AtlasType
elemType
)
{
AtlasEdge
ret
=
null
;
AtlasEdge
ret
=
null
;
...
@@ -1158,7 +1199,8 @@ public class EntityGraphMapper {
...
@@ -1158,7 +1199,8 @@ public class EntityGraphMapper {
}
}
//Removes unused edges from the old collection, compared to the new collection
//Removes unused edges from the old collection, compared to the new collection
private
List
<
AtlasEdge
>
removeUnusedArrayEntries
(
AtlasAttribute
attribute
,
List
<
AtlasEdge
>
currentEntries
,
List
<
AtlasEdge
>
newEntries
)
throws
AtlasBaseException
{
private
List
<
AtlasEdge
>
removeUnusedArrayEntries
(
AtlasAttribute
attribute
,
List
<
AtlasEdge
>
currentEntries
,
List
<
AtlasEdge
>
newEntries
,
AtlasVertex
entityVertex
)
throws
AtlasBaseException
{
if
(
CollectionUtils
.
isNotEmpty
(
currentEntries
))
{
if
(
CollectionUtils
.
isNotEmpty
(
currentEntries
))
{
AtlasType
entryType
=
((
AtlasArrayType
)
attribute
.
getAttributeType
()).
getElementType
();
AtlasType
entryType
=
((
AtlasArrayType
)
attribute
.
getAttributeType
()).
getElementType
();
...
@@ -1170,7 +1212,7 @@ public class EntityGraphMapper {
...
@@ -1170,7 +1212,7 @@ public class EntityGraphMapper {
for
(
AtlasEdge
edge
:
edgesToRemove
)
{
for
(
AtlasEdge
edge
:
edgesToRemove
)
{
boolean
deleted
=
deleteHandler
.
deleteEdgeReference
(
edge
,
entryType
.
getTypeCategory
(),
attribute
.
isOwnedRef
(),
boolean
deleted
=
deleteHandler
.
deleteEdgeReference
(
edge
,
entryType
.
getTypeCategory
(),
attribute
.
isOwnedRef
(),
true
,
attribute
.
getRelationshipEdgeDirection
());
true
,
attribute
.
getRelationshipEdgeDirection
()
,
entityVertex
);
if
(!
deleted
)
{
if
(!
deleted
)
{
additionalElements
.
add
(
edge
);
additionalElements
.
add
(
edge
);
...
@@ -1184,7 +1226,6 @@ public class EntityGraphMapper {
...
@@ -1184,7 +1226,6 @@ public class EntityGraphMapper {
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
}
}
private
void
setArrayElementsProperty
(
AtlasType
elementType
,
AtlasVertex
vertex
,
String
vertexPropertyName
,
List
<
Object
>
values
)
{
private
void
setArrayElementsProperty
(
AtlasType
elementType
,
AtlasVertex
vertex
,
String
vertexPropertyName
,
List
<
Object
>
values
)
{
if
(
AtlasGraphUtilsV1
.
isReference
(
elementType
))
{
if
(
AtlasGraphUtilsV1
.
isReference
(
elementType
))
{
GraphHelper
.
setListPropertyFromElementIds
(
vertex
,
vertexPropertyName
,
(
List
)
values
);
GraphHelper
.
setListPropertyFromElementIds
(
vertex
,
vertexPropertyName
,
(
List
)
values
);
...
@@ -1334,7 +1375,7 @@ public class EntityGraphMapper {
...
@@ -1334,7 +1375,7 @@ public class EntityGraphMapper {
String
relationshipLabel
=
GraphHelper
.
getTraitLabel
(
entityTypeName
,
classificationName
);
String
relationshipLabel
=
GraphHelper
.
getTraitLabel
(
entityTypeName
,
classificationName
);
AtlasEdge
edge
=
graphHelper
.
getEdgeForLabel
(
instanceVertex
,
relationshipLabel
);
AtlasEdge
edge
=
graphHelper
.
getEdgeForLabel
(
instanceVertex
,
relationshipLabel
);
if
(
edge
!=
null
)
{
if
(
edge
!=
null
)
{
deleteHandler
.
deleteEdgeReference
(
edge
,
TypeCategory
.
CLASSIFICATION
,
false
,
true
);
deleteHandler
.
deleteEdgeReference
(
edge
,
TypeCategory
.
CLASSIFICATION
,
false
,
true
,
instanceVertex
);
// update the traits in entity once trait removal is successful
// update the traits in entity once trait removal is successful
traitNames
.
remove
(
classificationName
);
traitNames
.
remove
(
classificationName
);
...
@@ -1433,7 +1474,7 @@ public class EntityGraphMapper {
...
@@ -1433,7 +1474,7 @@ public class EntityGraphMapper {
private
static
void
compactAttributes
(
AtlasEntity
entity
)
{
private
static
void
compactAttributes
(
AtlasEntity
entity
)
{
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
Map
<
String
,
Object
>
relationshipAttributes
=
entity
.
getRelationshipAttributes
();
Map
<
String
,
Object
>
relationshipAttributes
=
entity
.
getRelationshipAttributes
();
Map
<
String
,
Object
>
attributes
=
entity
.
getAttributes
();
Map
<
String
,
Object
>
attributes
=
entity
.
getAttributes
();
if
(
MapUtils
.
isNotEmpty
(
relationshipAttributes
)
&&
MapUtils
.
isNotEmpty
(
attributes
))
{
if
(
MapUtils
.
isNotEmpty
(
relationshipAttributes
)
&&
MapUtils
.
isNotEmpty
(
attributes
))
{
for
(
String
attrName
:
relationshipAttributes
.
keySet
())
{
for
(
String
attrName
:
relationshipAttributes
.
keySet
())
{
...
@@ -1444,4 +1485,23 @@ public class EntityGraphMapper {
...
@@ -1444,4 +1485,23 @@ public class EntityGraphMapper {
}
}
}
}
}
}
}
private
String
getIdFromInVertex
(
AtlasEdge
edge
)
{
return
getIdFromVertex
(
edge
.
getInVertex
());
}
private
String
getIdFromOutVertex
(
AtlasEdge
edge
)
{
return
getIdFromVertex
(
edge
.
getOutVertex
());
}
private
String
getIdFromBothVertex
(
AtlasEdge
currentEdge
,
AtlasVertex
parentEntityVertex
)
{
String
parentEntityId
=
getIdFromVertex
(
parentEntityVertex
);
String
currentEntityId
=
getIdFromVertex
(
currentEdge
.
getInVertex
());
if
(
StringUtils
.
equals
(
currentEntityId
,
parentEntityId
))
{
currentEntityId
=
getIdFromOutVertex
(
currentEdge
);
}
return
currentEntityId
;
}
}
\ No newline at end of file
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
View file @
f59284ad
...
@@ -72,6 +72,9 @@ import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_STRING;
...
@@ -72,6 +72,9 @@ import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_STRING;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
EDGE_LABEL_PREFIX
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
EDGE_LABEL_PREFIX
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
.
AtlasGraphUtilsV1
.
getIdFromVertex
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
.
AtlasGraphUtilsV1
.
getIdFromVertex
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
BOTH
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
IN
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasStructType
.
AtlasAttribute
.
AtlasRelationshipEdgeDirection
.
OUT
;
public
final
class
EntityGraphRetriever
{
public
final
class
EntityGraphRetriever
{
...
@@ -683,10 +686,12 @@ public final class EntityGraphRetriever {
...
@@ -683,10 +686,12 @@ public final class EntityGraphRetriever {
List
<
AtlasRelatedObjectId
>
ret
=
new
ArrayList
<>();
List
<
AtlasRelatedObjectId
>
ret
=
new
ArrayList
<>();
Iterator
<
AtlasEdge
>
edges
=
null
;
Iterator
<
AtlasEdge
>
edges
=
null
;
if
(
attribute
.
getRelationshipEdgeDirection
()
==
AtlasRelationshipEdgeDirection
.
IN
)
{
if
(
attribute
.
getRelationshipEdgeDirection
()
==
IN
)
{
edges
=
graphHelper
.
getIncomingEdgesByLabel
(
entityVertex
,
attribute
.
getRelationshipEdgeLabel
());
edges
=
graphHelper
.
getIncomingEdgesByLabel
(
entityVertex
,
attribute
.
getRelationshipEdgeLabel
());
}
else
if
(
attribute
.
getRelationshipEdgeDirection
()
==
AtlasRelationshipEdgeDirection
.
OUT
)
{
}
else
if
(
attribute
.
getRelationshipEdgeDirection
()
==
OUT
)
{
edges
=
graphHelper
.
getOutGoingEdgesByLabel
(
entityVertex
,
attribute
.
getRelationshipEdgeLabel
());
edges
=
graphHelper
.
getOutGoingEdgesByLabel
(
entityVertex
,
attribute
.
getRelationshipEdgeLabel
());
}
else
if
(
attribute
.
getRelationshipEdgeDirection
()
==
BOTH
)
{
edges
=
graphHelper
.
getAdjacentEdgesByLabel
(
entityVertex
,
AtlasEdgeDirection
.
BOTH
,
attribute
.
getRelationshipEdgeLabel
());
}
}
if
(
edges
!=
null
)
{
if
(
edges
!=
null
)
{
...
...
repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreHardDeleteV1Test.java
View file @
f59284ad
...
@@ -20,9 +20,15 @@ package org.apache.atlas.repository.store.graph.v1;
...
@@ -20,9 +20,15 @@ package org.apache.atlas.repository.store.graph.v1;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
org.apache.atlas.TestModules
;
import
org.apache.atlas.TestModules
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.testng.annotations.Guice
;
import
org.testng.annotations.Guice
;
import
java.util.List
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasTypeUtil
.
getAtlasObjectId
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasTypeUtil
.
getAtlasObjectId
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertNull
;
/**
/**
* Inverse reference update test with {@link HardDeleteHandlerV1}
* Inverse reference update test with {@link HardDeleteHandlerV1}
...
@@ -51,4 +57,56 @@ public class AtlasRelationshipStoreHardDeleteV1Test extends AtlasRelationshipSto
...
@@ -51,4 +57,56 @@ public class AtlasRelationshipStoreHardDeleteV1Test extends AtlasRelationshipSto
protected
void
verifyRelationshipAttributeUpdate_NonComposite_OneToOne
(
AtlasEntity
a1
,
AtlasEntity
b
)
{
protected
void
verifyRelationshipAttributeUpdate_NonComposite_OneToOne
(
AtlasEntity
a1
,
AtlasEntity
b
)
{
verifyRelationshipAttributeValue
(
a1
,
"b"
,
null
);
verifyRelationshipAttributeValue
(
a1
,
"b"
,
null
);
}
}
}
@Override
protected
void
verifyRelationshipAttributeUpdate_ManyToMany_Friends
(
AtlasEntity
max
,
AtlasEntity
julius
,
AtlasEntity
mike
,
AtlasEntity
john
)
throws
Exception
{
AtlasObjectId
johnId
=
employeeNameIdMap
.
get
(
"John"
);
AtlasObjectId
mikeId
=
employeeNameIdMap
.
get
(
"Mike"
);
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
maxId
=
employeeNameIdMap
.
get
(
"Max"
);
List
<
AtlasObjectId
>
maxFriendsIds
=
toAtlasObjectIds
(
max
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
maxFriendsIds
);
assertEquals
(
maxFriendsIds
.
size
(),
2
);
assertObjectIdsContains
(
maxFriendsIds
,
johnId
);
assertObjectIdsContains
(
maxFriendsIds
,
juliusId
);
// Julius's updated friends: [Max]
List
<
AtlasObjectId
>
juliusFriendsIds
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
juliusFriendsIds
);
assertEquals
(
juliusFriendsIds
.
size
(),
1
);
assertObjectIdsContains
(
juliusFriendsIds
,
maxId
);
// Mike's updated friends: [John]
List
<
AtlasObjectId
>
mikeFriendsIds
=
toAtlasObjectIds
(
mike
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
mikeFriendsIds
);
assertEquals
(
mikeFriendsIds
.
size
(),
1
);
assertObjectIdsContains
(
mikeFriendsIds
,
johnId
);
// John's updated friends: [Max, Mike]
List
<
AtlasObjectId
>
johnFriendsIds
=
toAtlasObjectIds
(
john
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
johnFriendsIds
);
assertEquals
(
johnFriendsIds
.
size
(),
2
);
assertObjectIdsContains
(
johnFriendsIds
,
maxId
);
assertObjectIdsContains
(
johnFriendsIds
,
mikeId
);
}
protected
void
verifyRelationshipAttributeUpdate_OneToOne_Sibling
(
AtlasEntity
julius
,
AtlasEntity
jane
,
AtlasEntity
mike
)
throws
Exception
{
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
mikeId
=
employeeNameIdMap
.
get
(
"Mike"
);
// Julius sibling updated to Mike
AtlasObjectId
juliusSiblingId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"sibling"
));
assertNotNull
(
juliusSiblingId
);
assertObjectIdEquals
(
juliusSiblingId
,
mikeId
);
// Mike's sibling is Julius
AtlasObjectId
mikeSiblingId
=
toAtlasObjectId
(
mike
.
getRelationshipAttribute
(
"sibling"
));
assertNotNull
(
mikeSiblingId
);
assertObjectIdEquals
(
mikeSiblingId
,
juliusId
);
// Julius removed from Jane's sibling (hard delete)
AtlasObjectId
janeSiblingId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"sibling"
));
assertNull
(
janeSiblingId
);
}
}
\ No newline at end of file
repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreSoftDeleteV1Test.java
View file @
f59284ad
...
@@ -20,9 +20,14 @@ package org.apache.atlas.repository.store.graph.v1;
...
@@ -20,9 +20,14 @@ package org.apache.atlas.repository.store.graph.v1;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
org.apache.atlas.TestModules
;
import
org.apache.atlas.TestModules
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.testng.annotations.Guice
;
import
org.testng.annotations.Guice
;
import
java.util.List
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasTypeUtil
.
getAtlasObjectId
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasTypeUtil
.
getAtlasObjectId
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
/**
/**
...
@@ -52,4 +57,60 @@ public class AtlasRelationshipStoreSoftDeleteV1Test extends AtlasRelationshipSto
...
@@ -52,4 +57,60 @@ public class AtlasRelationshipStoreSoftDeleteV1Test extends AtlasRelationshipSto
protected
void
verifyRelationshipAttributeUpdate_NonComposite_OneToOne
(
AtlasEntity
a1
,
AtlasEntity
b
)
{
protected
void
verifyRelationshipAttributeUpdate_NonComposite_OneToOne
(
AtlasEntity
a1
,
AtlasEntity
b
)
{
verifyRelationshipAttributeValue
(
a1
,
"b"
,
b
.
getGuid
());
verifyRelationshipAttributeValue
(
a1
,
"b"
,
b
.
getGuid
());
}
}
}
@Override
protected
void
verifyRelationshipAttributeUpdate_ManyToMany_Friends
(
AtlasEntity
max
,
AtlasEntity
julius
,
AtlasEntity
mike
,
AtlasEntity
john
)
throws
Exception
{
AtlasObjectId
johnId
=
employeeNameIdMap
.
get
(
"John"
);
AtlasObjectId
mikeId
=
employeeNameIdMap
.
get
(
"Mike"
);
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
maxId
=
employeeNameIdMap
.
get
(
"Max"
);
// Max's updated friends: [Julius, John, Mike(soft deleted)]
List
<
AtlasObjectId
>
maxFriendsIds
=
toAtlasObjectIds
(
max
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
maxFriendsIds
);
assertEquals
(
maxFriendsIds
.
size
(),
3
);
assertObjectIdsContains
(
maxFriendsIds
,
johnId
);
assertObjectIdsContains
(
maxFriendsIds
,
juliusId
);
assertObjectIdsContains
(
maxFriendsIds
,
mikeId
);
// Julius's updated friends: [Max]
List
<
AtlasObjectId
>
juliusFriendsIds
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
juliusFriendsIds
);
assertEquals
(
juliusFriendsIds
.
size
(),
1
);
assertObjectIdsContains
(
juliusFriendsIds
,
maxId
);
// Mike's updated friends: [John, Max(soft deleted)]
List
<
AtlasObjectId
>
mikeFriendsIds
=
toAtlasObjectIds
(
mike
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
mikeFriendsIds
);
assertEquals
(
mikeFriendsIds
.
size
(),
2
);
assertObjectIdsContains
(
mikeFriendsIds
,
johnId
);
assertObjectIdsContains
(
mikeFriendsIds
,
maxId
);
// John's updated friends: [Max, Mike]
List
<
AtlasObjectId
>
johnFriendsIds
=
toAtlasObjectIds
(
john
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
johnFriendsIds
);
assertEquals
(
johnFriendsIds
.
size
(),
2
);
assertObjectIdsContains
(
johnFriendsIds
,
maxId
);
assertObjectIdsContains
(
johnFriendsIds
,
mikeId
);
}
protected
void
verifyRelationshipAttributeUpdate_OneToOne_Sibling
(
AtlasEntity
julius
,
AtlasEntity
jane
,
AtlasEntity
mike
)
throws
Exception
{
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
mikeId
=
employeeNameIdMap
.
get
(
"Mike"
);
// Julius sibling updated to Mike
AtlasObjectId
juliusSiblingId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"sibling"
));
assertNotNull
(
juliusSiblingId
);
assertObjectIdEquals
(
juliusSiblingId
,
mikeId
);
// Mike's sibling is Julius
AtlasObjectId
mikeSiblingId
=
toAtlasObjectId
(
mike
.
getRelationshipAttribute
(
"sibling"
));
assertNotNull
(
mikeSiblingId
);
assertObjectIdEquals
(
mikeSiblingId
,
juliusId
);
// Jane's sibling is still Julius (soft delete)
AtlasObjectId
janeSiblingId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"sibling"
));
assertNotNull
(
janeSiblingId
);
assertObjectIdEquals
(
janeSiblingId
,
juliusId
);
}
}
\ No newline at end of file
repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1Test.java
View file @
f59284ad
...
@@ -131,21 +131,24 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -131,21 +131,24 @@ public abstract class AtlasRelationshipStoreV1Test {
AtlasObjectId
johnId
=
employeeNameIdMap
.
get
(
"John"
);
AtlasObjectId
johnId
=
employeeNameIdMap
.
get
(
"John"
);
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
janeId
=
employeeNameIdMap
.
get
(
"Jane"
);
AtlasObjectId
janeId
=
employeeNameIdMap
.
get
(
"Jane"
);
AtlasObjectId
mikeId
=
employeeNameIdMap
.
get
(
"Mike"
);
AtlasEntity
hrDept
=
getEntityFromStore
(
hrId
.
getGuid
());
AtlasEntity
hrDept
=
getEntityFromStore
(
hrId
.
getGuid
());
AtlasEntity
max
=
getEntityFromStore
(
maxId
.
getGuid
());
AtlasEntity
max
=
getEntityFromStore
(
maxId
.
getGuid
());
AtlasEntity
john
=
getEntityFromStore
(
johnId
.
getGuid
());
AtlasEntity
john
=
getEntityFromStore
(
johnId
.
getGuid
());
AtlasEntity
julius
=
getEntityFromStore
(
juliusId
.
getGuid
());
AtlasEntity
julius
=
getEntityFromStore
(
juliusId
.
getGuid
());
AtlasEntity
jane
=
getEntityFromStore
(
janeId
.
getGuid
());
AtlasEntity
jane
=
getEntityFromStore
(
janeId
.
getGuid
());
AtlasEntity
mike
=
getEntityFromStore
(
mikeId
.
getGuid
());
// Department relationship attributes
// Department relationship attributes
List
<
AtlasObjectId
>
deptEmployees
=
toAtlasObjectIds
(
hrDept
.
getRelationshipAttribute
(
"employees"
));
List
<
AtlasObjectId
>
deptEmployees
=
toAtlasObjectIds
(
hrDept
.
getRelationshipAttribute
(
"employees"
));
assertNotNull
(
deptEmployees
);
assertNotNull
(
deptEmployees
);
assertEquals
(
deptEmployees
.
size
(),
4
);
assertEquals
(
deptEmployees
.
size
(),
5
);
assertObjectIdsContains
(
deptEmployees
,
maxId
);
assertObjectIdsContains
(
deptEmployees
,
maxId
);
assertObjectIdsContains
(
deptEmployees
,
johnId
);
assertObjectIdsContains
(
deptEmployees
,
johnId
);
assertObjectIdsContains
(
deptEmployees
,
juliusId
);
assertObjectIdsContains
(
deptEmployees
,
juliusId
);
assertObjectIdsContains
(
deptEmployees
,
janeId
);
assertObjectIdsContains
(
deptEmployees
,
janeId
);
assertObjectIdsContains
(
deptEmployees
,
mikeId
);
// Max employee validation
// Max employee validation
AtlasObjectId
maxDepartmentId
=
toAtlasObjectId
(
max
.
getRelationshipAttribute
(
"department"
));
AtlasObjectId
maxDepartmentId
=
toAtlasObjectId
(
max
.
getRelationshipAttribute
(
"department"
));
...
@@ -156,15 +159,22 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -156,15 +159,22 @@ public abstract class AtlasRelationshipStoreV1Test {
assertNotNull
(
maxManagerId
);
assertNotNull
(
maxManagerId
);
assertObjectIdEquals
(
maxManagerId
,
janeId
);
assertObjectIdEquals
(
maxManagerId
,
janeId
);
AtlasObjectId
maxMentorId
=
toAtlasObjectId
(
max
.
getRelationshipAttribute
(
"mentor"
));
List
<
AtlasObjectId
>
maxMentorsId
=
toAtlasObjectIds
(
max
.
getRelationshipAttribute
(
"mentors"
));
assertNotNull
(
maxMentorId
);
assertNotNull
(
maxMentorsId
);
assertObjectIdEquals
(
maxMentorId
,
juliusId
);
assertEquals
(
maxMentorsId
.
size
(),
1
);
assertObjectIdEquals
(
maxMentorsId
.
get
(
0
),
juliusId
);
List
<
AtlasObjectId
>
maxMenteesId
=
toAtlasObjectIds
(
max
.
getRelationshipAttribute
(
"mentees"
));
List
<
AtlasObjectId
>
maxMenteesId
=
toAtlasObjectIds
(
max
.
getRelationshipAttribute
(
"mentees"
));
assertNotNull
(
maxMenteesId
);
assertNotNull
(
maxMenteesId
);
assertEquals
(
maxMenteesId
.
size
(),
1
);
assertEquals
(
maxMenteesId
.
size
(),
1
);
assertObjectIdEquals
(
maxMenteesId
.
get
(
0
),
johnId
);
assertObjectIdEquals
(
maxMenteesId
.
get
(
0
),
johnId
);
List
<
AtlasObjectId
>
maxFriendsIds
=
toAtlasObjectIds
(
max
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
maxFriendsIds
);
assertEquals
(
maxFriendsIds
.
size
(),
2
);
assertObjectIdsContains
(
maxFriendsIds
,
mikeId
);
assertObjectIdsContains
(
maxFriendsIds
,
johnId
);
// John Employee validation
// John Employee validation
AtlasObjectId
johnDepartmentId
=
toAtlasObjectId
(
john
.
getRelationshipAttribute
(
"department"
));
AtlasObjectId
johnDepartmentId
=
toAtlasObjectId
(
john
.
getRelationshipAttribute
(
"department"
));
assertNotNull
(
johnDepartmentId
);
assertNotNull
(
johnDepartmentId
);
...
@@ -174,13 +184,42 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -174,13 +184,42 @@ public abstract class AtlasRelationshipStoreV1Test {
assertNotNull
(
johnManagerId
);
assertNotNull
(
johnManagerId
);
assertObjectIdEquals
(
johnManagerId
,
janeId
);
assertObjectIdEquals
(
johnManagerId
,
janeId
);
AtlasObjectId
johnMentorId
=
toAtlasObjectId
(
john
.
getRelationshipAttribute
(
"mentor"
));
List
<
AtlasObjectId
>
johnMentorIds
=
toAtlasObjectIds
(
john
.
getRelationshipAttribute
(
"mentors"
));
assertNotNull
(
johnMentorId
);
assertNotNull
(
johnMentorIds
);
assertObjectIdEquals
(
johnMentorId
,
maxId
);
assertEquals
(
johnMentorIds
.
size
(),
2
);
assertObjectIdsContains
(
johnMentorIds
,
maxId
);
assertObjectIdsContains
(
johnMentorIds
,
juliusId
);
List
<
AtlasObjectId
>
johnMenteesId
=
toAtlasObjectIds
(
john
.
getRelationshipAttribute
(
"mentees"
));
List
<
AtlasObjectId
>
johnMenteesId
=
toAtlasObjectIds
(
john
.
getRelationshipAttribute
(
"mentees"
));
assertEmpty
(
johnMenteesId
);
assertEmpty
(
johnMenteesId
);
List
<
AtlasObjectId
>
johnFriendsIds
=
toAtlasObjectIds
(
john
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
johnFriendsIds
);
assertEquals
(
johnFriendsIds
.
size
(),
2
);
assertObjectIdsContains
(
johnFriendsIds
,
mikeId
);
assertObjectIdsContains
(
johnFriendsIds
,
maxId
);
// Mike Employee validation
AtlasObjectId
mikeDepartmentId
=
toAtlasObjectId
(
mike
.
getRelationshipAttribute
(
"department"
));
assertNotNull
(
mikeDepartmentId
);
assertObjectIdEquals
(
mikeDepartmentId
,
hrId
);
AtlasObjectId
mikeManagerId
=
toAtlasObjectId
(
mike
.
getRelationshipAttribute
(
"manager"
));
assertNotNull
(
mikeManagerId
);
assertObjectIdEquals
(
mikeManagerId
,
juliusId
);
List
<
AtlasObjectId
>
mikeMentorIds
=
toAtlasObjectIds
(
mike
.
getRelationshipAttribute
(
"mentors"
));
assertEmpty
(
mikeMentorIds
);
List
<
AtlasObjectId
>
mikeMenteesId
=
toAtlasObjectIds
(
mike
.
getRelationshipAttribute
(
"mentees"
));
assertEmpty
(
mikeMenteesId
);
List
<
AtlasObjectId
>
mikeFriendsIds
=
toAtlasObjectIds
(
mike
.
getRelationshipAttribute
(
"friends"
));
assertNotNull
(
mikeFriendsIds
);
assertEquals
(
mikeFriendsIds
.
size
(),
2
);
assertObjectIdsContains
(
mikeFriendsIds
,
maxId
);
assertObjectIdsContains
(
mikeFriendsIds
,
johnId
);
// Jane Manager validation
// Jane Manager validation
AtlasObjectId
janeDepartmentId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"department"
));
AtlasObjectId
janeDepartmentId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"department"
));
assertNotNull
(
janeDepartmentId
);
assertNotNull
(
janeDepartmentId
);
...
@@ -189,8 +228,8 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -189,8 +228,8 @@ public abstract class AtlasRelationshipStoreV1Test {
AtlasObjectId
janeManagerId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"manager"
));
AtlasObjectId
janeManagerId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"manager"
));
assertNull
(
janeManagerId
);
assertNull
(
janeManagerId
);
AtlasObjectId
janeMentorId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"mentor
"
));
List
<
AtlasObjectId
>
janeMentorIds
=
toAtlasObjectIds
(
jane
.
getRelationshipAttribute
(
"mentors
"
));
assert
Null
(
janeMentorId
);
assert
Empty
(
janeMentorIds
);
List
<
AtlasObjectId
>
janeMenteesId
=
toAtlasObjectIds
(
jane
.
getRelationshipAttribute
(
"mentees"
));
List
<
AtlasObjectId
>
janeMenteesId
=
toAtlasObjectIds
(
jane
.
getRelationshipAttribute
(
"mentees"
));
assertEmpty
(
janeMenteesId
);
assertEmpty
(
janeMenteesId
);
...
@@ -201,6 +240,13 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -201,6 +240,13 @@ public abstract class AtlasRelationshipStoreV1Test {
assertObjectIdsContains
(
janeSubordinateIds
,
maxId
);
assertObjectIdsContains
(
janeSubordinateIds
,
maxId
);
assertObjectIdsContains
(
janeSubordinateIds
,
johnId
);
assertObjectIdsContains
(
janeSubordinateIds
,
johnId
);
List
<
AtlasObjectId
>
janeFriendsIds
=
toAtlasObjectIds
(
jane
.
getRelationshipAttribute
(
"friends"
));
assertEmpty
(
janeFriendsIds
);
AtlasObjectId
janeSiblingId
=
toAtlasObjectId
(
jane
.
getRelationshipAttribute
(
"sibling"
));
assertNotNull
(
janeSiblingId
);
assertObjectIdEquals
(
janeSiblingId
,
juliusId
);
// Julius Manager validation
// Julius Manager validation
AtlasObjectId
juliusDepartmentId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"department"
));
AtlasObjectId
juliusDepartmentId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"department"
));
assertNotNull
(
juliusDepartmentId
);
assertNotNull
(
juliusDepartmentId
);
...
@@ -209,16 +255,26 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -209,16 +255,26 @@ public abstract class AtlasRelationshipStoreV1Test {
AtlasObjectId
juliusManagerId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"manager"
));
AtlasObjectId
juliusManagerId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"manager"
));
assertNull
(
juliusManagerId
);
assertNull
(
juliusManagerId
);
AtlasObjectId
juliusMentorId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"mentor
"
));
List
<
AtlasObjectId
>
juliusMentorIds
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"mentors
"
));
assert
Null
(
juliusMentorId
);
assert
Empty
(
juliusMentorIds
);
List
<
AtlasObjectId
>
juliusMenteesId
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"mentees"
));
List
<
AtlasObjectId
>
juliusMenteesId
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"mentees"
));
assertNotNull
(
juliusMenteesId
);
assertNotNull
(
juliusMenteesId
);
assertEquals
(
juliusMenteesId
.
size
(),
1
);
assertEquals
(
juliusMenteesId
.
size
(),
2
);
assertObjectIdsContains
(
juliusMenteesId
,
maxId
);
assertObjectIdsContains
(
juliusMenteesId
,
maxId
);
assertObjectIdsContains
(
juliusMenteesId
,
johnId
);
List
<
AtlasObjectId
>
juliusSubordinateIds
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"subordinates"
));
List
<
AtlasObjectId
>
juliusSubordinateIds
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"subordinates"
));
assertEmpty
(
juliusSubordinateIds
);
assertNotNull
(
juliusSubordinateIds
);
assertEquals
(
juliusSubordinateIds
.
size
(),
1
);
assertObjectIdsContains
(
juliusSubordinateIds
,
mikeId
);
List
<
AtlasObjectId
>
juliusFriendsIds
=
toAtlasObjectIds
(
julius
.
getRelationshipAttribute
(
"friends"
));
assertEmpty
(
juliusFriendsIds
);
AtlasObjectId
juliusSiblingId
=
toAtlasObjectId
(
julius
.
getRelationshipAttribute
(
"sibling"
));
assertNotNull
(
juliusSiblingId
);
assertObjectIdEquals
(
juliusSiblingId
,
janeId
);
}
}
@Test
@Test
...
@@ -226,6 +282,8 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -226,6 +282,8 @@ public abstract class AtlasRelationshipStoreV1Test {
AtlasObjectId
maxId
=
employeeNameIdMap
.
get
(
"Max"
);
AtlasObjectId
maxId
=
employeeNameIdMap
.
get
(
"Max"
);
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
juliusId
=
employeeNameIdMap
.
get
(
"Julius"
);
AtlasObjectId
janeId
=
employeeNameIdMap
.
get
(
"Jane"
);
AtlasObjectId
janeId
=
employeeNameIdMap
.
get
(
"Jane"
);
AtlasObjectId
mikeId
=
employeeNameIdMap
.
get
(
"Mike"
);
AtlasObjectId
johnId
=
employeeNameIdMap
.
get
(
"John"
);
// Change Max's Employee.manager reference to Julius and apply the change as a partial update.
// Change Max's Employee.manager reference to Julius and apply the change as a partial update.
// This should also update Julius to add Max to the inverse Manager.subordinates reference.
// This should also update Julius to add Max to the inverse Manager.subordinates reference.
...
@@ -249,9 +307,9 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -249,9 +307,9 @@ public abstract class AtlasRelationshipStoreV1Test {
AtlasEntity
maxEntity
=
updatedEntities
.
getEntity
(
maxId
.
getGuid
());
AtlasEntity
maxEntity
=
updatedEntities
.
getEntity
(
maxId
.
getGuid
());
verifyRelationshipAttributeValue
(
maxEntity
,
"manager"
,
juliusId
.
getGuid
());
verifyRelationshipAttributeValue
(
maxEntity
,
"manager"
,
juliusId
.
getGuid
());
// Max added to the subordinate list of Julius
// Max added to the subordinate list of Julius
, existing subordinate is Mike
AtlasEntity
juliusEntity
=
updatedEntities
.
getEntity
(
juliusId
.
getGuid
());
AtlasEntity
juliusEntity
=
updatedEntities
.
getEntity
(
juliusId
.
getGuid
());
verifyRelationshipAttributeList
(
juliusEntity
,
"subordinates"
,
ImmutableList
.
of
(
maxId
));
verifyRelationshipAttributeList
(
juliusEntity
,
"subordinates"
,
ImmutableList
.
of
(
maxId
,
mikeId
));
// Max removed from the subordinate list of Julius
// Max removed from the subordinate list of Julius
AtlasEntity
janeEntity
=
updatedEntities
.
getEntity
(
janeId
.
getGuid
());
AtlasEntity
janeEntity
=
updatedEntities
.
getEntity
(
janeId
.
getGuid
());
...
@@ -259,6 +317,48 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -259,6 +317,48 @@ public abstract class AtlasRelationshipStoreV1Test {
// Jane's subordinates list includes John and Max for soft delete
// Jane's subordinates list includes John and Max for soft delete
// Jane's subordinates list includes only John for hard delete
// Jane's subordinates list includes only John for hard delete
verifyRelationshipAttributeUpdate_NonComposite_OneToMany
(
janeEntity
);
verifyRelationshipAttributeUpdate_NonComposite_OneToMany
(
janeEntity
);
// Remove Mike from Max's friends list
// Max's current friends: [Mike, John]
// Max's updated friends: [Julius, John]
maxEntityForUpdate
=
new
AtlasEntity
(
EMPLOYEE_TYPE
);
maxEntityForUpdate
.
setRelationshipAttribute
(
"friends"
,
ImmutableList
.
of
(
johnId
,
juliusId
));
init
();
updateResponse
=
entityStore
.
updateByUniqueAttributes
(
employeeType
,
uniqAttributes
,
new
AtlasEntityWithExtInfo
(
maxEntityForUpdate
));
partialUpdatedEntities
=
updateResponse
.
getPartialUpdatedEntities
();
assertEquals
(
partialUpdatedEntities
.
size
(),
3
);
// 3 entities should have been updated:
// * Max added Julius and removed Mike from Employee.friends
// * Mike removed Max from Employee.friends
// * Julius added Max in Employee.friends
updatedEntities
=
entityStore
.
getByIds
(
ImmutableList
.
of
(
maxId
.
getGuid
(),
mikeId
.
getGuid
(),
johnId
.
getGuid
(),
juliusId
.
getGuid
()));
maxEntity
=
updatedEntities
.
getEntity
(
maxId
.
getGuid
());
juliusEntity
=
updatedEntities
.
getEntity
(
juliusId
.
getGuid
());
AtlasEntity
mikeEntity
=
updatedEntities
.
getEntity
(
mikeId
.
getGuid
());
AtlasEntity
johnEntity
=
updatedEntities
.
getEntity
(
johnId
.
getGuid
());
verifyRelationshipAttributeUpdate_ManyToMany_Friends
(
maxEntity
,
juliusEntity
,
mikeEntity
,
johnEntity
);
// Remove Julius from Jane's sibling and add Mike as new sibling
AtlasEntity
juliusEntityForUpdate
=
new
AtlasEntity
(
EMPLOYEE_TYPE
);
juliusEntityForUpdate
.
setRelationshipAttribute
(
"sibling"
,
mikeId
);
init
();
updateResponse
=
entityStore
.
updateByUniqueAttributes
(
employeeType
,
Collections
.<
String
,
Object
>
singletonMap
(
"name"
,
"Julius"
)
,
new
AtlasEntityWithExtInfo
(
juliusEntityForUpdate
));
partialUpdatedEntities
=
updateResponse
.
getPartialUpdatedEntities
();
assertEquals
(
partialUpdatedEntities
.
size
(),
3
);
updatedEntities
=
entityStore
.
getByIds
(
ImmutableList
.
of
(
juliusId
.
getGuid
(),
janeId
.
getGuid
(),
mikeId
.
getGuid
()));
juliusEntity
=
updatedEntities
.
getEntity
(
juliusId
.
getGuid
());
janeEntity
=
updatedEntities
.
getEntity
(
janeId
.
getGuid
());
mikeEntity
=
updatedEntities
.
getEntity
(
mikeId
.
getGuid
());
verifyRelationshipAttributeUpdate_OneToOne_Sibling
(
juliusEntity
,
janeEntity
,
mikeEntity
);
}
}
@Test
@Test
...
@@ -445,12 +545,16 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -445,12 +545,16 @@ public abstract class AtlasRelationshipStoreV1Test {
protected
abstract
void
verifyRelationshipAttributeUpdate_NonComposite_ManyToOne
(
AtlasEntity
a1
,
AtlasEntity
a2
,
AtlasEntity
a3
,
AtlasEntity
b
);
protected
abstract
void
verifyRelationshipAttributeUpdate_NonComposite_ManyToOne
(
AtlasEntity
a1
,
AtlasEntity
a2
,
AtlasEntity
a3
,
AtlasEntity
b
);
private
static
void
assertObjectIdsContains
(
List
<
AtlasObjectId
>
objectIds
,
AtlasObjectId
objectId
)
{
protected
abstract
void
verifyRelationshipAttributeUpdate_ManyToMany_Friends
(
AtlasEntity
e1
,
AtlasEntity
e2
,
AtlasEntity
e3
,
AtlasEntity
e4
)
throws
Exception
;
protected
abstract
void
verifyRelationshipAttributeUpdate_OneToOne_Sibling
(
AtlasEntity
e1
,
AtlasEntity
e2
,
AtlasEntity
e3
)
throws
Exception
;
protected
static
void
assertObjectIdsContains
(
List
<
AtlasObjectId
>
objectIds
,
AtlasObjectId
objectId
)
{
assertTrue
(
CollectionUtils
.
isNotEmpty
(
objectIds
));
assertTrue
(
CollectionUtils
.
isNotEmpty
(
objectIds
));
assertTrue
(
objectIds
.
contains
(
objectId
));
assertTrue
(
objectIds
.
contains
(
objectId
));
}
}
pr
ivate
static
void
assertObjectIdEquals
(
AtlasObjectId
objId1
,
AtlasObjectId
objId2
)
{
pr
otected
static
void
assertObjectIdEquals
(
AtlasObjectId
objId1
,
AtlasObjectId
objId2
)
{
assertTrue
(
objId1
.
equals
(
objId2
));
assertTrue
(
objId1
.
equals
(
objId2
));
}
}
...
@@ -458,7 +562,7 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -458,7 +562,7 @@ public abstract class AtlasRelationshipStoreV1Test {
assertTrue
(
collection
!=
null
&&
collection
.
isEmpty
());
assertTrue
(
collection
!=
null
&&
collection
.
isEmpty
());
}
}
pr
ivate
static
List
<
AtlasObjectId
>
toAtlasObjectIds
(
Object
object
)
{
pr
otected
static
List
<
AtlasObjectId
>
toAtlasObjectIds
(
Object
object
)
{
List
<
AtlasObjectId
>
ret
=
new
ArrayList
<>();
List
<
AtlasObjectId
>
ret
=
new
ArrayList
<>();
if
(
object
instanceof
List
)
{
if
(
object
instanceof
List
)
{
...
@@ -477,7 +581,7 @@ public abstract class AtlasRelationshipStoreV1Test {
...
@@ -477,7 +581,7 @@ public abstract class AtlasRelationshipStoreV1Test {
return
ret
;
return
ret
;
}
}
pr
ivate
static
AtlasObjectId
toAtlasObjectId
(
Object
object
)
{
pr
otected
static
AtlasObjectId
toAtlasObjectId
(
Object
object
)
{
if
(
object
instanceof
AtlasRelatedObjectId
)
{
if
(
object
instanceof
AtlasRelatedObjectId
)
{
AtlasRelatedObjectId
relatedObjectId
=
(
AtlasRelatedObjectId
)
object
;
AtlasRelatedObjectId
relatedObjectId
=
(
AtlasRelatedObjectId
)
object
;
return
new
AtlasObjectId
(
relatedObjectId
.
getGuid
(),
relatedObjectId
.
getTypeName
(),
relatedObjectId
.
getUniqueAttributes
());
return
new
AtlasObjectId
(
relatedObjectId
.
getGuid
(),
relatedObjectId
.
getTypeName
(),
relatedObjectId
.
getUniqueAttributes
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment