java.lang.Object
io.smint.clapi.consumer.integration.core.jobs.impl.DefaultSyncJob
All Implemented Interfaces:
ISyncJob

public class DefaultSyncJob extends Object implements ISyncJob
Implements a job that can be scheduled or called on-demand to drive the synchronization process.

This default implementation will connect to the Smint.io platform, prepare all data to be synchronized and pass the data to an instance of ISyncTarget.

No synchronization between jobs are performed. No job knows any other job. The creator must take care of it.

Semaphores are used to guarantee, that only a single synchronization job is running per tenant at a time. New tasks are waiting for the currently running task to complete and will be added to a waiting queue. As soon as the queue is full, the next sync task to wait for previous ones is cancelled with an CancellationException exception. However, at the moment the waiting queue only consists of a single waiting slot for each kind of sync job. The type of sync job is determined by the value of the boolean parameter to synchronize(boolean). Hence at maximum two sync jobs may be waiting for the a third currently running job to finish.

  • Constructor Details

    • DefaultSyncJob

      @Inject public DefaultSyncJob(Provider<ISettingsModel> settings, IAuthTokenStorage authTokenStorage, ISmintIoApiClient smintIoClient, ISyncTarget syncTarget, ISyncTargetDataFactory syncTargetDataFactory, ISyncJobDataStorage syncDataStorage, ISmintIoDownloadProvider downloadProvider, ISyncMetadataIdMapper idMapper)
      Create new sync job and provide all necessary parameters via parameters.
      Parameters:
      settings - the settings to read tenant ID etc. from
      authTokenStorage - OAuth token for authorization to connect to Smint.io API
      smintIoClient - Smint.IO API wrapper instance
      syncTarget - the target to synchronize to
      syncTargetDataFactory - the sync target data factory to create the data instance. Must not be null!
      syncDataStorage - storage to save some data between synchronization steps. Used for fetching the list of assets in chunks, as the list could be very long.
      downloadProvider - an instance to create file downloader for binary asset files.
      idMapper - a utility class to map from meta data Smint.io API IDs to sync target IDs.
  • Method Details

    • synchronize

      public void synchronize(boolean syncMetaData) throws SmintIoAuthenticatorException, SmintIoSyncJobException
      Description copied from interface: ISyncJob
      Perform synchronization without or without syncing any asset meta data.
      Specified by:
      synchronize in interface ISyncJob
      Parameters:
      syncMetaData - pass true to force synchronization of meta data. If you pass false then no meta data will be synchronized. The later is useful for non-scheduled synchronizations.
      Throws:
      SmintIoAuthenticatorException - in case authentication with Smint.io API fails.
      SmintIoSyncJobException - for any unexpected situation, like provided settings are invalid, etc.
      The message should then be logged somewhere.
    • validateSettingsForSync

      public ISettingsModel validateSettingsForSync(ISettingsModel settings) throws SmintIoAuthenticatorException, NullPointerException
      Validates the provided settings data for validity to be used with the synchronization job.

      Currently checks that the tenant ID has been set (see ISettingsModel.getTenantId()) and that valid import languages are available.

      Parameters:
      settings - the settings data to check.
      Returns:
      a validate version of the settings, to be used for a single run only. The import languages might have been changed.
      Throws:
      SmintIoAuthenticatorException - in case an invalid settings value has been provided.
      NullPointerException - if parameter settings is null
    • validateSettingsForAuthenticator

      public void validateSettingsForAuthenticator(ISettingsModel settings) throws SmintIoAuthenticatorException, NullPointerException
      Validates the provided settings for validity to be used with authorizing to the Smint.io API.

      Currently checks that the following values are valid:

      Parameters:
      settings - the settings data to check.
      Throws:
      SmintIoAuthenticatorException - in case an invalid settings value has been provided.
      NullPointerException - if parameter settings is null
    • validateAuthTokenForSync

      public void validateAuthTokenForSync(IAuthTokenModel authData) throws SmintIoAuthenticatorException, NullPointerException
      Validates the provided OAuth authorization token data for validity to be used with the synchronization job.

      Currently checks that the following values are valid:

      Parameters:
      authData - authentication data to check whether every data for OAuth authorization is available.
      Throws:
      SmintIoAuthenticatorException - in case an invalid settings value has been provided.
      NullPointerException - if parameter authData is null
    • synchronizeGenericMetadata

      public void synchronizeGenericMetadata(ISmintIoGenericMetadata metaData, ISyncTarget syncTarget) throws Exception
      Synchronizes the passed-in generic meta data.

      the meta data is split up into pieces and passed to the sync target one-by-one

      Parameters:
      metaData - the meta data to sync.
      syncTarget - the target to sync with.
      Throws:
      Exception - any exception if thrown by the sync target functions
    • synchronizeAssets

      public void synchronizeAssets(String tenantId, ISyncTarget syncTarget, ISyncJobDataStorage jobDataStorage, ISmintIoApiClient smintIoClient) throws Exception
      Fetches the assets from Smint.io API and synchronizes these with the target.

      The assets are fetched from the Smint.io RESTful API in chunks and passed to the sync target in these batches. A temporary directory is created to be used for downloading assets. In the end, all files and directories in the temporary directory are deleted at the end of synchronizing.

      Parameters:
      tenantId - the tenant ID is used forming a prefix for the temporary download directory.
      syncTarget - the target to sync with.
      jobDataStorage - data storage for job data (eg: continuation ID).
      smintIoClient - the Smint.io API library.
      Throws:
      Exception - any exception thrown by the syncTarget