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
7fe077dc
Commit
7fe077dc
authored
Oct 24, 2025
by
Breixo Senra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Plantillas de JSF funcionando
parent
4190697b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
208 additions
and
62 deletions
+208
-62
PetDetailsManagedBean.java
...ain/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
+35
-0
PetManagedBean.java
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
+9
-9
VetManagedBean.java
jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java
+6
-2
petDetails.xhtml
jsf/src/main/webapp/vet/petDetails.xhtml
+43
-0
supervisedPets.xhtml
jsf/src/main/webapp/vet/supervisedPets.xhtml
+48
-0
vaccines.xhtml
jsf/src/main/webapp/vet/vaccines.xhtml
+41
-32
VetResource.java
rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java
+10
-10
PetService.java
...e/src/main/java/es/uvigo/esei/xcs/service/PetService.java
+3
-3
VaccineService.java
...c/main/java/es/uvigo/esei/xcs/service/VaccineService.java
+2
-0
VetService.java
...e/src/main/java/es/uvigo/esei/xcs/service/VetService.java
+11
-6
No files found.
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java
0 → 100644
View file @
7fe077dc
package
es
.
uvigo
.
esei
.
xcs
.
jsf
;
import
javax.annotation.PostConstruct
;
import
javax.enterprise.context.RequestScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
javax.faces.context.FacesContext
;
import
java.util.Map
;
import
es.uvigo.esei.xcs.domain.entities.Pet
;
import
es.uvigo.esei.xcs.service.PetService
;
@Named
(
"petDetails"
)
@RequestScoped
public
class
PetDetailsManagedBean
{
@Inject
private
PetService
service
;
private
Pet
pet
;
@PostConstruct
public
void
init
()
{
Map
<
String
,
String
>
params
=
FacesContext
.
getCurrentInstance
()
.
getExternalContext
()
.
getRequestParameterMap
();
String
id
=
params
.
get
(
"id"
);
if
(
id
!=
null
)
{
this
.
pet
=
service
.
get
(
Long
.
parseLong
(
id
));
}
}
public
Pet
getPet
()
{
return
pet
;
}
}
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
View file @
7fe077dc
...
@@ -16,14 +16,14 @@ import es.uvigo.esei.xcs.service.PetService;
...
@@ -16,14 +16,14 @@ import es.uvigo.esei.xcs.service.PetService;
@Named
(
"pet"
)
@Named
(
"pet"
)
@RequestScoped
@RequestScoped
public
class
PetManagedBean
{
public
class
PetManagedBean
{
/*
@Inject
@Inject
private
PetService
service
;
private
PetService
service
;
private
String
name
;
private
String
name
;
private
Date
birth
;
private
Date
birth
;
private
AnimalType
animal
;
private
AnimalType
animal
;
private
Integer
id;
private
Long
id
;
private
String
errorMessage
;
private
String
errorMessage
;
...
@@ -65,19 +65,19 @@ public class PetManagedBean {
...
@@ -65,19 +65,19 @@ public class PetManagedBean {
return
this
.
id
!=
null
;
return
this
.
id
!=
null
;
}
}
public
Integer
getId() {
public
Long
getId
()
{
return
id
;
return
id
;
}
}
public void setId(
Integer
id) {
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
this
.
id
=
id
;
}
}
public
List
<
Pet
>
getPets
()
{
public
List
<
Pet
>
getPets
()
{
return this.service.list();
return
this
.
service
.
list
(
0
,
100
);
}
}
public String edit(
int
petId) {
public
String
edit
(
Long
petId
)
{
final
Pet
pet
=
this
.
service
.
get
(
petId
);
final
Pet
pet
=
this
.
service
.
get
(
petId
);
this
.
id
=
pet
.
getId
();
this
.
id
=
pet
.
getId
();
...
@@ -94,7 +94,7 @@ public class PetManagedBean {
...
@@ -94,7 +94,7 @@ public class PetManagedBean {
return
this
.
getViewId
();
return
this
.
getViewId
();
}
}
public String remove(
int
id) {
public
String
remove
(
Long
id
)
{
this
.
service
.
remove
(
id
);
this
.
service
.
remove
(
id
);
return
redirectTo
(
this
.
getViewId
());
return
redirectTo
(
this
.
getViewId
());
...
@@ -110,7 +110,7 @@ public class PetManagedBean {
...
@@ -110,7 +110,7 @@ public class PetManagedBean {
this
.
service
.
update
(
pet
);
this
.
service
.
update
(
pet
);
}
else
{
}
else
{
this.service.create(new Pet(name, animal, birth));
//
this.service.create(new Pet(name, animal, birth));
}
}
this
.
clear
();
this
.
clear
();
...
@@ -137,5 +137,5 @@ public class PetManagedBean {
...
@@ -137,5 +137,5 @@ public class PetManagedBean {
private
String
getViewId
()
{
private
String
getViewId
()
{
return
FacesContext
.
getCurrentInstance
().
getViewRoot
().
getViewId
();
return
FacesContext
.
getCurrentInstance
().
getViewRoot
().
getViewId
();
}
*/
}
}
}
jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java
View file @
7fe077dc
...
@@ -61,9 +61,13 @@ public class VetManagedBean {
...
@@ -61,9 +61,13 @@ public class VetManagedBean {
public
List
<
Vet
>
getVets
()
{
public
List
<
Vet
>
getVets
()
{
return
this
.
service
.
list
();
return
this
.
service
.
list
();
}
}
public
List
<
Pet
>
getPets
()
{
return
this
.
service
.
getPets
(
0
,
100
);
}
public
String
getPetNames
(
String
login
)
{
public
String
getPetNames
()
{
return
this
.
service
.
getPets
(
login
,
0
,
100
).
stream
()
return
this
.
service
.
getPets
(
0
,
100
).
stream
()
.
map
(
Pet:
:
getName
)
.
map
(
Pet:
:
getName
)
.
collect
(
joining
(
", "
));
.
collect
(
joining
(
", "
));
}
}
...
...
jsf/src/main/webapp/vet/petDetails.xhtml
0 → 100644
View file @
7fe077dc
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<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:ui=
"http://xmlns.jcp.org/jsf/facelets"
>
<h:head>
<title>
Detalle de Mascota
</title>
</h:head>
<h:body>
<ui:composition
template=
"../WEB-INF/template.xhtml"
>
<ui:define
name=
"content"
>
<h2>
Detalles de Mascota
</h2>
<h:panelGrid
columns=
"2"
>
<h:outputText
value=
"ID:"
/>
<h:outputText
value=
"#{petDetails.pet.id}"
/>
<h:outputText
value=
"Nombre:"
/>
<h:outputText
value=
"#{petDetails.pet.name}"
/>
<h:outputText
value=
"Animal:"
/>
<h:outputText
value=
"#{petDetails.pet.animal}"
/>
<h:outputText
value=
"Fecha de Nacimiento:"
/>
<h:outputText
value=
"#{petDetails.pet.birth}"
/>
</h:panelGrid>
<h3>
Vacunas
</h3>
<h:dataTable
value=
"#{petDetails.pet.vaccinations}"
var=
"v"
>
<h:column>
<f:facet
name=
"header"
>
Fecha
</f:facet>
#{v.date}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Vacuna
</f:facet>
#{v.vaccine.name}
</h:column>
</h:dataTable>
</ui:define>
</ui:composition>
</h:body>
</html>
jsf/src/main/webapp/vet/supervisedPets.xhtml
0 → 100644
View file @
7fe077dc
<?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"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
>
<head>
<title>
Vet - Pets Supervised
</title>
</head>
<body>
<ui:composition
template=
"../WEB-INF/template.xhtml"
>
<ui:define
name=
"jumbotron"
>
<h2>
Mascotas Supervisadas
</h2>
<p>
Listado de las mascotas que supervisas (nombre y tipo de animal).
</p>
</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"
>
<f:param
name=
"id"
value=
"#{supervisedPet.id}"
/>
</h:link>
</h:column>
</h:dataTable>
<h:panelGroup
class=
"alert alert-danger"
role=
"alert"
rendered=
"#{vet.error}"
>
<span
class=
"glyphicon glyphicon-exclamation-sign"
aria-hidden=
"true"
></span>
Error: #{vet.errorMessage}
</h:panelGroup>
</ui:define>
</ui:composition>
</body>
</html>
jsf/src/main/webapp/vet/vaccines.xhtml
View file @
7fe077dc
...
@@ -16,21 +16,20 @@
...
@@ -16,21 +16,20 @@
<h:column><f:facet
name=
"header"
>
ID
</f:facet>
#{v.id}
</h:column>
<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"
>
Nombre
</f:facet>
#{v.name}
</h:column>
<h:column><f:facet
name=
"header"
>
Tipo
</f:facet>
#{v.class.simpleName}
</h:column>
<h:column><f:facet
name=
"header"
>
Tipo
</f:facet>
#{v.class.simpleName}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Doses
</f:facet>
#{v.class.simpleName eq 'MultidoseVaccine' ? v.doses : ''}
</h:column>
<h:column
rendered=
"#{v.class.simpleName eq 'MultidoseVaccine'}"
>
<h:column>
<f:facet
name=
"header"
>
Doses
</f:facet>
<f:facet
name=
"header"
>
Periode
</f:facet>
#{v.doses}
#{v.class.simpleName eq 'PeriodicVaccine' ? v.periode : ''}
</h:column>
</h:column>
<h:column
rendered=
"#{v.class.simpleName eq 'PeriodicVaccine'}"
>
<f:facet
name=
"header"
>
Periode
</f:facet>
#{v.periode}
</h:column>
<h:column
rendered=
"#{v.class.simpleName eq 'PeriodicVaccine'}"
>
<h:column
>
<f:facet
name=
"header"
>
Periodic
Type
</f:facet>
<f:facet
name=
"header"
>
Periodic
Type
</f:facet>
#{v.periodicType
}
#{v.class.simpleName eq 'PeriodicVaccine' ? v.periodicType : ''
}
</h:column>
</h:column>
<h:column>
<h:column>
<f:facet
name=
"header"
>
Acciones
</f:facet>
<f:facet
name=
"header"
>
Acciones
</f:facet>
...
@@ -61,30 +60,40 @@
...
@@ -61,30 +60,40 @@
</h:selectOneMenu>
</h:selectOneMenu>
<!-- Doses solo si MULTIDOSE -->
<!-- Doses solo si MULTIDOSE -->
<h:outputLabel
value=
"Doses:"
for=
"doses"
rendered=
"#{vaccine.type eq 'MULTIDOSE'}"
/>
<
!--<
h:outputLabel value="Doses:" for="doses" rendered="#{vaccine.type eq 'MULTIDOSE'}"/>
<h:inputText id="doses" value="#{vaccine.doses}"
<h:inputText id="doses" value="#{vaccine.doses}"
rendered="#{vaccine.type eq 'MULTIDOSE'}"
rendered="#{vaccine.type eq 'MULTIDOSE'}"
required="#{vaccine.type eq 'MULTIDOSE'}"
required="#{vaccine.type eq 'MULTIDOSE'}"
validatorMessage="Las dosis deben ser mayores a 0">
validatorMessage="Las dosis deben ser mayores a 0">
<f:validateLongRange minimum="1"/>
<f:validateLongRange minimum="1"/>
</h:inputText>
</h:inputText>-->
<!-- Periode y PeriodicType solo si PERIODIC -->
<h:outputLabel
value=
"Periode:"
for=
"periode"
rendered=
"#{vaccine.type eq 'PERIODIC'}"
/>
<h:outputLabel
value=
"Doses:"
for=
"doses"
<h:inputText
id=
"periode"
value=
"#{vaccine.periode}"
style=
"display:#{vaccine.type eq 'MULTIDOSE' ? 'inline' : 'none'}"
/>
rendered=
"#{vaccine.type eq 'PERIODIC'}"
<h:inputText
id=
"doses"
value=
"#{vaccine.doses}"
required=
"#{vaccine.type eq 'MULTIDOSE'}"
required=
"#{vaccine.type eq 'PERIODIC'}"
style=
"display:#{vaccine.type eq 'MULTIDOSE' ? 'inline' : 'none'}"
>
validatorMessage=
"El periodo debe ser mayor a 0"
>
<f:validateLongRange
minimum=
"1"
/>
<f:validateLongRange
minimum=
"1"
/>
</h:inputText>
</h:inputText>
<h:outputLabel
value=
"Periodic Type:"
for=
"periodicType"
rendered=
"#{vaccine.type eq 'PERIODIC'}"
/>
<h:outputLabel
value=
"Periode:"
for=
"periode"
<h:selectOneMenu
id=
"periodicType"
value=
"#{vaccine.periodicType}"
style=
"display:#{vaccine.type eq 'PERIODIC' ? 'inline' : 'none'}"
/>
rendered=
"#{vaccine.type eq 'PERIODIC'}"
>
<h:inputText
id=
"periode"
value=
"#{vaccine.periode}"
required=
"#{vaccine.type eq 'PERIODIC'}"
<f:selectItem
itemLabel=
"DAYS"
itemValue=
"DAYS"
/>
style=
"display:#{vaccine.type eq 'PERIODIC' ? 'inline' : 'none'}"
>
<f:selectItem
itemLabel=
"MONTHS"
itemValue=
"MONTHS"
/>
<f:validateLongRange
minimum=
"1"
/>
<f:selectItem
itemLabel=
"YEARS"
itemValue=
"YEARS"
/>
</h:inputText>
</h:selectOneMenu>
<h:outputLabel
value=
"Periodic Type:"
for=
"periodicType"
style=
"display:#{vaccine.type eq 'PERIODIC' ? 'inline' : 'none'}"
/>
<h:selectOneMenu
id=
"periodicType"
value=
"#{vaccine.periodicType}"
style=
"display:#{vaccine.type eq 'PERIODIC' ? 'inline' : 'none'}"
>
<f:selectItem
itemLabel=
"DAYS"
itemValue=
"DAYS"
/>
<f:selectItem
itemLabel=
"MONTHS"
itemValue=
"MONTHS"
/>
<f:selectItem
itemLabel=
"YEARS"
itemValue=
"YEARS"
/>
</h:selectOneMenu>
</h:panelGrid>
</h:panelGrid>
<br/>
<br/>
...
...
rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java
View file @
7fe077dc
...
@@ -98,15 +98,15 @@ public class VetResource {
...
@@ -98,15 +98,15 @@ public class VetResource {
}
}
@GET
@GET
@Path
(
"
{login}/
pet"
)
@Path
(
"pet"
)
public
Response
listPets
(
public
Response
listPets
(
@PathParam
(
"login"
)
String
login
,
//
@PathParam("login") String login,
@QueryParam
(
"page"
)
@DefaultValue
(
"0"
)
int
page
,
@QueryParam
(
"page"
)
@DefaultValue
(
"0"
)
int
page
,
@QueryParam
(
"pageSize"
)
@DefaultValue
(
"10"
)
int
pageSize
@QueryParam
(
"pageSize"
)
@DefaultValue
(
"10"
)
int
pageSize
)
{
)
{
requireNonNull
(
login
,
"login can't be null"
);
//
requireNonNull(login, "login can't be null");
return
Response
.
ok
(
this
.
vetService
.
getPets
(
login
,
page
,
pageSize
)).
build
();
return
Response
.
ok
(
this
.
vetService
.
getPets
(
page
,
pageSize
)).
build
();
}
}
...
@@ -155,7 +155,7 @@ public class VetResource {
...
@@ -155,7 +155,7 @@ public class VetResource {
}
}
}
}
@Path
(
"
{login}/
pet/{petIdentifierType}/{petIdentifierValue}/vaccination"
)
@Path
(
"pet/{petIdentifierType}/{petIdentifierValue}/vaccination"
)
@GET
@GET
public
Response
listVaccinations
(
public
Response
listVaccinations
(
@PathParam
(
"login"
)
String
login
,
@PathParam
(
"login"
)
String
login
,
...
@@ -167,7 +167,7 @@ public class VetResource {
...
@@ -167,7 +167,7 @@ public class VetResource {
requireNonNull
(
login
,
"login can't be null"
);
requireNonNull
(
login
,
"login can't be null"
);
return
Response
.
ok
(
this
.
vetService
.
getVaccinationsFromOwnPet
(
return
Response
.
ok
(
this
.
vetService
.
getVaccinationsFromOwnPet
(
login
,
//
login,
petIdentifierType
,
petIdentifierType
,
petIdentifierValue
,
petIdentifierValue
,
page
,
page
,
...
@@ -218,16 +218,16 @@ public class VetResource {
...
@@ -218,16 +218,16 @@ public class VetResource {
@DELETE
@DELETE
@Path
(
"{login}/unassign/pet/{petId}"
)
@Path
(
"{login}/unassign/pet/{petId}"
)
public
Response
unassignVetFromPet
(
public
Response
unassignVetFromPet
(
@PathParam
(
"login"
)
String
vetLogin
,
//
@PathParam("login") String vetLogin,
@PathParam
(
"petId"
)
Long
petId
@PathParam
(
"petId"
)
Long
petId
)
{
)
{
requireNonNull
(
vetLogin
,
"vetLogin can't be null"
);
//
requireNonNull(vetLogin, "vetLogin can't be null");
requireNonNull
(
petId
,
"petId can't be null"
);
requireNonNull
(
petId
,
"petId can't be null"
);
try
{
try
{
petService
.
unassignVetFromPet
(
petId
,
vetLogin
);
petService
.
unassignVetFromPet
(
petId
);
return
Response
.
ok
()
return
Response
.
ok
()
.
entity
(
"Vet "
+
vetLogin
+
" unassigned from pet "
+
petId
)
//
.entity("Vet " + vetLogin + " unassigned from pet " + petId)
.
build
();
.
build
();
}
catch
(
IllegalArgumentException
e
)
{
}
catch
(
IllegalArgumentException
e
)
{
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
...
...
service/src/main/java/es/uvigo/esei/xcs/service/PetService.java
View file @
7fe077dc
...
@@ -175,15 +175,15 @@ public class PetService {
...
@@ -175,15 +175,15 @@ public class PetService {
}
}
public
void
unassignVetFromPet
(
Long
petId
,
String
vetLogin
)
{
public
void
unassignVetFromPet
(
Long
petId
)
{
requireNonNull
(
petId
,
"Pet ID can't be null"
);
requireNonNull
(
petId
,
"Pet ID can't be null"
);
requireNonNull
(
vetLogin
,
"Vet login can't be null"
);
//
requireNonNull(vetLogin, "Vet login can't be null");
Pet
pet
=
em
.
find
(
Pet
.
class
,
petId
);
Pet
pet
=
em
.
find
(
Pet
.
class
,
petId
);
if
(
pet
==
null
)
if
(
pet
==
null
)
throw
new
IllegalArgumentException
(
"Pet not found"
);
throw
new
IllegalArgumentException
(
"Pet not found"
);
Vet
vet
=
em
.
find
(
Vet
.
class
,
vetLogin
);
Vet
vet
=
em
.
find
(
Vet
.
class
,
currentUser
.
getName
()
);
if
(
vet
==
null
)
if
(
vet
==
null
)
throw
new
IllegalArgumentException
(
"Vet not found"
);
throw
new
IllegalArgumentException
(
"Vet not found"
);
...
...
service/src/main/java/es/uvigo/esei/xcs/service/VaccineService.java
View file @
7fe077dc
...
@@ -5,6 +5,7 @@ package es.uvigo.esei.xcs.service;
...
@@ -5,6 +5,7 @@ package es.uvigo.esei.xcs.service;
import
java.util.List
;
import
java.util.List
;
import
javax.annotation.security.PermitAll
;
import
javax.annotation.security.PermitAll
;
import
javax.annotation.security.RolesAllowed
;
import
javax.ejb.Stateless
;
import
javax.ejb.Stateless
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.PersistenceContext
;
...
@@ -18,6 +19,7 @@ import es.uvigo.esei.xcs.domain.entities.Vaccine;
...
@@ -18,6 +19,7 @@ import es.uvigo.esei.xcs.domain.entities.Vaccine;
@Stateless
@Stateless
@PermitAll
@PermitAll
//@RolesAllowed("VET")
public
class
VaccineService
{
public
class
VaccineService
{
@PersistenceContext
@PersistenceContext
private
EntityManager
em
;
private
EntityManager
em
;
...
...
service/src/main/java/es/uvigo/esei/xcs/service/VetService.java
View file @
7fe077dc
...
@@ -2,11 +2,13 @@ package es.uvigo.esei.xcs.service;
...
@@ -2,11 +2,13 @@ package es.uvigo.esei.xcs.service;
import
static
java
.
util
.
Objects
.
requireNonNull
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
import
java.security.Principal
;
import
java.util.List
;
import
java.util.List
;
import
javax.annotation.security.PermitAll
;
import
javax.annotation.security.PermitAll
;
import
javax.annotation.security.RolesAllowed
;
import
javax.annotation.security.RolesAllowed
;
import
javax.ejb.Stateless
;
import
javax.ejb.Stateless
;
import
javax.inject.Inject
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.PersistenceContext
;
...
@@ -19,6 +21,9 @@ import es.uvigo.esei.xcs.domain.entities.Vet;
...
@@ -19,6 +21,9 @@ import es.uvigo.esei.xcs.domain.entities.Vet;
//@RolesAllowed("VET")
//@RolesAllowed("VET")
@PermitAll
@PermitAll
public
class
VetService
{
public
class
VetService
{
@Inject
private
Principal
currentUser
;
@PersistenceContext
@PersistenceContext
EntityManager
em
;
EntityManager
em
;
...
@@ -68,8 +73,8 @@ public class VetService {
...
@@ -68,8 +73,8 @@ public class VetService {
}
}
public
List
<
Pet
>
getPets
(
String
login
,
int
page
,
int
pageSize
)
{
public
List
<
Pet
>
getPets
(
int
page
,
int
pageSize
)
{
requireNonNull
(
login
,
"Login can't be null"
);
//
requireNonNull(login, "Login can't be null");
if
(
page
<
0
)
{
if
(
page
<
0
)
{
throw
new
IllegalArgumentException
(
"The page can't be negative"
);
throw
new
IllegalArgumentException
(
"The page can't be negative"
);
}
}
...
@@ -80,18 +85,18 @@ public class VetService {
...
@@ -80,18 +85,18 @@ public class VetService {
+
"WHERE v.login = :login"
,
Pet
.
class
)
+
"WHERE v.login = :login"
,
Pet
.
class
)
.
setFirstResult
(
page
*
pageSize
)
.
setFirstResult
(
page
*
pageSize
)
.
setMaxResults
(
pageSize
)
.
setMaxResults
(
pageSize
)
.
setParameter
(
"login"
,
login
)
.
setParameter
(
"login"
,
currentUser
.
getName
()
)
.
getResultList
();
.
getResultList
();
}
}
public
List
<
Vaccination
>
getVaccinationsFromOwnPet
(
public
List
<
Vaccination
>
getVaccinationsFromOwnPet
(
String
login
,
//
String login,
IdentifierType
identifierType
,
IdentifierType
identifierType
,
String
identifierValue
,
String
identifierValue
,
int
page
,
int
page
,
int
pageSize
int
pageSize
){
){
requireNonNull
(
login
,
"login can't be null"
);
//
requireNonNull(login, "login can't be null");
requireNonNull
(
identifierType
,
"pet's identifier type can't be null"
);
requireNonNull
(
identifierType
,
"pet's identifier type can't be null"
);
requireNonNull
(
identifierValue
,
"pet's identifier value can't be null"
);
requireNonNull
(
identifierValue
,
"pet's identifier value can't be null"
);
if
(
page
<
0
)
{
if
(
page
<
0
)
{
...
@@ -110,7 +115,7 @@ public class VetService {
...
@@ -110,7 +115,7 @@ public class VetService {
+
"i.identifierType = :identifierType AND "
+
"i.identifierType = :identifierType AND "
+
"i.identifierValue = :identifierValue"
,
+
"i.identifierValue = :identifierValue"
,
Vaccination
.
class
)
Vaccination
.
class
)
.
setParameter
(
"login"
,
login
)
.
setParameter
(
"login"
,
currentUser
.
getName
()
)
.
setParameter
(
"identifierType"
,
identifierType
)
.
setParameter
(
"identifierType"
,
identifierType
)
.
setParameter
(
"identifierValue"
,
identifierValue
)
.
setParameter
(
"identifierValue"
,
identifierValue
)
.
setFirstResult
(
page
*
pageSize
)
.
setFirstResult
(
page
*
pageSize
)
...
...
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