Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bspastoriza19-esi-solutions
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Breixo Senra Pastoriza
bspastoriza19-esi-solutions
Commits
a92ee916
Commit
a92ee916
authored
Oct 26, 2025
by
Breixo Senra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restricciones de URL /vet a users VET
parent
c8ba5a32
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
246 additions
and
169 deletions
+246
-169
OwnerManagedBean.java
...src/main/java/es/uvigo/esei/xcs/jsf/OwnerManagedBean.java
+4
-4
PetDetailsManagedBean.java
...ain/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
+0
-2
VetManagedBean.java
jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java
+37
-5
web.xml
jsf/src/main/webapp/WEB-INF/web.xml
+18
-0
owners.xhtml
jsf/src/main/webapp/admin/owners.xhtml
+1
-1
petDetails.xhtml
jsf/src/main/webapp/vet/petDetails.xhtml
+16
-6
pets.xhtml
jsf/src/main/webapp/vet/pets.xhtml
+23
-14
supervisedPets.xhtml
jsf/src/main/webapp/vet/supervisedPets.xhtml
+11
-21
vaccines.xhtml
jsf/src/main/webapp/vet/vaccines.xhtml
+100
-96
OwnerService.java
...src/main/java/es/uvigo/esei/xcs/service/OwnerService.java
+16
-9
PetService.java
...e/src/main/java/es/uvigo/esei/xcs/service/PetService.java
+1
-3
VaccinationService.java
...in/java/es/uvigo/esei/xcs/service/VaccinationService.java
+5
-0
VetService.java
...e/src/main/java/es/uvigo/esei/xcs/service/VetService.java
+14
-8
No files found.
jsf/src/main/java/es/uvigo/esei/xcs/jsf/OwnerManagedBean.java
View file @
a92ee916
...
...
@@ -16,7 +16,7 @@ import es.uvigo.esei.xcs.service.OwnerService;
@Named
(
"owner"
)
@RequestScoped
public
class
OwnerManagedBean
{
/*
@Inject
@Inject
private
OwnerService
service
;
private
String
login
;
...
...
@@ -59,11 +59,11 @@ public class OwnerManagedBean {
}
public
List
<
Owner
>
getOwners
()
{
return this.service.list();
return
this
.
service
.
list
(
0
,
100
);
}
public
String
getPetNames
(
String
login
)
{
return this.service.getPets(
login
).stream()
return
this
.
service
.
getPets
(
0
,
100
).
stream
()
.
map
(
Pet:
:
getName
)
.
collect
(
joining
(
", "
));
}
...
...
@@ -121,5 +121,5 @@ public class OwnerManagedBean {
private
String
getViewId
()
{
return
FacesContext
.
getCurrentInstance
().
getViewRoot
().
getViewId
();
}
*/
}
}
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
View file @
a92ee916
...
...
@@ -38,8 +38,6 @@ public class PetDetailsManagedBean implements Serializable{
@Inject
private
VaccinationService
vaccinationService
;
@Inject
private
EmailService
emailService
;
private
Pet
pet
;
...
...
jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java
View file @
a92ee916
...
...
@@ -2,20 +2,30 @@ package es.uvigo.esei.xcs.jsf;
import
static
java
.
util
.
stream
.
Collectors
.
joining
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.Map
;
import
javax.annotation.PostConstruct
;
import
javax.enterprise.context.RequestScoped
;
import
javax.faces.context.FacesContext
;
import
javax.faces.view.ViewScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
org.primefaces.model.FilterMeta
;
import
org.primefaces.model.LazyDataModel
;
import
org.primefaces.model.SortMeta
;
import
es.uvigo.esei.xcs.domain.entities.Pet
;
import
es.uvigo.esei.xcs.domain.entities.Vet
;
import
es.uvigo.esei.xcs.service.VetService
;
@Named
(
"vet"
)
@RequestScoped
public
class
VetManagedBean
{
//@RequestScoped
@ViewScoped
public
class
VetManagedBean
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Inject
private
VetService
service
;
...
...
@@ -26,6 +36,28 @@ public class VetManagedBean {
private
boolean
editing
;
private
String
errorMessage
;
private
LazyDataModel
<
Pet
>
pets
;
@PostConstruct
public
void
init
()
{
pets
=
new
LazyDataModel
<
Pet
>()
{
@Override
public
List
<
Pet
>
load
(
int
first
,
int
pageSize
,
Map
<
String
,
SortMeta
>
sortBy
,
Map
<
String
,
FilterMeta
>
filterBy
)
{
return
service
.
getPets
(
first
,
pageSize
);
}
@Override
public
int
count
(
Map
<
String
,
FilterMeta
>
filterBy
)
{
return
service
.
countPets
();
}
};
}
public
LazyDataModel
<
Pet
>
getPets
()
{
return
pets
;
}
public
String
getLogin
()
{
return
login
;
}
...
...
@@ -62,9 +94,9 @@ public class VetManagedBean {
return
this
.
service
.
list
();
}
public
List
<
Pet
>
getPets
()
{
/*
public List<Pet> getPets() {
return this.service.getPets(0, 100);
}
}
*/
public
String
getPetNames
()
{
return
this
.
service
.
getPets
(
0
,
100
).
stream
()
...
...
jsf/src/main/webapp/WEB-INF/web.xml
View file @
a92ee916
...
...
@@ -60,6 +60,20 @@
<role-name>
OWNER
</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>
vet
</web-resource-name>
<url-pattern>
/vet/*
</url-pattern>
<http-method>
POST
</http-method>
<http-method>
GET
</http-method>
<http-method>
PUT
</http-method>
<http-method>
DELETE
</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>
VET
</role-name>
</auth-constraint>
</security-constraint>
<!--Defining security constraint for type of roles available -->
<!--Denining security role -->
...
...
@@ -70,5 +84,9 @@
<security-role>
<role-name>
OWNER
</role-name>
</security-role>
<security-role>
<role-name>
VET
</role-name>
</security-role>
<!--Denining security role -->
</web-app>
\ No newline at end of file
jsf/src/main/webapp/admin/owners.xhtml
View file @
a92ee916
w
<?xml version='1.0' encoding='UTF-8' ?>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
...
...
jsf/src/main/webapp/vet/petDetails.xhtml
View file @
a92ee916
...
...
@@ -10,8 +10,10 @@
</h:head>
<h:body>
<ui:composition
template=
"../WEB-INF/template.xhtml"
>
<ui:define
name=
"jumbotron"
>
<h2>
Detalles de #{petDetails.pet.name}
</h2>
</ui:define>
<ui:define
name=
"content"
>
<h2>
Detalles de Mascota
</h2>
<h:panelGrid
columns=
"2"
>
<h:outputText
value=
"ID:"
/>
...
...
@@ -28,10 +30,22 @@
<h:outputText
value=
"Propietario:"
/>
<h:outputText
value=
"#{petDetails.pet.owner.login}"
/>
<h4>
Identificadores
</h4>
<h:dataTable
value=
"#{petDetails.pet.identifiers}"
var=
"id"
styleClass=
"table table-striped table-bordered"
>
<h:column>
<f:facet
name=
"header"
>
Valor
</f:facet>
#{id.value}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Tipo
</f:facet>
#{id.type}
</h:column>
</h:dataTable>
</h:panelGrid>
<h3>
Vacunas
</h3>
<h:dataTable
value=
"#{petDetails.pet.vaccinations}"
var=
"v"
>
<h:dataTable
value=
"#{petDetails.pet.vaccinations}"
var=
"v"
styleClass=
"table table-striped table-bordered"
>
<h:column>
<f:facet
name=
"header"
>
Fecha
</f:facet>
#{v.date}
...
...
@@ -42,7 +56,6 @@
</h:column>
</h:dataTable>
<p:commandButton
value=
"Open Dialog"
/>
<h3>
Registrar nueva vacunación
</h3>
<h:form>
<h:messages
globalOnly=
"true"
style=
"color:red;"
/>
...
...
@@ -61,9 +74,6 @@
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
...
...
jsf/src/main/webapp/vet/pets.xhtml
View file @
a92ee916
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:p=
"http://primefaces.org/ui"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
>
<h:head>
<title>
Mis Mascotas
</title>
</h:head>
<h:body>
<h:form>
<ui:composition
template=
"../WEB-INF/template.xhtml"
>
<ui:define
name=
"jumbotron"
>
<h2>
Mascotas
</h2>
<p>
Listado de las mascotas
</p>
</ui:define>
<ui:define
name=
"content"
>
<!--NUEVA TABLA-->
<p:dataTable
value=
"#{pet.pets}"
var=
"p"
paginator=
"true"
rows=
"10"
lazy=
"true"
>
<p:column
headerText=
"Nombre"
>
#{p.name}
</p:column>
...
...
@@ -20,6 +27,8 @@
<h:messages
globalOnly=
"true"
/>
</ui:define>
</ui:composition>
</h:form>
</h:body>
</html>
jsf/src/main/webapp/vet/supervisedPets.xhtml
View file @
a92ee916
...
...
@@ -3,6 +3,7 @@
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:p=
"http://primefaces.org/ui"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
>
<head>
...
...
@@ -16,27 +17,16 @@
</ui:define>
<ui:define
name=
"content"
>
<h:dataTable
value=
"#{vet.pets}"
var=
"supervisedPet"
styleClass=
"table table-striped table-bordered"
>
<h:column>
<f:facet
name=
"header"
>
ID
</f:facet>
#{supervisedPet.id}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Nombre
</f:facet>
#{supervisedPet.name}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Tipo de Animal
</f:facet>
#{supervisedPet.animal}
</h:column>
<!--Añadidos los links-->
<h:column>
<f:facet
name=
"header"
>
Acciones
</f:facet>
<h:link
value=
"Ver Detalles"
outcome=
"petDetails.xhtml"
>
<p:dataTable
value=
"#{vet.pets}"
var=
"supervisedPet"
paginator=
"true"
rows=
"10"
lazy=
"true"
>
<p:column
headerText=
"ID"
>
#{supervisedPet.id}
</p:column>
<p:column
headerText=
"Nombre"
>
#{supervisedPet.name}
</p:column>
<p:column
headerText=
"Tipo de Animal"
>
#{supervisedPet.animal}
</p:column>
<p:column
headerText=
"Acciones"
>
<h:link
value=
"Ver Detalles"
outcome=
"petDetails"
>
<f:param
name=
"id"
value=
"#{supervisedPet.id}"
/>
</h:link>
</h
:column>
</h
:dataTable>
</p
:column>
</p
:dataTable>
<h:panelGroup
class=
"alert alert-danger"
role=
"alert"
rendered=
"#{vet.error}"
>
<span
class=
"glyphicon glyphicon-exclamation-sign"
aria-hidden=
"true"
></span>
...
...
jsf/src/main/webapp/vet/vaccines.xhtml
View file @
a92ee916
...
...
@@ -9,10 +9,13 @@
</h:head>
<h:body>
<h2>
CRUD de Vacunas
</h2>
<ui:composition
template=
"../WEB-INF/template.xhtml"
>
<ui:define
name=
"jumbotron"
>
<h2>
Gestión de Vacunas
</h2>
</ui:define>
<ui:define
name=
"content"
>
<!-- Tabla de vacunas -->
<h:dataTable
value=
"#{vaccine.vaccines}"
var=
"v"
border=
"1
"
>
<h:dataTable
value=
"#{vaccine.vaccines}"
var=
"v"
border=
"1"
styleClass=
"table table-striped table-bordered
"
>
<h:column><f:facet
name=
"header"
>
ID
</f:facet>
#{v.id}
</h:column>
<h:column><f:facet
name=
"header"
>
Nombre
</f:facet>
#{v.name}
</h:column>
<h:column><f:facet
name=
"header"
>
Tipo
</f:facet>
#{v.class.simpleName}
</h:column>
...
...
@@ -105,6 +108,7 @@
<h:commandButton
value=
"Guardar cambios"
action=
"#{vaccine.editVaccine}"
/>
<h:commandButton
value=
"Cancelar"
action=
"#{vaccine.setSelectedVaccine(null)}"
immediate=
"true"
/>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
service/src/main/java/es/uvigo/esei/xcs/service/OwnerService.java
View file @
a92ee916
...
...
@@ -2,9 +2,13 @@ package es.uvigo.esei.xcs.service;
import
static
java
.
util
.
Objects
.
requireNonNull
;
import
java.security.Principal
;
import
java.util.List
;
import
javax.annotation.security.PermitAll
;
import
javax.annotation.security.RolesAllowed
;
import
javax.ejb.Stateless
;
import
javax.inject.Inject
;
import
javax.persistence.EntityExistsException
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
...
...
@@ -21,11 +25,16 @@ import es.uvigo.esei.xcs.domain.entities.Vaccination;
* @author Miguel Reboiro Jato
*/
@Stateless
@RolesAllowed
(
"ADMIN"
)
//@RolesAllowed("ADMIN")
@PermitAll
public
class
OwnerService
{
@PersistenceContext
private
EntityManager
em
;
@Inject
private
Principal
currentUser
;
/**
* Returns the owner identified by {@code login}. If there is no owner with
* the specified login, {@code null} will be returned.
...
...
@@ -131,20 +140,18 @@ public class OwnerService {
* @throws IllegalArgumentException if {@code login} is {@code null} or it
* does not identifies a valid owner.
*/
public
List
<
Pet
>
getPets
(
String
login
,
int
page
,
int
pageSize
)
{
if
(
page
<
0
)
{
throw
new
IllegalArgumentException
(
"The page can't be negative"
);
}
if
(
pageSize
<=
0
)
{
throw
new
IllegalArgumentException
(
"The page size can't be negative or zero"
);
}
public
List
<
Pet
>
getPets
(
int
first
,
int
pageSize
)
{
if
(
first
<
0
)
throw
new
IllegalArgumentException
(
"First can't be negative"
);
if
(
pageSize
<=
0
)
throw
new
IllegalArgumentException
(
"Page size must be positive"
);
return
em
.
createQuery
(
"SELECT p FROM Owner o "
+
"JOIN o.pets p "
+
"WHERE "
+
"o.login = :login"
,
Pet
.
class
)
.
setFirstResult
(
page
*
pageSize
)
.
setFirstResult
(
first
)
.
setMaxResults
(
pageSize
)
.
setParameter
(
"login"
,
currentUser
.
getName
())
.
getResultList
();
}
...
...
service/src/main/java/es/uvigo/esei/xcs/service/PetService.java
View file @
a92ee916
...
...
@@ -17,6 +17,7 @@ import javax.persistence.PersistenceContext;
import
es.uvigo.esei.xcs.domain.entities.Owner
;
import
es.uvigo.esei.xcs.domain.entities.Pet
;
import
es.uvigo.esei.xcs.domain.entities.Vaccination
;
import
es.uvigo.esei.xcs.domain.entities.Vaccine
;
import
es.uvigo.esei.xcs.domain.entities.Vet
;
...
...
@@ -176,8 +177,6 @@ public class PetService {
em
.
remove
(
pet
);
}
public
List
<
Vaccine
>
getVaccinesByPetId
(
Long
id
,
int
page
,
int
pageSize
){
if
(
page
<
0
)
{
throw
new
IllegalArgumentException
(
"The page can't be negative"
);
...
...
@@ -192,7 +191,6 @@ public class PetService {
}
public
void
assignVetToPet
(
Long
petId
)
{
requireNonNull
(
petId
,
"Pet ID can't be null"
);
//requireNonNull(vetLogin, "Vet login can't be null");
...
...
service/src/main/java/es/uvigo/esei/xcs/service/VaccinationService.java
View file @
a92ee916
...
...
@@ -3,6 +3,7 @@ package es.uvigo.esei.xcs.service;
import
java.util.Date
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
import
java.security.Principal
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.List
;
...
...
@@ -10,6 +11,7 @@ import java.util.List;
import
javax.annotation.security.PermitAll
;
import
javax.ejb.EJB
;
import
javax.ejb.Stateless
;
import
javax.inject.Inject
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
...
...
@@ -22,6 +24,9 @@ import es.uvigo.esei.xcs.domain.entities.Vaccine;
@Stateless
@PermitAll
public
class
VaccinationService
{
@Inject
private
Principal
currentUser
;
@PersistenceContext
EntityManager
em
;
...
...
service/src/main/java/es/uvigo/esei/xcs/service/VetService.java
View file @
a92ee916
...
...
@@ -27,6 +27,15 @@ public class VetService {
@PersistenceContext
EntityManager
em
;
public
int
countPets
()
{
Long
count
=
em
.
createQuery
(
"SELECT COUNT(p) FROM Vet v JOIN v.pets p WHERE v.login = :login"
,
Long
.
class
)
.
setParameter
(
"login"
,
currentUser
.
getName
())
.
getSingleResult
();
return
count
.
intValue
();
}
public
Vet
get
(
String
login
)
{
return
em
.
find
(
Vet
.
class
,
login
);
}
...
...
@@ -73,17 +82,14 @@ public class VetService {
}
public
List
<
Pet
>
getPets
(
int
page
,
int
pageSize
)
{
public
List
<
Pet
>
getPets
(
int
first
,
int
pageSize
)
{
//requireNonNull(login, "Login can't be null");
if
(
page
<
0
)
{
throw
new
IllegalArgumentException
(
"The page can't be negative"
);
}
if
(
pageSize
<=
0
)
{
throw
new
IllegalArgumentException
(
"The page size can't be negative or zero"
);
}
if
(
first
<
0
)
throw
new
IllegalArgumentException
(
"First can't be negative"
);
if
(
pageSize
<=
0
)
throw
new
IllegalArgumentException
(
"Page size must be positive"
);
return
this
.
em
.
createQuery
(
"SELECT DISTINCT p FROM Vet v JOIN v.pets p "
+
"WHERE v.login = :login"
,
Pet
.
class
)
.
setFirstResult
(
page
*
pageSize
)
.
setFirstResult
(
first
)
.
setMaxResults
(
pageSize
)
.
setParameter
(
"login"
,
currentUser
.
getName
())
.
getResultList
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment