Skip to content

Commit

Permalink
Adjust javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
salander85 committed Oct 5, 2023
1 parent f475592 commit 089bab0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 56 deletions.
25 changes: 13 additions & 12 deletions src/main/java/com/commercetools/project/sync/Syncer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@
* Base class of the syncer that handles syncing a resource from a source CTP project to a target
* CTP project.
*
* @param <ResourceT>> The type of the resource to update (e.g. {@link ProductProjection}, {@link
* @param <ResourceT> The type of the resource to update (e.g. {@link ProductProjection}, {@link
* Category}, etc..)
* @param <ResourceUpdateActionT>> The type of the resource to create
* @param <ResourceDraftT>> The type of the resource draft (e.g. {@link ProductDraft}, {@link
* @param <ResourceUpdateActionT> The update actions to update the resource with (e.g.
* {@link com.commercetools.api.models.product.ProductUpdateAction})
* @param <ResourceDraftT> The type of the resource draft (e.g. {@link ProductDraft}, {@link
* CategoryDraft}, etc..)
* @param <SyncStatisticsT>> The type of the sync statistics resulting from the sync process (e.g.
* @param <SyncStatisticsT> The type of the sync statistics resulting from the sync process (e.g.
* {@link com.commercetools.sync.products.helpers.ProductSyncStatistics}, {@link
* com.commercetools.sync.categories.helpers.CategorySyncStatistics}, etc..)
* @param <SyncOptionsT>> The type of the sync options used for the sync (e.g. {@link
* @param <SyncOptionsT> The type of the sync options used for the sync (e.g. {@link
* com.commercetools.sync.products.ProductSyncOptions}, {@link
* com.commercetools.sync.categories.CategorySyncOptions}, etc..)
* @param <PagedQueryT> The type of the query used to query for the source resources (e.g. {@link
Expand Down Expand Up @@ -111,13 +112,13 @@ public Syncer(
}

/**
* Fetches the sourceClient's project resources of type {@code T} with all needed references
* expanded and treats each page as a batch to the sync process. Then executes the sync process of
* on every page fetched from the source project sequentially. It then returns a completion stage
* Fetches the sourceClient's project resources of type {@code ResourceT} with all needed references
* expanded and treats each page as a batch to the sync process. Then executes the sync process
* on every page sequentially. It then returns a completion stage
* containing a {@link Void} result after the execution of the sync process and logging the
* result.
*
* <p>Note: If {@code isFullSync} is {@code false}, i.e. a delta sync is required, the method
* <p>Note: If {@param isFullSync} is {@code false}, i.e. a delta sync is required, the method
* checks if there was a last sync time stamp persisted as a custom object in the target project
* for this specific source project and sync module. If there is, it will sync only the resources
* which were modified after the last sync time stamp and before the start of this sync.
Expand Down Expand Up @@ -265,11 +266,11 @@ private SyncStatisticsT syncPage(@Nonnull final List<ResourceT> page) {
}

/**
* Given a {@link List} representing a page of resources of type {@code T}, this method creates a
* a list of drafts of type {@link SyncStatisticsT} where reference ids of the references are
* Given a {@link List} representing a page of resources of type {@link ResourceT}, this method creates
* a list of drafts of type {@link ResourceDraftT} where reference ids of the references are
* replaced with keys and are ready for reference resolution by the sync process.
*
* @return a {@link CompletionStage} containing a list of drafts of type {@link SyncStatisticsT}
* @return a {@link CompletionStage} containing a list of drafts of type {@link ResourceDraftT}
* after being transformed from type {@link ResourceT}.
*/
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public long getLastSyncDurationInMillis() {

// Setters are needed for the 'com.fasterxml.jackson' deserialization, for example, when fetching
// from CTP custom objects.

public void setLastSyncTimestamp(@Nonnull final ZonedDateTime lastSyncTimestamp) {
this.lastSyncTimestamp = lastSyncTimestamp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,55 @@
import javax.annotation.Nullable;

public interface CustomObjectService {

/**
* Creates or updates a custom object with the container named
* 'commercetools-project-sync.{@param runnerName}.{@param syncModuleName}.timestampGenerator' and
* key equals 'timestampGenerator' and then reading the 'lastModifiedAt' field of the persisted custom
* object and returning it.
*
* @param syncModuleName the name of the resource being synced. E.g. productSync, categorySync,
* etc..
* @param runnerName the name of this specific running sync instance defined by the user.
* @return a {@link CompletionStage} containing the current CTP timestamp as {@link
* ZonedDateTime}.
*/
@Nonnull
CompletionStage<ZonedDateTime> getCurrentCtpTimestamp(
@Nullable final String runnerName, @Nonnull final String syncModuleName);

/**
* Get's a custom object which has a container named 'commercetools-project-sync.{@param
* runnerName}.{@param syncModuleName}' and key equals {@param sourceProjectKey}. The value of the
* fetched custom object is deserialized and wrapped in an {@link Optional}.
*
* @param sourceProjectKey the source project from which the data is coming.
* @param syncModuleName the name of the resource being synced. E.g. productSync, categorySync,
* etc..
* @param runnerName the name of this specific running sync instance defined by the user.
* @return the custom object with container 'commercetools-project-sync.{@param
* runnerName}.{@param syncModuleName}' and key '{@param sourceProjectKey}', wrapped in an {@link Optional} as a
* result of a {@link CompletionStage}.
*/
@Nonnull
CompletionStage<Optional<LastSyncCustomObject>> getLastSyncCustomObject(
@Nonnull final String sourceProjectKey,
@Nonnull final String syncModuleName,
@Nullable final String runnerName);

/**
* Creates (or updates an already existing) custom object, with the container named
* 'commercetools-project-sync.{@param runnerName}.{@param syncModuleName}' and key equals {@param
* sourceProjectKey}, enriched with the information in the passed {@link LastSyncCustomObject}
* param.
*
* @param sourceProjectKey the source project key from which the data is coming.
* @param syncModuleName the name of the resource being synced. E.g. productSync, categorySync,
* etc..
* @param runnerName the name of this specific running sync instance defined by the user.
* @param lastSyncCustomObject contains information about the last sync instance.
* @return a {@link CompletableFuture} of {@link ApiHttpResponse} with the created/updated custom object resource.
*/
@Nonnull
CompletableFuture<ApiHttpResponse<CustomObject>> createLastSyncCustomObject(
@Nonnull final String sourceProjectKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ public CustomObjectServiceImpl(@Nonnull final ProjectApiRoot ctpClient) {
this.ctpClient = ctpClient;
}

/**
* Gets the current timestamp of CTP by creating/updating a custom object with the container:
* 'commercetools-project-sync.{@code runnerName}.{@code syncModuleName}.timestampGenerator' and
* key: 'timestampGenerator' and then returning the lastModifiedAt of this created/updated custom
* object.
*
* @param syncModuleName the name of the resource being synced. E.g. productSync, categorySync,
* etc..
* @param runnerName the name of this specific running sync instance defined by the user.
* @return a {@link CompletionStage} containing the current CTP timestamp as {@link
* ZonedDateTime}.
*/
@Nonnull
@Override
public CompletionStage<ZonedDateTime> getCurrentCtpTimestamp(
Expand All @@ -62,28 +50,18 @@ public CompletionStage<ZonedDateTime> getCurrentCtpTimestamp(
.thenApply(CustomObject::getLastModifiedAt);
}

/**
* Helper to create a custom object of {@param customObjectDraft} on the CTP project defined by the {@code ctpClient}.
*
* @param customObjectDraft draft of custom object to create
* @return a {@link CompletableFuture} of {@link ApiHttpResponse} with the created custom object resource.
*/
@Nonnull
private CompletableFuture<ApiHttpResponse<CustomObject>> createCustomObject(
@Nonnull final CustomObjectDraft customObjectDraft) {
return this.ctpClient.customObjects().post(customObjectDraft).execute();
}

/**
* Queries for custom objects, on the CTP project defined by the {@code sphereClient}, which have
* a container: 'commercetools-project-sync.{@code runnerName}.{@code syncModuleName}' and key:
* {@code sourceProjectKey}. The method then returns the first custom object returned in the
* result set if there is, wrapped in an {@link Optional} as a result of a {@link
* CompletionStage}. It will be, at most, one custom object since the key is unique per custom
* object container as per CTP documentation.
*
* @param sourceProjectKey the source project from which the data is coming.
* @param syncModuleName the name of the resource being synced. E.g. productSync, categorySync,
* etc..
* @param runnerName the name of this specific running sync instance defined by the user.
* @return the first custom object returned in the result set if there is, wrapped in an {@link
* Optional} as a result of a {@link CompletionStage}. It will be, at most, one custom object
* since the key is unique per custom object container as per CTP documentation.
*/
@Nonnull
@Override
public CompletableFuture<Optional<LastSyncCustomObject>> getLastSyncCustomObject(
Expand Down Expand Up @@ -115,21 +93,6 @@ public CompletableFuture<Optional<LastSyncCustomObject>> getLastSyncCustomObject
});
}

/**
* Creates (or updates an already existing) custom object, with the container:
* 'commercetools-project-sync.{@code runnerName}.{@code syncModuleName}' and key: {@code
* sourceProjectKey}, enriched with the information in the passed {@link LastSyncCustomObject}
* param.
*
* @param sourceProjectKey the source project from which the data is coming.
* @param syncModuleName the name of the resource being synced. E.g. productSync, categorySync,
* etc..
* @param runnerName the name of this specific running sync instance defined by the user.
* @param lastSyncCustomObject contains information about the last sync instance.
* @return the first custom object returned in the result set if there is, wrapped in an {@link
* Optional} as a result of a {@link CompletionStage}. It will be, at most, one custom object
* since the key is unique per custom object container as per CTP documentation.
*/
@Nonnull
@Override
public CompletableFuture<ApiHttpResponse<CustomObject>> createLastSyncCustomObject(
Expand Down

0 comments on commit 089bab0

Please sign in to comment.