All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flyfish.oauth.common.sync.methods.DeleteSyncRequestAcceptor Maven / Gradle / Ivy

package com.flyfish.oauth.common.sync.methods;

import com.flyfish.oauth.client.RestClient;
import com.flyfish.oauth.common.Function;
import com.flyfish.oauth.common.sync.AbstractSyncRequestAcceptor;
import com.flyfish.oauth.common.sync.support.CollectionComparator;
import com.flyfish.oauth.configuration.sync.SyncDomainService;
import com.flyfish.oauth.utils.ContainUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 删除的方法支持,直接删除标识符撞击后的数据
 *
 * @author wangyu
 */
public class DeleteSyncRequestAcceptor extends AbstractSyncRequestAcceptor {

    /**
     * 比较并返回比较结果,根据不同实现策略进行不同的比较
     *
     * @param originList    原数据
     * @param domainService 数据service
     * @return 结果
     */
    @Override
    protected  CollectionComparator compare(List originList, SyncDomainService domainService) throws Exception {
        Function keyFunction = identifierFunction(domainService);
        List identifiers = ContainUtils.getIdentifiers(originList, keyFunction);
        // 查询出本批次存在的数据
        List saved = domainService.getList(identifiers);
        // 删除撞击的数据
        domainService.deleteAll(saved);
        // 记录一下
        return CollectionComparator.newInstance(saved, originList, keyFunction);
    }

    /**
     * 匹配
     *
     * @param request 请求
     * @return 结果
     */
    @Override
    public boolean accept(HttpServletRequest request) {
        return request.getMethod().equalsIgnoreCase(RestClient.HttpMethod.DELETE.name());
    }
}