From 921615797d1a42d798f68a3801cc6c924bd09d47 Mon Sep 17 00:00:00 2001
From: Lucas Garrido <LuC31G@gmail.com>
Date: Fri, 11 Oct 2019 05:22:52 -0300
Subject: [PATCH] Implementacion de WEB Alta,Modificar de video

---
 UyTube_web/src/java/com/uytube/AltaVideo.java |   4 +-
 .../src/java/com/uytube/ModificarVideo.java   |  73 +++++++-
 UyTube_web/web/AltaVideo.jsp                  |   7 +-
 UyTube_web/web/ModificarVideo.jsp             | 175 +++++++++++++++++-
 4 files changed, 244 insertions(+), 15 deletions(-)

diff --git a/UyTube_web/src/java/com/uytube/AltaVideo.java b/UyTube_web/src/java/com/uytube/AltaVideo.java
index 9099833..b31f184 100644
--- a/UyTube_web/src/java/com/uytube/AltaVideo.java
+++ b/UyTube_web/src/java/com/uytube/AltaVideo.java
@@ -138,9 +138,7 @@ public class AltaVideo extends HttpServlet {
             DtVideo vid = new DtVideo(0, pNombre, pDescripcion,duracion, data, pUrl, Priv, pCategoria, 0, 0);
 
             sys.altaVideo(vid);
-            RequestDispatcher rd; //objeto para despachar
-            rd = request.getRequestDispatcher("/IniciarSesion.jsp");
-            rd.forward(request, response);
+            response.sendRedirect("/uytube/buscar?texto="+vid.getNombre());
 
         } catch (Exception e) {
             System.out.println(e.getMessage());
diff --git a/UyTube_web/src/java/com/uytube/ModificarVideo.java b/UyTube_web/src/java/com/uytube/ModificarVideo.java
index e757445..ef4c119 100644
--- a/UyTube_web/src/java/com/uytube/ModificarVideo.java
+++ b/UyTube_web/src/java/com/uytube/ModificarVideo.java
@@ -5,8 +5,18 @@
  */
 package com.uytube;
 
+import Logica.DataType.DtVideo;
+import Logica.Enumerados.Privacidad;
+import Logica.Fabrica;
+import Logica.Interfaces.IUsuario;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.sql.Time;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -35,7 +45,7 @@ public class ModificarVideo extends HttpServlet {
             out.println("<!DOCTYPE html>");
             out.println("<html>");
             out.println("<head>");
-            out.println("<title>Servlet ModificarVideo</title>");            
+            out.println("<title>Servlet ModificarVideo</title>");
             out.println("</head>");
             out.println("<body>");
             out.println("<h1>Servlet ModificarVideo at " + request.getContextPath() + "</h1>");
@@ -56,7 +66,25 @@ public class ModificarVideo extends HttpServlet {
     @Override
     protected void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
-        processRequest(request, response);
+        try {
+            int id = Integer.parseInt(request.getParameter("id"));
+
+            IUsuario sys = Fabrica.getInstancia().getIUsuario();
+            boolean sesionIniciada = sys.sesionIniciada();
+            ArrayList<String> cate = sys.listarCategorias();
+            DtVideo video = sys.seleccionarVideo(id);
+
+            request.setAttribute("video", video);
+            request.setAttribute("Categorias", cate);
+            request.setAttribute("sesionIniciada", sesionIniciada);
+            RequestDispatcher rd; //objeto para despachar
+            rd = request.getRequestDispatcher("/ModificarVideo.jsp");
+            rd.forward(request, response);
+        } catch (Exception e) {
+            RequestDispatcher rd; //objeto para despachar
+            rd = request.getRequestDispatcher("/");
+            rd.forward(request, response);
+        }
     }
 
     /**
@@ -70,7 +98,46 @@ public class ModificarVideo extends HttpServlet {
     @Override
     protected void doPost(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
-        processRequest(request, response);
+
+        try {
+            IUsuario sys = Fabrica.getInstancia().getIUsuario();
+            String pNombre = request.getParameter("nombre");
+            String pDuracion = request.getParameter("duracion");
+            String pUrl = request.getParameter("url");
+            String pDescripcion = request.getParameter("descripcion");
+            String pCategoria = request.getParameter("categoria");
+            String pPrivacidad = request.getParameter("privacidad");
+            String pFecha = request.getParameter("fecha");
+
+            Privacidad Priv = Privacidad.PRIVADO;
+            if (pPrivacidad != null && pPrivacidad.equals("PUBLICO")) {
+                Priv = Privacidad.PUBLICO;
+            }
+            //============ Casteo de string a date =================================
+            SimpleDateFormat formato = new SimpleDateFormat("yyyy-mm-dd");
+            Date fechaDate = null;
+            try {
+                fechaDate = formato.parse(pFecha);
+            } catch (ParseException ex) {
+                RequestDispatcher rd; //objeto para despachar
+                rd = request.getRequestDispatcher("/");
+                rd.forward(request, response);
+            }
+            java.sql.Date data = new java.sql.Date(fechaDate.getTime());
+            //======================================================================
+            //============= Casteo de string a Time ================================
+            Time duracion = java.sql.Time.valueOf(pDuracion);
+            //======================================================================
+            DtVideo vid = new DtVideo(0, pNombre, pDescripcion, duracion, data, pUrl, Priv, pCategoria, 0, 0);
+
+            sys.modificarVideo(vid);
+            response.sendRedirect("/uytube/buscar?texto="+vid.getNombre());
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+            RequestDispatcher rd; //objeto para despachar
+            rd = request.getRequestDispatcher("/");
+            rd.forward(request, response);
+        }
     }
 
     /**
diff --git a/UyTube_web/web/AltaVideo.jsp b/UyTube_web/web/AltaVideo.jsp
index 3f04f8f..ecb3aec 100644
--- a/UyTube_web/web/AltaVideo.jsp
+++ b/UyTube_web/web/AltaVideo.jsp
@@ -64,20 +64,19 @@
                         <%
                             }
                         %>
-
                         <div class="contenido">
                             <section class="contenido-flexible">
                                 <!--================== Aca va el contenido central para agregar ========================== -->					
                                 <h3>Alta de video</h3>			
                                 <form class="form-alta-video" action="/uytube/video-agregar" method="post" >
                                     <div class="form-group row">
-                                        <div class="form-group col-md-10">
+                                        <div class="form-group col-md-9">
                                             <label for="inputNombre">Nombre</label>
                                             <input type="text" class="form-control" name="nombre" id="inputNombre" placeholder="Nombre del video">
                                         </div>
-                                        <div class="form-group col-md-2">
+                                        <div class="form-group col-md-3">
                                             <label for="inputDuracion">Duración</label>
-                                            <input type="time" step='1'  class="form-control" name="duracion" id="inputDuracion" placeholder="Duración">
+                                            <input type="time" step='1'class="form-control" name="duracion" id="inputDuracion" placeholder="Duración">
                                         </div>
                                     </div>
                                     <div class="form-group row">
diff --git a/UyTube_web/web/ModificarVideo.jsp b/UyTube_web/web/ModificarVideo.jsp
index e636439..2d548ff 100644
--- a/UyTube_web/web/ModificarVideo.jsp
+++ b/UyTube_web/web/ModificarVideo.jsp
@@ -4,14 +4,179 @@
     Author     : administrador
 --%>
 
+<%@page import="java.text.DateFormat"%>
+<%@page import="java.text.DateFormat"%>
+<%@page import="java.text.SimpleDateFormat"%>
+<%@page import="Logica.Enumerados.Privacidad"%>
+<%@page import="Logica.DataType.DtVideo"%>
+<%@page import="java.util.ArrayList"%>
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
-<!DOCTYPE html>
-<html>
+<html lang="es">
+    <%
+        DtVideo video = (DtVideo) request.getAttribute("video");
+        ArrayList<String> Categorias = (ArrayList) request.getAttribute("Categorias");
+        boolean sesionIniciada = (boolean) request.getAttribute("sesionIniciada");
+    %>
     <head>
-        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-        <title>JSP Page</title>
+        <meta charset="UTF-8">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
+        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+        <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
+        <link rel="stylesheet" type="text/css" href="css/body.css">
+        <link rel="stylesheet" type="text/css" href="css/header.css">
+        <link rel="stylesheet" type="text/css" href="css/menu.css">        
+        <link rel="stylesheet" type="text/css" href="css/widget.css">
+        <link rel="stylesheet" type="text/css" href="css/footer.css">
+        <link rel="stylesheet" type="text/css" href="css/contenido-alta-video.css">	
+        <link rel="stylesheet" type="text/css" href="iconos/style.css">
+        <link rel="icon" type="image/png" href="imagenes/icono.png" />
+        <title>UyTube</title>
     </head>
     <body>
-        <h1>ModificarVideo</h1>
+
+        <%
+            if (sesionIniciada) {
+        %>
+        <%@ include file='include/header-usuario.html' %>
+        <%
+        } else {
+        %>
+        <%@ include file='include/header-visitante.html' %>
+        <%
+            }
+        %>
+        <div class="container-fluid">
+            <div class="row">
+                <div class="col-12">
+                    <div class="relleno-header"></div>
+                </div>
+            </div>
+        </div>
+        <div class="container-fluid">
+            <div class="row">
+                <div class="col-12">
+                    <section class="principal">	
+
+                        <%
+                            if (sesionIniciada) {
+                        %>
+                        <%@ include file='include/menu-usuario.html' %>
+                        <%
+                        } else {
+                        %>
+                        <%@ include file='include/menu-visitante.html' %>
+                        <%
+                            }
+                        %>
+
+                        <div class="contenido">
+                            <section class="contenido-flexible">
+                                <!--================== Aca va el contenido central para agregar ========================== -->					
+                                <h3>Modificar de video</h3>			
+                                <form class="form-alta-video" action="/uytube/video-modificar" method="post" >
+                                    <div class="form-group row">
+                                        <div class="form-group col-md-9">
+                                            <label for="inputNombre">Nombre</label>
+                                            <input value="<%= video.getNombre()%>" type="text" class="form-control" name="nombre" id="inputNombre" placeholder="Nombre del video">
+                                        </div>
+                                        <div class="form-group col-md-3">
+                                            <label for="inputDuracion">Duración</label>
+                                            <input value="<%=video.getDuracion()%>" type="time" step='1' class="form-control" name="duracion" id="inputDuracion" placeholder="Duración">
+                                        </div>
+                                    </div>
+                                    <div class="form-group row">
+                                        <div class="form-group col-md-12">
+                                            <label for="inputUrl">URL</label>
+                                            <input value="<%= video.getUrlVideoOriginal()%>"type="url" class="form-control" name="url" id="inputUrl" placeholder="URL">
+                                        </div>
+                                    </div>
+                                    <div class="form-group row">
+                                        <div class="form-group col-md-12">
+                                            <label for="inputDescripcion">Descripción</label>
+                                            <textarea class="form-control" name="descripcion" id="inputDescripcion" rows="3"><%=video.getDescripcion()%></textarea>
+                                        </div>
+                                    </div>										
+                                    <div class="form-group row">
+                                        <div class="form-group col-md-4">
+
+                                            <label  for="cc-name">Privacidad del video</label>
+                                            <%
+                                                if (video.getPrivacidad() == Privacidad.PRIVADO) {
+                                            %>
+                                            <div class="custom-control custom-radio">
+                                                <input id="publico" name="privacidad" type="radio" class="custom-control-input" >
+                                                <label class="custom-control-label" for="publico">Publico</label>
+                                            </div>
+                                            <div class="custom-control custom-radio">
+                                                <input id="privado" name="privacidad" name="foto" type="radio" class="custom-control-input" checked>
+                                                <label class="custom-control-label" for="privado">Privado</label>
+                                            </div>
+                                            <%
+                                                }
+
+                                            %>
+
+                                            <%                                                if (video.getPrivacidad() == Privacidad.PUBLICO) {
+                                            %>
+                                            <div class="custom-control custom-radio">
+                                                <input id="publico" name="privacidad" type="radio" class="custom-control-input" checked>
+                                                <label class="custom-control-label" for="publico">Publico</label>
+                                            </div>
+                                            <div class="custom-control custom-radio">
+                                                <input id="privado" name="privacidad" name="foto" type="radio" class="custom-control-input">
+                                                <label class="custom-control-label" for="privado">Privado</label>
+                                            </div>
+                                            <%
+                                                }
+                                            %>
+
+                                        </div>
+
+                                        <div class="form-group col-md-4">
+                                            <%
+                                                DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+                                                String fecha = df.format(video.getFechaPublicacion());
+                                            %>
+                                            <label for="inputFecha">Fecha</label>
+                                            <input value="<%= fecha %>" type="date" name="fecha" class="form-control"  id="inputFecha">
+                                        </div>  
+                                        <div class="form-group col-md-4">
+                                            <label for="inputCategoria">Categoría</label>
+                                            <select id="inputCategoria" name="categoria" class="form-control">
+                                                <%
+                                                    for (String l : Categorias) {
+                                                        if (video.getCategoria().equals(l)) {
+                                                %>
+                                                <option  selected = "selected"> <%= l%>  </option> 
+                                                <%
+                                                } else {
+                                                %>
+                                                <option> <%= l%>  </option> 
+                                                <%
+                                                        }
+                                                    }
+                                                %>
+                                            </select>
+                                        </div>												
+                                    </div>
+                                    <button type="submit" class="btn btn-primary">Modificar video</button>
+                                    </div>											
+                                </form>
+                                <!-- Fin del contenido central -->
+                            </section>
+                        </div>
+
+                    </section>	
+                </div>
+            </div>
+        </div>
+
+        <%@ include file='include/widgets.html' %>
+        <%@ include file='include/footer.html' %>
+
+        <script src="js/jquery-3.4.1.min.js"></script>
+        <script src="js/bootstrap.bundle.min.js"></script>
+        <script src="js/bootstrap.min.js"></script>
+        <script src="js/funciones.js"></script>
     </body>
 </html>
-- 
GitLab