on ‎2018 Oct 16 2:32 PM
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?
Request clarification before answering.
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");
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.