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
87a421ac
Commit
87a421ac
authored
Aug 08, 2017
by
Sarath Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1999: Use AtlasRelatedObjectId to display relationshipAttribute values…
ATLAS-1999: Use AtlasRelatedObjectId to display relationshipAttribute values during entity retrieval
parent
e0bd96b7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
440 additions
and
93 deletions
+440
-93
AtlasRelatedObjectId.java
...org/apache/atlas/model/instance/AtlasRelatedObjectId.java
+120
-0
AtlasEntityType.java
.../src/main/java/org/apache/atlas/type/AtlasEntityType.java
+179
-6
AtlasTypeUtil.java
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
+8
-0
GraphHelper.java
...n/java/org/apache/atlas/repository/graph/GraphHelper.java
+11
-2
AtlasRelationshipStoreV1.java
...s/repository/store/graph/v1/AtlasRelationshipStoreV1.java
+3
-69
EntityGraphRetriever.java
...atlas/repository/store/graph/v1/EntityGraphRetriever.java
+97
-8
AtlasRelationshipStoreV1Test.java
...pository/store/graph/v1/AtlasRelationshipStoreV1Test.java
+22
-8
No files found.
intg/src/main/java/org/apache/atlas/model/instance/AtlasRelatedObjectId.java
0 → 100644
View file @
87a421ac
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
model
.
instance
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
/**
* Reference to an object-instance of AtlasEntity type used in relationship attribute values
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasRelatedObjectId
extends
AtlasObjectId
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
public
static
final
String
KEY_RELATIONSHIP_GUID
=
"relationshipGuid"
;
public
static
final
String
KEY_RELATIONSHIP_ATTRIBUTES
=
"relationshipAttributes"
;
private
String
displayText
=
null
;
private
String
relationshipGuid
=
null
;
private
AtlasStruct
relationshipAttributes
;
public
AtlasRelatedObjectId
()
{
}
public
AtlasRelatedObjectId
(
String
guid
,
String
typeName
,
String
relationshipGuid
,
AtlasStruct
relationshipAttributes
)
{
super
(
guid
,
typeName
);
setRelationshipGuid
(
relationshipGuid
);
setRelationshipAttributes
(
relationshipAttributes
);
}
public
AtlasRelatedObjectId
(
String
guid
,
String
typeName
,
Map
<
String
,
Object
>
uniqueAttributes
,
String
displayText
,
String
relationshipGuid
,
AtlasStruct
relationshipAttributes
)
{
super
(
guid
,
typeName
,
uniqueAttributes
);
setRelationshipGuid
(
relationshipGuid
);
setDisplayText
(
displayText
);
setRelationshipAttributes
(
relationshipAttributes
);
}
public
String
getDisplayText
()
{
return
displayText
;
}
public
void
setDisplayText
(
String
displayText
)
{
this
.
displayText
=
displayText
;
}
public
String
getRelationshipGuid
()
{
return
relationshipGuid
;
}
public
void
setRelationshipGuid
(
String
relationshipGuid
)
{
this
.
relationshipGuid
=
relationshipGuid
;
}
public
AtlasStruct
getRelationshipAttributes
()
{
return
relationshipAttributes
;
}
public
void
setRelationshipAttributes
(
AtlasStruct
relationshipAttributes
)
{
this
.
relationshipAttributes
=
relationshipAttributes
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
if
(!
super
.
equals
(
o
))
{
return
false
;
}
AtlasRelatedObjectId
that
=
(
AtlasRelatedObjectId
)
o
;
return
Objects
.
equals
(
displayText
,
that
.
displayText
)
&&
Objects
.
equals
(
relationshipGuid
,
that
.
relationshipGuid
)
&&
Objects
.
equals
(
relationshipAttributes
,
that
.
relationshipAttributes
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
super
.
hashCode
(),
displayText
,
relationshipGuid
,
relationshipAttributes
);
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
@Override
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasRelatedObjectId{"
);
super
.
toString
(
sb
);
sb
.
append
(
"displayText='"
).
append
(
displayText
).
append
(
'\''
);
sb
.
append
(
", relationshipGuid='"
).
append
(
relationshipGuid
).
append
(
'\''
);
sb
.
append
(
", relationshipAttributes="
).
append
(
relationshipAttributes
);
sb
.
append
(
'}'
);
return
sb
;
}
}
\ No newline at end of file
intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
View file @
87a421ac
...
...
@@ -22,6 +22,7 @@ import org.apache.atlas.AtlasErrorCode;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasObjectIdType
;
...
...
@@ -266,7 +267,8 @@ public class AtlasEntityType extends AtlasStructType {
return
false
;
}
}
return
super
.
isValidValue
(
obj
);
return
super
.
isValidValue
(
obj
)
&&
validateRelationshipAttributes
(
obj
);
}
return
true
;
...
...
@@ -339,8 +341,7 @@ public class AtlasEntityType extends AtlasStructType {
ret
=
superType
.
validateValue
(
obj
,
objName
,
messages
)
&&
ret
;
}
ret
=
super
.
validateValue
(
obj
,
objName
,
messages
)
&&
ret
;
ret
=
super
.
validateValue
(
obj
,
objName
,
messages
)
&&
validateRelationshipAttributes
(
obj
,
objName
,
messages
)
&&
ret
;
}
else
{
ret
=
false
;
messages
.
add
(
objName
+
": invalid value type '"
+
obj
.
getClass
().
getName
());
...
...
@@ -388,7 +389,7 @@ public class AtlasEntityType extends AtlasStructType {
superType
.
normalizeAttributeValues
(
ent
);
}
super
.
normalizeAttribut
eValues
(
ent
);
normaliz
eValues
(
ent
);
}
}
...
...
@@ -409,7 +410,7 @@ public class AtlasEntityType extends AtlasStructType {
superType
.
normalizeAttributeValues
(
obj
);
}
super
.
normalizeAttribut
eValues
(
obj
);
normaliz
eValues
(
obj
);
}
}
...
...
@@ -446,10 +447,13 @@ public class AtlasEntityType extends AtlasStructType {
collectTypeHierarchyInfo
(
typeRegistry
,
allSuperTypeNames
,
allAttributes
,
visitedTypes
);
}
/*
* This method should not assume that resolveReferences() has been called on all superTypes.
* this.entityDef is the only safe member to reference here
*/
private
void
collectTypeHierarchyInfo
(
AtlasTypeRegistry
typeRegistry
,
Set
<
String
>
allSuperTypeNames
,
Map
<
String
,
AtlasAttribute
>
allAttributes
,
...
...
@@ -480,10 +484,178 @@ public class AtlasEntityType extends AtlasStructType {
}
}
}
boolean
isAssignableFrom
(
AtlasObjectId
objId
)
{
boolean
ret
=
AtlasTypeUtil
.
isValid
(
objId
)
&&
(
StringUtils
.
equals
(
objId
.
getTypeName
(),
getTypeName
())
||
isSuperTypeOf
(
objId
.
getTypeName
()));
return
ret
;
}
private
boolean
validateRelationshipAttributes
(
Object
obj
)
{
if
(
obj
!=
null
&&
MapUtils
.
isNotEmpty
(
relationshipAttributes
))
{
if
(
obj
instanceof
AtlasEntity
)
{
AtlasEntity
entityObj
=
(
AtlasEntity
)
obj
;
for
(
AtlasAttribute
attribute
:
relationshipAttributes
.
values
())
{
Object
attributeValue
=
entityObj
.
getRelationshipAttribute
(
attribute
.
getName
());
AtlasAttributeDef
attributeDef
=
attribute
.
getAttributeDef
();
if
(!
isAssignableValue
(
attributeValue
,
attributeDef
))
{
return
false
;
}
}
}
else
if
(
obj
instanceof
Map
)
{
Map
map
=
AtlasTypeUtil
.
toRelationshipAttributes
((
Map
)
obj
);
for
(
AtlasAttribute
attribute
:
relationshipAttributes
.
values
())
{
Object
attributeValue
=
map
.
get
(
attribute
.
getName
());
AtlasAttributeDef
attributeDef
=
attribute
.
getAttributeDef
();
if
(!
isAssignableValue
(
attributeValue
,
attributeDef
))
{
return
false
;
}
}
}
else
{
return
false
;
}
}
return
true
;
}
private
boolean
isAssignableValue
(
Object
value
,
AtlasAttributeDef
attributeDef
)
{
boolean
ret
=
true
;
if
(
value
!=
null
)
{
AtlasAttribute
attribute
=
relationshipAttributes
.
get
(
attributeDef
.
getName
());
if
(
attribute
!=
null
)
{
AtlasType
attrType
=
attribute
.
getAttributeType
();
if
(!
isValidRelationshipType
(
attrType
)
&&
!
attrType
.
isValidValue
(
value
))
{
ret
=
false
;
}
}
}
return
ret
;
}
private
boolean
isValidRelationshipType
(
AtlasType
attributeType
)
{
boolean
ret
=
false
;
if
(
attributeType
!=
null
)
{
if
(
attributeType
instanceof
AtlasArrayType
)
{
attributeType
=
((
AtlasArrayType
)
attributeType
).
getElementType
();
}
if
(
attributeType
instanceof
AtlasObjectIdType
||
attributeType
instanceof
AtlasEntityType
)
{
ret
=
true
;
}
}
return
ret
;
}
private
void
normalizeRelationshipAttributeValues
(
AtlasStruct
obj
)
{
if
(
obj
!=
null
&&
obj
instanceof
AtlasEntity
)
{
AtlasEntity
entityObj
=
(
AtlasEntity
)
obj
;
for
(
AtlasAttribute
attribute
:
relationshipAttributes
.
values
())
{
String
attributeName
=
attribute
.
getName
();
AtlasAttributeDef
attributeDef
=
attribute
.
getAttributeDef
();
if
(((
AtlasEntity
)
obj
).
hasRelationshipAttribute
(
attributeName
))
{
Object
attributeValue
=
getNormalizedValue
(
entityObj
.
getAttribute
(
attributeName
),
attributeDef
);
obj
.
setAttribute
(
attributeName
,
attributeValue
);
}
}
}
}
public
void
normalizeRelationshipAttributeValues
(
Map
<
String
,
Object
>
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasAttribute
attribute
:
relationshipAttributes
.
values
())
{
String
attributeName
=
attribute
.
getName
();
AtlasAttributeDef
attributeDef
=
attribute
.
getAttributeDef
();
if
(
obj
.
containsKey
(
attributeName
))
{
Object
attributeValue
=
getNormalizedValue
(
obj
.
get
(
attributeName
),
attributeDef
);
obj
.
put
(
attributeName
,
attributeValue
);
}
}
}
}
private
Object
getNormalizedValue
(
Object
value
,
AtlasAttributeDef
attributeDef
)
{
AtlasAttribute
attribute
=
relationshipAttributes
.
get
(
attributeDef
.
getName
());
if
(
attribute
!=
null
)
{
AtlasType
attrType
=
attribute
.
getAttributeType
();
if
(
isValidRelationshipType
(
attrType
)
&&
value
!=
null
)
{
return
attrType
.
getNormalizedValue
(
value
);
}
}
return
null
;
}
private
void
normalizeValues
(
AtlasEntity
ent
)
{
super
.
normalizeAttributeValues
(
ent
);
normalizeRelationshipAttributeValues
(
ent
);
}
private
void
normalizeValues
(
Map
<
String
,
Object
>
obj
)
{
super
.
normalizeAttributeValues
(
obj
);
normalizeRelationshipAttributeValues
(
obj
);
}
private
boolean
validateRelationshipAttributes
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
boolean
ret
=
true
;
if
(
obj
!=
null
&&
MapUtils
.
isNotEmpty
(
relationshipAttributes
))
{
if
(
obj
instanceof
AtlasEntity
)
{
AtlasEntity
entityObj
=
(
AtlasEntity
)
obj
;
for
(
AtlasAttribute
attribute
:
relationshipAttributes
.
values
())
{
String
attributeName
=
attribute
.
getName
();
if
(
attribute
!=
null
)
{
AtlasType
dataType
=
attribute
.
getAttributeType
();
Object
value
=
entityObj
.
getAttribute
(
attributeName
);
String
fieldName
=
objName
+
"."
+
attributeName
;
if
(
isValidRelationshipType
(
dataType
)
&&
value
!=
null
)
{
ret
=
dataType
.
validateValue
(
value
,
fieldName
,
messages
)
&&
ret
;
}
}
}
}
else
if
(
obj
instanceof
Map
)
{
Map
attributes
=
AtlasTypeUtil
.
toStructAttributes
((
Map
)
obj
);
for
(
AtlasAttribute
attribute
:
relationshipAttributes
.
values
())
{
String
attributeName
=
attribute
.
getName
();
if
(
attribute
!=
null
)
{
AtlasType
dataType
=
attribute
.
getAttributeType
();
Object
value
=
attributes
.
get
(
attributeName
);
String
fieldName
=
objName
+
"."
+
attributeName
;
if
(
isValidRelationshipType
(
dataType
)
&&
value
!=
null
)
{
ret
=
dataType
.
validateValue
(
value
,
fieldName
,
messages
)
&&
ret
;
}
}
}
}
else
{
ret
=
false
;
messages
.
add
(
objName
+
"="
+
obj
+
": invalid value for type "
+
getTypeName
());
}
}
return
ret
;
}
}
\ No newline at end of file
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
View file @
87a421ac
...
...
@@ -315,6 +315,14 @@ public class AtlasTypeUtil {
return
map
;
}
public
static
Map
toRelationshipAttributes
(
Map
map
)
{
if
(
map
!=
null
&&
map
.
containsKey
(
"typeName"
)
&&
map
.
containsKey
(
"relationshipAttributes"
)
&&
map
.
get
(
"relationshipAttributes"
)
instanceof
Map
)
{
return
(
Map
)
map
.
get
(
"relationshipAttributes"
);
}
return
map
;
}
public
static
AtlasObjectId
getAtlasObjectId
(
AtlasEntity
entity
)
{
return
new
AtlasObjectId
(
entity
.
getGuid
(),
entity
.
getTypeName
());
}
...
...
repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
View file @
87a421ac
...
...
@@ -22,6 +22,7 @@ import com.google.common.annotations.VisibleForTesting;
import
com.google.common.collect.BiMap
;
import
com.google.common.collect.HashBiMap
;
import
org.apache.atlas.ApplicationProperties
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.RequestContext
;
import
org.apache.atlas.exception.AtlasBaseException
;
...
...
@@ -595,8 +596,16 @@ public final class GraphHelper {
return
findVertex
(
Constants
.
GUID_PROPERTY_KEY
,
guid
);
}
public
AtlasEdge
getEdgeForGUID
(
String
guid
)
throws
EntityNotFoundException
{
return
findEdge
(
Constants
.
GUID_PROPERTY_KEY
,
guid
);
public
AtlasEdge
getEdgeForGUID
(
String
guid
)
throws
AtlasBaseException
{
AtlasEdge
ret
=
null
;
try
{
ret
=
findEdge
(
Constants
.
GUID_PROPERTY_KEY
,
guid
);
}
catch
(
EntityNotFoundException
e
)
{
new
AtlasBaseException
(
AtlasErrorCode
.
RELATIONSHIP_GUID_NOT_FOUND
,
guid
);
}
return
ret
;
}
/**
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
View file @
87a421ac
...
...
@@ -116,13 +116,9 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
AtlasRelationship
ret
;
try
{
AtlasEdge
edge
=
graphHelper
.
getEdgeForGUID
(
guid
);
ret
=
mapEdgeToAtlasRelationship
(
edge
);
}
catch
(
EntityNotFoundException
ex
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
RELATIONSHIP_GUID_NOT_FOUND
,
guid
);
}
ret
=
entityRetriever
.
mapEdgeToAtlasRelationship
(
edge
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== getById({}): {}"
,
guid
,
ret
);
...
...
@@ -160,7 +156,7 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
AtlasEdge
relationshipEdge
=
getRelationshipEdge
(
end1Vertex
,
end2Vertex
,
relationship
);
if
(
relationshipEdge
!=
null
)
{
ret
=
mapEdgeToAtlasRelationship
(
relationshipEdge
);
ret
=
entityRetriever
.
mapEdgeToAtlasRelationship
(
relationshipEdge
);
}
else
{
validateRelationship
(
relationship
);
...
...
@@ -196,7 +192,7 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
}
}
ret
=
mapEdgeToAtlasRelationship
(
relationshipEdge
);
ret
=
entityRetriever
.
mapEdgeToAtlasRelationship
(
relationshipEdge
);
}
else
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
RELATIONSHIP_ALREADY_EXISTS
,
relationship
.
getTypeName
(),
...
...
@@ -379,68 +375,6 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
return
(
entityType
!=
null
)
?
entityType
.
getTypeAndAllSuperTypes
()
:
new
HashSet
<
String
>();
}
private
AtlasRelationship
mapEdgeToAtlasRelationship
(
AtlasEdge
edge
)
throws
AtlasBaseException
{
AtlasRelationship
ret
=
new
AtlasRelationship
();
mapSystemAttributes
(
edge
,
ret
);
mapAttributes
(
edge
,
ret
);
return
ret
;
}
private
AtlasRelationship
mapSystemAttributes
(
AtlasEdge
edge
,
AtlasRelationship
relationship
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Mapping system attributes for relationship"
);
}
relationship
.
setGuid
(
GraphHelper
.
getGuid
(
edge
));
relationship
.
setTypeName
(
GraphHelper
.
getTypeName
(
edge
));
relationship
.
setCreatedBy
(
GraphHelper
.
getCreatedByAsString
(
edge
));
relationship
.
setUpdatedBy
(
GraphHelper
.
getModifiedByAsString
(
edge
));
relationship
.
setCreateTime
(
new
Date
(
GraphHelper
.
getCreatedTime
(
edge
)));
relationship
.
setUpdateTime
(
new
Date
(
GraphHelper
.
getModifiedTime
(
edge
)));
Integer
version
=
GraphHelper
.
getVersion
(
edge
);
if
(
version
==
null
)
{
version
=
Integer
.
valueOf
(
1
);
}
relationship
.
setVersion
(
version
.
longValue
());
relationship
.
setStatus
(
GraphHelper
.
getEdgeStatus
(
edge
));
AtlasVertex
end1Vertex
=
edge
.
getOutVertex
();
AtlasVertex
end2Vertex
=
edge
.
getInVertex
();
relationship
.
setEnd1
(
new
AtlasObjectId
(
GraphHelper
.
getGuid
(
end1Vertex
),
GraphHelper
.
getTypeName
(
end1Vertex
)));
relationship
.
setEnd2
(
new
AtlasObjectId
(
GraphHelper
.
getGuid
(
end2Vertex
),
GraphHelper
.
getTypeName
(
end2Vertex
)));
relationship
.
setLabel
(
edge
.
getLabel
());
return
relationship
;
}
private
void
mapAttributes
(
AtlasEdge
edge
,
AtlasRelationship
relationship
)
throws
AtlasBaseException
{
AtlasType
objType
=
typeRegistry
.
getType
(
relationship
.
getTypeName
());
if
(!(
objType
instanceof
AtlasRelationshipType
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_INVALID
,
relationship
.
getTypeName
());
}
AtlasRelationshipType
relationshipType
=
(
AtlasRelationshipType
)
objType
;
for
(
AtlasAttribute
attribute
:
relationshipType
.
getAllAttributes
().
values
())
{
// mapping only primitive attributes
Object
attrValue
=
entityRetriever
.
mapVertexToPrimitive
(
edge
,
attribute
.
getQualifiedName
(),
attribute
.
getAttributeDef
());
relationship
.
setAttribute
(
attribute
.
getName
(),
attrValue
);
}
}
private
String
getTypeNameFromObjectId
(
AtlasObjectId
objectId
)
{
String
typeName
=
objectId
.
getTypeName
();
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
View file @
87a421ac
...
...
@@ -28,6 +28,8 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityExtInfo;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasRelatedObjectId
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
org.apache.atlas.model.typedef.AtlasRelationshipDef
;
import
org.apache.atlas.model.typedef.AtlasRelationshipEndDef
;
...
...
@@ -672,11 +674,11 @@ public final class EntityGraphRetriever {
private
AtlasObjectId
mapRelatedVertexToObjectId
(
AtlasVertex
entityVertex
,
AtlasAttribute
attribute
)
throws
AtlasBaseException
{
AtlasEdge
edge
=
graphHelper
.
getEdgeForLabel
(
entityVertex
,
attribute
.
getRelationshipEdgeLabel
(),
attribute
.
getRelationshipEdgeDirection
());
return
map
RelatedVertexTo
ObjectId
(
entityVertex
,
edge
);
return
map
VertexToRelated
ObjectId
(
entityVertex
,
edge
);
}
private
List
<
AtlasObjectId
>
mapRelationshipArrayAttribute
(
AtlasVertex
entityVertex
,
AtlasAttribute
attribute
)
throws
AtlasBaseException
{
List
<
AtlasObjectId
>
ret
=
new
ArrayList
<>();
private
List
<
Atlas
Related
ObjectId
>
mapRelationshipArrayAttribute
(
AtlasVertex
entityVertex
,
AtlasAttribute
attribute
)
throws
AtlasBaseException
{
List
<
Atlas
Related
ObjectId
>
ret
=
new
ArrayList
<>();
Iterator
<
AtlasEdge
>
edges
=
null
;
if
(
attribute
.
getRelationshipEdgeDirection
()
==
AtlasRelationshipEdgeDirection
.
IN
)
{
...
...
@@ -689,17 +691,17 @@ public final class EntityGraphRetriever {
while
(
edges
.
hasNext
())
{
AtlasEdge
relationshipEdge
=
edges
.
next
();
Atlas
ObjectId
objectId
=
mapRelatedVertexTo
ObjectId
(
entityVertex
,
relationshipEdge
);
Atlas
RelatedObjectId
relatedObjectId
=
mapVertexToRelated
ObjectId
(
entityVertex
,
relationshipEdge
);
ret
.
add
(
o
bjectId
);
ret
.
add
(
relatedO
bjectId
);
}
}
return
ret
;
}
private
Atlas
ObjectId
mapRelatedVertexTo
ObjectId
(
AtlasVertex
entityVertex
,
AtlasEdge
edge
)
throws
AtlasBaseException
{
AtlasObjectId
ret
=
null
;
private
Atlas
RelatedObjectId
mapVertexToRelated
ObjectId
(
AtlasVertex
entityVertex
,
AtlasEdge
edge
)
throws
AtlasBaseException
{
Atlas
Related
ObjectId
ret
=
null
;
if
(
GraphHelper
.
elementExists
(
edge
))
{
AtlasVertex
referenceVertex
=
edge
.
getInVertex
();
...
...
@@ -709,10 +711,97 @@ public final class EntityGraphRetriever {
}
if
(
referenceVertex
!=
null
)
{
ret
=
new
AtlasObjectId
(
GraphHelper
.
getGuid
(
referenceVertex
),
GraphHelper
.
getTypeName
(
referenceVertex
));
String
entityTypeName
=
GraphHelper
.
getTypeName
(
referenceVertex
);
String
entityGuid
=
GraphHelper
.
getGuid
(
referenceVertex
);
AtlasRelationship
relationship
=
mapEdgeToAtlasRelationship
(
edge
);
ret
=
new
AtlasRelatedObjectId
(
entityGuid
,
entityTypeName
,
relationship
.
getGuid
(),
new
AtlasStruct
(
relationship
.
getTypeName
(),
relationship
.
getAttributes
()));
Object
displayText
=
getDisplayText
(
referenceVertex
,
entityTypeName
);
if
(
displayText
!=
null
)
{
ret
.
setDisplayText
(
displayText
.
toString
());
}
}
}
return
ret
;
}
private
Object
getDisplayText
(
AtlasVertex
entityVertex
,
String
entityTypeName
)
throws
AtlasBaseException
{
AtlasEntityType
entityType
=
typeRegistry
.
getEntityTypeByName
(
entityTypeName
);
Object
ret
=
null
;
if
(
entityType
!=
null
)
{
ret
=
getVertexAttribute
(
entityVertex
,
entityType
.
getAttribute
(
AtlasClient
.
NAME
));
if
(
ret
==
null
)
{
ret
=
getVertexAttribute
(
entityVertex
,
entityType
.
getAttribute
(
AtlasClient
.
QUALIFIED_NAME
));
}
}
return
ret
;
}
public
AtlasRelationship
mapEdgeToAtlasRelationship
(
AtlasEdge
edge
)
throws
AtlasBaseException
{
AtlasRelationship
ret
=
new
AtlasRelationship
();
mapSystemAttributes
(
edge
,
ret
);
mapAttributes
(
edge
,
ret
);
return
ret
;
}
private
AtlasRelationship
mapSystemAttributes
(
AtlasEdge
edge
,
AtlasRelationship
relationship
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Mapping system attributes for relationship"
);
}
relationship
.
setGuid
(
GraphHelper
.
getGuid
(
edge
));
relationship
.
setTypeName
(
GraphHelper
.
getTypeName
(
edge
));
relationship
.
setCreatedBy
(
GraphHelper
.
getCreatedByAsString
(
edge
));
relationship
.
setUpdatedBy
(
GraphHelper
.
getModifiedByAsString
(
edge
));
relationship
.
setCreateTime
(
new
Date
(
GraphHelper
.
getCreatedTime
(
edge
)));
relationship
.
setUpdateTime
(
new
Date
(
GraphHelper
.
getModifiedTime
(
edge
)));
Integer
version
=
GraphHelper
.
getVersion
(
edge
);
if
(
version
==
null
)
{
version
=
Integer
.
valueOf
(
1
);
}
relationship
.
setVersion
(
version
.
longValue
());
relationship
.
setStatus
(
GraphHelper
.
getEdgeStatus
(
edge
));
AtlasVertex
end1Vertex
=
edge
.
getOutVertex
();
AtlasVertex
end2Vertex
=
edge
.
getInVertex
();
relationship
.
setEnd1
(
new
AtlasObjectId
(
GraphHelper
.
getGuid
(
end1Vertex
),
GraphHelper
.
getTypeName
(
end1Vertex
)));
relationship
.
setEnd2
(
new
AtlasObjectId
(
GraphHelper
.
getGuid
(
end2Vertex
),
GraphHelper
.
getTypeName
(
end2Vertex
)));
relationship
.
setLabel
(
edge
.
getLabel
());
return
relationship
;
}
private
void
mapAttributes
(
AtlasEdge
edge
,
AtlasRelationship
relationship
)
throws
AtlasBaseException
{
AtlasType
objType
=
typeRegistry
.
getType
(
relationship
.
getTypeName
());
if
(!(
objType
instanceof
AtlasRelationshipType
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_INVALID
,
relationship
.
getTypeName
());
}
AtlasRelationshipType
relationshipType
=
(
AtlasRelationshipType
)
objType
;
for
(
AtlasAttribute
attribute
:
relationshipType
.
getAllAttributes
().
values
())
{
// mapping only primitive attributes
Object
attrValue
=
mapVertexToPrimitive
(
edge
,
attribute
.
getQualifiedName
(),
attribute
.
getAttributeDef
());
relationship
.
setAttribute
(
attribute
.
getName
(),
attrValue
);
}
}
}
repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1Test.java
View file @
87a421ac
...
...
@@ -27,6 +27,7 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasRelatedObjectId
;
import
org.apache.atlas.model.instance.EntityMutationResponse
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.repository.graph.AtlasGraphProvider
;
...
...
@@ -45,6 +46,7 @@ import org.testng.annotations.Guice;
import
org.testng.annotations.Test
;
import
javax.inject.Inject
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -456,17 +458,29 @@ public abstract class AtlasRelationshipStoreV1Test {
assertTrue
(
collection
!=
null
&&
collection
.
isEmpty
());
}
private
static
List
<
AtlasObjectId
>
toAtlasObjectIds
(
Object
objectIds
)
{
if
(
objectIds
instanceof
List
)
{
return
(
List
<
AtlasObjectId
>)
objectIds
;
private
static
List
<
AtlasObjectId
>
toAtlasObjectIds
(
Object
object
)
{
List
<
AtlasObjectId
>
ret
=
new
ArrayList
<>();
if
(
object
instanceof
List
)
{
List
<?>
objectIds
=
(
List
)
object
;
if
(
CollectionUtils
.
isNotEmpty
(
objectIds
))
{
for
(
Object
obj
:
objectIds
)
{
if
(
obj
instanceof
AtlasRelatedObjectId
)
{
AtlasRelatedObjectId
relatedObjectId
=
(
AtlasRelatedObjectId
)
obj
;
ret
.
add
(
new
AtlasObjectId
(
relatedObjectId
.
getGuid
(),
relatedObjectId
.
getTypeName
(),
relatedObjectId
.
getUniqueAttributes
()));
}
}
}
}
return
null
;
return
ret
;
}
private
static
AtlasObjectId
toAtlasObjectId
(
Object
objectId
)
{
if
(
objectId
instanceof
AtlasObjectId
)
{
return
(
AtlasObjectId
)
objectId
;
private
static
AtlasObjectId
toAtlasObjectId
(
Object
object
)
{
if
(
object
instanceof
AtlasRelatedObjectId
)
{
AtlasRelatedObjectId
relatedObjectId
=
(
AtlasRelatedObjectId
)
object
;
return
new
AtlasObjectId
(
relatedObjectId
.
getGuid
(),
relatedObjectId
.
getTypeName
(),
relatedObjectId
.
getUniqueAttributes
());
}
return
null
;
...
...
@@ -482,7 +496,7 @@ public abstract class AtlasRelationshipStoreV1Test {
Object
refValue
=
entity
.
getRelationshipAttribute
(
relationshipAttrName
);
assertTrue
(
refValue
instanceof
List
);
List
<
AtlasObjectId
>
refList
=
(
List
<
AtlasObjectId
>)
refValue
;
List
<
AtlasObjectId
>
refList
=
toAtlasObjectIds
(
refValue
)
;
assertEquals
(
refList
.
size
(),
expectedValues
.
size
());
if
(
expectedValues
.
size
()
>
0
)
{
...
...
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