From a031e1f7fcff4677d83aece9e156677dc39e56ed Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Wed, 29 May 2013 00:40:38 +0200 Subject: [PATCH] Add wizard for creating delivery groups to GroupFrame --- .../sbc/valesriegler/group/GroupAgent.java | 13 +- .../group/gui/DeliveryOverviewModel.java | 5 +- .../group/gui/GroupCreationDetailsPanel.java | 113 +++++++++++++++ ....java => GroupCreationDetailsRequest.java} | 10 +- .../group/gui/GroupCreationHandler.java | 74 ++++++++++ .../group/gui/GroupCreationPanel.java | 133 ++++++------------ .../valesriegler/group/gui/GroupFrame.java | 128 +---------------- .../valesriegler/types/DeliveryGroupData.java | 10 ++ .../sbc/valesriegler/types/GroupData.java | 11 +- .../sbc/valesriegler/xvsm/WaiterXVSM.java | 13 +- 10 files changed, 283 insertions(+), 227 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java rename src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/{GroupCreationRequest.java => GroupCreationDetailsRequest.java} (55%) create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java 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 7cf297d..216f7ac 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 @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import javax.swing.*; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -30,6 +31,12 @@ public class GroupAgent { private DeliveryOverviewModel deliveryOverviewModel; private GroupAgentXVSM xvsm; + /* Contains the identifiers of the pizzerias. Whenever a new Pizzeria emerges or dies the group agent has to be + notified about this somehow and the list has to be adapted as it is the model of the dropdown in the GUI for + selecting for which pizzeria the customer groups are created + In case of XVSM the identifier string is a space URI*/ + private List pizzeriaIdentifiers = Collections.synchronizedList(new ArrayList()); + public static GroupAgent groupAgent; public static void main(String[] args) { @@ -78,6 +85,10 @@ public class GroupAgent { return groupconn; } + public List getPizzeriaIdentifiers() { + return pizzeriaIdentifiers; + } + public GroupOverviewModel getGroupModel() { return groupModel; } @@ -86,7 +97,7 @@ public class GroupAgent { return deliveryOverviewModel; } - public void onGroupsCreated(List newGroups) { + public void onGroupsCreated(List newGroups, boolean isDeliveryGroup) { if (!Util.useJMS) { List groupData = new ArrayList<>(); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java index 8db2932..b60054a 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/DeliveryOverviewModel.java @@ -18,7 +18,8 @@ public class DeliveryOverviewModel extends TableModel { private static final String PIZZAS = "Pizzas"; private static final String ADDRESS = "Address"; private static final String ID = "ID"; - private static final String[] COLUMNS = new String[] { ID, ADDRESS, PIZZAS, STATE }; + private static final String PIZZERIA = "Pizzeria"; + private static final String[] COLUMNS = new String[] { ID, ADDRESS, PIZZAS, STATE, PIZZERIA }; @Override @@ -43,6 +44,8 @@ public class DeliveryOverviewModel extends TableModel { return Util.pizzaDisplay(group.getDeliveryGroupData().getOrder().getOrderedPizzas()); case STATE: return group.getDeliveryGroupData().getDeliveryStatus(); + case PIZZERIA: + return group.getDeliveryGroupData().getPizzeriaId(); default: throw new RuntimeException(UNHANDLEDCOLUMN); } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java new file mode 100644 index 0000000..ad5ca71 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsPanel.java @@ -0,0 +1,113 @@ +package at.ac.tuwien.sbc.valesriegler.group.gui; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.*; + +import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; +import at.ac.tuwien.sbc.valesriegler.types.PizzaType; + +/** + * Panel which allows the selection of pizzas and the number of groups to create + *

+ * Features a Create- and Cancel-Button which call the respective methods of the + * {@link GroupCreationHandler} set by {@link #setCreateAndCancelHandler(GroupCreationHandler)} + * + * @author Gregor Riegler + * + */ +@SuppressWarnings("serial") +public class GroupCreationDetailsPanel extends JPanel { + + private GroupCreationHandler handler; + private int numberMembers; + private JSpinner numberOfGroupsSpinner; + private List combos = new ArrayList(); + private JTextField addressField = new JTextField(); + + public GroupCreationDetailsPanel(int numberMembers, boolean withAddressField) { + this.numberMembers = numberMembers; + + GridLayout layout = new GridLayout(0, 2); + setLayout(layout); + + for(int i=1; i<=numberMembers; i++) { + JLabel memberLabel = new JLabel(i + ". Person"); + JComboBox pizzaDropdown = new JComboBox(); + combos.add(pizzaDropdown); + for(PizzaType type : PizzaType.values()) { + pizzaDropdown.addItem(type); + } + this.add(memberLabel); + this.add(pizzaDropdown); + } + JLabel numberOfGroupsLabel = new JLabel("Number of groups to create: "); + SpinnerNumberModel model = new SpinnerNumberModel(1,1,100,1); + numberOfGroupsSpinner = new JSpinner(model); + + this.add(numberOfGroupsLabel); + this.add(numberOfGroupsSpinner); + + final JLabel pizzeriaLabel = new JLabel("Pizzeria: "); + final JComboBox pizzeriaDropdown = new JComboBox(); + + final List pizzeriaIdentifiers = GroupAgent.getInstance().getPizzeriaIdentifiers(); + for (String pizzeriaIdentifier : pizzeriaIdentifiers) { + pizzeriaDropdown.addItem(pizzeriaIdentifier); + } + + this.add(pizzeriaLabel); + this.add(pizzeriaDropdown); + + if(withAddressField) { + final JLabel addressLabel = new JLabel("Address: "); + this.add(addressLabel); + this.add(addressField); + } + + JButton create = new JButton("Create"); + JButton cancel = new JButton("Cancel"); + + this.add(create); + this.add(cancel); + + addCreateHandler(create); + addCancelHandler(cancel); + } + + + private void addCancelHandler(JButton cancel) { + cancel.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + handler.handleCancel(); + } + }); + } + + private void addCreateHandler(JButton create) { + create.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + List types = new ArrayList<>(); + for(JComboBox combo : combos) { + types.add((PizzaType) combo.getSelectedItem()); + } + GroupCreationDetailsRequest gcr = new GroupCreationDetailsRequest(numberMembers, (int) numberOfGroupsSpinner.getValue(), types, addressField.getText()); + handler.handleGroupCreation(gcr); + } + }); + } + + public void setCreateAndCancelHandler( + GroupCreationHandler groupCreationCallback) { + this.handler = groupCreationCallback; + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationRequest.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsRequest.java similarity index 55% rename from src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationRequest.java rename to src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsRequest.java index ee88ab9..a9b6057 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationRequest.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationDetailsRequest.java @@ -4,15 +4,17 @@ import java.util.List; import at.ac.tuwien.sbc.valesriegler.types.PizzaType; -public class GroupCreationRequest { +public class GroupCreationDetailsRequest { public final int size; public final int numberOfGroups; public final List pizzaTypes; + public final String address; - public GroupCreationRequest(int size, int numberOfGroups, - List pizzaTypes) { + public GroupCreationDetailsRequest(int size, int numberOfGroups, + List pizzaTypes, String address) { this.size = size; this.numberOfGroups = numberOfGroups; this.pizzaTypes = pizzaTypes; - } + this.address = address; + } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java new file mode 100644 index 0000000..fcbfe20 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationHandler.java @@ -0,0 +1,74 @@ +package at.ac.tuwien.sbc.valesriegler.group.gui; + +import at.ac.tuwien.sbc.valesriegler.group.Group; +import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; +import at.ac.tuwien.sbc.valesriegler.types.Order; +import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; +import at.ac.tuwien.sbc.valesriegler.types.PizzaType; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Handles the Wizard-like creation of groups. + *

+ * Give an instance of this class as a callback to the Panel from which a + * group creation request should be issued + */ +class GroupCreationHandler { + private final boolean isDeliveryGroup; + private JPanel creationPanel; + private JPanel chooseGroupSizePanel; + private JPanel groupCreationPanel; + + public GroupCreationHandler(JPanel creationPanel, JPanel chooseGroupSizePanel, JPanel groupCreationPanel, boolean isDeliveryGroup) { + this.isDeliveryGroup = isDeliveryGroup; + this.creationPanel = creationPanel; + this.chooseGroupSizePanel = chooseGroupSizePanel; + this.groupCreationPanel = groupCreationPanel; + } + + public void showGroupCreationDetailPanel() { + chooseGroupSizePanel.setVisible(false); + creationPanel.add(groupCreationPanel); + } + + public void handleGroupCreation(GroupCreationDetailsRequest gc) { + chooseGroupSizePanel.setVisible(true); + creationPanel.remove(groupCreationPanel); + creationPanel.repaint(); + + createGroups(gc); + } + + public void createGroups(GroupCreationDetailsRequest gc) { + List newGroups = new ArrayList<>(); + for (int i = 0; i < gc.numberOfGroups; i++) { + Group group = new Group(); + group.getGroupData().setSize(gc.size); + List pizzaOrders = new ArrayList<>(); + for (PizzaType pt : gc.pizzaTypes) { + pizzaOrders.add(new PizzaOrder(pt)); + } + Order order = new Order(group, pizzaOrders); +// the order id has to be set by the waiter + /*for (PizzaOrder pizzaOrder : order.getOrderedPizzas()) { + pizzaOrder.setOrderId(order.getId()); + }*/ + group.getGroupData().setOrder(order); + order.setNumberOfPizzas(order.getOrderedPizzas().size()); + + newGroups.add(group); + } + GroupOverviewModel groupModel = GroupAgent.getInstance().getGroupModel(); + groupModel.addItems(newGroups); + GroupAgent.getInstance().onGroupsCreated(newGroups, isDeliveryGroup); + } + + public void handleCancel() { + chooseGroupSizePanel.setVisible(true); + creationPanel.remove(groupCreationPanel); + creationPanel.repaint(); + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java index ee36f08..fcf056c 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java @@ -1,100 +1,51 @@ package at.ac.tuwien.sbc.valesriegler.group.gui; -import java.awt.GridLayout; +import javax.swing.*; +import javax.swing.border.TitledBorder; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.List; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.SpinnerNumberModel; -import at.ac.tuwien.sbc.valesriegler.group.gui.GroupFrame.GroupCreationHandler; -import at.ac.tuwien.sbc.valesriegler.types.PizzaType; - -/** - * Panel which allows the selection of pizzas and the number of groups to create - *

- * Features a Create- and Cancel-Button which call the respective methods of the - * {@link GroupCreationHandler} set by {@link #setCreateAndCancelHandler(GroupCreationHandler)} - * - * @author Gregor Riegler - * - */ -@SuppressWarnings("serial") public class GroupCreationPanel extends JPanel { - - private GroupCreationHandler handler; - private int numberMembers; - private JSpinner numberOfGroupsSpinner; - private List combos = new ArrayList(); - - public GroupCreationPanel(int numberMembers) { - this.numberMembers = numberMembers; - - GridLayout layout = new GridLayout(0, 2); - setLayout(layout); - - for(int i=1; i<=numberMembers; i++) { - JLabel memberLabel = new JLabel(i + ". Person"); - JComboBox pizzaDropdown = new JComboBox(); - combos.add(pizzaDropdown); - for(PizzaType type : PizzaType.values()) { - pizzaDropdown.addItem(type); - } - this.add(memberLabel); - this.add(pizzaDropdown); - } - JLabel numberOfGroupsLabel = new JLabel("Number of groups to create: "); - SpinnerNumberModel model = new SpinnerNumberModel(1,1,100,1); - numberOfGroupsSpinner = new JSpinner(model); - - this.add(numberOfGroupsLabel); - this.add(numberOfGroupsSpinner); - - JButton create = new JButton("Create"); - JButton cancel = new JButton("Cancel"); - - this.add(create); - this.add(cancel); - - addCreateHandler(create); - addCancelHandler(cancel); - } - - - private void addCancelHandler(JButton cancel) { - cancel.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - handler.handleCancel(); - } - }); - } - - private void addCreateHandler(JButton create) { - create.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - List types = new ArrayList<>(); - for(JComboBox combo : combos) { - types.add((PizzaType) combo.getSelectedItem()); - } - GroupCreationRequest gcr = new GroupCreationRequest(numberMembers, (int) numberOfGroupsSpinner.getValue(), types); - handler.handleGroupCreation(gcr); - } - }); - } - - public void setCreateAndCancelHandler( - GroupCreationHandler groupCreationCallback) { - this.handler = groupCreationCallback; - } + private boolean withAddress; + + public GroupCreationPanel(final boolean withAddress) { + this.withAddress = withAddress; + + final JPanel chooseGroupSizePanel = new JPanel(); + JLabel creationLabel = new JLabel("How many members should the group have?"); + JButton next = new JButton("Next"); + SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 4, 1); + final JSpinner spinner = new JSpinner(model); + + // When 'next' is clicked the second, final panel of the Group Creation + // Wizard should be shown + next.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int numberMembers = (int) spinner.getValue(); + GroupCreationPanel.this.withAddress = withAddress; + final GroupCreationDetailsPanel groupCreationDetailsPanel = new GroupCreationDetailsPanel(numberMembers, GroupCreationPanel.this.withAddress); + GroupCreationHandler groupCreationHandler = new GroupCreationHandler(GroupCreationPanel.this, chooseGroupSizePanel, + groupCreationDetailsPanel, GroupCreationPanel.this.withAddress); + + groupCreationDetailsPanel.setCreateAndCancelHandler(groupCreationHandler); + groupCreationHandler.showGroupCreationDetailPanel(); + + } + }); + + GridLayout creationPanelLayout = new GridLayout(3, 1); + chooseGroupSizePanel.setLayout(creationPanelLayout); + final String title = withAddress ? "Create Delivery Groups" : "Create Normal Groups"; + this.setBorder(new TitledBorder(title)); + + this.add(chooseGroupSizePanel); + chooseGroupSizePanel.add(creationLabel); + chooseGroupSizePanel.add(spinner); + chooseGroupSizePanel.add(next); + + } } 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 d77de18..34d5b0f 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 @@ -1,36 +1,14 @@ package at.ac.tuwien.sbc.valesriegler.group.gui; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.List; -import javax.swing.JButton; import javax.swing.JFrame; -import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.ScrollPaneConstants; -import javax.swing.SpinnerNumberModel; -import javax.swing.border.TitledBorder; import at.ac.tuwien.sbc.valesriegler.common.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.ac.tuwien.sbc.valesriegler.group.Group; -import at.ac.tuwien.sbc.valesriegler.group.GroupAgent; -import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame; -import at.ac.tuwien.sbc.valesriegler.types.Order; -import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder; -import at.ac.tuwien.sbc.valesriegler.types.PizzaType; - /** * Base Frame of the Group UI * @@ -44,11 +22,14 @@ public class GroupFrame extends JFrame { public GroupFrame(GroupOverviewModel groupModel, DeliveryOverviewModel deliveryModel) { super("Groups"); JPanel wrapper = new JPanel(); - GridLayout wrapperLayout = new GridLayout(3, 1); + GridLayout wrapperLayout = new GridLayout(2, 2); wrapper.setLayout(wrapperLayout); // Create Wizard-like panel for the creation of groups - initGroupCreation(wrapper); + wrapper.add(new GroupCreationPanel(false)); + + // Create Wizard-like panel for the creation of delivery groups + wrapper.add(new GroupCreationPanel(true)); // Create the panel for the group overview table initGroupOverview(wrapper, groupModel); @@ -61,44 +42,7 @@ public class GroupFrame extends JFrame { } - - private void initGroupCreation(JPanel wrapper) { - final JPanel creationPanel = new JPanel(); - final JPanel chooseGroupSizePanel = new JPanel(); - JLabel creationLabel = new JLabel("How many members should the group have?"); - JButton next = new JButton("Next"); - SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 4, 1); - final JSpinner spinner = new JSpinner(model); - - // When 'next' is clicked the second, final panel of the Group Creation - // Wizard should be shown - next.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - int numberMembers = (int) spinner.getValue(); - final GroupCreationPanel groupCreationPanel = new GroupCreationPanel(numberMembers); - GroupCreationHandler groupCreationHandler = new GroupCreationHandler(creationPanel, chooseGroupSizePanel, - groupCreationPanel); - - groupCreationPanel.setCreateAndCancelHandler(groupCreationHandler); - groupCreationHandler.showGroupCreationDetailPanel(); - - } - }); - - GridLayout creationPanelLayout = new GridLayout(3, 1); - chooseGroupSizePanel.setLayout(creationPanelLayout); - creationPanel.setBorder(new TitledBorder("Create Groups")); - - creationPanel.add(chooseGroupSizePanel); - chooseGroupSizePanel.add(creationLabel); - chooseGroupSizePanel.add(spinner); - chooseGroupSizePanel.add(next); - - wrapper.add(creationPanel); - } - - private void initGroupOverview(JPanel wrapper, GroupOverviewModel groupModel) { + private void initGroupOverview(JPanel wrapper, GroupOverviewModel groupModel) { JPanel tablePanel = new JPanel(); Util.createTableInTitledPanel(tablePanel, groupModel, "Group Overview"); wrapper.add(tablePanel); @@ -110,64 +54,4 @@ public class GroupFrame extends JFrame { wrapper.add(tablePanel); } - /** - * Handles the Wizard-like creation of groups. - *

- * Give an instance of this class as a callback to the Panel from which a - * group creation request should be issued - */ - class GroupCreationHandler { - private JPanel creationPanel; - private JPanel chooseGroupSizePanel; - private JPanel groupCreationPanel; - - public GroupCreationHandler(JPanel creationPanel, JPanel chooseGroupSizePanel, JPanel groupCreationPanel) { - this.creationPanel = creationPanel; - this.chooseGroupSizePanel = chooseGroupSizePanel; - this.groupCreationPanel = groupCreationPanel; - } - - public void showGroupCreationDetailPanel() { - chooseGroupSizePanel.setVisible(false); - creationPanel.add(groupCreationPanel); - } - - public void handleGroupCreation(GroupCreationRequest gc) { - chooseGroupSizePanel.setVisible(true); - creationPanel.remove(groupCreationPanel); - creationPanel.repaint(); - - createGroups(gc); - } - - public void createGroups(GroupCreationRequest gc) { - List newGroups = new ArrayList<>(); - for (int i = 0; i < gc.numberOfGroups; i++) { - Group group = new Group(); - group.getGroupData().setSize(gc.size); - List pizzaOrders = new ArrayList<>(); - for (PizzaType pt : gc.pizzaTypes) { - pizzaOrders.add(new PizzaOrder(pt)); - } - Order order = new Order(group, pizzaOrders); - for (PizzaOrder pizzaOrder : order.getOrderedPizzas()) { - pizzaOrder.setOrderId(order.getId()); - } - group.getGroupData().setOrder(order); - order.setNumberOfPizzas(order.getOrderedPizzas().size()); - - newGroups.add(group); - } - GroupOverviewModel groupModel = GroupAgent.getInstance().getGroupModel(); - groupModel.addItems(newGroups); - GroupAgent.getInstance().onGroupsCreated(newGroups); - } - - public void handleCancel() { - chooseGroupSizePanel.setVisible(true); - creationPanel.remove(groupCreationPanel); - creationPanel.repaint(); - } - } - } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java index b5ef986..a6965e2 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/DeliveryGroupData.java @@ -16,6 +16,8 @@ public class DeliveryGroupData implements Serializable, HasId { private Order order; private String address; private DeliveryStatus deliveryStatus; + private Integer pizzeriaId; + public DeliveryGroupData(int id) { this.id = id; @@ -49,6 +51,14 @@ public class DeliveryGroupData implements Serializable, HasId { this.deliveryStatus = deliveryStatus; } + public int getPizzeriaId() { + return Util.getIntSafe(pizzeriaId); + } + + public void setPizzeriaId(Integer pizzeriaId) { + this.pizzeriaId = pizzeriaId; + } + @Override public int getId() { return Util.getIntSafe(id); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java index 29cfc32..ac6f039 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/types/GroupData.java @@ -33,9 +33,10 @@ public class GroupData implements Serializable, HasId { private Integer orderWaiter; private Integer servingWaiter; private Integer payingWaiter; + private Integer pizzeriaId; - public GroupData() { + public GroupData() { } @@ -67,6 +68,14 @@ public class GroupData implements Serializable, HasId { return Util.getIntSafe(servingWaiter); } + public int getPizzeriaId() { + return Util.getIntSafe(pizzeriaId); + } + + public void setPizzeriaId(Integer pizzeriaId) { + this.pizzeriaId = pizzeriaId; + } + public int getSize() { return size; } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java index 2caaab2..760c314 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/WaiterXVSM.java @@ -8,6 +8,7 @@ import java.util.Iterator; import java.util.List; import at.ac.tuwien.sbc.valesriegler.common.OrderId; +import at.ac.tuwien.sbc.valesriegler.types.*; import org.mozartspaces.capi3.AnyCoordinator; import org.mozartspaces.capi3.FifoCoordinator; import org.mozartspaces.capi3.LindaCoordinator; @@ -24,12 +25,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.Util; -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.OrderStatus; -import at.ac.tuwien.sbc.valesriegler.types.Pizza; -import at.ac.tuwien.sbc.valesriegler.types.Table; public class WaiterXVSM extends AbstractXVSMConnector { private static final Logger log = LoggerFactory.getLogger(WaiterXVSM.class); @@ -209,7 +204,11 @@ public class WaiterXVSM extends AbstractXVSMConnector { update the space */ final OrderId orderId = takeMatchingEntity(new OrderId(null), infoContainer, tx, RequestTimeout.INFINITE, "The Order id object could not be taken from the space!"); final int id = orderId.getId(); - order.setId(id+100); + order.setId(id); + final List orderedPizzas = order.getOrderedPizzas(); + for (PizzaOrder orderedPizza : orderedPizzas) { + orderedPizza.setId(id); + } sendItemsToContainer(Arrays.asList(new OrderId(id+1)), infoContainer, RequestTimeout.DEFAULT, tx); // send the order as a whole to the space -- 2.43.0