|
|
|
@@ -42,13 +42,13 @@ public class SchematicNode {
|
|
|
|
|
TAB_CACHE.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final String nodeSelector = "SELECT NodeId, NodeOwner, NodeOwner AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode ";
|
|
|
|
|
private static final String nodeSelector = "SELECT NodeId, NodeOwner, NodeOwner AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode ";
|
|
|
|
|
|
|
|
|
|
private static final Table<SchematicNode> table = new Table<>(SchematicNode.class);
|
|
|
|
|
private static final Statement create = table.insertFields(true, "NodeOwner", "NodeName", "ParentNode", "NodeItem",
|
|
|
|
|
"NodeType");
|
|
|
|
|
private static final Statement update = table.update(Table.PRIMARY, "NodeName", "ParentNode", "NodeItem",
|
|
|
|
|
"NodeType", "NodeRank", "ReplaceColor", "AllowReplay");
|
|
|
|
|
"NodeType", "NodeRank", "Config");
|
|
|
|
|
private static final Statement delete = table.delete(Table.PRIMARY);
|
|
|
|
|
|
|
|
|
|
private static final SelectStatement<SchematicNode> byId = new SelectStatement<>(table,
|
|
|
|
@@ -66,13 +66,13 @@ public class SchematicNode {
|
|
|
|
|
private static final SelectStatement<SchematicNode> all = new SelectStatement<>(table,
|
|
|
|
|
"WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId");
|
|
|
|
|
private static final SelectStatement<SchematicNode> list = new SelectStatement<>(table,
|
|
|
|
|
"SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId "
|
|
|
|
|
"SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId "
|
|
|
|
|
+ Statement.NULL_SAFE_EQUALS
|
|
|
|
|
+ "? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName");
|
|
|
|
|
+ "? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName");
|
|
|
|
|
private static final SelectStatement<SchematicNode> byParentName = new SelectStatement<>(table,
|
|
|
|
|
"SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId "
|
|
|
|
|
"SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId "
|
|
|
|
|
+ Statement.NULL_SAFE_EQUALS
|
|
|
|
|
+ "? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?");
|
|
|
|
|
+ "? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?");
|
|
|
|
|
private static final SelectStatement<SchematicNode> schematicAccessibleForUser = new SelectStatement<>(table,
|
|
|
|
|
"WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE NodeId = ?");
|
|
|
|
|
private static final SelectStatement<SchematicNode> accessibleByUserTypeInParent = new SelectStatement<>(table,
|
|
|
|
@@ -81,7 +81,7 @@ public class SchematicNode {
|
|
|
|
|
private static final SelectStatement<SchematicNode> accessibleByUserType = new SelectStatement<>(table,
|
|
|
|
|
"WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.*, ? AS EffectiveOwner FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId WHERE NodeType = ?");
|
|
|
|
|
private static final SelectStatement<SchematicNode> byIdAndUser = new SelectStatement<>(table,
|
|
|
|
|
"SELECT NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, ReplaceColor, AllowReplay FROM SchematicNode WHERE NodeId = ?");
|
|
|
|
|
"SELECT NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE NodeId = ?");
|
|
|
|
|
private static final SelectStatement<SchematicNode> allParentsOfNode = new SelectStatement<>(table,
|
|
|
|
|
"WITH RECURSIVE R AS (SELECT NodeId, ParentNode FROM EffectiveSchematicNode WHERE NodeId = ? AND EffectiveOwner = ? UNION SELECT E.NodeId, E.ParentNode FROM R, EffectiveSchematicNode E WHERE R.ParentNode = E.NodeId AND E.EffectiveOwner = ?) SELECT SN.NodeId, SN.NodeOwner, ? AS EffectiveOwner, SN.NodeName, R.ParentNode, SN.LastUpdate, SN.NodeItem, SN.NodeType, SN.NodeRank, SN.ReplaceColor, SN.AllowReplay FROM R INNER JOIN SchematicNode SN ON SN.NodeId = R.NodeId");
|
|
|
|
|
|
|
|
|
@@ -108,10 +108,8 @@ public class SchematicNode {
|
|
|
|
|
private SchematicType nodeType;
|
|
|
|
|
@Field(def = "0")
|
|
|
|
|
private int nodeRank;
|
|
|
|
|
@Field(def = "1")
|
|
|
|
|
private boolean replaceColor;
|
|
|
|
|
@Field(def = "1")
|
|
|
|
|
private boolean allowReplay;
|
|
|
|
|
@Field
|
|
|
|
|
private int config;
|
|
|
|
|
|
|
|
|
|
private String brCache;
|
|
|
|
|
|
|
|
|
@@ -125,8 +123,7 @@ public class SchematicNode {
|
|
|
|
|
String nodeItem,
|
|
|
|
|
SchematicType nodeType,
|
|
|
|
|
int nodeRank,
|
|
|
|
|
boolean replaceColor,
|
|
|
|
|
boolean allowReplay) {
|
|
|
|
|
int config) {
|
|
|
|
|
this.nodeId = nodeId;
|
|
|
|
|
this.nodeOwner = nodeOwner;
|
|
|
|
|
this.effectiveOwner = effectiveOwner;
|
|
|
|
@@ -136,8 +133,7 @@ public class SchematicNode {
|
|
|
|
|
this.nodeType = nodeType;
|
|
|
|
|
this.lastUpdate = lastUpdate;
|
|
|
|
|
this.nodeRank = nodeRank;
|
|
|
|
|
this.replaceColor = replaceColor;
|
|
|
|
|
this.allowReplay = allowReplay;
|
|
|
|
|
this.config = config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<SchematicNode> getAll(SteamwarUser user) {
|
|
|
|
@@ -441,24 +437,45 @@ public class SchematicNode {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean replaceColor() {
|
|
|
|
|
return replaceColor;
|
|
|
|
|
return getConfig(ConfigFlags.REPLACE_COLOR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setReplaceColor(boolean replaceColor) {
|
|
|
|
|
if (isDir())
|
|
|
|
|
throw new SecurityException("Is Directory");
|
|
|
|
|
this.replaceColor = replaceColor;
|
|
|
|
|
updateDB();
|
|
|
|
|
setConfig(ConfigFlags.REPLACE_COLOR, replaceColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean allowReplay() {
|
|
|
|
|
return allowReplay;
|
|
|
|
|
return getConfig(ConfigFlags.ALLOW_REPLAY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAllowReplay(boolean allowReplay) {
|
|
|
|
|
if (isDir())
|
|
|
|
|
throw new SecurityException("Is Directory");
|
|
|
|
|
this.allowReplay = allowReplay;
|
|
|
|
|
setConfig(ConfigFlags.ALLOW_REPLAY, allowReplay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isPrepared() {
|
|
|
|
|
return getConfig(ConfigFlags.IS_PREPARED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPrepared(boolean prepared) {
|
|
|
|
|
if (isDir())
|
|
|
|
|
throw new SecurityException("Is Directory");
|
|
|
|
|
setConfig(ConfigFlags.IS_PREPARED, prepared);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getConfig(ConfigFlags flag) {
|
|
|
|
|
return (config & (1 << flag.ordinal())) == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setConfig(ConfigFlags flag, boolean value) {
|
|
|
|
|
if (value) {
|
|
|
|
|
config |= (1 << flag.ordinal());
|
|
|
|
|
} else {
|
|
|
|
|
config &= ~(1 << flag.ordinal());
|
|
|
|
|
}
|
|
|
|
|
updateDB();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -486,7 +503,7 @@ public class SchematicNode {
|
|
|
|
|
|
|
|
|
|
private void updateDB() {
|
|
|
|
|
this.lastUpdate = Timestamp.from(Instant.now());
|
|
|
|
|
update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, replaceColor, allowReplay, nodeId);
|
|
|
|
|
update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, config, nodeId);
|
|
|
|
|
TAB_CACHE.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -608,4 +625,10 @@ public class SchematicNode {
|
|
|
|
|
TAB_CACHE.computeIfAbsent(user.getId(), integer -> new HashMap<>()).putIfAbsent(cacheKey, list);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static enum ConfigFlags {
|
|
|
|
|
REPLACE_COLOR,
|
|
|
|
|
ALLOW_REPLAY,
|
|
|
|
|
IS_PREPARED
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|