@@ -29,23 +29,34 @@ class ApiExecutor
29
29
30
30
/**
31
31
* The entity object data being created, updated, or deleted.
32
+ *
32
33
* @var EntityDataObject $entityObject
33
34
*/
34
35
private $ entityObject ;
35
36
36
37
/**
37
38
* The json definitions used to map the operation.
39
+ *
38
40
* @var JsonDefinition $jsonDefinition
39
41
*/
40
42
private $ jsonDefinition ;
41
43
42
44
/**
43
45
* The array of dependentEntities this class can be given. When finding linked entities, APIExecutor
44
46
* uses this repository before looking for static data.
47
+ *
45
48
* @var array
46
49
*/
47
50
private $ dependentEntities = [];
48
51
52
+ /**
53
+ * The array of entity name and number of objects being created,
54
+ * we don't need to track objects in update and delete operations.
55
+ *
56
+ * @var array
57
+ */
58
+ private static $ entitySequences = [];
59
+
49
60
/**
50
61
* ApiSubObject constructor.
51
62
* @param string $operation
@@ -82,7 +93,10 @@ public function executeRequest()
82
93
83
94
if (!empty ($ matchedParams )) {
84
95
foreach ($ matchedParams [0 ] as $ paramKey => $ paramValue ) {
85
- $ param = $ this ->entityObject ->getDataByName ($ matchedParams [1 ][$ paramKey ]);
96
+ $ param = $ this ->entityObject ->getDataByName (
97
+ $ matchedParams [1 ][$ paramKey ],
98
+ EntityDataObject::CEST_UNIQUE_VALUE
99
+ );
86
100
$ apiClientUrl = str_replace ($ paramValue , $ param , $ apiClientUrl );
87
101
}
88
102
}
@@ -139,6 +153,7 @@ private function getAuthorizationHeader($authUrl)
139
153
private function convertJsonArray ($ entityObject , $ jsonArrayMetadata )
140
154
{
141
155
$ jsonArray = [];
156
+ self ::incrementSequence ($ entityObject ->getName ());
142
157
143
158
foreach ($ jsonArrayMetadata as $ jsonElement ) {
144
159
if ($ jsonElement ->getType () == JsonObjectExtractor::JSON_OBJECT_OBJ_NAME ) {
@@ -149,23 +164,21 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
149
164
$ jsonElementType = $ jsonElement ->getValue ();
150
165
151
166
if (in_array ($ jsonElementType , ApiExecutor::PRIMITIVE_TYPES )) {
152
- $ elementData = $ entityObject ->getDataByName ($ jsonElement ->getKey ());
153
- $ elementUniquenessData = $ entityObject ->getUniquenessDataByName ($ jsonElement ->getKey ());
154
- if ($ elementUniquenessData ) {
155
- if ($ elementUniquenessData == 'prefix ' ) {
156
- if (DataObjectHandler::UNIQUENESS_FUNCTION == 'msq ' ) {
157
- $ elementData = msq ($ entityObject ->getName ().'. ' . $ jsonElement ->getKey ()).$ elementData ;
158
- } elseif (DataObjectHandler::UNIQUENESS_FUNCTION == 'msqs ' ) {
159
- $ elementData = msqs ($ entityObject ->getName ().'. ' . $ jsonElement ->getKey ()).$ elementData ;
160
- }
161
- } elseif ($ elementUniquenessData == 'suffix ' ) {
162
- if (DataObjectHandler::UNIQUENESS_FUNCTION == 'msq ' ) {
163
- $ elementData .= msq ($ entityObject ->getName () . '. ' . $ jsonElement ->getKey ());
164
- } elseif (DataObjectHandler::UNIQUENESS_FUNCTION == 'msqs ' ) {
165
- $ elementData .= msqs ($ entityObject ->getName () . '. ' . $ jsonElement ->getKey ());
166
- }
167
+ $ elementData = $ entityObject ->getDataByName (
168
+ $ jsonElement ->getKey (),
169
+ EntityDataObject::CEST_UNIQUE_VALUE
170
+ );
171
+
172
+ if (array_key_exists ($ jsonElement ->getKey (), $ entityObject ->getUniquenessData ())) {
173
+ $ uniqueData = $ entityObject ->getUniquenessDataByName ($ jsonElement ->getKey ());
174
+ if ($ uniqueData === 'suffix ' ) {
175
+ $ elementData .= (string )self ::getSequence ($ entityObject ->getName ());
176
+ } else {
177
+ $ elementData = (string )self ::getSequence ($ entityObject ->getName ())
178
+ . $ elementData ;
167
179
}
168
180
}
181
+
169
182
$ jsonArray [$ jsonElement ->getKey ()] = $ this ->castValue ($ jsonElementType , $ elementData );
170
183
} else {
171
184
$ entityNamesOfType = $ entityObject ->getLinkedEntitiesOfType ($ jsonElementType );
@@ -242,6 +255,35 @@ public function getEncodedJsonString()
242
255
return json_encode ($ jsonMetadataArray , JSON_PRETTY_PRINT );
243
256
}
244
257
258
+ /**
259
+ * Increment an entity's sequence number by 1.
260
+ *
261
+ * @param string $entityName
262
+ * @return void
263
+ */
264
+ private static function incrementSequence ($ entityName )
265
+ {
266
+ if (array_key_exists ($ entityName , self ::$ entitySequences )) {
267
+ self ::$ entitySequences [$ entityName ]++;
268
+ } else {
269
+ self ::$ entitySequences [$ entityName ] = 1 ;
270
+ }
271
+ }
272
+
273
+ /**
274
+ * Get the current sequence number for an entity.
275
+ *
276
+ * @param string $entityName
277
+ * @return int
278
+ */
279
+ private static function getSequence ($ entityName )
280
+ {
281
+ if (array_key_exists ($ entityName , self ::$ entitySequences )) {
282
+ return self ::$ entitySequences [$ entityName ];
283
+ }
284
+ return 0 ;
285
+ }
286
+
245
287
// @codingStandardsIgnoreStart
246
288
/**
247
289
* This function takes a string value and its corresponding type and returns the string cast
0 commit comments