Archiviert
1
0

Fixing Merge Conflicts & Updating!

Dieser Commit ist enthalten in:
Chaoscaot 2021-11-12 15:52:15 +01:00
Ursprung a9172929be
Commit 3ac81810c4
5 geänderte Dateien mit 194 neuen und 162 gelöschten Zeilen

Datei anzeigen

@ -53,13 +53,13 @@ public class SchematicsManager {
CheckCommand.getSchemsToCheck().forEach(schematic -> { CheckCommand.getSchemsToCheck().forEach(schematic -> {
StringBuilder st = new StringBuilder(); StringBuilder st = new StringBuilder();
st.append("Typ: ").append(schematic.getSchemType().getKuerzel()); st.append("Typ: ").append(schematic.getSchemtype().getKuerzel());
st.append("\nVon: ").append(SteamwarUser.get(schematic.getSchemOwner()).getUserName()); st.append("\nVon: ").append(SteamwarUser.get(schematic.getOwner()).getUserName());
String checker = CheckCommand.getChecker(schematic); String checker = CheckCommand.getChecker(schematic);
if (checker != null) { if (checker != null) {
st.append("\nWird Geprüft von: ").append(checker); st.append("\nWird Geprüft von: ").append(checker);
} }
embedBuilder.addField(schematic.getSchemName(), st.toString(), true); embedBuilder.addField(schematic.getName(), st.toString(), true);
}); });
MessageBuilder messageBuilder = new MessageBuilder(); MessageBuilder messageBuilder = new MessageBuilder();

Datei anzeigen

@ -111,7 +111,7 @@ public class CheckCommand extends BasicCommand {
} }
} }
private static List<SchematicNode> getSchemsToCheck(){ public static List<SchematicNode> getSchemsToCheck(){
List<SchematicNode> schematicList = new LinkedList<>(); List<SchematicNode> schematicList = new LinkedList<>();
for (SchematicType type : SchematicType.values()) { for (SchematicType type : SchematicType.values()) {
@ -243,8 +243,8 @@ public class CheckCommand extends BasicCommand {
SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getId(), 0); SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getId(), 0);
currentCheckers.put(checker.getUniqueId(), this); currentCheckers.put(checker.getUniqueId(), this);
currentSchems.put(schematic.getId(), this); currentSchems.put(schematic.getId(), this);
for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getId())) for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic))
Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getReason()); Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason());
next(0); next(0);
}); });
} }
@ -294,7 +294,7 @@ public class CheckCommand extends BasicCommand {
} }
schematic.setType(schematic.getSchemtype().fightType().toDB()); schematic.setType(schematic.getSchemtype().fightType().toDB());
CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
SteamwarUser user = SteamwarUser.get(schematic.getOwner()); SteamwarUser user = SteamwarUser.get(schematic.getOwner());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
if(player != null) { if(player != null) {
@ -308,7 +308,7 @@ public class CheckCommand extends BasicCommand {
private void decline(String reason){ private void decline(String reason){
schematic.setType(SchematicType.Normal.toDB()); schematic.setType(SchematicType.Normal.toDB());
CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
SteamwarUser user = SteamwarUser.get(schematic.getOwner()); SteamwarUser user = SteamwarUser.get(schematic.getOwner());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
if(player != null) { if(player != null) {
@ -321,13 +321,13 @@ public class CheckCommand extends BasicCommand {
} }
private void abort(){ private void abort(){
CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen"); CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen");
stop(); stop();
} }
private void stop(){ private void stop(){
currentCheckers.remove(checker.getUniqueId()); currentCheckers.remove(checker.getUniqueId());
currentSchems.remove(schematic.getSchemID()); currentSchems.remove(schematic.getId());
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) { for (Subserver subserver : Subserver.getServerList()) {
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) { if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) {
@ -340,7 +340,7 @@ public class CheckCommand extends BasicCommand {
private void remove() { private void remove() {
currentCheckers.remove(checker.getUniqueId()); currentCheckers.remove(checker.getUniqueId());
currentSchems.remove(schematic.getSchemID()); currentSchems.remove(schematic.getId());
} }
} }
} }

Datei anzeigen

@ -24,56 +24,97 @@ import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class CheckedSchematic { public class CheckedSchematic {
private static final Statement create = new Statement("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)"); 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 previous = new Statement("SELECT * FROM CheckedSchematic WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC"); 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 final String schemName;
private final int schemOwner;
private final Integer node;
private final int validator; private final int validator;
private final Timestamp startTime; private final Timestamp startTime;
private final Timestamp endTime; private final Timestamp endTime;
private final String reason; private final String declineReason;
private CheckedSchematic(ResultSet rs) throws SQLException { private CheckedSchematic(ResultSet rs) throws SQLException {
nodeId = rs.getInt("NodeId"); this.node = rs.getInt("NodeId");
validator = rs.getInt("Validator"); this.validator = rs.getInt("Validator");
startTime = rs.getTimestamp("StartTime"); this.startTime = rs.getTimestamp("StartTime");
endTime = rs.getTimestamp("EndTime"); this.endTime = rs.getTimestamp("EndTime");
reason = rs.getString("DeclineReason"); this.declineReason = rs.getString("DeclineReason");
} }
public static void create(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String reason){ public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){
SQL.update("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)", insert.update(nodeId, name, owner, validator, startTime, endTime, reason);
schemName, schemOwner, validator, startTime, endTime, reason);
} }
public static List<CheckedSchematic> previousChecks(String schemName, int schemOwner){ public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason){
ResultSet rs = SQL.select("SELECT * FROM CheckedSchematic WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC", schemName, schemOwner); create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason);
}
public static List<CheckedSchematic> previousChecks(SchematicNode node){
return nodeHistory.select(rs -> {
List<CheckedSchematic> schematics = new ArrayList<>(); List<CheckedSchematic> schematics = new ArrayList<>();
try {
while(rs.next()) while(rs.next())
schematics.add(new CheckedSchematic(rs)); schematics.add(new CheckedSchematic(rs));
return schematics; return schematics;
}, schemName, schemOwner); }, node.getId());
}
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){
return getLastDeclinedOfNode(node.getId());
}
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
return nodeHistory.select(rs -> {
List<CheckedSchematic> lastDeclined = new ArrayList<>();
while(rs.next()){
lastDeclined.add(new CheckedSchematic(rs));
}
return lastDeclined;
}, node);
}
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
return getLastDelined(SteamwarUser.get(uuid).getId());
}
public static List<CheckedSchematic> getLastDelined(int schemOwner){
return checkHistory.select(rs -> {
List<CheckedSchematic> history = new ArrayList<>();
while(rs.next())
history.add(new CheckedSchematic(rs));
return history;
}, schemOwner);
} }
public int getValidator() { public int getValidator() {
return validator; return validator;
} }
public Timestamp getStartTime() {
return startTime;
}
public Timestamp getEndTime() { public Timestamp getEndTime() {
return endTime; return endTime;
} }
public String getReason() { public String getDeclineReason() {
return reason; return declineReason;
} }
public int getNodeId() { public int getNode() {
return nodeId; return node;
}
public String getSchemName() {
return SchematicNode.getSchematicNode(node).getName();
}
public int getSchemOwner() {
return SchematicNode.getSchematicNode(node).getId();
} }
} }

Datei anzeigen

@ -25,43 +25,40 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class NodeMember { public class NodeMember {
private static final Statement getNodeMember = new Statement("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?");
private static final Statement getNodeMembers = new Statement("SELECT * FROM NodeMember WHERE NodeId = ?");
private static final Statement getSchematics = new Statement("SELECT * FROM NodeMember WHERE UserId = ?");
private static final Statement createNodeMember = new Statement("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)");
private static final Statement deleteNodeMember = new Statement("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?");
public static NodeMember getNodeMember(int node, int member) { public static NodeMember getNodeMember(int node, int member) {
ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?", node, member); return getNodeMember.select(rs -> {
try { if(!rs.next())
if(!set.next())
return null; return null;
return new NodeMember(set); return new NodeMember(rs);
} catch (SQLException e) { }, node, member);
throw new SecurityException("Could not load NodeMember", e);
}
} }
public static Set<NodeMember> getNodeMembers(int node) { public static Set<NodeMember> getNodeMembers(int node) {
ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE NodeId = ?", node); return getNodeMembers.select(rs -> {
try {
Set<NodeMember> members = new HashSet<>(); Set<NodeMember> members = new HashSet<>();
while (set.next()) while (rs.next())
members.add(new NodeMember(set)); members.add(new NodeMember(rs));
return members; return members;
} catch (SQLException e) { }, node);
throw new SecurityException("Could not load NodeMember", e);
}
} }
public static Set<NodeMember> getSchematics(int member) { public static Set<NodeMember> getSchematics(int member) {
ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE UserId = ?", member); return getSchematics.select(rs -> {
try {
Set<NodeMember> members = new HashSet<>(); Set<NodeMember> members = new HashSet<>();
while (set.next()) while (rs.next())
members.add(new NodeMember(set)); members.add(new NodeMember(rs));
return members; return members;
} catch (SQLException e) { }, member);
throw new SecurityException("Could not load NodeMember", e);
}
} }
public static NodeMember createNodeMember(int node, int member) { public static NodeMember createNodeMember(int node, int member) {
SQL.update("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)", node, member); createNodeMember.update(node, member);
return getNodeMember(node, member); return getNodeMember(node, member);
} }
@ -82,6 +79,6 @@ public class NodeMember {
} }
public void delete() { public void delete() {
SQL.update("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?", node, member); deleteNodeMember.update(node, member);
} }
} }

Datei anzeigen

@ -29,6 +29,23 @@ import java.util.function.Predicate;
public class SchematicNode { public class SchematicNode {
private static final Statement createNode = new Statement("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)");
private static final Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL");
private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?");
private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL");
private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?");
private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL");
private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?");
private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?");
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 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 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 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) {
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), ""); return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
} }
@ -40,8 +57,7 @@ public class SchematicNode {
public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) { public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
if (parent == 0) if (parent == 0)
parent = null; 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)", createNode.update(name, owner, parent, type, item);
name, owner, parent, type, item);
return getSchematicNode(owner, name, parent); return getSchematicNode(owner, name, parent);
} }
@ -77,105 +93,85 @@ public class SchematicNode {
} }
public static SchematicNode getSchematicNode(int owner, String name, Integer parent) { public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
if (parent != null && parent == 0) if (parent != null && parent == 0) {
parent = null; parent = null;
ResultSet set;
if (parent == null) {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name);
} else {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
} }
try { Statement.ResultSetUser<SchematicNode> user = rs -> {
while (set.next()) { while (rs.next()) {
SchematicNode node = new SchematicNode(set); SchematicNode node = new SchematicNode(rs);
return node;
}
List<SchematicNode> nodes = getSchematicNodeInNode(parent);
for (SchematicNode node:nodes) {
if (node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null)
return node; return node;
} }
return null; return null;
}catch (SQLException e) { };
throw new SecurityException("Failed to load Schemnodes", e); if(parent == null) {
return getSchematicNode_Null.select(user, owner, name);
} else {
return getSchematicNode.select(user, owner, name, parent);
} }
} }
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) { public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
if(parent != null && parent == 0) if(parent != null && parent == 0)
parent = null; parent = null;
ResultSet set; Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
if(parent == null) {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL");
}else {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?", parent);
}
try {
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
while (set.next()) while (rs.next())
nodes.add(new SchematicNode(set)); nodes.add(new SchematicNode(rs));
return nodes; return nodes;
}catch (SQLException e) { };
throw new SecurityException("Failed to load Schemnodes", e); if(parent == null) {
return getSchematicsInNode_Null.select(user);
}else {
return getSchematicsInNode.select(user, parent);
} }
} }
public static SchematicNode getSchematicDirectory(String name, Integer parent) { public static SchematicNode getSchematicDirectory(String name, Integer parent) {
if(parent != null && parent == 0) if(parent != null && parent == 0)
parent = null; parent = null;
ResultSet set; Statement.ResultSetUser<SchematicNode> user = rs -> {
if(parent == null) { while (rs.next()) {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent); SchematicNode node = new SchematicNode(rs);
}else {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
}
try {
while (set.next()) {
SchematicNode node = new SchematicNode(set);
if(node.isDir()) if(node.isDir())
return node; return node;
} }
return null; return null;
}catch (SQLException e) { };
throw new SecurityException("Failed to load Schemnodes", e);
if(parent == null) {
return getSchematicDirectory_Null.select(user, name);
}else {
return getSchematicDirectory.select(user, name, parent);
} }
} }
public static SchematicNode getSchematicInParent(String name, Integer parent) { public static SchematicNode getSchematicNode(String name, Integer parent) {
if(parent != null && parent == 0) if(parent != null && parent == 0)
parent = null; parent = null;
ResultSet set; Statement.ResultSetUser<SchematicNode> user = rs -> {
if(parent == null) { while (rs.next()) {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name); return new SchematicNode(rs);
}else {
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
}
try {
while (set.next()) {
SchematicNode node = new SchematicNode(set);
if(!node.isDir())
return node;
} }
return null; return null;
}catch (SQLException e) { };
throw new SecurityException("Failed to load Schemnodes", e); if(parent == null) {
return getSchematicNodeO_Null.select(user, name);
}else {
return getSchematicNodeO.select(user, name, parent);
} }
} }
public static SchematicNode getSchematicNode(int id) { public static SchematicNode getSchematicNode(int id) {
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?", id); return getSchematicNodeId.select(rs -> {
try { if (!rs.next())
if (!set.next())
return null; return null;
return new SchematicNode(set); return new SchematicNode(rs);
} catch (SQLException e) { });
throw new SecurityException("Failed to load Schemnodes", e);
}
} }
public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, Integer parent) { public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, Integer parent) {
List<SchematicNode> schems = getAllSchematicsAccessibleByUser(owner); List<SchematicNode> schems = getAllSchematicsAccessibleByUser(owner);
schems.removeIf(node -> !node.getType().equals(schemType)); schems.removeIf(node -> node.isDir() || !node.getType().equals(schemType));
Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>(); Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>();
for (SchematicNode schematicNode : schems) { for (SchematicNode schematicNode : schems) {
SchematicNode currentNode = schematicNode; SchematicNode currentNode = schematicNode;
@ -188,27 +184,22 @@ public class SchematicNode {
} }
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) { public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType); return getAllSchemsOfTypeOwner.select(rs -> {
try {
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
while (set.next()) while (rs.next())
nodes.add(new SchematicNode(set)); nodes.add(new SchematicNode(rs));
return nodes; return nodes;
} catch (SQLException e) { }, owner, schemType);
throw new SecurityException("Failed to load Schemnodes", e);
}
} }
public static List<SchematicNode> getAllSchematicsOfType(String schemType) { public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?", schemType); return getAllSchemsOfType.select(rs -> {
try {
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
while (set.next()) while (rs.next())
nodes.add(new SchematicNode(set)); nodes.add(new SchematicNode(rs));
return nodes; return nodes;
} catch (SQLException e) { }, schemType);
throw new SecurityException("Failed to load Schemnodes", e);
}
} }
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) { public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
@ -241,30 +232,30 @@ public class SchematicNode {
if(isAdded) if(isAdded)
return getSchematicNodeInNode(parent); return getSchematicNodeInNode(parent);
} else { } else {
ResultSet set = SQL.select("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", user, user); return getAccessibleByUser.select(rs -> {
try{
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
while(set.next()) while(rs.next())
nodes.add(new SchematicNode(set)); nodes.add(new SchematicNode(rs));
return nodes; return nodes;
}catch(SQLException e){ }, user, user);
throw new SecurityException("Failed listing schematics", e);
}
} }
return Collections.emptyList(); return Collections.emptyList();
} }
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) { public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
ResultSet set = SQL.select("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 nm ON nm.NodeId = s.NodeId WHERE s.NodeOwner = ? OR nm.UserId = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user); return getAccessibleByUser.select(rs -> {
try{
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
while(set.next()) while(rs.next()) {
nodes.add(new SchematicNode(set)); SchematicNode node = new SchematicNode(rs);
return nodes; if(node.isDir()) {
}catch(SQLException e){ nodes.addAll(deepGet(node.getId(), node1 -> true));
throw new SecurityException("Failed listing schematics", e); } else {
nodes.add(node);
} }
} }
return nodes;
}, user, user);
}
private final int id; private final int id;
private final int owner; private final int owner;
@ -275,6 +266,7 @@ public class SchematicNode {
private boolean schemFormat; private boolean schemFormat;
private int rank; private int rank;
private final boolean isDir; private final boolean isDir;
private Map<Integer, String> brCache = new HashMap<>();
public static List<SchematicNode> filterSchems(int user, Predicate<SchematicNode> filter) { public static List<SchematicNode> filterSchems(int user, Predicate<SchematicNode> filter) {
List<SchematicNode> finalList = new ArrayList<>(); List<SchematicNode> finalList = new ArrayList<>();
@ -291,14 +283,12 @@ public class SchematicNode {
} }
public static Integer countNodes() { public static Integer countNodes() {
ResultSet set = SQL.select("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode"); return countNodes.select(rs -> {
try { if (rs.next()) {
if (set.next()) return rs.getInt("count");
return set.getInt("count");
return 0;
} catch (SQLException e) {
throw new SecurityException("Failed listing schematics", e);
} }
return 0;
});
} }
public int getId() { public int getId() {
@ -322,7 +312,7 @@ public class SchematicNode {
return parent; return parent;
} }
public void setParent(int parent) { public void setParent(Integer parent) {
this.parent = parent; this.parent = parent;
updateDB(); updateDB();
} }
@ -394,7 +384,7 @@ public class SchematicNode {
} }
public String generateBreadcrumbs(SteamwarUser user) { public String generateBreadcrumbs(SteamwarUser user) {
return generateBreadcrumbs("/", user); return brCache.computeIfAbsent(user.getId(), integer -> generateBreadcrumbs("/", user));
} }
public String generateBreadcrumbs(String split, SteamwarUser user) { public String generateBreadcrumbs(String split, SteamwarUser user) {
@ -413,20 +403,24 @@ public class SchematicNode {
} }
private void updateDB() { private void updateDB() {
SQL.update("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?", updateDB.update(name, owner, parent == 0 ? null : parent, item, type, rank, id);
name, owner, parent == 0 ? null : parent, item, type, rank, id);
this.lastUpdate = Timestamp.from(Instant.now()); this.lastUpdate = Timestamp.from(Instant.now());
this.brCache.clear();
} }
public void delete() { public void delete() {
if (isDir()) { if (isDir()) {
getSchematicNodeInNode(getId()).forEach(SchematicNode::delete); getSchematicNodeInNode(getId()).forEach(SchematicNode::delete);
} }
SQL.update("DELETE FROM SchematicNode WHERE NodeId = ?", id); deleteNode.update(id);
} }
private void updateDatabase(Blob blob, boolean newFormat) { @Override
SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id); public boolean equals(Object obj) {
schemFormat = newFormat; if (!(obj instanceof SchematicNode))
return false;
SchematicNode node = (SchematicNode) obj;
return node.getId() == id;
} }
} }