From c0ea43d219f33209bfa7df5d386ae1615a79fca4 Mon Sep 17 00:00:00 2001 From: manishgant Date: Sat, 31 Jan 2015 14:25:13 +0530 Subject: [PATCH 01/11] Cleaned up Attributes Page for Conditional Mandatory. Also Added extra field in DB for Conditional Mandatory --- WebContent/attributes.xhtml | 14 +- WebContent/scenarios.xhtml | 189 ++++++++++++--------- src/art/dashboard/ObjectOperations.java | 14 +- src/art/database/DatabaseOperations.java | 1 + src/art/datastructures/BOAttribute.java | 28 ++- src/art/datastructures/BusinessObject.java | 4 +- 6 files changed, 152 insertions(+), 98 deletions(-) diff --git a/WebContent/attributes.xhtml b/WebContent/attributes.xhtml index ccf9b59..620a324 100644 --- a/WebContent/attributes.xhtml +++ b/WebContent/attributes.xhtml @@ -101,7 +101,7 @@ - + @@ -116,9 +116,10 @@ + update = "attributeForm:attributesTable attributeForm:msgs" action="#{objectOperations.addAttribute}"> + addTo="#{objectOperations.selectedBO.attributes}" unique="true" + /> @@ -145,6 +146,13 @@ + + + + + + + diff --git a/WebContent/scenarios.xhtml b/WebContent/scenarios.xhtml index be90441..024d6f1 100644 --- a/WebContent/scenarios.xhtml +++ b/WebContent/scenarios.xhtml @@ -10,7 +10,7 @@ - + - @@ -81,8 +73,13 @@
+ + + + + + style="margin-top:10px"> @@ -94,8 +91,18 @@
+ + + + + +
+ + +
@@ -123,7 +130,7 @@ activeStyleClass="ui-state-highlight" datasource="availableObjects" onDrop="handleDrop"> + update="dropAreaForPreReq availableObjects msgs" />
@@ -149,7 +156,7 @@ activeStyleClass="ui-state-highlight" datasource="availableObjects" onDrop="handleDrop"> + update="dropAreaForInput availableObjects msgs" /> @@ -175,7 +182,7 @@ activeStyleClass="ui-state-highlight" datasource="availableObjects" onDrop="handleDrop"> + update="dropAreaForOutput availableObjects msgs" /> @@ -189,6 +196,13 @@ +
\ No newline at end of file diff --git a/dbScripts/dbScripts.txt b/dbScripts/dbScripts.txt new file mode 100644 index 0000000..93dd663 --- /dev/null +++ b/dbScripts/dbScripts.txt @@ -0,0 +1,20 @@ +CREATE TABLE `scenario_bo_mapping` ( + `scenario_bo_mapping_id` int(11) NOT NULL AUTO_INCREMENT, + `scenario_id` int(11) NOT NULL, + `objectID` bigint(20) NOT NULL, + `objectType` varchar(45) NOT NULL, + PRIMARY KEY (`scenario_bo_mapping_id`), + KEY `fk_scenario_bo_mapping_1_idx` (`scenario_id`), + KEY `fk_scenario_bo_mapping_2_idx` (`objectID`), + CONSTRAINT `fk_scenario_bo_mapping_1` FOREIGN KEY (`scenario_id`) REFERENCES `scenarios` (`scenarios_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_scenario_bo_mapping_2` FOREIGN KEY (`objectID`) REFERENCES `business_objects` (`objectID`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1 + +---------------------------------------------------------- + +CREATE TABLE `scenarios` ( + `scenarios_id` int(11) NOT NULL AUTO_INCREMENT, + `scenario_name` varchar(45) NOT NULL, + PRIMARY KEY (`scenarios_id`), + UNIQUE KEY `scenario_name_UNIQUE` (`scenario_name`) +) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=latin1 \ No newline at end of file diff --git a/src/art/dashboard/ScenarioListOperations.java b/src/art/dashboard/ScenarioListOperations.java new file mode 100644 index 0000000..268afcd --- /dev/null +++ b/src/art/dashboard/ScenarioListOperations.java @@ -0,0 +1,123 @@ +package art.dashboard; + +/****************************************************************************************************************** + * Copy rights @ Team ART + * + * Description: + * This Class embeds all operations on objects and their attributes + * + * Internal Methods : + * + * + * Reviewed by : + * + * Review Comments : + * + ******************************************************************************************************************/ +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.ManagedBean; +import javax.faces.application.FacesMessage; +import javax.faces.bean.SessionScoped; +import javax.faces.component.UIData; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.servlet.http.HttpServletRequest; + +import org.primefaces.event.DragDropEvent; +import org.primefaces.event.RowEditEvent; + +import java.sql.ResultSet; + +import art.database.DatabaseOperations; +import art.datastructures.BOAttribute; +import art.datastructures.BusinessObject; +import art.datastructures.Scenario; + +import com.google.visualization.*; +import com.google.visualization.datasource.datatable.DataTable; + +@ManagedBean(value = "scenarioListOperations") +@SessionScoped +public class ScenarioListOperations implements Serializable { + /** + * Added serialversion ID + */ + private static final long serialVersionUID = 1L; + private ArrayList preReqObjects = new ArrayList(); + private ArrayList inputObject = new ArrayList(); + private ArrayList outputObject = new ArrayList(); + private BusinessObject selectedPreReqObject = new BusinessObject(); + private BusinessObject selectedInputObject = new BusinessObject(); + private BusinessObject selectedOutputObject = new BusinessObject(); + private ArrayList scenarioList = new ArrayList(); + private String scenarioName; + + public ScenarioListOperations() { + + // read scenario list from DataBase + scenarioList = new DatabaseOperations().getScenarioList(); + + } + + public ArrayList getPreReqObjects() { + return preReqObjects; + } + + public ArrayList getInputObjects() { + return inputObject; + } + + public ArrayList getOutputObjects() { + return outputObject; + } + + public BusinessObject getSelectedPreReqObject() { + return selectedPreReqObject; + } + + public BusinessObject getSelectedInputObject() { + return selectedInputObject; + } + + public BusinessObject getSelectedOutputObject() { + return selectedOutputObject; + } + + + public void setPreReqObjects(ArrayList objects) { + this.preReqObjects = objects; + } + + + public void setSelectedObject(BusinessObject object) { + this.selectedPreReqObject = object; + } + + + public String getScenarioName() { + return scenarioName; + } + + public void setScenarioName(String text) { + this.scenarioName = text; + } + + public ArrayList getScenarioList(){ + return scenarioList; + } + + public void setScenarioList(ArrayList scenarioList) { + this.scenarioList = scenarioList; + } + + public void onRemoveScenarios(Scenario e) { + + } + +} \ No newline at end of file diff --git a/src/art/dashboard/ScenarioOperations.java b/src/art/dashboard/ScenarioOperations.java index c73a5f5..26db2a2 100644 --- a/src/art/dashboard/ScenarioOperations.java +++ b/src/art/dashboard/ScenarioOperations.java @@ -1,4 +1,5 @@ package art.dashboard; + /****************************************************************************************************************** * Copy rights @ Team ART * @@ -31,10 +32,15 @@ import org.primefaces.event.DragDropEvent; import org.primefaces.event.RowEditEvent; +import java.sql.ResultSet; + import art.database.DatabaseOperations; import art.datastructures.BOAttribute; import art.datastructures.BusinessObject; +import com.google.visualization.*; +import com.google.visualization.datasource.datatable.DataTable; + @ManagedBean(value = "scenarioOperations") @SessionScoped public class ScenarioOperations implements Serializable { @@ -44,30 +50,30 @@ public class ScenarioOperations implements Serializable { private static final long serialVersionUID = 1L; private ArrayList businessObjects = new ArrayList(); private ArrayList businessObjectsCopy = new ArrayList(); - private ArrayList preReqObjects = new ArrayList () ; - private ArrayList inputObject = new ArrayList (); - private ArrayList outputObject = new ArrayList (); + private ArrayList preReqObjects = new ArrayList(); + private ArrayList inputObject = new ArrayList(); + private ArrayList outputObject = new ArrayList(); private BusinessObject selectedPreReqObject = new BusinessObject(); private BusinessObject selectedInputObject = new BusinessObject(); private BusinessObject selectedOutputObject = new BusinessObject(); - + private String scenarioName; + public ScenarioOperations() { - + // read the business objects from DB businessObjects = new DatabaseOperations().readBusinessObjects(); businessObjectsCopy.addAll(businessObjects); - /*businessObjects.add(new BusinessObject(50,"Core Business Object","test1",null)); - businessObjects.add(new BusinessObject(50,"Core Business Object","test2",null));*/ + scenarioName = "Enter Scenario Name"; } - + public ArrayList getBusinessObjects() { return businessObjects; } - + public ArrayList getPreReqObjects() { return preReqObjects; } - + public ArrayList getInputObjects() { return inputObject; } @@ -75,58 +81,64 @@ public ArrayList getInputObjects() { public ArrayList getOutputObjects() { return outputObject; } - + public BusinessObject getSelectedPreReqObject() { return selectedPreReqObject; } - + public BusinessObject getSelectedInputObject() { return selectedInputObject; } - + public BusinessObject getSelectedOutputObject() { return selectedOutputObject; } - + public void setBusinessObjects(ArrayList objects) { this.businessObjects = objects; } - + public void setPreReqObjects(ArrayList objects) { this.preReqObjects = objects; } - - public void onDragDropPreReq(DragDropEvent event) { - BusinessObject object = (BusinessObject) event.getData(); - - preReqObjects.add(object); - businessObjects.remove(object); - - FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(object.getObjectName() + " added", "Position:" + event.getDropId())); - } - - public void onDragDropInput(DragDropEvent event) { - BusinessObject object = (BusinessObject) event.getData(); - - inputObject.add(object); - businessObjects.remove(object); - - FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(object.getObjectName() + " added", "Position:" + event.getDropId())); - } - - public void onDragDropOutput(DragDropEvent event) { - BusinessObject object = (BusinessObject) event.getData(); - - outputObject.add(object); - businessObjects.remove(object); - FacesMessage msg = new FacesMessage(object.getObjectName() + " added"); - FacesContext.getCurrentInstance().addMessage(null, msg); - } - + + public void onDragDropPreReq(DragDropEvent event) { + BusinessObject object = (BusinessObject) event.getData(); + + preReqObjects.add(object); + businessObjects.remove(object); + + FacesContext.getCurrentInstance().addMessage( + null, + new FacesMessage(object.getObjectName() + " added", "Position:" + + event.getDropId())); + } + + public void onDragDropInput(DragDropEvent event) { + BusinessObject object = (BusinessObject) event.getData(); + + inputObject.add(object); + businessObjects.remove(object); + + FacesContext.getCurrentInstance().addMessage( + null, + new FacesMessage(object.getObjectName() + " added", "Position:" + + event.getDropId())); + } + + public void onDragDropOutput(DragDropEvent event) { + BusinessObject object = (BusinessObject) event.getData(); + + outputObject.add(object); + businessObjects.remove(object); + FacesMessage msg = new FacesMessage(object.getObjectName() + " added"); + FacesContext.getCurrentInstance().addMessage(null, msg); + } + public void setSelectedObject(BusinessObject object) { - this.selectedPreReqObject = object; - } - + this.selectedPreReqObject = object; + } + public void reset() { businessObjects.clear(); businessObjects.addAll(businessObjectsCopy); @@ -134,4 +146,123 @@ public void reset() { inputObject.clear(); preReqObjects.clear(); } -} + + public String getScenarioName() { + return scenarioName; + } + + public void setScenarioName(String text) { + this.scenarioName = text; + } + + public void saveScenario() { + // Check if Scenario Name already exists + ArrayList rScenarioName = new ArrayList(); + String query = "select * from scenarios where scenario_name =" + +"'" + scenarioName +"'"; + DatabaseOperations dbOp = new DatabaseOperations(); + rScenarioName = dbOp.executegetColumnQuery(query, 1); + if (!rScenarioName.isEmpty()) { + FacesMessage msg = new FacesMessage("Scenario name " + scenarioName + + " already exists.Please choose a different name"); + FacesContext.getCurrentInstance().addMessage(null, msg); + } else { + ArrayList rScenarioID = new ArrayList(); + int flag = 0; + + // Insert scenarioName inside scenario Table + try { + query = "insert into scenarios(scenario_name) values(" + "'" + + scenarioName + "'" + " )"; + System.out.println(query); + DatabaseOperations dbop = new DatabaseOperations(); + flag = dbop.updateDB(query); + + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + try { + + // Select the scenario id for mapping purpose + query = "select scenarios_id from scenarios " + + "WHERE scenario_name='" + scenarioName + "'"; + + rScenarioID = new DatabaseOperations().executegetColumnQuery( + query, 1); + + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + try { + + //Insert prereq values into the database + for (BusinessObject bObject : preReqObjects) { + query = "insert into scenario_bo_mapping (scenario_id,objectID,objectType) values(" + + "'" + + rScenarioID.get(0) + + "'" + + "," + + "'" + + bObject.getObjectID() + + "'" + + "," + + "'" + + "Pre-Requisite" + "'" + " )"; + System.out.println(query); + DatabaseOperations dbop = new DatabaseOperations(); + flag = dbop.updateDB(query); + + } + + //Insert input values into the database + for (BusinessObject bObject : inputObject) { + query = "insert into scenario_bo_mapping (scenario_id,objectID,objectType) values(" + + "'" + + rScenarioID.get(0) + + "'" + + "," + + "'" + + bObject.getObjectID() + + "'" + + "," + + "'" + + "Input" + "'" + " )"; + System.out.println(query); + DatabaseOperations dbop = new DatabaseOperations(); + flag = dbop.updateDB(query); + + } + + //Insert output values into the database + for (BusinessObject bObject : outputObject) { + query = "insert into scenario_bo_mapping (scenario_id,objectID,objectType) values(" + + "'" + + rScenarioID.get(0) + + "'" + + "," + + "'" + + bObject.getObjectID() + + "'" + + "," + + "'" + + "Output" + "'" + " )"; + System.out.println(query); + DatabaseOperations dbop = new DatabaseOperations(); + flag = dbop.updateDB(query); + + } + + //Update to user that the save operation has been completed + FacesMessage msg = new FacesMessage("Scenario name " + scenarioName + + " is saved"); + FacesContext.getCurrentInstance().addMessage(null, msg); + + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + } + } +} \ No newline at end of file diff --git a/src/art/database/DatabaseOperations.java b/src/art/database/DatabaseOperations.java index 2426f6a..b2beecc 100644 --- a/src/art/database/DatabaseOperations.java +++ b/src/art/database/DatabaseOperations.java @@ -4,13 +4,18 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; -import java.util.List; + +import com.google.visualization.*; +import com.google.visualization.datasource.datatable.ColumnDescription; +import com.google.visualization.datasource.datatable.DataTable; import art.datastructures.BOAttribute; import art.datastructures.BusinessObject; +import art.datastructures.Scenario; public class DatabaseOperations { @@ -43,6 +48,29 @@ public ResultSet executeQuery(String query) { statement = connection.createStatement(); // resultSet gets the result of the SQL query resultSet = statement.executeQuery(query); + + } catch (Exception e) { + System.out.println("Error in Database Operations :" + + e.getMessage()); + + } + return resultSet; + + } + + public ArrayList executegetColumnQuery(String query,int columnIndex) { + ArrayList resultString = new ArrayList(); + + try { + // statements allow to issue SQL queries to the database + statement = connection.createStatement(); + // resultSet gets the result of the SQL query + resultSet = statement.executeQuery(query); + //get the values from resultSet + while (resultSet.next()) { + resultString.add(resultSet.getString(columnIndex)); + } + } catch (Exception e) { System.out.println("Error in Database Operations :" + e.getMessage()); @@ -58,10 +86,11 @@ public ResultSet executeQuery(String query) { + e.getMessage()); } } - return resultSet; + return resultString; } + public int updateDB(String query) { int flag=0; try { @@ -170,4 +199,27 @@ public ArrayList readAttributes(String businessObjectName) { return attributes; } + + public ArrayList getScenarioList() { + ArrayList scenarioNameList = new ArrayList(); + ArrayList scenario = new ArrayList(); + String query = "select scenario_name from scenarios"; + try { + DatabaseOperations dbOp = new DatabaseOperations(); + scenarioNameList = dbOp.executegetColumnQuery(query,1); + System.out.println("Message as per JK's advice -------------" + scenarioNameList); + + for(int i=0; i< scenarioNameList.size();i++) { + Scenario temp = new Scenario(); + temp.setScenarioName(scenarioNameList.get(i)); + scenario.add(temp); + } + + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + return scenario; + } + } diff --git a/src/art/datastructures/Scenario.java b/src/art/datastructures/Scenario.java new file mode 100644 index 0000000..126c008 --- /dev/null +++ b/src/art/datastructures/Scenario.java @@ -0,0 +1,44 @@ +package art.datastructures; + +import java.util.ArrayList; + +public class Scenario { + + private String scenarioName; + private int scenarioID; + private ArrayList preReqObjects; + private ArrayList inputObjects; + private ArrayList outputObjects; + + public String getScenarioName() { + return scenarioName; + } + public void setScenarioName(String scenarioName) { + this.scenarioName = scenarioName; + } + public int getScenarioID() { + return scenarioID; + } + public void setScenarioID(int scenarioID) { + this.scenarioID = scenarioID; + } + public ArrayList getPreReqObjects() { + return preReqObjects; + } + public void setPreReqObjects(ArrayList preReqObjects) { + this.preReqObjects = preReqObjects; + } + public ArrayList getInputObjects() { + return inputObjects; + } + public void setInputObjects(ArrayList inputObjects) { + this.inputObjects = inputObjects; + } + public ArrayList getOutputObjects() { + return outputObjects; + } + public void setOutputObjects(ArrayList outputObjects) { + this.outputObjects = outputObjects; + } + +} From 67ca2d0af7c2e6697cc347afdc0db35a1e588df0 Mon Sep 17 00:00:00 2001 From: manishgant Date: Fri, 13 Feb 2015 15:22:22 +0530 Subject: [PATCH 05/11] Finished Scenario Removal and get back saved scenario. Some issues pending in mapping existing scenario details to UI. @riceplatereddy inputs needed --- .../WebContent/WEB-INF/faces-config.pageflow | 7 +- WebContent/WEB-INF/faces-config.xml | 21 +- WebContent/attributes.xhtml | 2 +- WebContent/editScenarios.xhtml | 208 ++++++++ WebContent/home.xhtml | 2 +- WebContent/scenario_list.xhtml | 15 +- WebContent/scenarios.xhtml | 2 +- src/art/dashboard/EditScenarioOperations.java | 474 ++++++++++++++++++ src/art/dashboard/ScenarioListOperations.java | 35 +- src/art/dashboard/ScenarioOperations.java | 145 +++++- src/art/database/DatabaseOperations.java | 33 +- 11 files changed, 898 insertions(+), 46 deletions(-) create mode 100644 WebContent/editScenarios.xhtml create mode 100644 src/art/dashboard/EditScenarioOperations.java diff --git a/.metadata/WebContent/WEB-INF/faces-config.pageflow b/.metadata/WebContent/WEB-INF/faces-config.pageflow index fa1b570..0cfa084 100644 --- a/.metadata/WebContent/WEB-INF/faces-config.pageflow +++ b/.metadata/WebContent/WEB-INF/faces-config.pageflow @@ -1,6 +1,9 @@ - - + + + + + diff --git a/WebContent/WEB-INF/faces-config.xml b/WebContent/WEB-INF/faces-config.xml index c55c6cf..53252a6 100644 --- a/WebContent/WEB-INF/faces-config.xml +++ b/WebContent/WEB-INF/faces-config.xml @@ -19,15 +19,20 @@ test.DragTest session + + scenarioListOperations + art.dashboard.ScenarioListOperations + view + scenarioOperations art.dashboard.ScenarioOperations - application + view - scenarioListOperations - art.dashboard.ScenarioListOperations - session + editScenarioOperations + art.dashboard.EditScenarioOperations + view home @@ -37,5 +42,13 @@ /attributes.xhtml + + Scenario_List + /scenario_list.xhtml + + editScenario + /editScenarios.xhtml + + diff --git a/WebContent/attributes.xhtml b/WebContent/attributes.xhtml index d22a018..cb60de3 100644 --- a/WebContent/attributes.xhtml +++ b/WebContent/attributes.xhtml @@ -56,7 +56,7 @@