cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

In Hybris do I create validation rule that checks user uid using data validation framework?

Former Member
0 Likes
1,189

I'm learning Hybris Data Validation Framework. I see that I can't modify User generated class. Should I create a User POJO using beans-xml to achieve what I need?

Accepted Solutions (0)

Answers (1)

Answers (1)

geffchang
Active Contributor
0 Likes

You can implement a Validate Interceptor for your Model. See: https://help.hybris.com/1808/hcd/8bfbf43e8669101480d0f060d79b1baa.html

Example (from Hybris source code) - Create PriceRowValidateInterceptor for PriceRowModel:

 package de.hybris.platform.product.impl;
 
 import de.hybris.platform.catalog.model.CatalogVersionModel;
 import de.hybris.platform.core.model.product.ProductModel;
 import de.hybris.platform.core.model.product.UnitModel;
 import de.hybris.platform.europe1.model.PDTRowModel;
 import de.hybris.platform.europe1.model.PriceRowModel;
 import de.hybris.platform.jalo.JaloInvalidParameterException;
 import de.hybris.platform.servicelayer.interceptor.Interceptor;
 import de.hybris.platform.servicelayer.interceptor.InterceptorContext;
 import de.hybris.platform.servicelayer.interceptor.InterceptorException;
 import de.hybris.platform.servicelayer.interceptor.PrepareInterceptor;
 import de.hybris.platform.servicelayer.interceptor.ValidateInterceptor;
 
 
 public class PriceRowValidateInterceptor implements ValidateInterceptor<PriceRowModel>
 {
 
     @Override
     public void onValidate(final PriceRowModel priceRow, final InterceptorContext ctx) throws InterceptorException
     {
         validateMinQuantity(priceRow);
         validateUnitFactor(priceRow);
     }
 
     private void validateMinQuantity(final PriceRowModel priceRow) throws InterceptorException
     {
         if (priceRow.getMinqtd() == null || priceRow.getMinqtd() < 0)
         {
             throw new InterceptorException("Min quantity must be equal or greater zero but was " + priceRow.getMinqtd());
         }
     }
 
     private void validateUnitFactor(final PriceRowModel priceRow) throws InterceptorException
     {
         if (priceRow.getUnitFactor() == null)
         {
             throw new InterceptorException("Unit factor cannot be null");
         }
         else if (priceRow.getUnitFactor() == 0)
         {
             throw new InterceptorException("Unit factor cannot be zero");
         }
     }
 }
Former Member
0 Likes

thanks. the thing is, I need annotations to be used. like @Size(min = 3, max = 10). it looks easy. but I can't understand how I can apply this in a generated UserModel class.

geffchang
Active Contributor
0 Likes

Not using annotations, another way would be by impex. See #1 for example: https://help.hybris.com/1808/hcd/7ed4232ec84a4fb683d43a2c38f54cfb.html

Like you said, I don't think you can use annotations with models, because they get rebuilt every time you do a build.