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
4f4ab9b9
Commit
4f4ab9b9
authored
Feb 03, 2017
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1522: v1 to v2 entity converter fixes
parent
d8c2a10e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
65 deletions
+53
-65
AtlasEntityFormatConverter.java
...apache/atlas/web/adapters/AtlasEntityFormatConverter.java
+23
-20
AtlasFormatConverter.java
...a/org/apache/atlas/web/adapters/AtlasFormatConverter.java
+7
-18
AtlasInstanceRestAdapters.java
.../apache/atlas/web/adapters/AtlasInstanceRestAdapters.java
+3
-0
AtlasStructFormatConverter.java
...apache/atlas/web/adapters/AtlasStructFormatConverter.java
+2
-9
EntityREST.java
...p/src/main/java/org/apache/atlas/web/rest/EntityREST.java
+18
-18
No files found.
webapp/src/main/java/org/apache/atlas/web/adapters/AtlasEntityFormatConverter.java
View file @
4f4ab9b9
...
...
@@ -54,7 +54,7 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter {
@Override
public
Object
fromV1ToV2
(
Object
v1Obj
,
AtlasType
type
,
ConverterContext
context
)
throws
AtlasBaseException
{
Object
ret
=
null
;
AtlasObjectId
ret
=
null
;
if
(
v1Obj
!=
null
)
{
AtlasEntityType
entityType
=
(
AtlasEntityType
)
type
;
...
...
@@ -64,43 +64,46 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter {
ret
=
new
AtlasObjectId
(
id
.
getTypeName
(),
id
.
_getId
());
}
else
if
(
v1Obj
instanceof
IReferenceableInstance
)
{
IReferenceableInstance
entity
=
(
IReferenceableInstance
)
v1Obj
;
Map
<
String
,
Object
>
v1Attribs
=
null
;
IReferenceableInstance
entRef
=
(
IReferenceableInstance
)
v1Obj
;
ret
=
new
AtlasObjectId
(
entRef
.
getTypeName
(),
entRef
.
getId
().
_getId
());
ret
=
new
AtlasObjectId
(
entity
.
getTypeName
(),
entity
.
getId
().
_getId
());
if
(!
context
.
entityExists
(
ret
.
getGuid
()))
{
Map
<
String
,
Object
>
v1Attribs
=
null
;
try
{
v1Attribs
=
entity
.
getValuesMap
();
v1Attribs
=
entRef
.
getValuesMap
();
}
catch
(
AtlasException
excp
)
{
LOG
.
error
(
"IReferenceableInstance.getValuesMap() failed"
,
excp
);
}
AtlasEntityWithAssociations
ret1
=
new
AtlasEntityWithAssociations
(
entity
.
getTypeName
(),
super
.
fromV1ToV2
(
entityType
,
v1Attribs
,
context
));
ret1
.
setGuid
(
entity
.
getId
().
_getId
(
));
ret1
.
setStatus
(
convertState
(
entity
.
getId
().
getState
()
));
AtlasSystemAttributes
systemAttributes
=
entity
.
getSystemAttributes
(
);
ret1
.
setCreatedBy
(
systemAttributes
.
createdBy
);
ret1
.
setCreateTime
(
systemAttributes
.
createdTime
);
ret1
.
setUpdatedBy
(
systemAttributes
.
modifiedBy
);
ret1
.
setUpdateTime
(
systemAttributes
.
modifiedTime
);
ret1
.
setVersion
(
new
Long
(
entity
.
getId
().
version
));
if
(
CollectionUtils
.
isNotEmpty
(
entity
.
getTraits
()))
{
AtlasEntityWithAssociations
entity
=
new
AtlasEntityWithAssociations
(
entRef
.
getTypeName
(),
super
.
fromV1ToV2
(
entityType
,
v1Attribs
,
context
));
entity
.
setGuid
(
entRef
.
getId
().
_getId
(
));
entity
.
setStatus
(
convertState
(
entRef
.
getId
().
getState
())
);
entity
.
setCreatedBy
(
entRef
.
getSystemAttributes
()
.
createdBy
);
entity
.
setCreateTime
(
entRef
.
getSystemAttributes
()
.
createdTime
);
entity
.
setUpdatedBy
(
entRef
.
getSystemAttributes
()
.
modifiedBy
);
entity
.
setUpdateTime
(
entRef
.
getSystemAttributes
()
.
modifiedTime
);
entity
.
setVersion
(
new
Long
(
entRef
.
getId
().
version
));
if
(
CollectionUtils
.
isNotEmpty
(
entRef
.
getTraits
()))
{
List
<
AtlasClassification
>
classifications
=
new
ArrayList
<>();
AtlasFormatConverter
traitConverter
=
converterRegistry
.
getConverter
(
TypeCategory
.
CLASSIFICATION
);
for
(
String
traitName
:
entity
.
getTraits
())
{
IStruct
trait
=
entity
.
getTrait
(
traitName
);
for
(
String
traitName
:
entRef
.
getTraits
())
{
IStruct
trait
=
entRef
.
getTrait
(
traitName
);
AtlasType
classifiType
=
typeRegistry
.
getType
(
traitName
);
AtlasClassification
classification
=
(
AtlasClassification
)
traitConverter
.
fromV1ToV2
(
trait
,
classifiType
,
context
);
classifications
.
add
(
classification
);
}
ret1
.
setClassifications
(
classifications
);
entity
.
setClassifications
(
classifications
);
}
context
.
addEntity
(
ret1
);
context
.
addEntity
(
entity
);
}
}
else
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
UNEXPECTED_TYPE
,
"IReferenceableInstance"
,
v1Obj
.
getClass
().
getCanonicalName
());
...
...
webapp/src/main/java/org/apache/atlas/web/adapters/AtlasFormatConverter.java
View file @
4f4ab9b9
...
...
@@ -46,18 +46,14 @@ public interface AtlasFormatConverter {
}
public
void
addEntity
(
AtlasEntity
entity
)
{
if
(
entities
==
null
)
{
entities
=
new
HashMap
<>();
if
(
entity
instanceof
AtlasEntityWithAssociations
)
{
this
.
addEntity
((
AtlasEntityWithAssociations
)
entity
);
}
else
{
this
.
addEntity
(
new
AtlasEntityWithAssociations
(
entity
));
}
entities
.
put
(
entity
.
getGuid
(),
new
AtlasEntityWithAssociations
(
entity
));
}
public
boolean
exists
(
AtlasEntityWithAssociations
entity
)
{
return
entities
!=
null
?
entities
.
containsKey
(
entity
.
getGuid
())
:
false
;
}
public
AtlasEntity
getById
(
String
guid
)
{
public
AtlasEntityWithAssociations
getById
(
String
guid
)
{
if
(
entities
!=
null
)
{
return
entities
.
get
(
guid
);
}
...
...
@@ -65,17 +61,10 @@ public interface AtlasFormatConverter {
return
null
;
}
public
boolean
entityExists
(
String
guid
)
{
return
entities
!=
null
&&
entities
.
containsKey
(
guid
);
}
public
Map
<
String
,
AtlasEntityWithAssociations
>
getEntities
()
{
return
entities
;
}
public
void
addEntities
(
Map
<
String
,
AtlasEntity
>
entities
)
{
if
(
this
.
entities
==
null
)
{
this
.
entities
=
new
HashMap
<>(
entities
.
size
());
}
for
(
String
entityId
:
entities
.
keySet
())
{
this
.
entities
.
put
(
entityId
,
new
AtlasEntityWithAssociations
(
entities
.
get
(
entityId
)));
}
}
}
}
webapp/src/main/java/org/apache/atlas/web/adapters/AtlasInstanceRestAdapters.java
View file @
4f4ab9b9
...
...
@@ -130,12 +130,15 @@ public class AtlasInstanceRestAdapters {
AtlasFormatConverter
converter
=
instanceFormatters
.
getConverter
(
TypeCategory
.
ENTITY
);
AtlasEntityType
entityType
=
typeRegistry
.
getEntityTypeByName
(
referenceable
.
getTypeName
());
if
(
entityType
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_INVALID
,
TypeCategory
.
ENTITY
.
name
(),
referenceable
.
getTypeName
());
}
AtlasFormatConverter
.
ConverterContext
ctx
=
new
AtlasFormatConverter
.
ConverterContext
();
converter
.
fromV1ToV2
(
referenceable
,
entityType
,
ctx
);
return
ctx
.
getEntities
();
}
...
...
webapp/src/main/java/org/apache/atlas/web/adapters/AtlasStructFormatConverter.java
View file @
4f4ab9b9
...
...
@@ -164,17 +164,10 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter {
continue
;
}
AtlasFormatConverter
attrConverter
=
converterRegistry
.
getConverter
(
attrType
.
getTypeCategory
());
Object
v1Value
=
attributes
.
get
(
attr
.
getName
());
Object
v2Value
=
null
;
Object
v2Value
=
attrConverter
.
fromV1ToV2
(
v1Value
,
attrType
,
context
)
;
AtlasFormatConverter
attrConverter
=
null
;
if
(
attrType
.
getTypeCategory
()
==
TypeCategory
.
ENTITY
&&
!
attr
.
isContainedAttribute
())
{
attrConverter
=
new
AtlasObjectIdConverter
(
converterRegistry
,
typeRegistry
);
v2Value
=
attrConverter
.
fromV1ToV2
(
v1Value
,
attrType
,
context
);
}
else
{
attrConverter
=
converterRegistry
.
getConverter
(
attrType
.
getTypeCategory
());
v2Value
=
attrConverter
.
fromV1ToV2
(
v1Value
,
attrType
,
context
);
}
ret
.
put
(
attr
.
getAttributeDef
().
getName
(),
v2Value
);
}
}
...
...
webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
View file @
4f4ab9b9
...
...
@@ -84,13 +84,11 @@ public class EntityREST {
@Path
(
"/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
List
<
AtlasEntityWithAssociations
>
getById
(
@PathParam
(
"guid"
)
String
guid
)
throws
AtlasBaseException
{
List
<
AtlasEntityWithAssociations
>
entityList
=
new
ArrayList
<>();
try
{
ITypedReferenceableInstance
ref
=
metadataService
.
getEntityDefinition
(
guid
);
Map
<
String
,
AtlasEntityWithAssociations
>
entit
yRet
=
restAdapters
.
getAtlasEntity
(
ref
);
entityList
.
addAll
(
entityRet
.
values
());
return
entityList
;
Map
<
String
,
AtlasEntityWithAssociations
>
entit
ies
=
restAdapters
.
getAtlasEntity
(
ref
);
return
getOrderedEntityList
(
entities
,
guid
)
;
}
catch
(
AtlasException
e
)
{
throw
toAtlasBaseException
(
e
);
}
...
...
@@ -106,20 +104,9 @@ public class EntityREST {
@Path
(
"/guid/{guid}/associations"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
List
<
AtlasEntityWithAssociations
>
getWithAssociationsByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
AtlasBaseException
{
List
<
AtlasEntityWithAssociations
>
entityList
=
new
ArrayList
<>();
try
{
ITypedReferenceableInstance
ref
=
metadataService
.
getEntityDefinition
(
guid
);
Map
<
String
,
AtlasEntityWithAssociations
>
entityRet
=
restAdapters
.
getAtlasEntity
(
ref
);
entityList
.
addAll
(
entityRet
.
values
());
return
entityList
;
}
catch
(
AtlasException
e
)
{
throw
toAtlasBaseException
(
e
);
}
return
this
.
getById
(
guid
);
}
/**
* Delete an entity identified by its GUID
*
...
...
@@ -212,7 +199,6 @@ public class EntityREST {
return
entityList
;
}
/**
* Gets the list of classifications for a given entity represented by a guid.
*
...
...
@@ -373,4 +359,18 @@ public class EntityREST {
throw
new
AtlasBaseException
(
AtlasErrorCode
.
ATTRIBUTE_UNIQUE_INVALID
,
entityType
.
getTypeName
(),
attributeName
);
}
}
private
List
<
AtlasEntityWithAssociations
>
getOrderedEntityList
(
Map
<
String
,
AtlasEntityWithAssociations
>
entities
,
String
firstItemGuid
)
{
List
<
AtlasEntityWithAssociations
>
ret
=
new
ArrayList
<>(
entities
.
size
());
for
(
AtlasEntityWithAssociations
entity
:
entities
.
values
())
{
if
(
StringUtils
.
equals
(
entity
.
getGuid
(),
firstItemGuid
))
{
ret
.
add
(
0
,
entity
);
}
else
{
ret
.
add
(
entity
);
}
}
return
ret
;
}
}
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