Permalink
Browse files

added EquipmentDAO

added BatteryBean
added event onchange to equipment list
  • Loading branch information...
1 parent 1842335 commit 37ecc75d32b759f92efdb6636438c4a7a4c56363 @charlestontelles committed Sep 14, 2012
View
42 SolarPowerCalcWeb/src/au/edu/qut/inn372/greenhat/bean/Battery.java
@@ -0,0 +1,42 @@
+package au.edu.qut.inn372.greenhat.bean;
+
+import java.io.Serializable;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+/**
+ * Bean that represents an Equipment
+ *
+ * @author Charleston Telles
+ * @version 1.0
+ */
+@ManagedBean
+@SessionScoped
+public class Battery implements Serializable{
+
+ /**
+ * Unique identifier
+ */
+ private static final long serialVersionUID = -4373394917607346069L;
+ /**
+ * Battery Cost
+ */
+ private double cost;
+ /**
+ * Gets battery cost
+ * @return cost
+ */
+ public double getCost() {
+ return cost;
+ }
+ /**
+ * Sets battery cost
+ * @param cost
+ */
+ public void setCost(double cost) {
+ this.cost = cost;
+ }
+
+
+}
View
85 SolarPowerCalcWeb/src/au/edu/qut/inn372/greenhat/bean/Equipment.java
@@ -7,7 +7,7 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
-import javax.faces.model.SelectItem;
+
/**
* Bean that represents an Equipment
*
@@ -21,16 +21,18 @@
private double cost;
private double size;
- private ArrayList<Panel> panels;
- private List<SelectItem> panelList;
- private int totalPanels;
+ private String kitName = "";
+ private List<Panel> panels = new ArrayList<Panel>();
@ManagedProperty (value = "#{inverter}")
private Inverter inverter;
@ManagedProperty (value = "#{panel}")
private Panel panel;
+ @ManagedProperty (value = "#{battery}")
+ private Battery battery;
+
/**
* Get the inverter
* @return the inverter value of the inverter property
@@ -48,7 +50,21 @@ public void setInverter(Inverter inverter) {
}
-
+ /**
+ * Gets Battery Bean
+ * @return Battery
+ */
+ public Battery getBattery() {
+ return battery;
+ }
+ /**
+ * Sets Battery Bean
+ * @param battery
+ */
+ public void setBattery(Battery battery) {
+ this.battery = battery;
+ }
+
/**
* Get the panel
* @return the panel value of the panel property
@@ -69,60 +85,57 @@ public void setPanel(Panel panel) {
* Get the panels
* @return panels value of the panels property
*/
- public ArrayList<Panel> getPanels() {
+ public List<Panel> getPanels() {
return panels;
}
/**
* Set the panels
* @param panels new value for the panels property
*/
- public void setPanels(ArrayList<Panel> panels) {
+ public void setPanels(List<Panel> panels) {
this.panels = panels;
}
-
/**
- * Get the panel list
- * @return panel list value of the panel list property
+ * Add panel to Panel List
+ * @param panel
*/
- public List<SelectItem> getPanelList() {
- List<SelectItem> list = new ArrayList<SelectItem>();
- list.add(new SelectItem(1, "1"));
- list.add(new SelectItem(2, "2"));
- list.add(new SelectItem(3, "3"));
- list.add(new SelectItem(4, "4"));
- list.add(new SelectItem(5, "5"));
- list.add(new SelectItem(6, "6"));
- list.add(new SelectItem(7, "7"));
- list.add(new SelectItem(8, "8"));
- return list;
+ public void addPanel (Panel panel){
+ this.panels.add(panel);
}
-
/**
- * Set the panel list
- * @param panel list new value for the panel list property
+ * Remove panel from Panel List
+ * @param panel
*/
- public void setPanelList(List<SelectItem> panelList) {
- this.panelList = panelList;
+ public void removePanel (Panel panel){
+ this.panels.remove(panel);
}
-
+ /**
+ * Gets Kit name
+ * @return kit name
+ */
+ public String getKitName() {
+ return kitName;
+ }
+ /**
+ * Sets kit name
+ *
+ * @param kitName
+ */
+ public void setKitName(String kitName) {
+ this.kitName = kitName;
+ }
+
+
/**
* Get the selected panel
* @return selected panel value of the selected panel property
*/
public int getTotalPanels() {
- return totalPanels;
+ return this.panels.size();
}
/**
- * Set the selected panel
- * @param selected panel new value for the selected panel property
- */
- public void setTotalPanels(int totalPanels) {
- this.totalPanels = totalPanels;
- }
-
- /**
* Get the cost
* @return cost value of the cost property
*/
View
52 SolarPowerCalcWeb/src/au/edu/qut/inn372/greenhat/controller/CalculatorController.java
@@ -2,16 +2,23 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
+import javax.faces.event.AjaxBehaviorEvent;
+import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import au.edu.qut.inn372.greenhat.bean.Calculator;
+import au.edu.qut.inn372.greenhat.bean.Equipment;
import au.edu.qut.inn372.greenhat.dao.CalculatorDAO;
+import au.edu.qut.inn372.greenhat.dao.EquipmentDAO;
import au.edu.qut.inn372.greenhat.dao.gae.CalculatorDAOImpl;
+import au.edu.qut.inn372.greenhat.dao.gae.EquipmentDAOImpl;
/**
* Bean that represents a Calcualtor Controller
@@ -34,8 +41,18 @@
private CalculatorDAO calculatorDAO = new CalculatorDAOImpl();
+ private Map<String,String> equipments = new HashMap<String, String>();
+ List<Equipment> listEquipments;
private int tabIndex = 0;
+ public CalculatorController(){
+ EquipmentDAO equipmentDAO = new EquipmentDAOImpl();
+ listEquipments = equipmentDAO.getEquipments();
+ for (Equipment equipment : listEquipments) {
+ this.equipments.put(equipment.getKitName(), equipment.getKitName());
+ }
+ }
+
/**
* Get the calculator
* @return calculator value of the calculator property
@@ -50,14 +67,27 @@ public Calculator getCalculator() {
public void setCalculator(Calculator calculator) {
this.calculator = calculator;
}
-
+ /**
+ * Gets Tab Index
+ * @return
+ */
public int getTabIndex() {
return tabIndex;
}
+ /**
+ * Sets tabIndex
+ * @param tabIndex
+ */
public void setTabIndex(int tabIndex) {
this.tabIndex = tabIndex;
}
/**
+ * Gets Selected Equipment
+ * @return
+ */
+
+
+ /**
* Get the daily solar power generated and return the page to navigate to
* @return
*/
@@ -67,6 +97,14 @@ public void calculate(){
moveToOutput();//to go to the next tab
}
+ public void setEquipments(Map<String, String> equipments) {
+ this.equipments = equipments;
+ }
+
+ public Map<String, String> getEquipments() {
+ return equipments;
+ }
+
/**
* Save the calculation
*/
@@ -88,6 +126,18 @@ public void saveCalculation(){
return list;
}
+
+ /**
+ * Loads selected equipment to calculator
+ */
+ public void handleEquipmentChange(ValueChangeEvent event){
+ for (Equipment equipment : listEquipments) {
+ if (equipment.getKitName().equalsIgnoreCase(event.getNewValue().toString()))
+ this.calculator.setEquipment(equipment);
+ }
+ moveToEquipment();
+ }
+
/**
* Move to the equipment tab
* @return the equipment tab
View
21 SolarPowerCalcWeb/src/au/edu/qut/inn372/greenhat/dao/EquipmentDAO.java
@@ -0,0 +1,21 @@
+package au.edu.qut.inn372.greenhat.dao;
+
+import java.util.List;
+
+import au.edu.qut.inn372.greenhat.bean.Equipment;
+
+/**
+ * Equipment Data Access Object
+ *
+ * @author Charleston
+ *
+ */
+public interface EquipmentDAO {
+ /**
+ * Returns a list of Equipments
+ *
+ * @return Equipment List
+ */
+ public List<Equipment> getEquipments();
+
+}
View
101 SolarPowerCalcWeb/src/au/edu/qut/inn372/greenhat/dao/gae/EquipmentDAOImpl.java
@@ -0,0 +1,101 @@
+package au.edu.qut.inn372.greenhat.dao.gae;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import au.edu.qut.inn372.greenhat.bean.Battery;
+import au.edu.qut.inn372.greenhat.bean.Equipment;
+import au.edu.qut.inn372.greenhat.bean.Inverter;
+import au.edu.qut.inn372.greenhat.bean.Panel;
+import au.edu.qut.inn372.greenhat.dao.EquipmentDAO;
+
+public class EquipmentDAOImpl implements EquipmentDAO {
+
+ @Override
+ public List<Equipment> getEquipments() {
+ List<Equipment> equipments = new ArrayList<Equipment>();
+ Equipment equipment1 = new Equipment();
+ equipment1.setKitName("Kit 2.5Kwh - 10 panels(250w)");
+ equipment1.setCost(2500);
+ equipment1.setSize(2.5);
+ Inverter inverter1 = new Inverter();
+ inverter1.setEfficiency(85);
+ inverter1.setCost(500);
+ Panel panel1 = new Panel();
+ panel1.setEfficiency(95);
+ panel1.setPanelPowerRating(250);
+ Battery battery1 = new Battery();
+ battery1.setCost(500);
+ equipment1.setInverter(inverter1);
+ equipment1.setBattery(battery1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+ equipment1.addPanel(panel1);
+
+ equipments.add(equipment1);
+
+ Equipment equipment2 = new Equipment();
+ equipment2.setKitName("Kit 4Kwh - 8 panels(500w)");
+ equipment2.setCost(5000);
+ equipment2.setSize(4);
+ Inverter inverter2 = new Inverter();
+ inverter2.setEfficiency(90);
+ inverter2.setCost(500);
+ Panel panel2 = new Panel();
+ panel2.setEfficiency(95);
+ panel2.setPanelPowerRating(500);
+ Battery battery2 = new Battery();
+ battery2.setCost(500);
+ equipment2.setInverter(inverter2);
+ equipment2.setBattery(battery2);
+ equipment2.addPanel(panel2);
+ equipment2.addPanel(panel2);
+ equipment2.addPanel(panel2);
+ equipment2.addPanel(panel2);
+ equipment2.addPanel(panel2);
+ equipment2.addPanel(panel2);
+ equipment2.addPanel(panel2);
+ equipment2.addPanel(panel2);
+
+ equipments.add(equipment2);
+
+ Equipment equipment3 = new Equipment();
+ equipment3.setKitName("Kit 3.6Kwh - 12 panels(300w)");
+ equipment3.setCost(4000);
+ equipment3.setSize(3.6);
+ Inverter inverter3 = new Inverter();
+ inverter3.setEfficiency(90);
+ inverter3.setCost(500);
+ Panel panel3 = new Panel();
+ panel3.setEfficiency(95);
+ panel3.setPanelPowerRating(300);
+ Battery battery3 = new Battery();
+ battery3.setCost(500);
+ equipment3.setInverter(inverter3);
+ equipment3.setBattery(battery3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+ equipment3.addPanel(panel3);
+
+ equipments.add(equipment3);
+
+ return equipments;
+ }
+
+}
View
10 SolarPowerCalcWeb/test/au/edu/qut/inn372/greenhat/bean/EquipmentTest.java
@@ -59,17 +59,9 @@ public void testSetGetInverter() {
@Test
public void testGetSetTotalPanels(){
- int newSelectedNoOfPanel = 1;
- equipment.setTotalPanels(newSelectedNoOfPanel);
+ int newSelectedNoOfPanel = 0;
assertEquals(equipment.getTotalPanels(), newSelectedNoOfPanel);
}
- @Test
- public void testASelectionOfNoPanel(){
- int newSelectedNoOfPanel = 1;
- int firstElement = 0;
- equipment.setTotalPanels(newSelectedNoOfPanel);
- assertEquals(equipment.getPanelList().get(firstElement).getValue(), newSelectedNoOfPanel);
- }
}
View
27 SolarPowerCalcWeb/test/au/edu/qut/inn372/greenhat/dao/EquipmentDAOTest.java
@@ -0,0 +1,27 @@
+package au.edu.qut.inn372.greenhat.dao;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import au.edu.qut.inn372.greenhat.bean.Equipment;
+import au.edu.qut.inn372.greenhat.dao.gae.EquipmentDAOImpl;
+
+public class EquipmentDAOTest {
+ EquipmentDAO dao;
+ @Before
+ public void setUp() throws Exception {
+ dao = new EquipmentDAOImpl();
+ }
+
+ @Test
+ public void testGetEquipments() {
+ List<Equipment> equipments = dao.getEquipments();
+
+ assertEquals(equipments.size(), 3);
+
+ }
+}
View
24 SolarPowerCalcWeb/war/equipment.xhtml
@@ -10,22 +10,20 @@
</h:head>
<h:body>
- <f:view>
+
<h:form>
- <h:panelGrid columns="2" styleClass="input">
+ <h:panelGrid columns="2" styleClass="input">
- <h:outputText value="List of Equipment"></h:outputText>
- <h:selectOneMenu value="#{equipment.totalPanels}"><!-- temporary used -->
- <f:selectItem itemValue="" itemLabel="Select an equipment"/>
-
- </h:selectOneMenu>
+ <h:outputText value="List of Equipment"></h:outputText>
+ <h:selectOneMenu value="#{calculatorController.calculator.equipment.kitName}" onchange="submit()"
+ valueChangeListener="#{calculatorController.handleEquipmentChange}">
+ <f:selectItem itemLabel="Select Equipment" itemValue="" />
+ <f:selectItems value="#{calculatorController.equipments}" />
+ </h:selectOneMenu>
<h:outputText value="Number of Panels"></h:outputText>
- <h:selectOneMenu value="#{equipment.totalPanels}">
- <f:selectItem itemValue="" itemLabel="Select a number of panels"/>
- <f:selectItems value="#{equipment.panelList}" />
- </h:selectOneMenu>
+ <h:inputText value="#{calculatorController.calculator.equipment.totalPanels}" readonly="true"></h:inputText>
<h:outputText value="Panel Power rating:"></h:outputText>
<h:inputText value="#{panel.panelPowerRating}"></h:inputText>
@@ -49,10 +47,8 @@
</h:panelGrid>
-
-
</h:form>
- </f:view>
+
</h:body>
</html>

0 comments on commit 37ecc75

Please sign in to comment.