cancel
Showing results for 
Search instead for 
Did you mean: 

while extending the Canonical Item in Data hub how to make the existing attribute in the canonical model as primary key.

0 Kudos

After extending the item from out of the box jars given by Hybris, Can we extend the existing column attribute and make it as a primary key?

0 Kudos

I am trying to extend the endDate attribute of CanonicalPrice Model from sappricing-canonical-6.0.0.0-RC6.jar which is readily available jar in Hybris package. and want to make endDate as primary key.

Accepted Solutions (0)

Answers (1)

Answers (1)

rafal_gdowski
Active Contributor
0 Kudos

The easiest way to approach this would be to create your own implementation of IntegrationKeyGenerationStrategy (specifically this method String generateKeyValue(final String type, final Map<String, ?> keyValues) )that appends the enddate only to the type you’re interested in.

 <!-- key generation strategy -->
     <alias name="alphabeticalIntegrationKeyGenerationStrategy" alias="integrationKeyGenerationStrategy" />
     <bean name="alphabeticalIntegrationKeyGenerationStrategy"
           class="com.hybris.datahub.composition.key.AlphabeticalIntegrationKeyGenerationStrategy">
     </bean>

and just override this bean with your implementation in an extension.

0 Kudos

Hi Rafal, I tried doing what you suggested also created my own implementation but the class(implementing "integrationKeyGenerationStrategy") I wrote is not getting triggered, I put some Sysout and I cannot see them getting executed on Command prompt. So can you please guide me about where and how to put this logic which you suggested.

rafal_gdowski
Active Contributor
0 Kudos

If I were to create a new bean named AppendEndDateIntKeyGenerationStrategy:

     <alias name="appendIntegrationKeyGenerationStrategy" alias="integrationKeyGenerationStrategy" />
   <bean name="alphabeticalIntegrationKeyGenerationStrategy"
            class="com.hybris.datahub.composition.key.AppendEndDateIntKeyGenerationStrategy">
      </bean>

if you drop an extension containing this file in a correctly named extension jar with

enddate-datahub-extension.xml (can be empty) and **enddate-datahub-extension-spring.xm*l containing the bean definition above it should do the trick. Having the correctly named -extension.xml file will force this bean to be loaded after the original implementation, thus overwriting the original implementation. Having the alias is important.