Reputation: 5420
Hybris 6.3.0.2
I have created one AfterSaveListener which is performing some custom logic after saving items.
*AfterSaveListener -
@Override
public void afterSave(final Collection<AfterSaveEvent> events)
{
for (final AfterSaveEvent event : events)
{
final int type = event.getType();
if (AfterSaveEvent.UPDATE == type || AfterSaveEvent.CREATE == type)
{
final PK pk = event.getPk();
//The AttributeFormat Model typecode is "11001"
if (11001 == pk.getTypeCode())
{
final AttributeFormatModel attributeFormat = modelService.get(pk);
updateProductFeatureByAttributeFormat(attributeFormat);
}
}
}
}
A new Item type "AttributeFormat" has been created based on which i am updating product feature data.
This listener works fine if i update or create AttributeFormat from backoffice but its not working as expected when importing data via impex.
Impex -
INSERT_UPDATE AttributeFormat;code[unique=true];prefix[lang=$lang];suffix[lang=$lang];separator[lang=$lang];$classSystemVersion
;prefix_suffix_separator;<;change;,
When i am importing this Impex, call is going to AfterSaveListener but the expected typecode is not coming. Means if (11001 == pk.getTypeCode())
block is not executing at all.
I debug and found that some other media typecode is coming but not AttributeFormat. Have anyone experience the same problem ?
AfterSaveListener working with correct typecode value in case of item created at first time. Whenever AttributeFormat will create at first time, then listener works fine with correct typecode and if block is executing. But in case of Update, its not working.
Upvotes: 0
Views: 1902
Reputation: 11
Check your type code in hybris administrative console for your model AttributeFormatModel, usually type code of parent class in considered I would recommend to check using instanceof
@Override
public void afterSave(final Collection<AfterSaveEvent> events)
{
events.forEach(event -> {
if (event.getType() == AfterSaveEvent.CREATE)
{
final PK pk = event.getPk();
final Object object = getModelService().get(pk);
if (object instanceof ManageTransportOfferingForScheduleConfigurationCronJobModel)
{
final ManageTransportOfferingForScheduleConfigurationCronJobModel cronjob =
(ManageTransportOfferingForScheduleConfigurationCronJobModel) object;
cronjob.setActive(Boolean.TRUE);
getCronJobService().performCronJob(cronjob, true);
}
}
});
}
Upvotes: 1