Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0005198: table constants for version each table introduced
- Loading branch information
Showing
8 changed files
with
372 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
symmetric-core/src/main/java/org/jumpmind/symmetric/common/ConfigurationVersionHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Licensed to JumpMind Inc under one or more contributor | ||
* license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding | ||
* copyright ownership. JumpMind Inc licenses this file | ||
* to you under the GNU General Public License, version 3.0 (GPLv3) | ||
* (the "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* You should have received a copy of the GNU General Public License, | ||
* version 3.0 (GPLv3) along with this library; if not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
* 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.jumpmind.symmetric.common; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.jumpmind.symmetric.Version; | ||
import org.jumpmind.symmetric.model.Node; | ||
|
||
public class ConfigurationVersionHelper { | ||
protected Set<String> proTables; | ||
protected Map<String, String> tablesByVersion; | ||
protected boolean isTargetNodePro; | ||
protected String targetNodeVersion; | ||
|
||
public ConfigurationVersionHelper(String tablePrefix) { | ||
proTables = TableConstants.getTablesForConsole(tablePrefix); | ||
tablesByVersion = TableConstants.getConfigTablesByVersion(tablePrefix); | ||
} | ||
|
||
public ConfigurationVersionHelper(String tablePrefix, Node targetNode) { | ||
this(tablePrefix); | ||
setTargetNode(targetNode); | ||
} | ||
|
||
public boolean shouldSendTable(String tableName) { | ||
if (!isTargetNodePro && proTables.contains(tableName)) { | ||
return false; | ||
} | ||
String tableVersion = tablesByVersion.get(tableName); | ||
if (tableVersion != null && Version.isOlderThanVersion(targetNodeVersion, tableVersion)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public Set<Node> filterNodes(Set<Node> nodes, String tableName) { | ||
boolean isProTable = proTables.contains(tableName); | ||
String tableVersion = tablesByVersion.get(tableName); | ||
if (isProTable || tableVersion != null) { | ||
Set<Node> targetNodes = new HashSet<Node>(nodes.size()); | ||
for (Node node : nodes) { | ||
setTargetNode(node); | ||
if ((!isProTable || isTargetNodePro) && (tableVersion == null || !Version.isOlderThanVersion(targetNodeVersion, tableVersion))) { | ||
targetNodes.add(node); | ||
} | ||
} | ||
return targetNodes; | ||
} else { | ||
return nodes; | ||
} | ||
} | ||
|
||
public void setTargetNode(Node targetNode) { | ||
targetNodeVersion = targetNode.getSymmetricVersion(); | ||
isTargetNodePro = StringUtils.equals(targetNode.getDeploymentType(), Constants.DEPLOYMENT_TYPE_PROFESSIONAL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.