Fixing SchemNode Translation Layer
Dieser Commit ist enthalten in:
Ursprung
77f1e48c6e
Commit
bdfc5e8b0e
@ -83,6 +83,24 @@ public class CheckedSchematic {
|
||||
return lastDeclined;
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
|
||||
List<CheckedSchematic> lastDeclined = new LinkedList<>();
|
||||
try{
|
||||
ResultSet lastRS = SQL.select("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC", SteamwarUser.get(uuid).getId());
|
||||
while(lastRS.next()){
|
||||
int node = lastRS.getInt("NodeId");
|
||||
int validator = lastRS.getInt("Validator");
|
||||
Timestamp startTime = lastRS.getTimestamp("StartTime");
|
||||
Timestamp endTime = lastRS.getTimestamp("EndTime");
|
||||
String declineReason = lastRS.getString("DeclineReason");
|
||||
lastDeclined.add(new CheckedSchematic(node, validator, startTime, endTime, declineReason, false));
|
||||
}
|
||||
}catch(SQLException e){
|
||||
Bukkit.getLogger().log(Level.SEVERE, "getLastDeclined failed", e);
|
||||
}
|
||||
return lastDeclined;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
SQL.update("DELETE FROM CheckedSchematic WHERE NodeId", node);
|
||||
}
|
||||
|
@ -48,7 +48,10 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public static Schematic getSchemFromDB(String schemName, int schemOwner){
|
||||
return new Schematic(SchematicNode.getSchematicNode(schemOwner, schemName, 0));
|
||||
SchematicNode node = SchematicNode.getSchematicNode(schemOwner, schemName, (Integer) null);
|
||||
if(node == null)
|
||||
return null;
|
||||
return new Schematic(node);
|
||||
}
|
||||
|
||||
public static Schematic getSchemFromDB(int schemID){
|
||||
@ -62,7 +65,9 @@ public class Schematic {
|
||||
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
|
||||
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(schemOwner, 0);
|
||||
List<Schematic> schematics = new ArrayList<>();
|
||||
nodes.forEach(node1 -> schematics.add(new Schematic(node1)));
|
||||
nodes.forEach(node1 -> {
|
||||
if (!node1.isDir()) schematics.add(new Schematic(node1));
|
||||
});
|
||||
return schematics;
|
||||
}
|
||||
|
||||
|
@ -33,39 +33,42 @@ import java.util.*;
|
||||
|
||||
public class SchematicNode {
|
||||
|
||||
public static SchematicNode createSchematic(int owner, String name, int parent) {
|
||||
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
||||
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
||||
}
|
||||
|
||||
public static SchematicNode createSchematicDirectory(int owner, String name, int parent) {
|
||||
public static SchematicNode createSchematicDirectory(int owner, String name, Integer parent) {
|
||||
return createSchematicNode(owner, name, parent, null, "");
|
||||
}
|
||||
|
||||
public static SchematicNode createSchematicNode(int owner, String name, int parent, String type, String item) {
|
||||
public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||
if(parent == 0)
|
||||
parent = null;
|
||||
SQL.update("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)",
|
||||
name, owner, parent, type, item);
|
||||
return getSchematicNode(owner, name, type, parent);
|
||||
return getSchematicNode(owner, name, parent);
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int owner, String name, String type, int parent) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ? AND NodeType = ?", owner, name, parent, type);
|
||||
try {
|
||||
if(!set.next())
|
||||
return null;
|
||||
return new SchematicNode(set);
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("Failed to load Schemnodes", e);
|
||||
public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name);
|
||||
}else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
|
||||
}
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int owner, String name, int parent) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
|
||||
try {
|
||||
while (set.next()) {
|
||||
SchematicNode node = new SchematicNode(set);
|
||||
if(!node.isDir())
|
||||
return node;
|
||||
}
|
||||
List<SchematicNode> nodes = getSchematicNodeInNode(parent);
|
||||
for (SchematicNode node:nodes) {
|
||||
if(!node.isDir() && node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null)
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("Failed to load Schemnodes", e);
|
||||
@ -76,8 +79,15 @@ public class SchematicNode {
|
||||
return getSchematicNode(owner, name, parent.getId());
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicNodeInNode(int parent) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode = ?", parent);
|
||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode is NULL");
|
||||
}else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode = ?", parent);
|
||||
}
|
||||
try {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while (set.next())
|
||||
@ -92,12 +102,19 @@ public class SchematicNode {
|
||||
return getSchematicNodeInNode(parent.getId());
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicDirectory(int owner, String name, SchematicNode parent) {
|
||||
return getSchematicDirectory(owner, name, parent.getId());
|
||||
public static SchematicNode getSchematicDirectory(String name, SchematicNode parent) {
|
||||
return getSchematicDirectory(name, parent.getId());
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicDirectory(int owner, String name, int parent) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
|
||||
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
||||
}else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||
}
|
||||
try {
|
||||
while (set.next()) {
|
||||
SchematicNode node = new SchematicNode(set);
|
||||
@ -110,8 +127,15 @@ public class SchematicNode {
|
||||
}
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicInParent(String name, int parent) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||
public static SchematicNode getSchematicInParent(String name, Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
||||
}else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||
}
|
||||
try {
|
||||
while (set.next()) {
|
||||
SchematicNode node = new SchematicNode(set);
|
||||
@ -159,7 +183,9 @@ public class SchematicNode {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, int parent) {
|
||||
public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
List<SchematicNode> schems = getAllSchematicsOfType(owner, schemType);
|
||||
Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>();
|
||||
for (SchematicNode schematicNode : schems) {
|
||||
@ -172,8 +198,8 @@ public class SchematicNode {
|
||||
return new ArrayList<>(nodesInParent.values());
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, int parent) {
|
||||
if(parent != 0) {
|
||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||
if(parent != null && parent != 0) {
|
||||
SchematicNode node = SchematicNode.getSchematicNode(parent);
|
||||
boolean isAdded = false;
|
||||
while (node.getId() != 0) {
|
||||
@ -187,16 +213,18 @@ public class SchematicNode {
|
||||
}
|
||||
if(isAdded)
|
||||
return getSchematicNodeInNode(parent);
|
||||
} else {
|
||||
ResultSet set = SQL.select("SELECT * 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", user, user);
|
||||
try{
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while(set.next())
|
||||
nodes.add(new SchematicNode(set));
|
||||
return nodes;
|
||||
}catch(SQLException e){
|
||||
throw new SecurityException("Failed listing schematics", e);
|
||||
}
|
||||
}
|
||||
ResultSet set = SQL.select("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode FROM SchematicNode s LEFT JOIN NodeMember nm ON nm.NodeId = s.NodeId WHERE ( s.NodeOwner = ? OR nm.UserId = ? ) AND s.ParentNode = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user, parent);
|
||||
try{
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while(set.next())
|
||||
nodes.add(new SchematicNode(set));
|
||||
return nodes;
|
||||
}catch(SQLException e){
|
||||
throw new SecurityException("Failed listing schematics", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||
@ -231,7 +259,7 @@ public class SchematicNode {
|
||||
if(type != null) {
|
||||
isDir = false;
|
||||
rank = set.getInt("NodeRank");
|
||||
schemFormat = set.getBoolean("SchemFormat");
|
||||
schemFormat = set.getBoolean("NodeFormat");
|
||||
}else {
|
||||
isDir = true;
|
||||
}
|
||||
@ -417,7 +445,7 @@ public class SchematicNode {
|
||||
}
|
||||
|
||||
private void updateDatabase(Blob blob, boolean newFormat) {
|
||||
SQL.update("UPDATE SchematicNode SET NodeData = ?, SchemFormat = ? WHERE NodeId = ?", blob, newFormat, id);
|
||||
SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id);
|
||||
schemFormat = newFormat;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren