Roles, Users y Resources completos:

-Falta integrar Access
-Falta controlar a donde puede entrar el usuario segun Access
This commit is contained in:
Araozu 2018-06-16 16:46:12 -05:00
parent dbab7fdd1f
commit 7adc9dcce4
10 changed files with 104 additions and 80 deletions

View File

@ -1,5 +1,10 @@
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.PersistenceManager;
import javax.servlet.RequestDispatcher;
@ -29,13 +34,7 @@ public class ResourcesControllerAdd extends HttpServlet {
String url = request.getParameter("url");
Boolean status = Boolean.parseBoolean(request.getParameter("status"));
Resource resource = new Resource(url,status);
try{
pm.makePersistent(resource);
} finally {
System.out.println("Recurso creado");
}
createRole(url,status,pm);
break;
@ -50,17 +49,17 @@ public class ResourcesControllerAdd extends HttpServlet {
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"));
resource.setStatus(Boolean.parseBoolean(request.getParameter("status")));
resourc.setUrl(request.getParameter("url"));
resourc.setStatus(Boolean.parseBoolean(request.getParameter("status")));
break;
}
pm.close();
try{
response.sendRedirect("/resource");
response.sendRedirect("/resources");
}
//Al redirigr al jsp para crear, se usa RequestDispatcher, y este entra en conflicto con sendRedirect.
catch (IllegalStateException e){
@ -71,6 +70,17 @@ public class ResourcesControllerAdd extends HttpServlet {
}
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");
}
}
}

View File

@ -3,6 +3,7 @@ package controller.resources;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import model.Resource;
import model.Role;
import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
@ -21,9 +22,9 @@ public class ResourcesControllerDelete extends HttpServlet {
PersistenceManager pm = controller.PMF.get().getPersistenceManager();
try {
Key k = KeyFactory.stringToKey(request.getParameter("key"));
Key key = KeyFactory.stringToKey(request.getParameter("key"));
try{
pm.deletePersistent(pm.getObjectById(Role.class, k));
pm.deletePersistent(pm.getObjectById(Resource.class, key));
} catch (JDOObjectNotFoundException e){
System.err.println("Exception catched -> " + e.getMessage());
}
@ -33,11 +34,11 @@ public class ResourcesControllerDelete extends HttpServlet {
System.err.println("Exception captured -> " + e.getMessage());
}
response.sendRedirect("/resource");
response.sendRedirect("/resources");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
}

View File

@ -1,5 +1,6 @@
package controller.resources;
import controller.roles.RolesControllerView;
import controller.users.UsersControllerView;
import model.User;
@ -25,8 +26,8 @@ public class ResourcesControllerIndex extends HttpServlet {
if (user == null) throw new NullPointerException("UsersControllerIndex: El usuario recibido es nulo.");
request.setAttribute("User",user);
request.setAttribute("ResourceList",RolesControllerView.getAllRoles());
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resource/index.jsp");
request.setAttribute("ResourceList",ResourcesControllerView.getAllResources());
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resources/index.jsp");
dispatcher.forward(request,response);
}
@ -39,6 +40,6 @@ public class ResourcesControllerIndex extends HttpServlet {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
}

View File

@ -14,6 +14,8 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import static controller.roles.RolesControllerView.getRole;
@SuppressWarnings("serial")
public class ResourcesControllerView extends HttpServlet {
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)
if (action.equals("editRedirect") && key != null){
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resource/view.jsp");
request.setAttribute("Resource",getRole(key));
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resources/view.jsp");
request.setAttribute("Resource",getResource(key));
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.
@ -43,8 +45,8 @@ public class ResourcesControllerView extends HttpServlet {
}
//Redirige al formulario para ver un usuario (user/view)
else if (action.equals("viewRedirect") && key != null){
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resource/view.jsp");
request.setAttribute("Resource",getRole(key));
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resources/view.jsp");
request.setAttribute("Resource",getResource(key));
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.
@ -66,7 +68,7 @@ public class ResourcesControllerView extends HttpServlet {
}
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
* */
@SuppressWarnings("unchecked")
public static List<Resource> getAllRoles(){
public static List<Resource> getAllResources(){
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();
return users;
return resources;
}
public static Resource getResource(String key){
@ -91,4 +93,5 @@ public class ResourcesControllerView extends HttpServlet {
pm.close();
return resource;
}
}

View File

@ -1,7 +1,9 @@
package controller.users;
import controller.resources.ResourcesControllerView;
import controller.roles.RolesControllerAdd;
import controller.roles.RolesControllerView;
import model.Resource;
import model.Role;
import model.User;

View File

@ -11,48 +11,54 @@ import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
@PersistenceCapable
public class Resource {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
//URL del recurso
@Persistent
private String Url;
//URL del recurso
@Persistent
private String Url;
//Estado del recurso
@Persistent
private boolean status;
//Estado del recurso
@Persistent
private boolean status;
//Fecha de creacion del recurso
@Persistent
private String created;
//Fecha de creacion del recurso
@Persistent
private String created;
//Constructor
public Resource(String url,boolean status){
//Constructor
public Resource(String url,boolean status){
this.Url=url;
this.status=status;
DateFormat df = new SimpleDateFormat("HH:mm:ss dd/MM/yy");
created = df.format(Calendar.getInstance().getTime());
}
}
public String getKey() {
public String getKey() {
return KeyFactory.keyToString(key);
}
public void setUrl(String url){
}
public void setUrl(String url){
this.Url=url;
}
public String getUrl(){
}
public String getUrl(){
return this.Url;
}
public void setStatus(boolean status){
}
public void setStatus(boolean status){
this.status=status;
}
public boolean getStatus(){
}
public boolean getStatus(){
return this.status;
}
public String getCreateDate(){
return created;
}
public String toString(){
return "Recurso url: " + Url +"\n";
}

View File

@ -76,10 +76,10 @@
</div>
<ul id="nav-mobile" class="right">
<li class="active"><a class="whiteLink" href="">Users</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('./resources')">Resources</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('../access')">Access</a></li>
<li class="active"><a class="whiteLink" onclick="postRedirect('../resources')">Resources</a></li>
</ul>
</div>
</nav>
@ -94,7 +94,7 @@
<input name="action" value="create" type="hidden">
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 />
<select name="status" class="browser-default" required>
<option value="" disabled selected>Choose a status</option>

View File

@ -88,7 +88,7 @@
<div class="container">
<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 />
@ -102,14 +102,15 @@
<td>URL</td>
<td>Status</td>
<td>Date created</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<% for (int i = 0; i < recourseList.size(); i++) {%>
<% Recourse recourse = recourseList.get(i); %>
<% String key = recourse.getKey();
<% for (int i = 0; i < resourceList.size(); i++) {%>
<% Resource resource = resourceList.get(i); %>
<% String key = resource.getKey();
String[] arr = key.split("");
key = "";
for (String a : arr) {
@ -121,13 +122,13 @@
}
%>
<tr>
<td><%= recourse.getName()%></td>
<td><%= recourse.getStatus()%></td>
<td><%= recourse.getCreateDate()%></td>
<td><%= resource.getUrl()%></td>
<td><%= resource.getStatus()%></td>
<td><%= resource.getCreateDate()%></td>
<td>
<a class="postLink" onclick="postRedirect('recourses/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('recourses/delete',{key:'<%=key%>'})">Delete</a></td>
<a class="postLink" onclick="postRedirect('resources/view',{action:'viewRedirect',key:'<%=key%>'})">View</a>
| <a class="postLink" onclick="postRedirect('resources/view',{action:'editRedirect',key:'<%=key%>'})">Edit</a>
| <a class="postLink" onclick="postRedirect('resources/delete',{key:'<%=key%>'})">Delete</a></td>
</tr>
<% } %>

View File

@ -7,7 +7,7 @@
Time: 16:39
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");
boolean editAllowed = (Boolean) request.getAttribute("editAllowed");
String action = (String) request.getAttribute("action");
@ -89,7 +89,7 @@
<div class="container">
<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 />
@ -100,8 +100,8 @@
<input name="key" value="<%=resource.getKey()%>" type="hidden">
<input name="action" value="update" type="hidden">
Name:<br />
<input name="url" value="<%=resource.getName()%>" placeholder="url" required><br/>
Url:<br />
<input name="url" value="<%=resource.getUrl()%>" placeholder="url" required><br/>
<br/>
Status:<br />
<select name="status" class="browser-default" required>
@ -122,7 +122,7 @@
<div style="font-size: x-large">
Url: <%=resource.getUrl()%><br />
Email: <%=resource.getStatus()%><br />
Status: <%=resource.getStatus()%><br />
</div>

View File

@ -59,9 +59,9 @@
<br />
<hr />
Developed by:<br />
Fernando Araoz, 2017337<br />
Jose Rodriguez, <br />
Gustavo Turpo, <br />
Fernando Araoz, 20173373<br />
Jose Rodriguez, 20101650<br />
Gustavo Turpo, 20173374<br />
</div>