@@ -29,23 +29,34 @@ class ApiExecutor
2929
3030 /**
3131 * The entity object data being created, updated, or deleted.
32+ *
3233 * @var EntityDataObject $entityObject
3334 */
3435 private $ entityObject ;
3536
3637 /**
3738 * The json definitions used to map the operation.
39+ *
3840 * @var JsonDefinition $jsonDefinition
3941 */
4042 private $ jsonDefinition ;
4143
4244 /**
4345 * The array of dependentEntities this class can be given. When finding linked entities, APIExecutor
4446 * uses this repository before looking for static data.
47+ *
4548 * @var array
4649 */
4750 private $ dependentEntities = [];
4851
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+
4960 /**
5061 * ApiSubObject constructor.
5162 * @param string $operation
@@ -82,7 +93,10 @@ public function executeRequest()
8293
8394 if (!empty ($ matchedParams )) {
8495 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+ );
86100 $ apiClientUrl = str_replace ($ paramValue , $ param , $ apiClientUrl );
87101 }
88102 }
@@ -139,6 +153,7 @@ private function getAuthorizationHeader($authUrl)
139153 private function convertJsonArray ($ entityObject , $ jsonArrayMetadata )
140154 {
141155 $ jsonArray = [];
156+ self ::incrementSequence ($ entityObject ->getName ());
142157
143158 foreach ($ jsonArrayMetadata as $ jsonElement ) {
144159 if ($ jsonElement ->getType () == JsonObjectExtractor::JSON_OBJECT_OBJ_NAME ) {
@@ -149,23 +164,21 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
149164 $ jsonElementType = $ jsonElement ->getValue ();
150165
151166 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 ;
167179 }
168180 }
181+
169182 $ jsonArray [$ jsonElement ->getKey ()] = $ this ->castValue ($ jsonElementType , $ elementData );
170183 } else {
171184 $ entityNamesOfType = $ entityObject ->getLinkedEntitiesOfType ($ jsonElementType );
@@ -242,6 +255,35 @@ public function getEncodedJsonString()
242255 return json_encode ($ jsonMetadataArray , JSON_PRETTY_PRINT );
243256 }
244257
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+
245287 // @codingStandardsIgnoreStart
246288 /**
247289 * This function takes a string value and its corresponding type and returns the string cast
0 commit comments