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
6a4fcb95
Commit
6a4fcb95
authored
Mar 06, 2017
by
ashutoshm
Committed by
Madhan Neethiraj
Mar 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1646: added validation of classification attributes
parent
dc89e7f4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
9 deletions
+38
-9
AtlasBuiltInTypes.java
...rc/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
+10
-6
TestAtlasDateType.java
...rc/test/java/org/apache/atlas/type/TestAtlasDateType.java
+3
-3
AtlasEntityStoreV1.java
...e/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
+25
-0
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
View file @
6a4fcb95
...
...
@@ -18,18 +18,18 @@
package
org
.
apache
.
atlas
.
type
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.text.ParseException
;
import
java.util.Date
;
import
java.util.Map
;
import
org.apache.atlas.model.TypeCategory
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.lang.StringUtils
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.text.ParseException
;
import
java.util.Date
;
import
java.util.Map
;
/**
* Built-in types in Atlas.
...
...
@@ -449,6 +449,10 @@ public class AtlasBuiltInTypes {
return
true
;
}
if
(
obj
instanceof
String
&&
StringUtils
.
isEmpty
((
String
)
obj
))
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
...
...
intg/src/test/java/org/apache/atlas/type/TestAtlasDateType.java
View file @
6a4fcb95
...
...
@@ -34,7 +34,7 @@ public class TestAtlasDateType {
private
final
AtlasDateType
dateType
=
new
AtlasDateType
();
private
final
Object
[]
validValues
=
{
null
,
Byte
.
valueOf
((
byte
)
1
),
Short
.
valueOf
((
short
)
1
),
Integer
.
valueOf
(
1
),
Long
.
valueOf
(
1L
),
Float
.
valueOf
(
1
),
null
,
""
,
Byte
.
valueOf
((
byte
)
1
),
Short
.
valueOf
((
short
)
1
),
Integer
.
valueOf
(
1
),
Long
.
valueOf
(
1L
),
Float
.
valueOf
(
1
),
Double
.
valueOf
(
1
),
BigInteger
.
valueOf
(
1
),
BigDecimal
.
valueOf
(
1
),
"1"
,
};
...
...
@@ -43,7 +43,7 @@ public class TestAtlasDateType {
Double
.
valueOf
(-
1
),
BigInteger
.
valueOf
(-
1
),
BigDecimal
.
valueOf
(-
1
),
"-1"
,
};
private
final
Object
[]
invalidValues
=
{
"
"
,
"
12ab"
,
"abcd"
,
"-12ab"
,
};
private
final
Object
[]
invalidValues
=
{
"12ab"
,
"abcd"
,
"-12ab"
,
};
private
final
Date
now
=
new
Date
();
private
final
String
strNow
=
AtlasBaseTypeDef
.
DATE_FORMATTER
.
format
(
now
);
...
...
@@ -78,7 +78,7 @@ public class TestAtlasDateType {
assertNull
(
dateType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
if
(
value
==
null
||
value
==
""
)
{
continue
;
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
View file @
6a4fcb95
...
...
@@ -36,6 +36,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import
org.apache.atlas.repository.store.graph.AtlasEntityStore
;
import
org.apache.atlas.repository.store.graph.EntityGraphDiscovery
;
import
org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasStructType.AtlasAttribute
;
import
org.apache.atlas.type.AtlasType
;
...
...
@@ -427,6 +428,10 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
LOG
.
debug
(
"Adding classifications={} to entity={}"
,
classifications
,
guid
);
}
for
(
AtlasClassification
classification
:
classifications
)
{
validateAndNormalize
(
classification
);
}
EntityGraphMapper
graphMapper
=
new
EntityGraphMapper
(
deleteHandler
,
typeRegistry
);
graphMapper
.
addClassifications
(
new
EntityMutationContext
(),
guid
,
classifications
);
...
...
@@ -450,6 +455,8 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
EntityGraphMapper
graphMapper
=
new
EntityGraphMapper
(
deleteHandler
,
typeRegistry
);
validateAndNormalize
(
classification
);
List
<
AtlasClassification
>
classifications
=
Collections
.
singletonList
(
classification
);
for
(
String
guid
:
guids
)
{
...
...
@@ -573,4 +580,22 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
return
response
;
}
private
void
validateAndNormalize
(
AtlasClassification
classification
)
throws
AtlasBaseException
{
AtlasClassificationType
type
=
typeRegistry
.
getClassificationTypeByName
(
classification
.
getTypeName
());
if
(
type
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
CLASSIFICATION_NOT_FOUND
,
classification
.
getTypeName
());
}
List
<
String
>
messages
=
new
ArrayList
<>();
type
.
validateValue
(
classification
,
classification
.
getTypeName
(),
messages
);
if
(!
messages
.
isEmpty
())
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INVALID_PARAMETERS
,
messages
);
}
type
.
getNormalizedValue
(
classification
);
}
}
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