View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.data.pipeline.core.consistencycheck.result.yaml;
19  
20  import com.google.common.base.Strings;
21  import org.apache.shardingsphere.data.pipeline.core.consistencycheck.result.TableDataConsistencyCheckIgnoredType;
22  import org.apache.shardingsphere.data.pipeline.core.consistencycheck.result.TableDataConsistencyCheckResult;
23  import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
24  import org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
25  
26  /**
27   * Yaml table data consistency check result swapper.
28   */
29  public final class YamlTableDataConsistencyCheckResultSwapper implements YamlConfigurationSwapper<YamlTableDataConsistencyCheckResult, TableDataConsistencyCheckResult> {
30      
31      @Override
32      public YamlTableDataConsistencyCheckResult swapToYamlConfiguration(final TableDataConsistencyCheckResult data) {
33          YamlTableDataConsistencyCheckResult result = new YamlTableDataConsistencyCheckResult();
34          if (data.isIgnored()) {
35              result.setIgnoredType(data.getIgnoredType().name());
36              return result;
37          }
38          result.setMatched(data.isMatched());
39          return result;
40      }
41      
42      @Override
43      public TableDataConsistencyCheckResult swapToObject(final YamlTableDataConsistencyCheckResult yamlConfig) {
44          if (null == yamlConfig) {
45              return null;
46          }
47          if (!Strings.isNullOrEmpty(yamlConfig.getIgnoredType())) {
48              return new TableDataConsistencyCheckResult(TableDataConsistencyCheckIgnoredType.valueOf(yamlConfig.getIgnoredType()));
49          }
50          return new TableDataConsistencyCheckResult(yamlConfig.isMatched());
51      }
52      
53      /**
54       * Swap string to data consistency check result.
55       *
56       * @param param parameter
57       * @return data consistency check result
58       */
59      public TableDataConsistencyCheckResult swapToObject(final String param) {
60          return swapToObject(YamlEngine.unmarshal(param, YamlTableDataConsistencyCheckResult.class, true));
61      }
62  }