Access terminado

This commit is contained in:
Gustavo 2018-06-17 11:26:01 -05:00
parent 7adc9dcce4
commit 4d18d80d41
11 changed files with 432 additions and 116 deletions

View File

@ -1,18 +1,66 @@
package controller.access; package controller.access;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import javax.servlet.http.*;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import controller.PMF;
import javax.servlet.*;
import javax.jdo.PersistenceManager;
import model.entity.*;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class AccessControllerAdd extends HttpServlet { public class AccessControllerAdd extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PersistenceManager pm = PMF.get().getPersistenceManager();
} /*Role r = new Role("mesero");
Resource re = new Resource("/comida");
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {
pm.makePersistent(r);
pm.makePersistent(re);
} finally {
pm.close();
}*/
try{
System.out.print(request.getParameter("info"));
String query = "select from " + Role.class.getName();
String query2 = "select from " + Resource.class.getName();
List<Role> roles = (List<Role>)pm.newQuery(query).execute();
List<Resource> resources = (List<Resource>)pm.newQuery(query2).execute();
request.setAttribute("roles", roles);
request.setAttribute("resources", resources);
String queryp = "select " + Role.class.getName();
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/add.jsp");
dispatcher.forward(request, response);
try{
if(request.getParameter("info").equals("agregar")){
String idRole=request.getParameter("rolesl");
String idResource=request.getParameter("resourcesl");
if(idRole == null || idRole.equals("")|| idResource == null || idResource.equals("")){System.out.print("nombre vacio");}
else{
Access a = new Access(
new Long(idRole).longValue(),
new Long(idResource).longValue(),
true
);
//persist the entity
try {
System.out.print(request.getParameter("action"));
pm.makePersistent(a);
} finally {
pm.close();
}
}
}
}catch (java.lang.NullPointerException np){}
}catch(java.lang.NullPointerException np){} {
System.out.print("error");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} }
} }

View File

@ -1,18 +1,33 @@
package controller.access; package controller.access;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.*;
import java.util.Date;
import java.util.List;
import java.text.DateFormat;
import javax.servlet.*;
import javax.jdo.PersistenceManager;
import model.entity.*;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import controller.PMF;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class AccessControllerDelete extends HttpServlet { public class AccessControllerDelete extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// create the persistence manager instance
} PersistenceManager pm = PMF.get().getPersistenceManager();
// create the new account
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try{
Key k = KeyFactory.createKey(Access.class.getSimpleName(), new Long(request.getParameter("accessId")).longValue());
Access r = pm.getObjectById(Access.class, k);
pm.deletePersistent(r);
response.sendRedirect("/access");
} catch(javax.jdo.JDOObjectNotFoundException nf) {
response.sendRedirect("/access");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} }
} }

View File

@ -0,0 +1,55 @@
package controller.access;
import java.io.IOException;
import javax.servlet.http.*;
import java.util.Date;
import java.util.List;
import java.text.DateFormat;
import javax.servlet.*;
import javax.jdo.PersistenceManager;
import model.entity.*;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import controller.PMF;
@SuppressWarnings("serial")
public class AccessControllerEdit extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// create the persistence manager instance
PersistenceManager pm = PMF.get().getPersistenceManager();
try{
System.out.print(request.getParameter("info"));
Key k = KeyFactory.createKey(Access.class.getSimpleName(), new Long(request.getParameter("id")).longValue());
Access a = pm.getObjectById(Access.class, k);
request.setAttribute("access", a);
String query = "select from " + Role.class.getName();
String query2 = "select from " + Resource.class.getName();
List<Role> roles = (List<Role>)pm.newQuery(query).execute();
List<Resource> resources = (List<Resource>)pm.newQuery(query2).execute();
request.setAttribute("roles", roles);
request.setAttribute("resources", resources);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/edit.jsp");
dispatcher.forward(request, response);
try{
if(request.getParameter("info").equals("editar")){
String idRole=request.getParameter("rolesl");
String idResource=request.getParameter("resourcesl");
if(idRole == null || idRole.equals("")|| idResource == null || idResource.equals("")){System.out.print("nombre vacio");}
else{
if(a.getIdRole().equals(idRole)==false){
a.setIdRole(new Long(idRole).longValue());
}
if(a.getIdResource().equals(idResource)==false){
a.setIdResource(new Long(idResource).longValue());
}
}
}
}catch (java.lang.NullPointerException np){}
}catch(javax.jdo.JDOObjectNotFoundException nf) {
response.sendRedirect("/index.html");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}

View File

@ -1,18 +1,32 @@
package controller.access; package controller.access;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.*;
import java.util.Date;
import java.util.List;
import java.text.DateFormat;
import javax.servlet.*;
import javax.jdo.PersistenceManager;
import model.entity.*;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import controller.PMF;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class AccessControllerIndex extends HttpServlet { public class AccessControllerIndex extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
// create the persistence manager instance
PersistenceManager pm = PMF.get().getPersistenceManager();
// query for the entities by name
String query = "select from " + Access.class.getName();
List<Access> accesses = (List<Access>)pm.newQuery(query).execute();
// pass the list to the jsp
request.setAttribute("accesses", accesses);
// forward the request to the jsp
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/index.jsp");
dispatcher.forward(request, response);
} }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response);
} }
} }

View File

@ -1,18 +1,43 @@
package controller.access; package controller.access;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.*;
import java.util.Date;
import java.util.List;
import java.text.DateFormat;
import javax.servlet.*;
import javax.jdo.PersistenceManager;
import model.entity.*;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import controller.PMF;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class AccessControllerView extends HttpServlet { public class AccessControllerView extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// create the persistence manager instance
} PersistenceManager pm = PMF.get().getPersistenceManager();
try{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.print(request.getParameter("info"));
Key k = KeyFactory.createKey(Access.class.getSimpleName(), new Long(request.getParameter("id")).longValue());
Access a = pm.getObjectById(Access.class, k);
request.setAttribute("access", a);
Key krol = KeyFactory.createKey(Role.class.getSimpleName(), a.getIdRole());
Role rol = pm.getObjectById(Role.class, krol);
String nrol = rol.getName();
Key kres = KeyFactory.createKey(Resource.class.getSimpleName(), a.getIdResource());
Resource res = pm.getObjectById(Resource.class, kres);
String nres = res.getName();
System.out.print(nres);
request.setAttribute("role", nrol);
request.setAttribute("resource", nres);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/view.jsp");
dispatcher.forward(request, response);
}catch(javax.jdo.JDOObjectNotFoundException nf) {
response.sendRedirect("/access");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} }
} }

View File

@ -1,4 +1,45 @@
package model; package model.entity;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Access { public class Access {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Long id;
@Persistent private Long idRole;
@Persistent private Long idResource;
@Persistent private boolean status;
public Access(Long idRole, Long idResource, boolean status) {
this.idRole = idRole;
this.idResource = idResource;
this.status = status;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getIdRole() {
return idRole;
}
public void setIdRole(Long idRole) {
this.idRole = idRole;
}
public Long getIdResource() {
return idResource;
}
public void setIdResource(Long idResource) {
this.idResource = idResource;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
} }

View File

@ -1,16 +1,43 @@
<%-- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
Created by IntelliJ IDEA. pageEncoding="ISO-8859-1"%>
User: Fernando <%@ page import="model.entity.*"%>
Date: 07/06/2018 <%@ page import="java.util.List"%>
Time: 16:39 <%
To change this template use File | Settings | File Templates. List<Role> roles = (List<Role>)request.getAttribute("roles");
--%> List<Resource> resourses = (List<Resource>)request.getAttribute("resources");
<%@ page contentType="text/html;charset=UTF-8" language="java" %> %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>
<head> <head>
<title>Title</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head> </head>
<body> <body>
<span class="nav"><a href="/access">Back</a></span><p/>
<form name="post" method="post" action="add">
<input type="hidden" name="info" value="agregar"/>
<select name="rolesl">
<% if (roles.size() > 0) { %>
<% for (int i = 0;i<roles.size();i++) { %>
<% Role r = (Role)roles.get(i); %>
<option value="<%= r.getId() %>"><%= r.getName() %></option>
<% } %>
<% } else { %>
<p/><span class="heading">No hay empleados registrados</span>
<% } %>
</select>
<select name="resourcesl">
<% if (resourses.size() > 0) { %>
<% for (int i = 0;i<resourses.size();i++) { %>
<% Resource res = (Resource)resourses.get(i); %>
<option value="<%= res.getId() %>"><%= res.getName() %></option>
<% } %>
<% } else { %>
<p/><span class="heading">No hay empleados registrados</span>
<% } %>
</select>
<input type="submit" value="Submit">
</form>
</body> </body>
</html> </html>

View File

@ -0,0 +1,45 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="model.entity.*"%>
<%@ page import="java.util.List"%>
<%
List<Role> roles = (List<Role>)request.getAttribute("roles");
List<Resource> resourses = (List<Resource>)request.getAttribute("resources");
Access a = (Access)request.getAttribute("access");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<span class="nav"><a href="/access">Back</a></span><p/>
<form name="post" method="post" action="edit">
<input type="hidden" name="id" value="<%= a.getId() %>"/>
<input type="hidden" name="info" value="editar"/>
<select name="rolesl">
<% if (roles.size() > 0) { %>
<% for (int i = 0;i<roles.size();i++) { %>
<% Role r = (Role)roles.get(i); %>
<option value="<%= r.getId() %>"><%= r.getName() %></option>
<% } %>
<% } else { %>
<p/><span class="heading">No hay empleados registrados</span>
<% } %>
</select>
<select name="resourcesl">
<% if (resourses.size() > 0) { %>
<% for (int i = 0;i<resourses.size();i++) { %>
<% Resource res = (Resource)resourses.get(i); %>
<option value="<%= res.getId() %>"><%= res.getName() %></option>
<% } %>
<% } else { %>
<p/><span class="heading">No hay empleados registrados</span>
<% } %>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>

View File

@ -1,16 +1,41 @@
<%-- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
Created by IntelliJ IDEA. pageEncoding="ISO-8859-1"%>
User: Fernando <%@ page import="java.util.List"%>
Date: 07/06/2018 <%@ page import="model.entity.*"%>
Time: 16:39 <%
To change this template use File | Settings | File Templates. List<Access> accesses = (List<Access>)request.getAttribute("accesses");
--%> %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>
<head> <head>
<title>Title</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head> </head>
<body> <body>
<a href="/index.html">Regresar</a>
<table border="0" cellspacing="1" cellpadding="5" bgcolor="#CCCCCC">
<tr>
<td>ID</td>
<td>Role</td>
<td>Resource</td>
<td>Status</td>
</tr>
<% if (accesses.size() > 0) { %>
<% for (int i = 0;i<accesses.size();i++) { %>
<% Access e = (Access)accesses.get(i); %>
<tr style="background:#ffffff" onMouseOver="this.style.background='#eeeeee';" onMouseOut="this.style.background='#ffffff';">
<td nowrap style="font-weight: bold;"><%= e.getId() %></td>
<td style="font-weight: bold;"><%= e.getIdRole() %></td>
<td style="font-weight: bold;"><%= e.getIdResource() %></td>
<td style="font-weight: bold;"><%= e.getStatus() %></td>
<td><a href="/access/view?id=<%= e.getId() %>">View</a></td>
<td><a href="/access/edit?id=<%= e.getId() %>">Edit</a></td>
<td><form name="post_<%= e.getId() %>" style="display:none;" method="post" action="/access/delete"><input type="hidden" name="accessId" value="<%= e.getId() %>"/></form><a href="#" onclick="if (confirm(&quot;Are you sure you want to delete # <%= e.getId() %>?&quot;)) { document.post_<%= e.getId() %>.submit(); } event.returnValue = false; return false;">Delete</a></td>
</tr>
<% } %>
</table>
<% } else { %>
<p/><span class="heading">No hay empleados registrados</span>
<% } %>
</body> </body>
</html> </html>

View File

@ -1,16 +1,32 @@
<%-- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
Created by IntelliJ IDEA. pageEncoding="ISO-8859-1"%>
User: Fernando <%@ page import="model.entity.*"%>
Date: 07/06/2018 <%
Time: 16:39 Access access = (Access)request.getAttribute("access");
To change this template use File | Settings | File Templates. String role = (String)request.getAttribute("role");
--%> String resource = (String)request.getAttribute("resource");
<%@ page contentType="text/html;charset=UTF-8" language="java" %> %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>
<head> <head>
<title>Title</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head> </head>
<body> <body>
<span class="nav"><a href="/access">Back</a></span><p/>
<table border="0" cellspacing="1" cellpadding="5" bgcolor="#CCCCCC">
<tr bgcolor="#407BA8">
<td style="color: #ffffff; font-weight: bold;">ID</td>
<td bgcolor="#ffffff"><%= access.getId() %></td>
</tr>
<tr bgcolor="#407BA8">
<td style="color: #ffffff; font-weight: bold;">Role</td>
<td bgcolor="#ffffff"><%= role %></td>
</tr>
<tr bgcolor="#407BA8">
<td style="color: #ffffff; font-weight: bold;">Resource</td>
<td bgcolor="#ffffff"><%= resource %></td>
</tr>
</table>
</body> </body>
</html> </html>

View File

@ -117,6 +117,14 @@
<servlet>
<servlet-name>AccessControllerEdit</servlet-name>
<servlet-class>controller.access.AccessControllerEdit</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AccessControllerEdit</servlet-name>
<url-pattern>/access/edit</url-pattern>
</servlet-mapping>
<servlet> <servlet>
<servlet-name>AccessControllerAdd</servlet-name> <servlet-name>AccessControllerAdd</servlet-name>
<servlet-class>controller.access.AccessControllerAdd</servlet-class> <servlet-class>controller.access.AccessControllerAdd</servlet-class>
@ -125,7 +133,6 @@
<servlet-name>AccessControllerAdd</servlet-name> <servlet-name>AccessControllerAdd</servlet-name>
<url-pattern>/access/add</url-pattern> <url-pattern>/access/add</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet> <servlet>
<servlet-name>AccessControllerIndex</servlet-name> <servlet-name>AccessControllerIndex</servlet-name>
<servlet-class>controller.access.AccessControllerIndex</servlet-class> <servlet-class>controller.access.AccessControllerIndex</servlet-class>
@ -134,7 +141,6 @@
<servlet-name>AccessControllerIndex</servlet-name> <servlet-name>AccessControllerIndex</servlet-name>
<url-pattern>/access</url-pattern> <url-pattern>/access</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet> <servlet>
<servlet-name>AccessControllerView</servlet-name> <servlet-name>AccessControllerView</servlet-name>
<servlet-class>controller.access.AccessControllerView</servlet-class> <servlet-class>controller.access.AccessControllerView</servlet-class>
@ -143,7 +149,6 @@
<servlet-name>AccessControllerView</servlet-name> <servlet-name>AccessControllerView</servlet-name>
<url-pattern>/access/view</url-pattern> <url-pattern>/access/view</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet> <servlet>
<servlet-name>AccessControllerDelete</servlet-name> <servlet-name>AccessControllerDelete</servlet-name>
<servlet-class>controller.access.AccessControllerDelete</servlet-class> <servlet-class>controller.access.AccessControllerDelete</servlet-class>