/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.core.rule;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import lombok.Getter;
import org.apache.shardingsphere.api.config.encryptor.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.api.config.encryptor.EncryptorConfiguration;
import org.apache.shardingsphere.core.encrypt.ShardingEncryptorFactory;
import org.apache.shardingsphere.core.encrypt.ShardingEncryptorStrategy;
import org.apache.shardingsphere.spi.algorithm.encrypt.ShardingEncryptor;

import java.util.Collections;
import java.util.List;

/**
 * Encrypt table rule.
 *
 * @author panjuan
 */
@Getter
public final class EncryptTableRule {
    
    private final String table;
    
    private final ShardingEncryptorStrategy shardingEncryptorStrategy;
    
    public EncryptTableRule(final EncryptTableRuleConfiguration tableRuleConfig) {
        table = tableRuleConfig.getTable();
        shardingEncryptorStrategy = null == tableRuleConfig.getEncryptorConfig() ? null : getShardingEncryptorStrategy(tableRuleConfig.getEncryptorConfig());
    }
    
    private ShardingEncryptorStrategy getShardingEncryptorStrategy(final EncryptorConfiguration encryptorConfiguration) {
        ShardingEncryptor shardingEncryptor = ShardingEncryptorFactory.getInstance().newAlgorithm(encryptorConfiguration.getType(), encryptorConfiguration.getProperties());
        List<String> columns = Splitter.on(",").trimResults().splitToList(encryptorConfiguration.getColumns());
        List<String> assistedQueryColumns = Strings.isNullOrEmpty(encryptorConfiguration.getAssistedQueryColumns())
                ? Collections.<String>emptyList() : Splitter.on(",").trimResults().splitToList(encryptorConfiguration.getAssistedQueryColumns());
        return new ShardingEncryptorStrategy(columns, assistedQueryColumns, shardingEncryptor);
    }
}

@@ -846,87 +846,8 @@
 e;%0A%0A
-import com.google.common.base.Splitter;%0Aimport com.google.common.base.Strings;%0A
 impo
@@ -986,324 +986,46 @@
 ere.
-api.config.encryptor.EncryptorConfiguration;%0Aimport org.apache.shardingsphere.core.encrypt.ShardingEncryptorFactory;%0Aimport org.apache.shardingsphere.core.encrypt.ShardingEncryptorStrategy;%0Aimport org.apache.shardingsphere.spi.algorithm.encrypt.ShardingEncryptor;%0A%0Aimport java.util.Collections;%0Aimport java.util.List
+core.encrypt.ShardingEncryptorStrategy
 ;%0A%0A/
@@ -1461,849 +1461,74 @@
 l : 
-getShardingEncryptorStrategy(tableRuleConfig.getEncryptorConfig());%0A    %7D%0A    %0A    private ShardingEncryptorStrategy getShardingEncryptorStrategy(final EncryptorConfiguration encryptorConfiguration) %7B%0A        ShardingEncryptor shardingEncryptor = ShardingEncryptorFactory.getInstance().newAlgorithm(encryptorConfiguration.getType(), encryptorConfiguration.getProperties());%0A        List%3CString%3E columns = Splitter.on(%22,%22).trimResults().splitToList(encryptorConfiguration.getColumns());%0A        List%3CString%3E assistedQueryColumns = Strings.isNullOrEmpty(encryptorConfiguration.getAssistedQueryColumns())%0A                ? Collections.%3CString%3EemptyList() : Splitter.on(%22,%22).trimResults().splitToList(encryptorConfiguration.getAssistedQueryColumns());%0A        return new ShardingEncryptorStrategy(columns, assistedQueryColumns, shardingEncryptor
+new ShardingEncryptorStrategy(tableRuleConfig.getEncryptorConfig()
 );%0A 

create shardingEncryptorStrategy