Latest and Greatest Changes
Dieser Commit ist enthalten in:
Ursprung
ea74198a40
Commit
3aa896771e
@ -21,17 +21,17 @@ package de.steamwar.comms.packets;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import de.steamwar.comms.PacketIdManager;
|
import de.steamwar.comms.PacketIdManager;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
|
||||||
public class PrepareSchemPacket extends SpigotPacket{
|
public class PrepareSchemPacket extends SpigotPacket{
|
||||||
|
|
||||||
private final SteamwarUser user;
|
private final SteamwarUser user;
|
||||||
private final Schematic schematic;
|
private final SchematicNode schematic;
|
||||||
private final SchematicType schematicType;
|
private final SchematicType schematicType;
|
||||||
|
|
||||||
public PrepareSchemPacket(SteamwarUser user, Schematic schematic, SchematicType schematicType){
|
public PrepareSchemPacket(SteamwarUser user, SchematicNode schematic, SchematicType schematicType) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.schematic = schematic;
|
this.schematic = schematic;
|
||||||
this.schematicType = schematicType;
|
this.schematicType = schematicType;
|
||||||
@ -45,7 +45,7 @@ public class PrepareSchemPacket extends SpigotPacket{
|
|||||||
@Override
|
@Override
|
||||||
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
||||||
byteArrayDataOutput.writeInt(user.getId());
|
byteArrayDataOutput.writeInt(user.getId());
|
||||||
byteArrayDataOutput.writeInt(schematic.getSchemID());
|
byteArrayDataOutput.writeInt(schematic.getId());
|
||||||
byteArrayDataOutput.writeUTF(schematicType.toDB());
|
byteArrayDataOutput.writeUTF(schematicType.toDB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ import java.io.InputStream;
|
|||||||
import java.sql.Blob;
|
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.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@ -43,59 +45,33 @@ 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)",
|
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);
|
name, owner, parent, type, item);
|
||||||
return getSchematicNode(owner, name, parent);
|
return getSchematicNode(owner, name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
private Timestamp lastUpdate;
|
||||||
if(parent != null && parent == 0)
|
|
||||||
parent = null;
|
|
||||||
ResultSet set;
|
|
||||||
if(parent == null) {
|
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name);
|
|
||||||
}else {
|
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
||||||
return getSchematicNode(owner, name, parent.getId());
|
return getSchematicNode(owner, name, parent.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
private SchematicNode(ResultSet set) throws SQLException {
|
||||||
if(parent != null && parent == 0)
|
id = set.getInt("NodeId");
|
||||||
parent = null;
|
owner = set.getInt("NodeOwner");
|
||||||
ResultSet set;
|
name = set.getString("NodeName");
|
||||||
if(parent == null) {
|
parent = set.getInt("ParentNode");
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE ParentNode is NULL");
|
item = set.getString("NodeItem");
|
||||||
}else {
|
type = set.getString("NodeType");
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE ParentNode = ?", parent);
|
lastUpdate = set.getTimestamp("LastUpdate");
|
||||||
}
|
if (type != null) {
|
||||||
try {
|
isDir = false;
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
rank = set.getInt("NodeRank");
|
||||||
while (set.next())
|
schemFormat = set.getBoolean("NodeFormat");
|
||||||
nodes.add(new SchematicNode(set));
|
} else {
|
||||||
return nodes;
|
isDir = true;
|
||||||
}catch (SQLException e) {
|
|
||||||
throw new SecurityException("Failed to load Schemnodes", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,14 +83,58 @@ public class SchematicNode {
|
|||||||
return getSchematicDirectory(name, parent.getId());
|
return getSchematicDirectory(name, parent.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 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 {
|
||||||
|
while (set.next()) {
|
||||||
|
SchematicNode node = new SchematicNode(set);
|
||||||
|
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 null;
|
||||||
|
}catch (SQLException e) {
|
||||||
|
throw new SecurityException("Failed to load Schemnodes", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
|
if(parent != null && parent == 0)
|
||||||
|
parent = null;
|
||||||
|
ResultSet set;
|
||||||
|
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<>();
|
||||||
|
while (set.next())
|
||||||
|
nodes.add(new SchematicNode(set));
|
||||||
|
return nodes;
|
||||||
|
}catch (SQLException e) {
|
||||||
|
throw new SecurityException("Failed to load Schemnodes", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
ResultSet set;
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
||||||
}else {
|
}else {
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
@ -133,9 +153,9 @@ public class SchematicNode {
|
|||||||
parent = null;
|
parent = null;
|
||||||
ResultSet set;
|
ResultSet set;
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name);
|
||||||
}else {
|
}else {
|
||||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
@ -150,36 +170,12 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int id) {
|
public static SchematicNode getSchematicNode(int id) {
|
||||||
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeId = ?", id);
|
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?", id);
|
||||||
try {
|
try {
|
||||||
if(!set.next())
|
if (!set.next())
|
||||||
return null;
|
return null;
|
||||||
return new SchematicNode(set);
|
return new SchematicNode(set);
|
||||||
}catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SecurityException("Failed to load Schemnodes", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
|
||||||
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType);
|
|
||||||
try {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (set.next())
|
|
||||||
nodes.add(new SchematicNode(set));
|
|
||||||
return nodes;
|
|
||||||
}catch (SQLException e) {
|
|
||||||
throw new SecurityException("Failed to load Schemnodes", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
|
||||||
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank FROM SchematicNode WHERE NodeType = ?", schemType);
|
|
||||||
try {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (set.next())
|
|
||||||
nodes.add(new SchematicNode(set));
|
|
||||||
return nodes;
|
|
||||||
}catch (SQLException e) {
|
|
||||||
throw new SecurityException("Failed to load Schemnodes", e);
|
throw new SecurityException("Failed to load Schemnodes", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,44 +194,27 @@ public class SchematicNode {
|
|||||||
return new ArrayList<>(nodesInParent.values());
|
return new ArrayList<>(nodesInParent.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||||
if(parent != null && parent != 0) {
|
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType);
|
||||||
SchematicNode node = SchematicNode.getSchematicNode(parent);
|
try {
|
||||||
boolean isAdded = false;
|
|
||||||
while (node.getId() != 0) {
|
|
||||||
for (NodeMember member:node.getMembers()) {
|
|
||||||
if (member.getMember() == user) {
|
|
||||||
isAdded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node = SchematicNode.getSchematicNode(node.getParent());
|
|
||||||
}
|
|
||||||
if(isAdded)
|
|
||||||
return getSchematicNodeInNode(parent);
|
|
||||||
} else {
|
|
||||||
ResultSet set = SQL.select("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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);
|
|
||||||
try{
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
while(set.next())
|
while (set.next())
|
||||||
nodes.add(new SchematicNode(set));
|
nodes.add(new SchematicNode(set));
|
||||||
return nodes;
|
return nodes;
|
||||||
}catch(SQLException e){
|
} catch (SQLException e) {
|
||||||
throw new SecurityException("Failed listing schematics", e);
|
throw new SecurityException("Failed to load Schemnodes", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
try {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
|
while (set.next())
|
||||||
|
nodes.add(new SchematicNode(set));
|
||||||
|
return nodes;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new SecurityException("Failed to load Schemnodes", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +232,47 @@ public class SchematicNode {
|
|||||||
return finalList;
|
return finalList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
for (NodeMember member:node.getMembers()) {
|
||||||
|
if (member.getMember() == user) {
|
||||||
|
isAdded = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node = SchematicNode.getSchematicNode(node.getParent());
|
||||||
|
}
|
||||||
|
if(isAdded)
|
||||||
|
return getSchematicNodeInNode(parent);
|
||||||
|
} 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);
|
||||||
|
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 Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
private final int owner;
|
private final int owner;
|
||||||
private String name;
|
private String name;
|
||||||
@ -263,19 +283,28 @@ public class SchematicNode {
|
|||||||
private int rank;
|
private int rank;
|
||||||
private final boolean isDir;
|
private final boolean isDir;
|
||||||
|
|
||||||
private SchematicNode(ResultSet set) throws SQLException {
|
public static List<SchematicNode> filterSchems(int user, Predicate<SchematicNode> filter) {
|
||||||
id = set.getInt("NodeId");
|
List<SchematicNode> finalList = new ArrayList<>();
|
||||||
owner = set.getInt("NodeOwner");
|
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user, null);
|
||||||
name = set.getString("NodeName");
|
nodes.forEach(node -> {
|
||||||
parent = set.getInt("ParentNode");
|
if (node.isDir()) {
|
||||||
item = set.getString("NodeItem");
|
finalList.addAll(deepGet(node.getId(), filter));
|
||||||
type = set.getString("NodeType");
|
} else {
|
||||||
if(type != null) {
|
if (filter.test(node))
|
||||||
isDir = false;
|
finalList.add(node);
|
||||||
rank = set.getInt("NodeRank");
|
}
|
||||||
schemFormat = set.getBoolean("NodeFormat");
|
});
|
||||||
}else {
|
return finalList;
|
||||||
isDir = true;
|
}
|
||||||
|
|
||||||
|
public static Integer countNodes() {
|
||||||
|
ResultSet set = SQL.select("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
||||||
|
try {
|
||||||
|
if (set.next())
|
||||||
|
return set.getInt("count");
|
||||||
|
return 0;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new SecurityException("Failed listing schematics", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,17 +396,25 @@ public class SchematicNode {
|
|||||||
return NodeMember.getNodeMembers(id);
|
return NodeMember.getNodeMembers(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateBreadcrumbs() {
|
public Timestamp getLastUpdate() {
|
||||||
return generateBreadcrumbs("/");
|
return lastUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateBreadcrumbs(String split) {
|
public String generateBreadcrumbs(SteamwarUser user) {
|
||||||
|
return generateBreadcrumbs("/", user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateBreadcrumbs(String split, SteamwarUser user) {
|
||||||
StringBuilder builder = new StringBuilder(getName());
|
StringBuilder builder = new StringBuilder(getName());
|
||||||
SchematicNode currentNode = this;
|
SchematicNode currentNode = this;
|
||||||
while (currentNode.parent != null) {
|
if (currentNode.isDir()) builder.append("/");
|
||||||
|
while (currentNode.getParentNode() != null) {
|
||||||
currentNode = currentNode.getParentNode();
|
currentNode = currentNode.getParentNode();
|
||||||
builder.insert(0, split)
|
builder.insert(0, split)
|
||||||
.insert(0, currentNode.getName());
|
.insert(0, currentNode.getName());
|
||||||
|
if (currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
@ -385,6 +422,7 @@ public class SchematicNode {
|
|||||||
private void updateDB() {
|
private void updateDB() {
|
||||||
SQL.update("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?",
|
SQL.update("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?",
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren