Roles, Users y Resources completos:
-Falta integrar Access -Falta controlar a donde puede entrar el usuario segun Access
This commit is contained in:
parent
dbab7fdd1f
commit
7adc9dcce4
@ -1,5 +1,10 @@
|
|||||||
package controller.resources;
|
package controller.resources;
|
||||||
|
|
||||||
|
import com.google.appengine.api.datastore.Key;
|
||||||
|
import com.google.appengine.api.datastore.KeyFactory;
|
||||||
|
import controller.users.UsersControllerView;
|
||||||
|
import model.Resource;
|
||||||
|
|
||||||
import javax.jdo.JDOObjectNotFoundException;
|
import javax.jdo.JDOObjectNotFoundException;
|
||||||
import javax.jdo.PersistenceManager;
|
import javax.jdo.PersistenceManager;
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
@ -29,13 +34,7 @@ public class ResourcesControllerAdd extends HttpServlet {
|
|||||||
String url = request.getParameter("url");
|
String url = request.getParameter("url");
|
||||||
Boolean status = Boolean.parseBoolean(request.getParameter("status"));
|
Boolean status = Boolean.parseBoolean(request.getParameter("status"));
|
||||||
|
|
||||||
Resource resource = new Resource(url,status);
|
createRole(url,status,pm);
|
||||||
|
|
||||||
try{
|
|
||||||
pm.makePersistent(resource);
|
|
||||||
} finally {
|
|
||||||
System.out.println("Recurso creado");
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -50,17 +49,17 @@ public class ResourcesControllerAdd extends HttpServlet {
|
|||||||
|
|
||||||
Key a = KeyFactory.stringToKey(request.getParameter("key"));
|
Key a = KeyFactory.stringToKey(request.getParameter("key"));
|
||||||
|
|
||||||
Resource resource = pm.getObjectById(Resource.class, a);
|
Resource resourc = pm.getObjectById(Resource.class, a);
|
||||||
|
|
||||||
resource.setName(request.getParameter("url"));
|
resourc.setUrl(request.getParameter("url"));
|
||||||
resource.setStatus(Boolean.parseBoolean(request.getParameter("status")));
|
resourc.setStatus(Boolean.parseBoolean(request.getParameter("status")));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pm.close();
|
pm.close();
|
||||||
try{
|
try{
|
||||||
response.sendRedirect("/resource");
|
response.sendRedirect("/resources");
|
||||||
}
|
}
|
||||||
//Al redirigr al jsp para crear, se usa RequestDispatcher, y este entra en conflicto con sendRedirect.
|
//Al redirigr al jsp para crear, se usa RequestDispatcher, y este entra en conflicto con sendRedirect.
|
||||||
catch (IllegalStateException e){
|
catch (IllegalStateException e){
|
||||||
@ -71,6 +70,17 @@ public class ResourcesControllerAdd extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createRole(String url, boolean status, PersistenceManager pm){
|
||||||
|
Resource role = new Resource(url,status);
|
||||||
|
|
||||||
|
try{
|
||||||
|
pm.makePersistent(role);
|
||||||
|
return role.getKey();
|
||||||
|
} finally {
|
||||||
|
System.out.println("Role creado");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package controller.resources;
|
|||||||
import com.google.appengine.api.datastore.Key;
|
import com.google.appengine.api.datastore.Key;
|
||||||
import com.google.appengine.api.datastore.KeyFactory;
|
import com.google.appengine.api.datastore.KeyFactory;
|
||||||
import model.Resource;
|
import model.Resource;
|
||||||
|
import model.Role;
|
||||||
|
|
||||||
import javax.jdo.JDOObjectNotFoundException;
|
import javax.jdo.JDOObjectNotFoundException;
|
||||||
import javax.jdo.PersistenceManager;
|
import javax.jdo.PersistenceManager;
|
||||||
@ -21,9 +22,9 @@ public class ResourcesControllerDelete extends HttpServlet {
|
|||||||
PersistenceManager pm = controller.PMF.get().getPersistenceManager();
|
PersistenceManager pm = controller.PMF.get().getPersistenceManager();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Key k = KeyFactory.stringToKey(request.getParameter("key"));
|
Key key = KeyFactory.stringToKey(request.getParameter("key"));
|
||||||
try{
|
try{
|
||||||
pm.deletePersistent(pm.getObjectById(Role.class, k));
|
pm.deletePersistent(pm.getObjectById(Resource.class, key));
|
||||||
} catch (JDOObjectNotFoundException e){
|
} catch (JDOObjectNotFoundException e){
|
||||||
System.err.println("Exception catched -> " + e.getMessage());
|
System.err.println("Exception catched -> " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -33,11 +34,11 @@ public class ResourcesControllerDelete extends HttpServlet {
|
|||||||
System.err.println("Exception captured -> " + e.getMessage());
|
System.err.println("Exception captured -> " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
response.sendRedirect("/resource");
|
response.sendRedirect("/resources");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package controller.resources;
|
package controller.resources;
|
||||||
|
|
||||||
|
import controller.roles.RolesControllerView;
|
||||||
import controller.users.UsersControllerView;
|
import controller.users.UsersControllerView;
|
||||||
import model.User;
|
import model.User;
|
||||||
|
|
||||||
@ -25,8 +26,8 @@ public class ResourcesControllerIndex extends HttpServlet {
|
|||||||
if (user == null) throw new NullPointerException("UsersControllerIndex: El usuario recibido es nulo.");
|
if (user == null) throw new NullPointerException("UsersControllerIndex: El usuario recibido es nulo.");
|
||||||
|
|
||||||
request.setAttribute("User",user);
|
request.setAttribute("User",user);
|
||||||
request.setAttribute("ResourceList",RolesControllerView.getAllRoles());
|
request.setAttribute("ResourceList",ResourcesControllerView.getAllResources());
|
||||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resource/index.jsp");
|
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resources/index.jsp");
|
||||||
dispatcher.forward(request,response);
|
dispatcher.forward(request,response);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -39,6 +40,6 @@ public class ResourcesControllerIndex extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static controller.roles.RolesControllerView.getRole;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ResourcesControllerView extends HttpServlet {
|
public class ResourcesControllerView extends HttpServlet {
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
@ -28,8 +30,8 @@ public class ResourcesControllerView extends HttpServlet {
|
|||||||
|
|
||||||
//Redirige al formulario para editar un Resource (resource/view)
|
//Redirige al formulario para editar un Resource (resource/view)
|
||||||
if (action.equals("editRedirect") && key != null){
|
if (action.equals("editRedirect") && key != null){
|
||||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resource/view.jsp");
|
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resources/view.jsp");
|
||||||
request.setAttribute("Resource",getRole(key));
|
request.setAttribute("Resource",getResource(key));
|
||||||
request.setAttribute("UserLogged",UsersControllerView.getUser(request.getSession().getAttribute("userID").toString()));
|
request.setAttribute("UserLogged",UsersControllerView.getUser(request.getSession().getAttribute("userID").toString()));
|
||||||
|
|
||||||
//Ya que se quiere editar, el atributo permitirEdicion es verdadero. Este atributo se comprueba en el JSP.
|
//Ya que se quiere editar, el atributo permitirEdicion es verdadero. Este atributo se comprueba en el JSP.
|
||||||
@ -43,8 +45,8 @@ public class ResourcesControllerView extends HttpServlet {
|
|||||||
}
|
}
|
||||||
//Redirige al formulario para ver un usuario (user/view)
|
//Redirige al formulario para ver un usuario (user/view)
|
||||||
else if (action.equals("viewRedirect") && key != null){
|
else if (action.equals("viewRedirect") && key != null){
|
||||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resource/view.jsp");
|
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resources/view.jsp");
|
||||||
request.setAttribute("Resource",getRole(key));
|
request.setAttribute("Resource",getResource(key));
|
||||||
request.setAttribute("UserLogged",UsersControllerView.getUser(request.getSession().getAttribute("userID").toString()));
|
request.setAttribute("UserLogged",UsersControllerView.getUser(request.getSession().getAttribute("userID").toString()));
|
||||||
|
|
||||||
//Ya que no quiere editar, el atributo permitirEdicion es falso. Este atributo se comprueba en el JSP.
|
//Ya que no quiere editar, el atributo permitirEdicion es falso. Este atributo se comprueba en el JSP.
|
||||||
@ -66,7 +68,7 @@ public class ResourcesControllerView extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,11 +79,11 @@ public class ResourcesControllerView extends HttpServlet {
|
|||||||
* @return Un List<Resource> con todos los Recursos
|
* @return Un List<Resource> con todos los Recursos
|
||||||
* */
|
* */
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<Resource> getAllRoles(){
|
public static List<Resource> getAllResources(){
|
||||||
PersistenceManager pm = controller.PMF.get().getPersistenceManager();
|
PersistenceManager pm = controller.PMF.get().getPersistenceManager();
|
||||||
List<Resource> users = (List<Resource>) pm.newQuery("select from " + Resource.class.getName()).execute();
|
List<Resource> resources = (List<Resource>) pm.newQuery("select from " + Resource.class.getName()).execute();
|
||||||
pm.close();
|
pm.close();
|
||||||
return users;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Resource getResource(String key){
|
public static Resource getResource(String key){
|
||||||
@ -91,4 +93,5 @@ public class ResourcesControllerView extends HttpServlet {
|
|||||||
pm.close();
|
pm.close();
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package controller.users;
|
package controller.users;
|
||||||
|
|
||||||
|
import controller.resources.ResourcesControllerView;
|
||||||
import controller.roles.RolesControllerAdd;
|
import controller.roles.RolesControllerAdd;
|
||||||
import controller.roles.RolesControllerView;
|
import controller.roles.RolesControllerView;
|
||||||
|
import model.Resource;
|
||||||
import model.Role;
|
import model.Role;
|
||||||
import model.User;
|
import model.User;
|
||||||
|
|
||||||
|
@ -11,48 +11,54 @@ import javax.jdo.annotations.PrimaryKey;
|
|||||||
|
|
||||||
import com.google.appengine.api.datastore.Key;
|
import com.google.appengine.api.datastore.Key;
|
||||||
import com.google.appengine.api.datastore.KeyFactory;
|
import com.google.appengine.api.datastore.KeyFactory;
|
||||||
|
|
||||||
|
@PersistenceCapable
|
||||||
public class Resource {
|
public class Resource {
|
||||||
|
|
||||||
|
@PrimaryKey
|
||||||
@PrimaryKey
|
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
|
||||||
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
|
private Key key;
|
||||||
private Key key;
|
|
||||||
|
//URL del recurso
|
||||||
//URL del recurso
|
@Persistent
|
||||||
@Persistent
|
private String Url;
|
||||||
private String Url;
|
|
||||||
|
//Estado del recurso
|
||||||
//Estado del recurso
|
@Persistent
|
||||||
@Persistent
|
private boolean status;
|
||||||
private boolean status;
|
|
||||||
|
//Fecha de creacion del recurso
|
||||||
//Fecha de creacion del recurso
|
@Persistent
|
||||||
@Persistent
|
private String created;
|
||||||
private String created;
|
|
||||||
|
//Constructor
|
||||||
//Constructor
|
public Resource(String url,boolean status){
|
||||||
public Resource(String url,boolean status){
|
|
||||||
this.Url=url;
|
this.Url=url;
|
||||||
this.status=status;
|
this.status=status;
|
||||||
DateFormat df = new SimpleDateFormat("HH:mm:ss dd/MM/yy");
|
DateFormat df = new SimpleDateFormat("HH:mm:ss dd/MM/yy");
|
||||||
created = df.format(Calendar.getInstance().getTime());
|
created = df.format(Calendar.getInstance().getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return KeyFactory.keyToString(key);
|
return KeyFactory.keyToString(key);
|
||||||
}
|
}
|
||||||
public void setUrl(String url){
|
public void setUrl(String url){
|
||||||
this.Url=url;
|
this.Url=url;
|
||||||
}
|
}
|
||||||
public String getUrl(){
|
public String getUrl(){
|
||||||
return this.Url;
|
return this.Url;
|
||||||
}
|
}
|
||||||
public void setStatus(boolean status){
|
public void setStatus(boolean status){
|
||||||
this.status=status;
|
this.status=status;
|
||||||
}
|
}
|
||||||
public boolean getStatus(){
|
public boolean getStatus(){
|
||||||
return this.status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCreateDate(){
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "Recurso url: " + Url +"\n";
|
return "Recurso url: " + Url +"\n";
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul id="nav-mobile" class="right">
|
<ul id="nav-mobile" class="right">
|
||||||
<li class="active"><a class="whiteLink" href="">Users</a></li>
|
<li><a class="whiteLink" onclick="postRedirect('../users')">Users</a></li>
|
||||||
<li><a class="whiteLink" onclick="postRedirect('./roles')">Roles</a></li>
|
<li><a class="whiteLink" onclick="postRedirect('../roles')">Roles</a></li>
|
||||||
<li><a class="whiteLink" onclick="postRedirect('./access')">Access</a></li>
|
<li><a class="whiteLink" onclick="postRedirect('../access')">Access</a></li>
|
||||||
<li><a class="whiteLink" onclick="postRedirect('./resources')">Resources</a></li>
|
<li class="active"><a class="whiteLink" onclick="postRedirect('../resources')">Resources</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@ -94,7 +94,7 @@
|
|||||||
<input name="action" value="create" type="hidden">
|
<input name="action" value="create" type="hidden">
|
||||||
|
|
||||||
Url of the Resource:<br />
|
Url of the Resource:<br />
|
||||||
<input name="url" placeholder="Url of the Role" required><br />
|
<input name="url" placeholder="Url of the Resource" required><br />
|
||||||
Status of the Resource:<br />
|
Status of the Resource:<br />
|
||||||
<select name="status" class="browser-default" required>
|
<select name="status" class="browser-default" required>
|
||||||
<option value="" disabled selected>Choose a status</option>
|
<option value="" disabled selected>Choose a status</option>
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<br />
|
<br />
|
||||||
<span style="font-size: xx-large; font-family: 'Product Sans',Roboto,serif">Roles</span>
|
<span style="font-size: xx-large; font-family: 'Product Sans',Roboto,serif">Resources</span>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
@ -102,14 +102,15 @@
|
|||||||
<td>URL</td>
|
<td>URL</td>
|
||||||
<td>Status</td>
|
<td>Status</td>
|
||||||
<td>Date created</td>
|
<td>Date created</td>
|
||||||
|
<td>Actions</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<% for (int i = 0; i < recourseList.size(); i++) {%>
|
<% for (int i = 0; i < resourceList.size(); i++) {%>
|
||||||
<% Recourse recourse = recourseList.get(i); %>
|
<% Resource resource = resourceList.get(i); %>
|
||||||
<% String key = recourse.getKey();
|
<% String key = resource.getKey();
|
||||||
String[] arr = key.split("");
|
String[] arr = key.split("");
|
||||||
key = "";
|
key = "";
|
||||||
for (String a : arr) {
|
for (String a : arr) {
|
||||||
@ -121,13 +122,13 @@
|
|||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= recourse.getName()%></td>
|
<td><%= resource.getUrl()%></td>
|
||||||
<td><%= recourse.getStatus()%></td>
|
<td><%= resource.getStatus()%></td>
|
||||||
<td><%= recourse.getCreateDate()%></td>
|
<td><%= resource.getCreateDate()%></td>
|
||||||
<td>
|
<td>
|
||||||
<a class="postLink" onclick="postRedirect('recourses/view',{action:'viewRedirect',key:'<%=key%>'})">View</a>
|
<a class="postLink" onclick="postRedirect('resources/view',{action:'viewRedirect',key:'<%=key%>'})">View</a>
|
||||||
| <a class="postLink" onclick="postRedirect('recourses/view',{action:'editRedirect',key:'<%=key%>'})">Edit</a>
|
| <a class="postLink" onclick="postRedirect('resources/view',{action:'editRedirect',key:'<%=key%>'})">Edit</a>
|
||||||
| <a class="postLink" onclick="postRedirect('recourses/delete',{key:'<%=key%>'})">Delete</a></td>
|
| <a class="postLink" onclick="postRedirect('resources/delete',{key:'<%=key%>'})">Delete</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
Time: 16:39
|
Time: 16:39
|
||||||
To change this template use File | Settings | File Templates.
|
To change this template use File | Settings | File Templates.
|
||||||
--%>
|
--%>
|
||||||
<% Resource = (Resource) request.getAttribute("Resource");
|
<% Resource resource = (Resource) request.getAttribute("Resource");
|
||||||
User userLogged = (User) request.getAttribute("UserLogged");
|
User userLogged = (User) request.getAttribute("UserLogged");
|
||||||
boolean editAllowed = (Boolean) request.getAttribute("editAllowed");
|
boolean editAllowed = (Boolean) request.getAttribute("editAllowed");
|
||||||
String action = (String) request.getAttribute("action");
|
String action = (String) request.getAttribute("action");
|
||||||
@ -89,7 +89,7 @@
|
|||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<br />
|
<br />
|
||||||
<span style="font-size: xx-large; font-family: 'Product Sans',Roboto,serif"><%=action%> a User</span>
|
<span style="font-size: xx-large; font-family: 'Product Sans',Roboto,serif"><%=action%> a Resource</span>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
@ -100,8 +100,8 @@
|
|||||||
<input name="key" value="<%=resource.getKey()%>" type="hidden">
|
<input name="key" value="<%=resource.getKey()%>" type="hidden">
|
||||||
<input name="action" value="update" type="hidden">
|
<input name="action" value="update" type="hidden">
|
||||||
|
|
||||||
Name:<br />
|
Url:<br />
|
||||||
<input name="url" value="<%=resource.getName()%>" placeholder="url" required><br/>
|
<input name="url" value="<%=resource.getUrl()%>" placeholder="url" required><br/>
|
||||||
<br/>
|
<br/>
|
||||||
Status:<br />
|
Status:<br />
|
||||||
<select name="status" class="browser-default" required>
|
<select name="status" class="browser-default" required>
|
||||||
@ -122,7 +122,7 @@
|
|||||||
|
|
||||||
<div style="font-size: x-large">
|
<div style="font-size: x-large">
|
||||||
Url: <%=resource.getUrl()%><br />
|
Url: <%=resource.getUrl()%><br />
|
||||||
Email: <%=resource.getStatus()%><br />
|
Status: <%=resource.getStatus()%><br />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@
|
|||||||
<br />
|
<br />
|
||||||
<hr />
|
<hr />
|
||||||
Developed by:<br />
|
Developed by:<br />
|
||||||
Fernando Araoz, 2017337<br />
|
Fernando Araoz, 20173373<br />
|
||||||
Jose Rodriguez, <br />
|
Jose Rodriguez, 20101650<br />
|
||||||
Gustavo Turpo, <br />
|
Gustavo Turpo, 20173374<br />
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user