on 02-17-2015 12:52 PM
Hi, expert!
We want to syncronize some products from java code via Model layer (not Jalo). We founded solution for all catalog:
final CatalogVersionModel catalogVersion = catalogVersionService.getCatalogVersion(fromCatalog, STAGED);
final List<SyncItemJobModel> synchronizations = catalogVersion.getSynchronizations();
for (final SyncItemJobModel syncItemJob : synchronizations) {
final SyncItemCronJobModel cronJob = modelService.create(CatalogVersionSyncCronJobModel.class);
cronJob.setLogToDatabase(Boolean.FALSE);
cronJob.setLogToFile(Boolean.FALSE);
cronJob.setForceUpdate(Boolean.FALSE);
cronJob.setJob(syncItemJob);
modelService.save(cronJob);
modelService.refresh(cronJob);
LOGGER.info("Generating cronjob : " + cronJob.getCode() + " to synchronize the catalog : " + fromCatalog);
cronJobService.performCronJob(cronJob, true);
But we need to sync some product, not all catalog version. Is it possible? How we can do it?
Thanks.
We founded a solution by adding Configurator to Sync Job. Full example:
final CatalogVersion source = modelService.getSource(stagedCatalogVersionModel);
final CatalogVersion target = modelService.getSource(onlineCatalogVersionModel);
final SyncItemJob syncJob = CatalogManager.getInstance().getSyncJob(source, target);
final SyncItemCronJob synchronizeJob = syncJob.newExecution();
final List itemPKs = new ArrayList();
for (final ProductModel productModel : productModels)
{
final Product sourceProduct = modelService.getSource(productModel);
final ProductModel targetProductModel = findProductFromOnline(productModel);
Product targetProduct = null;
if (targetProductModel != null)
{
targetProduct = modelService.getSource(targetProductModel);
}
itemPKs.add(new PK[]
{ sourceProduct.getPK(), targetProduct == null ? null : targetProduct.getPK() });
}
synchronizeJob.addPendingItems(itemPKs, false);
synchronizeJob.setConfigurator(new SyncItemCronJob.Configurator()
{
@Deprecated
@Override
public void configureCronjob(final SyncItemCronJob syncItemCronJob, final SyncItemCopyContext syncItemCopyContext)
{
}
public CompletionInfo getCompletionInfo()
{
return new SyncItemJob.CompletionInfo(&quot;configuring full version sync&quot;, 0, 0, 0, 0);
}
});
syncJob.perform(synchronizeJob, true);
Yves, thanks for help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Overriding the configureCronojob worked for me to sync the selected products synchronizeJob.setConfigurator(new SyncItemCronJob.Configurator() {
@Override
public CompletionInfo getCompletionInfo()
{
return new SyncItemJob.CompletionInfo("configuring full version sync", 0, 0, 0, 0);
}
@Deprecated
@Override
public void configureCronjob(final SyncItemCronJob arg0, final SyncItemCopyContext arg1)
{
syncJob.addCatalogItemsToSync(synchronizeJob, items);
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried two method:
1 Sync via Jalo layer:
final CatalogVersion source = modelService.getSource(stagedCatalogVersionModel);
final CatalogVersion target = modelService.getSource(onlineCatalogVersionModel);
final SyncItemJob syncJob = CatalogManager.getInstance().getSyncJob(source, target);
final SyncItemCronJob synchronizeJob = syncJob.newExecution();
final Product sourceProduct = modelService.getSource(sourceproductModel);
final Product targetProduct = modelService.getSource(targetProductModel);
synchronizeJob.addPendingItem(sourceProduct, targetProduct);
syncJob.perform(synchronizeJob, true);
Result: sync update ALL products (not sourceProduct)
2 Sync via SynchronizationServiceImpl:
final CatalogVersion target = modelService.getSource(onlineCatalogVersionModel);
final SyncItemJob syncJob = CatalogManager.getInstance().getSyncJob(source, target);
final List<String> synkPkJobs = new ArrayList<String>();
synkPkJobs.add(syncJob.getPK().toString());
final SynchronizationServiceImpl synchronizationService = new SynchronizationServiceImpl();
synchronizationService.performSynchronization(productModels, synkPkJobs, onlineCatalogVersionModel, syncJob.getCode());
Result: exception java.lang.NullPointerException at de.hybris.platform.cockpit.services.sync.impl.SynchronizationServiceImpl.performSynchronization(SynchronizationServiceImpl.java:242)
Could somebody share working example sync one product?
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to initialize/load your bean the one. Either you call your bean as follows
SynchronizationService syncService = (SynchronizationService) SpringUtil.getBean("synchronizationService");
or in your spring file :
<bean id="YourSyncJobPerformable" class="your package.YourSyncJobPerformable" parent="abstractJobPerformable" >
<property name="synchronizationService" ref="synchronizationService"/>
</bean>
Yves
Hi, Yves. I can not use SpringUtil because i am using core extention, not cockpit(zkozz). When i try to set
<property name="synchronizationService" ref="synchronizationService"/>
there are error: No bean named 'synchronizationService' is defined. Are you sure that service name is "SynchronizationService"? Not SynchronizationServiceImpl? Can i use SynchronizationService in core extention?
Regarding your first option, at first I haven't noticed what you have implemented but what makes you say that it synchronizes all the products? Maybe by trying to use the de.hybris.platform.catalog.jalo.SyncItemCronJob.addPendingItems(List, boolean) method it should only sync the list you have passed as parameter ( instead of using synchronizeJob.addPendingItem(sourceProduct, targetProduct);)
Otherwise, you can contact Product Support by creating a BCP ticket, we will be glad to help you further or at least to give you some hints 😉
Yves
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, the sync process is still using the Jalo layer underneath, even though the Service Layer has been added for some sync features/function. Either you can use that classes or you can have a look at : de.hybris.platform.cockpit.services.sync.impl.SynchronizationServiceImpl.performSynchronization(...)
Hope that helps.
Cheers, Yves
User | Count |
---|---|
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.