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
f8cb9edc
Commit
f8cb9edc
authored
Oct 24, 2025
by
Breixo Senra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Asignación de mascotas funcionando
parent
7fe077dc
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
186 additions
and
30 deletions
+186
-30
Pet.java
.../src/main/java/es/uvigo/esei/xcs/domain/entities/Pet.java
+2
-2
pom.xml
jsf/pom.xml
+10
-0
PetManagedBean.java
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
+33
-1
template.xhtml
jsf/src/main/webapp/WEB-INF/template.xhtml
+1
-1
web.xml
jsf/src/main/webapp/WEB-INF/web.xml
+5
-0
index.xhtml
jsf/src/main/webapp/index.xhtml
+2
-0
pets.xhtml
jsf/src/main/webapp/vet/pets.xhtml
+32
-0
vaccines.xhtml
jsf/src/main/webapp/vet/vaccines.xhtml
+4
-14
pom.xml
pom.xml
+15
-3
pom.xml
rest/pom.xml
+14
-0
AdministratorResource.java
...in/java/es/uvigo/esei/xcs/rest/AdministratorResource.java
+12
-0
PetResource.java
rest/src/main/java/es/uvigo/esei/xcs/rest/PetResource.java
+14
-2
VetResource.java
rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java
+6
-6
EmailService.java
...src/main/java/es/uvigo/esei/xcs/service/EmailService.java
+2
-0
PetService.java
...e/src/main/java/es/uvigo/esei/xcs/service/PetService.java
+34
-1
No files found.
domain/src/main/java/es/uvigo/esei/xcs/domain/entities/Pet.java
View file @
f8cb9edc
...
...
@@ -35,7 +35,7 @@ import javax.xml.bind.annotation.XmlTransient;
@Entity
(
name
=
"Pet"
)
@XmlRootElement
(
name
=
"pet"
,
namespace
=
"http://entities.domain.xcs.esei.uvigo.es"
)
@XmlRootElement
(
name
=
"pet
t
"
,
namespace
=
"http://entities.domain.xcs.esei.uvigo.es"
)
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Pet
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -69,7 +69,7 @@ public class Pet implements Serializable {
private
Owner
owner
;
@ManyToMany
(
fetch
=
FetchType
.
LAZY
,
fetch
=
FetchType
.
LAZY
,
//es LAZY
cascade
=
{
CascadeType
.
PERSIST
,
CascadeType
.
MERGE
}
)
@JoinTable
(
...
...
jsf/pom.xml
View file @
f8cb9edc
...
...
@@ -13,6 +13,16 @@
<description>
XCS Sample - JSF
</description>
<dependencies>
<!--Componentes de PrimeFaces-->
<dependency>
<groupId>
org.primefaces
</groupId>
<artifactId>
primefaces
</artifactId>
</dependency>
<dependency>
<groupId>
org.primefaces.themes
</groupId>
<artifactId>
bootstrap
</artifactId>
</dependency>
<!-- General -->
<dependency>
<groupId>
javax
</groupId>
...
...
jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java
View file @
f8cb9edc
...
...
@@ -74,7 +74,9 @@ public class PetManagedBean {
}
public
List
<
Pet
>
getPets
()
{
return
this
.
service
.
list
(
0
,
100
);
List
<
Pet
>
list
=
this
.
service
.
getAll
(
0
,
100
);
System
.
out
.
println
(
list
);
return
list
;
}
public
String
edit
(
Long
petId
)
{
...
...
@@ -138,4 +140,34 @@ public class PetManagedBean {
private
String
getViewId
()
{
return
FacesContext
.
getCurrentInstance
().
getViewRoot
().
getViewId
();
}
public
void
assignToMe
(
Long
petId
)
{
try
{
service
.
assignVetToPet
(
petId
);
}
catch
(
Exception
e
)
{
this
.
errorMessage
=
e
.
getMessage
();
}
}
public
void
unassignFromMe
(
Long
petId
)
{
try
{
service
.
unassignVetFromPet
(
petId
);
}
catch
(
Exception
e
)
{
this
.
errorMessage
=
e
.
getMessage
();
}
}
public
boolean
isAssignedToMe
(
Pet
pet
)
{
return
this
.
service
.
isAssignedToCurrentVet
(
pet
.
getId
());
}
public
void
toggleAssignment
(
Pet
pet
)
{
if
(
isAssignedToMe
(
pet
))
{
unassignFromMe
(
pet
.
getId
());
}
else
{
assignToMe
(
pet
.
getId
());
}
}
}
jsf/src/main/webapp/WEB-INF/template.xhtml
View file @
f8cb9edc
...
...
@@ -41,7 +41,7 @@
</div>
</div>
<
h:outputScript
name=
"webjars/jquery/1.11.1/jquery.min.js"
/
>
<
!--<h:outputScript name="webjars/jquery/1.11.1/jquery.min.js" />--
>
<h:outputScript
name=
"webjars/bootstrap/3.4.1/js/bootstrap.min.js"
/>
</h:body>
</html>
\ No newline at end of file
jsf/src/main/webapp/WEB-INF/web.xml
View file @
f8cb9edc
...
...
@@ -14,6 +14,11 @@
<param-value>
Development
</param-value>
</context-param>
<context-param>
<param-name>
primefaces.THEME
</param-name>
<param-value>
bootstrap
</param-value>
</context-param>
<!-- JSF mapping -->
<servlet>
<servlet-name>
Faces Servlet
</servlet-name>
...
...
jsf/src/main/webapp/index.xhtml
View file @
f8cb9edc
...
...
@@ -4,6 +4,7 @@
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:p=
"http://primefaces.org/ui"
xmlns:a=
"http://xmlns.jcp.org/jsf/passthrough"
>
<head>
<title>
Pet Store - Index
</title>
...
...
@@ -13,6 +14,7 @@
<ui:define
name=
"jumbotron"
>
<h2>
Welcome!
</h2>
<div>
This is the Pet Store web page, where you can manage your pets. Please, login to continue.
</div>
<p:commandButton
value=
"Open Dialog"
/>
</ui:define>
</ui:composition>
</body>
...
...
jsf/src/main/webapp/vet/pets.xhtml
0 → 100644
View file @
f8cb9edc
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
>
<h:head>
<title>
Mis Mascotas
</title>
</h:head>
<h:body>
<h:form>
<h:dataTable
value=
"#{pet.pets}"
var=
"p"
border=
"1"
>
<h:column>
<f:facet
name=
"header"
>
Nombre
</f:facet>
#{p.name}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Nacimiento
</f:facet>
#{p.birth}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Tipo
</f:facet>
#{p.animal}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Acción
</f:facet>
<h:commandButton
value=
"#{pet.isAssignedToMe(p) ? 'Desasignar' : 'Asignar'}"
action=
"#{pet.toggleAssignment(p)}"
/>
</h:column>
</h:dataTable>
<h:messages
globalOnly=
"true"
/>
</h:form>
</h:body>
</html>
jsf/src/main/webapp/vet/vaccines.xhtml
View file @
f8cb9edc
...
...
@@ -56,20 +56,10 @@
<f:selectItem
itemLabel=
"MONODOSE"
itemValue=
"MONODOSE"
/>
<f:selectItem
itemLabel=
"MULTIDOSE"
itemValue=
"MULTIDOSE"
/>
<f:selectItem
itemLabel=
"PERIODIC"
itemValue=
"PERIODIC"
/>
<f:ajax
render=
"doses periode periodicType"
/>
<f:ajax
render=
"doses
-label periode-label periodic-type-label doses
periode periodicType"
/>
</h:selectOneMenu>
<!-- Doses solo si MULTIDOSE -->
<!--<h:outputLabel value="Doses:" for="doses" rendered="#{vaccine.type eq 'MULTIDOSE'}"/>
<h:inputText id="doses" value="#{vaccine.doses}"
rendered="#{vaccine.type eq 'MULTIDOSE'}"
required="#{vaccine.type eq 'MULTIDOSE'}"
validatorMessage="Las dosis deben ser mayores a 0">
<f:validateLongRange minimum="1"/>
</h:inputText>-->
<h:outputLabel
value=
"Doses:"
for=
"doses"
<h:outputLabel
id=
"doses-label"
value=
"Doses:"
for=
"doses"
style=
"display:#{vaccine.type eq 'MULTIDOSE' ? 'inline' : 'none'}"
/>
<h:inputText
id=
"doses"
value=
"#{vaccine.doses}"
required=
"#{vaccine.type eq 'MULTIDOSE'}"
style=
"display:#{vaccine.type eq 'MULTIDOSE' ? 'inline' : 'none'}"
>
...
...
@@ -77,7 +67,7 @@
</h:inputText>
<h:outputLabel
value=
"Periode:"
for=
"periode"
<h:outputLabel
id=
"periode-label"
value=
"Periode:"
for=
"periode"
style=
"display:#{vaccine.type eq 'PERIODIC' ? 'inline' : 'none'}"
/>
<h:inputText
id=
"periode"
value=
"#{vaccine.periode}"
required=
"#{vaccine.type eq 'PERIODIC'}"
style=
"display:#{vaccine.type eq 'PERIODIC' ? 'inline' : 'none'}"
>
...
...
@@ -85,7 +75,7 @@
</h:inputText>
<h:outputLabel
value=
"Periodic Type:"
for=
"periodicType"
<h:outputLabel
id=
"periodic-type-label"
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'}"
>
...
...
pom.xml
View file @
f8cb9edc
...
...
@@ -79,7 +79,17 @@
<dependencyManagement>
<dependencies>
<!--Componentes de PrimeFaces-->
<dependency>
<groupId>
org.primefaces
</groupId>
<artifactId>
primefaces
</artifactId>
<version>
13.0.10
</version>
<!-- Mejor llevar la versión a properties -->
</dependency>
<dependency>
<groupId>
org.primefaces.themes
</groupId>
<artifactId>
bootstrap
</artifactId>
<version>
1.1.0
</version>
<!-- Mejor llevar la versión a properties -->
</dependency>
...
...
@@ -744,6 +754,8 @@
=> "required", "module-options" => [("dsJndiName" => "java:jboss/datasources/xcs"),("principalsQuery" => "SELECT password FROM User WHERE
login=?"),("rolesQuery" => "SELECT role, 'Roles' FROM User WHERE login=?"),("hashAlgorithm" => "MD5"),("hashEncoding" =>
"hex"),("ignorePasswordCase" => "true")]}])
</command>
<command>
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=mail-smtp:write-attribute(name=port,value=2525)
</command>
<command>
:reload
</command>
</commands>
</configuration>
</execution>
...
...
rest/pom.xml
View file @
f8cb9edc
...
...
@@ -13,6 +13,20 @@
<description>
XCS Sample - REST
</description>
<dependencies>
<!--Componentes de PrimeFaces-->
<dependency>
<groupId>
org.primefaces
</groupId>
<artifactId>
primefaces
</artifactId>
</dependency>
<dependency>
<groupId>
org.primefaces.themes
</groupId>
<artifactId>
bootstrap
</artifactId>
</dependency>
<!-- General -->
<dependency>
<groupId>
javax
</groupId>
...
...
rest/src/main/java/es/uvigo/esei/xcs/rest/AdministratorResource.java
View file @
f8cb9edc
...
...
@@ -4,6 +4,7 @@ package es.uvigo.esei.xcs.rest;
import
javax.ejb.EJB
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.QueryParam
;
...
...
@@ -11,6 +12,7 @@ import javax.ws.rs.core.MediaType;
import
javax.ws.rs.core.Response
;
import
es.uvigo.esei.xcs.service.AdministratorService
;
import
es.uvigo.esei.xcs.service.EmailService
;
@Path
(
"administrator"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
...
...
@@ -20,9 +22,19 @@ public class AdministratorResource {
@EJB
AdministratorService
service
;
@EJB
EmailService
emailService
;
@GET
public
Response
list
(
@QueryParam
(
"page"
)
int
page
,
@QueryParam
(
"pageSize"
)
int
pageSize
)
{
return
Response
.
ok
(
this
.
service
.
list
(
page
,
pageSize
)).
build
();
}
@POST
public
Response
sendEmail
()
{
this
.
emailService
.
send
(
"email@fake.email"
,
"Topic"
,
"Text Message"
);
return
Response
.
ok
().
build
();
}
}
rest/src/main/java/es/uvigo/esei/xcs/rest/PetResource.java
View file @
f8cb9edc
...
...
@@ -7,6 +7,7 @@ import javax.ejb.EJBAccessException;
import
javax.persistence.EntityExistsException
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.DefaultValue
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.PUT
;
...
...
@@ -28,7 +29,7 @@ import es.uvigo.esei.xcs.service.PetService;
*
* @author Miguel Reboiro Jato
*/
@Path
(
"pet"
)
@Path
(
"pet
tt
"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
class
PetResource
{
...
...
@@ -67,8 +68,19 @@ public class PetResource {
* @return an {@code OK} response containing the complete list of pets of
* the current owner.
*/
@GET
@Path
(
"lista"
)
public
Response
getAll
(
@QueryParam
(
"page"
)
@DefaultValue
(
"0"
)
int
page
,
@QueryParam
(
"pageSize"
)
@DefaultValue
(
"10"
)
int
pageSize
)
{
return
Response
.
ok
(
this
.
service
.
getAll
(
page
,
pageSize
)).
build
();
}
@GET
public
Response
list
(
@QueryParam
(
"page"
)
int
page
,
@QueryParam
(
"pageSize"
)
int
pageSize
)
{
public
Response
list
(
@QueryParam
(
"page"
)
@DefaultValue
(
"0"
)
int
page
,
@QueryParam
(
"pageSize"
)
@DefaultValue
(
"10"
)
int
pageSize
)
{
return
Response
.
ok
(
this
.
service
.
list
(
page
,
pageSize
)).
build
();
}
...
...
rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java
View file @
f8cb9edc
...
...
@@ -98,7 +98,7 @@ public class VetResource {
}
@GET
@Path
(
"pet"
)
@Path
(
"pet
s
"
)
public
Response
listPets
(
//@PathParam("login") String login,
@QueryParam
(
"page"
)
@DefaultValue
(
"0"
)
int
page
,
...
...
@@ -111,7 +111,7 @@ public class VetResource {
@GET
@Path
(
"pet/{petId}"
)
@Path
(
"pet
s
/{petId}"
)
public
Response
getPet
(
@PathParam
(
"petId"
)
Long
petId
)
{
return
Response
.
ok
(
this
.
petService
.
get
(
petId
)).
build
();
}
...
...
@@ -155,7 +155,7 @@ public class VetResource {
}
}
@Path
(
"pet/{petIdentifierType}/{petIdentifierValue}/vaccination"
)
@Path
(
"pet
s
/{petIdentifierType}/{petIdentifierValue}/vaccination"
)
@GET
public
Response
listVaccinations
(
@PathParam
(
"login"
)
String
login
,
...
...
@@ -175,7 +175,7 @@ public class VetResource {
)).
build
();
}
@Path
(
"
/pet
/{petIdentifierType}/{petIdentifierValue}/vaccination"
)
@Path
(
"
pets
/{petIdentifierType}/{petIdentifierValue}/vaccination"
)
@POST
public
Response
registerVaccination
(
@QueryParam
(
"date"
)
String
date
,
...
...
@@ -195,7 +195,7 @@ public class VetResource {
@POST
@Path
(
"/assign/pet/{petId}"
)
@Path
(
"/assign/pet
s
/{petId}"
)
public
Response
assignVetToPet
(
//@PathParam("login") String vetLogin,
@PathParam
(
"petId"
)
Long
petId
...
...
@@ -216,7 +216,7 @@ public class VetResource {
}
@DELETE
@Path
(
"{login}/unassign/pet/{petId}"
)
@Path
(
"{login}/unassign/pet
s
/{petId}"
)
public
Response
unassignVetFromPet
(
//@PathParam("login") String vetLogin,
@PathParam
(
"petId"
)
Long
petId
...
...
service/src/main/java/es/uvigo/esei/xcs/service/EmailService.java
View file @
f8cb9edc
...
...
@@ -7,12 +7,14 @@ import javax.mail.Session;
import
javax.mail.Transport
;
import
javax.mail.internet.InternetAddress
;
import
javax.annotation.Resource
;
import
javax.annotation.security.PermitAll
;
import
javax.mail.internet.MimeMessage
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
@Stateless
@PermitAll
public
class
EmailService
{
@Resource
(
name
=
"java:jboss/mail/Default"
)
private
Session
session
;
...
...
service/src/main/java/es/uvigo/esei/xcs/service/PetService.java
View file @
f8cb9edc
...
...
@@ -2,6 +2,7 @@ package es.uvigo.esei.xcs.service;
import
static
java
.
util
.
Objects
.
requireNonNull
;
import
java.io.Console
;
import
java.security.Principal
;
import
java.util.List
;
...
...
@@ -25,7 +26,7 @@ import es.uvigo.esei.xcs.domain.entities.Vet;
* @author Miguel Reboiro Jato
*/
@Stateless
//@RolesAllowed("
OWNER
")
//@RolesAllowed("
VET
")
@PermitAll
public
class
PetService
{
@Inject
...
...
@@ -59,6 +60,20 @@ public class PetService {
return
em
.
find
(
Pet
.
class
,
id
);
}
public
List
<
Pet
>
getAll
(
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"
);
}
return
em
.
createQuery
(
"SELECT p FROM Pet p"
,
Pet
.
class
)
.
setFirstResult
(
page
*
pageSize
)
.
setMaxResults
(
pageSize
)
.
getResultList
();
}
/**
* Returns the complete list of pets of the current owner.
*
...
...
@@ -192,6 +207,24 @@ public class PetService {
em
.
merge
(
pet
);
}
public
Principal
getCurrentUser
()
{
return
this
.
currentUser
;
}
public
boolean
isAssignedToCurrentVet
(
Long
petId
)
{
requireNonNull
(
petId
,
"Pet ID can't be null"
);
Long
count
=
em
.
createQuery
(
"SELECT COUNT(p) FROM Pet p JOIN p.vets v WHERE p.id = :petId AND v.login = :login"
,
Long
.
class
)
.
setParameter
(
"petId"
,
petId
)
.
setParameter
(
"login"
,
currentUser
.
getName
())
.
getSingleResult
();
return
count
>
0
;
}
}
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