String Product=request.getParameter("product");
String Person=request.getParameter("person");
if ((Product==null) && (Person==null)) { //llamada de entrada
try {
JSONObject responseObj = new JSONObject();
Person p = giveUser(User);
int Idp=p.getIdPerson();
List<Product> productos = scrum.getProductListPerson(Idp);
// Recogemos los datos de los productos obtenidos
List<JSONObject> productObjects = new LinkedList<JSONObject>();
for (Product product : productos) {
JSONObject productObj = new JSONObject();
productObj.put("Description", product.getDescription());
productObj.put("name", product.getName());
productObj.put("Done", product.getDone());
productObj.put("CurrentEstimation",product.getCurrentEstimation());
productObj.put("InitialEstimation",product.getInitialEstimation());
productObj.put("Assigned",product.getAssigned());
productObj.put("Planned",product.getPlanned());
productObj.put("id", product.getId());
productObjects.add(productObj);
}
//Escribimos la respuesta
responseObj.put("paso", checkPassword(User,Password));
//responseObj.put("productos",jsonString.toString());
responseObj.put("productos", productObjects);
PrintWriter writer = response.getWriter();
writer.write( responseObj.toString());
writer.flush();
}
catch (Exception e) {
e.printStackTrace();
throw new ServletException(e);
}
}else if ((Product != null) && (Product.equals("assigned"))){
//Recuperamos las personas asignadas a este producto
try {
List<Person> persons ;
JSONObject responseObj = new JSONObject();
String id=request.getParameter("id");
String Asiggned=request.getParameter("work");
if (Asiggned.equals("no")){
persons = scrum.getProductPersonList(Integer.valueOf(id),false);
}else{
persons = scrum.getProductPersonList(Integer.valueOf(id),true);
}
List<JSONObject> personsObjects = new LinkedList<JSONObject>();
for (Person person : persons) {
JSONObject personObj = new JSONObject();
personObj.put("name", person.getName());
personObj.put("id", person.getIdPerson());
personsObjects.add(personObj);
}
//Escribimos la respuesta
responseObj.put("paso", checkPassword(User,Password));
responseObj.put("personas", personsObjects);
PrintWriter writer = response.getWriter();
writer.write(responseObj.toString());
writer.flush();
}
catch (Exception e) {
throw new ServletException(e);
}
}else if ((Product != null) && (Product.equals("rescue"))){
//Para recuperar un producto y sus themes dando su id
try {
JSONObject responseObj = new JSONObject();
String id=request.getParameter("id");
Product product= scrum.getProduct(Integer.valueOf(id));
responseObj.put("Description", product.getDescription());
responseObj.put("name", product.getName());
responseObj.put("Done", product.getDone());
responseObj.put("CurrentEstimation",product.getCurrentEstimation());
responseObj.put("InitialEstimation",product.getInitialEstimation());
responseObj.put("Assigned",product.getAssigned());
responseObj.put("Planned",product.getPlanned());
responseObj.put("id", product.getId());
/*Sacamos los themes de el producto para enviarlos */
List<Theme> temas = product.getThemeList();
List<JSONObject> themeObjects = new LinkedList<JSONObject>();
for (Theme tema : temas) {
JSONObject themeObj = new JSONObject();
themeObj.put("description", tema.getDescription());
themeObj.put("name", tema.getName());
themeObj.put("id", tema.getId());
themeObj.put("parent",tema.getParent());
themeObj.put("parentproduct",tema.getParentProduct());
themeObj.put("stored",tema.getStored());
themeObjects.add(themeObj);
}
/*Sacamos los Subtemas del producto para enviarlos */
List<Theme> Subtemas = product.getSubThemeList();
List<JSONObject> SubthemeObjects = new LinkedList<JSONObject>();
for (Theme tema : Subtemas) {
JSONObject themeObj = new JSONObject();
themeObj.put("description", tema.getDescription());
themeObj.put("name", tema.getName());
themeObj.put("id", tema.getId());
themeObj.put("parent",tema.getParent());
themeObj.put("parentproduct",tema.getParentProduct());
themeObj.put("stored",tema.getStored());
SubthemeObjects.add(themeObj);
}
//Escribimos la respuesta
responseObj.put("paso", checkPassword(User,Password));
responseObj.put("themes", themeObjects);
responseObj.put("subthemes",SubthemeObjects);
PrintWriter writer = response.getWriter();
writer.write(responseObj.toString());
writer.flush();
}
catch (Exception e) {
throw new ServletException(e);
}
}else if ((Person != null) && (Person.equals("rescue"))){
/* Mostramos las personas
* Si viene un 0 sacaremos a todas.
*/
try {
JSONObject responseObj = new JSONObject();
String id=request.getParameter("id");
if (id.equals("0")){
List<Person> persons = scrum.getCompleteStaffList();
List<JSONObject> personObjects = new LinkedList<JSONObject>();
for (Person person : persons) {
JSONObject personObj = new JSONObject();
personObj.put("name", person.getName());
personObj.put("id", person.getIdPerson());
personObj.put("stored", person.getStored());
personObjects.add(personObj);
}
responseObj.put("paso", checkPassword(User,Password));
responseObj.put("personas", personObjects);
PrintWriter writer = response.getWriter();
writer.write( responseObj.toString());
writer.flush();
}else{
Person person= scrum.getPerson(Integer.valueOf(id));
responseObj.put("name", person.getName());
responseObj.put("parent", person.getParent());
responseObj.put("id", person.getIdPerson());
responseObj.put("stored", person.getStored());
//Escribimos la respuesta
responseObj.put("paso", checkPassword(User,Password));
PrintWriter writer = response.getWriter();
writer.write(responseObj.toString());
writer.flush();