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
698a5652
Commit
698a5652
authored
Oct 02, 2016
by
Shwetha GS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1171 Structured, high-level public APIs (mneethiraj via shwethags)
parent
a52112d8
Hide whitespace changes
Inline
Side-by-side
Showing
53 changed files
with
8316 additions
and
1 deletion
+8316
-1
pom.xml
intg/pom.xml
+65
-0
AtlasApiEntities.java
.../src/main/java/org/apache/atlas/api/AtlasApiEntities.java
+52
-0
AtlasApiTypes.java
intg/src/main/java/org/apache/atlas/api/AtlasApiTypes.java
+99
-0
PList.java
intg/src/main/java/org/apache/atlas/api/PList.java
+128
-0
SearchFilter.java
intg/src/main/java/org/apache/atlas/api/SearchFilter.java
+123
-0
AtlasBaseException.java
...n/java/org/apache/atlas/exception/AtlasBaseException.java
+43
-0
AtlasClassification.java
.../org/apache/atlas/model/instance/AtlasClassification.java
+60
-0
AtlasEntity.java
...ain/java/org/apache/atlas/model/instance/AtlasEntity.java
+206
-0
AtlasObjectId.java
...n/java/org/apache/atlas/model/instance/AtlasObjectId.java
+132
-0
AtlasStruct.java
...ain/java/org/apache/atlas/model/instance/AtlasStruct.java
+230
-0
AtlasBaseTypeDef.java
...java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
+353
-0
AtlasClassificationDef.java
...rg/apache/atlas/model/typedef/AtlasClassificationDef.java
+169
-0
AtlasEntityDef.java
...n/java/org/apache/atlas/model/typedef/AtlasEntityDef.java
+166
-0
AtlasEnumDef.java
...ain/java/org/apache/atlas/model/typedef/AtlasEnumDef.java
+335
-0
AtlasStructDef.java
...n/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+401
-0
AtlasArrayType.java
intg/src/main/java/org/apache/atlas/type/AtlasArrayType.java
+271
-0
AtlasBuiltInTypes.java
...rc/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
+547
-0
AtlasClassificationType.java
...n/java/org/apache/atlas/type/AtlasClassificationType.java
+201
-0
AtlasEntityType.java
.../src/main/java/org/apache/atlas/type/AtlasEntityType.java
+201
-0
AtlasEnumType.java
intg/src/main/java/org/apache/atlas/type/AtlasEnumType.java
+87
-0
AtlasMapType.java
intg/src/main/java/org/apache/atlas/type/AtlasMapType.java
+189
-0
AtlasStructType.java
.../src/main/java/org/apache/atlas/type/AtlasStructType.java
+292
-0
AtlasType.java
intg/src/main/java/org/apache/atlas/type/AtlasType.java
+73
-0
AtlasTypeRegistry.java
...rc/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
+442
-0
ModelTestUtil.java
intg/src/test/java/org/apache/atlas/model/ModelTestUtil.java
+411
-0
TestAtlasClassification.java
.../apache/atlas/model/instance/TestAtlasClassification.java
+89
-0
TestAtlasEntity.java
...java/org/apache/atlas/model/instance/TestAtlasEntity.java
+89
-0
TestAtlasClassificationDef.java
...pache/atlas/model/typedef/TestAtlasClassificationDef.java
+100
-0
TestAtlasEntityDef.java
...va/org/apache/atlas/model/typedef/TestAtlasEntityDef.java
+140
-0
TestAtlasEnumDef.java
...java/org/apache/atlas/model/typedef/TestAtlasEnumDef.java
+110
-0
TestAtlasStructDef.java
...va/org/apache/atlas/model/typedef/TestAtlasStructDef.java
+104
-0
TestAtlasArrayType.java
...c/test/java/org/apache/atlas/type/TestAtlasArrayType.java
+120
-0
TestAtlasBigDecimalType.java
...t/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
+114
-0
TestAtlasBigIntegerType.java
...t/java/org/apache/atlas/type/TestAtlasBigIntegerType.java
+115
-0
TestAtlasBooleanType.java
...test/java/org/apache/atlas/type/TestAtlasBooleanType.java
+88
-0
TestAtlasByteType.java
...rc/test/java/org/apache/atlas/type/TestAtlasByteType.java
+115
-0
TestAtlasClassificationType.java
...va/org/apache/atlas/type/TestAtlasClassificationType.java
+125
-0
TestAtlasDateType.java
...rc/test/java/org/apache/atlas/type/TestAtlasDateType.java
+132
-0
TestAtlasDoubleType.java
.../test/java/org/apache/atlas/type/TestAtlasDoubleType.java
+115
-0
TestAtlasEntityType.java
.../test/java/org/apache/atlas/type/TestAtlasEntityType.java
+125
-0
TestAtlasFloatType.java
...c/test/java/org/apache/atlas/type/TestAtlasFloatType.java
+115
-0
TestAtlasIntType.java
...src/test/java/org/apache/atlas/type/TestAtlasIntType.java
+115
-0
TestAtlasLongType.java
...rc/test/java/org/apache/atlas/type/TestAtlasLongType.java
+115
-0
TestAtlasMapType.java
...src/test/java/org/apache/atlas/type/TestAtlasMapType.java
+116
-0
TestAtlasObjectIdType.java
...est/java/org/apache/atlas/type/TestAtlasObjectIdType.java
+122
-0
TestAtlasShortType.java
...c/test/java/org/apache/atlas/type/TestAtlasShortType.java
+115
-0
TestAtlasStringType.java
.../test/java/org/apache/atlas/type/TestAtlasStringType.java
+90
-0
TestAtlasStructType.java
.../test/java/org/apache/atlas/type/TestAtlasStructType.java
+183
-0
pom.xml
pom.xml
+8
-0
release-log.txt
release-log.txt
+1
-0
checkstyle.xml
src/build/checkstyle.xml
+3
-1
pom.xml
webapp/pom.xml
+5
-0
TypesREST.java
...pp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
+371
-0
No files found.
intg/pom.xml
0 → 100644
View file @
698a5652
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<artifactId>
apache-atlas
</artifactId>
<groupId>
org.apache.atlas
</groupId>
<version>
0.8-incubating-SNAPSHOT
</version>
</parent>
<artifactId>
atlas-intg
</artifactId>
<description>
Apache Atlas Integration
</description>
<name>
Apache Atlas Integration
</name>
<packaging>
jar
</packaging>
<properties>
<checkstyle.failOnViolation>
true
</checkstyle.failOnViolation>
</properties>
<dependencies>
<dependency>
<groupId>
commons-collections
</groupId>
<artifactId>
commons-collections
</artifactId>
</dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.hadoop
</groupId>
<artifactId>
hadoop-common
</artifactId>
</dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-jaxrs
</artifactId>
<version>
${codehaus.jackson.version}
</version>
</dependency>
<dependency>
<groupId>
org.testng
</groupId>
<artifactId>
testng
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
intg/src/main/java/org/apache/atlas/api/AtlasApiEntities.java
0 → 100644
View file @
698a5652
/**
* 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
.
api
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
/**
* API to work with CRUD of Atlas entities.
*/
public
interface
AtlasApiEntities
{
AtlasEntity
createEntity
(
AtlasEntity
entity
)
throws
AtlasBaseException
;
AtlasEntity
getEntity
(
AtlasObjectId
objId
)
throws
AtlasBaseException
;
AtlasEntity
updateEntity
(
AtlasObjectId
objId
,
AtlasEntity
entity
)
throws
AtlasBaseException
;
AtlasEntity
updateEntityAttributes
(
AtlasObjectId
objId
,
Map
<
String
,
Object
>
attributes
)
throws
AtlasBaseException
;
void
deleteEntity
(
AtlasObjectId
objId
)
throws
AtlasBaseException
;
PList
<
AtlasEntity
>
searchEntities
(
SearchFilter
filter
)
throws
AtlasBaseException
;
void
addEntityClassification
(
AtlasObjectId
entityId
,
AtlasClassification
classification
)
throws
AtlasBaseException
;
void
removeEntityClassification
(
AtlasObjectId
entityId
,
String
classificationName
)
throws
AtlasBaseException
;
List
<
AtlasClassification
>
getEntityClassifications
(
AtlasObjectId
entityId
)
throws
AtlasBaseException
;
List
<
String
>
getEntityClassificationNames
(
AtlasObjectId
entityId
)
throws
AtlasBaseException
;
}
intg/src/main/java/org/apache/atlas/api/AtlasApiTypes.java
0 → 100644
View file @
698a5652
/**
* 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
.
api
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
/**
* API to work with CRUD of Atlas types - enum/struct/classification/entity.
*/
public
interface
AtlasApiTypes
{
AtlasEnumDef
createEnumDef
(
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
;
AtlasEnumDef
getEnumDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasEnumDef
getEnumDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasEnumDef
updateEnumDefByName
(
String
name
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
;
AtlasEnumDef
updateEnumDefByGuid
(
String
guid
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
;
void
deleteEnumDefByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteEnumDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
PList
<
AtlasEnumDef
>
searchEnumDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
AtlasStructDef
createStructDef
(
AtlasStructDef
structDef
)
throws
AtlasBaseException
;
AtlasStructDef
getStructDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasStructDef
getStructDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasStructDef
updateStructDefByName
(
String
name
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
;
AtlasStructDef
updateStructDefByGuid
(
String
guid
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
;
void
deleteStructDefByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteStructDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
PList
<
AtlasStructDef
>
searchStructDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
AtlasClassificationDef
createClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
AtlasClassificationDef
getClassificationDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasClassificationDef
getClassificationDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasClassificationDef
updateClassificationDefByName
(
String
name
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
AtlasClassificationDef
updateClassificationDefByGuid
(
String
guid
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
void
deleteClassificationDefByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteClassificationDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
PList
<
AtlasClassificationDef
>
searchClassificationDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
AtlasEntityDef
createEntityDef
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
AtlasEntityDef
getEntityDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasEntityDef
getEntityDefByIdByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasEntityDef
updateEntityDefByName
(
String
name
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
AtlasEntityDef
updateEntityDefByGuid
(
String
guid
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
void
deleteEntityDef
(
String
name
)
throws
AtlasBaseException
;
void
deleteEntityDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
PList
<
AtlasEntityDef
>
searchEntityDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
}
intg/src/main/java/org/apache/atlas/api/PList.java
0 → 100644
View file @
698a5652
/**
* 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
.
api
;
import
java.util.List
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
org.apache.atlas.api.SearchFilter.SortType
;
/**
* Paged-list, for returning search results.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
PList
<
T
>
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
List
<
T
>
list
=
null
;
private
long
startIndex
=
0
;
private
int
pageSize
=
0
;
private
long
totalCount
=
0
;
private
String
sortBy
=
null
;
private
SortType
sortType
=
null
;
public
PList
()
{
}
public
PList
(
List
<
T
>
list
,
long
startIndex
,
int
pageSize
,
long
totalCount
,
SortType
sortType
,
String
sortBy
)
{
setList
(
list
);
setStartIndex
(
startIndex
);
setPageSize
(
pageSize
);
setTotalCount
(
totalCount
);
setSortType
(
sortType
);
setSortBy
(
sortBy
);
}
public
List
<
T
>
getList
()
{
return
list
;
}
public
void
setList
(
List
<
T
>
list
)
{
this
.
list
=
list
;
}
public
long
getStartIndex
()
{
return
startIndex
;
}
public
void
setStartIndex
(
long
startIndex
)
{
this
.
startIndex
=
startIndex
;
}
public
int
getPageSize
()
{
return
pageSize
;
}
public
void
setPageSize
(
int
pageSize
)
{
this
.
pageSize
=
pageSize
;
}
public
long
getTotalCount
()
{
return
totalCount
;
}
public
void
setTotalCount
(
long
totalCount
)
{
this
.
totalCount
=
totalCount
;
}
public
SortType
getSortType
()
{
return
sortType
;
}
public
void
setSortType
(
SortType
sortType
)
{
this
.
sortType
=
sortType
;
}
public
String
getSortBy
()
{
return
sortBy
;
}
public
void
setSortBy
(
String
sortBy
)
{
this
.
sortBy
=
sortBy
;
}
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"PList<T>{"
);
sb
.
append
(
"list='"
).
append
((
list
==
null
?
"null"
:
(
"size:"
+
list
.
size
()))).
append
(
'\''
);
sb
.
append
(
", startIndex="
).
append
(
startIndex
);
sb
.
append
(
", pageSize="
).
append
(
pageSize
);
sb
.
append
(
", totalCount="
).
append
(
totalCount
);
sb
.
append
(
", sortType="
).
append
(
sortType
);
sb
.
append
(
", version="
).
append
(
sortBy
);
sb
.
append
(
'}'
);
return
sb
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
}
intg/src/main/java/org/apache/atlas/api/SearchFilter.java
0 → 100644
View file @
698a5652
/**
* 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
.
api
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* Generic filter, to specify search criteria using name/value pairs.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SearchFilter
{
/**
* to specify whether the result should be sorted? If yes, whether asc or desc.
*/
public
enum
SortType
{
NONE
,
ASC
,
DESC
};
private
Map
<
String
,
String
>
params
=
null
;
private
long
startIndex
=
0
;
private
long
maxRows
=
Long
.
MAX_VALUE
;
private
boolean
getCount
=
true
;
private
String
sortBy
=
null
;
private
SortType
sortType
=
null
;
public
SearchFilter
()
{
setParams
(
null
);
}
public
SearchFilter
(
Map
<
String
,
String
>
params
)
{
setParams
(
params
);
}
public
Map
<
String
,
String
>
getParams
()
{
return
params
;
}
public
void
setParams
(
Map
<
String
,
String
>
params
)
{
this
.
params
=
params
;
}
public
String
getParam
(
String
name
)
{
String
ret
=
null
;
if
(
name
!=
null
&&
params
!=
null
)
{
ret
=
params
.
get
(
name
);
}
return
ret
;
}
public
void
setParam
(
String
name
,
String
value
)
{
if
(
name
!=
null
)
{
if
(
params
==
null
)
{
params
=
new
HashMap
<
String
,
String
>();
}
params
.
put
(
name
,
value
);
}
}
public
long
getStartIndex
()
{
return
startIndex
;
}
public
void
setStartIndex
(
long
startIndex
)
{
this
.
startIndex
=
startIndex
;
}
public
long
getMaxRows
()
{
return
maxRows
;
}
public
void
setMaxRows
(
long
maxRows
)
{
this
.
maxRows
=
maxRows
;
}
public
boolean
isGetCount
()
{
return
getCount
;
}
public
void
setGetCount
(
boolean
getCount
)
{
this
.
getCount
=
getCount
;
}
public
String
getSortBy
()
{
return
sortBy
;
}
public
void
setSortBy
(
String
sortBy
)
{
this
.
sortBy
=
sortBy
;
}
public
SortType
getSortType
()
{
return
sortType
;
}
public
void
setSortType
(
SortType
sortType
)
{
this
.
sortType
=
sortType
;
}
}
intg/src/main/java/org/apache/atlas/exception/AtlasBaseException.java
0 → 100644
View file @
698a5652
/**
* 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
.
exception
;
/**
* Base Exception class for Atlas API.
*/
public
class
AtlasBaseException
extends
Exception
{
public
AtlasBaseException
()
{
}
public
AtlasBaseException
(
String
message
)
{
super
(
message
);
}
public
AtlasBaseException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
AtlasBaseException
(
Throwable
cause
)
{
super
(
cause
);
}
public
AtlasBaseException
(
String
message
,
Throwable
cause
,
boolean
enableSuppression
,
boolean
writableStackTrace
)
{
super
(
message
,
cause
,
enableSuppression
,
writableStackTrace
);
}
}
intg/src/main/java/org/apache/atlas/model/instance/AtlasClassification.java
0 → 100644
View file @
698a5652
/**
* 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
java.io.Serializable
;
import
java.util.Map
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* An instance of a classfication; it doesn't have an identity, this object exists only when associated with an entity.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasClassification
extends
AtlasStruct
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
public
AtlasClassification
()
{
this
(
null
,
null
);
}
public
AtlasClassification
(
String
typeName
)
{
this
(
typeName
,
null
);
}
public
AtlasClassification
(
String
typeName
,
Map
<
String
,
Object
>
attributes
)
{
super
(
typeName
,
attributes
);
}
public
AtlasClassification
(
String
typeName
,
String
attrName
,
Object
attrValue
)
{
super
(
typeName
,
attrName
,
attrValue
);
}
public
AtlasClassification
(
AtlasClassification
other
)
{
if
(
other
!=
null
)
{
setTypeName
(
other
.
getTypeName
());
setAttributes
(
other
.
getAttributes
());
}
}
}
intg/src/main/java/org/apache/atlas/model/instance/AtlasEntity.java
0 → 100644
View file @
698a5652
/**
* 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
java.io.Serializable
;
import
java.util.Date
;
import
java.util.Map
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* An instance of an entity - like hive_table, hive_database.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasEntity
extends
AtlasStruct
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* Status of the entity - can be active or deleted. Deleted entities are not removed from Atlas store.
*/
public
enum
Status
{
STATUS_ACTIVE
,
STATUS_DELETED
};
private
String
guid
=
null
;
private
Status
status
=
Status
.
STATUS_ACTIVE
;
private
String
createdBy
=
null
;
private
String
updatedBy
=
null
;
private
Date
createTime
=
null
;
private
Date
updateTime
=
null
;
private
Long
version
=
null
;
public
AtlasEntity
()
{
this
(
null
,
null
);
}
public
AtlasEntity
(
String
typeName
)
{
this
(
typeName
,
null
);
}
public
AtlasEntity
(
AtlasEntityDef
entityDef
)
{
this
(
entityDef
!=
null
?
entityDef
.
getName
()
:
null
,
null
);
}
public
AtlasEntity
(
String
typeName
,
Map
<
String
,
Object
>
attributes
)
{
super
(
typeName
,
attributes
);
setGuid
(
null
);
setStatus
(
null
);
setCreatedBy
(
null
);
setUpdatedBy
(
null
);
setCreateTime
(
null
);
setUpdateTime
(
null
);
setVersion
(
null
);
}
public
AtlasEntity
(
AtlasEntity
other
)
{
super
(
other
);
if
(
other
!=
null
)
{
setGuid
(
other
.
getGuid
());
setStatus
(
other
.
getStatus
());
setCreatedBy
(
other
.
getCreatedBy
());
setUpdatedBy
(
other
.
getUpdatedBy
());
setCreateTime
(
other
.
getCreateTime
());
setUpdateTime
(
other
.
getUpdateTime
());
setVersion
(
other
.
getVersion
());
}
}
public
String
getGuid
()
{
return
guid
;
}
public
void
setGuid
(
String
guid
)
{
this
.
guid
=
guid
;
}
public
Status
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Status
status
)
{
this
.
status
=
status
;
}
public
String
getCreatedBy
()
{
return
createdBy
;
}
public
void
setCreatedBy
(
String
createdBy
)
{
this
.
createdBy
=
createdBy
;
}
public
String
getUpdatedBy
()
{
return
updatedBy
;
}
public
void
setUpdatedBy
(
String
updatedBy
)
{
this
.
updatedBy
=
updatedBy
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Date
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Date
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
Long
getVersion
()
{
return
version
;
}
public
void
setVersion
(
Long
version
)
{
this
.
version
=
version
;
}
@Override
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasEntity{"
);
sb
.
append
(
"guid='"
).
append
(
guid
).
append
(
'\''
);
sb
.
append
(
", status="
).
append
(
status
);
sb
.
append
(
", createdBy='"
).
append
(
createdBy
).
append
(
'\''
);
sb
.
append
(
", updatedBy='"
).
append
(
updatedBy
).
append
(
'\''
);
dumpDateField
(
", createTime="
,
createTime
,
sb
);
dumpDateField
(
", updateTime="
,
updateTime
,
sb
);
sb
.
append
(
", version="
).
append
(
version
);
sb
.
append
(
", "
);
super
.
toString
(
sb
);
sb
.
append
(
'}'
);
return
sb
;
}
@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
;
}
AtlasEntity
that
=
(
AtlasEntity
)
o
;
if
(
guid
!=
null
?
!
guid
.
equals
(
that
.
guid
)
:
that
.
guid
!=
null
)
{
return
false
;
}
if
(
status
!=
null
?
!
status
.
equals
(
that
.
status
)
:
that
.
status
!=
null
)
{
return
false
;
}
if
(
createdBy
!=
null
?
!
createdBy
.
equals
(
that
.
createdBy
)
:
that
.
createdBy
!=
null
)
{
return
false
;
}
if
(
updatedBy
!=
null
?
!
updatedBy
.
equals
(
that
.
updatedBy
)
:
that
.
updatedBy
!=
null
)
{
return
false
;
}
if
(
createTime
!=
null
?
!
createTime
.
equals
(
that
.
createTime
)
:
that
.
createTime
!=
null
)
{
return
false
;
}
if
(
updateTime
!=
null
?
!
updateTime
.
equals
(
that
.
updateTime
)
:
that
.
updateTime
!=
null
)
{
return
false
;
}
if
(
version
!=
null
?
!
version
.
equals
(
that
.
version
)
:
that
.
version
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
super
.
hashCode
();
result
=
31
*
result
+
guid
!=
null
?
guid
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
status
!=
null
?
status
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
createdBy
!=
null
?
createdBy
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
updatedBy
!=
null
?
updatedBy
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
createTime
!=
null
?
createTime
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
updateTime
!=
null
?
updateTime
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
version
!=
null
?
version
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
}
intg/src/main/java/org/apache/atlas/model/instance/AtlasObjectId.java
0 → 100644
View file @
698a5652
/**
* 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
java.io.Serializable
;
import
java.util.Map
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* Reference to an object-instance of an Atlas type - like entity.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasObjectId
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
public
static
final
String
KEY_TYPENAME
=
"typeName"
;
public
static
final
String
KEY_GUID
=
"guid"
;
private
String
typeName
;
private
String
guid
;
public
AtlasObjectId
()
{
this
(
null
,
null
);
}
public
AtlasObjectId
(
String
typeName
)
{
this
(
typeName
,
null
);
}
public
AtlasObjectId
(
String
typeName
,
String
guid
)
{
setTypeName
(
typeName
);
setGuid
(
guid
);
}
public
AtlasObjectId
(
AtlasObjectId
other
)
{
if
(
other
!=
null
)
{
setTypeName
(
other
.
getTypeName
());
setGuid
(
other
.
getGuid
());
}
}
public
AtlasObjectId
(
Map
objIdMap
)
{
if
(
objIdMap
!=
null
)
{
Object
t
=
objIdMap
.
get
(
KEY_TYPENAME
);
Object
g
=
objIdMap
.
get
(
KEY_GUID
);
if
(
t
!=
null
)
{
setTypeName
(
t
.
toString
());
}
if
(
g
!=
null
)
{
setGuid
(
g
.
toString
());
}
}
}
public
String
getTypeName
()
{
return
typeName
;
}
public
void
setTypeName
(
String
typeName
)
{
this
.
typeName
=
typeName
;
}
public
String
getGuid
()
{
return
guid
;
}
public
void
setGuid
(
String
guid
)
{
this
.
guid
=
guid
;
}
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasObjectId{"
);
sb
.
append
(
"typeName='"
).
append
(
typeName
).
append
(
'\''
);
sb
.
append
(
", guid='"
).
append
(
guid
).
append
(
'\''
);
sb
.
append
(
'}'
);
return
sb
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
AtlasObjectId
that
=
(
AtlasObjectId
)
o
;
if
(
typeName
!=
null
?
!
typeName
.
equals
(
that
.
typeName
)
:
that
.
typeName
!=
null
)
{
return
false
;
}
if
(
guid
!=
null
?
!
guid
.
equals
(
that
.
guid
)
:
that
.
guid
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
typeName
!=
null
?
typeName
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
guid
!=
null
?
guid
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
}
intg/src/main/java/org/apache/atlas/model/instance/AtlasStruct.java
0 → 100644
View file @
698a5652
/**
* 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
java.io.Serializable
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* Captures details of struct contents. Not instantiated directly, used only via AtlasEntity, AtlasClassification.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasStruct
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
public
static
final
String
SERIALIZED_DATE_FORMAT_STR
=
"yyyyMMdd-HH:mm:ss.SSS-Z"
;
public
static
final
DateFormat
DATE_FORMATTER
=
new
SimpleDateFormat
(
SERIALIZED_DATE_FORMAT_STR
);
private
String
typeName
;
private
Map
<
String
,
Object
>
attributes
;
public
AtlasStruct
()
{
this
(
null
,
null
);
}
public
AtlasStruct
(
String
typeName
)
{
this
(
typeName
,
null
);
}
public
AtlasStruct
(
String
typeName
,
Map
<
String
,
Object
>
attributes
)
{
setTypeName
(
typeName
);
setAttributes
(
attributes
);
}
public
AtlasStruct
(
String
typeName
,
String
attrName
,
Object
attrValue
)
{
setTypeName
(
typeName
);
setAttribute
(
attrName
,
attrValue
);
}
public
AtlasStruct
(
AtlasStruct
other
)
{
if
(
other
!=
null
)
{
setTypeName
(
other
.
getTypeName
());
setAttributes
(
other
.
getAttributes
());
}
}
public
String
getTypeName
()
{
return
typeName
;
}
public
void
setTypeName
(
String
typeName
)
{
this
.
typeName
=
typeName
;
}
public
Map
<
String
,
Object
>
getAttributes
()
{
return
attributes
;
}
public
void
setAttributes
(
Map
<
String
,
Object
>
attributes
)
{
this
.
attributes
=
attributes
;
}
public
boolean
hasAttribute
(
String
name
)
{
Map
<
String
,
Object
>
a
=
this
.
attributes
;
return
a
!=
null
?
a
.
containsKey
(
name
)
:
null
;
}
public
Object
getAttribute
(
String
name
)
{
Map
<
String
,
Object
>
a
=
this
.
attributes
;
return
a
!=
null
?
a
.
get
(
name
)
:
null
;
}
public
void
setAttribute
(
String
name
,
Object
value
)
{
Map
<
String
,
Object
>
a
=
this
.
attributes
;
if
(
a
!=
null
)
{
a
.
put
(
name
,
value
);
}
else
{
a
=
new
HashMap
<
String
,
Object
>();
a
.
put
(
name
,
value
);
this
.
attributes
=
a
;
}
}
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasStruct{"
);
sb
.
append
(
"typeName='"
).
append
(
typeName
).
append
(
'\''
);
sb
.
append
(
", attributes=["
);
dumpObjects
(
attributes
,
sb
);
sb
.
append
(
"]"
);
sb
.
append
(
'}'
);
return
sb
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
AtlasStruct
that
=
(
AtlasStruct
)
o
;
if
(
typeName
!=
null
?
!
typeName
.
equals
(
that
.
typeName
)
:
that
.
typeName
!=
null
)
{
return
false
;
}
if
(
attributes
!=
null
?
!
attributes
.
equals
(
that
.
attributes
)
:
that
.
attributes
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
(
typeName
!=
null
?
typeName
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
attributes
!=
null
?
attributes
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
public
static
StringBuilder
dumpModelObjects
(
Collection
<?
extends
AtlasStruct
>
objList
,
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
if
(
CollectionUtils
.
isNotEmpty
(
objList
))
{
int
i
=
0
;
for
(
AtlasStruct
obj
:
objList
)
{
if
(
i
>
0
)
{
sb
.
append
(
", "
);
}
obj
.
toString
(
sb
);
i
++;
}
}
return
sb
;
}
public
static
StringBuilder
dumpObjects
(
Collection
<?
extends
Object
>
objects
,
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
if
(
CollectionUtils
.
isNotEmpty
(
objects
))
{
int
i
=
0
;
for
(
Object
obj
:
objects
)
{
if
(
i
>
0
)
{
sb
.
append
(
", "
);
}
sb
.
append
(
obj
);
i
++;
}
}
return
sb
;
}
public
static
StringBuilder
dumpObjects
(
Map
<?
extends
Object
,
?
extends
Object
>
objects
,
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
if
(
MapUtils
.
isNotEmpty
(
objects
))
{
int
i
=
0
;
for
(
Map
.
Entry
<?
extends
Object
,
?
extends
Object
>
e
:
objects
.
entrySet
())
{
if
(
i
>
0
)
{
sb
.
append
(
", "
);
}
sb
.
append
(
e
.
getKey
()).
append
(
":"
).
append
(
e
.
getValue
());
i
++;
}
}
return
sb
;
}
public
static
StringBuilder
dumpDateField
(
String
prefix
,
Date
value
,
StringBuilder
sb
)
{
sb
.
append
(
prefix
);
if
(
value
==
null
)
{
sb
.
append
(
value
);
}
else
{
sb
.
append
(
DATE_FORMATTER
.
format
(
value
));
}
return
sb
;
}
}
intg/src/main/java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.Map
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* Base class that captures common-attributes for all Atlas types.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
abstract
class
AtlasBaseTypeDef
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
public
static
final
String
ATLAS_TYPE_BOOLEAN
=
"boolean"
;
public
static
final
String
ATLAS_TYPE_BYTE
=
"byte"
;
public
static
final
String
ATLAS_TYPE_SHORT
=
"short"
;
public
static
final
String
ATLAS_TYPE_INT
=
"int"
;
public
static
final
String
ATLAS_TYPE_LONG
=
"long"
;
public
static
final
String
ATLAS_TYPE_FLOAT
=
"float"
;
public
static
final
String
ATLAS_TYPE_DOUBLE
=
"double"
;
public
static
final
String
ATLAS_TYPE_BIGINTEGER
=
"biginteger"
;
public
static
final
String
ATLAS_TYPE_BIGDECIMAL
=
"bigdecimal"
;
public
static
final
String
ATLAS_TYPE_STRING
=
"string"
;
public
static
final
String
ATLAS_TYPE_DATE
=
"date"
;
public
static
final
String
ATLAS_TYPE_OBJECT_ID
=
"objectid"
;
public
static
final
String
ATLAS_TYPE_ARRAY_PREFIX
=
"array<"
;
public
static
final
String
ATLAS_TYPE_ARRAY_SUFFIX
=
">"
;
public
static
final
String
ATLAS_TYPE_MAP_PREFIX
=
"map<"
;
public
static
final
String
ATLAS_TYPE_MAP_KEY_VAL_SEP
=
","
;
public
static
final
String
ATLAS_TYPE_MAP_SUFFIX
=
">"
;
public
static
final
String
ATLAS_TYPE_PROCESS
=
"Process"
;
public
static
final
String
ATLAS_TYPE_DATASET
=
"DataSet"
;
public
static
final
String
ATLAS_TYPE_ASSET
=
"Asset"
;
public
static
final
String
ATLAS_TYPE_INFRASTRUCTURE
=
"Infrastructure"
;
public
static
final
String
[]
ATLAS_PRIMITIVE_TYPES
=
{
ATLAS_TYPE_BOOLEAN
,
ATLAS_TYPE_BYTE
,
ATLAS_TYPE_SHORT
,
ATLAS_TYPE_INT
,
ATLAS_TYPE_LONG
,
ATLAS_TYPE_FLOAT
,
ATLAS_TYPE_DOUBLE
,
ATLAS_TYPE_BIGINTEGER
,
ATLAS_TYPE_BIGDECIMAL
,
ATLAS_TYPE_STRING
,
};
public
static
final
String
[]
ATLAS_BUILTIN_TYPES
=
{
ATLAS_TYPE_BOOLEAN
,
ATLAS_TYPE_BYTE
,
ATLAS_TYPE_SHORT
,
ATLAS_TYPE_INT
,
ATLAS_TYPE_LONG
,
ATLAS_TYPE_FLOAT
,
ATLAS_TYPE_DOUBLE
,
ATLAS_TYPE_BIGINTEGER
,
ATLAS_TYPE_BIGDECIMAL
,
ATLAS_TYPE_STRING
,
ATLAS_TYPE_DATE
,
ATLAS_TYPE_OBJECT_ID
,
};
public
static
final
String
SERIALIZED_DATE_FORMAT_STR
=
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
;
public
static
final
DateFormat
DATE_FORMATTER
=
new
SimpleDateFormat
(
SERIALIZED_DATE_FORMAT_STR
);
private
String
guid
=
null
;
private
String
createdBy
=
null
;
private
String
updatedBy
=
null
;
private
Date
createTime
=
null
;
private
Date
updateTime
=
null
;
private
Long
version
=
null
;
private
String
name
;
private
String
description
;
private
String
typeVersion
;
public
AtlasBaseTypeDef
()
{
this
(
null
,
null
,
null
);
}
public
AtlasBaseTypeDef
(
String
name
)
{
this
(
name
,
null
,
null
);
}
public
AtlasBaseTypeDef
(
String
name
,
String
description
)
{
this
(
name
,
description
,
null
);
}
public
AtlasBaseTypeDef
(
String
name
,
String
description
,
String
typeVersion
)
{
super
();
setGuid
(
null
);
setCreatedBy
(
null
);
setUpdatedBy
(
null
);
setCreateTime
(
null
);
setUpdateTime
(
null
);
setVersion
(
null
);
setName
(
name
);
setDescription
(
description
);
setTypeVersion
(
typeVersion
);
}
public
AtlasBaseTypeDef
(
AtlasBaseTypeDef
other
)
{
if
(
other
!=
null
)
{
setGuid
(
other
.
getGuid
());
setCreatedBy
(
other
.
getCreatedBy
());
setUpdatedBy
(
other
.
getUpdatedBy
());
setCreateTime
(
other
.
getCreateTime
());
setUpdateTime
(
other
.
getUpdateTime
());
setVersion
(
other
.
getVersion
());
setName
(
other
.
getName
());
setDescription
(
other
.
getDescription
());
setTypeVersion
(
other
.
getTypeVersion
());
}
else
{
setGuid
(
null
);
setCreatedBy
(
null
);
setUpdatedBy
(
null
);
setCreateTime
(
null
);
setUpdateTime
(
null
);
setVersion
(
null
);
setName
(
null
);
setDescription
(
null
);
setTypeVersion
(
null
);
}
}
public
String
getGuid
()
{
return
guid
;
}
public
void
setGuid
(
String
guid
)
{
this
.
guid
=
guid
;
}
public
String
getCreatedBy
()
{
return
createdBy
;
}
public
void
setCreatedBy
(
String
createdBy
)
{
this
.
createdBy
=
createdBy
;
}
public
String
getUpdatedBy
()
{
return
updatedBy
;
}
public
void
setUpdatedBy
(
String
updatedBy
)
{
this
.
updatedBy
=
updatedBy
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Date
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Date
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
Long
getVersion
()
{
return
version
;
}
public
void
setVersion
(
Long
version
)
{
this
.
version
=
version
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
String
getTypeVersion
()
{
return
typeVersion
;
}
public
void
setTypeVersion
(
String
typeVersion
)
{
this
.
typeVersion
=
typeVersion
;
}
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
", AtlasBaseTypeDef{"
);
sb
.
append
(
"guid='"
).
append
(
guid
).
append
(
'\''
);
sb
.
append
(
", createdBy='"
).
append
(
createdBy
).
append
(
'\''
);
sb
.
append
(
", updatedBy='"
).
append
(
updatedBy
).
append
(
'\''
);
dumpDateField
(
", createTime="
,
createTime
,
sb
);
dumpDateField
(
", updateTime="
,
updateTime
,
sb
);
sb
.
append
(
", version="
).
append
(
version
);
sb
.
append
(
", name='"
).
append
(
name
).
append
(
'\''
);
sb
.
append
(
", description='"
).
append
(
description
).
append
(
'\''
);
sb
.
append
(
", typeVersion='"
).
append
(
typeVersion
).
append
(
'\''
);
sb
.
append
(
'}'
);
return
sb
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
AtlasBaseTypeDef
that
=
(
AtlasBaseTypeDef
)
o
;
if
(
guid
!=
null
?
!
guid
.
equals
(
that
.
guid
)
:
that
.
guid
!=
null
)
{
return
false
;
}
if
(
createdBy
!=
null
?
!
createdBy
.
equals
(
that
.
createdBy
)
:
that
.
createdBy
!=
null
)
{
return
false
;
}
if
(
updatedBy
!=
null
?
!
updatedBy
.
equals
(
that
.
updatedBy
)
:
that
.
updatedBy
!=
null
)
{
return
false
;
}
if
(
createTime
!=
null
?
!
createTime
.
equals
(
that
.
createTime
)
:
that
.
createTime
!=
null
)
{
return
false
;
}
if
(
updateTime
!=
null
?
!
updateTime
.
equals
(
that
.
updateTime
)
:
that
.
updateTime
!=
null
)
{
return
false
;
}
if
(
version
!=
null
?
!
version
.
equals
(
that
.
version
)
:
that
.
version
!=
null
)
{
return
false
;
}
if
(
name
!=
null
?
!
name
.
equals
(
that
.
name
)
:
that
.
name
!=
null
)
{
return
false
;
}
if
(
description
!=
null
?
!
description
.
equals
(
that
.
description
)
:
that
.
description
!=
null
)
{
return
false
;
}
if
(
typeVersion
!=
null
?
!
typeVersion
.
equals
(
that
.
typeVersion
)
:
that
.
typeVersion
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
guid
!=
null
?
guid
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
createdBy
!=
null
?
createdBy
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
updatedBy
!=
null
?
updatedBy
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
createTime
!=
null
?
createTime
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
updateTime
!=
null
?
updateTime
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
version
!=
null
?
version
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
name
!=
null
?
name
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
description
!=
null
?
description
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
typeVersion
!=
null
?
typeVersion
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
public
static
String
getArrayTypeName
(
String
elemTypeName
)
{
return
ATLAS_TYPE_ARRAY_PREFIX
+
elemTypeName
+
ATLAS_TYPE_ARRAY_SUFFIX
;
}
public
static
String
getMapTypeName
(
String
keyTypeName
,
String
valueTypeName
)
{
return
String
.
format
(
"%s%s%s%s%s"
,
ATLAS_TYPE_MAP_PREFIX
,
keyTypeName
,
ATLAS_TYPE_MAP_KEY_VAL_SEP
,
valueTypeName
,
ATLAS_TYPE_MAP_SUFFIX
);
}
public
static
StringBuilder
dumpObjects
(
Collection
<?
extends
Object
>
objects
,
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
if
(
CollectionUtils
.
isNotEmpty
(
objects
))
{
int
i
=
0
;
for
(
Object
obj
:
objects
)
{
if
(
i
>
0
)
{
sb
.
append
(
", "
);
}
sb
.
append
(
obj
);
i
++;
}
}
return
sb
;
}
public
static
StringBuilder
dumpObjects
(
Map
<?
extends
Object
,
?
extends
Object
>
objects
,
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
if
(
MapUtils
.
isNotEmpty
(
objects
))
{
int
i
=
0
;
for
(
Map
.
Entry
<?
extends
Object
,
?
extends
Object
>
e
:
objects
.
entrySet
())
{
if
(
i
>
0
)
{
sb
.
append
(
", "
);
}
sb
.
append
(
e
.
getKey
()).
append
(
":"
).
append
(
e
.
getValue
());
i
++;
}
}
return
sb
;
}
public
static
StringBuilder
dumpDateField
(
String
prefix
,
Date
value
,
StringBuilder
sb
)
{
sb
.
append
(
prefix
);
if
(
value
==
null
)
{
sb
.
append
(
value
);
}
else
{
sb
.
append
(
DATE_FORMATTER
.
format
(
value
));
}
return
sb
;
}
}
intg/src/main/java/org/apache/atlas/model/typedef/AtlasClassificationDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* class that captures details of a classification-type.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasClassificationDef
extends
AtlasStructDef
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
Set
<
String
>
superTypes
;
public
AtlasClassificationDef
()
{
super
();
setSuperTypes
(
null
);
}
public
AtlasClassificationDef
(
String
name
)
{
this
(
name
,
null
,
null
,
null
,
null
);
}
public
AtlasClassificationDef
(
String
name
,
String
description
)
{
this
(
name
,
description
,
null
,
null
,
null
);
}
public
AtlasClassificationDef
(
String
name
,
String
description
,
String
typeVersion
)
{
this
(
name
,
description
,
typeVersion
,
null
,
null
);
}
public
AtlasClassificationDef
(
String
name
,
String
description
,
String
typeVersion
,
List
<
AtlasAttributeDef
>
attributeDefs
)
{
this
(
name
,
description
,
typeVersion
,
attributeDefs
,
null
);
}
public
AtlasClassificationDef
(
String
name
,
String
description
,
String
typeVersion
,
List
<
AtlasAttributeDef
>
attributeDefs
,
Set
<
String
>
superTypes
)
{
super
(
name
,
description
,
typeVersion
,
attributeDefs
);
setSuperTypes
(
superTypes
);
}
public
AtlasClassificationDef
(
AtlasClassificationDef
other
)
{
super
(
other
);
setSuperTypes
(
other
!=
null
?
other
.
getSuperTypes
()
:
null
);
}
public
Set
<
String
>
getSuperTypes
()
{
return
superTypes
;
}
public
void
setSuperTypes
(
Set
<
String
>
superTypes
)
{
if
(
superTypes
!=
null
&&
this
.
superTypes
==
superTypes
)
{
return
;
}
if
(
CollectionUtils
.
isEmpty
(
superTypes
))
{
this
.
superTypes
=
Collections
.
emptySet
();
}
else
{
this
.
superTypes
=
Collections
.
unmodifiableSet
(
new
HashSet
<
String
>(
superTypes
));
}
}
public
boolean
hasSuperType
(
String
typeName
)
{
return
hasSuperType
(
superTypes
,
typeName
);
}
public
void
addSuperType
(
String
typeName
)
{
Set
<
String
>
s
=
this
.
superTypes
;
if
(!
hasSuperType
(
s
,
typeName
))
{
s
=
new
HashSet
<
String
>(
s
);
s
.
add
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
);
}
}
public
void
removeSuperType
(
String
typeName
)
{
Set
<
String
>
s
=
this
.
superTypes
;
if
(
hasSuperType
(
s
,
typeName
))
{
s
=
new
HashSet
<
String
>(
s
);
s
.
remove
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
);
}
}
private
static
boolean
hasSuperType
(
Set
<
String
>
superTypes
,
String
typeName
)
{
return
superTypes
!=
null
&&
typeName
!=
null
&&
superTypes
.
contains
(
typeName
);
}
@Override
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasClassificationDef{"
);
super
.
toString
(
sb
);
sb
.
append
(
", superTypes=["
);
dumpObjects
(
superTypes
,
sb
);
sb
.
append
(
"]"
);
sb
.
append
(
'}'
);
return
sb
;
}
@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
;
}
AtlasClassificationDef
that
=
(
AtlasClassificationDef
)
o
;
if
(
superTypes
!=
null
?
!
superTypes
.
equals
(
that
.
superTypes
)
:
that
.
superTypes
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
super
.
hashCode
();
result
=
31
*
result
+
(
superTypes
!=
null
?
superTypes
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
}
intg/src/main/java/org/apache/atlas/model/typedef/AtlasEntityDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* class that captures details of a entity-type.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasEntityDef
extends
AtlasStructDef
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
Set
<
String
>
superTypes
;
public
AtlasEntityDef
()
{
this
(
null
,
null
,
null
,
null
,
null
);
}
public
AtlasEntityDef
(
String
name
)
{
this
(
name
,
null
,
null
,
null
,
null
);
}
public
AtlasEntityDef
(
String
name
,
String
description
)
{
this
(
name
,
description
,
null
,
null
,
null
);
}
public
AtlasEntityDef
(
String
name
,
String
description
,
String
typeVersion
)
{
this
(
name
,
description
,
typeVersion
,
null
,
null
);
}
public
AtlasEntityDef
(
String
name
,
String
description
,
String
typeVersion
,
List
<
AtlasAttributeDef
>
attributeDefs
)
{
this
(
name
,
description
,
typeVersion
,
attributeDefs
,
null
);
}
public
AtlasEntityDef
(
String
name
,
String
description
,
String
typeVersion
,
List
<
AtlasAttributeDef
>
attributeDefs
,
Set
<
String
>
superTypes
)
{
super
(
name
,
description
,
typeVersion
,
attributeDefs
);
setSuperTypes
(
superTypes
);
}
public
AtlasEntityDef
(
AtlasEntityDef
other
)
{
super
(
other
);
setSuperTypes
(
other
!=
null
?
other
.
getSuperTypes
()
:
null
);
}
public
Set
<
String
>
getSuperTypes
()
{
return
superTypes
;
}
public
void
setSuperTypes
(
Set
<
String
>
superTypes
)
{
if
(
superTypes
!=
null
&&
this
.
superTypes
==
superTypes
)
{
return
;
}
if
(
CollectionUtils
.
isEmpty
(
superTypes
))
{
this
.
superTypes
=
Collections
.
emptySet
();
}
else
{
this
.
superTypes
=
Collections
.
unmodifiableSet
(
new
HashSet
<
String
>(
superTypes
));
}
}
public
boolean
hasSuperType
(
String
typeName
)
{
return
hasSuperType
(
superTypes
,
typeName
);
}
public
void
addSuperType
(
String
typeName
)
{
Set
<
String
>
s
=
this
.
superTypes
;
if
(!
hasSuperType
(
s
,
typeName
))
{
s
=
new
HashSet
<
String
>(
s
);
s
.
add
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
);
}
}
public
void
removeSuperType
(
String
typeName
)
{
Set
<
String
>
s
=
this
.
superTypes
;
if
(
hasSuperType
(
s
,
typeName
))
{
s
=
new
HashSet
<
String
>(
s
);
s
.
remove
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
);
}
}
private
static
boolean
hasSuperType
(
Set
<
String
>
superTypes
,
String
typeName
)
{
return
superTypes
!=
null
&&
typeName
!=
null
&&
superTypes
.
contains
(
typeName
);
}
@Override
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasEntityDef{"
);
super
.
toString
(
sb
);
sb
.
append
(
", superTypes=["
);
dumpObjects
(
superTypes
,
sb
);
sb
.
append
(
"]"
);
sb
.
append
(
'}'
);
return
sb
;
}
@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
;
}
AtlasEntityDef
that
=
(
AtlasEntityDef
)
o
;
if
(
superTypes
!=
null
?
!
superTypes
.
equals
(
that
.
superTypes
)
:
that
.
superTypes
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
super
.
hashCode
();
result
=
31
*
result
+
(
superTypes
!=
null
?
superTypes
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
}
intg/src/main/java/org/apache/atlas/model/typedef/AtlasEnumDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
java.io.Serializable
;
import
java.util.*
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.hadoop.util.StringUtils
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* class that captures details of an enum-type.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasEnumDef
extends
AtlasBaseTypeDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
List
<
AtlasEnumElementDef
>
elementDefs
;
private
String
defaultValue
;
public
AtlasEnumDef
()
{
super
();
setElementDefs
(
null
);
setDefaultValue
(
null
);
}
public
AtlasEnumDef
(
String
name
)
{
this
(
name
,
null
,
null
,
null
,
null
);
}
public
AtlasEnumDef
(
String
name
,
String
description
)
{
this
(
name
,
description
,
null
,
null
,
null
);
}
public
AtlasEnumDef
(
String
name
,
String
description
,
String
typeVersion
)
{
this
(
name
,
description
,
typeVersion
,
null
,
null
);
}
public
AtlasEnumDef
(
String
name
,
String
description
,
List
<
AtlasEnumElementDef
>
elementDefs
)
{
this
(
name
,
description
,
null
,
elementDefs
,
null
);
}
public
AtlasEnumDef
(
String
name
,
String
description
,
String
typeVersion
,
List
<
AtlasEnumElementDef
>
elementDefs
)
{
this
(
name
,
description
,
typeVersion
,
elementDefs
,
null
);
}
public
AtlasEnumDef
(
String
name
,
String
description
,
String
typeVersion
,
List
<
AtlasEnumElementDef
>
elementDefs
,
String
defaultValue
)
{
super
(
name
,
description
,
typeVersion
);
setElementDefs
(
elementDefs
);
setDefaultValue
(
defaultValue
);
}
public
AtlasEnumDef
(
AtlasEnumDef
other
)
{
super
(
other
);
if
(
other
!=
null
)
{
setElementDefs
(
other
.
getElementDefs
());
setDefaultValue
(
other
.
getDefaultValue
());
}
}
public
List
<
AtlasEnumElementDef
>
getElementDefs
()
{
return
elementDefs
;
}
public
void
setElementDefs
(
List
<
AtlasEnumElementDef
>
elementDefs
)
{
if
(
elementDefs
!=
null
&&
this
.
elementDefs
==
elementDefs
)
{
return
;
}
if
(
CollectionUtils
.
isEmpty
(
elementDefs
))
{
this
.
elementDefs
=
Collections
.
emptyList
();
}
else
{
// if multiple elements with same value are present, keep only the last entry
List
<
AtlasEnumElementDef
>
tmpList
=
new
ArrayList
<
AtlasEnumElementDef
>(
elementDefs
.
size
());
Set
<
String
>
elementValues
=
new
HashSet
<
String
>();
ListIterator
<
AtlasEnumElementDef
>
iter
=
elementDefs
.
listIterator
(
elementDefs
.
size
());
while
(
iter
.
hasPrevious
())
{
AtlasEnumElementDef
elementDef
=
iter
.
previous
();
String
elementValue
=
elementDef
!=
null
?
elementDef
.
getValue
()
:
null
;
if
(
elementValue
!=
null
)
{
elementValue
=
elementValue
.
toLowerCase
();
if
(!
elementValues
.
contains
(
elementValue
))
{
tmpList
.
add
(
new
AtlasEnumElementDef
(
elementDef
));
elementValues
.
add
(
elementValue
);
}
}
}
Collections
.
reverse
(
tmpList
);
this
.
elementDefs
=
Collections
.
unmodifiableList
(
tmpList
);
}
}
public
String
getDefaultValue
()
{
return
defaultValue
;
}
public
void
setDefaultValue
(
String
value
)
{
this
.
defaultValue
=
value
;
}
public
AtlasEnumElementDef
getElement
(
String
elemValue
)
{
return
findElement
(
this
.
elementDefs
,
elemValue
);
}
public
void
addElement
(
AtlasEnumElementDef
elementDef
)
{
List
<
AtlasEnumElementDef
>
e
=
this
.
elementDefs
;
List
<
AtlasEnumElementDef
>
tmpList
=
new
ArrayList
<
AtlasEnumElementDef
>();
if
(
CollectionUtils
.
isNotEmpty
(
e
))
{
// copy existing elements, except ones having same value as the element being added
for
(
AtlasEnumElementDef
existingElem
:
e
)
{
if
(!
StringUtils
.
equalsIgnoreCase
(
existingElem
.
getValue
(),
elementDef
.
getValue
()))
{
tmpList
.
add
(
existingElem
);
}
}
}
tmpList
.
add
(
new
AtlasEnumElementDef
(
elementDef
));
this
.
elementDefs
=
Collections
.
unmodifiableList
(
tmpList
);
}
public
void
removeElement
(
String
elemValue
)
{
List
<
AtlasEnumElementDef
>
e
=
this
.
elementDefs
;
// if element doesn't exist, no need to create the tmpList below
if
(
hasElement
(
e
,
elemValue
))
{
List
<
AtlasEnumElementDef
>
tmpList
=
new
ArrayList
<
AtlasEnumElementDef
>();
// copy existing elements, except ones having same value as the element being removed
for
(
AtlasEnumElementDef
existingElem
:
e
)
{
if
(!
StringUtils
.
equalsIgnoreCase
(
existingElem
.
getValue
(),
elemValue
))
{
tmpList
.
add
(
existingElem
);
}
}
this
.
elementDefs
=
Collections
.
unmodifiableList
(
tmpList
);
}
}
public
boolean
hasElement
(
String
elemValue
)
{
return
getElement
(
elemValue
)
!=
null
;
}
private
static
boolean
hasElement
(
List
<
AtlasEnumElementDef
>
elementDefs
,
String
elemValue
)
{
return
findElement
(
elementDefs
,
elemValue
)
!=
null
;
}
private
static
AtlasEnumElementDef
findElement
(
List
<
AtlasEnumElementDef
>
elementDefs
,
String
elemValue
)
{
AtlasEnumElementDef
ret
=
null
;
if
(
CollectionUtils
.
isNotEmpty
(
elementDefs
))
{
for
(
AtlasEnumElementDef
elementDef
:
elementDefs
)
{
if
(
StringUtils
.
equalsIgnoreCase
(
elementDef
.
getValue
(),
elemValue
))
{
ret
=
elementDef
;
break
;
}
}
}
return
ret
;
}
@Override
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasEnumDef{"
);
super
.
toString
(
sb
);
sb
.
append
(
", elementDefs=["
);
dumpObjects
(
elementDefs
,
sb
);
sb
.
append
(
"]"
);
sb
.
append
(
'}'
);
return
sb
;
}
@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
;
}
AtlasEnumDef
that
=
(
AtlasEnumDef
)
o
;
if
(
elementDefs
!=
null
?
!
elementDefs
.
equals
(
that
.
elementDefs
)
:
that
.
elementDefs
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
super
.
hashCode
();
result
=
31
*
result
+
(
elementDefs
!=
null
?
elementDefs
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
/**
* class that captures details of an enum-element.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
AtlasEnumElementDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
value
;
private
String
description
;
private
Integer
ordinal
;
public
AtlasEnumElementDef
()
{
this
(
null
,
null
,
null
);
}
public
AtlasEnumElementDef
(
String
value
,
String
description
,
Integer
ordinal
)
{
setValue
(
value
);
setDescription
(
description
);
setOrdinal
(
ordinal
);
}
public
AtlasEnumElementDef
(
AtlasEnumElementDef
other
)
{
if
(
other
!=
null
)
{
setValue
(
other
.
getValue
());
setDescription
(
other
.
getDescription
());
setOrdinal
(
other
.
getOrdinal
());
}
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
Integer
getOrdinal
()
{
return
ordinal
;
}
public
void
setOrdinal
(
Integer
ordinal
)
{
this
.
ordinal
=
ordinal
;
}
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasEnumElementDef{"
);
sb
.
append
(
"value='"
).
append
(
value
).
append
(
'\''
);
sb
.
append
(
", description='"
).
append
(
description
).
append
(
'\''
);
sb
.
append
(
", ordinal="
).
append
(
ordinal
);
sb
.
append
(
'}'
);
return
sb
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
AtlasEnumElementDef
that
=
(
AtlasEnumElementDef
)
o
;
if
(
value
!=
null
?
!
value
.
equals
(
that
.
value
)
:
that
.
value
!=
null
)
{
return
false
;
}
if
(
description
!=
null
?
!
description
.
equals
(
that
.
description
)
:
that
.
description
!=
null
)
{
return
false
;
}
if
(
ordinal
!=
null
?
!
ordinal
.
equals
(
that
.
ordinal
)
:
that
.
ordinal
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
value
!=
null
?
value
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
description
!=
null
?
description
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
ordinal
!=
null
?
ordinal
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
}
}
intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.ListIterator
;
import
java.util.Set
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.hadoop.util.StringUtils
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
/**
* class that captures details of a struct-type.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AtlasStructDef
extends
AtlasBaseTypeDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
// do not update this list contents directly - the list might be in the middle of iteration in another thread
// to update list contents: 1) make a copy 2) update the copy 3) assign the copy to this member
private
List
<
AtlasAttributeDef
>
attributeDefs
;
public
AtlasStructDef
()
{
this
(
null
,
null
,
null
,
null
);
}
public
AtlasStructDef
(
String
name
)
{
this
(
name
,
null
,
null
,
null
);
}
public
AtlasStructDef
(
String
name
,
String
description
)
{
this
(
name
,
description
,
null
,
null
);
}
public
AtlasStructDef
(
String
name
,
String
description
,
String
typeVersion
)
{
this
(
name
,
description
,
typeVersion
,
null
);
}
public
AtlasStructDef
(
String
name
,
String
description
,
String
typeVersion
,
List
<
AtlasAttributeDef
>
attributeDefs
)
{
super
(
name
,
description
,
typeVersion
);
setAttributeDefs
(
attributeDefs
);
}
public
AtlasStructDef
(
AtlasStructDef
other
)
{
super
(
other
);
setAttributeDefs
(
other
!=
null
?
other
.
getAttributeDefs
()
:
null
);
}
public
List
<
AtlasAttributeDef
>
getAttributeDefs
()
{
return
attributeDefs
;
}
public
void
setAttributeDefs
(
List
<
AtlasAttributeDef
>
attributeDefs
)
{
if
(
this
.
attributeDefs
!=
null
&&
this
.
attributeDefs
==
attributeDefs
)
{
return
;
}
if
(
CollectionUtils
.
isEmpty
(
attributeDefs
))
{
this
.
attributeDefs
=
Collections
.
emptyList
();
}
else
{
// if multiple attributes with same name are present, keep only the last entry
List
<
AtlasAttributeDef
>
tmpList
=
new
ArrayList
<
AtlasAttributeDef
>(
attributeDefs
.
size
());
Set
<
String
>
attribNames
=
new
HashSet
<
String
>();
ListIterator
<
AtlasAttributeDef
>
iter
=
attributeDefs
.
listIterator
(
attributeDefs
.
size
());
while
(
iter
.
hasPrevious
())
{
AtlasAttributeDef
attributeDef
=
iter
.
previous
();
String
attribName
=
attributeDef
!=
null
?
attributeDef
.
getName
()
:
null
;
if
(
attribName
!=
null
)
{
attribName
=
attribName
.
toLowerCase
();
if
(!
attribNames
.
contains
(
attribName
))
{
tmpList
.
add
(
new
AtlasAttributeDef
(
attributeDef
));
attribNames
.
add
(
attribName
);
}
}
}
Collections
.
reverse
(
tmpList
);
this
.
attributeDefs
=
Collections
.
unmodifiableList
(
tmpList
);
}
}
public
AtlasAttributeDef
getAttribute
(
String
attrName
)
{
return
findAttribute
(
this
.
attributeDefs
,
attrName
);
}
public
void
addAttribute
(
AtlasAttributeDef
attributeDef
)
{
if
(
attributeDef
==
null
)
{
return
;
}
List
<
AtlasAttributeDef
>
a
=
this
.
attributeDefs
;
List
<
AtlasAttributeDef
>
tmpList
=
new
ArrayList
<
AtlasAttributeDef
>();
if
(
CollectionUtils
.
isNotEmpty
(
a
))
{
// copy existing attributes, except ones having same name as the attribute being added
for
(
AtlasAttributeDef
existingAttrDef
:
a
)
{
if
(!
StringUtils
.
equalsIgnoreCase
(
existingAttrDef
.
getName
(),
attributeDef
.
getName
()))
{
tmpList
.
add
(
existingAttrDef
);
}
}
}
tmpList
.
add
(
new
AtlasAttributeDef
(
attributeDef
));
this
.
attributeDefs
=
Collections
.
unmodifiableList
(
tmpList
);
}
public
void
removeAttribute
(
String
attrName
)
{
List
<
AtlasAttributeDef
>
a
=
this
.
attributeDefs
;
if
(
hasAttribute
(
a
,
attrName
))
{
List
<
AtlasAttributeDef
>
tmpList
=
new
ArrayList
<
AtlasAttributeDef
>();
// copy existing attributes, except ones having same name as the attribute being removed
for
(
AtlasAttributeDef
existingAttrDef
:
a
)
{
if
(!
StringUtils
.
equalsIgnoreCase
(
existingAttrDef
.
getName
(),
attrName
))
{
tmpList
.
add
(
existingAttrDef
);
}
}
this
.
attributeDefs
=
Collections
.
unmodifiableList
(
tmpList
);
}
}
public
boolean
hasAttribute
(
String
attrName
)
{
return
getAttribute
(
attrName
)
!=
null
;
}
private
static
boolean
hasAttribute
(
List
<
AtlasAttributeDef
>
attributeDefs
,
String
attrName
)
{
return
findAttribute
(
attributeDefs
,
attrName
)
!=
null
;
}
private
static
AtlasAttributeDef
findAttribute
(
List
<
AtlasAttributeDef
>
attributeDefs
,
String
attrName
)
{
AtlasAttributeDef
ret
=
null
;
if
(
CollectionUtils
.
isNotEmpty
(
attributeDefs
))
{
for
(
AtlasAttributeDef
attributeDef
:
attributeDefs
)
{
if
(
StringUtils
.
equalsIgnoreCase
(
attributeDef
.
getName
(),
attrName
))
{
ret
=
attributeDef
;
break
;
}
}
}
return
ret
;
}
@Override
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasStructDef{"
);
super
.
toString
(
sb
);
sb
.
append
(
", attributeDefs=["
);
dumpObjects
(
attributeDefs
,
sb
);
sb
.
append
(
"]"
);
sb
.
append
(
'}'
);
return
sb
;
}
@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
;
}
AtlasStructDef
that
=
(
AtlasStructDef
)
o
;
if
(
attributeDefs
!=
null
?
!
attributeDefs
.
equals
(
that
.
attributeDefs
)
:
that
.
attributeDefs
!=
null
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
super
.
hashCode
();
result
=
31
*
result
+
(
attributeDefs
!=
null
?
attributeDefs
.
hashCode
()
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
/**
* class that captures details of a struct-attribute.
*/
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
AtlasAttributeDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* single-valued attribute or multi-valued attribute.
*/
public
enum
Cardinality
{
SINGLE
,
LIST
,
SET
};
public
static
final
int
COUNT_NOT_SET
=
-
1
;
private
String
name
;
private
String
typeName
;
private
boolean
isOptional
;
private
Cardinality
cardinality
;
private
int
valuesMinCount
;
private
int
valuesMaxCount
;
private
boolean
isUnique
;
private
boolean
isIndexable
;
public
AtlasAttributeDef
()
{
this
(
null
,
null
);
}
public
AtlasAttributeDef
(
String
name
,
String
typeName
)
{
this
(
name
,
typeName
,
false
,
Cardinality
.
SINGLE
,
1
,
1
,
false
,
false
);
}
public
AtlasAttributeDef
(
String
name
,
String
typeName
,
boolean
isOptional
,
Cardinality
cardinality
,
int
valuesMinCount
,
int
valuesMaxCount
,
boolean
isUnique
,
boolean
isIndexable
)
{
setName
(
name
);
setTypeName
(
typeName
);
setOptional
(
isOptional
);
setCardinality
(
cardinality
);
setValuesMinCount
(
valuesMinCount
);
setValuesMaxCount
(
valuesMaxCount
);
setUnique
(
isUnique
);
setIndexable
(
isIndexable
);
}
public
AtlasAttributeDef
(
AtlasAttributeDef
other
)
{
if
(
other
!=
null
)
{
setName
(
other
.
getName
());
setTypeName
(
other
.
getTypeName
());
setOptional
(
other
.
isOptional
());
setCardinality
(
other
.
getCardinality
());
setValuesMinCount
(
other
.
getValuesMinCount
());
setValuesMaxCount
(
other
.
getValuesMaxCount
());
setUnique
(
other
.
isUnique
());
setIndexable
(
other
.
isIndexable
());
}
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getTypeName
()
{
return
typeName
;
}
public
void
setTypeName
(
String
typeName
)
{
this
.
typeName
=
typeName
;
}
public
boolean
isOptional
()
{
return
isOptional
;
}
public
void
setOptional
(
boolean
optional
)
{
isOptional
=
optional
;
}
public
void
setCardinality
(
Cardinality
cardinality
)
{
this
.
cardinality
=
cardinality
;
}
public
Cardinality
getCardinality
()
{
return
cardinality
;
}
public
int
getValuesMinCount
()
{
return
valuesMinCount
;
}
public
void
setValuesMinCount
(
int
valuesMinCount
)
{
this
.
valuesMinCount
=
valuesMinCount
;
}
public
int
getValuesMaxCount
()
{
return
valuesMaxCount
;
}
public
void
setValuesMaxCount
(
int
valuesMaxCount
)
{
this
.
valuesMaxCount
=
valuesMaxCount
;
}
public
boolean
isUnique
()
{
return
isUnique
;
}
public
void
setUnique
(
boolean
unique
)
{
isUnique
=
unique
;
}
public
boolean
isIndexable
()
{
return
isIndexable
;
}
public
void
setIndexable
(
boolean
idexable
)
{
isIndexable
=
idexable
;
}
public
StringBuilder
toString
(
StringBuilder
sb
)
{
if
(
sb
==
null
)
{
sb
=
new
StringBuilder
();
}
sb
.
append
(
"AtlasAttributeDef{"
);
sb
.
append
(
"name='"
).
append
(
name
).
append
(
'\''
);
sb
.
append
(
", typeName='"
).
append
(
typeName
).
append
(
'\''
);
sb
.
append
(
", isOptional="
).
append
(
isOptional
);
sb
.
append
(
", cardinality="
).
append
(
cardinality
);
sb
.
append
(
", valuesMinCount="
).
append
(
valuesMinCount
);
sb
.
append
(
", valuesMaxCount="
).
append
(
valuesMaxCount
);
sb
.
append
(
", isUnique="
).
append
(
isUnique
);
sb
.
append
(
", isIndexable="
).
append
(
isIndexable
);
sb
.
append
(
'}'
);
return
sb
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
AtlasAttributeDef
that
=
(
AtlasAttributeDef
)
o
;
if
(
name
!=
null
?
!
name
.
equals
(
that
.
name
)
:
that
.
name
!=
null
)
{
return
false
;
}
if
(
typeName
!=
null
?
!
typeName
.
equals
(
that
.
typeName
)
:
that
.
typeName
!=
null
)
{
return
false
;
}
if
(
isOptional
!=
that
.
isOptional
)
{
return
false
;
}
if
(
cardinality
!=
null
?
!
cardinality
.
equals
(
that
.
cardinality
)
:
that
.
cardinality
!=
null
)
{
return
false
;
}
if
(
valuesMinCount
!=
that
.
valuesMinCount
)
{
return
false
;
}
if
(
valuesMaxCount
!=
that
.
valuesMaxCount
)
{
return
false
;
}
if
(
isUnique
!=
that
.
isUnique
)
{
return
false
;
}
if
(
isIndexable
!=
that
.
isIndexable
)
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
name
!=
null
?
name
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
typeName
!=
null
?
typeName
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
isOptional
?
1
:
0
);
result
=
31
*
result
+
(
cardinality
!=
null
?
cardinality
.
hashCode
()
:
0
);
result
=
31
*
result
+
valuesMinCount
;
result
=
31
*
result
+
valuesMaxCount
;
result
=
31
*
result
+
(
isUnique
?
1
:
0
);
result
=
31
*
result
+
(
isIndexable
?
1
:
0
);
return
result
;
}
@Override
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
}
}
}
intg/src/main/java/org/apache/atlas/type/AtlasArrayType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.lang.reflect.Array
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasStructDef
.
AtlasAttributeDef
.
COUNT_NOT_SET
;
/**
* class that implements behaviour of an array-type.
*/
public
class
AtlasArrayType
extends
AtlasType
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasArrayType
.
class
);
private
final
String
elementTypeName
;
private
final
int
minCount
;
private
final
int
maxCount
;
private
AtlasType
elementType
;
public
AtlasArrayType
(
AtlasType
elementType
)
{
this
(
elementType
,
COUNT_NOT_SET
,
COUNT_NOT_SET
);
}
public
AtlasArrayType
(
AtlasType
elementType
,
int
minCount
,
int
maxCount
)
{
super
(
AtlasBaseTypeDef
.
getArrayTypeName
(
elementType
.
getTypeName
()));
this
.
elementTypeName
=
elementType
.
getTypeName
();
this
.
minCount
=
minCount
;
this
.
maxCount
=
maxCount
;
this
.
elementType
=
elementType
;
}
public
AtlasArrayType
(
String
elementTypeName
)
{
this
(
elementTypeName
,
COUNT_NOT_SET
,
COUNT_NOT_SET
);
}
public
AtlasArrayType
(
String
elementTypeName
,
int
minCount
,
int
maxCount
)
{
super
(
AtlasBaseTypeDef
.
getArrayTypeName
(
elementTypeName
));
this
.
elementTypeName
=
elementTypeName
;
this
.
minCount
=
minCount
;
this
.
maxCount
=
maxCount
;
this
.
elementType
=
null
;
}
public
AtlasArrayType
(
String
elementTypeName
,
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
this
(
elementTypeName
,
COUNT_NOT_SET
,
COUNT_NOT_SET
,
typeRegistry
);
}
public
AtlasArrayType
(
String
elementTypeName
,
int
minCount
,
int
maxCount
,
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
super
(
AtlasBaseTypeDef
.
getArrayTypeName
(
elementTypeName
));
this
.
elementTypeName
=
elementTypeName
;
this
.
minCount
=
minCount
;
this
.
maxCount
=
maxCount
;
this
.
resolveReferences
(
typeRegistry
);
}
@Override
public
void
resolveReferences
(
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
elementType
=
typeRegistry
.
getType
(
elementTypeName
);
if
(
elementType
==
null
)
{
String
msg
=
elementTypeName
+
": unknown element-type for array"
;
LOG
.
error
(
msg
);
throw
new
AtlasBaseException
(
msg
);
}
elementType
.
resolveReferences
(
typeRegistry
);
}
@Override
public
Collection
<?
extends
Object
>
createDefaultValue
()
{
Collection
<
Object
>
ret
=
new
ArrayList
<
Object
>();
ret
.
add
(
elementType
.
createDefaultValue
());
if
(
minCount
!=
COUNT_NOT_SET
)
{
for
(
int
i
=
1
;
i
<
minCount
;
i
++)
{
ret
.
add
(
elementType
.
createDefaultValue
());
}
}
return
ret
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
List
||
obj
instanceof
Set
)
{
Collection
objList
=
(
Collection
)
obj
;
if
(!
isValidElementCount
(
objList
.
size
()))
{
return
false
;
}
for
(
Object
element
:
objList
)
{
if
(!
elementType
.
isValidValue
(
element
))
{
return
false
;
}
}
}
else
if
(
obj
.
getClass
().
isArray
())
{
int
arrayLen
=
Array
.
getLength
(
obj
);
if
(!
isValidElementCount
(
arrayLen
))
{
return
false
;
}
for
(
int
i
=
0
;
i
<
arrayLen
;
i
++)
{
if
(!
elementType
.
isValidValue
(
Array
.
get
(
obj
,
i
)))
{
return
false
;
}
}
}
else
{
return
false
;
// invalid type
}
}
return
true
;
}
@Override
public
Collection
<?
extends
Object
>
getNormalizedValue
(
Object
obj
)
{
if
(
obj
==
null
)
{
return
null
;
}
if
(
obj
instanceof
List
||
obj
instanceof
Set
)
{
List
<
Object
>
ret
=
new
ArrayList
<
Object
>();
Collection
objList
=
(
Collection
)
obj
;
if
(!
isValidElementCount
(
objList
.
size
()))
{
return
null
;
}
for
(
Object
element
:
objList
)
{
if
(
element
!=
null
)
{
Object
normalizedValue
=
elementType
.
getNormalizedValue
(
element
);
if
(
normalizedValue
!=
null
)
{
ret
.
add
(
normalizedValue
);
}
else
{
return
null
;
// invalid element value
}
}
else
{
ret
.
add
(
element
);
}
}
return
ret
;
}
else
if
(
obj
.
getClass
().
isArray
())
{
List
<
Object
>
ret
=
new
ArrayList
<
Object
>();
int
arrayLen
=
Array
.
getLength
(
obj
);
if
(!
isValidElementCount
(
arrayLen
))
{
return
null
;
}
for
(
int
i
=
0
;
i
<
arrayLen
;
i
++)
{
Object
element
=
Array
.
get
(
obj
,
i
);
if
(
element
!=
null
)
{
Object
normalizedValue
=
elementType
.
getNormalizedValue
(
element
);
if
(
normalizedValue
!=
null
)
{
ret
.
add
(
normalizedValue
);
}
else
{
return
null
;
// invalid element value
}
}
else
{
ret
.
add
(
element
);
}
}
return
ret
;
}
return
null
;
}
@Override
public
boolean
validateValue
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
boolean
ret
=
true
;
if
(
obj
!=
null
)
{
if
(
obj
instanceof
List
||
obj
instanceof
Set
)
{
Collection
objList
=
(
Collection
)
obj
;
if
(!
isValidElementCount
(
objList
.
size
()))
{
ret
=
false
;
messages
.
add
(
objName
+
": incorrect number of values. found="
+
objList
.
size
()
+
"; expected: minCount="
+
minCount
+
", maxCount="
+
maxCount
);
}
int
idx
=
0
;
for
(
Object
element
:
objList
)
{
ret
=
elementType
.
validateValue
(
element
,
objName
+
"["
+
idx
+
"]"
,
messages
)
&&
ret
;
idx
++;
}
}
else
if
(
obj
.
getClass
().
isArray
())
{
int
arrayLen
=
Array
.
getLength
(
obj
);
if
(!
isValidElementCount
(
arrayLen
))
{
ret
=
false
;
messages
.
add
(
objName
+
": incorrect number of values. found="
+
arrayLen
+
"; expected: minCount="
+
minCount
+
", maxCount="
+
maxCount
);
}
for
(
int
i
=
0
;
i
<
arrayLen
;
i
++)
{
ret
=
elementType
.
validateValue
(
Array
.
get
(
obj
,
i
),
objName
+
"["
+
i
+
"]"
,
messages
)
&&
ret
;
}
}
else
{
ret
=
false
;
messages
.
add
(
objName
+
"="
+
obj
+
": invalid value for type "
+
getTypeName
());
}
}
return
ret
;
}
private
boolean
isValidElementCount
(
int
count
)
{
if
(
minCount
!=
COUNT_NOT_SET
)
{
if
(
count
<
minCount
)
{
return
false
;
}
}
if
(
maxCount
!=
COUNT_NOT_SET
)
{
if
(
count
>
maxCount
)
{
return
false
;
}
}
return
true
;
}
}
intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
0 → 100644
View file @
698a5652
/**
* 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
.
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.instance.AtlasObjectId
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.commons.lang.StringUtils
;
/**
* Built-in types in Atlas.
*/
public
class
AtlasBuiltInTypes
{
/**
* class that implements behaviour of boolean type.
*/
public
static
class
AtlasBooleanType
extends
AtlasType
{
private
static
final
Boolean
DEFAULT_VALUE
=
Boolean
.
FALSE
;
public
AtlasBooleanType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BOOLEAN
);
}
@Override
public
Boolean
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
return
true
;
}
@Override
public
Boolean
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Boolean
)
{
return
(
Boolean
)
obj
;
}
else
{
return
Boolean
.
valueOf
(
obj
.
toString
());
}
}
return
null
;
}
}
/**
* class that implements behaviour of byte type.
*/
public
static
class
AtlasByteType
extends
AtlasType
{
private
static
final
Byte
DEFAULT_VALUE
=
new
Byte
((
byte
)
0
);
public
AtlasByteType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BYTE
);
}
@Override
public
Byte
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
Byte
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Byte
)
{
return
(
Byte
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
((
Number
)
obj
).
byteValue
();
}
else
{
String
strValue
=
obj
.
toString
();
if
(
StringUtils
.
isNotEmpty
(
strValue
))
{
return
Byte
.
valueOf
(
strValue
);
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of short type.
*/
public
static
class
AtlasShortType
extends
AtlasType
{
private
static
final
Short
DEFAULT_VALUE
=
new
Short
((
short
)
0
);
public
AtlasShortType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_SHORT
);
}
@Override
public
Short
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
Short
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Short
)
{
return
(
Short
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
((
Number
)
obj
).
shortValue
();
}
else
{
try
{
return
Short
.
valueOf
(
obj
.
toString
());
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of integer type.
*/
public
static
class
AtlasIntType
extends
AtlasType
{
private
static
final
Integer
DEFAULT_VALUE
=
new
Integer
(
0
);
public
AtlasIntType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
);
}
@Override
public
Integer
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
Integer
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Integer
)
{
return
(
Integer
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
((
Number
)
obj
).
intValue
();
}
else
{
try
{
return
Integer
.
valueOf
(
obj
.
toString
());
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of long type.
*/
public
static
class
AtlasLongType
extends
AtlasType
{
private
static
final
Long
DEFAULT_VALUE
=
new
Long
(
0
);
public
AtlasLongType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_LONG
);
}
@Override
public
Long
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
Long
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Long
)
{
return
(
Long
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
((
Number
)
obj
).
longValue
();
}
else
{
try
{
return
Long
.
valueOf
(
obj
.
toString
());
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of float type.
*/
public
static
class
AtlasFloatType
extends
AtlasType
{
private
static
final
Float
DEFAULT_VALUE
=
new
Float
(
0
);
public
AtlasFloatType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_FLOAT
);
}
@Override
public
Float
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
Float
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Float
)
{
return
(
Float
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
((
Number
)
obj
).
floatValue
();
}
else
{
try
{
return
Float
.
valueOf
(
obj
.
toString
());
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of double type.
*/
public
static
class
AtlasDoubleType
extends
AtlasType
{
private
static
final
Double
DEFAULT_VALUE
=
new
Double
(
0
);
public
AtlasDoubleType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_DOUBLE
);
}
@Override
public
Double
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
Double
getNormalizedValue
(
Object
obj
)
{
Double
ret
;
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Double
)
{
return
(
Double
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
((
Number
)
obj
).
doubleValue
();
}
else
{
try
{
return
Double
.
valueOf
(
obj
.
toString
());
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of Java BigInteger type.
*/
public
static
class
AtlasBigIntegerType
extends
AtlasType
{
private
static
final
BigInteger
DEFAULT_VALUE
=
BigInteger
.
ZERO
;
public
AtlasBigIntegerType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
);
}
@Override
public
BigInteger
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
BigInteger
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
BigInteger
)
{
return
(
BigInteger
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
BigInteger
.
valueOf
(((
Number
)
obj
).
longValue
());
}
else
{
try
{
return
new
BigInteger
(
obj
.
toString
());
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of Java BigDecimal type.
*/
public
static
class
AtlasBigDecimalType
extends
AtlasType
{
private
static
final
BigDecimal
DEFAULT_VALUE
=
BigDecimal
.
ZERO
;
public
AtlasBigDecimalType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGDECIMAL
);
}
@Override
public
BigDecimal
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
BigDecimal
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
BigDecimal
)
{
return
(
BigDecimal
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
BigDecimal
.
valueOf
(((
Number
)
obj
).
longValue
());
}
else
{
try
{
return
new
BigDecimal
(
obj
.
toString
());
}
catch
(
NumberFormatException
excp
)
{
// ignore
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of Date type.
*/
public
static
class
AtlasDateType
extends
AtlasType
{
private
static
final
Date
DEFAULT_VALUE
=
new
Date
(
0
);
public
AtlasDateType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_DATE
);
}
@Override
public
Date
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
Date
||
obj
instanceof
Number
)
{
return
true
;
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
Date
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Date
)
{
return
(
Date
)
obj
;
}
else
if
(
obj
instanceof
Number
)
{
return
new
Date
(((
Number
)
obj
).
longValue
());
}
else
{
try
{
return
AtlasBaseTypeDef
.
DATE_FORMATTER
.
parse
(
obj
.
toString
());
}
catch
(
ParseException
excp
)
{
try
{
// try to read it as a number
long
longDate
=
Long
.
valueOf
(
obj
.
toString
());
return
new
Date
(
longDate
);
}
catch
(
NumberFormatException
e
)
{
// ignore
}
}
}
}
return
null
;
}
}
/**
* class that implements behaviour of String type.
*/
public
static
class
AtlasStringType
extends
AtlasType
{
private
static
final
String
DEFAULT_VALUE
=
""
;
public
AtlasStringType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
);
}
@Override
public
String
createDefaultValue
()
{
return
DEFAULT_VALUE
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
return
true
;
}
@Override
public
String
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
return
obj
.
toString
();
}
return
null
;
}
}
/**
* class that implements behaviour of Atlas object-id type.
*/
public
static
class
AtlasObjectIdType
extends
AtlasType
{
public
AtlasObjectIdType
()
{
super
(
AtlasBaseTypeDef
.
ATLAS_TYPE_OBJECT_ID
);
}
@Override
public
AtlasObjectId
createDefaultValue
()
{
return
new
AtlasObjectId
(
AtlasBaseTypeDef
.
ATLAS_TYPE_ASSET
,
"test"
);
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
==
null
||
obj
instanceof
AtlasObjectId
)
{
return
true
;
}
else
if
(
obj
instanceof
Map
)
{
Map
map
=
(
Map
)
obj
;
return
map
.
containsKey
(
AtlasObjectId
.
KEY_TYPENAME
)
&&
map
.
containsKey
(
AtlasObjectId
.
KEY_GUID
);
}
return
getNormalizedValue
(
obj
)
!=
null
;
}
@Override
public
AtlasObjectId
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
AtlasObjectId
)
{
return
(
AtlasObjectId
)
obj
;
}
else
if
(
obj
instanceof
Map
)
{
Map
map
=
(
Map
)
obj
;
if
(
map
.
containsKey
(
AtlasObjectId
.
KEY_TYPENAME
)
&&
map
.
containsKey
(
AtlasObjectId
.
KEY_GUID
))
{
return
new
AtlasObjectId
(
map
);
}
}
}
return
null
;
}
}
}
intg/src/main/java/org/apache/atlas/type/AtlasClassificationType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.commons.collections.CollectionUtils
;
/**
* class that implements behaviour of a classification-type.
*/
public
class
AtlasClassificationType
extends
AtlasStructType
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasClassificationType
.
class
);
private
final
AtlasClassificationDef
classificationDef
;
private
List
<
AtlasClassificationType
>
superTypes
=
Collections
.
emptyList
();
private
Set
<
String
>
allSuperTypes
=
Collections
.
emptySet
();
public
AtlasClassificationType
(
AtlasClassificationDef
classificationDef
)
{
super
(
classificationDef
);
this
.
classificationDef
=
classificationDef
;
}
public
AtlasClassificationType
(
AtlasClassificationDef
classificationDef
,
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
super
(
classificationDef
);
this
.
classificationDef
=
classificationDef
;
resolveReferences
(
typeRegistry
);
}
@Override
public
void
resolveReferences
(
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
super
.
resolveReferences
(
typeRegistry
);
List
<
AtlasClassificationType
>
s
=
new
ArrayList
<
AtlasClassificationType
>();
Set
<
String
>
allS
=
new
HashSet
<
String
>();
for
(
String
superTypeName
:
classificationDef
.
getSuperTypes
())
{
AtlasType
superType
=
typeRegistry
.
getType
(
superTypeName
);
if
(
superType
!=
null
&&
superType
instanceof
AtlasClassificationType
)
{
AtlasClassificationType
superClassificationType
=
(
AtlasClassificationType
)
superType
;
superClassificationType
.
resolveReferences
(
typeRegistry
);
s
.
add
(
superClassificationType
);
allS
.
add
(
superTypeName
);
if
(
CollectionUtils
.
isNotEmpty
(
superClassificationType
.
getAllSuperTypes
()))
{
allS
.
addAll
(
superClassificationType
.
getAllSuperTypes
());
}
}
else
{
String
msg
=
superTypeName
+
((
superType
==
null
)
?
": unknown"
:
": incompatible"
);
msg
+=
(
" supertype in classification "
+
classificationDef
.
getName
());
LOG
.
error
(
msg
);
throw
new
AtlasBaseException
(
msg
);
}
}
this
.
superTypes
=
Collections
.
unmodifiableList
(
s
);
this
.
allSuperTypes
=
allS
;
}
public
Set
<
String
>
getSuperTypes
()
{
return
classificationDef
.
getSuperTypes
();
}
public
Set
<
String
>
getAllSuperTypes
()
{
return
allSuperTypes
;
}
public
boolean
isSuperTypeOf
(
AtlasClassificationType
classificationType
)
{
return
classificationType
!=
null
?
classificationType
.
getAllSuperTypes
().
contains
(
this
.
getTypeName
())
:
false
;
}
public
boolean
isSubTypeOf
(
AtlasClassificationType
classificationType
)
{
return
classificationType
!=
null
?
allSuperTypes
.
contains
(
classificationType
.
getTypeName
())
:
false
;
}
@Override
public
AtlasClassification
createDefaultValue
()
{
AtlasClassification
ret
=
new
AtlasClassification
(
classificationDef
.
getName
());
populateDefaultValues
(
ret
);
return
ret
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasClassificationType
superType
:
superTypes
)
{
if
(!
superType
.
isValidValue
(
obj
))
{
return
false
;
}
}
return
super
.
isValidValue
(
obj
);
}
return
true
;
}
@Override
public
Object
getNormalizedValue
(
Object
obj
)
{
Object
ret
=
null
;
if
(
obj
!=
null
)
{
if
(
isValidValue
(
obj
))
{
if
(
obj
instanceof
AtlasClassification
)
{
normalizeAttributeValues
((
AtlasClassification
)
obj
);
ret
=
obj
;
}
else
if
(
obj
instanceof
Map
)
{
normalizeAttributeValues
((
Map
)
obj
);
ret
=
obj
;
}
}
}
return
ret
;
}
@Override
public
boolean
validateValue
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
boolean
ret
=
true
;
if
(
obj
!=
null
)
{
for
(
AtlasClassificationType
superType
:
superTypes
)
{
ret
=
superType
.
validateValue
(
obj
,
objName
,
messages
)
&&
ret
;
}
ret
=
super
.
validateValue
(
obj
,
objName
,
messages
)
&&
ret
;
}
return
ret
;
}
public
void
normalizeAttributeValues
(
AtlasClassification
classification
)
{
if
(
classification
!=
null
)
{
for
(
AtlasClassificationType
superType
:
superTypes
)
{
superType
.
normalizeAttributeValues
(
classification
);
}
super
.
normalizeAttributeValues
(
classification
);
}
}
@Override
public
void
normalizeAttributeValues
(
Map
<
String
,
Object
>
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasClassificationType
superType
:
superTypes
)
{
superType
.
normalizeAttributeValues
(
obj
);
}
super
.
normalizeAttributeValues
(
obj
);
}
}
public
void
populateDefaultValues
(
AtlasClassification
classification
)
{
if
(
classification
!=
null
)
{
for
(
AtlasClassificationType
superType
:
superTypes
)
{
superType
.
populateDefaultValues
(
classification
);
}
super
.
populateDefaultValues
(
classification
);
}
}
}
intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* class that implements behaviour of an entity-type.
*/
public
class
AtlasEntityType
extends
AtlasStructType
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasEntityType
.
class
);
private
final
AtlasEntityDef
entityDef
;
private
List
<
AtlasEntityType
>
superTypes
=
Collections
.
emptyList
();
private
Set
<
String
>
allSuperTypes
=
Collections
.
emptySet
();
public
AtlasEntityType
(
AtlasEntityDef
entityDef
)
{
super
(
entityDef
);
this
.
entityDef
=
entityDef
;
}
public
AtlasEntityType
(
AtlasEntityDef
entityDef
,
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
super
(
entityDef
);
this
.
entityDef
=
entityDef
;
resolveReferences
(
typeRegistry
);
}
@Override
public
void
resolveReferences
(
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
super
.
resolveReferences
(
typeRegistry
);
List
<
AtlasEntityType
>
s
=
new
ArrayList
<
AtlasEntityType
>();
Set
<
String
>
allS
=
new
HashSet
<
String
>();
for
(
String
superTypeName
:
entityDef
.
getSuperTypes
())
{
AtlasType
superType
=
typeRegistry
.
getType
(
superTypeName
);
if
(
superType
!=
null
&&
superType
instanceof
AtlasEntityType
)
{
AtlasEntityType
superEntityType
=
(
AtlasEntityType
)
superType
;
superEntityType
.
resolveReferences
(
typeRegistry
);
s
.
add
(
superEntityType
);
allS
.
add
(
superTypeName
);
if
(
CollectionUtils
.
isNotEmpty
(
superEntityType
.
getAllSuperTypes
()))
{
allS
.
addAll
(
superEntityType
.
getAllSuperTypes
());
}
}
else
{
String
msg
=
superTypeName
+
((
superType
==
null
)
?
": unknown"
:
": incompatible"
);
msg
+=
(
" supertype in entity "
+
entityDef
.
getName
());
LOG
.
error
(
msg
);
throw
new
AtlasBaseException
(
msg
);
}
}
this
.
superTypes
=
Collections
.
unmodifiableList
(
s
);
this
.
allSuperTypes
=
Collections
.
unmodifiableSet
(
allS
);
}
public
Set
<
String
>
getSuperTypes
()
{
return
entityDef
.
getSuperTypes
();
}
public
Set
<
String
>
getAllSuperTypes
()
{
return
allSuperTypes
;
}
public
boolean
isSuperTypeOf
(
AtlasEntityType
entityType
)
{
return
entityType
!=
null
?
entityType
.
getAllSuperTypes
().
contains
(
this
.
getTypeName
())
:
false
;
}
public
boolean
isSubTypeOf
(
AtlasEntityType
entityType
)
{
return
entityType
!=
null
?
allSuperTypes
.
contains
(
entityType
.
getTypeName
())
:
false
;
}
@Override
public
AtlasEntity
createDefaultValue
()
{
AtlasEntity
ret
=
new
AtlasEntity
(
entityDef
.
getName
());
populateDefaultValues
(
ret
);
return
ret
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasEntityType
superType
:
superTypes
)
{
if
(!
superType
.
isValidValue
(
obj
))
{
return
false
;
}
}
return
super
.
isValidValue
(
obj
);
}
return
true
;
}
@Override
public
Object
getNormalizedValue
(
Object
obj
)
{
Object
ret
=
null
;
if
(
obj
!=
null
)
{
if
(
isValidValue
(
obj
))
{
if
(
obj
instanceof
AtlasEntity
)
{
normalizeAttributeValues
((
AtlasEntity
)
obj
);
ret
=
obj
;
}
else
if
(
obj
instanceof
Map
)
{
normalizeAttributeValues
((
Map
)
obj
);
ret
=
obj
;
}
}
}
return
ret
;
}
@Override
public
boolean
validateValue
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
boolean
ret
=
true
;
if
(
obj
!=
null
)
{
for
(
AtlasEntityType
superType
:
superTypes
)
{
ret
=
superType
.
validateValue
(
obj
,
objName
,
messages
)
&&
ret
;
}
ret
=
super
.
validateValue
(
obj
,
objName
,
messages
)
&&
ret
;
}
return
ret
;
}
public
void
normalizeAttributeValues
(
AtlasEntity
ent
)
{
if
(
ent
!=
null
)
{
for
(
AtlasEntityType
superType
:
superTypes
)
{
superType
.
normalizeAttributeValues
(
ent
);
}
super
.
normalizeAttributeValues
(
ent
);
}
}
@Override
public
void
normalizeAttributeValues
(
Map
<
String
,
Object
>
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasEntityType
superType
:
superTypes
)
{
superType
.
normalizeAttributeValues
(
obj
);
}
super
.
normalizeAttributeValues
(
obj
);
}
}
public
void
populateDefaultValues
(
AtlasEntity
ent
)
{
if
(
ent
!=
null
)
{
for
(
AtlasEntityType
superType
:
superTypes
)
{
superType
.
populateDefaultValues
(
ent
);
}
super
.
populateDefaultValues
(
ent
);
}
}
}
intg/src/main/java/org/apache/atlas/type/AtlasEnumType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef
;
/**
* class that implements behaviour of an enum-type.
*/
public
class
AtlasEnumType
extends
AtlasType
{
private
final
AtlasEnumDef
enumDef
;
private
final
Map
<
String
,
AtlasEnumElementDef
>
elementDefs
;
private
final
String
defaultValue
;
public
AtlasEnumType
(
AtlasEnumDef
enumDef
)
{
super
(
enumDef
.
getName
());
Map
<
String
,
AtlasEnumElementDef
>
e
=
new
HashMap
<
String
,
AtlasEnumElementDef
>();
for
(
AtlasEnumElementDef
elementDef
:
enumDef
.
getElementDefs
())
{
e
.
put
(
elementDef
.
getValue
().
toLowerCase
(),
elementDef
);
}
String
d
=
enumDef
.
getDefaultValue
();
if
(
d
==
null
)
{
AtlasEnumElementDef
defElem
=
enumDef
.
getElementDefs
().
size
()
>
0
?
enumDef
.
getElementDefs
().
get
(
0
)
:
null
;
if
(
defElem
!=
null
)
{
d
=
defElem
.
getValue
();
}
}
this
.
enumDef
=
enumDef
;
this
.
elementDefs
=
Collections
.
unmodifiableMap
(
e
);
this
.
defaultValue
=
d
;
}
@Override
public
Object
createDefaultValue
()
{
return
defaultValue
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
return
elementDefs
.
containsKey
(
obj
.
toString
().
toLowerCase
());
}
return
true
;
}
@Override
public
Object
getNormalizedValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
AtlasEnumElementDef
elementDef
=
elementDefs
.
get
(
obj
.
toString
().
toLowerCase
());
if
(
elementDef
!=
null
)
{
return
elementDef
.
getValue
();
}
}
return
null
;
}
}
intg/src/main/java/org/apache/atlas/type/AtlasMapType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.*
;
/**
* class that implements behaviour of a map-type.
*/
public
class
AtlasMapType
extends
AtlasType
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasEntityType
.
class
);
private
final
String
keyTypeName
;
private
final
String
valueTypeName
;
private
AtlasType
keyType
;
private
AtlasType
valueType
;
public
AtlasMapType
(
String
keyTypeName
,
String
valueTypeName
)
{
super
(
AtlasBaseTypeDef
.
getMapTypeName
(
keyTypeName
,
valueTypeName
));
this
.
keyTypeName
=
keyTypeName
;
this
.
valueTypeName
=
valueTypeName
;
}
public
AtlasMapType
(
AtlasType
keyType
,
AtlasType
valueType
)
{
super
(
AtlasBaseTypeDef
.
getMapTypeName
(
keyType
.
getTypeName
(),
valueType
.
getTypeName
()));
this
.
keyTypeName
=
keyType
.
getTypeName
();
this
.
valueTypeName
=
valueType
.
getTypeName
();
this
.
keyType
=
keyType
;
this
.
valueType
=
valueType
;
}
public
AtlasMapType
(
String
keyTypeName
,
String
valueTypeName
,
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
super
(
AtlasBaseTypeDef
.
getMapTypeName
(
keyTypeName
,
valueTypeName
));
this
.
keyTypeName
=
keyTypeName
;
this
.
valueTypeName
=
valueTypeName
;
resolveReferences
(
typeRegistry
);
}
@Override
public
void
resolveReferences
(
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
this
.
keyType
=
typeRegistry
.
getType
(
keyTypeName
);
this
.
valueType
=
typeRegistry
.
getType
(
valueTypeName
);
if
(
keyType
==
null
)
{
String
msg
=
keyTypeName
+
": unknown key-type for map"
;
LOG
.
error
(
msg
);
throw
new
AtlasBaseException
(
msg
);
}
if
(
valueType
==
null
)
{
String
msg
=
valueTypeName
+
": unknown value-type for map"
;
LOG
.
error
(
msg
);
throw
new
AtlasBaseException
(
msg
);
}
keyType
.
resolveReferences
(
typeRegistry
);
valueType
.
resolveReferences
(
typeRegistry
);
}
@Override
public
Map
<
Object
,
Object
>
createDefaultValue
()
{
Map
<
Object
,
Object
>
ret
=
new
HashMap
<
Object
,
Object
>();
ret
.
put
(
keyType
.
createDefaultValue
(),
valueType
.
createDefaultValue
());
return
ret
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Map
)
{
Map
<
Object
,
Objects
>
map
=
(
Map
<
Object
,
Objects
>)
obj
;
for
(
Map
.
Entry
e
:
map
.
entrySet
())
{
if
(!
keyType
.
isValidValue
(
e
.
getKey
())
||
!
valueType
.
isValidValue
(
e
.
getValue
()))
{
return
false
;
// invalid key/value
}
}
}
else
{
return
false
;
// invalid type
}
}
return
true
;
}
@Override
public
Map
<
Object
,
Object
>
getNormalizedValue
(
Object
obj
)
{
if
(
obj
==
null
)
{
return
null
;
}
if
(
obj
instanceof
Map
)
{
Map
<
Object
,
Object
>
ret
=
new
HashMap
<
Object
,
Object
>();
Map
<
Object
,
Objects
>
map
=
(
Map
<
Object
,
Objects
>)
obj
;
for
(
Map
.
Entry
e
:
map
.
entrySet
())
{
Object
normalizedKey
=
keyType
.
getNormalizedValue
(
e
.
getKey
());
if
(
normalizedKey
!=
null
)
{
Object
value
=
e
.
getValue
();
if
(
value
!=
null
)
{
Object
normalizedValue
=
valueType
.
getNormalizedValue
(
e
.
getValue
());
if
(
normalizedValue
!=
null
)
{
ret
.
put
(
normalizedKey
,
normalizedValue
);
}
else
{
return
null
;
// invalid value
}
}
else
{
ret
.
put
(
normalizedKey
,
value
);
}
}
else
{
return
null
;
// invalid key
}
}
return
ret
;
}
return
null
;
}
@Override
public
boolean
validateValue
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
boolean
ret
=
true
;
if
(
obj
!=
null
)
{
if
(
obj
instanceof
Map
)
{
Map
<
Object
,
Objects
>
map
=
(
Map
<
Object
,
Objects
>)
obj
;
for
(
Map
.
Entry
e
:
map
.
entrySet
())
{
Object
key
=
e
.
getKey
();
if
(!
keyType
.
isValidValue
(
key
))
{
ret
=
false
;
messages
.
add
(
objName
+
"."
+
key
+
": invalid key for type "
+
getTypeName
());
}
else
{
Object
value
=
e
.
getValue
();
ret
=
valueType
.
validateValue
(
value
,
objName
+
"."
+
key
,
messages
)
&&
ret
;
}
}
}
else
{
ret
=
false
;
messages
.
add
(
objName
+
"="
+
obj
+
": invalid value for type "
+
getTypeName
());
}
}
return
ret
;
}
}
intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.*
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* class that implements behaviour of a struct-type.
*/
public
class
AtlasStructType
extends
AtlasType
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasStructType
.
class
);
private
final
AtlasStructDef
structDef
;
private
Map
<
String
,
AtlasType
>
attrTypes
=
Collections
.
emptyMap
();
public
AtlasStructType
(
AtlasStructDef
structDef
)
{
super
(
structDef
.
getName
());
this
.
structDef
=
structDef
;
}
public
AtlasStructType
(
AtlasStructDef
structDef
,
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
super
(
structDef
.
getName
());
this
.
structDef
=
structDef
;
this
.
resolveReferences
(
typeRegistry
);
}
@Override
public
void
resolveReferences
(
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
Map
<
String
,
AtlasType
>
a
=
new
HashMap
<
String
,
AtlasType
>();
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
AtlasType
attrType
=
typeRegistry
.
getType
(
attributeDef
.
getTypeName
());
if
(
attrType
!=
null
)
{
Cardinality
cardinality
=
attributeDef
.
getCardinality
();
if
(
cardinality
==
Cardinality
.
LIST
||
cardinality
==
Cardinality
.
SET
)
{
attrType
=
new
AtlasArrayType
(
attrType
,
attributeDef
.
getValuesMinCount
(),
attributeDef
.
getValuesMaxCount
());
}
a
.
put
(
attributeDef
.
getName
(),
attrType
);
}
else
{
String
msg
=
attributeDef
.
getTypeName
()
+
": unknown type for attribute "
+
structDef
.
getName
()
+
"."
+
attributeDef
.
getName
();
LOG
.
error
(
msg
);
throw
new
AtlasBaseException
(
msg
);
}
}
this
.
attrTypes
=
Collections
.
unmodifiableMap
(
a
);
}
@Override
public
AtlasStruct
createDefaultValue
()
{
AtlasStruct
ret
=
new
AtlasStruct
(
structDef
.
getName
());
populateDefaultValues
(
ret
);
return
ret
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
if
(
obj
instanceof
AtlasStruct
)
{
AtlasStruct
structObj
=
(
AtlasStruct
)
obj
;
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
if
(!
isAssignableValue
(
structObj
.
getAttribute
(
attributeDef
.
getName
()),
attributeDef
))
{
return
false
;
}
}
}
else
if
(
obj
instanceof
Map
)
{
Map
map
=
(
Map
)
obj
;
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
if
(!
isAssignableValue
(
map
.
get
(
attributeDef
.
getName
()),
attributeDef
))
{
return
false
;
// no value for non-optinal attribute
}
}
}
else
{
return
false
;
// invalid type
}
}
return
true
;
}
@Override
public
Object
getNormalizedValue
(
Object
obj
)
{
Object
ret
=
null
;
if
(
obj
!=
null
)
{
if
(
isValidValue
(
obj
))
{
if
(
obj
instanceof
AtlasStruct
)
{
normalizeAttributeValues
((
AtlasStruct
)
obj
);
ret
=
obj
;
}
else
if
(
obj
instanceof
Map
)
{
normalizeAttributeValues
((
Map
)
obj
);
ret
=
obj
;
}
}
}
return
ret
;
}
@Override
public
boolean
validateValue
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
boolean
ret
=
true
;
if
(
obj
!=
null
)
{
if
(
obj
instanceof
AtlasStruct
)
{
AtlasStruct
structObj
=
(
AtlasStruct
)
obj
;
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
String
attrName
=
attributeDef
.
getName
();
AtlasType
dataType
=
attrTypes
.
get
(
attributeDef
.
getName
());
if
(
dataType
!=
null
)
{
Object
value
=
structObj
.
getAttribute
(
attrName
);
String
fieldName
=
objName
+
"."
+
attrName
;
if
(
value
!=
null
)
{
ret
=
dataType
.
validateValue
(
value
,
fieldName
,
messages
)
&&
ret
;
}
else
if
(!
attributeDef
.
isOptional
())
{
ret
=
false
;
messages
.
add
(
fieldName
+
": mandatory attribute value missing in type "
+
getTypeName
());
}
}
}
}
else
if
(
obj
instanceof
Map
)
{
Map
map
=
(
Map
)
obj
;
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
String
attrName
=
attributeDef
.
getName
();
AtlasType
dataType
=
attrTypes
.
get
(
attributeDef
.
getName
());
if
(
dataType
!=
null
)
{
Object
value
=
map
.
get
(
attrName
);
String
fieldName
=
objName
+
"."
+
attrName
;
if
(
value
!=
null
)
{
ret
=
dataType
.
validateValue
(
value
,
fieldName
,
messages
)
&&
ret
;
}
else
if
(!
attributeDef
.
isOptional
())
{
ret
=
false
;
messages
.
add
(
fieldName
+
": mandatory attribute value missing in type "
+
getTypeName
());
}
}
}
}
else
{
ret
=
false
;
messages
.
add
(
objName
+
"="
+
obj
+
": invalid value for type "
+
getTypeName
());
}
}
return
ret
;
}
public
void
normalizeAttributeValues
(
AtlasStruct
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
String
attributeName
=
attributeDef
.
getName
();
if
(
obj
.
hasAttribute
(
attributeName
))
{
Object
attributeValue
=
getNormalizedValue
(
obj
.
getAttribute
(
attributeName
),
attributeDef
);
obj
.
setAttribute
(
attributeName
,
attributeValue
);
}
else
if
(!
attributeDef
.
isOptional
())
{
obj
.
setAttribute
(
attributeName
,
createDefaultValue
(
attributeDef
));
}
}
}
}
public
void
normalizeAttributeValues
(
Map
<
String
,
Object
>
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
String
attributeName
=
attributeDef
.
getName
();
if
(
obj
.
containsKey
(
attributeName
))
{
Object
attributeValue
=
getNormalizedValue
(
obj
.
get
(
attributeName
),
attributeDef
);
obj
.
put
(
attributeName
,
attributeValue
);
}
else
if
(!
attributeDef
.
isOptional
())
{
obj
.
put
(
attributeName
,
createDefaultValue
(
attributeDef
));
}
}
}
}
public
void
populateDefaultValues
(
AtlasStruct
obj
)
{
if
(
obj
!=
null
)
{
Map
<
String
,
Object
>
attributes
=
obj
.
getAttributes
();
if
(
attributes
==
null
)
{
attributes
=
new
HashMap
<
String
,
Object
>();
}
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
if
(!
attributeDef
.
isOptional
())
{
attributes
.
put
(
attributeDef
.
getName
(),
createDefaultValue
(
attributeDef
));
}
}
obj
.
setAttributes
(
attributes
);
}
}
private
Object
createDefaultValue
(
AtlasAttributeDef
attributeDef
)
{
Object
ret
=
null
;
if
(
attributeDef
!=
null
)
{
AtlasType
dataType
=
attrTypes
.
get
(
attributeDef
.
getName
());
if
(
dataType
!=
null
)
{
ret
=
dataType
.
createDefaultValue
();
}
}
return
ret
;
}
private
boolean
isAssignableValue
(
Object
value
,
AtlasAttributeDef
attributeDef
)
{
boolean
ret
=
true
;
if
(
value
!=
null
)
{
AtlasType
attrType
=
attrTypes
.
get
(
attributeDef
.
getName
());
if
(
attrType
!=
null
)
{
if
(!
attrType
.
isValidValue
(
value
))
{
ret
=
false
;
// invalid value
}
}
}
else
if
(!
attributeDef
.
isOptional
())
{
ret
=
false
;
// mandatory attribute not present
}
return
ret
;
}
private
Object
getNormalizedValue
(
Object
value
,
AtlasAttributeDef
attributeDef
)
{
AtlasType
attrType
=
attrTypes
.
get
(
attributeDef
.
getName
());
if
(
attrType
!=
null
)
{
if
(
value
==
null
)
{
if
(!
attributeDef
.
isOptional
())
{
return
attrType
.
createDefaultValue
();
}
}
else
{
return
attrType
.
getNormalizedValue
(
value
);
}
}
return
null
;
}
}
intg/src/main/java/org/apache/atlas/type/AtlasType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
java.util.List
;
/**
* base class that declares interface for all Atlas types.
*/
public
abstract
class
AtlasType
{
private
static
final
Gson
GSON
=
new
GsonBuilder
().
setDateFormat
(
AtlasBaseTypeDef
.
SERIALIZED_DATE_FORMAT_STR
).
create
();
private
final
String
typeName
;
public
AtlasType
(
String
typeName
)
{
this
.
typeName
=
typeName
;
}
public
void
resolveReferences
(
AtlasTypeRegistry
typeRegistry
)
throws
AtlasBaseException
{
}
public
String
getTypeName
()
{
return
typeName
;
}
public
abstract
Object
createDefaultValue
();
public
abstract
boolean
isValidValue
(
Object
obj
);
public
abstract
Object
getNormalizedValue
(
Object
obj
);
public
boolean
validateValue
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
boolean
ret
=
isValidValue
(
obj
);
if
(!
ret
)
{
messages
.
add
(
objName
+
"="
+
obj
+
": invalid value for type "
+
getTypeName
());
}
return
ret
;
}
public
static
String
toJson
(
Object
obj
)
{
return
GSON
.
toJson
(
obj
);
}
public
static
<
T
>
T
fromJson
(
String
jsonStr
,
Class
<
T
>
type
)
{
return
GSON
.
fromJson
(
jsonStr
,
type
);
}
}
intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.typedef.*
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_ARRAY_PREFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_ARRAY_SUFFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_MAP_PREFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_MAP_SUFFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_MAP_KEY_VAL_SEP
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* registry for all types defined in Atlas.
*/
public
class
AtlasTypeRegistry
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasStructType
.
class
);
private
final
Map
<
String
,
AtlasType
>
allTypes
;
private
final
TypeDefCache
<
AtlasEnumDef
>
enumDefs
;
private
final
TypeDefCache
<
AtlasStructDef
>
structDefs
;
private
final
TypeDefCache
<
AtlasClassificationDef
>
classificationDefs
;
private
final
TypeDefCache
<
AtlasEntityDef
>
entityDefs
;
public
AtlasTypeRegistry
()
{
allTypes
=
new
ConcurrentHashMap
<
String
,
AtlasType
>();
enumDefs
=
new
TypeDefCache
<
AtlasEnumDef
>(
this
);
structDefs
=
new
TypeDefCache
<
AtlasStructDef
>(
this
);
classificationDefs
=
new
TypeDefCache
<
AtlasClassificationDef
>(
this
);
entityDefs
=
new
TypeDefCache
<
AtlasEntityDef
>(
this
);
registerType
(
new
AtlasBuiltInTypes
.
AtlasBooleanType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasByteType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasShortType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasIntType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasLongType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasFloatType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasDoubleType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasBigIntegerType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasBigDecimalType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasDateType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasStringType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasObjectIdType
());
}
public
void
resolveReferences
()
throws
AtlasBaseException
{
for
(
Map
.
Entry
<
String
,
AtlasType
>
e
:
allTypes
.
entrySet
())
{
e
.
getValue
().
resolveReferences
(
this
);
}
}
public
Collection
<
String
>
getAllTypeNames
()
{
return
Collections
.
unmodifiableSet
(
allTypes
.
keySet
());
}
public
AtlasType
getType
(
String
typeName
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.getType("
+
typeName
+
")"
);
}
AtlasType
ret
=
allTypes
.
get
(
typeName
);
if
(
ret
==
null
)
{
try
{
if
(
typeName
.
startsWith
(
ATLAS_TYPE_ARRAY_PREFIX
)
&&
typeName
.
endsWith
(
ATLAS_TYPE_ARRAY_SUFFIX
))
{
int
startIdx
=
ATLAS_TYPE_ARRAY_PREFIX
.
length
();
int
endIdx
=
typeName
.
length
()
-
ATLAS_TYPE_ARRAY_SUFFIX
.
length
();
String
elementTypeName
=
typeName
.
substring
(
startIdx
,
endIdx
);
ret
=
new
AtlasArrayType
(
elementTypeName
,
this
);
}
else
if
(
typeName
.
startsWith
(
ATLAS_TYPE_MAP_PREFIX
)
&&
typeName
.
endsWith
(
ATLAS_TYPE_MAP_SUFFIX
))
{
int
startIdx
=
ATLAS_TYPE_MAP_PREFIX
.
length
();
int
endIdx
=
typeName
.
length
()
-
ATLAS_TYPE_MAP_SUFFIX
.
length
();
String
[]
keyValueTypes
=
typeName
.
substring
(
startIdx
,
endIdx
).
split
(
ATLAS_TYPE_MAP_KEY_VAL_SEP
,
2
);
String
keyTypeName
=
keyValueTypes
.
length
>
0
?
keyValueTypes
[
0
]
:
null
;
String
valueTypeName
=
keyValueTypes
.
length
>
1
?
keyValueTypes
[
1
]
:
null
;
ret
=
new
AtlasMapType
(
keyTypeName
,
valueTypeName
,
this
);
}
}
catch
(
AtlasBaseException
excp
)
{
LOG
.
warn
(
"failed to instantiate type for "
+
typeName
,
excp
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.getType("
+
typeName
+
")"
);
}
return
ret
;
}
public
void
addEnumDef
(
AtlasEnumDef
enumDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addEnumDef("
+
enumDef
+
")"
);
}
enumDefs
.
addType
(
enumDef
,
new
AtlasEnumType
(
enumDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addEnumDef("
+
enumDef
+
")"
);
}
}
public
Collection
<
AtlasEnumDef
>
getAllEnumDefs
()
{
return
enumDefs
.
getAll
();
}
public
AtlasEnumDef
getEnumDefByGuid
(
String
guid
)
{
return
enumDefs
.
getTypeDefByGuid
(
guid
);
}
public
AtlasEnumDef
getEnumDefByName
(
String
name
)
{
return
enumDefs
.
getTypeDefByName
(
name
);
}
public
void
removeEnumDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEnumDefByGuid("
+
guid
+
")"
);
}
AtlasEnumDef
enumDef
=
enumDefs
.
getTypeDefByGuid
(
guid
);
if
(
enumDef
!=
null
)
{
enumDefs
.
removeTypeDefByGuid
(
guid
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEnumDefByGuid("
+
guid
+
")"
);
}
}
public
void
removeEnumDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEnumDefByName("
+
name
+
")"
);
}
AtlasEnumDef
enumDef
=
enumDefs
.
getTypeDefByName
(
name
);
if
(
enumDef
!=
null
)
{
enumDefs
.
removeTypeDefByName
(
name
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEnumDefByName("
+
name
+
")"
);
}
}
public
void
addStructDefWithNoRefResolve
(
AtlasStructDef
structDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addStructDefWithNoRefResolve("
+
structDef
+
")"
);
}
structDefs
.
addType
(
structDef
,
new
AtlasStructType
(
structDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addStructDefWithNoRefResolve("
+
structDef
+
")"
);
}
}
public
void
addStructDef
(
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addStructDef("
+
structDef
+
")"
);
}
structDefs
.
addType
(
structDef
,
new
AtlasStructType
(
structDef
,
this
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addStructDef("
+
structDef
+
")"
);
}
}
public
Collection
<
AtlasStructDef
>
getAllStructDefs
()
{
return
structDefs
.
getAll
();
}
public
AtlasStructDef
getStructDefByGuid
(
String
guid
)
{
return
structDefs
.
getTypeDefByGuid
(
guid
);
}
public
AtlasStructDef
getStructDefByName
(
String
name
)
{
return
structDefs
.
getTypeDefByName
(
name
);
}
public
void
removeStructDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeStructDefByGuid("
+
guid
+
")"
);
}
AtlasStructDef
structDef
=
structDefs
.
getTypeDefByGuid
(
guid
);
if
(
structDef
!=
null
)
{
structDefs
.
removeTypeDefByGuid
(
guid
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeStructDefByGuid("
+
guid
+
")"
);
}
}
public
void
removeStructDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeStructDefByName("
+
name
+
")"
);
}
AtlasStructDef
structDef
=
structDefs
.
getTypeDefByName
(
name
);
if
(
structDef
!=
null
)
{
structDefs
.
removeTypeDefByName
(
name
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeStructDefByName("
+
name
+
")"
);
}
}
public
void
addClassificationDefWithNoRefResolve
(
AtlasClassificationDef
classificationDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addClassificationDefWithNoRefResolve("
+
classificationDef
+
")"
);
}
classificationDefs
.
addType
(
classificationDef
,
new
AtlasClassificationType
(
classificationDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addClassificationDefWithNoRefResolve("
+
classificationDef
+
")"
);
}
}
public
void
addClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addClassificationDef("
+
classificationDef
+
")"
);
}
classificationDefs
.
addType
(
classificationDef
,
new
AtlasClassificationType
(
classificationDef
,
this
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addClassificationDef("
+
classificationDef
+
")"
);
}
}
public
Collection
<
AtlasClassificationDef
>
getAllClassificationDefs
()
{
return
classificationDefs
.
getAll
();
}
public
AtlasClassificationDef
getClassificationDefByGuid
(
String
guid
)
{
return
classificationDefs
.
getTypeDefByGuid
(
guid
);
}
public
AtlasClassificationDef
getClassificationDefByName
(
String
name
)
{
return
classificationDefs
.
getTypeDefByName
(
name
);
}
public
void
removeClassificationDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeClassificationDefByGuid("
+
guid
+
")"
);
}
AtlasClassificationDef
classificationDef
=
classificationDefs
.
getTypeDefByGuid
(
guid
);
if
(
classificationDef
!=
null
)
{
classificationDefs
.
removeTypeDefByGuid
(
guid
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeClassificationDefByGuid("
+
guid
+
")"
);
}
}
public
void
removeClassificationDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeClassificationDefByName("
+
name
+
")"
);
}
AtlasClassificationDef
classificationDef
=
classificationDefs
.
getTypeDefByName
(
name
);
if
(
classificationDef
!=
null
)
{
classificationDefs
.
removeTypeDefByName
(
name
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeClassificationDefByName("
+
name
+
")"
);
}
}
public
void
addEntityDefWithNoRefResolve
(
AtlasEntityDef
entityDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addEntityDefWithNoRefResolve("
+
entityDef
+
")"
);
}
entityDefs
.
addType
(
entityDef
,
new
AtlasEntityType
(
entityDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addEntityDefWithNoRefResolve("
+
entityDef
+
")"
);
}
}
public
void
addEntityDef
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addEntityDef("
+
entityDef
+
")"
);
}
entityDefs
.
addType
(
entityDef
,
new
AtlasEntityType
(
entityDef
,
this
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addEntityDef("
+
entityDef
+
")"
);
}
}
public
Collection
<
AtlasEntityDef
>
getAllEntityDefs
()
{
return
entityDefs
.
getAll
();
}
public
AtlasEntityDef
getEntityDefByGuid
(
String
guid
)
{
return
entityDefs
.
getTypeDefByGuid
(
guid
);
}
public
AtlasEntityDef
getEntityDefByName
(
String
name
)
{
return
entityDefs
.
getTypeDefByName
(
name
);
}
public
void
removeEntityDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEntityDefByGuid("
+
guid
+
")"
);
}
AtlasEntityDef
entityDef
=
entityDefs
.
getTypeDefByGuid
(
guid
);
if
(
entityDef
!=
null
)
{
entityDefs
.
removeTypeDefByGuid
(
guid
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEntityDefByGuid("
+
guid
+
")"
);
}
}
public
void
removeEntityDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEntityDefByName("
+
name
+
")"
);
}
AtlasEntityDef
entityDef
=
entityDefs
.
getTypeDefByName
(
name
);
if
(
entityDef
!=
null
)
{
entityDefs
.
removeTypeDefByName
(
name
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEntityDefByName("
+
name
+
")"
);
}
}
private
void
registerType
(
AtlasType
dataType
)
{
allTypes
.
put
(
dataType
.
getTypeName
(),
dataType
);
}
private
void
unregisterType
(
AtlasType
dataType
)
{
allTypes
.
remove
(
dataType
.
getTypeName
());
}
private
void
unregisterTypeByName
(
String
typeName
)
{
allTypes
.
remove
(
typeName
);
}
class
TypeDefCache
<
T
extends
AtlasBaseTypeDef
>
{
private
final
AtlasTypeRegistry
typeRegistry
;
private
final
Map
<
String
,
T
>
typeDefGuidMap
=
new
ConcurrentHashMap
<
String
,
T
>();
private
final
Map
<
String
,
T
>
typeDefNameMap
=
new
ConcurrentHashMap
<
String
,
T
>();
public
TypeDefCache
(
AtlasTypeRegistry
typeRegistry
)
{
this
.
typeRegistry
=
typeRegistry
;
}
public
void
addType
(
T
typeDef
,
AtlasType
type
)
{
if
(
type
!=
null
)
{
if
(
StringUtils
.
isNotEmpty
(
typeDef
.
getGuid
()))
{
typeDefGuidMap
.
put
(
typeDef
.
getGuid
(),
typeDef
);
}
if
(
StringUtils
.
isNotEmpty
(
typeDef
.
getName
()))
{
typeDefNameMap
.
put
(
typeDef
.
getName
(),
typeDef
);
}
typeRegistry
.
registerType
(
type
);
}
}
public
Collection
<
T
>
getAll
()
{
return
Collections
.
unmodifiableCollection
(
typeDefNameMap
.
values
());
}
public
T
getTypeDefByGuid
(
String
guid
)
{
T
ret
=
guid
!=
null
?
typeDefGuidMap
.
get
(
guid
)
:
null
;
return
ret
;
}
public
T
getTypeDefByName
(
String
name
)
{
T
ret
=
name
!=
null
?
typeDefNameMap
.
get
(
name
)
:
null
;
return
ret
;
}
public
void
removeTypeDefByGuid
(
String
guid
)
{
T
typeDef
=
guid
!=
null
?
typeDefGuidMap
.
remove
(
guid
)
:
null
;
if
(
typeDef
!=
null
)
{
if
(
StringUtils
.
isNotEmpty
(
typeDef
.
getName
()))
{
typeDefNameMap
.
remove
(
typeDef
.
getName
());
typeRegistry
.
unregisterTypeByName
(
typeDef
.
getName
());
}
}
}
public
void
removeTypeDefByName
(
String
name
)
{
T
typeDef
=
name
!=
null
?
typeDefNameMap
.
get
(
name
)
:
null
;
if
(
typeDef
!=
null
)
{
if
(
StringUtils
.
isNotEmpty
(
typeDef
.
getGuid
()))
{
typeDefGuidMap
.
remove
(
typeDef
.
getGuid
());
typeRegistry
.
unregisterTypeByName
(
typeDef
.
getName
());
}
}
}
}
}
intg/src/test/java/org/apache/atlas/model/ModelTestUtil.java
0 → 100644
View file @
698a5652
/**
* 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
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.ThreadLocalRandom
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_BUILTIN_TYPES
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_PRIMITIVE_TYPES
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasStructType
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
final
class
ModelTestUtil
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ModelTestUtil
.
class
);
private
static
final
String
PREFIX_ENUM_DEF
=
"testEnumDef-"
;
private
static
final
String
PREFIX_STRUCT_DEF
=
"testStructDef-"
;
private
static
final
String
PREFIX_ENTITY_DEF
=
"testEntityDef-"
;
private
static
final
String
PREFIX_CLASSIFICATION_DEF
=
"testClassificationDef-"
;
private
static
final
String
PREFIX_ATTRIBUTE_NAME
=
"attr-"
;
private
static
final
String
PREFIX_STRUCT
=
"testStruct-"
;
private
static
final
String
PREFIX_ENTITY
=
"testEntity-"
;
private
static
final
String
PREFIX_CLASSIFICATION
=
"testClassification-"
;
private
static
final
int
MAX_ENUM_ELEMENT_COUNT
=
30
;
private
static
final
AtomicInteger
IDX_ENUM_DEF
=
new
AtomicInteger
();
private
static
final
AtomicInteger
IDX_ENTITY_DEF
=
new
AtomicInteger
();
private
static
final
AtomicInteger
IDX_CLASSIFICATION_DEF
=
new
AtomicInteger
();
private
static
final
AtomicInteger
IDX_STRUCT_DEF
=
new
AtomicInteger
();
private
static
final
AtomicInteger
IDX_CLASSIFICATION
=
new
AtomicInteger
();
private
static
final
AtomicInteger
IDX_ENTITY
=
new
AtomicInteger
();
private
static
final
AtomicInteger
IDX_STRUCT
=
new
AtomicInteger
();
private
static
final
AtlasTypeRegistry
TYPE_REGISTRY
;
private
static
final
AtlasEnumDef
ENUM_DEF
;
private
static
final
AtlasEnumDef
ENUM_DEF_WITH_NO_DEFAULT
;
private
static
final
AtlasStructDef
STRUCT_DEF
;
private
static
final
AtlasEntityDef
ENTITY_DEF
;
private
static
final
AtlasEntityDef
ENTITY_DEF_WITH_SUPER_TYPE
;
private
static
final
AtlasEntityDef
ENTITY_DEF_WITH_SUPER_TYPES
;
private
static
final
AtlasClassificationDef
CLASSIFICATION_DEF
;
private
static
final
AtlasClassificationDef
CLASSIFICATION_DEF_WITH_SUPER_TYPE
;
private
static
final
AtlasClassificationDef
CLASSIFICATION_DEF_WITH_SUPER_TYPES
;
static
{
TYPE_REGISTRY
=
new
AtlasTypeRegistry
();
ENUM_DEF
=
newEnumDef
(
true
);
ENUM_DEF_WITH_NO_DEFAULT
=
newEnumDef
(
false
);
STRUCT_DEF
=
newStructDef
();
ENTITY_DEF
=
newEntityDef
();
ENTITY_DEF_WITH_SUPER_TYPE
=
newEntityDef
(
new
AtlasEntityDef
[]
{
ENTITY_DEF
});
ENTITY_DEF_WITH_SUPER_TYPES
=
newEntityDef
(
new
AtlasEntityDef
[]
{
ENTITY_DEF
,
ENTITY_DEF_WITH_SUPER_TYPE
});
CLASSIFICATION_DEF
=
newClassificationDef
();
CLASSIFICATION_DEF_WITH_SUPER_TYPE
=
newClassificationDef
(
new
AtlasClassificationDef
[]
{
CLASSIFICATION_DEF
});
CLASSIFICATION_DEF_WITH_SUPER_TYPES
=
newClassificationDef
(
new
AtlasClassificationDef
[]
{
CLASSIFICATION_DEF
,
CLASSIFICATION_DEF_WITH_SUPER_TYPE
});
}
private
ModelTestUtil
()
{
}
public
static
AtlasTypeRegistry
getTypesRegistry
()
{
return
TYPE_REGISTRY
;
}
public
static
AtlasEnumDef
getEnumDef
()
{
return
ENUM_DEF
;
}
public
static
AtlasEnumDef
getEnumDefWithNoDefault
()
{
return
ENUM_DEF_WITH_NO_DEFAULT
;
}
public
static
AtlasStructDef
getStructDef
()
{
return
STRUCT_DEF
;
}
public
static
AtlasEntityDef
getEntityDef
()
{
return
ENTITY_DEF
;
}
public
static
AtlasEntityDef
getEntityDefWithSuperType
()
{
return
ENTITY_DEF_WITH_SUPER_TYPE
;
}
public
static
AtlasEntityDef
getEntityDefWithSuperTypes
()
{
return
ENTITY_DEF_WITH_SUPER_TYPES
;
}
public
static
AtlasClassificationDef
getClassificationDef
()
{
return
CLASSIFICATION_DEF
;
}
public
static
AtlasClassificationDef
getClassificationDefWithSuperType
()
{
return
CLASSIFICATION_DEF_WITH_SUPER_TYPE
;
}
public
static
AtlasClassificationDef
getClassificationDefWithSuperTypes
()
{
return
CLASSIFICATION_DEF_WITH_SUPER_TYPES
;
}
public
static
AtlasEnumDef
newEnumDef
()
{
return
newEnumDef
(
getTypesRegistry
(),
true
);
}
public
static
AtlasEnumDef
newEnumDef
(
boolean
hasDefaultValue
)
{
return
newEnumDef
(
getTypesRegistry
(),
hasDefaultValue
);
}
public
static
AtlasEnumDef
newEnumDef
(
AtlasTypeRegistry
typesRegistry
)
{
return
newEnumDef
(
getTypesRegistry
(),
true
);
}
public
static
AtlasEnumDef
newEnumDef
(
AtlasTypeRegistry
typesRegistry
,
boolean
hasDefaultValue
)
{
int
enumDefIdx
=
IDX_ENUM_DEF
.
getAndIncrement
();
AtlasEnumDef
ret
=
new
AtlasEnumDef
();
ret
.
setName
(
PREFIX_ENUM_DEF
+
enumDefIdx
);
ret
.
setDescription
(
ret
.
getName
());
int
numElements
=
ThreadLocalRandom
.
current
().
nextInt
(
1
,
MAX_ENUM_ELEMENT_COUNT
);
for
(
int
i
=
0
;
i
<
numElements
;
i
++)
{
String
elementName
=
"element-"
+
i
;
ret
.
addElement
(
new
AtlasEnumElementDef
(
elementName
,
elementName
.
toUpperCase
(),
i
));
}
if
(
hasDefaultValue
)
{
int
idxDefault
=
ThreadLocalRandom
.
current
().
nextInt
(
0
,
numElements
);
ret
.
setDefaultValue
(
ret
.
getElementDefs
().
get
(
idxDefault
).
getValue
());
}
typesRegistry
.
addEnumDef
(
ret
);
return
ret
;
}
public
static
AtlasStructDef
newStructDef
()
{
return
newStructDef
(
getTypesRegistry
());
}
public
static
AtlasStructDef
newStructDef
(
AtlasTypeRegistry
typesRegistry
)
{
int
structDefIdx
=
IDX_STRUCT_DEF
.
getAndIncrement
();
AtlasStructDef
ret
=
new
AtlasStructDef
();
ret
.
setName
(
PREFIX_STRUCT_DEF
+
structDefIdx
);
ret
.
setDescription
(
ret
.
getName
());
ret
.
setAttributeDefs
(
newAttributeDefsWithAllBuiltInTypes
(
PREFIX_ATTRIBUTE_NAME
));
try
{
typesRegistry
.
addStructDef
(
ret
);
}
catch
(
AtlasBaseException
excp
)
{
LOG
.
error
(
"failed to create struct-def"
,
excp
);
ret
=
null
;
}
return
ret
;
}
public
static
AtlasEntityDef
newEntityDef
()
{
return
newEntityDef
(
getTypesRegistry
(),
null
);
}
public
static
AtlasEntityDef
newEntityDef
(
AtlasEntityDef
[]
superTypes
)
{
return
newEntityDef
(
getTypesRegistry
(),
superTypes
);
}
public
static
AtlasEntityDef
newEntityDef
(
AtlasTypeRegistry
typesRegistry
)
{
return
newEntityDef
(
getTypesRegistry
(),
null
);
}
public
static
AtlasEntityDef
newEntityDef
(
AtlasTypeRegistry
typesRegistry
,
AtlasEntityDef
[]
superTypes
)
{
int
entDefIdx
=
IDX_ENTITY_DEF
.
getAndIncrement
();
AtlasEntityDef
ret
=
new
AtlasEntityDef
();
ret
.
setName
(
PREFIX_ENTITY_DEF
+
entDefIdx
);
ret
.
setDescription
(
ret
.
getName
());
ret
.
setAttributeDefs
(
newAttributeDefsWithAllBuiltInTypes
(
PREFIX_ATTRIBUTE_NAME
));
if
(
superTypes
!=
null
)
{
for
(
AtlasEntityDef
superType
:
superTypes
)
{
ret
.
addSuperType
(
superType
.
getName
());
}
}
try
{
typesRegistry
.
addEntityDef
(
ret
);
}
catch
(
AtlasBaseException
excp
)
{
LOG
.
error
(
"failed to create entity-def"
,
excp
);
ret
=
null
;
}
return
ret
;
}
public
static
AtlasEntityDef
newEntityDefWithSuperTypes
()
{
return
newEntityDefWithSuperTypes
(
getTypesRegistry
());
}
public
static
AtlasEntityDef
newEntityDefWithSuperTypes
(
AtlasTypeRegistry
typesRegistry
)
{
return
newEntityDef
(
typesRegistry
,
new
AtlasEntityDef
[]
{
ENTITY_DEF
,
ENTITY_DEF_WITH_SUPER_TYPE
});
}
public
static
AtlasClassificationDef
newClassificationDef
()
{
return
newClassificationDef
(
getTypesRegistry
(),
null
);
}
public
static
AtlasClassificationDef
newClassificationDef
(
AtlasClassificationDef
[]
superTypes
)
{
return
newClassificationDef
(
getTypesRegistry
(),
superTypes
);
}
public
static
AtlasClassificationDef
newClassificationDef
(
AtlasTypeRegistry
typesRegistry
)
{
return
newClassificationDef
(
typesRegistry
,
null
);
}
public
static
AtlasClassificationDef
newClassificationDef
(
AtlasTypeRegistry
typesRegistry
,
AtlasClassificationDef
[]
superTypes
)
{
int
classificationDefIdx
=
IDX_CLASSIFICATION_DEF
.
getAndIncrement
();
AtlasClassificationDef
ret
=
new
AtlasClassificationDef
();
ret
.
setName
(
PREFIX_CLASSIFICATION_DEF
+
classificationDefIdx
);
ret
.
setDescription
(
ret
.
getName
());
ret
.
setAttributeDefs
(
newAttributeDefsWithAllBuiltInTypes
(
PREFIX_ATTRIBUTE_NAME
));
if
(
superTypes
!=
null
)
{
for
(
AtlasClassificationDef
superType
:
superTypes
)
{
ret
.
addSuperType
(
superType
.
getName
());
}
}
try
{
typesRegistry
.
addClassificationDef
(
ret
);
}
catch
(
AtlasBaseException
excp
)
{
LOG
.
error
(
"failed to create classification-def"
,
excp
);
ret
=
null
;
}
return
ret
;
}
public
static
AtlasEntity
newEntity
(
AtlasEntityDef
entityDef
)
{
return
newEntity
(
entityDef
,
getTypesRegistry
());
}
public
static
AtlasEntity
newEntity
(
AtlasEntityDef
entityDef
,
AtlasTypeRegistry
typesRegistry
)
{
AtlasEntity
ret
=
null
;
AtlasType
dataType
=
typesRegistry
.
getType
(
entityDef
.
getName
());
if
(
dataType
!=
null
&&
dataType
instanceof
AtlasEntityType
)
{
ret
=
((
AtlasEntityType
)
dataType
).
createDefaultValue
();
}
return
ret
;
}
public
static
AtlasStruct
newStruct
(
AtlasStructDef
structDef
)
{
return
newStruct
(
structDef
,
getTypesRegistry
());
}
public
static
AtlasStruct
newStruct
(
AtlasStructDef
structDef
,
AtlasTypeRegistry
typesRegistry
)
{
AtlasStruct
ret
=
null
;
AtlasType
dataType
=
typesRegistry
.
getType
(
structDef
.
getName
());
if
(
dataType
!=
null
&&
dataType
instanceof
AtlasStructType
)
{
ret
=
((
AtlasStructType
)
dataType
).
createDefaultValue
();
}
return
ret
;
}
public
static
AtlasClassification
newClassification
(
AtlasClassificationDef
classificationDef
)
{
return
newClassification
(
classificationDef
,
getTypesRegistry
());
}
public
static
AtlasClassification
newClassification
(
AtlasClassificationDef
classificationDef
,
AtlasTypeRegistry
typesRegistry
)
{
AtlasClassification
ret
=
null
;
AtlasType
dataType
=
typesRegistry
.
getType
(
classificationDef
.
getName
());
if
(
dataType
!=
null
&&
dataType
instanceof
AtlasClassificationType
)
{
ret
=
((
AtlasClassificationType
)
dataType
).
createDefaultValue
();
}
return
ret
;
}
public
static
List
<
AtlasAttributeDef
>
newAttributeDefsWithAllBuiltInTypes
(
String
attrNamePrefix
)
{
List
<
AtlasAttributeDef
>
ret
=
new
ArrayList
<
AtlasAttributeDef
>();
// add all built-in types
for
(
int
i
=
0
;
i
<
ATLAS_BUILTIN_TYPES
.
length
;
i
++)
{
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
ATLAS_BUILTIN_TYPES
[
i
]));
}
// add enum types
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
ENUM_DEF
.
getName
()));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
ENUM_DEF_WITH_NO_DEFAULT
.
getName
()));
// add array of built-in types
for
(
int
i
=
0
;
i
<
ATLAS_BUILTIN_TYPES
.
length
;
i
++)
{
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
ATLAS_BUILTIN_TYPES
[
i
])));
}
// add array of enum types
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
ENUM_DEF
.
getName
())));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
ENUM_DEF_WITH_NO_DEFAULT
.
getName
())));
// add few map types
for
(
int
i
=
0
;
i
<
ATLAS_PRIMITIVE_TYPES
.
length
;
i
++)
{
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getMapTypeName
(
ATLAS_PRIMITIVE_TYPES
[
i
],
getRandomBuiltInType
())));
}
// add map types with enum as key
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getMapTypeName
(
ENUM_DEF
.
getName
(),
getRandomBuiltInType
())));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getMapTypeName
(
ENUM_DEF_WITH_NO_DEFAULT
.
getName
(),
getRandomBuiltInType
())));
// add map types with enum as value
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getMapTypeName
(
getRandomPrimitiveType
(),
ENUM_DEF
.
getName
())));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getMapTypeName
(
getRandomPrimitiveType
(),
ENUM_DEF_WITH_NO_DEFAULT
.
getName
())));
// add few array of arrays
for
(
int
i
=
0
;
i
<
ATLAS_BUILTIN_TYPES
.
length
;
i
++)
{
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
AtlasBaseTypeDef
.
getArrayTypeName
(
getRandomBuiltInType
()))));
}
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
ENUM_DEF
.
getName
())));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
ENUM_DEF_WITH_NO_DEFAULT
.
getName
())));
// add few array of maps
for
(
int
i
=
0
;
i
<
ATLAS_PRIMITIVE_TYPES
.
length
;
i
++)
{
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
AtlasBaseTypeDef
.
getMapTypeName
(
ATLAS_PRIMITIVE_TYPES
[
i
],
getRandomBuiltInType
()))));
}
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
AtlasBaseTypeDef
.
getMapTypeName
(
ENUM_DEF
.
getName
(),
getRandomBuiltInType
()))));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
AtlasBaseTypeDef
.
getMapTypeName
(
ENUM_DEF_WITH_NO_DEFAULT
.
getName
(),
getRandomBuiltInType
()))));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
AtlasBaseTypeDef
.
getMapTypeName
(
getRandomPrimitiveType
(),
ENUM_DEF
.
getName
()))));
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getArrayTypeName
(
AtlasBaseTypeDef
.
getMapTypeName
(
getRandomPrimitiveType
(),
ENUM_DEF_WITH_NO_DEFAULT
.
getName
()))));
// add few map of arrays
for
(
int
i
=
0
;
i
<
ATLAS_PRIMITIVE_TYPES
.
length
;
i
++)
{
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getMapTypeName
(
ATLAS_PRIMITIVE_TYPES
[
i
],
AtlasBaseTypeDef
.
getArrayTypeName
(
getRandomBuiltInType
()))));
}
// add few map of maps
for
(
int
i
=
0
;
i
<
ATLAS_PRIMITIVE_TYPES
.
length
;
i
++)
{
ret
.
add
(
getAttributeDef
(
attrNamePrefix
,
AtlasBaseTypeDef
.
getMapTypeName
(
ATLAS_PRIMITIVE_TYPES
[
i
],
AtlasBaseTypeDef
.
getMapTypeName
(
ATLAS_PRIMITIVE_TYPES
[
i
],
getRandomBuiltInType
()))));
}
return
ret
;
}
public
static
String
getDefaultAttributeName
(
String
attrType
)
{
return
PREFIX_ATTRIBUTE_NAME
+
attrType
;
}
private
static
AtlasAttributeDef
getAttributeDef
(
String
attrNamePrefix
,
String
attrType
)
{
return
new
AtlasAttributeDef
(
attrNamePrefix
+
attrType
,
attrType
);
}
private
static
String
getRandomPrimitiveType
()
{
return
ATLAS_PRIMITIVE_TYPES
[
ThreadLocalRandom
.
current
().
nextInt
(
0
,
ATLAS_PRIMITIVE_TYPES
.
length
)];
}
private
static
String
getRandomBuiltInType
()
{
return
ATLAS_BUILTIN_TYPES
[
ThreadLocalRandom
.
current
().
nextInt
(
0
,
ATLAS_BUILTIN_TYPES
.
length
)];
}
}
intg/src/test/java/org/apache/atlas/model/instance/TestAtlasClassification.java
0 → 100644
View file @
698a5652
/**
* 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.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
public
class
TestAtlasClassification
{
@Test
public
void
testClassificationSerDe
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDef
();
AtlasTypeRegistry
typeRegistry
=
ModelTestUtil
.
getTypesRegistry
();
AtlasType
dataType
=
typeRegistry
.
getType
(
classificationDef
.
getName
());
assertTrue
(
dataType
instanceof
AtlasClassificationType
);
AtlasClassification
ent1
=
ModelTestUtil
.
newClassification
(
classificationDef
,
typeRegistry
);
String
jsonString
=
AtlasType
.
toJson
(
ent1
);
AtlasClassification
ent2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasClassification
.
class
);
((
AtlasClassificationType
)
dataType
).
normalizeAttributeValues
(
ent2
);
assertEquals
(
ent2
,
ent1
,
"Incorrect serialization/deserialization of AtlasClassification"
);
}
@Test
public
void
testClassificationSerDeWithSuperType
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDefWithSuperType
();
AtlasTypeRegistry
typeRegistry
=
ModelTestUtil
.
getTypesRegistry
();
AtlasType
dataType
=
typeRegistry
.
getType
(
classificationDef
.
getName
());
assertTrue
(
dataType
instanceof
AtlasClassificationType
);
AtlasClassification
ent1
=
((
AtlasClassificationType
)
dataType
).
createDefaultValue
();
String
jsonString
=
AtlasType
.
toJson
(
ent1
);
AtlasClassification
ent2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasClassification
.
class
);
((
AtlasClassificationType
)
dataType
).
normalizeAttributeValues
(
ent2
);
assertEquals
(
ent2
,
ent1
,
"Incorrect serialization/deserialization of AtlasClassification with superType"
);
}
@Test
public
void
testClassificationSerDeWithSuperTypes
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDefWithSuperTypes
();
AtlasTypeRegistry
typeRegistry
=
ModelTestUtil
.
getTypesRegistry
();
AtlasType
dataType
=
typeRegistry
.
getType
(
classificationDef
.
getName
());
assertTrue
(
dataType
instanceof
AtlasClassificationType
);
AtlasClassification
ent1
=
((
AtlasClassificationType
)
dataType
).
createDefaultValue
();
String
jsonString
=
AtlasType
.
toJson
(
ent1
);
AtlasClassification
ent2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasClassification
.
class
);
((
AtlasClassificationType
)
dataType
).
normalizeAttributeValues
(
ent2
);
assertEquals
(
ent2
,
ent1
,
"Incorrect serialization/deserialization of AtlasClassification with superTypes"
);
}
}
intg/src/test/java/org/apache/atlas/model/instance/TestAtlasEntity.java
0 → 100644
View file @
698a5652
/**
* 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.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
public
class
TestAtlasEntity
{
@Test
public
void
testEntitySerDe
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDef
();
AtlasTypeRegistry
typeRegistry
=
ModelTestUtil
.
getTypesRegistry
();
AtlasType
dataType
=
typeRegistry
.
getType
(
entityDef
.
getName
());
assertTrue
(
dataType
instanceof
AtlasEntityType
);
AtlasEntity
ent1
=
((
AtlasEntityType
)
dataType
).
createDefaultValue
();
String
jsonString
=
AtlasType
.
toJson
(
ent1
);
AtlasEntity
ent2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEntity
.
class
);
((
AtlasEntityType
)
dataType
).
normalizeAttributeValues
(
ent2
);
assertEquals
(
ent2
,
ent1
,
"Incorrect serialization/deserialization of AtlasEntity"
);
}
@Test
public
void
testEntitySerDeWithSuperType
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDefWithSuperType
();
AtlasTypeRegistry
typeRegistry
=
ModelTestUtil
.
getTypesRegistry
();
AtlasType
dataType
=
typeRegistry
.
getType
(
entityDef
.
getName
());
assertTrue
(
dataType
instanceof
AtlasEntityType
);
AtlasEntity
ent1
=
((
AtlasEntityType
)
dataType
).
createDefaultValue
();
String
jsonString
=
AtlasType
.
toJson
(
ent1
);
AtlasEntity
ent2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEntity
.
class
);
((
AtlasEntityType
)
dataType
).
normalizeAttributeValues
(
ent2
);
assertEquals
(
ent2
,
ent1
,
"Incorrect serialization/deserialization of AtlasEntity with superType"
);
}
@Test
public
void
testEntitySerDeWithSuperTypes
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDefWithSuperTypes
();
AtlasTypeRegistry
typeRegistry
=
ModelTestUtil
.
getTypesRegistry
();
AtlasType
dataType
=
typeRegistry
.
getType
(
entityDef
.
getName
());
assertTrue
(
dataType
instanceof
AtlasEntityType
);
AtlasEntity
ent1
=
((
AtlasEntityType
)
dataType
).
createDefaultValue
();
String
jsonString
=
AtlasType
.
toJson
(
ent1
);
AtlasEntity
ent2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEntity
.
class
);
((
AtlasEntityType
)
dataType
).
normalizeAttributeValues
(
ent2
);
assertEquals
(
ent2
,
ent1
,
"Incorrect serialization/deserialization of AtlasEntity with superTypes"
);
}
}
intg/src/test/java/org/apache/atlas/model/typedef/TestAtlasClassificationDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
org.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.type.AtlasType
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
public
class
TestAtlasClassificationDef
{
@Test
public
void
testClassificationDefSerDeEmpty
()
{
AtlasClassificationDef
classificationDef
=
new
AtlasClassificationDef
(
"emptyClassificationDef"
);
String
jsonString
=
AtlasType
.
toJson
(
classificationDef
);
AtlasClassificationDef
classificationDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasClassificationDef
.
class
);
assertEquals
(
classificationDef2
,
classificationDef
,
"Incorrect serialization/deserialization of AtlasClassificationDef"
);
}
@Test
public
void
testClassificationDefSerDe
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDef
();
String
jsonString
=
AtlasType
.
toJson
(
classificationDef
);
AtlasClassificationDef
classificationDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasClassificationDef
.
class
);
assertEquals
(
classificationDef2
,
classificationDef
,
"Incorrect serialization/deserialization of AtlasClassificationDef"
);
}
@Test
public
void
testClassificationDefSerDeWithSuperType
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDefWithSuperType
();
String
jsonString
=
AtlasType
.
toJson
(
classificationDef
);
AtlasClassificationDef
classificationDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasClassificationDef
.
class
);
assertEquals
(
classificationDef2
,
classificationDef
,
"Incorrect serialization/deserialization of AtlasClassificationDef with superType"
);
}
@Test
public
void
testClassificationDefSerDeWithSuperTypes
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDefWithSuperTypes
();
String
jsonString
=
AtlasType
.
toJson
(
classificationDef
);
AtlasClassificationDef
classificationDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasClassificationDef
.
class
);
assertEquals
(
classificationDef2
,
classificationDef
,
"Incorrect serialization/deserialization of AtlasClassificationDef with superTypes"
);
}
@Test
public
void
testClassificationDefHasSuperTypeWithNoSuperType
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDef
();
for
(
String
superType
:
classificationDef
.
getSuperTypes
())
{
assertTrue
(
classificationDef
.
hasSuperType
(
superType
));
}
assertFalse
(
classificationDef
.
hasSuperType
(
"01234-xyzabc-;''-)("
));
}
@Test
public
void
testClassificationDefHasSuperTypeWithSuperType
()
{
AtlasClassificationDef
classificationDef
=
ModelTestUtil
.
getClassificationDefWithSuperTypes
();
for
(
String
superType
:
classificationDef
.
getSuperTypes
())
{
assertTrue
(
classificationDef
.
hasSuperType
(
superType
));
}
assertFalse
(
classificationDef
.
hasSuperType
(
"01234-xyzabc-;''-)("
));
}
}
intg/src/test/java/org/apache/atlas/model/typedef/TestAtlasEntityDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
org.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.type.AtlasType
;
import
org.testng.annotations.Test
;
import
java.util.HashSet
;
import
java.util.Set
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
public
class
TestAtlasEntityDef
{
@Test
public
void
testEntityDefSerDeEmpty
()
{
AtlasEntityDef
entityDef
=
new
AtlasEntityDef
(
"emptyEntityDef"
);
String
jsonString
=
AtlasType
.
toJson
(
entityDef
);
AtlasEntityDef
entityDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEntityDef
.
class
);
assertEquals
(
entityDef2
,
entityDef
,
"Incorrect serialization/deserialization of AtlasEntityDef"
);
}
@Test
public
void
testEntityDefSerDe
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDef
();
String
jsonString
=
AtlasType
.
toJson
(
entityDef
);
AtlasEntityDef
entityDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEntityDef
.
class
);
assertEquals
(
entityDef2
,
entityDef
,
"Incorrect serialization/deserialization of AtlasEntityDef"
);
}
@Test
public
void
testEntityDefSerDeWithSuperType
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDefWithSuperType
();
String
jsonString
=
AtlasType
.
toJson
(
entityDef
);
AtlasEntityDef
entityDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEntityDef
.
class
);
assertEquals
(
entityDef2
,
entityDef
,
"Incorrect serialization/deserialization of AtlasEntityDef with superType"
);
}
@Test
public
void
testEntityDefSerDeWithSuperTypes
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDefWithSuperTypes
();
String
jsonString
=
AtlasType
.
toJson
(
entityDef
);
AtlasEntityDef
entityDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEntityDef
.
class
);
assertEquals
(
entityDef2
,
entityDef
,
"Incorrect serialization/deserialization of AtlasEntityDef with superTypes"
);
}
@Test
public
void
testEntityDefAddSuperType
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
newEntityDef
();
String
newSuperType
=
"newType-abcd-1234"
;
entityDef
.
addSuperType
(
newSuperType
);
assertTrue
(
entityDef
.
hasSuperType
(
newSuperType
));
}
@Test
public
void
testEntityDefDefRemoveElement
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
newEntityDefWithSuperTypes
();
for
(
String
superType
:
entityDef
.
getSuperTypes
())
{
entityDef
.
removeSuperType
(
superType
);
assertFalse
(
entityDef
.
hasSuperType
(
superType
));
}
}
@Test
public
void
testEntityDefSetSuperTypes
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
newEntityDefWithSuperTypes
();
Set
<
String
>
oldSuperTypes
=
entityDef
.
getSuperTypes
();
Set
<
String
>
newSuperTypes
=
new
HashSet
<
String
>();
newSuperTypes
.
add
(
"newType-abcd-1234"
);
entityDef
.
setSuperTypes
(
newSuperTypes
);
for
(
String
superType
:
oldSuperTypes
)
{
assertFalse
(
entityDef
.
hasSuperType
(
superType
));
}
for
(
String
superType
:
newSuperTypes
)
{
assertTrue
(
entityDef
.
hasSuperType
(
superType
));
}
}
@Test
public
void
testEntityDefHasSuperTypeWithNoSuperType
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDef
();
for
(
String
superType
:
entityDef
.
getSuperTypes
())
{
assertTrue
(
entityDef
.
hasSuperType
(
superType
));
}
assertFalse
(
entityDef
.
hasSuperType
(
"01234-xyzabc-;''-)("
));
}
@Test
public
void
testEntityDefHasSuperTypeWithNoSuperTypes
()
{
AtlasEntityDef
entityDef
=
ModelTestUtil
.
getEntityDefWithSuperTypes
();
for
(
String
superType
:
entityDef
.
getSuperTypes
())
{
assertTrue
(
entityDef
.
hasSuperType
(
superType
));
}
assertFalse
(
entityDef
.
hasSuperType
(
"01234-xyzabc-;''-)("
));
}
}
intg/src/test/java/org/apache/atlas/model/typedef/TestAtlasEnumDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef
;
import
org.apache.atlas.type.AtlasType
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
public
class
TestAtlasEnumDef
{
@Test
public
void
testEnumDefSerDeEmpty
()
{
AtlasEnumDef
enumDef1
=
new
AtlasEnumDef
();
String
jsonString
=
AtlasType
.
toJson
(
enumDef1
);
AtlasEnumDef
enumDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEnumDef
.
class
);
assertEquals
(
enumDef1
,
enumDef2
,
"Incorrect serialization/deserialization of AtlasEnumDef"
);
}
@Test
public
void
testEnumDefSerDe
()
{
AtlasEnumDef
enumDef
=
ModelTestUtil
.
getEnumDef
();
String
jsonString
=
AtlasType
.
toJson
(
enumDef
);
AtlasEnumDef
enumDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasEnumDef
.
class
);
assertEquals
(
enumDef
,
enumDef2
,
"Incorrect serialization/deserialization of AtlasEnumDef"
);
}
@Test
public
void
testEnumDefHasElement
()
{
AtlasEnumDef
enumDef
=
ModelTestUtil
.
getEnumDef
();
for
(
AtlasEnumElementDef
elementDef
:
enumDef
.
getElementDefs
())
{
assertTrue
(
enumDef
.
hasElement
(
elementDef
.
getValue
()));
}
assertFalse
(
enumDef
.
hasElement
(
"01234-xyzabc-;''-)("
));
}
@Test
public
void
testEnumDefAddElement
()
{
AtlasEnumDef
enumDef
=
ModelTestUtil
.
newEnumDef
();
String
newElement
=
"newElement-abcd-1234"
;
enumDef
.
addElement
(
new
AtlasEnumElementDef
(
newElement
,
"A new element"
,
enumDef
.
getElementDefs
().
size
()));
assertTrue
(
enumDef
.
hasElement
(
newElement
));
}
@Test
public
void
testEnumDefRemoveElement
()
{
AtlasEnumDef
enumDef
=
ModelTestUtil
.
newEnumDef
();
if
(
enumDef
.
getElementDefs
().
size
()
>
0
)
{
String
elementValue
=
enumDef
.
getElementDefs
().
get
(
0
).
getValue
();
assertTrue
(
enumDef
.
hasElement
(
elementValue
));
enumDef
.
removeElement
(
elementValue
);
assertFalse
(
enumDef
.
hasElement
(
elementValue
));
}
}
@Test
public
void
testEnumDefSetElementDefs
()
{
AtlasEnumDef
enumDef
=
ModelTestUtil
.
newEnumDef
();
List
<
AtlasEnumElementDef
>
oldElements
=
enumDef
.
getElementDefs
();
List
<
AtlasEnumElementDef
>
newElements
=
new
ArrayList
<
AtlasEnumElementDef
>();
newElements
.
add
(
new
AtlasEnumElementDef
(
"newElement"
,
"new Element"
,
100
));
enumDef
.
setElementDefs
(
newElements
);
for
(
AtlasEnumElementDef
elementDef
:
oldElements
)
{
assertFalse
(
enumDef
.
hasElement
(
elementDef
.
getValue
()));
}
for
(
AtlasEnumElementDef
elementDef
:
newElements
)
{
assertTrue
(
enumDef
.
hasElement
(
elementDef
.
getValue
()));
}
}
}
intg/src/test/java/org/apache/atlas/model/typedef/TestAtlasStructDef.java
0 → 100644
View file @
698a5652
/**
* 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
.
typedef
;
import
java.util.List
;
import
org.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.type.AtlasType
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
public
class
TestAtlasStructDef
{
@Test
public
void
testStructDefSerDeEmpty
()
{
AtlasStructDef
structDef
=
new
AtlasStructDef
(
"emptyStructDef"
);
String
jsonString
=
AtlasType
.
toJson
(
structDef
);
AtlasStructDef
structDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasStructDef
.
class
);
assertEquals
(
structDef2
,
structDef
,
"Incorrect serialization/deserialization of AtlasStructDef"
);
}
@Test
public
void
testStructDefSerDe
()
{
AtlasStructDef
structDef
=
ModelTestUtil
.
getStructDef
();
String
jsonString
=
AtlasType
.
toJson
(
structDef
);
AtlasStructDef
structDef2
=
AtlasType
.
fromJson
(
jsonString
,
AtlasStructDef
.
class
);
assertEquals
(
structDef2
,
structDef
,
"Incorrect serialization/deserialization of AtlasStructDef"
);
}
@Test
public
void
testStructDefHasAttribute
()
{
AtlasStructDef
structDef
=
ModelTestUtil
.
getStructDef
();
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
assertTrue
(
structDef
.
hasAttribute
(
attributeDef
.
getName
()));
}
assertFalse
(
structDef
.
hasAttribute
(
"01234-xyzabc-;''-)("
));
}
@Test
public
void
testStructDefAddAttribute
()
{
AtlasStructDef
structDef
=
ModelTestUtil
.
newStructDef
();
structDef
.
addAttribute
(
new
AtlasAttributeDef
(
"newAttribute"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
));
assertTrue
(
structDef
.
hasAttribute
(
"newAttribute"
));
}
@Test
public
void
testStructDefRemoveAttribute
()
{
AtlasStructDef
structDef
=
ModelTestUtil
.
newStructDef
();
String
attrName
=
structDef
.
getAttributeDefs
().
get
(
0
).
getName
();
assertTrue
(
structDef
.
hasAttribute
(
attrName
));
structDef
.
removeAttribute
(
attrName
);
assertFalse
(
structDef
.
hasAttribute
(
attrName
));
}
@Test
public
void
testStructDefSetAttributeDefs
()
{
AtlasStructDef
structDef
=
ModelTestUtil
.
newStructDef
();
List
<
AtlasAttributeDef
>
oldAttributes
=
structDef
.
getAttributeDefs
();
List
<
AtlasAttributeDef
>
newttributes
=
ModelTestUtil
.
newAttributeDefsWithAllBuiltInTypes
(
"newAttributes"
);
structDef
.
setAttributeDefs
(
newttributes
);
for
(
AtlasAttributeDef
attributeDef
:
oldAttributes
)
{
assertFalse
(
structDef
.
hasAttribute
(
attributeDef
.
getName
()));
}
for
(
AtlasAttributeDef
attributeDef
:
newttributes
)
{
assertTrue
(
structDef
.
hasAttribute
(
attributeDef
.
getName
()));
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasArrayType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasIntType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.*
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasArrayType
{
private
final
AtlasArrayType
intArrayType
=
new
AtlasArrayType
(
new
AtlasIntType
());
private
final
Object
[]
validValues
;
private
final
Object
[]
invalidValues
;
{
List
<
Integer
>
intList
=
new
ArrayList
<
Integer
>();
Set
<
Integer
>
intSet
=
new
HashSet
<
Integer
>();
Integer
[]
intArray
=
new
Integer
[]
{
1
,
2
,
3
};
List
<
Object
>
objList
=
new
ArrayList
<
Object
>();
Set
<
Object
>
objSet
=
new
HashSet
<
Object
>();
Object
[]
objArray
=
new
Object
[]
{
1
,
2
,
3
};
List
<
String
>
strList
=
new
ArrayList
<
String
>();
Set
<
String
>
strSet
=
new
HashSet
<
String
>();
String
[]
strArray
=
new
String
[]
{
"1"
,
"2"
,
"3"
};
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
intList
.
add
(
i
);
intSet
.
add
(
i
);
objList
.
add
(
i
);
objSet
.
add
(
i
);
strList
.
add
(
Integer
.
toString
(
i
));
strSet
.
add
(
Integer
.
toString
(
i
));
}
validValues
=
new
Object
[]
{
null
,
new
Integer
[]
{
},
intList
,
intSet
,
intArray
,
objList
,
objSet
,
objArray
,
strList
,
strSet
,
strArray
,
new
byte
[]
{
1
},
new
short
[]
{
1
},
new
int
[]
{
1
},
new
long
[]
{
1
},
new
float
[]
{
1
},
new
double
[]
{
1
},
new
BigInteger
[]
{
BigInteger
.
valueOf
(
1
)
},
new
BigDecimal
[]
{
BigDecimal
.
valueOf
(
1
)},
};
invalidValues
=
new
Object
[]
{
new
String
[]
{
"1"
,
"abcd"
,
"3"
,
"xyz"
,
"5"
},
"1"
,
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
),
};
}
@Test
public
void
testArrayTypeDefaultValue
()
{
Collection
defValue
=
intArrayType
.
createDefaultValue
();
assertEquals
(
defValue
.
size
(),
1
);
}
@Test
public
void
testArrayTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
intArrayType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
intArrayType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testArrayTypeGetNormalizedValue
()
{
assertNull
(
intArrayType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Collection
normalizedValue
=
intArrayType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
intArrayType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testArrayTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
intArrayType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
intArrayType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertTrue
(
messages
.
size
()
>
0
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasBigDecimalType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasBigDecimalType
{
private
final
AtlasBigDecimalType
bigDecimalType
=
new
AtlasBigDecimalType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
};
@Test
public
void
testBigDecimalTypeDefaultValue
()
{
BigDecimal
defValue
=
bigDecimalType
.
createDefaultValue
();
assertEquals
(
defValue
,
BigDecimal
.
valueOf
(
0
));
}
@Test
public
void
testBigDecimalTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
bigDecimalType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
bigDecimalType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
bigDecimalType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testBigDecimalTypeGetNormalizedValue
()
{
assertNull
(
bigDecimalType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
BigDecimal
normalizedValue
=
bigDecimalType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
BigDecimal
normalizedValue
=
bigDecimalType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
bigDecimalType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testBigDecimalTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
bigDecimalType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
bigDecimalType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
bigDecimalType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasBigIntegerType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasBigIntegerType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasBigIntegerType
{
private
final
AtlasBigIntegerType
bigIntegerType
=
new
AtlasBigIntegerType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
@Test
public
void
testBigIntegerTypeDefaultValue
()
{
BigInteger
defValue
=
bigIntegerType
.
createDefaultValue
();
assertEquals
(
defValue
,
BigInteger
.
valueOf
(
0
));
}
@Test
public
void
testBigIntegerTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
bigIntegerType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
bigIntegerType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
bigIntegerType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testBigIntegerTypeGetNormalizedValue
()
{
assertNull
(
bigIntegerType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
BigInteger
normalizedValue
=
bigIntegerType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
BigInteger
.
valueOf
(
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
BigInteger
normalizedValue
=
bigIntegerType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
BigInteger
.
valueOf
(-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
bigIntegerType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testBigIntegerTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
bigIntegerType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
bigIntegerType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
bigIntegerType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasBooleanType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasBooleanType
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasBooleanType
{
private
final
AtlasBooleanType
booleanType
=
new
AtlasBooleanType
();
private
final
Object
[]
validValues
=
{
null
,
Boolean
.
TRUE
,
Boolean
.
FALSE
,
"true"
,
"false"
,
"TRUE"
,
"FALSE"
,
};
private
final
Object
[]
invalidValues
=
{
};
@Test
public
void
testBooleanTypeDefaultValue
()
{
Boolean
defValue
=
booleanType
.
createDefaultValue
();
assertFalse
(
defValue
);
}
@Test
public
void
testBooleanTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
booleanType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
booleanType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testBooleanTypeGetNormalizedValue
()
{
Object
[]
trueValues
=
{
Boolean
.
TRUE
,
"true"
,
"TRUE"
,
"tRuE"
,
"TrUe"
};
Object
[]
falseValues
=
{
Boolean
.
FALSE
,
"false"
,
"FALSE"
,
"fAlSe"
,
"FaLsE"
};
assertNull
(
booleanType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
trueValues
)
{
Boolean
normalizedValue
=
booleanType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertTrue
(
normalizedValue
,
"value="
+
value
);
}
for
(
Object
value
:
falseValues
)
{
Boolean
normalizedValue
=
booleanType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertFalse
(
normalizedValue
,
"value="
+
value
);
}
}
@Test
public
void
testBooleanTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
booleanType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
booleanType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasByteType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasByteType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasByteType
{
private
final
AtlasByteType
byteType
=
new
AtlasByteType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
};
@Test
public
void
testByteTypeDefaultValue
()
{
Byte
defValue
=
byteType
.
createDefaultValue
();
assertEquals
(
defValue
,
Byte
.
valueOf
((
byte
)
0
));
}
@Test
public
void
testByteTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
byteType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
byteType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
byteType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testByteTypeGetNormalizedValue
()
{
assertNull
(
byteType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Byte
normalizedValue
=
byteType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Byte
.
valueOf
((
byte
)
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
Byte
normalizedValue
=
byteType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Byte
.
valueOf
((
byte
)-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
byteType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testByteTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
byteType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
byteType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
byteType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasClassificationType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.*
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasClassificationType
{
private
final
AtlasClassificationType
classificationType
;
private
final
List
<
Object
>
validValues
=
new
ArrayList
<
Object
>();
private
final
List
<
Object
>
invalidValues
=
new
ArrayList
<
Object
>();
{
classificationType
=
getClassificationType
(
ModelTestUtil
.
getClassificationDefWithSuperTypes
());
AtlasClassification
invalidValue1
=
classificationType
.
createDefaultValue
();
AtlasClassification
invalidValue2
=
classificationType
.
createDefaultValue
();
Map
<
String
,
Object
>
invalidValue3
=
classificationType
.
createDefaultValue
().
getAttributes
();
// invalid value for int
invalidValue1
.
setAttribute
(
ModelTestUtil
.
getDefaultAttributeName
(
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
),
"xyz"
);
// invalid value for date
invalidValue2
.
setAttribute
(
ModelTestUtil
.
getDefaultAttributeName
(
AtlasBaseTypeDef
.
ATLAS_TYPE_DATE
),
"xyz"
);
// invalid value for bigint
invalidValue3
.
put
(
ModelTestUtil
.
getDefaultAttributeName
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
),
"xyz"
);
validValues
.
add
(
null
);
validValues
.
add
(
classificationType
.
createDefaultValue
());
validValues
.
add
(
classificationType
.
createDefaultValue
().
getAttributes
());
// Map<String, Object>
invalidValues
.
add
(
invalidValue1
);
invalidValues
.
add
(
invalidValue2
);
invalidValues
.
add
(
invalidValue3
);
invalidValues
.
add
(
new
AtlasClassification
());
// no values for mandatory attributes
invalidValues
.
add
(
new
HashMap
<
Object
,
Object
>());
// no values for mandatory attributes
invalidValues
.
add
(
1
);
// incorrect datatype
invalidValues
.
add
(
new
HashSet
());
// incorrect datatype
invalidValues
.
add
(
new
ArrayList
());
// incorrect datatype
invalidValues
.
add
(
new
String
[]
{});
// incorrect datatype
}
@Test
public
void
testClassificationTypeDefaultValue
()
{
AtlasClassification
defValue
=
classificationType
.
createDefaultValue
();
assertNotNull
(
defValue
);
assertEquals
(
defValue
.
getTypeName
(),
classificationType
.
getTypeName
());
}
@Test
public
void
testClassificationTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
classificationType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
classificationType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testClassificationTypeGetNormalizedValue
()
{
assertNull
(
classificationType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Object
normalizedValue
=
classificationType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
classificationType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testClassificationTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
classificationType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
classificationType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertTrue
(
messages
.
size
()
>
0
,
"value="
+
value
);
messages
.
clear
();
}
}
private
static
AtlasClassificationType
getClassificationType
(
AtlasClassificationDef
classificationDef
)
{
try
{
return
new
AtlasClassificationType
(
classificationDef
,
ModelTestUtil
.
getTypesRegistry
());
}
catch
(
AtlasBaseException
excp
)
{
return
null
;
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasDateType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasDateType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.Date
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
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
),
Double
.
valueOf
(
1
),
BigInteger
.
valueOf
(
1
),
BigDecimal
.
valueOf
(
1
),
"1"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
private
final
Date
now
=
new
Date
();
private
final
String
strNow
=
AtlasBaseTypeDef
.
DATE_FORMATTER
.
format
(
now
);
@Test
public
void
testDateTypeDefaultValue
()
{
Date
defValue
=
dateType
.
createDefaultValue
();
assertEquals
(
defValue
,
new
Date
(
0
));
}
@Test
public
void
testDateTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
dateType
.
isValidValue
(
value
),
"value="
+
value
);
}
assertTrue
(
dateType
.
isValidValue
(
now
),
"value="
+
now
);
assertTrue
(
dateType
.
isValidValue
(
strNow
),
"value="
+
strNow
);
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
dateType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
dateType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testDateTypeGetNormalizedValue
()
{
assertNull
(
dateType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Date
normalizedValue
=
dateType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
new
Date
(
1
),
"value="
+
value
);
}
assertNotNull
(
dateType
.
getNormalizedValue
(
now
),
"value="
+
now
);
assertEquals
(
dateType
.
getNormalizedValue
(
now
),
now
,
"value="
+
now
);
assertNotNull
(
dateType
.
getNormalizedValue
(
strNow
),
"value="
+
strNow
);
assertEquals
(
dateType
.
getNormalizedValue
(
now
),
now
,
"value="
+
now
);
for
(
Object
value
:
negativeValues
)
{
Date
normalizedValue
=
dateType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
new
Date
(-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
dateType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testDateTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
dateType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
assertTrue
(
dateType
.
validateValue
(
now
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
now
);
assertTrue
(
dateType
.
validateValue
(
strNow
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
strNow
);
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
dateType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
dateType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasDoubleType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasDoubleType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasDoubleType
{
private
final
AtlasDoubleType
doubleType
=
new
AtlasDoubleType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
@Test
public
void
testDoubleTypeDefaultValue
()
{
Double
defValue
=
doubleType
.
createDefaultValue
();
assertEquals
(
defValue
,
Double
.
valueOf
(
0
));
}
@Test
public
void
testDoubleTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
doubleType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
doubleType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
doubleType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testDoubleTypeGetNormalizedValue
()
{
assertNull
(
doubleType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Double
normalizedValue
=
doubleType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Double
.
valueOf
(
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
Double
normalizedValue
=
doubleType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Double
.
valueOf
(-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
doubleType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testDoubleTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
doubleType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
doubleType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
doubleType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasEntityType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.*
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasEntityType
{
private
final
AtlasEntityType
entityType
;
private
final
List
<
Object
>
validValues
=
new
ArrayList
<
Object
>();
private
final
List
<
Object
>
invalidValues
=
new
ArrayList
<
Object
>();
{
entityType
=
getEntityType
(
ModelTestUtil
.
getEntityDefWithSuperTypes
());
AtlasEntity
invalidValue1
=
entityType
.
createDefaultValue
();
AtlasEntity
invalidValue2
=
entityType
.
createDefaultValue
();
Map
<
String
,
Object
>
invalidValue3
=
entityType
.
createDefaultValue
().
getAttributes
();
// invalid value for int
invalidValue1
.
setAttribute
(
ModelTestUtil
.
getDefaultAttributeName
(
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
),
"xyz"
);
// invalid value for date
invalidValue2
.
setAttribute
(
ModelTestUtil
.
getDefaultAttributeName
(
AtlasBaseTypeDef
.
ATLAS_TYPE_DATE
),
"xyz"
);
// invalid value for bigint
invalidValue3
.
put
(
ModelTestUtil
.
getDefaultAttributeName
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
),
"xyz"
);
validValues
.
add
(
null
);
validValues
.
add
(
entityType
.
createDefaultValue
());
validValues
.
add
(
entityType
.
createDefaultValue
().
getAttributes
());
// Map<String, Object>
invalidValues
.
add
(
invalidValue1
);
invalidValues
.
add
(
invalidValue2
);
invalidValues
.
add
(
invalidValue3
);
invalidValues
.
add
(
new
AtlasEntity
());
// no values for mandatory attributes
invalidValues
.
add
(
new
HashMap
<
Object
,
Object
>());
// no values for mandatory attributes
invalidValues
.
add
(
1
);
// incorrect datatype
invalidValues
.
add
(
new
HashSet
());
// incorrect datatype
invalidValues
.
add
(
new
ArrayList
());
// incorrect datatype
invalidValues
.
add
(
new
String
[]
{});
// incorrect datatype
}
@Test
public
void
testEntityTypeDefaultValue
()
{
AtlasEntity
defValue
=
entityType
.
createDefaultValue
();
assertNotNull
(
defValue
);
assertEquals
(
defValue
.
getTypeName
(),
entityType
.
getTypeName
());
}
@Test
public
void
testEntityTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
entityType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
entityType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testEntityTypeGetNormalizedValue
()
{
assertNull
(
entityType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Object
normalizedValue
=
entityType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
entityType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testEntityTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
entityType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
entityType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertTrue
(
messages
.
size
()
>
0
,
"value="
+
value
);
messages
.
clear
();
}
}
private
static
AtlasEntityType
getEntityType
(
AtlasEntityDef
entityDef
)
{
try
{
return
new
AtlasEntityType
(
entityDef
,
ModelTestUtil
.
getTypesRegistry
());
}
catch
(
AtlasBaseException
excp
)
{
return
null
;
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasFloatType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasFloatType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasFloatType
{
private
final
AtlasFloatType
floatType
=
new
AtlasFloatType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
@Test
public
void
testFloatTypeDefaultValue
()
{
Float
defValue
=
floatType
.
createDefaultValue
();
assertEquals
(
defValue
,
Float
.
valueOf
(
0
));
}
@Test
public
void
testFloatTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
floatType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
floatType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
floatType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testFloatTypeGetNormalizedValue
()
{
assertNull
(
floatType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Float
normalizedValue
=
floatType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Float
.
valueOf
(
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
Float
normalizedValue
=
floatType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Float
.
valueOf
(-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
floatType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testFloatTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
floatType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
floatType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
floatType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasIntType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasIntType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasIntType
{
private
final
AtlasIntType
intType
=
new
AtlasIntType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
@Test
public
void
testIntTypeDefaultValue
()
{
Integer
defValue
=
intType
.
createDefaultValue
();
assertEquals
(
defValue
,
Integer
.
valueOf
(
0
));
}
@Test
public
void
testIntTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
intType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
intType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
intType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testIntTypeGetNormalizedValue
()
{
assertNull
(
intType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Integer
normalizedValue
=
intType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Integer
.
valueOf
(
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
Integer
normalizedValue
=
intType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Integer
.
valueOf
(-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
intType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testIntTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
intType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
intType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
intType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasLongType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasLongType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasLongType
{
private
final
AtlasLongType
longType
=
new
AtlasLongType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
@Test
public
void
testLongTypeDefaultValue
()
{
Long
defValue
=
longType
.
createDefaultValue
();
assertEquals
(
defValue
,
Long
.
valueOf
(
0
));
}
@Test
public
void
testLongTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
longType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
longType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
longType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testLongTypeGetNormalizedValue
()
{
assertNull
(
longType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Long
normalizedValue
=
longType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Long
.
valueOf
(
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
Long
normalizedValue
=
longType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Long
.
valueOf
(-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
longType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testLongTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
longType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
longType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
longType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasMapType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasIntType
;
import
org.testng.annotations.Test
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasMapType
{
private
final
AtlasMapType
intIntMapType
=
new
AtlasMapType
(
new
AtlasIntType
(),
new
AtlasIntType
());
private
final
Object
[]
validValues
;
private
final
Object
[]
invalidValues
;
{
Map
<
String
,
Integer
>
strIntMap
=
new
HashMap
<
String
,
Integer
>();
Map
<
String
,
Double
>
strDoubleMap
=
new
HashMap
<
String
,
Double
>();
Map
<
String
,
String
>
strStringMap
=
new
HashMap
<
String
,
String
>();
Map
<
Integer
,
Integer
>
intIntMap
=
new
HashMap
<
Integer
,
Integer
>();
Map
<
Object
,
Object
>
objObjMap
=
new
HashMap
<
Object
,
Object
>();
Map
<
Object
,
Object
>
invObjObjMap1
=
new
HashMap
<
Object
,
Object
>();
Map
<
Object
,
Object
>
invObjObjMap2
=
new
HashMap
<
Object
,
Object
>();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
strIntMap
.
put
(
Integer
.
toString
(
i
),
i
);
strDoubleMap
.
put
(
Integer
.
toString
(
i
),
Double
.
valueOf
(
i
));
strStringMap
.
put
(
Integer
.
toString
(
i
),
Integer
.
toString
(
i
));
intIntMap
.
put
(
i
,
i
);
objObjMap
.
put
(
i
,
i
);
}
invObjObjMap1
.
put
(
"xyz"
,
"123"
);
// invalid key
invObjObjMap2
.
put
(
"123"
,
"xyz"
);
// invalid value
validValues
=
new
Object
[]
{
null
,
new
HashMap
<
String
,
Integer
>(),
new
HashMap
<
Object
,
Object
>(),
strIntMap
,
strDoubleMap
,
strStringMap
,
intIntMap
,
objObjMap
,
};
invalidValues
=
new
Object
[]
{
invObjObjMap1
,
invObjObjMap2
,
};
}
@Test
public
void
testMapTypeDefaultValue
()
{
Map
<
Object
,
Object
>
defValue
=
intIntMapType
.
createDefaultValue
();
assertEquals
(
defValue
.
size
(),
1
);
}
@Test
public
void
testMapTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
intIntMapType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
intIntMapType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testMapTypeGetNormalizedValue
()
{
assertNull
(
intIntMapType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Map
<
Object
,
Object
>
normalizedValue
=
intIntMapType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
intIntMapType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testMapTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
intIntMapType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
intIntMapType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertTrue
(
messages
.
size
()
>
0
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasObjectIdType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasObjectIdType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasObjectIdType
{
private
final
AtlasObjectIdType
objectIdType
=
new
AtlasObjectIdType
();
private
final
Object
[]
validValues
;
private
final
Object
[]
invalidValues
;
{
Map
<
String
,
String
>
objectId1
=
new
HashMap
<
String
,
String
>();
Map
<
Object
,
Object
>
objectId2
=
new
HashMap
<
Object
,
Object
>();
Map
<
Object
,
Object
>
objectId3
=
new
HashMap
<
Object
,
Object
>();
Map
<
Object
,
Object
>
objectId4
=
new
HashMap
<
Object
,
Object
>();
Map
<
Object
,
Object
>
objectId5
=
new
HashMap
<
Object
,
Object
>();
objectId1
.
put
(
AtlasObjectId
.
KEY_TYPENAME
,
"testType"
);
objectId1
.
put
(
AtlasObjectId
.
KEY_GUID
,
"guid-1234"
);
objectId2
.
put
(
AtlasObjectId
.
KEY_TYPENAME
,
"testType"
);
objectId2
.
put
(
AtlasObjectId
.
KEY_GUID
,
1234
);
objectId3
.
put
(
AtlasObjectId
.
KEY_TYPENAME
,
"testType"
);
// no guid
objectId4
.
put
(
AtlasObjectId
.
KEY_GUID
,
"guid-1234"
);
// no typeName
objectId4
.
put
(
AtlasObjectId
.
KEY_TYPENAME
+
"-invalid"
,
"testType"
);
objectId5
.
put
(
AtlasObjectId
.
KEY_GUID
+
"-invalid"
,
"guid-1234"
);
validValues
=
new
Object
[]
{
null
,
objectId1
,
objectId2
,
new
AtlasObjectId
(),
new
AtlasObjectId
(
"testType"
,
"guid-1234"
),
};
invalidValues
=
new
Object
[]
{
objectId3
,
objectId4
,
objectId5
,
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"
,
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
}
@Test
public
void
testObjectIdTypeDefaultValue
()
{
AtlasObjectId
defValue
=
objectIdType
.
createDefaultValue
();
assertNotNull
(
defValue
);
}
@Test
public
void
testObjectIdTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
objectIdType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
objectIdType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testObjectIdTypeGetNormalizedValue
()
{
assertNull
(
objectIdType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
AtlasObjectId
normalizedValue
=
objectIdType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
if
(
value
instanceof
AtlasObjectId
)
{
assertEquals
(
normalizedValue
,
value
,
"value="
+
value
);
}
else
if
(
value
instanceof
Map
)
{
assertEquals
(
normalizedValue
.
getTypeName
(),
((
Map
)
value
).
get
(
AtlasObjectId
.
KEY_TYPENAME
).
toString
(),
"value="
+
value
);
assertEquals
(
normalizedValue
.
getGuid
(),
((
Map
)
value
).
get
(
AtlasObjectId
.
KEY_GUID
).
toString
(),
"value="
+
value
);
}
}
}
@Test
public
void
testObjectIdTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
objectIdType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
objectIdType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasShortType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasShortType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasShortType
{
private
final
AtlasShortType
shortType
=
new
AtlasShortType
();
private
final
Object
[]
validValues
=
{
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"
,
};
private
final
Object
[]
negativeValues
=
{
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"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
@Test
public
void
testShortTypeDefaultValue
()
{
Short
defValue
=
shortType
.
createDefaultValue
();
assertEquals
(
defValue
,
Short
.
valueOf
((
short
)
0
));
}
@Test
public
void
testShortTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
shortType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
shortType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
shortType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testShortTypeGetNormalizedValue
()
{
assertNull
(
shortType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Short
normalizedValue
=
shortType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Short
.
valueOf
((
short
)
1
),
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
Short
normalizedValue
=
shortType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
Short
.
valueOf
((
short
)-
1
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
shortType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testShortTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
shortType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
negativeValues
)
{
assertTrue
(
shortType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
shortType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasStringType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
org.apache.atlas.type.AtlasBuiltInTypes.AtlasStringType
;
import
org.testng.annotations.Test
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasStringType
{
private
final
AtlasStringType
stringType
=
new
AtlasStringType
();
private
final
Object
[]
validValues
=
{
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"
,
""
,
"12ab"
,
"abcd"
,
"-12ab"
,
};
private
final
Object
[]
invalidValues
=
{
};
@Test
public
void
testStringTypeDefaultValue
()
{
String
defValue
=
stringType
.
createDefaultValue
();
assertEquals
(
defValue
,
""
);
}
@Test
public
void
testStringTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
stringType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
stringType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testStringTypeGetNormalizedValue
()
{
assertNull
(
stringType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
String
normalizedValue
=
stringType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
value
.
toString
(),
"value="
+
value
);
}
}
@Test
public
void
testStringTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
stringType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
stringType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
1
,
"value="
+
value
);
messages
.
clear
();
}
}
}
intg/src/test/java/org/apache/atlas/type/TestAtlasStructType.java
0 → 100644
View file @
698a5652
/**
* 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
.
type
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.ModelTestUtil
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_DATE
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.*;
public
class
TestAtlasStructType
{
private
static
final
String
MULTI_VAL_ATTR_NAME_MIN_MAX
=
"multiValMinMax"
;
private
static
final
String
MULTI_VAL_ATTR_NAME_MIN
=
"multiValMin"
;
private
static
final
String
MULTI_VAL_ATTR_NAME_MAX
=
"multiValMax"
;
private
static
final
int
MULTI_VAL_ATTR_MIN_COUNT
=
2
;
private
static
final
int
MULTI_VAL_ATTR_MAX_COUNT
=
5
;
private
final
AtlasStructType
structType
;
private
final
List
<
Object
>
validValues
;
private
final
List
<
Object
>
invalidValues
;
{
AtlasAttributeDef
multiValuedAttribMinMax
=
new
AtlasAttributeDef
(
MULTI_VAL_ATTR_NAME_MIN_MAX
,
ATLAS_TYPE_INT
);
AtlasAttributeDef
multiValuedAttribMin
=
new
AtlasAttributeDef
(
MULTI_VAL_ATTR_NAME_MIN
,
ATLAS_TYPE_INT
);
AtlasAttributeDef
multiValuedAttribMax
=
new
AtlasAttributeDef
(
MULTI_VAL_ATTR_NAME_MAX
,
ATLAS_TYPE_INT
);
multiValuedAttribMinMax
.
setCardinality
(
Cardinality
.
LIST
);
multiValuedAttribMinMax
.
setValuesMinCount
(
MULTI_VAL_ATTR_MIN_COUNT
);
multiValuedAttribMinMax
.
setValuesMaxCount
(
MULTI_VAL_ATTR_MAX_COUNT
);
multiValuedAttribMinMax
.
setCardinality
(
Cardinality
.
SET
);
multiValuedAttribMin
.
setValuesMinCount
(
MULTI_VAL_ATTR_MIN_COUNT
);
multiValuedAttribMinMax
.
setCardinality
(
Cardinality
.
LIST
);
multiValuedAttribMax
.
setValuesMaxCount
(
MULTI_VAL_ATTR_MAX_COUNT
);
AtlasStructDef
structDef
=
ModelTestUtil
.
newStructDef
();
structDef
.
addAttribute
(
multiValuedAttribMinMax
);
structDef
.
addAttribute
(
multiValuedAttribMin
);
structDef
.
addAttribute
(
multiValuedAttribMax
);
structType
=
getStructType
(
structDef
);
validValues
=
new
ArrayList
<
Object
>();
invalidValues
=
new
ArrayList
<
Object
>();
AtlasStruct
invalidValue1
=
structType
.
createDefaultValue
();
AtlasStruct
invalidValue2
=
structType
.
createDefaultValue
();
AtlasStruct
invalidValue3
=
structType
.
createDefaultValue
();
AtlasStruct
invalidValue4
=
structType
.
createDefaultValue
();
AtlasStruct
invalidValue5
=
structType
.
createDefaultValue
();
AtlasStruct
invalidValue6
=
structType
.
createDefaultValue
();
AtlasStruct
invalidValue7
=
structType
.
createDefaultValue
();
// invalid value for int
invalidValue1
.
setAttribute
(
ModelTestUtil
.
getDefaultAttributeName
(
ATLAS_TYPE_INT
),
"xyz"
);
// invalid value for date
invalidValue2
.
setAttribute
(
ModelTestUtil
.
getDefaultAttributeName
(
ATLAS_TYPE_DATE
),
"xyz"
);
// invalid value for bigint
invalidValue3
.
setAttribute
(
ModelTestUtil
.
getDefaultAttributeName
(
ATLAS_TYPE_BIGINTEGER
),
"xyz"
);
// minCount is less than required
invalidValue4
.
setAttribute
(
MULTI_VAL_ATTR_NAME_MIN_MAX
,
new
Integer
[]
{
1
});
// maxCount is more than allowed
invalidValue5
.
setAttribute
(
MULTI_VAL_ATTR_NAME_MIN_MAX
,
new
Integer
[]
{
1
,
2
,
3
,
4
,
5
,
6
});
// minCount is less than required
invalidValue6
.
setAttribute
(
MULTI_VAL_ATTR_NAME_MIN
,
new
Integer
[]
{
});
// maxCount is more than allowed
invalidValue7
.
setAttribute
(
MULTI_VAL_ATTR_NAME_MAX
,
new
Integer
[]
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
});
validValues
.
add
(
null
);
validValues
.
add
(
structType
.
createDefaultValue
());
validValues
.
add
(
structType
.
createDefaultValue
().
getAttributes
());
// Map<String, Object>
invalidValues
.
add
(
invalidValue1
);
invalidValues
.
add
(
invalidValue2
);
invalidValues
.
add
(
invalidValue3
);
invalidValues
.
add
(
invalidValue4
);
invalidValues
.
add
(
invalidValue5
);
invalidValues
.
add
(
invalidValue6
);
invalidValues
.
add
(
invalidValue7
);
invalidValues
.
add
(
new
AtlasStruct
());
// no values for mandatory attributes
invalidValues
.
add
(
new
HashMap
<
Object
,
Object
>());
// no values for mandatory attributes
invalidValues
.
add
(
1
);
// incorrect datatype
invalidValues
.
add
(
new
HashSet
());
// incorrect datatype
invalidValues
.
add
(
new
ArrayList
());
// incorrect datatype
invalidValues
.
add
(
new
String
[]
{});
// incorrect datatype
}
@Test
public
void
testStructTypeDefaultValue
()
{
AtlasStruct
defValue
=
structType
.
createDefaultValue
();
assertNotNull
(
defValue
);
assertEquals
(
defValue
.
getTypeName
(),
structType
.
getTypeName
());
}
@Test
public
void
testStructTypeIsValidValue
()
{
for
(
Object
value
:
validValues
)
{
assertTrue
(
structType
.
isValidValue
(
value
),
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
structType
.
isValidValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testStructTypeGetNormalizedValue
()
{
assertNull
(
structType
.
getNormalizedValue
(
null
),
"value="
+
null
);
for
(
Object
value
:
validValues
)
{
if
(
value
==
null
)
{
continue
;
}
Object
normalizedValue
=
structType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertNull
(
structType
.
getNormalizedValue
(
value
),
"value="
+
value
);
}
}
@Test
public
void
testStructTypeValidateValue
()
{
List
<
String
>
messages
=
new
ArrayList
<
String
>();
for
(
Object
value
:
validValues
)
{
assertTrue
(
structType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertEquals
(
messages
.
size
(),
0
,
"value="
+
value
);
}
for
(
Object
value
:
invalidValues
)
{
assertFalse
(
structType
.
validateValue
(
value
,
"testObj"
,
messages
));
assertTrue
(
messages
.
size
()
>
0
,
"value="
+
value
);
messages
.
clear
();
}
}
private
static
AtlasStructType
getStructType
(
AtlasStructDef
structDef
)
{
try
{
return
new
AtlasStructType
(
structDef
,
ModelTestUtil
.
getTypesRegistry
());
}
catch
(
AtlasBaseException
excp
)
{
return
null
;
}
}
}
pom.xml
View file @
698a5652
...
...
@@ -429,6 +429,7 @@
<javax.servlet.version>
3.1.0
</javax.servlet.version>
<!-- Needed for hooks -->
<aopalliance.version>
1.0
</aopalliance.version>
<codehaus.jackson.version>
1.9.13
</codehaus.jackson.version>
<commons-conf.version>
1.10
</commons-conf.version>
<commons-collections.version>
3.2.2
</commons-collections.version>
<commons-logging.version>
1.1.3
</commons-logging.version>
...
...
@@ -501,6 +502,7 @@
</profiles>
<modules>
<module>
intg
</module>
<module>
common
</module>
<module>
typesystem
</module>
<module>
server-api
</module>
...
...
@@ -999,6 +1001,12 @@
<!-- atlas modules -->
<dependency>
<groupId>
org.apache.atlas
</groupId>
<artifactId>
atlas-intg
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.atlas
</groupId>
<artifactId>
atlas-typesystem
</artifactId>
<version>
${project.version}
</version>
</dependency>
...
...
release-log.txt
View file @
698a5652
...
...
@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1171 Structured, high-level public APIs (mneethiraj via shwethags)
ATLAS-247 Hive Column level lineage (rhbutani,svimal2106 via shwethags)
ATLAS-1184 ReservedTypesRegistrar checks for existence of 1st class type (svimal2106 via shwethags)
ATLAS-1199 Atlas UI not loading after fresh build due to jquery-asBreadcrumbs plugin upgrade (kevalbhatt via shwethags)
...
...
src/build/checkstyle.xml
View file @
698a5652
...
...
@@ -115,7 +115,9 @@
<property
name=
"max"
value=
"120"
/>
</module>
<module
name=
"MethodLength"
/>
<module
name=
"ParameterNumber"
/>
<module
name=
"ParameterNumber"
>
<property
name=
"tokens"
value=
"METHOD_DEF"
/>
</module>
<module
name=
"OuterTypeNumber"
/>
<!-- Checks for whitespace -->
...
...
webapp/pom.xml
View file @
698a5652
...
...
@@ -125,6 +125,11 @@
</dependency>
<dependency>
<groupId>
org.apache.atlas
</groupId>
<artifactId>
atlas-intg
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.hadoop
</groupId>
<artifactId>
hadoop-common
</artifactId>
</dependency>
...
...
webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
0 → 100644
View file @
698a5652
/**
* 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
.
web
.
rest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.PUT
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.Context
;
import
org.apache.atlas.api.PList
;
import
org.apache.atlas.api.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.web.util.Servlets
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
@Path
(
"types"
)
public
class
TypesREST
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
TypesREST
.
class
);
@POST
@Path
(
"/enumdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
createEnumDef
(
AtlasEnumDef
enumDef
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.createEnumDef()
return
ret
;
}
@GET
@Path
(
"/enumdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
getEnumDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.getEnumDefByName(name)
return
ret
;
}
@GET
@Path
(
"/enumdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
getEnumDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.getEnumDefByGuid(guid)
return
ret
;
}
@PUT
@Path
(
"/enumdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
updateEnumDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasEnumDef
enumDef
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.updateEnumDefByName(name, enumDef)
return
ret
;
}
@PUT
@Path
(
"/enumdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
updateEnumDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasEnumDef
enumDef
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.updateEnumDefByGuid(guid, enumDef)
return
ret
;
}
@DELETE
@Path
(
"/enumdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEnumDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteEnumDefByName(name)
}
@DELETE
@Path
(
"/enumdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEnumDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteEnumDefByGuid(guid)
}
@GET
@Path
(
"/enumdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
PList
<
AtlasEnumDef
>
searchEnumDefs
(
@Context
HttpServletRequest
request
)
throws
Exception
{
PList
<
AtlasEnumDef
>
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request);
// TODO: ret = store.searchEnumDefs(filter);
return
ret
;
}
@POST
@Path
(
"/structdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
createStructDef
(
AtlasStructDef
structDef
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.createStructDef()
return
ret
;
}
@GET
@Path
(
"/structdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
getStructDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.getStructDefByName(name)
return
ret
;
}
@GET
@Path
(
"/structdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
getStructDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.getStructDefByGuid(guid)
return
ret
;
}
@PUT
@Path
(
"/structdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
updateStructDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasStructDef
structDef
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.updateStructDefByName(name, structDef)
return
ret
;
}
@PUT
@Path
(
"/structdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
updateStructDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasStructDef
structDef
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.updateStructDefByGuid(guid, structDef)
return
ret
;
}
@DELETE
@Path
(
"/structdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteStructDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteStructDefByName(name)
}
@DELETE
@Path
(
"/structdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteStructDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteStructDefByGuid(guid)
}
@GET
@Path
(
"/structdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
PList
<
AtlasStructDef
>
searchStructDefs
(
@Context
HttpServletRequest
request
)
throws
Exception
{
PList
<
AtlasStructDef
>
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request);
// TODO: ret = store.searchStructDefs(filter);
return
ret
;
}
@POST
@Path
(
"/classificationdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
createClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.createClassificationDef()
return
ret
;
}
@GET
@Path
(
"/classificationdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
getClassificationDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.getClassificationDefByName(name)
return
ret
;
}
@GET
@Path
(
"/classificationdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
getClassificationDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.getClassificationDefByGuid(guid)
return
ret
;
}
@PUT
@Path
(
"/classificationdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
updateClassificationDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasClassificationDef
classificationDef
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.updateClassificationDefByName(name, classificationDef)
return
ret
;
}
@PUT
@Path
(
"/classificationdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
updateClassificationDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasClassificationDef
classificationDef
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.updateClassificationDefByGuid(guid, classificationDef)
return
ret
;
}
@DELETE
@Path
(
"/classificationdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteClassificationDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteClassificationDefByName(name)
}
@DELETE
@Path
(
"/classificationdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteClassificationDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteClassificationDefByGuid(guid)
}
@GET
@Path
(
"/classificationdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
PList
<
AtlasClassificationDef
>
searchClassificationDefs
(
SearchFilter
filter
)
throws
Exception
{
PList
<
AtlasClassificationDef
>
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request);
// TODO: ret = store.searchClassificationDefs(filter);
return
ret
;
}
@POST
@Path
(
"/entitydef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
createEntityDef
(
AtlasEntityDef
entityDef
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.createEntityDef()
return
ret
;
}
@GET
@Path
(
"/entitydef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
getEntityDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.getEntityDefByName(name)
return
ret
;
}
@GET
@Path
(
"/entitydef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
getEntityDefByIdByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.getEntityDefByGuid(guid)
return
ret
;
}
@PUT
@Path
(
"/entitydef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
updateEntityDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasEntityDef
entityDef
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.updateEntityDefByName(name, entityDef)
return
ret
;
}
@PUT
@Path
(
"/entitydef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
updateEntityDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasEntityDef
entityDef
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.updateEntityDefByGuid(guid, entityDef)
return
ret
;
}
@DELETE
@Path
(
"/entitydef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEntityDef
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteEntityDefByName(name)
}
@DELETE
@Path
(
"/entitydef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEntityDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteEntityDefByGuid(guid)
}
@GET
@Path
(
"/entitydef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
PList
<
AtlasEntityDef
>
searchEntityDefs
(
SearchFilter
filter
)
throws
Exception
{
PList
<
AtlasEntityDef
>
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request);
// TODO: ret = store.searchEntityDefs(filter);
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