SAP Hybris 1905 - Update OOTB 'relation' - sap-commerce-cloud

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" ;)

Related

how to see if a relation is created in hybris?

I have created a relation in hybris. How to see if the relation was created? Is there a field created in backoffice or in code? My code
<relation code="CartEntries2B2BUnits" autocreate="true" localized="false" generate="true">
<sourceElement qualifier="cartEntry" type="CartEntry" cardinality="many">
<modifiers read="true" write="true" search="true" optional="true"/>
</sourceElement>
<targetElement qualifier="b2bUnit" type="B2BUnit" cardinality="one">
<modifiers read="true" write="true" search="true" optional="true"/>
</targetElement>
</relation>
After build you can see changes on java code. After initialize/update you can see new relation type and new fields on source and target type in type system at backoffice.
Sidenote
By an one-to-many relation you will find a new attribute on the model.
By a many-to-many relation an own ModelType will be created. Here is a picture with an example for it. other stackoverflow question

Hybris data modeling : custom properties

I am trying to understand custom properties in hybris data modeling;
Could anyone share useful links or information about it?
Item attributes define the state of an item. They are actually the columns of the the db table that is created (except the dynamic attributes) as a result of platform build and update process.
Custom attributes are certain defined attributes which are used in the type system definition to defined certain properties of a type. In general, if you interpret the metadata of the type system you may read the attributes to achieve the desired behaviour. They could be defined at various levels
At an item type level - Custom-properties are used to define properties for a type. For example
<custom-properties>
<property name="catalogItemType">
<value>java.lang.Boolean.TRUE</value>
</property>
<property name="catalogVersionAttributeQualifier">
<value>"catalogVersion"</value></property>
<property name="uniqueKeyAttributeQualifier">
<value>"id"</value>
</property>
</custom-properties>
these properties are defined at a type level - These attributes provide catalog awareness at a type level. These attributes could be retrieved these item type properties at runtime via the getProperty( String propertyName ) methodThere are other examples as well.
Relation level, please see the snippet below
<relation code="User2Addresses" generate="true" localized="false" autocreate="true">
<sourceElement type="User" cardinality="one" qualifier="owner">
<modifiers read="true" write="true" search="true" optional="true" initial="false"/>
</sourceElement>
<targetElement type="Address" cardinality="many" qualifier="addresses">
<modifiers read="true" write="true" search="true" optional="true" partof="true"/>
<custom-properties>
<property name="condition.query">
<value>"{original} is null"</value>
</property>
</custom-properties>
</targetElement>
</relation>
The property holds a string that is later added to the 'where' part of the select query generated for a one-to-many or many-to-one relation.
Ordering Attribute - By defining ordering.attribute, it is possible to specify which attribute will be used to order the many-side items when retrieving from the database
<relation code="AbstractOrder2AbstractOrderEntry" localized="false" generate="true" autocreate="true">
<sourceElement type="AbstractOrder" qualifier="order" cardinality="one">
<modifiers read="true" write="true" search="true" optional="true" />
<custom-properties>
<property name="ordering.attribute">
<value>"entryNumber"</value>
</property>
</custom-properties>
</sourceElement>
<targetElement type="AbstractOrderEntry" qualifier="entries" cardinality="many" collectiontype="list" ordered="false" >
<modifiers read="true" write="true" search="true" optional="true" partof="true" />
</targetElement>
</relation>
Backoffice Custom Attributes- Backoffice would allow to display all attributes of any type (out of the box), nevertheless there are some special (let's say technical) attributes that definitely should not be visible in the UI or should at least be readonly in the UI (no matter what the access rights they have). For those very rare case hybris have introduced two custom attributes that we interprete when the typesystem is scanned
<property name="readOnlyForUI">
<value>Boolean.TRUE</value>
</property>
<property name="hiddenForUI">
<value>Boolean.TRUE</value>
</property>
Hope this helps!
I hope you want to know about
<custom-properties>
<property name="catalogItemType">
<value>java.lang.Boolean.TRUE</value>
</property>
<property name="catalogVersionAttributeQualifier">
<value>"catalogVersion"</value>
</property>
<property name="uniqueKeyAttributeQualifier">
<value>"code"</value>
</property>
</custom-properties>
These <custom-properties> are used to define ItemType as catalog aware. Like Product Type.
Refer helphybris post for more detail
Have a look at The Type System in Hybris Help, as well as Data Models in the Hybris123 section.
Models are defined per extension in extensionname-items.xml, and generated during the build process.
In order for model updates to be reflected in the type system of your instance, run a system update in HAC > Platform > Update. For more information, see also Initializing and Updating SAP Hybris Commerce.

Limit number of results in, or remove, attributechip from hmc admin tab

I have a list relation within one of my items in Hybris. This list is not necessary to display in the HMC admin tab and is causing long load times when viewing the item.
I'm having difficulty trying to limit the number of results displayed or remove the particular attributechip from the HMC all together using the hmc.xml.
Any advice would be appreciated.
Thanks
<relation code="Favorite2ProductRelation" localized="false"
generate="true" autocreate="true">
<sourceElement type="Favorite" qualifier="favorite"
cardinality="many">
<modifiers read="true" write="true" search="true" />
<custom-properties>
<property name="hiddenForUI">
<value>Boolean.TRUE</value>
</property>
</custom-properties>
</sourceElement>
<targetElement type="Product" qualifier="product"
cardinality="one">
<modifiers read="true" write="true" search="true" initial="true"
optional="false" />
</targetElement>
In the attribute definition you can set the property hiddenForUI, it will hide the field from bo :
<attribute ...>
<custom-properties>
<property name="hiddenForUI">
<value>Boolean.TRUE</value>
</property>
</custom-properties>
</attribute>
However it seems that it can't be used in relation...
You can switch the attribute value using impex :
INSERT_UPDATE RelationDescriptor;qualifier[unique=true];hiddenForUI[default=true]
;<attributeOfYourRelationToHide>;
If you have an attribute name present in different objects, you can specify which object you working on with enclosingType (thanks to Mouad El Fakir for the recall)
INSERT_UPDATE RelationDescriptor;enclosingType(code)[unique=true];qualifier[unique=true];hiddenForUI[default=true]
;<objectHoldingTheAttributeToHide>;<attributeOfYourRelationToHide>;

Can someone explain details of hybris auditing system?

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

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