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
4d601907
Commit
4d601907
authored
Dec 18, 2014
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support ReferenceableInstance json serialization
parent
e05c8845
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
9 deletions
+75
-9
Id.java
src/main/java/org/apache/metadata/storage/Id.java
+8
-1
ClassType.java
src/main/java/org/apache/metadata/types/ClassType.java
+6
-2
Serialization.scala
src/main/scala/org/apache/metadata/json/Serialization.scala
+0
-0
SerializationTest.scala
...st/scala/org/apache/metadata/json/SerializationTest.scala
+61
-6
No files found.
src/main/java/org/apache/metadata/storage/Id.java
View file @
4d601907
...
@@ -21,9 +21,11 @@ package org.apache.metadata.storage;
...
@@ -21,9 +21,11 @@ package org.apache.metadata.storage;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
org.apache.metadata.IReferenceableInstance
;
import
org.apache.metadata.IReferenceableInstance
;
import
org.apache.metadata.IStruct
;
import
org.apache.metadata.IStruct
;
import
org.apache.metadata.ITypedReferenceableInstance
;
import
org.apache.metadata.MetadataException
;
import
org.apache.metadata.MetadataException
;
import
org.apache.metadata.types.FieldMapping
;
public
class
Id
implements
IReferenceableInstance
{
public
class
Id
implements
I
Typed
ReferenceableInstance
{
public
final
long
id
;
public
final
long
id
;
public
final
String
className
;
public
final
String
className
;
...
@@ -76,4 +78,9 @@ public class Id implements IReferenceableInstance {
...
@@ -76,4 +78,9 @@ public class Id implements IReferenceableInstance {
public
void
set
(
String
attrName
,
Object
val
)
throws
MetadataException
{
public
void
set
(
String
attrName
,
Object
val
)
throws
MetadataException
{
throw
new
MetadataException
(
"Get/Set not supported on an Id object"
);
throw
new
MetadataException
(
"Get/Set not supported on an Id object"
);
}
}
@Override
public
FieldMapping
fieldMapping
()
{
return
null
;
}
}
}
src/main/java/org/apache/metadata/types/ClassType.java
View file @
4d601907
...
@@ -153,8 +153,12 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
...
@@ -153,8 +153,12 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
return
createInstance
(
null
);
return
createInstance
(
null
);
}
}
public
ITypedReferenceableInstance
createInstance
(
Id
id
)
throws
MetadataException
{
public
ITypedReferenceableInstance
createInstance
(
String
...
traitNames
)
throws
MetadataException
{
return
createInstanceWithTraits
(
id
,
null
);
return
createInstance
(
null
,
traitNames
);
}
public
ITypedReferenceableInstance
createInstance
(
Id
id
,
String
...
traitNames
)
throws
MetadataException
{
return
createInstanceWithTraits
(
id
,
null
,
traitNames
);
}
}
public
ITypedReferenceableInstance
createInstanceWithTraits
(
Id
id
,
Referenceable
r
,
String
...
traitNames
)
public
ITypedReferenceableInstance
createInstanceWithTraits
(
Id
id
,
Referenceable
r
,
String
...
traitNames
)
...
...
src/main/scala/org/apache/metadata/json/Serialization.scala
View file @
4d601907
This diff is collapsed.
Click to expand it.
src/test/scala/org/apache/metadata/json/SerializationTest.scala
View file @
4d601907
...
@@ -19,9 +19,8 @@
...
@@ -19,9 +19,8 @@
package
org.apache.metadata.json
package
org.apache.metadata.json
import
com.google.common.collect.ImmutableList
import
com.google.common.collect.ImmutableList
import
org.apache.metadata.
{
ITypedStruct
,
Struct
,
BaseTest
}
import
org.apache.metadata._
import
org.apache.metadata.storage.StructInstance
import
org.apache.metadata.storage.
{
ReferenceableInstance
,
StructInstance
}
import
org.apache.metadata.storage.StructInstance
import
org.apache.metadata.types._
import
org.apache.metadata.types._
import
org.json4s.NoTypeHints
import
org.json4s.NoTypeHints
import
org.junit.Before
import
org.junit.Before
...
@@ -29,7 +28,7 @@ import org.junit.Test
...
@@ -29,7 +28,7 @@ import org.junit.Test
import
org.junit.Assert
import
org.junit.Assert
import
org.json4s._
import
org.json4s._
import
org.json4s.native.Serialization.
{
read
,
write
=>
swrite
}
import
org.json4s.native.Serialization.
{
write
=>
swrite
,
_
}
import
org.json4s.native.JsonMethods._
import
org.json4s.native.JsonMethods._
class
SerializationTest
extends
BaseTest
{
class
SerializationTest
extends
BaseTest
{
...
@@ -51,7 +50,7 @@ class SerializationTest extends BaseTest {
...
@@ -51,7 +50,7 @@ class SerializationTest extends BaseTest {
Assert
.
assertEquals
(
ts
.
toString
,
"{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tWed Dec 10 18:35:58 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.1, 1.1]\n\to : \t{b=2.0, a=1.0}\n}"
)
Assert
.
assertEquals
(
ts
.
toString
,
"{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tWed Dec 10 18:35:58 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.1, 1.1]\n\to : \t{b=2.0, a=1.0}\n}"
)
implicit
val
formats
=
org
.
json4s
.
native
.
Serialization
.
formats
(
NoTypeHints
)
+
new
TypedStructSerializer
+
implicit
val
formats
=
org
.
json4s
.
native
.
Serialization
.
formats
(
NoTypeHints
)
+
new
TypedStructSerializer
+
new
BigDecimalSerializer
+
new
BigIntegerSerializer
new
BigDecimalSerializer
+
new
BigIntegerSerializer
//Json representation
//Json representation
val
ser
=
swrite
(
ts
)
val
ser
=
swrite
(
ts
)
...
@@ -126,4 +125,59 @@ class SerializationTest extends BaseTest {
...
@@ -126,4 +125,59 @@ class SerializationTest extends BaseTest {
// Typed Struct read from string:
// Typed Struct read from string:
Assert
.
assertEquals
(
ts1
.
toString
,
"{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}"
)
Assert
.
assertEquals
(
ts1
.
toString
,
"{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}"
)
}
}
}
@Test
def
testClass
{
val
ts
:
TypeSystem
=
ms
.
getTypeSystem
val
deptTypeDef
:
HierarchicalTypeDefinition
[
ClassType
]
=
createClassTypeDef
(
"Department"
,
ImmutableList
.
of
[
String
],
BaseTest
.
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"employees"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
true
,
"department"
))
val
personTypeDef
:
HierarchicalTypeDefinition
[
ClassType
]
=
createClassTypeDef
(
"Person"
,
ImmutableList
.
of
[
String
],
BaseTest
.
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"department"
,
"Department"
,
Multiplicity
.
REQUIRED
,
false
,
"employees"
),
new
AttributeDefinition
(
"manager"
,
"Manager"
,
Multiplicity
.
OPTIONAL
,
false
,
"subordinates"
))
val
managerTypeDef
:
HierarchicalTypeDefinition
[
ClassType
]
=
createClassTypeDef
(
"Manager"
,
ImmutableList
.
of
[
String
](
"Person"
),
new
AttributeDefinition
(
"subordinates"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
false
,
"manager"
))
val
securityClearanceTypeDef
:
HierarchicalTypeDefinition
[
TraitType
]
=
createTraitTypeDef
(
"SecurityClearance"
,
ImmutableList
.
of
[
String
],
BaseTest
.
createRequiredAttrDef
(
"level"
,
DataTypes
.
INT_TYPE
))
ts
.
defineTypes
(
ImmutableList
.
of
[
StructTypeDefinition
],
ImmutableList
.
of
[
HierarchicalTypeDefinition
[
TraitType
]](
securityClearanceTypeDef
),
ImmutableList
.
of
[
HierarchicalTypeDefinition
[
ClassType
]](
deptTypeDef
,
personTypeDef
,
managerTypeDef
)
)
val
hrDept
:
Referenceable
=
new
Referenceable
(
"Department"
)
val
john
:
Referenceable
=
new
Referenceable
(
"Person"
)
val
jane
:
Referenceable
=
new
Referenceable
(
"Manager"
,
"SecurityClearance"
)
hrDept
.
set
(
"name"
,
"hr"
)
john
.
set
(
"name"
,
"John"
)
john
.
set
(
"department"
,
hrDept
)
jane
.
set
(
"name"
,
"Jane"
)
jane
.
set
(
"department"
,
hrDept
)
john
.
set
(
"manager"
,
jane
)
hrDept
.
set
(
"employees"
,
ImmutableList
.
of
[
Referenceable
](
john
,
jane
))
jane
.
set
(
"subordinates"
,
ImmutableList
.
of
[
Referenceable
](
john
))
jane
.
getTrait
(
"SecurityClearance"
).
set
(
"level"
,
1
)
val
deptType
:
ClassType
=
ts
.
getDataType
(
classOf
[
ClassType
],
"Department"
)
val
hrDept2
:
ITypedReferenceableInstance
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
)
println
(
s
"HR Dept Object Graph:\n${hrDept2}\n"
)
implicit
val
formats
=
org
.
json4s
.
native
.
Serialization
.
formats
(
NoTypeHints
)
+
new
TypedStructSerializer
+
new
TypedReferenceableInstanceSerializer
+
new
BigDecimalSerializer
+
new
BigIntegerSerializer
val
ser
=
swrite
(
hrDept2
)
println
(
s
"HR Dept JSON:\n${pretty(render(parse(ser)))}\n"
)
println
(
s
"HR Dept Object Graph read from JSON:${read[ReferenceableInstance](ser)}\n"
)
}
}
\ No newline at end of file
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