码迷,mamicode.com
首页 > 其他好文 > 详细

hybris interceptor 应用于对象保存前的数据验证

时间:2017-08-04 16:09:35      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:row   logs   div   etl   comm   ann   contex   err   pack   

package com.aaa.backoffice.Interceptors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.aaa.core.model.CAHOrderApprovedConfigModel;
import com.aaa.core.services.util.dao.CahCommonDao;

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.model.ModelService;

public class OrderApprovedConfigSavingInterceptor implements PrepareInterceptor<OrderApprovedConfigModel> {

    private final static Logger LOG = LoggerFactory.getLogger(OrderApprovedConfigSavingInterceptor.class);

    @Autowired
    private ModelService modelService;

    @Autowired
    private CahCommonDao cahCommonDao;

    @Override
    public void onPrepare(OrderApprovedConfigModel config, InterceptorContext arg1) throws InterceptorException {
        // 内容check
        checkSavedValues(config);
        // 保存Code
        String code = config.getSalesOrg().getUid()+"-"+config.getOrderReason().getCode()+"-"+config.getOrderType();
        config.setCode(code);
    }

    private void checkSavedValues(OrderApprovedConfigModel config) throws InterceptorException {

        if (null == config.getSalesOrg()) {
            throw new InterceptorException("请选择xxx!");
        }
        if (null == config.getOrderReason()) {
            throw new InterceptorException("请选择xxx!");
        }
        if (null == config.getOrderType()) {
            throw new InterceptorException("请选择xxx!");
        }
        if (null == config.getRoles()) {
            throw new InterceptorException("请选择角色!");
        }

       
    }
}

 

hybris interceptor 应用于对象保存前的数据验证

标签:row   logs   div   etl   comm   ann   contex   err   pack   

原文地址:http://www.cnblogs.com/wahaha603/p/7285467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!