Skip to content

Commit

Permalink
Merge branch 'development' into feature/CONNECTOR-136/up-download-end…
Browse files Browse the repository at this point in the history
…points
  • Loading branch information
WilcoLouwerse committed Nov 19, 2024
2 parents cc823cf + 15eff74 commit 1494be2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
16 changes: 10 additions & 6 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function __construct(
*/
public function synchronize(Synchronization $synchronization, ?bool $isTest = false): array
{
if (empty($synchronization->getSourceId()) === true) {
throw new Exception('sourceId of synchronziation cannot be empty. Canceling synchronization..');
}

$objectList = $this->getAllObjectsFromSource(synchronization: $synchronization, isTest: $isTest);

Expand Down Expand Up @@ -151,7 +154,7 @@ private function getOriginId(Synchronization $synchronization, array $object): i
$sourceConfig = $synchronization->getSourceConfig();

// Check if a custom ID position is defined in the source configuration
if (isset($sourceConfig['idPosition']) === true) {
if (isset($sourceConfig['idPosition']) === true && empty($sourceConfig['idPosition']) === false) {
// Override default with custom ID position from config
$originIdPosition = $sourceConfig['idPosition'];
}
Expand Down Expand Up @@ -391,19 +394,21 @@ public function getAllObjectsFromApi(Synchronization $synchronization, ?bool $is

// Current page is 2 because the first call made above is page 1.
$currentPage = 2;
$usedNextEndpoint = false;
$useNextEndpoint = false;
if (array_key_exists('next', $body)) {
$useNextEndpoint = true;
}


// Continue making API calls if there are more pages from 'next' the response body or if paginationQuery is set
while($nextEndpoint = $this->getNextEndpoint(body: $body, url: $source->getLocation(), sourceConfig: $sourceConfig, currentPage: $currentPage)) {
$usedNextEndpoint = true;
while($useNextEndpoint === true && $nextEndpoint = $this->getNextEndpoint(body: $body, url: $source->getLocation(), sourceConfig: $sourceConfig, currentPage: $currentPage)) {
// Do not pass $config here becuase it overwrites the query attached to nextEndpoint
$response = $this->callService->call(source: $source, endpoint: $nextEndpoint)->getResponse();
$body = json_decode($response['body'], true);
$objects = array_merge($objects, $this->getAllObjectsFromArray($body, $synchronization));
}

if ($usedNextEndpoint === false) {
if ($useNextEndpoint === false) {
do {
$config = $this->getNextPage(config: $config, sourceConfig: $sourceConfig, currentPage: $currentPage);
$response = $this->callService->call(source: $source, endpoint: $endpoint, method: 'GET', config: $config)->getResponse();
Expand Down Expand Up @@ -523,7 +528,6 @@ public function getAllObjectsFromArray(array $array, Synchronization $synchroniz
*/
public function getNextlinkFromCall(array $body): ?string
{
// Check if the 'next' key exists in the response body
return $body['next'] ?? null;
}
}
2 changes: 2 additions & 0 deletions src/services/getValidISOstring.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Converts a given date string or Date object to a valid ISO string.
*
* this function can double as a validator for ISO / date strings
*
* If the dateString is valid it will return the ISO string,
* if it is not a valid dateString it will return null.
*
Expand Down
6 changes: 4 additions & 2 deletions src/views/Job/JobDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ import { jobStore, navigationStore, logStore } from '../../store/store.js'
<div class="gridContent">
<b>Next Run:</b>
<p>
{{ new Date(jobStore.jobItem.nextRun).toLocaleString() || 'N/A' }}
{{ getValidISOstring(jobStore.jobItem.nextRun) ? new Date(jobStore.jobItem.nextRun).toLocaleString() : 'N/A' }}
</p>
</div>
<div class="gridContent">
<b>Last Run:</b>
<p>
{{ new Date(jobStore.jobItem.lastRun).toLocaleString() || 'N/A' }}
{{ getValidISOstring(jobStore.jobItem.lastRun) ? new Date(jobStore.jobItem.lastRun).toLocaleString() : 'N/A' }}
</p>
</div>
</div>
Expand Down Expand Up @@ -195,6 +195,8 @@ import Update from 'vue-material-design-icons/Update.vue'
import Sync from 'vue-material-design-icons/Sync.vue'
import EyeOutline from 'vue-material-design-icons/EyeOutline.vue'
import getValidISOstring from '../../services/getValidISOstring.js'
export default {
name: 'JobDetails',
components: {
Expand Down

0 comments on commit 1494be2

Please sign in to comment.