diff --git a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java new file mode 100644 index 0000000000000000000000000000000000000000..75f8651dd8a67b624b2331c4404c71494ac93b63 --- /dev/null +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java @@ -0,0 +1,35 @@ +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 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; + } +} diff --git a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java index 836ee765e7fd455afa0b73e55fc12ff270eab725..e6854fd65376670687095e0c11e4a8a3c4d6114b 100644 --- a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetManagedBean.java @@ -16,14 +16,14 @@ import es.uvigo.esei.xcs.service.PetService; @Named("pet") @RequestScoped public class PetManagedBean { -/* @Inject + @Inject private PetService service; private String name; private Date birth; private AnimalType animal; - private Integer id; + private Long id; private String errorMessage; @@ -65,19 +65,19 @@ public class PetManagedBean { return this.id != null; } - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } public List 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); this.id = pet.getId(); @@ -94,7 +94,7 @@ public class PetManagedBean { return this.getViewId(); } - public String remove(int id) { + public String remove(Long id) { this.service.remove(id); return redirectTo(this.getViewId()); @@ -110,7 +110,7 @@ public class PetManagedBean { this.service.update(pet); } else { - this.service.create(new Pet(name, animal, birth)); + //this.service.create(new Pet(name, animal, birth)); } this.clear(); @@ -137,5 +137,5 @@ public class PetManagedBean { private String getViewId() { return FacesContext.getCurrentInstance().getViewRoot().getViewId(); - }*/ + } } diff --git a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java index ab30c3979c3aacf324525385edd8d1c23df8ca6f..ab12b02fa012a59c1872c4d873b5271fe7ff68d4 100644 --- a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VetManagedBean.java @@ -61,9 +61,13 @@ public class VetManagedBean { public List getVets() { return this.service.list(); } + + public List getPets() { + return this.service.getPets(0, 100); + } - public String getPetNames(String login) { - return this.service.getPets(login, 0, 100).stream() + public String getPetNames() { + return this.service.getPets(0, 100).stream() .map(Pet::getName) .collect(joining(", ")); } diff --git a/jsf/src/main/webapp/vet/petDetails.xhtml b/jsf/src/main/webapp/vet/petDetails.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..1874831fd110f81b41cb6e705f364246f4fbdf2c --- /dev/null +++ b/jsf/src/main/webapp/vet/petDetails.xhtml @@ -0,0 +1,43 @@ + + + + + Detalle de Mascota + + + + +

Detalles de Mascota

+ + + + + + + + + + + + + + + +

Vacunas

+ + + Fecha + #{v.date} + + + Vacuna + #{v.vaccine.name} + + +
+
+
+ diff --git a/jsf/src/main/webapp/vet/supervisedPets.xhtml b/jsf/src/main/webapp/vet/supervisedPets.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..1cd9acda4331f2bb46d5669d2937b6ac7fd8054c --- /dev/null +++ b/jsf/src/main/webapp/vet/supervisedPets.xhtml @@ -0,0 +1,48 @@ + + + + + + Vet - Pets Supervised + + + + +

Mascotas Supervisadas

+

Listado de las mascotas que supervisas (nombre y tipo de animal).

+
+ + + + + ID + #{supervisedPet.id} + + + Nombre + #{supervisedPet.name} + + + Tipo de Animal + #{supervisedPet.animal} + + + + Acciones + + + + + + + + + Error: #{vet.errorMessage} + + +
+ + diff --git a/jsf/src/main/webapp/vet/vaccines.xhtml b/jsf/src/main/webapp/vet/vaccines.xhtml index 3f22e636e96d34b40a9dcda9ffa6b75ed63574fa..466243cc24720ff578605f4ebe0b23e3034fe240 100644 --- a/jsf/src/main/webapp/vet/vaccines.xhtml +++ b/jsf/src/main/webapp/vet/vaccines.xhtml @@ -16,21 +16,20 @@ ID#{v.id} Nombre#{v.name} Tipo#{v.class.simpleName} + + Doses + #{v.class.simpleName eq 'MultidoseVaccine' ? v.doses : ''} + - - Doses - #{v.doses} - - - - Periode - #{v.periode} - + + Periode + #{v.class.simpleName eq 'PeriodicVaccine' ? v.periode : ''} + - - PeriodicType - #{v.periodicType} - + + Periodic Type + #{v.class.simpleName eq 'PeriodicVaccine' ? v.periodicType : ''} + Acciones @@ -61,30 +60,40 @@ - + - - - - - - - - - - - + --> + + + + + + + + + + + + + + + + + + + + +
diff --git a/rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java b/rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java index 9da343a7532fb2105c5115c16dc1c138ea8e8dcc..f053e04b57b0382709fe062d77bbbaade98ac077 100644 --- a/rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java +++ b/rest/src/main/java/es/uvigo/esei/xcs/rest/VetResource.java @@ -98,15 +98,15 @@ public class VetResource { } @GET - @Path("{login}/pet") + @Path("pet") public Response listPets( - @PathParam("login") String login, + //@PathParam("login") String login, @QueryParam("page") @DefaultValue("0") int page, @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 { } } - @Path("{login}/pet/{petIdentifierType}/{petIdentifierValue}/vaccination") + @Path("pet/{petIdentifierType}/{petIdentifierValue}/vaccination") @GET public Response listVaccinations( @PathParam("login") String login, @@ -167,7 +167,7 @@ public class VetResource { requireNonNull(login, "login can't be null"); return Response.ok(this.vetService.getVaccinationsFromOwnPet( - login, + //login, petIdentifierType, petIdentifierValue, page, @@ -218,16 +218,16 @@ public class VetResource { @DELETE @Path("{login}/unassign/pet/{petId}") public Response unassignVetFromPet( - @PathParam("login") String vetLogin, + //@PathParam("login") String vetLogin, @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"); try { - petService.unassignVetFromPet(petId, vetLogin); + petService.unassignVetFromPet(petId); return Response.ok() - .entity("Vet " + vetLogin + " unassigned from pet " + petId) + //.entity("Vet " + vetLogin + " unassigned from pet " + petId) .build(); } catch (IllegalArgumentException e) { return Response.status(Response.Status.NOT_FOUND) diff --git a/service/src/main/java/es/uvigo/esei/xcs/service/PetService.java b/service/src/main/java/es/uvigo/esei/xcs/service/PetService.java index 16125eba31bdccfd18459ca2c4cb372024fdf50a..664a2d0a302ac32559101315653c4bfd13b5f8f2 100644 --- a/service/src/main/java/es/uvigo/esei/xcs/service/PetService.java +++ b/service/src/main/java/es/uvigo/esei/xcs/service/PetService.java @@ -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(vetLogin, "Vet login can't be null"); + //requireNonNull(vetLogin, "Vet login can't be null"); Pet pet = em.find(Pet.class, petId); if (pet == null) throw new IllegalArgumentException("Pet not found"); - Vet vet = em.find(Vet.class, vetLogin); + Vet vet = em.find(Vet.class, currentUser.getName()); if (vet == null) throw new IllegalArgumentException("Vet not found"); diff --git a/service/src/main/java/es/uvigo/esei/xcs/service/VaccineService.java b/service/src/main/java/es/uvigo/esei/xcs/service/VaccineService.java index 0ad391c7cd31822479d24fa67c398309c7bb1dfe..1973d4bd1df81dfa907e454a298653c4c797a016 100644 --- a/service/src/main/java/es/uvigo/esei/xcs/service/VaccineService.java +++ b/service/src/main/java/es/uvigo/esei/xcs/service/VaccineService.java @@ -5,6 +5,7 @@ package es.uvigo.esei.xcs.service; import java.util.List; import javax.annotation.security.PermitAll; +import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @@ -18,6 +19,7 @@ import es.uvigo.esei.xcs.domain.entities.Vaccine; @Stateless @PermitAll +//@RolesAllowed("VET") public class VaccineService { @PersistenceContext private EntityManager em; diff --git a/service/src/main/java/es/uvigo/esei/xcs/service/VetService.java b/service/src/main/java/es/uvigo/esei/xcs/service/VetService.java index d45d0acfe579c5c0003cf94f02c0abac0831936c..cdb90959f912de31f005bc7508f260f733f8ec81 100644 --- a/service/src/main/java/es/uvigo/esei/xcs/service/VetService.java +++ b/service/src/main/java/es/uvigo/esei/xcs/service/VetService.java @@ -2,11 +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.EntityManager; import javax.persistence.PersistenceContext; @@ -19,6 +21,9 @@ import es.uvigo.esei.xcs.domain.entities.Vet; //@RolesAllowed("VET") @PermitAll public class VetService { + @Inject + private Principal currentUser; + @PersistenceContext EntityManager em; @@ -68,8 +73,8 @@ public class VetService { } - public List getPets(String login, int page , int pageSize) { - requireNonNull(login, "Login can't be null"); + public List getPets(int page , int pageSize) { + //requireNonNull(login, "Login can't be null"); if (page < 0) { throw new IllegalArgumentException("The page can't be negative"); } @@ -80,18 +85,18 @@ public class VetService { + "WHERE v.login = :login", Pet.class) .setFirstResult(page * pageSize) .setMaxResults(pageSize) - .setParameter("login", login) + .setParameter("login", currentUser.getName()) .getResultList(); } public List getVaccinationsFromOwnPet( - String login, + //String login, IdentifierType identifierType, String identifierValue, int page, 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(identifierValue, "pet's identifier value can't be null"); if (page < 0) { @@ -110,7 +115,7 @@ public class VetService { + "i.identifierType = :identifierType AND " + "i.identifierValue = :identifierValue", Vaccination.class) - .setParameter("login", login) + .setParameter("login", currentUser.getName()) .setParameter("identifierType", identifierType) .setParameter("identifierValue", identifierValue) .setFirstResult(page * pageSize)