From faea290a6f00e86fe76d819dfa06eb42af2679c5 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Sun, 5 May 2013 20:03:23 +0200 Subject: [PATCH] GroupAgent now handles Group creation and run-Group-as-Thread as expected --- .../sbc/valesriegler/{jms => }/cook/Cook.java | 6 +- .../messageListeners/CookRequestedPizza.java | 22 ++++++ .../group/AbstractGroupConnector.java | 18 +++++ .../tuwien/sbc/valesriegler/group/Group.java | 3 +- .../sbc/valesriegler/group/GroupAgent.java | 12 +-- .../group/actions/AbstractAction.java | 2 +- .../group/actions/TableRequest.java | 2 +- .../group/actions/TableResponse.java | 2 +- .../valesriegler/group/gui/GroupFrame.java | 4 +- .../JMSGroupConnector.java} | 24 +++--- .../gui/{Order.java => DEP_Order.java} | 18 ++--- .../{PizzaOrder.java => DEP_PizzaOrder.java} | 5 +- .../pizzeria/gui/PizzeriaFrame.java | 22 +++--- .../gui/tablemodels/OrdersOverviewModel.java | 8 +- .../gui/tablemodels/PizzasOfOrderModel.java | 14 ++-- .../tablemodels/TableModelOfSingleOrder.java | 8 +- .../gui/tablemodels/WaitersOfOrderModel.java | 2 +- .../{group => types}/GroupData.java | 15 ++-- .../tuwien/sbc/valesriegler/types/Order.java | 74 +++++++++++++++++++ .../sbc/valesriegler/types/OrderStatus.java | 7 ++ .../tuwien/sbc/valesriegler/types/Pizza.java | 14 ++-- .../tuwien/sbc/valesriegler/types/Table.java | 8 +- 22 files changed, 212 insertions(+), 78 deletions(-) rename src/main/java/at/ac/tuwien/sbc/valesriegler/{jms => }/cook/Cook.java (95%) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java rename src/main/java/at/ac/tuwien/sbc/valesriegler/group/{GroupConnector.java => jms/JMSGroupConnector.java} (83%) rename src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/{Order.java => DEP_Order.java} (89%) rename src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/{PizzaOrder.java => DEP_PizzaOrder.java} (93%) rename src/main/java/at/ac/tuwien/sbc/valesriegler/{group => types}/GroupData.java (83%) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/cook/Cook.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/Cook.java similarity index 95% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/jms/cook/Cook.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/cook/Cook.java index 9208824..03c4161 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/jms/cook/Cook.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/Cook.java @@ -1,4 +1,4 @@ -package at.ac.tuwien.sbc.valesriegler.jms.cook; +package at.ac.tuwien.sbc.valesriegler.cook; import java.io.Serializable; @@ -30,6 +30,10 @@ public class Cook implements Serializable { produce(PizzaType.CARDINALE); } + public int getId() { + return id; + } + public void produce(PizzaType pizzatype) { try { // Connecting to the Broker and to the output queue diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java new file mode 100644 index 0000000..3767f0c --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/cook/jms/messageListeners/CookRequestedPizza.java @@ -0,0 +1,22 @@ +package at.ac.tuwien.sbc.valesriegler.cook.jms.messageListeners; + +import javax.jms.Message; +import javax.jms.MessageListener; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.ac.tuwien.sbc.valesriegler.cook.Cook; + +public class CookRequestedPizza implements MessageListener { + private static final Logger log = LoggerFactory.getLogger(CookRequestedPizza.class); + private final Cook cook; + + public CookRequestedPizza(Cook cook) { + this.cook = cook; + } + + @Override + public void onMessage(Message m) { + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java new file mode 100644 index 0000000..28c859c --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/AbstractGroupConnector.java @@ -0,0 +1,18 @@ +package at.ac.tuwien.sbc.valesriegler.group; + +import at.ac.tuwien.sbc.valesriegler.group.actions.AbstractAction; + +/** + * Abstract class to handle lower-level communication with other processes. + * + * @author jan + * + */ +public abstract class AbstractGroupConnector { + public void init() { + } + + public void send(AbstractAction request) { + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java index 6b5cd61..20acf58 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java @@ -4,8 +4,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.group.actions.TableRequest; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; import at.ac.tuwien.sbc.valesriegler.types.GroupState; +import at.ac.tuwien.sbc.valesriegler.types.Order; import at.ac.tuwien.sbc.valesriegler.types.Table; // class doing all the Group related work as required. diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java index 3c731bf..e15dd1d 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java @@ -3,6 +3,7 @@ package at.ac.tuwien.sbc.valesriegler.group; import javax.swing.SwingUtilities; import at.ac.tuwien.sbc.valesriegler.group.gui.GroupOverviewModel; +import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector; /** * The Main class of the Group component. @@ -10,30 +11,31 @@ import at.ac.tuwien.sbc.valesriegler.group.gui.GroupOverviewModel; * Start the communication and the group GUI: * * @author Gregor Riegler + * @author jan * */ public class GroupAgent { public static GroupAgent groupAgent; private GroupOverviewModel groupModel; - private GroupConnector groupconn; + private AbstractGroupConnector groupconn; public static void main(String[] args) { // TODO: use jms and xvsm manager here. - groupAgent = new GroupAgent(new GroupConnector()); + groupAgent = new GroupAgent(new JMSGroupConnector()); SwingUtilities.invokeLater(new GroupGUI()); } - public GroupAgent(GroupConnector groupconn) { + public GroupAgent(JMSGroupConnector groupconn) { groupModel = new GroupOverviewModel(); this.groupconn = groupconn; - groupconn.init();// TODO: move somewhere else! + groupconn.init(); } public static GroupAgent getInstance() { return groupAgent; } - public GroupConnector getGroupcomm() { + public AbstractGroupConnector getGroupcomm() { return groupconn; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/AbstractAction.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/AbstractAction.java index 9940805..65744f8 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/AbstractAction.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/AbstractAction.java @@ -2,7 +2,7 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; -import at.ac.tuwien.sbc.valesriegler.group.GroupData; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; public abstract class AbstractAction implements Serializable { private final GroupData groupdata; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java index f4a8076..10ac6a7 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableRequest.java @@ -2,7 +2,7 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; -import at.ac.tuwien.sbc.valesriegler.group.GroupData; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; public class TableRequest extends AbstractAction implements Serializable { public TableRequest(GroupData groupdata) { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java index 71c69c9..e7a73a0 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/actions/TableResponse.java @@ -2,7 +2,7 @@ package at.ac.tuwien.sbc.valesriegler.group.actions; import java.io.Serializable; -import at.ac.tuwien.sbc.valesriegler.group.GroupData; +import at.ac.tuwien.sbc.valesriegler.types.GroupData; import at.ac.tuwien.sbc.valesriegler.types.Table; public class TableResponse extends AbstractAction implements Serializable { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java index 5239b4a..8546657 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java @@ -22,6 +22,7 @@ import javax.swing.border.TitledBorder; import at.ac.tuwien.sbc.valesriegler.group.Group; import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; +import at.ac.tuwien.sbc.valesriegler.types.Order; /** * Base Frame of the Group UI @@ -137,7 +138,8 @@ public class GroupFrame extends JFrame { for (int i = 0; i < gc.numberOfGroups; i++) { Group group = new Group(); group.getGroupData().setSize(gc.size); - group.getGroupData().setPizzas(gc.pizzaTypes); + Order order = new Order(group, gc.pizzaTypes); + group.getGroupData().setOrder(order); newGroups.add(group); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupConnector.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/JMSGroupConnector.java similarity index 83% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupConnector.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/JMSGroupConnector.java index 6f30697..812461a 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupConnector.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/jms/JMSGroupConnector.java @@ -1,4 +1,4 @@ -package at.ac.tuwien.sbc.valesriegler.group; +package at.ac.tuwien.sbc.valesriegler.group.jms; import javax.jms.Connection; import javax.jms.DeliveryMode; @@ -14,16 +14,20 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.ac.tuwien.sbc.valesriegler.group.AbstractGroupConnector; +import at.ac.tuwien.sbc.valesriegler.group.Group; +import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; import at.ac.tuwien.sbc.valesriegler.group.actions.AbstractAction; import at.ac.tuwien.sbc.valesriegler.group.actions.TableResponse; -// This handles lower-level communication between processes. -// put messages into queues, put data into space. -// not sure if it should be refactored to be an interface with xvsm + jms classes implementing this. - -//TODO -public class GroupConnector implements MessageListener { - private static final Logger log = LoggerFactory.getLogger(GroupConnector.class); +/** + * This class handles the communication with other processes using JMS. + * + * @author jan + * + */ +public class JMSGroupConnector extends AbstractGroupConnector implements MessageListener { + private static final Logger log = LoggerFactory.getLogger(JMSGroupConnector.class); private Connection connection; @@ -39,10 +43,6 @@ public class GroupConnector implements MessageListener { } } - public Group findGroup(GroupData gd) { - return null; - } - @Override public void onMessage(Message msg) { try { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Order.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Order.java similarity index 89% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Order.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Order.java index 91beea2..b90fa00 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Order.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_Order.java @@ -2,19 +2,23 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; import java.util.List; -//TODO: cahnge me! -public class Order { +@Deprecated +public class DEP_Order { private int id; private int tableId; private int groupId; private OrderStatus status; + enum OrderStatus { + ORDERED, PAID, DELIVERED + } + private int waiterIdOfTableAssignment; private int waiterIdOfOrder; private int waiterIdOfServing; private int waiterIdOfPayment; - private List pizzaOrders; + private List pizzaOrders; public int getId() { return id; @@ -80,16 +84,12 @@ public class Order { this.waiterIdOfPayment = waiterIdOfPayment; } - public List getPizzaOrders() { + public List getPizzaOrders() { return pizzaOrders; } - public void setPizzaOrders(List pizzaOrders) { + public void setPizzaOrders(List pizzaOrders) { this.pizzaOrders = pizzaOrders; } - enum OrderStatus { - ORDERED, PAID, DELIVERED - } - } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzaOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_PizzaOrder.java similarity index 93% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzaOrder.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_PizzaOrder.java index ce6b90b..9fead0b 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzaOrder.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/DEP_PizzaOrder.java @@ -2,11 +2,12 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; import at.ac.tuwien.sbc.valesriegler.types.PizzaType; -public class PizzaOrder { +@Deprecated +public class DEP_PizzaOrder { private PizzaType pizzaType; private int cookId; private PizzaOrderStatus status; - + public PizzaType getPizzaType() { return pizzaType; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java index 7a99e0e..79ea518 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java @@ -23,7 +23,7 @@ import javax.swing.event.TableModelListener; import at.ac.tuwien.sbc.valesriegler.common.TableModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent; import at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent.TablesCreatedHandler; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzaOrder.PizzaOrderStatus; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_PizzaOrder.PizzaOrderStatus; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.GroupsOverviewModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.OrdersOverviewModel; import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.PizzasOfOrderModel; @@ -110,7 +110,7 @@ public class PizzeriaFrame extends JFrame { } private void initModels() { - List orders = getOrdersTestData(); + List orders = getOrdersTestData(); ordersModel.setItems(orders); // When the tables get created in the first place, the handler is informed @@ -142,7 +142,7 @@ public class PizzeriaFrame extends JFrame { .getSource(); int minIndex = lsm.getMinSelectionIndex(); - Order currentOrder = ordersModel + DEP_Order currentOrder = ordersModel .getOrderOfRow(minIndex); waitersPanel.setBorder(new TitledBorder(String.format( WAITER_IDS_CAPTION, currentOrder.getId()))); @@ -220,12 +220,12 @@ public class PizzeriaFrame extends JFrame { /** * not necessary in production */ - private List getOrdersTestData() { - List orders = new ArrayList<>(); - Order order1 = new Order(); - Order order2 = new Order(); - Order order3 = new Order(); - Order order4 = new Order(); + private List getOrdersTestData() { + List orders = new ArrayList<>(); + DEP_Order order1 = new DEP_Order(); + DEP_Order order2 = new DEP_Order(); + DEP_Order order3 = new DEP_Order(); + DEP_Order order4 = new DEP_Order(); order1.setId(1); order2.setId(2); @@ -235,8 +235,8 @@ public class PizzeriaFrame extends JFrame { order1.setWaiterIdOfOrder(4); order2.setWaiterIdOfServing(2); - List pizzas = new ArrayList<>(); - PizzaOrder pizzaOrder1 = new PizzaOrder(); + List pizzas = new ArrayList<>(); + DEP_PizzaOrder pizzaOrder1 = new DEP_PizzaOrder(); pizzaOrder1.setPizzaType(PizzaType.CARDINALE); pizzaOrder1.setStatus(PizzaOrderStatus.DONE); pizzaOrder1.setCookId(3); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java index 5d4f47c..fafde45 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java @@ -4,9 +4,9 @@ import java.util.ArrayList; import java.util.List; import at.ac.tuwien.sbc.valesriegler.common.TableModel; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Order; -public class OrdersOverviewModel extends TableModel { +public class OrdersOverviewModel extends TableModel { private static final String ID = "Order ID"; private static final String TABLE_ID = "Table ID"; private static final String GROUP_ID = "Group ID"; @@ -18,7 +18,7 @@ public class OrdersOverviewModel extends TableModel { @Override public Object getValueAt(int rowIndex, int columnIndex) { - Order order = items.get(rowIndex); + DEP_Order order = items.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; switch(wantedColumn) { case ID : return order.getId(); @@ -29,7 +29,7 @@ public class OrdersOverviewModel extends TableModel { } } - public Order getOrderOfRow(int rowIndex) { + public DEP_Order getOrderOfRow(int rowIndex) { return items.get(rowIndex); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java index 10405eb..9e738b7 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java @@ -3,10 +3,10 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; import java.util.List; import at.ac.tuwien.sbc.valesriegler.common.TableModel; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzaOrder; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Order; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_PizzaOrder; -public class PizzasOfOrderModel extends TableModel { +public class PizzasOfOrderModel extends TableModel { private static final String TYPE = "Type"; private static final String STATUS = "Status"; private static final String COOK = "Cook"; @@ -15,9 +15,9 @@ public class PizzasOfOrderModel extends TableModel { TYPE, STATUS, COOK }; - private Order currentOrder; + private DEP_Order currentOrder; - public void setCurrentOrder(Order currentOrder) { + public void setCurrentOrder(DEP_Order currentOrder) { this.currentOrder = currentOrder; fireTableDataChanged(); @@ -27,10 +27,10 @@ public class PizzasOfOrderModel extends TableModel { public Object getValueAt(int rowIndex, int columnIndex) { if(rowIndex > 0) return null; - List pizzaOrders = currentOrder.getPizzaOrders(); + List pizzaOrders = currentOrder.getPizzaOrders(); if(pizzaOrders == null) return null; - PizzaOrder pizzaOrder = pizzaOrders.get(rowIndex); + DEP_PizzaOrder pizzaOrder = pizzaOrders.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; switch(wantedColumn) { case TYPE : return pizzaOrder.getPizzaType(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java index 2fa3549..471b296 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java @@ -1,12 +1,12 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; import at.ac.tuwien.sbc.valesriegler.common.TableModel; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Order; -public abstract class TableModelOfSingleOrder extends TableModel { - protected Order currentOrder; +public abstract class TableModelOfSingleOrder extends TableModel { + protected DEP_Order currentOrder; - public void setCurrentOrder(Order currentOrder) { + public void setCurrentOrder(DEP_Order currentOrder) { this.currentOrder = currentOrder; fireTableDataChanged(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java index 3b80a98..7badbe2 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java @@ -1,6 +1,6 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.DEP_Order; public class WaitersOfOrderModel extends TableModelOfSingleOrder { private static final String TABLE_ASSIGNMENT = "Table Assignment"; diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupData.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java similarity index 83% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupData.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java index 8ba2a81..04891bc 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupData.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java @@ -1,4 +1,4 @@ -package at.ac.tuwien.sbc.valesriegler.group; +package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; import java.util.ArrayList; @@ -7,11 +7,6 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; -import at.ac.tuwien.sbc.valesriegler.types.GroupState; -import at.ac.tuwien.sbc.valesriegler.types.PizzaType; -import at.ac.tuwien.sbc.valesriegler.types.Table; - /** * This class represents all of a group's data, that can be relevant to send * across the net. @@ -76,6 +71,7 @@ public class GroupData implements Serializable { } public void setOrder(Order order) { + order.setGroupId(id); this.order = order; } @@ -106,4 +102,11 @@ public class GroupData implements Serializable { public void setTableWaiter(int tableWaiter) { this.tableWaiter = tableWaiter; } + + @Override + public String toString() { + return "GroupData [id=" + id + ", state=" + state + ", size=" + size + ", table=" + table + ", tableWaiter=" + + tableWaiter + ", order=" + order + ", orderWaiter=" + orderWaiter + ", pizzaWaiter=" + pizzaWaiter + + ", pizzas=" + pizzas + "]"; + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java new file mode 100644 index 0000000..84f9f9d --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Order.java @@ -0,0 +1,74 @@ +package at.ac.tuwien.sbc.valesriegler.types; + +import java.io.Serializable; +import java.util.List; + +import at.ac.tuwien.sbc.valesriegler.group.Group; + +public class Order implements Serializable { + private static int idNext = 0; + private final int id; + private int groupId; + private OrderStatus status; + + private List orderedPizzas; + private List cookedPizzas; + + public Order(int groupId, List orderedPizzas) { + id = ++idNext; + this.groupId = groupId; + status = OrderStatus.NEW; + this.orderedPizzas = orderedPizzas; + cookedPizzas = null; + } + + public Order(Group group, List orderedPizzas) { + id = ++idNext; + groupId = group.getGroupData().getId(); + status = OrderStatus.NEW; + this.orderedPizzas = orderedPizzas; + cookedPizzas = null; + } + + public List getCookedPizzas() { + return cookedPizzas; + } + + public int getGroupId() { + return groupId; + } + + public int getId() { + return id; + } + + public List getOrderedPizzas() { + return orderedPizzas; + } + + public OrderStatus getStatus() { + return status; + } + + public void setCookedPizzas(List cookedPizzas) { + this.cookedPizzas = cookedPizzas; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + public void setOrderedPizzas(List orderedPizzas) { + this.orderedPizzas = orderedPizzas; + } + + public void setStatus(OrderStatus status) { + this.status = status; + } + + @Override + public String toString() { + return "Order [id=" + id + ", groupId=" + groupId + ", status=" + status + ", orderedPizzas=" + orderedPizzas + + ", cookedPizzas=" + cookedPizzas + "]"; + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java new file mode 100644 index 0000000..2a6256e --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/OrderStatus.java @@ -0,0 +1,7 @@ +package at.ac.tuwien.sbc.valesriegler.types; + +import java.io.Serializable; + +public enum OrderStatus implements Serializable { + NEW, ORDERED, DELIVERED, PAID +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java index 9990c39..1bfeabd 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Pizza.java @@ -2,29 +2,29 @@ package at.ac.tuwien.sbc.valesriegler.types; import java.io.Serializable; -import at.ac.tuwien.sbc.valesriegler.jms.cook.Cook; +import at.ac.tuwien.sbc.valesriegler.cook.Cook; import at.ac.tuwien.sbc.valesriegler.waiter.Waiter; public class Pizza implements Serializable { - final private PizzaType typ; + final private PizzaType type; // debugzeugs private static int nextID = 0; final private int id; - final public Cook producer; + final public int cookId; public Waiter deliveryAgent; // private Person consumer; - public Pizza(PizzaType typ, Cook producer) { + public Pizza(PizzaType type, Cook producer) { id = ++nextID; - this.typ = typ; - this.producer = producer; + this.type = type; + cookId = producer.getId(); } @Override public String toString() { - return "Pizza [typ=" + typ + ", id=" + id + ", producer=" + producer + "]"; + return "Pizza [type=" + type + ", id=" + id + ", cookId=" + cookId + ", deliveryAgent=" + deliveryAgent + "]"; } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java index 62b03c2..0b48bcc 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/Table.java @@ -9,13 +9,13 @@ public class Table implements Serializable { this.id = id; } + public int getId() { + return id; + } + @Override public String toString() { return "Table [id=" + id + "]"; } - public int getId() { - return id; - } - } -- 2.43.0