cancel
Showing results for 
Search instead for 
Did you mean: 

y2ysync publish deleted canonical items (hybris 5.7)

saskias
Explorer
0 Kudos

I've searched the whole forum here and searched also the documentation and I found the information that it is possible to delete a canonical item:

https://wiki.hybris.com/display/release5/Changing+the+Value+or+Status+of+a+Canonical+Item+During+Com...

This text also says, that in case of a hybris target system, the deletion can be published to the target system. As far as I can see this does not happen automatically. Can someone point me to the correct direction how this can be achieved?

Thanks a lot in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Slava
Advisor
Advisor
0 Kudos

The only option in 5.7 is to delete items by making REST calls to DataHub. You can delete canonical items by type or by integration key of an item. Also, if you have no knowledge about the canonical data but deal with raw model only, then you can delete by feeding raw items with attribute values for the canonical item primary key. See details here https://help.hybris.com/6.0.0/api/datahub/DataHubAPI60.html It's a newer document but everything for deleting items should be the same as in 5.7 (pay attention to DELETE method requests). Those REST calls will make items deleted inside Data Hub, then you will need to publish as usual in order to propagate deletion to the platform.

saskias
Explorer
0 Kudos

Thank you for your answer 🙂

To send the deletion is not the problem. It "soft-deletes" the Canonical Item. I already did that. The question is more how I can propagate this deletion to the platform. So far this does not work. It just sets the canonical item to deleted and then no publication to the target system is triggered.

Or do you mean to create raw fragments and the whole chain etc to propagate the deletion to the platform with "publish as usual"?

Slava
Advisor
Advisor
0 Kudos

It won't trigger automatically. You have to publish the changes, so publish the items as usual and the deleted items will be sent to the platform. If I understood you correctly, the canonical items already have DELETED status, so what's remaining is just to publish: make POST request to datahub-webapp/v1/pools/your_pool/publications with the body containing target system specification. See the REST API for reference.

Answers (5)

Answers (5)

Slava
Advisor
Advisor
0 Kudos

Rasika, can you describe your scenario because I'm confused. Let's say we have categories in ECP:

 code,name
 c1,category 1
 c2,category 2

and a product:

 code,categories
 p1,c1

If we delete category c2, then it can be done after insert_updates - no harm.

If we want to delete category c1, same as c2 except now p1 refers non-existent category.

To change category in the product, load these raw products to DataHub, which will be present in the insert_update section during export to ECP:

 p1,<empty>
 p1,c2

The delete section is empty in the generated impex. The product is associated only with category c2 in ECP now and both categories c1 and c2 still exist in ECP.

If besides changing category in the product, category c1 was also deleted - let's say these raw items were loaded:

first category:

 code,deleted
 c1,true

then the product as it's shown above:

 p1,<empty>
 p1,c2

Then it's good the deletes are at the end of the impex because first, the product's category will change and then category c1 that is not referred anymore is deleted.

Former Member
0 Kudos

Ok, I can answer myself. Maybe it will be the answer for someone else.

Only Hybris in version 5.6.0 (and higher) can publish canonical items with status DELETED.

You can compare: https://wiki.hybris.com/display/release5/Item+Statuses+and+Lifecycle+-+5.3+Through+5.5.1 https://wiki.hybris.com/display/release5/Item+Statuses+and+Lifecycle+-+5.6.0+Through+5.7.0

I have to update my Hybris and then I can continue.

Former Member
0 Kudos

,

I refer above steps to delete/remove canonical items . but my requirement is remove previous categoryand assign new category. but when I publish target items through datahub it execute all insert_update queries and at last remove query. To maintain sequence I had provided dependency of remove CategoryProductRelation item in insert CategoryProductRelation,but still issue is not resolved.

how to change sequence of insert-update and remove in target datahub extension?

Regards, Rasika

Slava
Advisor
Advisor
0 Kudos

Rasika,

didn't this answer https://answers.sap.com/questions/12766891/remove-previous-categories-and-assign-new-categori.html?c... help you? Using techniques in this thread you can delete a category or delete a product, so that it won't exist anymore in ECP. If you need to reassign categories in a product without actually deleting either the product or the referred categories, then use value in the product's "categories" field to reset categories previously assigned to the product.

Former Member
0 Kudos

, ,

I tried it, but now its adding categories first through insert_update and then deleting it by remove query.I want to change this OOTB query creation sequence to first execute REMOVE and then INSERT_UPDATE.

For that I tried to provide dependency to set order of target item execution, but that is also giving same result. below is the code I tried.link text

how to change sequence of insert-update and remove in target datahub extension?

Regards, Rasika

Former Member
0 Kudos

Hi all,

I have similiar problem, related with publishing deleted canonical items to target system. I'm using Hybris 5.5.1. I go through instructions from .

1) I have dummy raw type with a field "DELETE" which is mapped to dummy canonical type to field "toDelete".

2) I have DeleteCompositionHandler which is an implementation of CompositionRuleHandler. The compose method sets canonicalItem's status to CompositionStatusType.DELETED. Currently, as you can see, I would like to force removal of all canonical objects which have the field "toDelete".

  public class DeleteCompositionHandler implements CompositionRuleHandler {

  private String canonicalAttributeName;

  public DeleteCompositionHandler(final String canonicalAttr) {
     canonicalAttributeName = canonicalAttr != null && !canonicalAttr.trim().isEmpty()
             ? canonicalAttr : "<null>";
 }

 @Override
 public <T extends CanonicalItem> T compose(final CanonicalAttributeDefinition attribute,
         final CompositionGroup<? extends RawItem> compositionGroup, final T canonicalItem) {
     Object field = canonicalItem.getField("toDelete");
     canonicalItem.setStatus(CompositionStatusType.DELETED);
     return canonicalItem;
 }

 @Override
 public boolean isApplicable(CanonicalAttributeDefinition attribute) {
     return attribute.getCanonicalAttributeModelDefinition().getAttributeName().equals(canonicalAttributeName);
 }

 @Override
 public int getOrder() {
     return 3;
 }

}

3) Order of my composition handler is set to 3.

 <bean id="deleteCompositionHandler"  class="com.qiagen.ecom.datahub.composition.impl.DeleteCompositionHandler">
     <constructor-arg value="toDelete"/>
 </bean>

4) After sending rawItem, I send POST request to /datahub-webapp/v1/pools/{poolname}/compositions.

5) It's the only one canonical item in my database. It has status "DELETED". However no publish event is triggered. I don't see any target item. You said that datahub should automatically trigger publication. It doesn't work for me.

I've also tried via REST api. Canonical item was successfully marked as "DELETED", however I'm not able to publish remove impex to the target system.

Do you have an idea what's wrong?

Best regards,

Krystian

saskias
Explorer
0 Kudos

Hi Krystian,

in our system all publications are automatically done (autopublish). If that is not triggered, did you try to trigger a publication over the REST api?

I remember I once had this, but I had several versions the same "canonical item" in the datahub db.

Also it might be possible that the datahub 5.5 simply works differently. Sorry that I cannot help much

saskias
Explorer
0 Kudos

Hello,

you need to create a CompositionHandler which implements the interface CompositionRuleHandler. Implement the isApplicable method so it accepts only your itemtypes where you want this. In the compose method simply set the status of the canonical item as DELETED.

 @Override
 public <T extends CanonicalItem> T compose(final CanonicalAttributeDefinition attribute, final CompositionGroup<? extends RawItem> compositionGroup, final T canonicalItem)
 {
     Object field = canonicalItem.getField("deleteMe");
     if (Boolean.TRUE.equals(new Boolean((String) field))) {
         canonicalItem.setStatus(CompositionStatusType.DELETED);
     }
     return canonicalItem;
 }

And I added this CompositionHandler to the spring configuration.

saskias
Explorer
0 Kudos

I want to add the steps I did to fulfill the deletion in the y2ysync:

  1. I used the pk of the item as truly unique identifier during sync (added it as srcPk in raw and in canonical defintion and set it as unique)

  2. I extended the creation of the delete script of the ExportScriptCreator to add empty values for the contents I don't have (the itemversionmarkers info column contained always "created" which did not help), so my REMOVE impex script contained the right amount of columns. Also I added a column "deletion" and set the value always to true

  3. The raw items were created with every field for the impex header with an empty value except for srcPk and deletion

  4. I've created a CompositionHandler where I checked if there is a field "deletion" and if it is true. If so, the canonical item was created with status "DELETE"

  5. Automatically the datahub creates a publication with publication type delete and thus a REMOVE-impex script is send to the target.

Actually I did not need the rest API in the way as mentioned above. Because the REST Delete on a canonical item will only set an existing, already processed canonical item to status DELETED and that won't be published to the target since it is mapped to an action with IS already published.

I hope that helps anyone having the same problem I had.

Former Member
0 Kudos

Hi Saskia, I'm trying to do something similar to what you have described. Can you please share with me how you marked the status of the canonical item as deleted in step 4 above? while(iter.hasNext()) { RawItem rawItem = (RawItem)iter.next(); final String value = (String) rawItem.getField("deleteMe"); if (value.equalsIgnoreCase("true")){ canonicalItem.setStatus(CompositionStatusType.DELETED); }} return canonicalItem; I tried something like the above and it doesn't set status to 'deleted' when I view the canonical item in the pool. Nor does it generate a remove impex.