Can someone explain details of hybris auditing system? - sap-commerce-cloud

By Default hybris auditing system comes in picture whenever any change in model or any attribute.
I want to use Hybris auditing module in my application?(SavedValuesModel).Does this module has any issue in use? does this work under the same transaction model.? I am newbie for hybris. Please provide some details on this.

Hybris auditing system comes with the item SavedValues. this is the item which maintains the model value history in it. Please refer to the item type declaration below:
<!-- hmc legacy - Saved Values -->
<itemtype code="SavedValues"
generate="true"
jaloclass="de.hybris.platform.hmc.jalo.SavedValues"
extends="GenericItem"
autocreate="true">
<deployment table="SavedValues" typecode="334"/>
<attributes>
.
.
.
</attributes>
</itemtype>
Now this item has a 1-n relation with the SavedValueEntry,
<!-- hmc legacy - Saved values -->
<relation code="SavedValueEntriesRelation" autocreate="true" generate="true" localized="false">
<sourceElement type="SavedValues" qualifier="parent" cardinality="one">
<modifiers read="true" write="false" initial="true" optional="false" search="true"/>
</sourceElement>
<targetElement type="SavedValueEntry" qualifier="savedValuesEntries" cardinality="many"
collectiontype="set">
<modifiers read="true" write="false" optional="true" partof="true"></modifiers>
</targetElement>
</relation>
This item type contains the original and changed values of the item, along with the other details such as modification type (create/update/remove), the user doing the change etc.
The main disadvantages of this system are mentioned below:
Any changes done to the item type outside hmc (e.g. by impex etc.) are not recorded. However, if the changes need to be logged then one can use the below syntax
HMCManager.getInstance().logItemModification(item.getPk(), newValues, oldValues, false);
This audit trail has a performance overhead and needs to be cleaned up for performance tune ups.
You can follow the below references for further reading:
https://wiki.hybris.com/display/release5/SavedValues+-+Keeping+Track+of+Attribute+Value+Modification
https://experts.hybris.com/questions/9332/logging-to-savedvalues-table.html

Related

Hybris define product prices for PointOfService

Hybris Out of the box doesn't provide any friendly way to define prices for products at point of service/vendor level, I need to implement price for products per store, what is the best way to implement this?
I think the best approach is to make a composite attribute in the POS model with UserPriceGroup.
<typegroup name="PointOfService">
<itemtype code="PointOfService" autocreate="false" generate="false">
<attributes>
<attribute qualifier="posUsergroup" type="UserPriceGroup">
<persistence type="property"/>
<modifiers optional="false" initial="true"/>
</attribute>
</attributes>
</attributes>
</itemtype>
</typegroup>
--> PriceRow supports different prices based on UserPriceGroup.

SAP Hybris 1905 - Update OOTB 'relation'

I'm looking at updating an OOTB 'relation', just wanted to add 'ordered=true'.
OOTB
\hybris\bin\modules\commerce-services\commerceservices\resources\commerceservices-items.xml
<relation code="PoS2WarehouseRel" localized="false"
generate="true" autocreate="true">
<description>This relation determines available warehouses for the point of service.</description>
<deployment table="PoS2WarehouseRel" typecode="6217" />
<sourceElement qualifier="pointsOfService" type="PointOfService"
cardinality="many" />
<targetElement qualifier="warehouses" type="Warehouse"
cardinality="many" collectiontype="list" />
</relation>
In my extension core, myextncore-items.xml, I overwrote the OOTB relation,
<relation code="PoS2WarehouseRel" localized="false"
generate="true" autocreate="false">
<description>This relation determines available warehouses for the point of service.</description>
<sourceElement qualifier="pointsOfService" type="PointOfService"
cardinality="many" />
<targetElement qualifier="warehouses" type="Warehouse"
cardinality="many" collectiontype="list" ordered="true"/>
</relation>
But getting error - [ycheckdeployments] No deployment defined for relation PoS2WarehouseRel
Then I tried, Updating to a new code name, added a 'deployment' element,
<relation code="PoS2WarehouseRelNew" localized="false"
generate="true" autocreate="true">
<description>This relation determines available warehouses for the point of service.</description>
<deployment table="PoS2WarehouseRelNew" typecode="13000" />
<sourceElement qualifier="pointsOfService" type="PointOfService"
cardinality="many" />
<targetElement qualifier="warehouses" type="Warehouse"
cardinality="many" collectiontype="list" ordered="true"/>
</relation>
This time getting error - java.lang.UnsupportedOperationException: Attribute warehouses from PoS2WarehouseRelNew relation is already declared in Warehouse
How do I define/update a relation between 'pointsOfService' and 'warehouses' ?
Maybe the example here helps:
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/bae7ed9732a4423f867114217ae21b46.html
In that example they redeclared the Collection attribute on one end of the itemtype. But looks hacky...
UPDATE: The given link included relationType has ordered property but xsd file hasn't got. I haven't tried this yet, may be compiler give an error.
Relations haven't got ordered attribute. ordered attribute exist on collections. You can check xxx-item.xml file schema item.xsdin module folder.
I've encountered the same problem. No deployment was defined and when i did - got the same exception. In my case it was all about changing name in qualifier.
In this case i would change it to "posWarehouses" ;)

Redefining data type in items.xml in Hybris

I had a datatype defined as follows in items.xml:
<attribute qualifier="daysOfWeek" type="java.lang.String">
<persistence type="property" />
</attribute>
To modify the data type to enumeration,I redefined it as follows:
<enumtype code="DaysOfWeek" autocreate="true" generate="true">
<value code="Monday" />
<value code="Tuesday" />
</enumtype>
<attribute qualifier="daysOfWeek" type="DaysOfWeek">
<persistence type="property" />
</attribute>
After updating the extension,I am getting SQLException.Is there anything wrong with this approach?
hybris doesn't support updates like this in a "running" system.
The reason is that hybris won't drop any db columns and recreate them as any data contained in there would be lost (plus its probably difficult to write this logic for multiple supported databases).
If you are in a development phase of your project, the easiest way to fix this is to initialize your system from scratch (i.e. it will drop the database and recreate it).
If you have a live system / production system, you would have to take another approach:
You would define a new attribute (different name!) with your enumeration type.
You would then probably update any code to use the new field.
You would also have to take care of data migration, i.e. write some scripts that transfer the old data (e.g. the String "Monday" to the new respective enum value).
Hope this helps!

how to redeclare core model attribute type without extending it in Hybris

By default Hybtis gives CreditCardType as a mandatory attribute. I want to make it Optional by using redeclare=true (without extending it with new model). I am wondering why its not updating CreditCardPaymentInfo model. I am doing like this
<itemtype code="CreditCardPaymentInfo" autocreate="false" generate="false" >
<attributes>
<attribute qualifier="type" type="CreditCardType" redeclare="true" autocreate="false" generate="true">
<modifiers read="true" write="true" search="true" optional="true" />
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
My ant build is working fine. But whenever i m updating running system, Hybris is not making this attribute non mandatory.
In case if I am extending it with my custom model and re-declaring it then its working, but that's what i don't need. I just want to make it optional without extending it.
I think its possible with Impex also, but i don't know the way. Please help.
You can't redeclare an attribute without extending a type.
The documentation for redeclare says it clearly:
Lets you re-define the attribute definition from an inherited type. In
essence, you can use a different type of attribute as well as
different modifier combinations than on the supertype.
Impex to the rescue. You can alter attribute modifiers with an impex afterwards.
Place following impex script
update AttributeDescriptor;enclosingType(code)[unique=true];qualifier[unique=true];optional
;CreditCardPaymentInfo;type;true
under <your-extension>/resources/impex/essentialdata-<chosse-a-name>.impex.
On each typesystem update (or initialize) this impex gets executed and marks CreditCardPaymentInfo.type as optional. For testing purpose, you can run this script within hac, too.

Hybris - overriding existing unique attributes of an Item Type to make them non-unique

In my hybris application, I wanted to override my CustomerReview item type so that its attributes product and user are not unique anymore.
The uniqueness of these attributes are declared in the relationships between CustomerReview and Product/User. I tried adding the relationship declaration again to my extname-items.xml file and set the appropriate unique="false" attributes, as follows:
<relation generate="false" localized="false" code="ReviewToUserRel" autocreate="false">
<sourceElement type="User" qualifier="user" cardinality="one">
<modifiers write="false" initial="true" optional="false" unique="false" />
</sourceElement>
<targetElement type="CustomerReview" qualifier="customerReviews" cardinality="many">
<modifiers write="false" initial="true" />
</targetElement>
</relation>
This doesn't do the trick though. After I rebuild the application and Update the Running System, the user and product attributes of a CustomerReview are still unique attributes.
So what's the best solution for this problem?
It's true that rewriting the relation will not override it.
Another way to solve it would be to add an attribute to the type and set that as unique. For instance emailAddress:
<itemtype code="CustomerReview" autocreate="false" generate="false">
<attributes>
<attribute type="java.lang.String" qualifier="email">
<persistence type="property" />
<modifiers read="true" write="true" unique="true"/>
</attribute>
</attributes>
</itemtype>
Then you could have multiple reviews from the same user for the same product, as long as the emailAddress differs.
Updating the relation will not overwrite the existing relation. Better create new item definition for CustomerReview and then relate this with product.

Resources