46
46
import org .apache .jena .vocabulary .XSD ;
47
47
import org .eclipse .esmf .aspectmodel .generator .AbstractGenerator ;
48
48
import org .eclipse .esmf .aspectmodel .generator .NumericTypeTraits ;
49
- import org .eclipse .esmf .aspectmodel .vocabulary .SAMM ;
50
- import org .jeasy .random .EasyRandom ;
51
- import org .jeasy .random .EasyRandomParameters ;
52
-
53
- import com .fasterxml .jackson .databind .ObjectMapper ;
54
- import com .fasterxml .jackson .databind .SerializationFeature ;
55
- import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
56
- import com .github .curiousoddman .rgxgen .RgxGen ;
57
- import com .google .common .collect .ImmutableList ;
58
- import com .google .common .collect .ImmutableMap ;
59
-
60
49
import org .eclipse .esmf .aspectmodel .jackson .AspectModelJacksonModule ;
61
50
import org .eclipse .esmf .aspectmodel .resolver .services .DataType ;
62
51
import org .eclipse .esmf .characteristic .Collection ;
68
57
import org .eclipse .esmf .constraint .RangeConstraint ;
69
58
import org .eclipse .esmf .constraint .RegularExpressionConstraint ;
70
59
import org .eclipse .esmf .metamodel .AbstractEntity ;
71
- import org .eclipse .esmf .metamodel .Aspect ;
72
- import org .eclipse .esmf .metamodel .AspectContext ;
73
60
import org .eclipse .esmf .metamodel .Characteristic ;
74
61
import org .eclipse .esmf .metamodel .ComplexType ;
75
62
import org .eclipse .esmf .metamodel .Constraint ;
76
63
import org .eclipse .esmf .metamodel .Entity ;
64
+ import org .eclipse .esmf .metamodel .ExtendedAspectContext ;
77
65
import org .eclipse .esmf .metamodel .Property ;
78
66
import org .eclipse .esmf .metamodel .Scalar ;
79
67
import org .eclipse .esmf .metamodel .ScalarValue ;
80
68
import org .eclipse .esmf .metamodel .Type ;
81
69
import org .eclipse .esmf .metamodel .Value ;
82
70
import org .eclipse .esmf .metamodel .datatypes .Curie ;
83
71
import org .eclipse .esmf .metamodel .impl .BoundDefinition ;
72
+ import org .jeasy .random .EasyRandom ;
73
+ import org .jeasy .random .EasyRandomParameters ;
74
+
75
+ import com .fasterxml .jackson .databind .ObjectMapper ;
76
+ import com .fasterxml .jackson .databind .SerializationFeature ;
77
+ import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
78
+ import com .github .curiousoddman .rgxgen .RgxGen ;
79
+ import com .google .common .collect .ImmutableList ;
80
+ import com .google .common .collect .ImmutableMap ;
84
81
85
82
public class AspectModelJsonPayloadGenerator extends AbstractGenerator {
86
83
/**
@@ -90,27 +87,20 @@ public class AspectModelJsonPayloadGenerator extends AbstractGenerator {
90
87
private static final String EITHER_LEFT = "left" ;
91
88
private static final double THRESHOLD = .0001 ;
92
89
93
- private final Aspect aspect ;
94
90
private final List <Transformer > transformers ;
95
91
private final ExampleValueGenerator exampleValueGenerator ;
96
92
private final ObjectMapper objectMapper ;
97
93
private final List <Property > recursiveProperty ;
98
94
private final ValueToPayloadStructure valueToPayloadStructure = new ValueToPayloadStructure ();
99
95
100
- public AspectModelJsonPayloadGenerator ( final Aspect aspect ) {
101
- this ( aspect , new SAMM ( aspect .getMetaModelVersion () ), new Random () );
102
- }
103
-
104
- public AspectModelJsonPayloadGenerator ( final AspectContext context ) {
105
- this ( context .aspect () );
106
- }
107
-
108
- public AspectModelJsonPayloadGenerator ( final Aspect aspect , final Random randomStrategy ) {
109
- this ( aspect , new SAMM ( aspect .getMetaModelVersion () ), randomStrategy );
96
+ private final ExtendedAspectContext context ;
97
+
98
+ public AspectModelJsonPayloadGenerator ( final ExtendedAspectContext context ) {
99
+ this ( context , new Random () );
110
100
}
111
101
112
- private AspectModelJsonPayloadGenerator ( final Aspect aspect , final SAMM samm , final Random randomStrategy ) {
113
- this .aspect = aspect ;
102
+ public AspectModelJsonPayloadGenerator ( final ExtendedAspectContext context , final Random randomStrategy ) {
103
+ this .context = context ;
114
104
exampleValueGenerator = new ExampleValueGenerator ( randomStrategy );
115
105
objectMapper = AspectModelJsonPayloadGenerator .createObjectMapper ();
116
106
objectMapper .configure ( SerializationFeature .FAIL_ON_EMPTY_BEANS , false );
@@ -129,7 +119,7 @@ private AspectModelJsonPayloadGenerator( final Aspect aspect, final SAMM samm, f
129
119
* @param nameMapper The callback function that maps the Aspect name to an OutputStream
130
120
*/
131
121
public void generateJson ( final Function <String , OutputStream > nameMapper ) throws IOException {
132
- try ( final OutputStream output = nameMapper .apply ( aspect .getName () ) ) {
122
+ try ( final OutputStream output = nameMapper .apply ( context . aspect () .getName () ) ) {
133
123
output .write ( generateJson ().getBytes () );
134
124
}
135
125
}
@@ -140,7 +130,7 @@ public void generateJson( final Function<String, OutputStream> nameMapper ) thro
140
130
* @see #generateJson(Function)
141
131
*/
142
132
public void generateJsonPretty ( final Function <String , OutputStream > nameMapper ) throws IOException {
143
- try ( final OutputStream output = nameMapper .apply ( aspect .getName () ) ) {
133
+ try ( final OutputStream output = nameMapper .apply ( context . aspect () .getName () ) ) {
144
134
output .write ( generateJsonPretty ().getBytes () );
145
135
}
146
136
}
@@ -162,7 +152,7 @@ private static ObjectMapper createObjectMapper() {
162
152
}
163
153
164
154
private Map <String , Object > transformAspectProperties () {
165
- return transformProperties ( aspect .getProperties () );
155
+ return transformProperties ( context . aspect () .getProperties () );
166
156
}
167
157
168
158
/**
@@ -228,7 +218,7 @@ private Map<String, Object> transformAbstractEntityProperty( final BasicProperty
228
218
final Optional <AbstractEntity > dataType = getForCharacteristic ( property .getCharacteristic (), AbstractEntity .class );
229
219
if ( dataType .isPresent () ) {
230
220
final AbstractEntity abstractEntity = dataType .get ();
231
- final ComplexType extendingComplexType = abstractEntity .getExtendingElements ().get ( 0 );
221
+ final ComplexType extendingComplexType = abstractEntity .getExtendingElements ( context ).get ( 0 );
232
222
final Map <String , Object > generatedProperties = transformProperties ( extendingComplexType .getAllProperties () );
233
223
generatedProperties .put ( "@type" , extendingComplexType .getName () );
234
224
return toMap ( property .getName (), generatedProperties );
@@ -304,7 +294,7 @@ private List<Object> getCollectionValues( final BasicProperty property, final Co
304
294
final Type dataType = collection .getDataType ().orElseThrow ( () -> new IllegalArgumentException ( "DataType for collection is required." ) );
305
295
if ( dataType .is ( AbstractEntity .class ) ) {
306
296
final AbstractEntity abstractEntity = dataType .as ( AbstractEntity .class );
307
- final ComplexType extendingComplexType = abstractEntity .getExtendingElements ().get ( 0 );
297
+ final ComplexType extendingComplexType = abstractEntity .getExtendingElements ( context ).get ( 0 );
308
298
final Map <String , Object > propertyValueMap = transformProperties ( extendingComplexType .getAllProperties () );
309
299
propertyValueMap .put ( "@type" , extendingComplexType .getName () );
310
300
return ImmutableList .of ( propertyValueMap );
0 commit comments