Class DefaultChangeDetectionService

java.lang.Object
de.hybris.deltadetection.impl.DefaultChangeDetectionService
All Implemented Interfaces:
ChangeDetectionService

public class DefaultChangeDetectionService extends Object implements ChangeDetectionService
Default Implementation of change detection service
  • Field Details

  • Constructor Details

    • DefaultChangeDetectionService

      public DefaultChangeDetectionService()
  • Method Details

    • getChangeForExistingItem

      public ItemChangeDTO getChangeForExistingItem(ItemModel item, String streamId)
      Description copied from interface: ChangeDetectionService
      Detects change for a given existing item and stream. Finds changes of change type 'NEW' or "MODIFIED'.
      Specified by:
      getChangeForExistingItem in interface ChangeDetectionService
      Parameters:
      item - the item to be checked
      streamId - the streamId for which the changes should be detect
      Returns:
      ItemChangeDTO Object containing all the information about the change
    • getChangeForRemovedItem

      public ItemChangeDTO getChangeForRemovedItem(PK pk, String streamId)
      Description copied from interface: ChangeDetectionService
      Detects potential change for a an not existing item - (change type 'DELETED'), stored under ItemVersionMarker referencing given item pk.
      Specified by:
      getChangeForRemovedItem in interface ChangeDetectionService
      Parameters:
      pk - the pk of the item to be checked
      streamId - the streamId for which the change should be detect
      Returns:
      ItemChangeDTO Object containing all the information about the change
    • isItemVersionMarkerActive

      protected boolean isItemVersionMarkerActive(ItemVersionMarkerModel marker)
    • getChangesForRemovedItems

      public List<ItemChangeDTO> getChangesForRemovedItems(String streamId)
      Description copied from interface: ChangeDetectionService
      Detects changes for all items, which doesn't exist anymore (change type 'DELETED'), stored under ItemVersionMarker referencing the not existing item pks.
      Specified by:
      getChangesForRemovedItems in interface ChangeDetectionService
      Parameters:
      streamId - the streamId for which the change should be detect
      Returns:
      List of ItemChangeDTO Objects containing all the information about the changes
    • collectChangesForType

      public void collectChangesForType(ComposedTypeModel composedType, String streamId, ChangesCollector collector)
      Description copied from interface: ChangeDetectionService
      Detects all kind of changes (NEW, MODIFIED, DELETED) on items for the given composed type.
      Specified by:
      collectChangesForType in interface ChangeDetectionService
      Parameters:
      composedType - the type for which the change detection should be executed (including subtypes)
      streamId - the streamId for which the change should be detect
      collector - responsible for collecting the changes in specified way, e.g. store them in memory or generate csv file.
    • collectChangesForType

      public void collectChangesForType(ComposedTypeModel composedType, StreamConfiguration configuration, ChangesCollector collector)
      Description copied from interface: ChangeDetectionService
      Detects all kind of changes (NEW, MODIFIED, DELETED) on items for the given composed type.
      Specified by:
      collectChangesForType in interface ChangeDetectionService
      Parameters:
      composedType - the type for which the change detection should be executed (including subtypes)
      configuration - the stream configuration defining which item should be included into the stream.
      collector - responsible for collecting the changes in specified way, e.g. store them in memory or generate csv file.
      See Also:
    • getChangeFromRow

      protected ItemChangeDTO getChangeFromRow(List<Object> row, String streamId)
    • prepareQueryForFindingChangesByType

      protected String prepareQueryForFindingChangesByType(ComposedTypeModel composedType, StreamConfiguration configuration)
    • getQueryForDeletedItems

      protected String getQueryForDeletedItems(String typePksAsQueryParams, String baseType, String itemSelector)
    • getQueryForModifiedItems

      protected String getQueryForModifiedItems(String typePksAsQueryParams, String baseType, String itemSelector, String versionValuePart)
    • getQueryForNewItems

      protected String getQueryForNewItems(String typePksAsQueryParams, String baseType, String itemSelector, String versionValuePart)
    • preloadVersionMarkers

      protected Map<Long,ItemVersionMarkerModel> preloadVersionMarkers(List<ItemChangeDTO> changes, String streamId)
    • consumeChangesBatch

      protected int consumeChangesBatch(List<ItemChangeDTO> changes, String streamId)
    • consumeChanges

      public void consumeChanges(List<ItemChangeDTO> allChanges)
      Description copied from interface: ChangeDetectionService
      Consumes all given changes. it Means, for the changes of change type NEW - a new ItemVersionMarker is created, in case of change type MODIFIED - the item version marker is updated properly and in case of change type DELETED - the ItemVersionMarker is removed. The stream for which the changes will be consumed is defined inside the given ItemChangeDTO objects
      Specified by:
      consumeChanges in interface ChangeDetectionService
      Parameters:
      allChanges - list of the changes to be consumed.
    • logConsumedChanges

      protected void logConsumedChanges(int numConsumed)
    • getPartitionedBatchChangesByStreamId

      protected Map<String,List<List<ItemChangeDTO>>> getPartitionedBatchChangesByStreamId(List<ItemChangeDTO> allChanges)
    • prepareBatchExecutionCallables

      protected List<Callable<Integer>> prepareBatchExecutionCallables(List<ItemChangeDTO> allChanges)
    • createConsumeBatchCallable

      protected Callable<Integer> createConsumeBatchCallable(String streamId, List<ItemChangeDTO> changes, int maxRetries)
    • deleteItemVersionMarkersForStream

      public void deleteItemVersionMarkersForStream(String streamId)
      Description copied from interface: ChangeDetectionService
      Deletes all item version markers belonging to the stream
      Specified by:
      deleteItemVersionMarkersForStream in interface ChangeDetectionService
      Parameters:
      streamId - stream id for which item version markers should be deleted
    • resetStream

      public void resetStream(String streamId)
      Description copied from interface: ChangeDetectionService
      Resets the stream. It means that all ItemVersionMarkers with status DELETED will change their status to ACTIVE and all the ItemVersionMarkers with status ACTIVE will have their versionTS set to the beginning of Unix Epoch time (1 January 1970).
      Specified by:
      resetStream in interface ChangeDetectionService
      Parameters:
      streamId - stream id for which item version markers should be reset
    • findItemVersionMarkersForStreamByPKs

      protected Map<Long,ItemVersionMarkerModel> findItemVersionMarkersForStreamByPKs(String streamId, List<PK> PKs)
    • findVersionMarkerByItemPK

      protected ItemVersionMarkerModel findVersionMarkerByItemPK(String streamId, Long itemPk)
      Checks and returns existing item version marker for the item and stream. Useful to check if the item has already assigned ItemVersionMarker in 'DELETED' state - in such case we'd just change status to 'ACTIVE' in order to avoid having to ItemVersionMarkers ('ACTIVE' and 'DELETED') for the same item.
    • isNotSingleResult

      protected boolean isNotSingleResult(List<ItemVersionMarkerModel> result)
    • getNewOrModifiedVersionMarkers

      protected List<ItemVersionMarkerModel> getNewOrModifiedVersionMarkers(String streamId, ComposedTypeModel model)
    • getDeletedVersionMarkers

      protected List<ItemVersionMarkerModel> getDeletedVersionMarkers(String streamId)
    • getComposedTypesForStream

      protected List<ComposedTypeModel> getComposedTypesForStream(String streamId)
    • getStreamById

      protected Optional<StreamConfigurationModel> getStreamById(String streamId)
    • getVersionMarkersForRemovedItems

      protected List<ItemVersionMarkerModel> getVersionMarkersForRemovedItems(String streamId)
    • fillInitialVersionMarker

      protected void fillInitialVersionMarker(ItemVersionMarkerModel marker, Long itemPK, Date version, String versionValue, String info, ComposedTypeModel itemComposedType, String streamId)
    • updateVersionMarker

      protected void updateVersionMarker(ItemVersionMarkerModel marker, Date version, String versionValue, String info)
    • parseInfoExpression

      protected String parseInfoExpression(Long itemPK, StreamConfigurationModel streamConfiguration)
    • getSavedModel

      protected ItemModel getSavedModel(PK pk)
    • setFlexibleSearchService

      public void setFlexibleSearchService(FlexibleSearchService flexibleSearchService)
    • getFlexibleSearchService

      protected FlexibleSearchService getFlexibleSearchService()
    • setModelService

      public void setModelService(ModelService modelService)
    • getModelService

      protected ModelService getModelService()
    • setTypeService

      public void setTypeService(TypeService typeService)
    • getTypeService

      protected TypeService getTypeService()