geforkt von SteamWar/BungeeCore
Everthings Tested!
Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
3ac81810c4
Commit
2e5f0de710
@ -30,7 +30,7 @@ public class CheckedSchematic {
|
|||||||
|
|
||||||
private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC");
|
private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC");
|
||||||
private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
|
private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
|
||||||
private static final Statement insert = new Statement("INSERT INTO CheckedSchematic (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?)");
|
private static final Statement insert = new Statement("INSERT INTO CheckedSchematic (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
private final Integer node;
|
private final Integer node;
|
||||||
private final int validator;
|
private final int validator;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import java.sql.Blob;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@ -42,8 +41,16 @@ public class SchematicNode {
|
|||||||
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?");
|
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?");
|
||||||
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?");
|
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?");
|
||||||
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND s.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName");
|
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND s.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName");
|
||||||
|
private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ?");
|
||||||
|
private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null");
|
||||||
|
private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ?");
|
||||||
|
private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType is not null");
|
||||||
|
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
||||||
|
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN");
|
||||||
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
||||||
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
|
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
|
||||||
|
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||||
|
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
||||||
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
||||||
|
|
||||||
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
||||||
@ -166,21 +173,32 @@ public class SchematicNode {
|
|||||||
if (!rs.next())
|
if (!rs.next())
|
||||||
return null;
|
return null;
|
||||||
return new SchematicNode(rs);
|
return new SchematicNode(rs);
|
||||||
});
|
}, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, Integer parent) {
|
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||||
List<SchematicNode> schems = getAllSchematicsAccessibleByUser(owner);
|
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
||||||
schems.removeIf(node -> node.isDir() || !node.getType().equals(schemType));
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>();
|
while (rs.next()) {
|
||||||
for (SchematicNode schematicNode : schems) {
|
nodes.add(new SchematicNode(rs));
|
||||||
SchematicNode currentNode = schematicNode;
|
|
||||||
while (currentNode.getParent() != parent) {
|
|
||||||
currentNode = currentNode.getParentNode();
|
|
||||||
}
|
}
|
||||||
nodesInParent.putIfAbsent(currentNode.getId(), currentNode);
|
return nodes;
|
||||||
|
};
|
||||||
|
if(parent == null || parent == 0) {
|
||||||
|
return getAccessibleByUserByTypeInNode_Null.select(user, owner, owner, schemType);
|
||||||
|
} else {
|
||||||
|
return getAccessibleByUserByTypeInNode.select(user, owner, owner, parent, schemType);
|
||||||
}
|
}
|
||||||
return new ArrayList<>(nodesInParent.values());
|
}
|
||||||
|
|
||||||
|
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||||
|
return getAccessibleByUserByType.select(rs -> {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
nodes.add(new SchematicNode(rs));
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
|
}, user, user, schemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||||
@ -192,7 +210,6 @@ public class SchematicNode {
|
|||||||
}, owner, schemType);
|
}, owner, schemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||||
return getAllSchemsOfType.select(rs -> {
|
return getAllSchemsOfType.select(rs -> {
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
@ -218,18 +235,10 @@ public class SchematicNode {
|
|||||||
|
|
||||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
if (parent != null && parent != 0) {
|
if (parent != null && parent != 0) {
|
||||||
SchematicNode node = SchematicNode.getSchematicNode(parent);
|
if(isSchematicAccessibleForUser.select(rs -> {
|
||||||
boolean isAdded = false;
|
rs.next();
|
||||||
while (node.getId() != 0) {
|
return rs.getInt("Accessible") > 0;
|
||||||
for (NodeMember member:node.getMembers()) {
|
}, parent, user, user))
|
||||||
if (member.getMember() == user) {
|
|
||||||
isAdded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node = SchematicNode.getSchematicNode(node.getParent());
|
|
||||||
}
|
|
||||||
if(isAdded)
|
|
||||||
return getSchematicNodeInNode(parent);
|
return getSchematicNodeInNode(parent);
|
||||||
} else {
|
} else {
|
||||||
return getAccessibleByUser.select(rs -> {
|
return getAccessibleByUser.select(rs -> {
|
||||||
@ -243,20 +252,29 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
return getAccessibleByUser.select(rs -> {
|
return getAllSchematicsAccessibleByUser.select(rs -> {
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
SchematicNode node = new SchematicNode(rs);
|
nodes.add(new SchematicNode(rs));
|
||||||
if(node.isDir()) {
|
|
||||||
nodes.addAll(deepGet(node.getId(), node1 -> true));
|
|
||||||
} else {
|
|
||||||
nodes.add(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}, user, user);
|
}, user, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
||||||
|
return getAllParentsOfNode(node.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
|
return getAllParentsOfNode.select(rs -> {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
|
while(rs.next()) {
|
||||||
|
nodes.add(new SchematicNode(rs));
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
|
}, node);
|
||||||
|
}
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
private final int owner;
|
private final int owner;
|
||||||
private String name;
|
private String name;
|
||||||
@ -408,13 +426,6 @@ public class SchematicNode {
|
|||||||
this.brCache.clear();
|
this.brCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
|
||||||
if (isDir()) {
|
|
||||||
getSchematicNodeInNode(getId()).forEach(SchematicNode::delete);
|
|
||||||
}
|
|
||||||
deleteNode.update(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof SchematicNode))
|
if (!(obj instanceof SchematicNode))
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren