public List<Server> getNodeServers(Node node) { List<Server> servers = new ArrayList<>(); DBCursor serversCursor = getDatabase().findMany("servers", new BasicDBObject("node_id", node.getId().toString())); while (serversCursor.hasNext()) { servers.add(getModel((ObjectId) serversCursor.next().get("_id"))); } return servers; }
@Override public Node getModel(ObjectId id) { DBObject dbNode = getDatabase().findOne("nodes", new BasicDBObject("_id", id)); if (dbNode == null) { return null; } Node node = new Node((ObjectId) dbNode.get("_id"), (Date) dbNode.get("created_at")); node.setUpdated_at((Date) dbNode.get("updated_at")); node.setName((String) dbNode.get("name")); node.setPrivateAddress((String) dbNode.get("privateAddress")); node.setRam(Integer.parseInt((String) dbNode.get("ram"))); if (dbNode.containsField("publicaddresses")) { BasicDBList publicAddressList = (BasicDBList) dbNode.get("publicaddresses"); for (Object objPublicAddress : publicAddressList) { DBObject dbPublicAddress = (DBObject) objPublicAddress; NodePublicAddress nodePublicAddress = new NodePublicAddress( (ObjectId) dbPublicAddress.get("_id"), (Date) dbPublicAddress.get("created_at")); nodePublicAddress.setUpdated_at((Date) dbPublicAddress.get("updated_at")); nodePublicAddress.setPublicAddress((String) dbPublicAddress.get("publicAddress")); nodePublicAddress.setNode(node); node.getPublicAddresses().put(nodePublicAddress.getId(), nodePublicAddress); } } return node; }