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
2fbea9f2
Commit
2fbea9f2
authored
Oct 16, 2018
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2922: Multiplicity computation updated for SET/optional
parent
c6aaef08
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
41 deletions
+76
-41
AtlasStructDef.java
...n/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+1
-0
AtlasTypeUtil.java
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
+8
-11
Multiplicity.java
.../java/org/apache/atlas/v1/model/typedef/Multiplicity.java
+12
-6
TestMultiplicity.java
...src/test/java/org/apache/atlas/type/TestMultiplicity.java
+54
-0
AtlasStructDefStoreV2.java
...tlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
+1
-24
No files found.
intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
View file @
2fbea9f2
...
...
@@ -441,6 +441,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
}
@JsonIgnore
public
boolean
isSoftReferenced
()
{
return
this
.
options
!=
null
&&
getOptions
().
containsKey
(
AtlasAttributeDef
.
ATTRDEF_OPTION_SOFT_REFERENCE
)
&&
...
...
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
View file @
2fbea9f2
...
...
@@ -482,11 +482,15 @@ public class AtlasTypeUtil {
ret
.
setDefaultValue
(
attributeDef
.
getDefaultValue
());
ret
.
setDescription
(
attributeDef
.
getDescription
());
ret
.
setOptions
(
attributeDef
.
getOptions
());
ret
.
setMultiplicity
(
getMultiplicity
(
attributeDef
));
final
int
lower
;
final
int
upper
;
return
ret
;
}
if
(
attributeDef
.
getCardinality
()
==
AtlasAttributeDef
.
Cardinality
.
SINGLE
)
{
public
static
Multiplicity
getMultiplicity
(
AtlasAttributeDef
attributeDef
)
{
int
lower
;
int
upper
;
if
(
attributeDef
.
getCardinality
()
==
Cardinality
.
SINGLE
)
{
lower
=
attributeDef
.
getIsOptional
()
?
0
:
1
;
upper
=
1
;
}
else
{
...
...
@@ -499,14 +503,7 @@ public class AtlasTypeUtil {
upper
=
attributeDef
.
getValuesMaxCount
()
<
2
?
Integer
.
MAX_VALUE
:
attributeDef
.
getValuesMaxCount
();
}
Multiplicity
multiplicity
=
new
Multiplicity
();
multiplicity
.
setLower
(
lower
);
multiplicity
.
setUpper
(
upper
);
multiplicity
.
setIsUnique
(
AtlasAttributeDef
.
Cardinality
.
SET
.
equals
(
attributeDef
.
getCardinality
()));
ret
.
setMultiplicity
(
multiplicity
);
return
ret
;
return
new
Multiplicity
(
lower
,
upper
,
Cardinality
.
SET
.
equals
(
attributeDef
.
getCardinality
()));
}
public
static
Map
<
String
,
Object
>
toMap
(
AtlasEntity
entity
)
{
...
...
intg/src/main/java/org/apache/atlas/v1/model/typedef/Multiplicity.java
View file @
2fbea9f2
...
...
@@ -125,15 +125,21 @@ public class Multiplicity implements Serializable {
@Override
public
void
serialize
(
Multiplicity
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
{
if
(
value
!=
null
)
{
if
(
value
.
equals
(
Multiplicity
.
REQUIRED
))
{
jgen
.
writeString
(
"required"
);
}
else
if
(
value
.
equals
(
Multiplicity
.
OPTIONAL
)
)
{
jgen
.
writeString
(
"optional"
)
;
final
String
serializedValue
;
if
(
value
.
getLower
()
<
1
)
{
serializedValue
=
"optional"
;
}
else
if
(
value
.
equals
(
Multiplicity
.
COLLECTION
))
{
jgen
.
writeString
(
"collection"
)
;
serializedValue
=
"collection"
;
}
else
if
(
value
.
equals
(
Multiplicity
.
SET
))
{
jgen
.
writeString
(
"set"
);
serializedValue
=
"set"
;
}
else
if
(
value
.
equals
(
Multiplicity
.
REQUIRED
))
{
serializedValue
=
"required"
;
}
else
{
// default value
serializedValue
=
"required"
;
}
jgen
.
writeString
(
serializedValue
);
}
}
}
...
...
intg/src/test/java/org/apache/atlas/type/TestMultiplicity.java
0 → 100644
View file @
2fbea9f2
/**
* 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.AtlasStructDef
;
import
org.apache.atlas.v1.model.typedef.AttributeDefinition
;
import
org.apache.atlas.v1.model.typedef.Multiplicity
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
public
class
TestMultiplicity
{
@Test
public
void
verify
()
{
assertMultiplicity
(
AtlasStructDef
.
AtlasAttributeDef
.
Cardinality
.
SINGLE
,
false
,
1
,
1
);
assertMultiplicity
(
AtlasStructDef
.
AtlasAttributeDef
.
Cardinality
.
LIST
,
false
,
1
,
Integer
.
MAX_VALUE
);
assertMultiplicity
(
AtlasStructDef
.
AtlasAttributeDef
.
Cardinality
.
SET
,
true
,
0
,
Integer
.
MAX_VALUE
);
}
private
void
assertMultiplicity
(
AtlasStructDef
.
AtlasAttributeDef
.
Cardinality
cardinality
,
boolean
optionality
,
int
expectedLower
,
int
expectedUpper
)
{
AtlasStructDef
.
AtlasAttributeDef
attributeDef
=
new
AtlasStructDef
.
AtlasAttributeDef
();
attributeDef
.
setCardinality
(
cardinality
);
attributeDef
.
setIsOptional
(
optionality
);
Multiplicity
multiplicity
=
AtlasTypeUtil
.
getMultiplicity
(
attributeDef
);
assertNotNull
(
multiplicity
);
assertEquals
(
multiplicity
.
getLower
(),
expectedLower
);
assertEquals
(
multiplicity
.
getUpper
(),
expectedUpper
);
AttributeDefinition
attributeDefinition
=
new
AttributeDefinition
();
attributeDefinition
.
setMultiplicity
(
multiplicity
);
assertNotNull
(
AtlasType
.
toJson
(
attributeDefinition
));
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
View file @
2fbea9f2
...
...
@@ -585,29 +585,6 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
return
ret
;
}
public
static
Multiplicity
getMultiplicity
(
AtlasAttributeDef
attributeDef
)
{
final
int
lower
;
final
int
upper
;
final
boolean
isUnique
=
AtlasAttributeDef
.
Cardinality
.
SET
.
equals
(
attributeDef
.
getCardinality
());
if
(
attributeDef
.
getCardinality
()
==
AtlasAttributeDef
.
Cardinality
.
SINGLE
)
{
lower
=
attributeDef
.
getIsOptional
()
?
0
:
1
;
upper
=
1
;
}
else
{
if
(
attributeDef
.
getIsOptional
())
{
lower
=
0
;
}
else
{
lower
=
attributeDef
.
getValuesMinCount
()
<
1
?
1
:
attributeDef
.
getValuesMinCount
();
}
upper
=
attributeDef
.
getValuesMaxCount
()
<
2
?
Integer
.
MAX_VALUE
:
attributeDef
.
getValuesMaxCount
();
}
Multiplicity
ret
=
new
Multiplicity
(
lower
,
upper
,
isUnique
);
return
ret
;
}
public
static
AttributeDefinition
toAttributeDefinition
(
AtlasAttribute
attribute
)
{
final
AtlasAttributeDef
attrDef
=
attribute
.
getAttributeDef
();
...
...
@@ -615,7 +592,7 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
ret
.
setName
(
attrDef
.
getName
());
ret
.
setDataTypeName
(
attrDef
.
getTypeName
());
ret
.
setMultiplicity
(
getMultiplicity
(
attrDef
));
ret
.
setMultiplicity
(
AtlasTypeUtil
.
getMultiplicity
(
attrDef
));
ret
.
setIsComposite
(
attribute
.
isOwnedRef
());
ret
.
setIsUnique
(
attrDef
.
getIsUnique
());
ret
.
setIsIndexable
(
attrDef
.
getIsIndexable
());
...
...
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